[
  {
    "path": ".arcconfig",
    "content": "{\n\t\"phabricator.uri\": \"https://phabricator.purduesigbots.com/\",\n\t\"repoistory.callsign\": \"rRESTRICTEDPROS\",\n\t\"lint.engine\": \"ArcanistConfigurationDrivenLintEngine\",\n\t\"default-reviewers\": \"berman5 jhabibi jbuschjr\",\n\t\"load\": [\n\t\t\"clang-format-linter\"\n\t]\n}\n"
  },
  {
    "path": ".arclint",
    "content": "{\n\t\"linters\": {\n\t\t\"clang-format\": {\n\t\t\t\"type\": \"clang-format\",\n\t\t\t\"include\": \"(.*\\\\.(c|cpp|h|hpp)$)\",\n\t\t\t\"exclude\": \"(^(src|include)/(rtos/|display/lv_.+))\"\n\t\t},\n\t\t\"spelling\": {\n\t\t\t\"type\": \"spelling\",\n\t\t\t\"include\": \"(.*)\",\n\t\t\t\"exclude\": \"(^(src|include)|(rtos/|display/lv_.*))\"\n\t\t},\n\t\t\"text\": {\n\t\t\t\"type\": \"text\",\n\t\t\t\"include\": \"(.*)\",\n\t\t\t\"exclude\": \"(^(src|include)/(((rtos)/)|(system/dev/banners.h)|(display/((lv_.+)|(licence.txt)))))\",\n\t\t\t\"severity\": {\n\t\t\t\t\"2\": \"disabled\",\n\t\t\t\t\"3\": \"disabled\"\n\t\t\t}\n\t\t}\n\t}\n}\n"
  },
  {
    "path": ".clang-format",
    "content": "BasedOnStyle: Google\nTabWidth: 2\nLanguage: Cpp\nUseTab: ForIndentation\nColumnLimit: 120\nStandard: Cpp11\nDerivePointerAlignment: false\nPointerAlignment: Left\nFixNamespaceComments: true\nReflowComments: true\nSortIncludes: true\nAccessModifierOffset: 0\nAllowShortBlocksOnASingleLine: false\nAllowShortCaseLabelsOnASingleLine: false\nAllowShortFunctionsOnASingleLine: Empty\n"
  },
  {
    "path": ".github/CONTRIBUTING.md",
    "content": "# Contributing to PROS\n\n:tada: :+1: :steam_locomotive: Thanks for taking the time to contribute! :steam_locomotive: :+1: :tada:\n\n**Did you find a bug?**\n- **Before opening an issue, make sure you are in the right repository!**\n  purduesigbots maintains four repositories related to PROS:\n  - [purduesigbots/pros](https://github.com/purduesigbots/pros): the repository containing the source code for the kernel the user-facing API. Issues should be opened here if they affect the code you write (e.g., \"I would like to be able to do X with PROS,\" or \"when I call <PROS function> X doesn't work as I expect\")\n  - [purduesigbots/pros-cli](https://github.com/purduesigbots/pros-cli): the repository containing the source code for the command line interface (CLI). Issues should be opened here if they concern the PROS CLI (e.g., problems with commands like `pros make`), as well as project creation and management.\n  - [purduesigbots/pros-atom](https://github.com/purduesigbots/pros-vsc): the repository containing the source code for the VSCode extension. Issues should be opened here if they concern the coding experience within VSCode (e.g., \"there is no button to do X,\" or \"the linter is spamming my interface with errors\").\n  - [purduesigbots/pros-docs](https://github.com/purduesigbots/pros-docs): the repository containing the source code for [our documentation website](https://pros.cs.purdue.edu). Issues should be opened here if they concern available documentation (e.g., \"there is not guide on using <PROS feature>,\" or \"the documentation says to do X, but only Y works\")\n- **Verify the bug lies in PROS.** We receive quite a few reports that are due to bugs in user code, not the kernel.\n- Ensure the bug wasn't already reported by searching GitHub [issues](https://github.com/purduesigbots/pros/issues)\n- If you're unable to find an issue, [open](https://github.com/purduesigbots/pros/issues/new) a new one.\n\n**Did you patch a bug or add a new feature?**\n1. [Fork](https://github.com/purduesigbots/pros/fork) and clone the repository\n2. Create a new branch: `git checkout -b my-branch-name`\n3. Make your changes.\n4. Push to your fork and submit a pull request.\n5. Wait for your pull request to be reviewed. In order to ensure that the PROS kernel is stable, we take extra time to test pull requests. As a result, your pull request may take some time to be merged into master.\n\nHere are a few tips that can help expedite your pull request being accepted:\n- Follow existing code's style.\n- Document why you made the changes you did.\n- Keep your change as focused as possible. If you have multiple independent changes, make a pull request for each.\n- If you did some testing, describe your procedure and results.\n- If you're fixing an issue, reference it by number.\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE.md",
    "content": "#### Expected Behavior:\n<!-- Describe what you expected to happen -->\n\n#### Actual Behavior:\n<!-- Describe what actually happened -->\n\n#### Steps to reproduce:\n<!-- Is the observed behavior repeatable? If so, describe the steps needed to reproduce it. -->\n\n#### System information:\nPlatform: <!-- e.g. V5 or Cortex -->\nPROS Kernel Version: <!-- run `prosv5 conduct info-project` in the project root -->\n\n#### Additional Information\n<!-- Is there any additional information you think is relevant? -->\n\n#### Screenshots/Output Dumps/Stack Traces\n"
  },
  {
    "path": ".github/PULL_REQUEST_TEMPLATE.md",
    "content": "#### Summary:\n<!-- Provide a concise description of your changes -->\n\n#### Motivation:\n<!-- Provide a brief description of why you think these changes need to be made -->\n\n##### References (optional):\n<!-- If this PR is related to an issue or task, reference it here (e.g. closes #1) -->\n\n#### Test Plan:\n<!-- Provide a list of steps that can be taken to verify these changes work as intended -->\n\n- [ ] test item\n"
  },
  {
    "path": ".gitignore",
    "content": ".vscode/\n.idea/\nbin/\n.*.sw*\ntemplate/\nversion\ncquery_log.txt\ncompile_commands.json\n.ccls-cache/\n.ccls\ntemp.log\ntemp.errors\n.d/\n.clangd/\n.cache/\n.DS_Store\n"
  },
  {
    "path": ".gitmodules",
    "content": "[submodule \"firmware/libv5rts\"]\n\tpath = firmware/libv5rts\n\turl = git@github.com:purduesigbots/libv5rts.git\n\tignore = dirty\n"
  },
  {
    "path": "LICENSE",
    "content": "PROS 4.0 contains modified or linked source code from the following packages:\n    - FreeRTOS (src/rtos/LICENSE)\n\nUnless otherwise specified, PROS 4.0 is distributed under the Mozilla Public\nLicense Version 2.0, reproduced below:\n\nMozilla Public License Version 2.0\n==================================\n\n1. Definitions\n--------------\n\n1.1. \"Contributor\"\n    means each individual or legal entity that creates, contributes to\n    the creation of, or owns Covered Software.\n\n1.2. \"Contributor Version\"\n    means the combination of the Contributions of others (if any) used\n    by a Contributor and that particular Contributor's Contribution.\n\n1.3. \"Contribution\"\n    means Covered Software of a particular Contributor.\n\n1.4. \"Covered Software\"\n    means Source Code Form to which the initial Contributor has attached\n    the notice in Exhibit A, the Executable Form of such Source Code\n    Form, and Modifications of such Source Code Form, in each case\n    including portions thereof.\n\n1.5. \"Incompatible With Secondary Licenses\"\n    means\n\n    (a) that the initial Contributor has attached the notice described\n        in Exhibit B to the Covered Software; or\n\n    (b) that the Covered Software was made available under the terms of\n        version 1.1 or earlier of the License, but not also under the\n        terms of a Secondary License.\n\n1.6. \"Executable Form\"\n    means any form of the work other than Source Code Form.\n\n1.7. \"Larger Work\"\n    means a work that combines Covered Software with other material, in\n    a separate file or files, that is not Covered Software.\n\n1.8. \"License\"\n    means this document.\n\n1.9. \"Licensable\"\n    means having the right to grant, to the maximum extent possible,\n    whether at the time of the initial grant or subsequently, any and\n    all of the rights conveyed by this License.\n\n1.10. \"Modifications\"\n    means any of the following:\n\n    (a) any file in Source Code Form that results from an addition to,\n        deletion from, or modification of the contents of Covered\n        Software; or\n\n    (b) any new file in Source Code Form that contains any Covered\n        Software.\n\n1.11. \"Patent Claims\" of a Contributor\n    means any patent claim(s), including without limitation, method,\n    process, and apparatus claims, in any patent Licensable by such\n    Contributor that would be infringed, but for the grant of the\n    License, by the making, using, selling, offering for sale, having\n    made, import, or transfer of either its Contributions or its\n    Contributor Version.\n\n1.12. \"Secondary License\"\n    means either the GNU General Public License, Version 2.0, the GNU\n    Lesser General Public License, Version 2.1, the GNU Affero General\n    Public License, Version 3.0, or any later versions of those\n    licenses.\n\n1.13. \"Source Code Form\"\n    means the form of the work preferred for making modifications.\n\n1.14. \"You\" (or \"Your\")\n    means an individual or a legal entity exercising rights under this\n    License. For legal entities, \"You\" includes any entity that\n    controls, is controlled by, or is under common control with You. For\n    purposes of this definition, \"control\" means (a) the power, direct\n    or indirect, to cause the direction or management of such entity,\n    whether by contract or otherwise, or (b) ownership of more than\n    fifty percent (50%) of the outstanding shares or beneficial\n    ownership of such entity.\n\n2. License Grants and Conditions\n--------------------------------\n\n2.1. Grants\n\nEach Contributor hereby grants You a world-wide, royalty-free,\nnon-exclusive license:\n\n(a) under intellectual property rights (other than patent or trademark)\n    Licensable by such Contributor to use, reproduce, make available,\n    modify, display, perform, distribute, and otherwise exploit its\n    Contributions, either on an unmodified basis, with Modifications, or\n    as part of a Larger Work; and\n\n(b) under Patent Claims of such Contributor to make, use, sell, offer\n    for sale, have made, import, and otherwise transfer either its\n    Contributions or its Contributor Version.\n\n2.2. Effective Date\n\nThe licenses granted in Section 2.1 with respect to any Contribution\nbecome effective for each Contribution on the date the Contributor first\ndistributes such Contribution.\n\n2.3. Limitations on Grant Scope\n\nThe licenses granted in this Section 2 are the only rights granted under\nthis License. No additional rights or licenses will be implied from the\ndistribution or licensing of Covered Software under this License.\nNotwithstanding Section 2.1(b) above, no patent license is granted by a\nContributor:\n\n(a) for any code that a Contributor has removed from Covered Software;\n    or\n\n(b) for infringements caused by: (i) Your and any other third party's\n    modifications of Covered Software, or (ii) the combination of its\n    Contributions with other software (except as part of its Contributor\n    Version); or\n\n(c) under Patent Claims infringed by Covered Software in the absence of\n    its Contributions.\n\nThis License does not grant any rights in the trademarks, service marks,\nor logos of any Contributor (except as may be necessary to comply with\nthe notice requirements in Section 3.4).\n\n2.4. Subsequent Licenses\n\nNo Contributor makes additional grants as a result of Your choice to\ndistribute the Covered Software under a subsequent version of this\nLicense (see Section 10.2) or under the terms of a Secondary License (if\npermitted under the terms of Section 3.3).\n\n2.5. Representation\n\nEach Contributor represents that the Contributor believes its\nContributions are its original creation(s) or it has sufficient rights\nto grant the rights to its Contributions conveyed by this License.\n\n2.6. Fair Use\n\nThis License is not intended to limit any rights You have under\napplicable copyright doctrines of fair use, fair dealing, or other\nequivalents.\n\n2.7. Conditions\n\nSections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted\nin Section 2.1.\n\n3. Responsibilities\n-------------------\n\n3.1. Distribution of Source Form\n\nAll distribution of Covered Software in Source Code Form, including any\nModifications that You create or to which You contribute, must be under\nthe terms of this License. You must inform recipients that the Source\nCode Form of the Covered Software is governed by the terms of this\nLicense, and how they can obtain a copy of this License. You may not\nattempt to alter or restrict the recipients' rights in the Source Code\nForm.\n\n3.2. Distribution of Executable Form\n\nIf You distribute Covered Software in Executable Form then:\n\n(a) such Covered Software must also be made available in Source Code\n    Form, as described in Section 3.1, and You must inform recipients of\n    the Executable Form how they can obtain a copy of such Source Code\n    Form by reasonable means in a timely manner, at a charge no more\n    than the cost of distribution to the recipient; and\n\n(b) You may distribute such Executable Form under the terms of this\n    License, or sublicense it under different terms, provided that the\n    license for the Executable Form does not attempt to limit or alter\n    the recipients' rights in the Source Code Form under this License.\n\n3.3. Distribution of a Larger Work\n\nYou may create and distribute a Larger Work under terms of Your choice,\nprovided that You also comply with the requirements of this License for\nthe Covered Software. If the Larger Work is a combination of Covered\nSoftware with a work governed by one or more Secondary Licenses, and the\nCovered Software is not Incompatible With Secondary Licenses, this\nLicense permits You to additionally distribute such Covered Software\nunder the terms of such Secondary License(s), so that the recipient of\nthe Larger Work may, at their option, further distribute the Covered\nSoftware under the terms of either this License or such Secondary\nLicense(s).\n\n3.4. Notices\n\nYou may not remove or alter the substance of any license notices\n(including copyright notices, patent notices, disclaimers of warranty,\nor limitations of liability) contained within the Source Code Form of\nthe Covered Software, except that You may alter any license notices to\nthe extent required to remedy known factual inaccuracies.\n\n3.5. Application of Additional Terms\n\nYou may choose to offer, and to charge a fee for, warranty, support,\nindemnity or liability obligations to one or more recipients of Covered\nSoftware. However, You may do so only on Your own behalf, and not on\nbehalf of any Contributor. You must make it absolutely clear that any\nsuch warranty, support, indemnity, or liability obligation is offered by\nYou alone, and You hereby agree to indemnify every Contributor for any\nliability incurred by such Contributor as a result of warranty, support,\nindemnity or liability terms You offer. You may include additional\ndisclaimers of warranty and limitations of liability specific to any\njurisdiction.\n\n4. Inability to Comply Due to Statute or Regulation\n---------------------------------------------------\n\nIf it is impossible for You to comply with any of the terms of this\nLicense with respect to some or all of the Covered Software due to\nstatute, judicial order, or regulation then You must: (a) comply with\nthe terms of this License to the maximum extent possible; and (b)\ndescribe the limitations and the code they affect. Such description must\nbe placed in a text file included with all distributions of the Covered\nSoftware under this License. Except to the extent prohibited by statute\nor regulation, such description must be sufficiently detailed for a\nrecipient of ordinary skill to be able to understand it.\n\n5. Termination\n--------------\n\n5.1. The rights granted under this License will terminate automatically\nif You fail to comply with any of its terms. However, if You become\ncompliant, then the rights granted under this License from a particular\nContributor are reinstated (a) provisionally, unless and until such\nContributor explicitly and finally terminates Your grants, and (b) on an\nongoing basis, if such Contributor fails to notify You of the\nnon-compliance by some reasonable means prior to 60 days after You have\ncome back into compliance. Moreover, Your grants from a particular\nContributor are reinstated on an ongoing basis if such Contributor\nnotifies You of the non-compliance by some reasonable means, this is the\nfirst time You have received notice of non-compliance with this License\nfrom such Contributor, and You become compliant prior to 30 days after\nYour receipt of the notice.\n\n5.2. If You initiate litigation against any entity by asserting a patent\ninfringement claim (excluding declaratory judgment actions,\ncounter-claims, and cross-claims) alleging that a Contributor Version\ndirectly or indirectly infringes any patent, then the rights granted to\nYou by any and all Contributors for the Covered Software under Section\n2.1 of this License shall terminate.\n\n5.3. In the event of termination under Sections 5.1 or 5.2 above, all\nend user license agreements (excluding distributors and resellers) which\nhave been validly granted by You or Your distributors under this License\nprior to termination shall survive termination.\n\n************************************************************************\n*                                                                      *\n*  6. Disclaimer of Warranty                                           *\n*  -------------------------                                           *\n*                                                                      *\n*  Covered Software is provided under this License on an \"as is\"       *\n*  basis, without warranty of any kind, either expressed, implied, or  *\n*  statutory, including, without limitation, warranties that the       *\n*  Covered Software is free of defects, merchantable, fit for a        *\n*  particular purpose or non-infringing. The entire risk as to the     *\n*  quality and performance of the Covered Software is with You.        *\n*  Should any Covered Software prove defective in any respect, You     *\n*  (not any Contributor) assume the cost of any necessary servicing,   *\n*  repair, or correction. This disclaimer of warranty constitutes an   *\n*  essential part of this License. No use of any Covered Software is   *\n*  authorized under this License except under this disclaimer.         *\n*                                                                      *\n************************************************************************\n\n************************************************************************\n*                                                                      *\n*  7. Limitation of Liability                                          *\n*  --------------------------                                          *\n*                                                                      *\n*  Under no circumstances and under no legal theory, whether tort      *\n*  (including negligence), contract, or otherwise, shall any           *\n*  Contributor, or anyone who distributes Covered Software as          *\n*  permitted above, be liable to You for any direct, indirect,         *\n*  special, incidental, or consequential damages of any character      *\n*  including, without limitation, damages for lost profits, loss of    *\n*  goodwill, work stoppage, computer failure or malfunction, or any    *\n*  and all other commercial damages or losses, even if such party      *\n*  shall have been informed of the possibility of such damages. This   *\n*  limitation of liability shall not apply to liability for death or   *\n*  personal injury resulting from such party's negligence to the       *\n*  extent applicable law prohibits such limitation. Some               *\n*  jurisdictions do not allow the exclusion or limitation of           *\n*  incidental or consequential damages, so this exclusion and          *\n*  limitation may not apply to You.                                    *\n*                                                                      *\n************************************************************************\n\n8. Litigation\n-------------\n\nAny litigation relating to this License may be brought only in the\ncourts of a jurisdiction where the defendant maintains its principal\nplace of business and such litigation shall be governed by laws of that\njurisdiction, without reference to its conflict-of-law provisions.\nNothing in this Section shall prevent a party's ability to bring\ncross-claims or counter-claims.\n\n9. Miscellaneous\n----------------\n\nThis License represents the complete agreement concerning the subject\nmatter hereof. If any provision of this License is held to be\nunenforceable, such provision shall be reformed only to the extent\nnecessary to make it enforceable. Any law or regulation which provides\nthat the language of a contract shall be construed against the drafter\nshall not be used to construe this License against a Contributor.\n\n10. Versions of the License\n---------------------------\n\n10.1. New Versions\n\nMozilla Foundation is the license steward. Except as provided in Section\n10.3, no one other than the license steward has the right to modify or\npublish new versions of this License. Each version will be given a\ndistinguishing version number.\n\n10.2. Effect of New Versions\n\nYou may distribute the Covered Software under the terms of the version\nof the License under which You originally received the Covered Software,\nor under the terms of any subsequent version published by the license\nsteward.\n\n10.3. Modified Versions\n\nIf you create software not governed by this License, and you want to\ncreate a new license for such software, you may create and use a\nmodified version of this License if you rename the license and remove\nany references to the name of the license steward (except to note that\nsuch modified license differs from this License).\n\n10.4. Distributing Source Code Form that is Incompatible With Secondary\nLicenses\n\nIf You choose to distribute Source Code Form that is Incompatible With\nSecondary Licenses under the terms of this version of the License, the\nnotice described in Exhibit B of this License must be attached.\n\nExhibit A - Source Code Form License Notice\n-------------------------------------------\n\n  This Source Code Form is subject to the terms of the Mozilla Public\n  License, v. 2.0. If a copy of the MPL was not distributed with this\n  file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\nIf it is not possible or desirable to put the notice in a particular\nfile, then You may include the notice in a location (such as a LICENSE\nfile in a relevant directory) where a recipient would be likely to look\nfor such a notice.\n\nYou may add additional accurate notices of copyright ownership.\n\nExhibit B - \"Incompatible With Secondary Licenses\" Notice\n---------------------------------------------------------\n\n  This Source Code Form is \"Incompatible With Secondary Licenses\", as\n  defined by the Mozilla Public License, v. 2.0.\n"
  },
  {
    "path": "Makefile",
    "content": "################################################################################\n######################### User configurable parameters #########################\n# filename extensions\nCEXTS:=c\nASMEXTS:=s S\nCXXEXTS:=cpp c++ cc\n\n# probably shouldn't modify these, but you may need them below\nROOT=.\nFWDIR:=$(ROOT)/firmware\nBINDIR=$(ROOT)/bin\nSRCDIR=$(ROOT)/src\nINCDIR=$(ROOT)/include\nEXTRA_INCDIR=$(FWDIR)/libv5rts/sdk/vexv5/patched_include\n\n# Directories to be excluded from all builds\nEXCLUDE_SRCDIRS+=$(SRCDIR)/tests\n\nC_STANDARD=gnu2x\nCXX_STANDARD=gnu++23\n\nWARNFLAGS+=-Wall -Wpedantic\nEXTRA_CFLAGS+=\nEXTRA_CXXFLAGS=-D_PROS_KERNEL_SUPPRESS_LLEMU_WARNING\n\n.DEFAULT_GOAL=quick\nUSE_PACKAGE:=0\n\n# Set this to 1 to add additional rules to compile your project as a PROS library template\nIS_LIBRARY:=1\nLIBNAME:=libpros\nVERSION=$(shell cat $(ROOT)/version)\n# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c\nEXCLUDE_SRC_FROM_LIB+=$(EXCLUDE_SRCDIRS)\n# this line excludes opcontrol.c and similar files\nEXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/main,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext)))\n\n# files that get distributed to every user (beyond your source archive) - add\n# whatever files you want here. This line is configured to add all header files\n# that are in the the include directory get exported\nTEMPLATE_FILES=$(ROOT)/common.mk $(FWDIR)/v5.ld $(FWDIR)/v5-common.ld $(FWDIR)/v5-hot.ld\nTEMPLATE_FILES+=$(FWDIR)/libc.a $(FWDIR)/libm.a\nTEMPLATE_FILES+= $(INCDIR)/api.h $(INCDIR)/main.h $(INCDIR)/pros/*.* \nTEMPLATE_FILES+= $(SRCDIR)/main.cpp\nTEMPLATE_FILES+= $(ROOT)/template-gitignore\n\nPATCHED_SDK=$(FWDIR)/libv5rts/sdk/vexv5/libv5rts.patched.a\n\nEXTRA_LIB_DEPS=$(INCDIR)/api.h $(PATCHED_SDK)\n\n################################################################################\n################################################################################\n########## Nothing below this line should be edited by typical users ###########\n-include ./common.mk\n\n.PHONY: $(INCDIR)/pros/version.h patch_sdk_headers clean\n$(INCDIR)/pros/version.h: version.py\n\t$(VV)python version.py\n\npatch_sdk_headers: patch_headers.py\n\t@echo \"Patching SDK headers\"\n\t$(VV)python patch_headers.py\n\n# Override clean, necessary to remove patched sdk on clean\nclean::\n\t@echo \"Cleaning patched SDK\"\n\t@rm -f $(PATCHED_SDK)\n\t@rm -rf $(EXTRA_INCDIR)\n\n$(PATCHED_SDK): $(FWDIR)/libv5rts/sdk/vexv5/libv5rts.a\n\t$(call test_output_2,Stripping unwanted symbols from libv5rts.a ,$(STRIP) $^ @libv5rts-strip-options.txt -o $@, $(DONE_STRING))\n\nCREATE_TEMPLATE_ARGS=--system \"./**/*\"\nCREATE_TEMPLATE_ARGS+=--user \"src/main.{cpp,c,cc}\" --user \"include/main.{hpp,h,hh}\" --user \"Makefile\" --user \".gitignore\"\nCREATE_TEMPLATE_ARGS+=--target v5\nCREATE_TEMPLATE_ARGS+=--output bin/monolith.bin --cold_output bin/cold.package.bin --hot_output bin/hot.package.bin --cold_addr 58720256 --hot_addr 125829120\n\ntemplate:: patch_sdk_headers clean-template library\n\t$(VV)mkdir -p $(TEMPLATE_DIR)\n\t@echo \"Moving template files to $(TEMPLATE_DIR)\"\n\t$Dif [ $(shell uname -s) == \"Darwin\" ]; then \\\n\t\trsync -R $(TEMPLATE_FILES) $(TEMPLATE_DIR); \\\n\telse \\\n\t\tcp --parents -r $(TEMPLATE_FILES) $(TEMPLATE_DIR); \\\n\tfi\n\t$(VV)mkdir -p $(TEMPLATE_DIR)/firmware\n\t$Dcp $(LIBAR) $(TEMPLATE_DIR)/firmware\n\t$Dcp $(ROOT)/template-Makefile $(TEMPLATE_DIR)/Makefile\n\t$Dmv $(TEMPLATE_DIR)/template-gitignore $(TEMPLATE_DIR)/.gitignore\n\t@echo \"Creating template\"\n\t$Dpros c create-template $(TEMPLATE_DIR) kernel $(shell cat $(ROOT)/version) $(CREATE_TEMPLATE_ARGS)\n\nLIBV5RTS_EXTRACTION_DIR=$(BINDIR)/libv5rts\n$(LIBAR): patch_sdk_headers $(call GETALLOBJ,$(EXCLUDE_SRC_FROM_LIB)) $(EXTRA_LIB_DEPS)\n\t$(VV)mkdir -p $(LIBV5RTS_EXTRACTION_DIR)\n\t$(call test_output_2,Extracting libv5rts ,cd $(LIBV5RTS_EXTRACTION_DIR) && $(AR) x ../../$(PATCHED_SDK),$(DONE_STRING))\n\t$(eval LIBV5RTS_OBJECTS := $(shell $(AR) t $(PATCHED_SDK)))\n\t-$Drm -f $@\n\t$(call test_output_2,Creating $@ ,$(AR) rcs $@ $(addprefix $(LIBV5RTS_EXTRACTION_DIR)/, $(LIBV5RTS_OBJECTS)) $(call GETALLOBJ,$(EXCLUDE_SRC_FROM_LIB)),$(DONE_STRING))\n# @echo -n \"Stripping non-public symbols \"\n# $(call test_output,$D$(OBJCOPY) -S -D -g --strip-unneeded --keep-symbols public_symbols.txt $@,$(DONE_STRING))"
  },
  {
    "path": "README.md",
    "content": "# PROS Kernel for the VEX V5 Brain\n\n[![Build Status](https://dev.azure.com/purdue-acm-sigbots/Kernel/_apis/build/status/purduesigbots.pros?branchName=develop)](https://dev.azure.com/purdue-acm-sigbots/Kernel/_build/latest?definitionId=5&branchName=develop)\n\n### What is PROS?\nPROS is a lightweight and fast alternative open source operating system for the VEX V5 Brain. PROS is built with developers in mind and with a focus on providing an environment for industry-applicable experience.\n\nPrimary maintenance of PROS is done by students at Purdue University through [Purdue ACM SIGBots](http://purduesigbots.com). Inspiration for this project came from several computer science and engineering students itching to write code for the extended autonomous period. We created PROS to leverage this opportunity.\n\nAll PROS development is open sourced and available for the community to inspect. We believe that sharing source improves PROS through community contributions and allows students to learn by example.\n\nPROS is built using the GCC toolchain and standard C/C++ practices (C23 & C++23 w/GNU extensions) to make the learning curve small. Structures, pointers, dynamic memory allocation, and function pointers are all available. Additionally, code is run on bare metal, allowing you to take full advantage of the microcontroller's power.\n\nYou can develop code on Windows, OS X, or Linux. Code is compiled using GCC and the PROS CLI is available on most operating systems. The PROS development team makes distributions for Windows, OS X, and Debian-based Linux distributions.\n\nThe PROS team develops a plugin for Atom to making developing projects in PROS the best possible experience. The highly customizable editor designed for the 21st century enables students to learn how to code in a modern environment.\n\n### What's the difference between PROS 4 and 3?\nPROS 4 is a Kernel upgrade from PROS 4 to both decrease the size of the base Kernel, and provide utilities such as the base device class and liblvgl that makes it easier for both users and library writers to customize their PROS projects. This version also moves all documentation to a doxygen site rather than a Sphinx documentation page. \n\n### What's the difference between PROS 2 and PROS 3?\nPROS 2 refers to the kernel that runs on the [VEX Arm Cortex-based Microcontroller](https://www.vexrobotics.com/276-2194.html). The source for this kernel is still available on the `cortex-master` branch. The future development for this version of the PROS kernel will be focused on maintenance and critical bugfixes.\n\nPROS 3 refers to the kernel that runs on the [VEX V5](https://www.vexrobotics.com/vexedr/v5) microcontroller platform. The majority of our development focus will be on this version of the PROS kernel.\n\n### Does PROS support C++?\n- PROS 3.x and 4.x (V5) officially supports C++. We're still working on enabling all of the features of C++ (particularly in the I/O area).\n- PROS 2.x (Cortex) does not officially support C++. Some users have found ways around this, but be warned: we will not be able to help if you run into issues doing this.\n\n### Cool, how do I get it?\nPay a visit to our website, [pros.cs.purdue.edu](https://pros.cs.purdue.edu), to download our latest installer or view installation instructions for your preferred platform.\n\n### How do I use it?\nWe have a number of resources available on our website, including\n- [A basic tutorial to get you acquainted with the PROS ecosystem](https://pros.cs.purdue.edu/v5/getting-started/new-users.html)\n- [A series of tutorials on how to use some of the more advanced features of PROS](https://pros.cs.purdue.edu/v5/tutorials/index.html)\n- [Extensive documentation on the kernel's API](https://pros.cs.purdue.edu/v5/api/index.html)\n\n### I still have questions!\nDrop us a line\n- at pros_development@cs.purdue.edu\n- on the [VEX Forum](https://www.vexforum.com/)\n- on [VEX Teams of the World Discord](https://discord.gg/xddjWGj)\n\n### I think I found a bug!\nWe maintain GitHub repositories for the three major components of the PROS ecosystem:\n- The Command Line Interface (cli) at [purduesigbots/pros-cli](https://github.com/purduesigbots/pros-cli)\n- The VS Code plugin at [purduesigbots/pros-vsc](https://github.com/purduesigbots/pros-vsc)\n- The kernel [here](https://github.com/purduesigbots/pros)\n\nIf you find a problem with our documentation or tutorials, we have a repository for that, too, at [purduesigbots/pros-docs](https://github.com/purduesigbots/pros-docs).\n\n### Hey! Why can't I build the PROS kernel?\nThe PROS kernel depends on VEX's proprietary Software Development Kit (SDK), which is not publicly available.\n"
  },
  {
    "path": "STYLEGUIDE.md",
    "content": "# PROS Kernel Styleguide\n\nMaintaining a consistent coding style throughout the PROS kernel is important for future developers and students to learn about the PROS kernel. An inconsistent style can lead to confusion for everyone.\n\nThe PROS style is based on the Google C++ coding style (with some modifications noted a bit farther down), which allows `clang-format` to be used on every file and get correctly formatted code.\n\nSome additional notes follow:\n\n## File extensions\n- C source files will have the extension `.c`\n- C++ source files will have the extension `.cpp`\n- C header files will have the extension `.h`\n- C++ header files will have the extension `.hpp`\n\n## Naming Conventions\nThe PROS kernel follows these naming conventions:\n\n- Structures: `structname_s`:\n  - Structure members: these do not have any special convention, as you will never see a structure member without seeing that it is in a structure.\n- Enumerated types: `enumname_e`\n  - Enumerated type members: `E_ENUMNAME_MEMBERNAME`\n\n    For example, in `task_state_e`, you might have members such as `E_TASK_STATE_RUNNING`. Note that \"ENUMNAME\" can be multiple words, separated by underscores.\n- Function pointers: `funcname_fn`\n- Type definitions: append `_t` to the end of the structure/enum/function pointer name\n- C++ classes: these should be named in UpperCamelCase (also known as PascalCase)\n  - Class members: use lower_snake_case as normal, and use good sense when naming\n\nThis section provides only a brief overview of the naming conventions used in the PROS kernel. For more about the motivations behind these, see section 4 (Naming) below.\n\n## Documentation\nUse Doxygen-style comments as shown in the sections below.\n\n### File-Level Comments\nThese should be placed at the very start of a file.\n```c\n/**\n * \\file filename.h\n *\n * Short description of the file\n *\n * Extended description goes here. This should explain what the functions (etc)\n * in the file contains and a general description of what they do (no specifics,\n * but they should all have something in common anyway).\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n```\n\n### Enum-Level Comments\nThese should be placed immediately before the declaration of the enum.\n```c\n/*\n * Short description of the enum\n *\n * Extended description of the enum goes here. This should explain general usage\n * patterns for the enum.\n */\nenum my_enum {\n        E_MEMBER_0, // short description of member 0 goes here.\n        E_MEMBER_1, // these can be omitted if it's painfully obvious\n        E_MEMBER_2, // what each is for, or if there are just so many of\n        E_MEMBER_3, // them it doesn't make practical sense to\n        E_MEMBER_4  // document them all.\n}\n```\n_Note: in the above example, the comments describing each member of the `enum` run together and form complete sentences for effect. Please do not do this in your code!_\n\n### Function-Level Comments\nThese should be placed immediately before the function prototype they are describing in a header file.\n\n```c\n/**\n * Brief description of the function.\n *\n * An extended description of the function (if applicable).\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ERRNO_VALUE - Description of what causes this error\n *\n * \\param parameter_name\n *        The parameter description\n * \\param other_parameter_name\n *        The parameter description\n *\n * \\return The description of the return value, if this is longer than one line\n * then it will wrap around under the return statement\n */\n```\n\n### Inline Implementation Comments\nSometimes it is necessary to explain a particularly complex statement or series of statements. In this case, you should use inline comments, placed either immediately before or trailing the line or lines in question. In general, prefer placing such comments before offending lines, unless the comment is quite short. These comments should start with a `//` followed by a space. If they are placed trailing a line, they should be separated from the end of the line by one space.\n```c\nfloat Q_rsqrt(float number) {\n    long i;\n    float x2, y;\n    const float threehalfs = 1.5F;\n    x2 = number * 0.5F;\n    y  = number;\n    // perform some absolute magic on these numbers to get the inverse square root\n    i  = *(long*)&y; // evil floating point bit level hacking\n    i  = 0x5f3759df - (i >> 1); // what the [heck]?\n    y  = *(float*)&i;\n    y  = y * (threehalfs - (x2 * y * y)); // 1st iteration\n    //y  = y * (threehalfs - (x2 * y * y)); // 2nd iteration, this can be removed\n    return y;\n}\n```\n_Note: in the above example, there is a line of code that has been commented out. This is fine to do while testing, but any commented out lines of code should be removed before any merge into the master branch takes place, unless a compelling reason can be presented for them to remain._\n\nAll that being said, try to avoid code that is so complex that it requires inline comments for its purpose to be clear.\n\n#### Notes to Other Developers (Or Yourself)\nWhen writing code, it can sometimes be useful to leave notes to other developers or to yourself in the future. Examples of these include:\n\n- `// TODO: something that should be done`\n- `// NOTE: a note about something in the code`\n  - `// NB: this is the same as NOTE, but it's in Latin, so it's fancier`\n- `// HACK: used to describe a particularly nasty way of solving a problem-- could be improved, but it works for now`\n- `// FIXME: this code is broken and should be fixed`\n  - `// XXX: this is like FIXME, but it's worse (note that this has also been used in the same way as HACK, so you should use that or FIXME to clarify what is meant)`\n  - `// BUG: this is used to mark a line of code that is known to cause a bug. kind of like FIXME, though it may include some more specific information than FIXME would`\n\nWhile it is not strictly necessary to use these keywords in comments, they can be helpful-- modern editors (like Atom or VSCode) either highlight some of these keywords by default or have extensions that do. This can make certain comments stand out even more when developers are \"grepping\" the codebase (visually or otherwise).\n\n### Word Choice and Tense\n\nContent for the docs should follow the\n[Google Developer Documentation Style Guide](https://developers.google.com/style/),\nand the [API Reference Comments Section](https://developers.google.com/style/api-reference-comments)\nin particular.\n\nWhile the Google Style Guide should determine the vast majority of the docs' word choices,\nadditionally follow these content-specific guides:\n\n- All ports, Smart, ADI, or otherwise, should be referred to as a port, not a channel\n  or pin.\n- C++ functions should be written as their full function name, without removing the\n  `pros::` namespace (e.g. `pros::Motor::move`).\n- All enumerated values referenced in the code comments should be written as their\n  full name per the PROS Style Guide, not the `PROS_USE_SIMPLE_NAMES` version.\n  (e.g. `E_MOTOR_GEARSET_18`, not `E_MOTOR_GEARSET_18`).\n\n### C/C++ Format Guide\n\nThe PROS Coding style is based on the [Google C++ Coding Style](https://google.github.io/styleguide/cppguide.html) with the following modifications:\n\n```\nTabWidth: 2\nUseTab: ForIndentation\nColumnLimit: 120\nDerivePointerAlignment: false\nPointerAlignment: Left\nFixNamespaceComments: true\nReflowComments: true\nSortIncludes: true\nAccessModifierOffset: 0\nAllowShortBlocksOnASingleLine: false\nAllowShortCaseLabelsOnASingleLine: false\nAllowShortFunctionsOnASingleLine: Empty\n```\n"
  },
  {
    "path": "VSCode.md",
    "content": "Use the following include paths for intellisense completion:\n\n\"${env:PROS_TOOLCHAIN}/arm-none-eabi/include\",\n\"${env:PROS_TOOLCHAIN}/lib/gcc/arm-none-eabi/6.3.1/include\",\n\"${workspaceRoot}\",\n\"${workspaceRoot}/include\"\n\nAdd \"_INTELLISENSE\" to your defines to fix certain intellisense errors that will actually compile without issue"
  },
  {
    "path": "azure-build-libc.yaml",
    "content": "###############################################################################\n#\n# This pipeline builds newlib with the same flags as the official toolchain,\n# but adds -funwind-tables so we can have proper unwind info inside libc\n#\n###############################################################################\nvariables:\n  source_url: 'https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2018q4/gcc-arm-none-eabi-8-2018-q4-major-src.tar.bz2'\n  source_directory: 'gcc-arm-none-eabi-8-2018-q4-major'\n\njobs:\n- job: BuildLibc\n  pool:\n    vmImage: 'ubuntu-16.04'\n  timeoutInMinutes: 0\n  steps:\n    - bash: |\n        sudo apt-get install software-properties-common\n        sudo dpkg --add-architecture i386\n        sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa\n        sudo apt-get update\n        sudo apt-get install build-essential autoconf autogen bison dejagnu flex flip gawk git gperf gzip \\\n                             nsis openssh-client p7zip-full perl python-dev libisl-dev scons tcl tofrodos \\\n                             wget libncurses5-dev pv\n        sudo apt-get install gcc-arm-embedded\n      displayName: Install apt packages\n    - bash: |\n        curl -L $(source_url) -o $(source_directory).tar.bz2\n        pv -f $(source_directory).tar.bz2 | tar -xjf -\n      displayName: Download/extract arm-none-eabi-gcc source\n    - bash: |\n        sed -i '95s/TERM|\\\\/TERM|agent.jobstatus|\\\\/' ./build-common.sh\n        sed -i '302s/http:\\/\\/www.mr511.de\\/software\\//https:\\/\\/github.com\\/gnu-mcu-eclipse\\/files\\/raw\\/master\\/libs\\//' ./build-common.sh\n      displayName: Edit ./build-common.sh\n      workingDirectory: $(source_directory)\n    - bash: |\n        sed -i \"294s/.*/saveenvvar CFLAGS_FOR_TARGET '-g -O2 -ffunction-sections -fdata-sections -funwind-tables'/\" ./build-toolchain.sh\n        head -n 316 ./build-toolchain.sh > ./build-toolchain.sh\n      displayName: Edit ./build-toolchain.sh\n      workingDirectory: $(source_directory)\n    - bash: |\n        ./install-sources.sh --skip_steps=mingw32\n      displayName: Install sources\n      workingDirectory: $(source_directory)\n    - bash: |\n        ./build-prerequisites.sh --skip_steps=mingw32\n      displayName: Build prerequisites\n      workingDirectory: $(source_directory)\n    - bash: |\n        export CFLAGS_FOR_TARGET='-g -O2 -ffunction-sections -fdata-sections -funwind-tables'\n        export ROOT=`pwd`\n        mkdir -p $ROOT/build-native/newlib\n        pushd $ROOT/build-native/newlib\n        $ROOT/src/newlib/configure                                                                          \\\n          --build=\"`uname -m | sed 'y/XI/xi/'`\"-linux-gnu --host=\"`uname -m | sed 'y/XI/xi/'`\"-linux-gnu    \\\n          --target=arm-none-eabi                                                                            \\\n          --prefix=$ROOT/newlib                                                                             \\\n          --enable-newlib-io-long-long                                                                      \\\n          --enable-newlib-io-c99-formats                                                                    \\\n          --enable-newlib-register-fini                                                                     \\\n          --enable-newlib-retargetable-locking                                                              \\\n          --disable-newlib-supplied-syscalls                                                                \\\n          --disable-nls                                                                                     \\\n\n        make -j`grep ^processor /proc/cpuinfo|wc -l`\n        make install\n\n        ls -R $ROOT/newlib\n        ls -R $ROOT/build-native/newlib\n\n        cp $ROOT/newlib/arm-none-eabi/lib/thumb/v7-ar/libc.a $(Build.ArtifactStagingDirectory)\n        cp $ROOT/newlib/arm-none-eabi/lib/thumb/v7-ar/libm.a $(Build.ArtifactStagingDirectory)\n        ls $(Build.ArtifactStagingDirectory)\n\n        TARGET_LIBRARIES=`find $(Build.ArtifactStagingDirectory) -name \\*.a`\n        for target_lib in $TARGET_LIBRARIES ; do\n          echo Stripping $target_lib\n          arm-none-eabi-objcopy -R .comment -R .note -R .debug_info -R .debug_aranges -R .debug_pubnames -R .debug_pubtypes -R .debug_abbrev -R .debug_line -R .debug_str -R .debug_ranges -R .debug_loc $target_lib || true\n        done\n      displayName: Build toolchain\n      workingDirectory: $(source_directory)\n    - task: PublishPipelineArtifact@0\n      inputs:\n        artifactName: 'newlib'\n        targetPath: $(Build.ArtifactStagingDirectory)\n"
  },
  {
    "path": "azure-pipelines.yml",
    "content": "jobs:\n- job: BuildTemplate\n  variables:\n    toolchain_update: 13.3.rel1\n    toolchain: https://developer.arm.com/-/media/Files/downloads/gnu/$(toolchain_update)/binrel/arm-gnu-toolchain-$(toolchain_update)-x86_64-arm-none-eabi.tar.xz\n  pool:\n    vmImage: 'ubuntu-latest'\n  steps:\n  - task: InstallSSHKey@0\n    inputs:\n      sshKeySecureFile: id_sigbot_github_azure_devops\n      hostName: $(gh.knownhosts)\n      sshPublicKey: $(gh.publickey)\n  - checkout: self\n  - bash: |\n      curl -LSso toolchain.tar.xz $(toolchain)\n      tar -xJvf toolchain.tar.xz\n      echo \"##vso[task.prependpath]$(pwd)/arm-gnu-toolchain-$(toolchain_update)-x86_64-arm-none-eabi/bin\"\n    displayName: Install gcc-arm-embedded\n  - task: UsePythonVersion@0\n    inputs:\n      addToPath: true\n      versionSpec: '3.11.0'\n  - task: PipAuthenticate@1\n    inputs:\n      artifactFeeds: 'pros-cli'\n      # use official PyPi registry first and fall back to internal feed as needed\n      onlyAddExtraIndex: true\n  - bash: pip install pros-cli\n    displayName: Install CLI\n  - bash: |\n      make template\n      mkdir -p artifacts\n      cp template/*.zip artifacts\n    displayName: Build template\n  - bash: |\n      echo \"##vso[build.UpdateBuildNumber]`cat version`\"\n      echo \"##vso[task.setvariable variable=KernelVersion]`cat version`\"\n    displayName: Update Build Number\n  - bash: |\n      make\n    displayName: Build binaries\n  - task: PublishPipelineArtifact@0\n    inputs:\n      targetPath: artifacts\n      artifactName: template\n    condition: succeeded()\n  # - task: UniversalPackages@0\n  #   inputs:\n  #     command: publish\n  #     publishDirectory: artifacts\n  #     vstsFeedPublish: 'pros-depot-nightly'\n  #     vstsFeedPackagePublish: 'kernel'\n  #     versionOption: custom\n  #     versionPublish: $(KernelVersion)\n  #     packagePublishDescription: 'CI Build of Kernel'\n  #   condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/develop')))\n"
  },
  {
    "path": "common.mk",
    "content": "ARCHTUPLE=arm-none-eabi-\nDEVICE=VEX EDR V5\n\nMFLAGS=-mcpu=cortex-a9 -mfpu=neon-fp16 -mfloat-abi=hard -Os -g -mthumb\nCPPFLAGS=-D_POSIX_THREADS -D_UNIX98_THREAD_MUTEX_ATTRIBUTES -D_POSIX_TIMERS -D_POSIX_MONOTONIC_CLOCK\nGCCFLAGS=-ffunction-sections -fdata-sections -fdiagnostics-color -funwind-tables\n\n# Check if the llemu files in libvgl exist. If they do, define macros that the\n# llemu headers in the kernel repo can use to conditionally include the libvgl\n# versions\nifneq (,$(wildcard ./include/liblvgl/llemu.h))\n\tCPPFLAGS += -D_PROS_INCLUDE_LIBLVGL_LLEMU_H\nendif\nifneq (,$(wildcard ./include/liblvgl/llemu.hpp))\n\tCPPFLAGS += -D_PROS_INCLUDE_LIBLVGL_LLEMU_HPP\nendif\n\nWARNFLAGS+=-Wno-psabi\n\nSPACE := $() $()\nCOMMA := ,\n\nC_STANDARD?=gnu23\nCXX_STANDARD?=gnu++26\n\nDEPDIR := .d\n$(shell mkdir -p $(DEPDIR))\nDEPFLAGS = -MT $$@ -MMD -MP -MF $(DEPDIR)/$$*.Td\nMAKEDEPFOLDER = -$(VV)mkdir -p $(DEPDIR)/$$(dir $$(patsubst $(BINDIR)/%, %, $(ROOT)/$$@))\nRENAMEDEPENDENCYFILE = -$(VV)mv -f $(DEPDIR)/$$*.Td $$(patsubst $(SRCDIR)/%, $(DEPDIR)/%.d, $(ROOT)/$$<) && touch $$@\n\nLIBRARIES+=$(wildcard $(FWDIR)/*.a)\n# Cannot include newlib and libc because not all of the req'd stubs are implemented\nEXCLUDE_COLD_LIBRARIES+=$(FWDIR)/libc.a $(FWDIR)/libm.a\nCOLD_LIBRARIES=$(filter-out $(EXCLUDE_COLD_LIBRARIES), $(LIBRARIES))\nwlprefix=-Wl,$(subst $(SPACE),$(COMMA),$1)\nLNK_FLAGS=--gc-sections --start-group $(strip $(LIBRARIES)) -lgcc -lstdc++ --end-group -T$(FWDIR)/v5-common.ld --no-warn-rwx-segments --sort-section=alignment --sort-common\n\nASMFLAGS=$(MFLAGS) $(WARNFLAGS)\nCFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=$(C_STANDARD)\nCXXFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=$(CXX_STANDARD)\nLDFLAGS=$(MFLAGS) $(WARNFLAGS) -nostdlib $(GCCFLAGS)\nSIZEFLAGS=-d --common\nNUMFMTFLAGS=--to=iec --format %.2f --suffix=B\n\nAR:=$(ARCHTUPLE)ar\n# using arm-none-eabi-as generates a listing by default. This produces a super verbose output.\n# Using gcc accomplishes the same thing without the extra output\nAS:=$(ARCHTUPLE)gcc\nCC:=$(ARCHTUPLE)gcc\nCXX:=$(ARCHTUPLE)g++\nLD:=$(ARCHTUPLE)g++\nOBJCOPY:=$(ARCHTUPLE)objcopy\nSIZETOOL:=$(ARCHTUPLE)size\nREADELF:=$(ARCHTUPLE)readelf\nSTRIP:=$(ARCHTUPLE)strip\n\nifneq (, $(shell command -v gnumfmt 2> /dev/null))\n\tSIZES_NUMFMT:=| gnumfmt --field=-4 --header $(NUMFMTFLAGS)\nelse\nifneq (, $(shell command -v numfmt 2> /dev/null))\n\tSIZES_NUMFMT:=| numfmt --field=-4 --header $(NUMFMTFLAGS)\nelse\n\tSIZES_NUMFMT:=\nendif\nendif\n\nifneq (, $(shell command -v sed 2> /dev/null))\nSIZES_SED:=| sed -e 's/  dec/total/'\nelse\nSIZES_SED:=\nendif\n\nrwildcard=$(foreach d,$(filter-out $3,$(wildcard $1*)),$(call rwildcard,$d/,$2,$3)$(filter $(subst *,%,$2),$d))\n\n# Colors\nNO_COLOR=$(shell printf \"%b\" \"\\033[0m\")\nOK_COLOR=$(shell printf \"%b\" \"\\033[32;01m\")\nERROR_COLOR=$(shell printf \"%b\" \"\\033[31;01m\")\nWARN_COLOR=$(shell printf \"%b\" \"\\033[33;01m\")\nSTEP_COLOR=$(shell printf \"%b\" \"\\033[37;01m\")\nOK_STRING=$(OK_COLOR)[OK]$(NO_COLOR)\nDONE_STRING=$(OK_COLOR)[DONE]$(NO_COLOR)\nERROR_STRING=$(ERROR_COLOR)[ERRORS]$(NO_COLOR)\nWARN_STRING=$(WARN_COLOR)[WARNINGS]$(NO_COLOR)\nECHO=/bin/printf \"%s\\n\"\necho=@$(ECHO) \"$2$1$(NO_COLOR)\"\nechon=@/bin/printf \"%s\" \"$2$1$(NO_COLOR)\"\n\ndefine test_output_2\n@if test $(BUILD_VERBOSE) -eq $(or $4,1); then printf \"%s\\n\" \"$2\"; fi;\n@output=\"$$($2 2>&1)\"; exit=$$?;           \\\nif test 0 -ne $$exit; then                 \\\n  printf \"%s%s\\n\" \"$1\" \"$(ERROR_STRING)\";  \\\n  printf \"%s\\n\" \"$$output\";                \\\n  exit $$exit;                             \\\nelif test -n \"$$output\"; then              \\\n  printf \"%s%s\\n\" \"$1\" \"$(WARN_STRING)\";   \\\n  printf \"%s\\n\" \"$$output\";                \\\nelse                                       \\\n  printf \"%s%s\\n\" \"$1\" \"$3\";               \\\nfi;\nendef\n\ndefine test_output\n@output=$$($1 2>&1); exit=$$?;            \\\nif test 0 -ne $$exit; then                \\\n  printf \"%s\\n\" \"$(ERROR_STRING)\" $$?;    \\\n  printf \"%s\\n\" $$output;                 \\\n  exit $$exit;                            \\\nelif test -n \"$$output\"; then             \\\n  printf \"%s\\n\" \"$(WARN_STRING)\";         \\\n  printf \"%s\" $$output;                   \\\nelse                                      \\\n  printf \"%s\\n\" \"$2\";                     \\\nfi;\nendef\n\n# Makefile Verbosity\nifeq (\"$(origin VERBOSE)\", \"command line\")\nBUILD_VERBOSE = $(VERBOSE)\nendif\nifeq (\"$(origin V)\", \"command line\")\nBUILD_VERBOSE = $(V)\nendif\n\nifndef BUILD_VERBOSE\nBUILD_VERBOSE = 0\nendif\n\n# R is reduced (default messages) - build verbose = 0\n# V is verbose messages - verbosity = 1\n# VV is super verbose - verbosity = 2\nifeq ($(BUILD_VERBOSE), 0)\nR = @echo\nD = @\nVV = @\nendif\nifeq ($(BUILD_VERBOSE), 1)\nR = @echo\nD =\nVV = @\nendif\nifeq ($(BUILD_VERBOSE), 2)\nR =\nD =\nVV =\nendif\n\nINCLUDE=$(foreach dir,$(INCDIR) $(EXTRA_INCDIR),-iquote\"$(dir)\")\n\nASMSRC=$(foreach asmext,$(ASMEXTS),$(call rwildcard, $(SRCDIR),*.$(asmext), $1))\nASMOBJ=$(addprefix $(BINDIR)/,$(patsubst $(SRCDIR)/%,%.o,$(call ASMSRC,$1)))\nCSRC=$(foreach cext,$(CEXTS),$(call rwildcard, $(SRCDIR),*.$(cext), $1))\nCOBJ=$(addprefix $(BINDIR)/,$(patsubst $(SRCDIR)/%,%.o,$(call CSRC, $1)))\nCXXSRC=$(foreach cxxext,$(CXXEXTS),$(call rwildcard, $(SRCDIR),*.$(cxxext), $1))\nCXXOBJ=$(addprefix $(BINDIR)/,$(patsubst $(SRCDIR)/%,%.o,$(call CXXSRC,$1)))\n\nGETALLOBJ=$(sort $(call ASMOBJ,$1) $(call COBJ,$1) $(call CXXOBJ,$1))\n\nARCHIVE_TEXT_LIST=$(subst $(SPACE),$(COMMA),$(notdir $(basename $(LIBRARIES))))\n\nLDTIMEOBJ:=$(BINDIR)/_pros_ld_timestamp.o\n\nMONOLITH_BIN:=$(BINDIR)/monolith.bin\nMONOLITH_ELF:=$(basename $(MONOLITH_BIN)).elf\n\nHOT_BIN:=$(BINDIR)/hot.package.bin\nHOT_ELF:=$(basename $(HOT_BIN)).elf\nCOLD_BIN:=$(BINDIR)/cold.package.bin\nCOLD_ELF:=$(basename $(COLD_BIN)).elf\n\n# Check if USE_PACKAGE is defined to check for migration steps from purduesigbots/pros#87\nifndef USE_PACKAGE\n$(error Your Makefile must be migrated! Visit https://pros.cs.purdue.edu/v5/releases/kernel3.1.6.html to learn how)\nendif\n\nDEFAULT_BIN=$(MONOLITH_BIN)\nifeq ($(USE_PACKAGE),1)\nDEFAULT_BIN=$(HOT_BIN)\nendif\n\n-include $(wildcard $(FWDIR)/*.mk)\n\n.PHONY: all clean quick\n\nquick: $(DEFAULT_BIN)\n\nall: clean $(DEFAULT_BIN)\n\nclean::\n\t@echo Cleaning project\n\t-$Drm -rf $(BINDIR)\n\t-$Drm -rf $(DEPDIR)\n\nifeq ($(IS_LIBRARY),1)\nifeq ($(LIBNAME),libbest)\n$(error \"You should rename your library! libbest is the default library name and should be changed\")\nendif\n\nLIBAR=$(BINDIR)/$(LIBNAME).a\nTEMPLATE_DIR=$(ROOT)/template\n\nclean-template:\n\t@echo Cleaning $(TEMPLATE_DIR)\n\t-$Drm -rf $(TEMPLATE_DIR)\n\n$(LIBAR): $(call GETALLOBJ,$(EXCLUDE_SRC_FROM_LIB)) $(EXTRA_LIB_DEPS)\n\t-$Dmkdir $(BINDIR)\n\t-$Drm -f $@\n\t$(call test_output_2,Creating $@ ,$(AR) rcs $@ $^, $(DONE_STRING))\n\n.PHONY: library\nlibrary: $(LIBAR)\n\n.PHONY: template\ntemplate:: clean-template $(LIBAR)\n\t$Dpros c create-template . $(LIBNAME) $(VERSION) $(foreach file,$(TEMPLATE_FILES) $(LIBAR),--system \"$(file)\") --target v5 $(CREATE_TEMPLATE_FLAGS)\nendif\n\n# if project is a library source, compile the archive and link output.elf against the archive rather than source objects\nifeq ($(IS_LIBRARY),1)\nELF_DEPS+=$(filter-out $(call GETALLOBJ,$(EXCLUDE_SRC_FROM_LIB)), $(call GETALLOBJ,$(EXCLUDE_SRCDIRS)))\nLIBRARIES+=$(LIBAR)\nelse\nELF_DEPS+=$(call GETALLOBJ,$(EXCLUDE_SRCDIRS))\nendif\n\n$(MONOLITH_BIN): $(MONOLITH_ELF) $(BINDIR)\n\t$(call test_output_2,Creating $@ for $(DEVICE) ,$(OBJCOPY) $< -O binary -R .hot_init $@,$(DONE_STRING))\n\n$(MONOLITH_ELF): $(ELF_DEPS) $(LIBRARIES)\n\t$(call _pros_ld_timestamp)\n\t$(call test_output_2,Linking project with $(ARCHIVE_TEXT_LIST) ,$(LD) $(LDFLAGS) $(ELF_DEPS) $(LDTIMEOBJ) $(call wlprefix,-T$(FWDIR)/v5.ld $(LNK_FLAGS)) -o $@,$(OK_STRING))\n\t@echo Section sizes:\n\t-$(VV)$(SIZETOOL) $(SIZEFLAGS) $@ $(SIZES_SED) $(SIZES_NUMFMT)\n\n$(COLD_BIN): $(COLD_ELF)\n\t$(call test_output_2,Creating cold package binary for $(DEVICE) ,$(OBJCOPY) $< -O binary -R .hot_init $@,$(DONE_STRING))\n\n$(COLD_ELF): $(COLD_LIBRARIES)\n\t$(VV)mkdir -p $(dir $@)\n\t$(call test_output_2,Creating cold package with $(ARCHIVE_TEXT_LIST) ,$(LD) $(LDFLAGS) $(call wlprefix,--gc-keep-exported --whole-archive $^ -lstdc++ --no-whole-archive) $(call wlprefix,-T$(FWDIR)/v5.ld $(LNK_FLAGS) -o $@),$(OK_STRING))\n\t$(call test_output_2,Stripping cold package ,$(OBJCOPY) --strip-symbol=install_hot_table --strip-symbol=__libc_init_array --strip-symbol=_PROS_COMPILE_DIRECTORY --strip-symbol=_PROS_COMPILE_TIMESTAMP --strip-symbol=_PROS_COMPILE_TIMESTAMP_INT $@ $@, $(DONE_STRING))\n\t@echo Section sizes:\n\t-$(VV)$(SIZETOOL) $(SIZEFLAGS) $@ $(SIZES_SED) $(SIZES_NUMFMT)\n\n$(HOT_BIN): $(HOT_ELF) $(COLD_BIN)\n\t$(call test_output_2,Creating $@ for $(DEVICE) ,$(OBJCOPY) $< -O binary $@,$(DONE_STRING))\n\n$(HOT_ELF): $(COLD_ELF) $(ELF_DEPS)\n\t$(call _pros_ld_timestamp)\n\t$(call test_output_2,Linking hot project with $(COLD_ELF) and $(ARCHIVE_TEXT_LIST) ,$(LD) -nostartfiles $(LDFLAGS) $(call wlprefix,-R $<) $(filter-out $<,$^) $(LDTIMEOBJ) $(LIBRARIES) $(call wlprefix,-T$(FWDIR)/v5-hot.ld $(LNK_FLAGS) -o $@),$(OK_STRING))\n\t@printf \"%s\\n\" \"Section sizes:\"\n\t-$(VV)$(SIZETOOL) $(SIZEFLAGS) $@ $(SIZES_SED) $(SIZES_NUMFMT)\n\ndefine asm_rule\n$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1\n\t$(VV)mkdir -p $$(dir $$@)\n\t$$(call test_output_2,Compiled $$< ,$(AS) -c $(ASMFLAGS) -o $$@ $$<,$(OK_STRING))\nendef\n$(foreach asmext,$(ASMEXTS),$(eval $(call asm_rule,$(asmext))))\n\ndefine c_rule\n$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1\n$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 $(DEPDIR)/$(basename %).d\n\t$(VV)mkdir -p $$(dir $$@)\n\t$(MAKEDEPFOLDER)\n\t$$(call test_output_2,Compiled $$< ,$(CC) -c $(INCLUDE) -iquote\"$(INCDIR)/$$(dir $$*)\" $(CFLAGS) $(EXTRA_CFLAGS) $(DEPFLAGS) -o $$@ $$<,$(OK_STRING))\n\t$(RENAMEDEPENDENCYFILE)\nendef\n$(foreach cext,$(CEXTS),$(eval $(call c_rule,$(cext))))\n\ndefine cxx_rule\n$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1\n$(BINDIR)/%.$1.o: $(SRCDIR)/%.$1 $(DEPDIR)/$(basename %).d\n\t$(VV)mkdir -p $$(dir $$@)\n\t$(MAKEDEPFOLDER)\n\t$$(call test_output_2,Compiled $$< ,$(CXX) -c $(INCLUDE) -iquote\"$(INCDIR)/$$(dir $$*)\" $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(DEPFLAGS) -o $$@ $$<,$(OK_STRING))\n\t$(RENAMEDEPENDENCYFILE)\nendef\n$(foreach cxxext,$(CXXEXTS),$(eval $(call cxx_rule,$(cxxext))))\n\ndefine _pros_ld_timestamp\n$(VV)mkdir -p $(dir $(LDTIMEOBJ))\n@# Pipe a line of code defining _PROS_COMPILE_TOOLSTAMP and _PROS_COMPILE_DIRECTORY into GCC,\n@# which allows compilation from stdin. We define _PROS_COMPILE_DIRECTORY using a command line-defined macro\n@# which is the pwd | tail bit, which will truncate the path to the last 23 characters\n@# \n@# const int _PROS_COMPILE_TIMESTAMP_INT = $(( $(date +%s) - $(date +%z) * 3600 ))\n@# char const * const _PROS_COMPILE_TIEMSTAMP = __DATE__ \" \" __TIME__\n@# char const * const _PROS_COMPILE_DIRECTORY = \"$(shell pwd | tail -c23)\";\n@#\n@# The shell command $$(($$(date +%s)+($$(date +%-z)/100*3600))) fetches the current\n@# unix timestamp, and then adds the UTC timezone offset to account for time zones.\n\n$(call test_output_2,Adding timestamp ,echo 'const int _PROS_COMPILE_TIMESTAMP_INT = $(shell echo $$(($$(date +%s)+($$(date +%-z)/100*3600)))); char const * const _PROS_COMPILE_TIMESTAMP = __DATE__ \" \" __TIME__; char const * const _PROS_COMPILE_DIRECTORY = \"$(wildcard $(shell pwd | tail -c23))\";' | $(CC) -c -x c $(CFLAGS) $(EXTRA_CFLAGS) -o $(LDTIMEOBJ) -,$(OK_STRING))\nendef\n\n# these rules are for build-compile-commands, which just print out sysroot information\ncc-sysroot:\n\t@echo | $(CC) -c -x c $(CFLAGS) $(EXTRA_CFLAGS) --verbose -o /dev/null -\ncxx-sysroot:\n\t@echo | $(CXX) -c -x c++ $(CXXFLAGS) $(EXTRA_CXXFLAGS) --verbose -o /dev/null -\n\n$(DEPDIR)/%.d: ;\n.PRECIOUS: $(DEPDIR)/%.d\n\ninclude $(wildcard $(patsubst $(SRCDIR)/%,$(DEPDIR)/%.d,$(CSRC) $(CXXSRC)))"
  },
  {
    "path": "firmware/v5-common.ld",
    "content": "/* Define the sections, and where they are mapped in memory */\nSECTIONS\n{\n/* This will get stripped out before uploading, but we need to place code\n   here so we can at least link to it (install_hot_table) */\n.hot_init : {\n  KEEP (*(.hot_magic))\n  KEEP (*(.hot_init))\n} > HOT_MEMORY\n\n.text : {\n   KEEP (*(.vectors))\n   /* boot data should be exactly 32 bytes long */\n   *(.boot_data)\n   . = 0x20;\n   *(.boot)\n   . = ALIGN(64);\n   *(.freertos_vectors)\n   *(.text)\n   *(.text.*)\n   *(.gnu.linkonce.t.*)\n   *(.plt)\n   *(.gnu_warning)\n   *(.gcc_except_table)\n   *(.glue_7)\n   *(.glue_7t)\n   *(.vfp11_veneer)\n   *(.ARM.extab)\n   *(.gnu.linkonce.armextab.*)\n} > RAM\n\n.init : {\n   KEEP (*(.init))\n} > RAM\n\n.fini : {\n   KEEP (*(.fini))\n} > RAM\n\n.rodata : {\n   __rodata_start = .;\n   *(.rodata)\n   *(.rodata.*)\n   *(.gnu.linkonce.r.*)\n   __rodata_end = .;\n} > RAM\n\n.rodata1 : {\n   __rodata1_start = .;\n   *(.rodata1)\n   *(.rodata1.*)\n   __rodata1_end = .;\n} > RAM\n\n.sdata2 : {\n   __sdata2_start = .;\n   *(.sdata2)\n   *(.sdata2.*)\n   *(.gnu.linkonce.s2.*)\n   __sdata2_end = .;\n} > RAM\n\n.sbss2 : {\n   __sbss2_start = .;\n   *(.sbss2)\n   *(.sbss2.*)\n   *(.gnu.linkonce.sb2.*)\n   __sbss2_end = .;\n} > RAM\n\n.data : {\n   __data_start = .;\n   *(.data)\n   *(.data.*)\n   *(.gnu.linkonce.d.*)\n   *(.jcr)\n   *(.got)\n   *(.got.plt)\n   __data_end = .;\n} > RAM\n\n.data1 : {\n   __data1_start = .;\n   *(.data1)\n   *(.data1.*)\n   __data1_end = .;\n} > RAM\n\n.got : {\n   *(.got)\n} > RAM\n\n.ctors : {\n   __CTOR_LIST__ = .;\n   ___CTORS_LIST___ = .;\n   KEEP (*crtbegin.o(.ctors))\n   KEEP (*(EXCLUDE_FILE(*crtend.o) .ctors))\n   KEEP (*(SORT(.ctors.*)))\n   KEEP (*(.ctors))\n   __CTOR_END__ = .;\n   ___CTORS_END___ = .;\n} > RAM\n\n.dtors : {\n   __DTOR_LIST__ = .;\n   ___DTORS_LIST___ = .;\n   KEEP (*crtbegin.o(.dtors))\n   KEEP (*(EXCLUDE_FILE(*crtend.o) .dtors))\n   KEEP (*(SORT(.dtors.*)))\n   KEEP (*(.dtors))\n   __DTOR_END__ = .;\n   ___DTORS_END___ = .;\n} > RAM\n\n.fixup : {\n   __fixup_start = .;\n   *(.fixup)\n   __fixup_end = .;\n} > RAM\n\n.eh_frame : {\n   *(.eh_frame)\n} > RAM\n\n.eh_framehdr : {\n   __eh_framehdr_start = .;\n   *(.eh_framehdr)\n   __eh_framehdr_end = .;\n} > RAM\n\n.gcc_except_table : {\n   *(.gcc_except_table)\n} > RAM\n\n.ARM.exidx : {\n   __exidx_start = .;\n   *(.ARM.exidx*)\n   *(.gnu.linkonce.armexidix.*.*)\n   __exidx_end = .;\n} > RAM\n\n.preinit_array : {\n   __preinit_array_start = .;\n   KEEP (*(SORT(.preinit_array.*)))\n   KEEP (*(.preinit_array))\n   __preinit_array_end = .;\n} > RAM\n\n.init_array : {\n   __init_array_start = .;\n   KEEP (*(SORT(.init_array.*)))\n   KEEP (*(.init_array))\n   __init_array_end = .;\n} > RAM\n\n.fini_array : {\n   __fini_array_start = .;\n   KEEP (*(SORT(.fini_array.*)))\n   KEEP (*(.fini_array))\n   __fini_array_end = .;\n} > RAM\n\n/DISCARD/ : {\n  *(.ARM.attributes*)\n}\n\n.sdata : {\n   __sdata_start = .;\n   *(.sdata)\n   *(.sdata.*)\n   *(.gnu.linkonce.s.*)\n   __sdata_end = .;\n} > RAM\n\n.sbss (NOLOAD) : {\n   __sbss_start = .;\n   *(.sbss)\n   *(.sbss.*)\n   *(.gnu.linkonce.sb.*)\n   __sbss_end = .;\n} > RAM\n\n.tdata : {\n   __tdata_start = .;\n   *(.tdata)\n   *(.tdata.*)\n   *(.gnu.linkonce.td.*)\n   __tdata_end = .;\n} > RAM\n\n.tbss : {\n   __tbss_start = .;\n   *(.tbss)\n   *(.tbss.*)\n   *(.gnu.linkonce.tb.*)\n   __tbss_end = .;\n} > RAM\n\n.bss (NOLOAD) : {\n   __bss_start = .;\n   *(.bss)\n   *(.bss.*)\n   *(.gnu.linkonce.b.*)\n   __bss_end = .;\n} > RAM\n\n_SDA_BASE_ = __sdata_start + ((__sbss_end - __sdata_start) / 2 );\n\n_SDA2_BASE_ = __sdata2_start + ((__sbss2_end - __sdata2_start) / 2 );\n\n/* Stack section\n   provides __stack for the partner SDK initialization (vexMain).\n   This prevents the stack from being placed in .bss, which would\n   cause corruption of variables at the end of .bss (see issue #783).\n   FreeRTOS task stacks are dynamically allocated separately. */\n.stack (NOLOAD) : ALIGN(8) {\n   _stack_end = .;\n   . += _STACK_SIZE;\n   __stack = .;\n   _stack_start = .;\n} > RAM\n\n.heap (NOLOAD) : {\n   . = ALIGN(16);\n   _heap = .;\n   HeapBase = .;\n   _heap_start = .;\n   . += _HEAP_SIZE;\n   _heap_end = .;\n   HeapLimit = .;\n} > HEAP\n\n_end = .;\n}\n"
  },
  {
    "path": "firmware/v5-hot.ld",
    "content": "/* This stack is used during initialization, but FreeRTOS tasks have their own\n   stack allocated in BSS or Heap (kernel tasks in FreeRTOS .bss heap; user tasks\n   in standard heap) */\n_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x2000;\n\n_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x02E00000;  /* ~48 MB */\n\n/* Define Memories in the system */\nstart_of_cold_mem = 0x03800000;\n_COLD_MEM_SIZE = 0x04800000;\nend_of_cold_mem = start_of_cold_mem + _COLD_MEM_SIZE;\n\nstart_of_hot_mem = 0x07800000;\n_HOT_MEM_SIZE = 0x00800000;\nend_of_hot_mem = start_of_hot_mem + _HOT_MEM_SIZE;\n\nMEMORY\n{\n   /* user code  72M */\n   COLD_MEMORY : ORIGIN = start_of_cold_mem, LENGTH = _COLD_MEM_SIZE /* Just under 19 MB */\n   HEAP : ORIGIN = 0x04A00000, LENGTH = _HEAP_SIZE\n   HOT_MEMORY : ORIGIN = start_of_hot_mem, LENGTH = _HOT_MEM_SIZE  /* Just over 8 MB */\n}\n\nREGION_ALIAS(\"RAM\", HOT_MEMORY);\n\nENTRY(install_hot_table)\n"
  },
  {
    "path": "firmware/v5.ld",
    "content": "/* This stack is used during initialization, but FreeRTOS tasks have their own\n   stack allocated in BSS or Heap (kernel tasks in FreeRTOS .bss heap; user tasks\n   in standard heap) */\n_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x2000;\n\n_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x02E00000;  /* ~48 MB */\n\n/* Define Memories in the system */\nstart_of_cold_mem = 0x03800000;\n_COLD_MEM_SIZE = 0x04800000;\nend_of_cold_mem = start_of_cold_mem + _COLD_MEM_SIZE;\n\nstart_of_hot_mem = 0x07800000;\n_HOT_MEM_SIZE = 0x00800000;\nend_of_hot_mem = start_of_hot_mem + _HOT_MEM_SIZE;\n\nMEMORY\n{\n   /* user code  72M */\n   COLD_MEMORY : ORIGIN = start_of_cold_mem, LENGTH = _COLD_MEM_SIZE /* Just under 19 MB */\n   HEAP : ORIGIN = 0x04A00000, LENGTH = _HEAP_SIZE\n   HOT_MEMORY : ORIGIN = start_of_hot_mem, LENGTH = _HOT_MEM_SIZE  /* Just over 8 MB */\n}\n\nREGION_ALIAS(\"RAM\", COLD_MEMORY);\n\nENTRY(vexStartup)\n"
  },
  {
    "path": "include/api.h",
    "content": "/**\n * \\file api.h\n *\n * PROS API header provides high-level user functionality\n *\n * Contains declarations for use by typical VEX programmers using PROS.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#ifndef _PROS_API_H_\n#define _PROS_API_H_\n\n#ifdef __cplusplus\n#include <cerrno>\n#include <cmath>\n#include <cstddef>\n#include <cstdint>\n#include <cstdio>\n#include <cstdlib>\n#include <iostream>\n#else /* (not) __cplusplus */\n#include <errno.h>\n#include <math.h>\n#include <stdbool.h>\n#include <stddef.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <unistd.h>\n#endif /* __cplusplus */\n\n#include \"pros/adi.h\"\n#include \"pros/ai_vision.h\"\n#include \"pros/colors.h\"\n#include \"pros/device.h\"\n#include \"pros/distance.h\"\n#include \"pros/error.h\"\n#include \"pros/ext_adi.h\"\n#include \"pros/gps.h\"\n#include \"pros/imu.h\"\n#include \"pros/link.h\"\n#include \"pros/llemu.h\"\n#include \"pros/misc.h\"\n#include \"pros/motors.h\"\n#include \"pros/optical.h\"\n#include \"pros/rotation.h\"\n#include \"pros/rtos.h\"\n#include \"pros/screen.h\"\n#include \"pros/vision.h\"\n\n#ifdef __cplusplus\n#include \"pros/adi.hpp\"\n#include \"pros/ai_vision.hpp\"\n#include \"pros/colors.hpp\"\n#include \"pros/device.hpp\"\n#include \"pros/distance.hpp\"\n#include \"pros/gps.hpp\"\n#include \"pros/imu.hpp\"\n#include \"pros/link.hpp\"\n#include \"pros/llemu.hpp\"\n#include \"pros/misc.hpp\"\n#include \"pros/motor_group.hpp\"\n#include \"pros/motors.hpp\"\n#include \"pros/optical.hpp\"\n#include \"pros/rotation.hpp\"\n#include \"pros/rtos.hpp\"\n#include \"pros/screen.hpp\"\n#include \"pros/vision.hpp\"\n#endif\n\n#endif  // _PROS_API_H_\n"
  },
  {
    "path": "include/common/cobs.h",
    "content": "/**\n * \\file common/cobs.h\n *\n * Consistent Overhead Byte Stuffing header\n *\n * See common/cobs.c for discussion\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n#include <stdint.h>\n\n#define COBS_ENCODE_MEASURE_MAX(src_len) ((src_len) + (((src_len) + 253) / 254))\n\n/**\n * Encodes src in the Consistent Overhead Byte Stuffing algorithm, and writes\n * the result to dest. dest must be sufficiently long. use cobs_encode_measure()\n * to compute the size of the buff or use COBS_ENCODE_MEASURE_MAX(src_len) macro\n * to get the max buffer size needed (e.g. for static allocation)\n *\n * \\param[out] dest\n *             The location to write the stuffed data to\n * \\param[in] src\n *            The location of the incoming data\n * \\param src_len\n *        The length of the source data\n * \\param prefix\n *        The four character stream identifier\n *\n * \\return The number of bytes written\n */\nint cobs_encode(uint8_t* restrict dest, const uint8_t* restrict src, const size_t src_len, const uint32_t prefix);\n\n/**\n * Same as cobs_encode() but doesn't write to an output buffer. Used to\n * determine how much space is needed for src.\n *\n * \\param[in] src\n *            The location of the incoming data\n * \\param src_len\n *        The length of the source data\n * \\param prefix\n *        The four character stream identifier\n *\n * \\return The size of src when encoded\n */\nsize_t cobs_encode_measure(const uint8_t* restrict src, const size_t src_len, const uint32_t prefix);\n"
  },
  {
    "path": "include/common/gid.h",
    "content": "/**\n * \\file common/gid.h\n *\n * Globally unique Identifer facility header\n *\n * See common/gid.c for discussion\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n#include <stdint.h>\n#include \"api.h\"\n\nstruct gid_metadata {\n\tuint32_t* const bitmap;    // a constant pointer to a bitmap\n\tconst size_t max;          // Maximum gid value\n\tconst size_t reserved;     // first n GIDs may be reserved, at most 32, but at least 1\n\tconst size_t bitmap_size;  // Cached number of uint32_t's used to map gid_max.\n\t                           // Use gid_size_to_words to compute\n\n\t// internal usage to ensure that GIDs get delegated linearly before wrapping\n\t// around back to 0\n\tsize_t _cur_val;\n\tmutex_t _lock;\n};\n\n#ifndef UINT32_WIDTH\n#define UINT32_WIDTH 32\n#endif\n\n/**\n * convert the maximum number of gids into a number of words needed to store the\n * bitmap\n */\n#define gid_size_to_words(size) (((size) + UINT32_WIDTH - 1) / UINT32_WIDTH)\n\n/**\n * Initializes a gid_metadata structure by \"freeing\" all IDs in the bitmap\n *\n * \\param[in] metadata\n *            The gid_metadata structure to initialize\n */\nvoid gid_init(struct gid_metadata* const metadata);\n\n/**\n * Allocates a gid from the gid structure and returns it.\n *\n * \\param[in] metadata\n *            The gid_metadata to record to the gid structure\n *\n * \\return The gid, or 0 if there are no more gids left.\n */\nuint32_t gid_alloc(struct gid_metadata* const metadata);\n\n/**\n * Frees the gid specified from the structure.\n *\n * \\param[in] metadata\n *            The gid_metadata to free from the gid structure\n * \\param id\n *        The gid value indicating the metadata's position in the gid structure\n */\nvoid gid_free(struct gid_metadata* const metadata, uint32_t id);\n\n/**\n * Checks if the gid specified is allocated.\n *\n * \\param[in] metadata\n *            The gid_metadata to check\n * \\param id\n *        The gid value indicating the metadata's position in the gid structure\n *\n * \\return True if the given metadata/id combo is present in the gid structure,\n * false otherwise.\n */\nbool gid_check(struct gid_metadata* metadata, uint32_t id);\n"
  },
  {
    "path": "include/common/linkedlist.h",
    "content": "/*\n * \\file common/linkedlist.h\n *\n * Linked list implementation for internal use\n *\n * This file defines a linked list implementation that operates on the FreeRTOS\n * heap, and is able to generically store function pointers and data\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\ntypedef void (*generic_fn_t)(void);\n\ntypedef struct ll_node_s {\n\tunion {\n\t\tgeneric_fn_t func; // Note: a list should not contain both data/funcs\n\t\tvoid* data;\n\t} payload;\n\tstruct ll_node_s* next;\n} ll_node_s_t;\n\ntypedef struct {\n\tll_node_s_t* head;\n} linked_list_s_t;\n\n/**\n * Initialize a linked list node storing an arbitrary function pointer\n *\n * \\param func\n *        Function pointer to store in the node\n *\n * \\return A linked list node that stores a function pointer\n */\nll_node_s_t* linked_list_init_func_node(generic_fn_t func);\n\n/**\n * Initialize a linked list node storing a pointer to arbitrary data\n *\n * \\param[in] data\n *            Pointer to data\n *\n * \\return A linked list node that stores some data\n */\nll_node_s_t* linked_list_init_data_node(void* data);\n\n/**\n * Initialize a linked list\n *\n * \\return An initialized linked list\n */\nlinked_list_s_t* linked_list_init();\n\n/**\n * Prepend a node containing a function pointer to a linked list\n *\n * If the provided linked list is NULL, it will be initialized first.\n *\n * \\param[in, out] list\n *                 Linked list to which the node will be prepended\n * \\param func\n *        Function pointer with which to initialize the node\n */\nvoid linked_list_prepend_func(linked_list_s_t* list, generic_fn_t func);\n\n/**\n * Prepend a node containing some data to a linked list\n *\n * If the provided linked list is NULL, it will be initialized first.\n *\n * \\param[in, out] list\n *                 Linked list to which the node will be prepended\n * \\param[in] data\n *            Data with which to initialize the node\n */\nvoid linked_list_prepend_data(linked_list_s_t* list, void* data);\n\n/**\n * Append a node containing a function pointer to a linked list\n *\n * If the provided linked list is NULL, it will be initialized first.\n *\n * \\param[in, out] list\n *                 Linked list to which the node will be appended\n * \\param func\n *        Function pointer with which to initialize the node\n */\nvoid linked_list_append_func(linked_list_s_t* list, generic_fn_t func);\n\n/**\n * Removes the node containing the given function pointer from the linked list\n *\n * \\param[in, out] list\n *                 Linked list from which the node will be removed\n * \\param func\n *        Function pointer to be removed\n */\nvoid linked_list_remove_func(linked_list_s_t* list, generic_fn_t func);\n\n/**\n * Append a node containing some data to a linked list\n *\n * If the provided linked list is NULL, it will be initialized first.\n *\n * \\param[in, out] list\n *                 Linked list to which the node will be appended\n * \\param data\n *        Data with which to initialize the node\n */\nvoid linked_list_append_data(linked_list_s_t* list, void* data);\n\n/**\n * Remove the node containing the given data from the linked list\n *\n * \\param[in, out] list\n *                 Linked list from which the node will be removed\n * \\param data\n *        Data to be removed\n */\nvoid linked_list_remove_data(linked_list_s_t* list, void* data);\n\ntypedef void (*linked_list_foreach_fn_t)(ll_node_s_t*, void*);\n\n/**\n * Perform a function on every node in a linked list\n *\n * If the provided linked list is NULL, the function will terminate.\n *\n * \\param list\n *        Linked list upon which to perform the function\n * \\param cb\n *        Pointer to a callback function that will be provided the current node\n *        as well as some extra data\n * \\param extra_data\n *        Extra data to pass to the callback function\n */\nvoid linked_list_foreach(linked_list_s_t* list, linked_list_foreach_fn_t, void* extra_data);\n\n/**\n * Frees a linked_list_s_t, making it no longer a valid list. This does not free any\n * internal data, only the linekd_list structure.\n *\n * \\param list\n *\t\t\t\tList to free\n */\nvoid linked_list_free(linked_list_s_t* list);\n"
  },
  {
    "path": "include/common/set.h",
    "content": "/**\n * \\file common/set.h\n *\n * Kernel-allocated thread-safe simple sets header\n *\n * See common/set.c for discussion\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n#include <stdbool.h>\n#include <stddef.h>\n#include <stdint.h>\n#include \"kapi.h\"\n\nstruct set {\n\tuint32_t* arr;\n\tsize_t used;\n\tsize_t size;\n\tstatic_sem_s_t mtx_buf;\n\tmutex_t mtx;\n};\n\n/**\n * Initializes a a set.\n *\n * \\param set\n *        A pointer to a set structure\n */\nvoid set_initialize(struct set* const set);\n\n/**\n * Adds item to the set if it didn't already exist\n *\n * \\param set\n *        A pointer to the set structure\n * \\param item\n *        Item to add to the set\n *\n * \\return Ttrue if the item was added to the set or was already present\n */\nbool set_add(struct set* const set, uint32_t item);\n\n/**\n * Removes an item from the set\n *\n * \\param set\n *        A pointer to the set structure\n * \\param item\n *        The item to remove\n *\n * \\return True if the item was removed (or was already not present)\n */\nbool set_rm(struct set* const set, uint32_t item);\n\n/**\n * Checks if the set contains an item\n *\n * \\param set\n *        A pointer to the set structure\n * \\param item\n *        The item to check\n *\n * \\return True if the item is in the set\n */\nbool set_contains(struct set* set, uint32_t item);\n\n/**\n * Checks if the list contains an item\n *\n * \\param list\n *        A pointer to a list of words\n * \\param size\n *        The number of items in the list\n * \\param item\n *        The item to check\n *\n * \\return True if the item is in the list\n */\nbool list_contains(uint32_t const* const list, const size_t size, const uint32_t item);\n"
  },
  {
    "path": "include/common/string.h",
    "content": "/**\n * \\file common/string.h\n *\n * Extra string functions header\n *\n * See common/string.c for discussion\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n/**\n * strdup but uses the kernel heap\n *\n * \\param s\n *        Pointer to the string to duplicate\n *\n * \\return The duplicate string\n */\nchar* kstrdup(const char* s);\n\n/**\n * strndup but uses the kernel heap\n *\n * \\param s\n *        Pointer to the string to duplicate\n * \\param n\n *        The number of characters to duplicate\n *\n * \\return The duplicate string\n */\nchar* kstrndup(const char* s, size_t n);\n"
  },
  {
    "path": "include/kapi.h",
    "content": "/**\n * \\file kapi.h\n *\n * Kernel API header\n *\n * Contains additional declarations for use internally within kernel\n * development. This file includes the FreeRTOS header, which allows for\n * creation of statically allocated FreeRTOS primitives like tasks, semaphores,\n * and queues.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n#include \"api.h\"\n#include \"pros/apix.h\"\n#include \"rtos/FreeRTOS.h\"\n#include \"rtos/stream_buffer.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#define task_t pros::task_t\n#define task_fn_t pros::task_fn_t\n#define mutex_t pros::mutex_t\n#define sem_t pros::c::sem_t\n#define queue_t pros::c::queue_t\n#endif\n\n#define KDBG_FILENO 3\n\n#define warn_printf(fmt, ...) dprintf(STDERR_FILENO, \"%s:%d -- \" fmt \"\\n\", __FILE__, __LINE__, ##__VA_ARGS__)\n#define warn_wprint(str) wprintf(\"%s\", str)\n\n#define kprintf(fmt, ...) dprintf(KDBG_FILENO, \"%s:%d -- \" fmt \"\\n\", __FILE__, __LINE__, ##__VA_ARGS__)\n#define kprint(str) kprintf(\"%s\", str)\n\n#ifndef PROS_RELEASING\n#define kassert(cond)                     \\\n\tdo {                                    \\\n\t\tif (!(cond)) {                        \\\n\t\t\tkprint(\"Assertion failed: \" #cond); \\\n\t\t}                                     \\\n\t} while (0)\n#else\n#define kassert(cond)\n#endif\n\ntypedef uint32_t task_stack_t;\n\n/**\n * Suspends the scheduler without disabling interrupts. context switches will\n * not occur while the scheduler is suspended. RTOS ticks that occur while the\n * scheduler is suspended will be held pending until the scheduler has been\n * unsuspended with rtos_resume_all()\n *\n * When used correctly, this function ensures that operations occur atomically\n * w.r.t. multitasking. Functions like task_delay, queue_send, and other\n * functions MUST NOT be called while the scheduler is disabled.\n */\nvoid rtos_suspend_all(void);\n\n/**\n * Resumes the scheduler. It does not resume unsuspended tasks that were\n * previously suspended by task_suspend.\n *\n * if(rtos_resume_all()) {\n *     task_delay(0); // force context switch\n * }\n * \\return True if a context switch is necessary.\n */\nint32_t rtos_resume_all(void);\n\n/**\n * Creates a task using statically allocated buffers. All tasks used by the PROS\n * system must use statically allocated buffers.\n * This function uses the following values of errno when an error state is\n * reached:\n * ENOMEM - The stack cannot be used as the TCB was not created.\n *\n * \\param function\n *        Pointer to the task entry function\n * \\param parameters\n *        Pointer to memory that will be used as a parameter for the task being\n *        created. This memory should not typically come from stack, but rather\n *        from dynamically (i.e., malloc'd) or statically allocated memory.\n * \\param prio\n *        The priority at which the task should run.\n *        TASK_PRIO_DEFAULT plus/minus 1 or 2 is typically used.\n * \\param stack_depth\n *        The number of words (i.e. 4 * stack_depth) available on the task's\n *        stack. TASK_STACK_DEPTH_DEFAULT is typically sufficienct.\n * \\param name\n *        A descriptive name for the task.  This is mainly used to facilitate\n *        debugging. The name may be up to 32 characters long.\n *\n * \\return A handle by which the newly created task can be referenced. If an\n * error occurred, NULL will be returned and errno can be checked for hints as\n * to why task_create failed.\n */\ntask_t task_create_static(task_fn_t task_code, void* const param, uint32_t priority, const size_t stack_size,\n                          const char* const name, task_stack_t* const stack_buffer, static_task_s_t* const task_buffer);\n\n/**\n * Creates a statically allocated mutex.\n *\n * All FreeRTOS primitives must be created statically if they are required for\n * operation of the kernel.\n *\n * \\param[out] mutex_buffer\n *             A buffer to store the mutex in\n *\n * \\return A handle to a newly created mutex. If an error occurred, NULL will be\n * returned and errno can be checked for hints as to why mutex_create failed.\n */\nmutex_t mutex_create_static(static_sem_s_t* mutex_buffer);\n\n/**\n * Creates a statically allocated semaphore.\n *\n * All FreeRTOS primitives must be created statically if they are required for\n * operation of the kernel.\n *\n * \\param max_count\n *        The maximum count value that can be reached.\n * \\param init_count\n *        The initial count value assigned to the new semaphore.\n * \\param[out] semaphore_buffer\n *             A buffer to store the semaphore in\n *\n * \\return A newly created semaphore. If an error occurred, NULL will be\n * returned and errno can be checked for hints as to why sem_create failed.\n */\nsem_t sem_create_static(uint32_t max_count, uint32_t init_count, static_sem_s_t* semaphore_buffer);\n\n/**\n * Creates a statically allocated queue.\n *\n * All FreeRTOS primitives must be created statically if they are required for\n * operation of the kernel.\n *\n * \\param length\n *        The maximum number of items that the queue can contain.\n * \\param item_size\n *        The number of bytes each item in the queue will require.\n * \\param[out] storage_buffer\n *             A memory location for data storage\n * \\param[out] queue_buffer\n *             A buffer to store the queue in\n *\n * \\return A handle to a newly created queue, or NULL if the queue cannot be\n * created.\n */\nqueue_t queue_create_static(uint32_t length, uint32_t item_size, uint8_t* storage_buffer,\n                            static_queue_s_t* queue_buffer);\n\n\n/**\n * Display a fatal error to the built-in LCD/touch screen.\n *\n * This function is intended to be used when the integrity of the RTOS cannot be\n * trusted. No thread-safety mechanisms are used and this function only relies\n * on the use of the libv5rts.\n *\n * \\param[in] text\n *            The text string to display to the screen\n */\nvoid display_fatal_error(const char* text);\n\n/**\n * Prints hex characters to the terminal.\n *\n * \\param[in] s\n *            The array of hex characters to print\n * \\param len\n *        The number of hex characters to print\n */\nvoid kprint_hex(uint8_t* s, size_t len);\n\nint32_t xTaskGetSchedulerState();\n#define taskSCHEDULER_SUSPENDED ((int32_t)0)\n#define taskSCHEDULER_NOT_STARTED ((int32_t)1)\n#define taskSCHEDULER_RUNNING ((int32_t)2)\n\n#ifdef __cplusplus\n#undef task_t\n#undef task_fn_t\n#undef mutex_t\n}\n#endif\n"
  },
  {
    "path": "include/main.h",
    "content": "/**\n * \\file main.h\n *\n * Contains common definitions and header files used throughout your PROS\n * project.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#ifndef _PROS_MAIN_H_\n#define _PROS_MAIN_H_\n\n/**\n * If defined, some commonly used enums will have preprocessor macros which give\n * a shorter, more convenient naming pattern. If this isn't desired, simply\n * comment the following line out.\n *\n * For instance, E_CONTROLLER_MASTER has a shorter name: CONTROLLER_MASTER.\n * E_CONTROLLER_MASTER is pedantically correct within the PROS styleguide, but\n * not convenient for most student programmers.\n */\n#define PROS_USE_SIMPLE_NAMES\n\n/**\n * If defined, C++ literals will be available for use. All literals are in the\n * pros::literals namespace.\n *\n * For instance, you can do `4_mtr = 50` to set motor 4's target velocity to 50\n */\n#define PROS_USE_LITERALS\n\n#include \"api.h\"\n\n/**\n * You should add more #includes here\n */\n//#include \"okapi/api.hpp\"\n\n/**\n * If you find doing pros::Motor() to be tedious and you'd prefer just to do\n * Motor, you can use the namespace with the following commented out line.\n *\n * IMPORTANT: Only the okapi or pros namespace may be used, not both\n * concurrently! The okapi namespace will export all symbols inside the pros\n * namespace.\n */\n// using namespace pros;\n// using namespace pros::literals;\n// using namespace okapi;\n\n/**\n * Prototypes for the competition control tasks are redefined here to ensure\n * that they can be called from user code (i.e. calling autonomous from a\n * button press in opcontrol() for testing purposes).\n */\n#ifdef __cplusplus\nextern \"C\" {\n#endif\nvoid autonomous(void);\nvoid initialize(void);\nvoid disabled(void);\nvoid competition_initialize(void);\nvoid opcontrol(void);\n#ifdef __cplusplus\n}\n#endif\n\n#ifdef __cplusplus\n/**\n * You can add C++-only headers here\n */\n//#include <iostream>\n#endif\n\n#endif  // _PROS_MAIN_H_\n"
  },
  {
    "path": "include/pros/abstract_motor.hpp",
    "content": "/**\n * \\file abstract_motor.hpp\n * \\ingroup cpp-abstract-motor\n *\n * Contains prototypes for AbstractMotor, the abstract base class of both\n * motors and motor groups. Abstract motors cannot be directly constructed, but\n * you can use motors and motor groups as abstract motors.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#ifndef _PROS_ABSTRACT_MOTORS_HPP_\n#define _PROS_ABSTRACT_MOTORS_HPP_\n\n#include <cstdint>\n#include <iostream>\n\n#include \"pros/device.hpp\"\n#include \"pros/motors.h\"\n#include \"rtos.hpp\"\n\nnamespace pros {\ninline namespace v5 {\n\n/**\n * \\enum MotorBrake\n * Indicates the current 'brake mode' of a motor.\n */\nenum class MotorBrake {\n\tcoast = 0, ///< Motor coasts when stopped, traditional behavior\n\tbrake = 1, ///< Motor brakes when stopped\n\thold = 2, ///< Motor actively holds position when stopped\n\tinvalid = INT32_MAX ///< Invalid brake mode\n};\n\n/**\n * \\enum MotorEncoderUnits\n * Indicates the units used by the motor encoders.\n */\nenum class MotorEncoderUnits {\n\tdegrees = 0, ///< Position is recorded as angle in degrees as a floating point number\n\tdeg = 0, ///< Position is recorded as angle in degrees as a floating point number\n\trotations = 1, ///< Position is recorded as angle in rotations as a floating point number\n\tcounts = 2, ///< Position is recorded as raw encoder ticks as a whole number\n\tinvalid = INT32_MAX ///< Invalid motor encoder units\n};\n\n// Alias for MotorEncoderUnits\nusing MotorUnits = MotorEncoderUnits;\n\nenum class MotorGears {\n\tratio_36_to_1 = 0, ///< 36:1, 100 RPM, Red gear set\n\tred = ratio_36_to_1, ///< 36:1, 100 RPM, Red gear set\n\trpm_100 = ratio_36_to_1, ///< 36:1, 100 RPM, Red gear set\n\tratio_18_to_1 = 1, ///< 18:1, 200 RPM, Green gear set\n\tgreen = ratio_18_to_1, ///< 18:1, 200 RPM, Green gear set\n\trpm_200 = ratio_18_to_1, ///< 18:1, 200 RPM, Green gear set\n\tratio_6_to_1 = 2, ///< 6:1, 600 RPM, Blue gear set\n\tblue = ratio_6_to_1, ///< 6:1, 600 RPM, Blue gear set\n\trpm_600 = ratio_6_to_1, ///< 6:1, 600 RPM, Blue gear set\n\tinvalid = INT32_MAX ///< Error return code\n};\n\n/**\n * \\enum MotorType\n * Indicates the type of a motor\n */\nenum class MotorType {\n\tv5 = 0, ///< 11w motor\n\texp = 1, ///< 5.5w motor\n\tinvalid = INT32_MAX ///< Error return code\n};\n\n\n// Provide Aliases for MotorGears\nusing MotorGearset = MotorGears;\nusing MotorCart = MotorGears;\nusing MotorCartridge = MotorGears;\nusing MotorGear = MotorGears;\n\n/**\n * \\ingroup cpp-abstract-motor\n */\nclass AbstractMotor {\n\t/**\n\t * \\addtogroup cpp-abstract-motor\n\t *  @{\n\t */\n\tpublic:\n\t/// \\name Motor movement functions\n\t/// These functions allow programmers to make motors move\n\t///@{\n\n\t/**\n\t * Sets the voltage for the motor from -127 to 127.\n\t *\n\t * This is designed to map easily to the input from the controller's analog\n\t * stick for simple opcontrol use. The actual behavior of the motor is\n\t * analogous to use of motor_move(), or motorSet() from the PROS 2 API.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param voltage\n\t *        The new motor voltage from -127 to 127\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t move(std::int32_t voltage) const = 0;\n\n\t/**\n\t * Sets the target absolute position for the motor to move to.\n\t *\n\t * This movement is relative to the position of the motor when initialized or\n\t * the position when it was most recently reset with\n\t * pros::Motor::set_zero_position().\n\t *\n\t * \\note This function simply sets the target for the motor, it does not block\n\t * program execution until the movement finishes.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param position\n\t *        The absolute position to move to in the motor's encoder units\n\t * \\param velocity\n\t *        The maximum allowable velocity for the movement in RPM\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t move_absolute(const double position, const std::int32_t velocity) const = 0;\n\n\t/**\n\t * Sets the relative target position for the motor to move to.\n\t *\n\t * This movement is relative to the current position of the motor as given in\n\t * pros::Motor::motor_get_position(). Providing 10.0 as the position parameter\n\t * would result in the motor moving clockwise 10 units, no matter what the\n\t * current position is.\n\t *\n\t * \\note This function simply sets the target for the motor, it does not block\n\t * program execution until the movement finishes.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param position\n\t *        The relative position to move to in the motor's encoder units\n\t * \\param velocity\n\t *        The maximum allowable velocity for the movement in RPM\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t move_relative(const double position, const std::int32_t velocity) const = 0;\n\n\t/**\n\t * Sets the velocity for the motor.\n\t *\n\t * This velocity corresponds to different actual speeds depending on the\n\t * gearset used for the motor. This results in a range of +-100 for\n\t * E_MOTOR_GEARSET_36, +-200 for E_MOTOR_GEARSET_18, and +-600 for\n\t * E_MOTOR_GEARSET_6. The velocity is held with PID to ensure consistent\n\t * speed, as opposed to setting the motor's voltage.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param velocity\n\t *        The new motor velocity from -+-100, +-200, or +-600 depending on the\n\t *        motor's gearset\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t move_velocity(const std::int32_t velocity) const = 0;\n\n\t/**\n\t * Sets the output voltage for the motor from -12000 to 12000 in millivolts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t * \\param voltage\n\t *        The new voltage value from -12000 to 12000\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t move_voltage(const std::int32_t voltage) const = 0;\n\n\t/**\n\t * Stops the motor using the currently configured brake mode.\n\t * \n\t * This function sets motor velocity to zero, which will cause it to act\n\t * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD,\n\t * this function may behave differently than calling move_absolute(0)\n\t * or motor_move_relative(0).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t */\n\tvirtual std::int32_t brake(void) const = 0;\n\n\t/**\n\t * Changes the output velocity for a profiled movement (motor_move_absolute or\n\t * motor_move_relative). This will have no effect if the motor is not following\n\t * a profiled movement.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param velocity\n\t *        The new motor velocity from +-100, +-200, or +-600 depending on the\n\t *        motor's gearset\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t modify_profiled_velocity(const std::int32_t velocity) const = 0;\n\n\t/**\n\t * Gets the target position set for the motor by the user, with a parameter\n\t * for the motor index.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The target position in its encoder units or PROS_ERR_F if the\n\t * operation failed, setting errno.\n\t */\n\tvirtual double get_target_position(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector containing the target position(s) set for the motor(s) by the user\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t *\n\t * \\return A vector containing the target position(s) in its encoder units or PROS_ERR_F if the\n\t * operation failed, setting errno.\n\t */\n\tvirtual std::vector<double> get_target_position_all(void) const = 0;\n\n\t/**\n\t * Gets the velocity commanded to the motor by the user.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n\t * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The commanded motor velocity from +-100, +-200, or +-600, or\n\t * PROS_ERR if the operation failed, setting errno.\n\t */\n\tvirtual std::int32_t get_target_velocity(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector containing the velocity/velocities commanded to the motor(s) by the user\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing the commanded motor velocity/velocities from +-100, \n\t * +-200, or +-600, or PROS_ERR if the operation failed, setting errno.\n\t */\n\tvirtual std::vector<std::int32_t> get_target_velocity_all(void) const = 0;\n\n\t///@}\n\n\t/// \\name Motor telemetry functions\n\t/// \\addtogroup cpp-motor-telemetry\n\t/// These functions allow programmers to collect telemetry from motors\n\t///@{\n\n\t/**\n\t * Gets the actual velocity of the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The motor's actual velocity in RPM or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual double get_actual_velocity(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector containing the actual velocity/velocities of the motor(s)\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing the motor's/motors' actual velocity/velocities in RPM or PROS_ERR_F\n\t * if the operation failed, setting errno.\n\t */\t\n\tvirtual std::vector<double> get_actual_velocity_all(void) const = 0;\n\n\t/**\n\t * Gets the current drawn by the motor in mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The motor's current in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t */\n\tvirtual std::int32_t get_current_draw(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector containing the current(s) drawn by the motor(s) in mA.\n\t * \n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * \n\t * ENODEV - The port cannot be configured as a motor\n\t * \n\t * \n\t * \\return A vector conatining the motor's/motors' current(s) in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t */\n\tvirtual std::vector<std::int32_t> get_current_draw_all(void) const = 0;\n\n\t/**\n\t * Gets the direction of movement for the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 for moving in the positive direction, -1 for moving in the\n\t * negative direction, and PROS_ERR if the operation failed, setting errno.\n\t */\n\tvirtual std::int32_t get_direction(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector containing the direction(s) of movement for the motor(s).\n\t *\n\t * \n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * \n\t * ENODEV - The port cannot be configured as a motor\n\t * \n\t * \n\t * \\return A vector containing 1 for moving in the positive direction, -1 for moving in the\n\t * negative direction, and PROS_ERR if the operation failed, setting errno.\n\t */\n\tvirtual std::vector<std::int32_t> get_direction_all(void) const = 0;\n\n\t/**\n\t * Gets the efficiency of the motor in percent.\n\t *\n\t * An efficiency of 100% means that the motor is moving electrically while\n\t * drawing no electrical power, and an efficiency of 0% means that the motor\n\t * is drawing power but not moving.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The motor's efficiency in percent or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual double get_efficiency(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector containing the efficiency/efficiencies of the motor(s) in percent.\n\t *\n\t * An efficiency of 100% means that the motor is moving electrically while\n\t * drawing no electrical power, and an efficiency of 0% means that the motor\n\t * is drawing power but not moving.\n\t * \n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * \n\t * ENODEV - The port cannot be configured as a motor\n\t * \n\t *\n\t * \\return A vector containing the motor's/motors' efficiency/efficiencies in percent or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::vector<double> get_efficiency_all(void) const = 0;\n\n\t/**\n\t * Gets the faults experienced by the motor.\n\t *\n\t * Compare this bitfield to the bitmasks in pros::motor_fault_e_t.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return A bitfield containing the motor's faults.\n\t */\n\tvirtual std::uint32_t get_faults(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the faults experienced by the motor(s).\n\t *\n\t * Compare this bitfield to the bitmasks in pros::motor_fault_e_t.\n\t * \n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * \n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A bitfield containing the motor's/motors' faults.\n\t */\n\tvirtual std::vector<std::uint32_t> get_faults_all(void) const = 0;\n\t/**\n\t * Gets the flags set by the motor's operation.\n\t *\n\t * Compare this bitfield to the bitmasks in pros::motor_flag_e_t.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return A bitfield containing the motor's flags.\n\t */\n\tvirtual std::uint32_t get_flags(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the flags set by the motor's/motors' operation.\n\t *\n\t * Compare this bitfield to the bitmasks in pros::motor_flag_e_t.\n\t * \n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * \n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t *\n\t * \\return A bitfield containing the motor's/motors' flags.\n\t */\n\tvirtual std::vector<std::uint32_t> get_flags_all(void) const = 0;\n\n\t/**\n\t * Gets the absolute position of the motor in its encoder units.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The motor's absolute position in its encoder units or PROS_ERR_F\n\t * if the operation failed, setting errno.\n\t */\n\tvirtual double get_position(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector containing the absolute position(s) of the motor(s) in its encoder units.\n\t * \n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * \n\t * ENODEV - The port cannot be configured as a motor\n\t \n\t *\n\t * \\return A vector containing the motor's/motors' absolute position(s) in its encoder units or PROS_ERR_F\n\t * if the operation failed, setting errno.\n\t */\n\tvirtual std::vector<double> get_position_all(void) const = 0;\n\n\t/**\n\t * Gets the power drawn by the motor in Watts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The motor's power draw in Watts or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual double get_power(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector containing the power(s) drawn by the motor(s) in Watts.\n\t * \n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * \n\t * ENODEV - The port cannot be configured as a motor\n\t * \n\t * \\return A vector containing the motor's/motors' power draw in Watts or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::vector<double> get_power_all(void) const = 0;\n\n\t/**\n\t * Gets the raw encoder count of the motor at a given timestamp.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param[in] timestamp\n\t *            A pointer to a time in milliseconds for which the encoder count\n\t *            will be returned. If NULL, the timestamp at which the encoder\n\t *            count was read will not be supplied\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The raw encoder count at the given timestamp or PROS_ERR if the\n\t * operation failed.\n\t */\n\tvirtual std::int32_t get_raw_position(std::uint32_t* const timestamp, const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the raw encoder count(s) of the motor(s) at a given timestamp.\n\t *\n\t * \n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * \n\t * ENODEV - The port cannot be configured as a motor\n\t * \n\t * \\param timestamp\n\t *            A pointer to a time in milliseconds for which the encoder count\n\t *            will be returned. If NULL, the timestamp at which the encoder\n\t *            count was read will not be supplied\n\t * \n\t * \\return A vector containing the raw encoder count(s) at the given timestamp or PROS_ERR if the\n\t * operation failed.\n\t */\n\tvirtual std::vector<std::int32_t> get_raw_position_all(std::uint32_t* const timestamp) const = 0;\n\n\t/**\n\t * Gets the temperature of the motor in degrees Celsius.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The motor's temperature in degrees Celsius or PROS_ERR_F if the\n\t * operation failed, setting errno.\n\t */\n\tvirtual double get_temperature(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the temperature(s) of the motor(s) in degrees Celsius.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return A vector containing the motor's/motors' temperature(s) in degrees Celsius or PROS_ERR_F if the\n\t * operation failed, setting errno.\n\t */\n\tvirtual std::vector<double> get_temperature_all(void) const = 0;\n\t/**\n\t * Gets the torque generated by the motor in Newton Meters (Nm).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The motor's torque in Nm or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t */\n\tvirtual double get_torque(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the torque(s) generated by the motor(s) in Newton Meters (Nm).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return A vector containing the motor's/motors' torque(s) in Nm or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t */\n\tvirtual std::vector<double> get_torque_all(void) const = 0;\n\t/**\n\t * Gets the voltage delivered to the motor in millivolts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The motor's voltage in mV or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t */\n\tvirtual std::int32_t get_voltage(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the voltage(s) delivered to the motor(s) in millivolts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return A vector containing the motor's/motors' voltage(s) in mV or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t */\n\tvirtual std::vector<std::int32_t> get_voltage_all(void) const = 0;\n\n\t/**\n\t * Checks if the motor is drawing over its current limit.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the motor's current limit is being exceeded and 0 if the\n\t * current limit is not exceeded, or PROS_ERR if the operation failed, setting\n\t * errno.\n\t */\n\tvirtual std::int32_t is_over_current(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of whether each motor is drawing over its current limit.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the motor's current limit is being exceeded and 0 if the\n\t * current limit is not exceeded, or PROS_ERR if the operation failed, setting\n\t * errno.\n\t */\n\tvirtual std::vector<std::int32_t> is_over_current_all(void) const = 0;\n\n\t/**\n\t * Gets the temperature limit flag for the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the temperature limit is exceeded and 0 if the temperature is\n\t * below the limit, or PROS_ERR if the operation failed, setting errno.\n\t */\n\tvirtual std::int32_t is_over_temp(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the temperature limit flag(s) for the motor(s).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the temperature limit is exceeded and 0 if the temperature is\n\t * below the limit, or PROS_ERR if the operation failed, setting errno.\n\t */\n\tvirtual std::vector<std::int32_t> is_over_temp_all(void) const = 0;\n\n\t///@}\n\n\t/// \\name Motor configuration functions\n\t/// \\addtogroup cpp-motor-configuration\n\t/// These functions allow programmers to configure the behavior of motors\n\t///@{\n\n\t/**\n\t * Gets the brake mode that was set for the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return One of MotorBrake, according to what was set for the\n\t * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno.\n\t */\n\tvirtual MotorBrake get_brake_mode(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the brake mode(s) that was set for the motor(s).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return A vector containing MotorBrake(s), according to what was set for the\n\t * motor(s), or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno.\n\t */\n\tvirtual std::vector<MotorBrake> get_brake_mode_all(void) const = 0;\n\n\t/**\n\t * Gets the current limit for the motor in mA.\n\t *\n\t * The default value is 2500 mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The motor's current limit in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t */\n\tvirtual std::int32_t get_current_limit(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the current limit(s) for the motor(s) in mA.\n\t *\n\t * The default value is 2500 mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return A vector containing the motor's/motors' current limit(s) in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t */\n\tvirtual std::vector<std::int32_t> get_current_limit_all(void) const = 0;\n\n\t/**\n\t * Gets the encoder units that were set for the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return One of MotorUnits according to what is set for the\n\t * motor or E_MOTOR_ENCODER_INVALID if the operation failed.\n\t */\n\tvirtual MotorUnits get_encoder_units(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the encoder units that were set for the motor(s).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return A vector of MotorUnits according to what is set for the\n\t * motor(s) or E_MOTOR_ENCODER_INVALID if the operation failed.\n\t */\n\tvirtual std::vector<MotorUnits> get_encoder_units_all(void) const = 0;\n\n\t/**\n\t * Gets the gearset that was set for the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return One of MotorGears according to what is set for the motor,\n\t * or pros::MotorGears::invalid if the operation failed.\n\t */\n\tvirtual MotorGears get_gearing(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the gearset(s) that was/were set for the motor(s).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return A vector of MotorGears according to what is set for the motor(s),\n\t * or pros::MotorGears::invalid if the operation failed.\n\t */\n\tvirtual std::vector<MotorGears> get_gearing_all(void) const = 0;\n\n\t/**\n\t * @brief Gets returns a vector with all the port numbers in the motor group.\n\t *\n\t * @return std::vector<std::int8_t>\n\t */\n\tvirtual std::vector<std::int8_t> get_port_all(void) const = 0;\n\n\t/**\n\t * Gets the voltage limit set by the user.\n\t *\n\t * Default value is 0V, which means that there is no software limitation\n\t * imposed on the voltage.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return The motor's voltage limit in V or PROS_ERR if the operation failed,\n\t * setting errno.\n\t */\n\tvirtual std::int32_t get_voltage_limit(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the voltage limit(s) set by the user.\n\t *\n\t * Default value is 0V, which means that there is no software limitation\n\t * imposed on the voltage.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return A vector containing the motor's/motors' voltage limit(s) in V or PROS_ERR if the operation failed,\n\t * setting errno.\n\t */\n\tvirtual std::vector<std::int32_t> get_voltage_limit_all(void) const = 0;\n\n\t/**\n\t * Gets the operation direction of the motor as set by the user.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the motor has been reversed and 0 if the motor was not\n\t * reversed, or PROS_ERR if the operation failed, setting errno.\n\t */\n\tvirtual std::int32_t is_reversed(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the operation direction(s) of the motor(s) as set by the user.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the motor has been reversed and 0 if the motor was not\n\t * reversed, or PROS_ERR if the operation failed, setting errno.\n\t */\n\tvirtual std::vector<std::int32_t> is_reversed_all(void) const = 0;\n\n\t/**\n\t * Gets the type of the motor\n\t * \n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return One of MotorType according to the type of the motor,\n\t * or pros::MotorType::invalid if the operation failed\n\t */\n\tvirtual MotorType get_type(const std::uint8_t index = 0) const = 0;\n\n\t/**\n\t * Gets a vector of the type(s) of the motor(s).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n\t * \\return A vector of MotorType according to the type(s) of the motor(s),\n\t * or pros::MotorType::invalid if the operation failed.\n\t */\n\tvirtual std::vector<MotorType> get_type_all(void) const = 0;\n\n\t/**\n\t * Sets one of MotorBrake to the motor. Works with the C enum\n\t * and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param mode\n\t *        The MotorBrake to set for the motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t set_brake_mode(const MotorBrake mode, const std::uint8_t index = 0) const = 0;\n\tvirtual std::int32_t set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index = 0) const = 0;\n\tvirtual std::int32_t set_brake_mode_all(const MotorBrake mode) const = 0;\n\tvirtual std::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const = 0;\n\t/**\n\t * Sets the current limit for the motor in mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param limit\n\t *        The new current limit in mA\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t set_current_limit(const std::int32_t limit, const std::uint8_t index = 0) const = 0;\n\tvirtual std::int32_t set_current_limit_all(const std::int32_t limit) const = 0;\n\t/**\n\t * Sets one of MotorUnits for the motor encoder. Works with the C\n\t * enum and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param units\n\t *        The new motor encoder units\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t set_encoder_units(const MotorUnits units, const std::uint8_t index = 0) const = 0;\n\tvirtual std::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index = 0) const = 0;\n\tvirtual std::int32_t set_encoder_units_all(const MotorUnits units) const = 0;\n\tvirtual std::int32_t set_encoder_units_all(const pros::motor_encoder_units_e_t units) const = 0;\n\t/**\n\t * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with\n\t * the C++ enum class and the C enum.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param gearset\n\t *        The new motor gearset\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t set_gearing(const MotorGears gearset, const std::uint8_t index = 0) const = 0;\n\tvirtual std::int32_t set_gearing(const pros::motor_gearset_e_t gearset, const std::uint8_t index = 0) const = 0;\n\tvirtual std::int32_t set_gearing_all(const MotorGears gearset) const = 0;\n\tvirtual std::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const = 0;\n\n\t/**\n\t * Sets the reverse flag for the motor.\n\t *\n\t * This will invert its movements and the values returned for its position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param reverse\n\t *        True reverses the motor, false is default\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t set_reversed(const bool reverse, const std::uint8_t index = 0) = 0;\n\tvirtual std::int32_t set_reversed_all(const bool reverse) = 0;\n\n\t/**\n\t * Sets the voltage limit for the motor in Volts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param limit\n\t *        The new voltage limit in Volts\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t set_voltage_limit(const std::int32_t limit, const std::uint8_t index = 0) const = 0;\n\tvirtual std::int32_t set_voltage_limit_all(const std::int32_t limit) const = 0;\n\n\t/**\n\t * Sets the position for the motor in its encoder units.\n\t *\n\t * This will be the future reference point for the motor's \"absolute\"\n\t * position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param position\n\t *        The new reference position in its encoder units\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t set_zero_position(const double position, const std::uint8_t index = 0) const = 0;\n\tvirtual std::int32_t set_zero_position_all(const double position) const = 0;\n\n\t/**\n\t * Sets the \"absolute\" zero position of the motor to its current position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * \n     * \\param index Optional parameter. \n     *           The index of the motor to get the target position of.\n     *           By default index is 0, and will return an error for an out of bounds index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tvirtual std::int32_t tare_position(const std::uint8_t index = 0) const = 0;\n\tvirtual std::int32_t tare_position_all(void) const = 0;\n\tvirtual std::int8_t get_port(const std::uint8_t index = 0) const = 0;\n\t/**\n\t * @brief Returns the number of objects\n\t *\n\t * @return std::int8_t\n\t */\n\tvirtual std::int8_t size(void) const = 0;\n\n\t///@}\n\tprivate:\n};\n\n} // namespace v5\n} // namespace pros\n\n///@}\n\n#endif\n"
  },
  {
    "path": "include/pros/adi.h",
    "content": "/**\n * \\file pros/adi.h\n * \\ingroup c-adi\n *\n * Contains prototypes for interfacing with the ADI.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup c-adi ADI (TriPort) C API\n * \\note The external ADI API can be found [here.](@ref ext-adi)\n * \\note Additional example code for this module can be found in its [Tutorial.](@ref adi)\n */\n\n#ifndef _PROS_ADI_H_\n#define _PROS_ADI_H_\n\n#include <stdbool.h>\n#include <stdint.h>\n#ifndef PROS_ERR\n#define PROS_ERR (INT32_MAX)\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\n#endif\n\n/**\n * \\ingroup c-adi\n */\n\n/**\n * \\addtogroup c-adi\n *  @{\n */\n\n/**\n * \\enum adi_port_config_e\n * Represents the port type for an ADI port.\n */\ntypedef enum adi_port_config_e {\n\tE_ADI_ANALOG_IN = 0,\n\tE_ADI_ANALOG_OUT = 1,\n\tE_ADI_DIGITAL_IN = 2,\n\tE_ADI_DIGITAL_OUT = 3,\n\n#ifdef _INTELLISENSE\n#define _DEPRECATE_DIGITAL_IN = E_ADI_DIGITAL_IN\n#define _DEPRECATE_ANALOG_IN = E_ADI_ANALOG_IN\n#else\n#define _DEPRECATE_DIGITAL_IN __attribute__((deprecated(\"use E_ADI_DIGITAL_IN instead\"))) = E_ADI_DIGITAL_IN\n#define _DEPRECATE_ANALOG_IN __attribute__((deprecated(\"use E_ADI_ANALOG_IN instead\"))) = E_ADI_ANALOG_IN\n#endif\n\n\tE_ADI_SMART_BUTTON _DEPRECATE_DIGITAL_IN,\n\tE_ADI_SMART_POT _DEPRECATE_ANALOG_IN,\n\n\tE_ADI_LEGACY_BUTTON _DEPRECATE_DIGITAL_IN,\n\tE_ADI_LEGACY_POT _DEPRECATE_ANALOG_IN,\n\tE_ADI_LEGACY_LINE_SENSOR _DEPRECATE_ANALOG_IN,\n\tE_ADI_LEGACY_LIGHT_SENSOR _DEPRECATE_ANALOG_IN,\n\tE_ADI_LEGACY_GYRO = 10,\n\tE_ADI_LEGACY_ACCELEROMETER _DEPRECATE_ANALOG_IN,\n\n#undef _DEPRECATE_DIGITAL_IN\n#undef _DEPRECATE_ANALOG_IN\n\n\tE_ADI_LEGACY_SERVO = 12,\n\tE_ADI_LEGACY_PWM = 13,\n\n\tE_ADI_LEGACY_ENCODER = 14,\n\tE_ADI_LEGACY_ULTRASONIC = 15,\n\n\tE_ADI_TYPE_UNDEFINED = 255,\n\tE_ADI_ERR = PROS_ERR\n} adi_port_config_e_t;\n\n/**\n * \\enum adi_potentiometer_type_e_t\n * Represents the potentiometer version type.\n */\ntypedef enum adi_potentiometer_type_e { \n\tE_ADI_POT_EDR = 0,\n\tE_ADI_POT_V2\n} adi_potentiometer_type_e_t;\n\n#ifdef PROS_USE_SIMPLE_NAMES\n#ifdef __cplusplus\n#define ADI_ANALOG_IN pros::E_ADI_ANALOG_IN\n#define ADI_ANALOG_OUT pros::E_ADI_ANALOG_OUT\n#define ADI_DIGITAL_IN pros::E_ADI_DIGITAL_IN\n#define ADI_DIGITAL_OUT pros::E_ADI_DIGITAL_OUT\n#define ADI_SMART_BUTTON pros::E_ADI_SMART_BUTTON\n#define ADI_SMART_POT pros::E_ADI_SMART_POT\n#define ADI_LEGACY_BUTTON pros::E_ADI_LEGACY_BUTTON\n#define ADI_LEGACY_POT pros::E_ADI_LEGACY_POT\n#define ADI_LEGACY_LINE_SENSOR pros::E_ADI_LEGACY_LINE_SENSOR\n#define ADI_LEGACY_LIGHT_SENSOR pros::E_ADI_LEGACY_LIGHT_SENSOR\n#define ADI_LEGACY_GYRO pros::E_ADI_LEGACY_GYRO\n#define ADI_LEGACY_ACCELEROMETER pros::E_ADI_LEGACY_ACCELEROMETER\n#define ADI_LEGACY_SERVO pros::E_ADI_LEGACY_SERVO\n#define ADI_LEGACY_PWM pros::E_ADI_LEGACY_PWM\n#define ADI_LEGACY_ENCODER pros::E_ADI_LEGACY_ENCODER\n#define ADI_LEGACY_ULTRASONIC pros::E_ADI_LEGACY_ULTRASONIC\n#define ADI_TYPE_UNDEFINED pros::E_ADI_TYPE_UNDEFINED\n#define ADI_ERR pros::E_ADI_ERR\n#else\n#define ADI_ANALOG_IN E_ADI_ANALOG_IN\n#define ADI_ANALOG_OUT E_ADI_ANALOG_OUT\n#define ADI_DIGITAL_IN E_ADI_DIGITAL_IN\n#define ADI_DIGITAL_OUT E_ADI_DIGITAL_OUT\n#define ADI_SMART_BUTTON E_ADI_SMART_BUTTON\n#define ADI_SMART_POT E_ADI_SMART_POT\n#define ADI_LEGACY_BUTTON E_ADI_LEGACY_BUTTON\n#define ADI_LEGACY_POT E_ADI_LEGACY_POT\n#define ADI_LEGACY_LINE_SENSOR E_ADI_LEGACY_LINE_SENSOR\n#define ADI_LEGACY_LIGHT_SENSOR E_ADI_LEGACY_LIGHT_SENSOR\n#define ADI_LEGACY_GYRO E_ADI_LEGACY_GYRO\n#define ADI_LEGACY_ACCELEROMETER E_ADI_LEGACY_ACCELEROMETER\n#define ADI_LEGACY_SERVO E_ADI_LEGACY_SERVO\n#define ADI_LEGACY_PWM E_ADI_LEGACY_PWM\n#define ADI_LEGACY_ENCODER E_ADI_LEGACY_ENCODER\n#define ADI_LEGACY_ULTRASONIC E_ADI_LEGACY_ULTRASONIC\n#define ADI_TYPE_UNDEFINED E_ADI_TYPE_UNDEFINED\n#define ADI_ERR E_ADI_ERR\n#endif\n#endif\n\n#define INTERNAL_ADI_PORT 22\n#define NUM_ADI_PORTS 8\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n/** @} Add to group c-adi*/\n\n/**\n * \\ingroup c-adi\n */\n\n/**\n * \\addtogroup c-adi\n *  @{\n */\n\n/**\n * Gets the configuration for the given ADI port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports.\n *\n * \\param port\n *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') for which to return\n *        the configuration\n *\n * \\return The ADI configuration for the given port\n * \n * \\b Example\n * \\code\n * #define ANALOG_SENSOR_PORT 1\n * \n * void initialize() {\n *   adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN);\n *   // Displays the value of E_ADI_ANALOG_IN\n *   printf(\"Port Type: %d\\n\", adi_port_get_config(ANALOG_SENSOR_PORT));\n * }\n * \\endcode\n */\nadi_port_config_e_t adi_port_get_config(uint8_t port);\n\n/**\n * Gets the value for the given ADI port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports.\n *\n * \\param port\n *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') for which the value\n *        will be returned\n *\n * \\return The value stored for the given port\n * \n * \\b Example\n * \\code\n * #define ANALOG_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN);\n *   printf(\"Port Value: %d\\n\", adi_get_value(ANALOG_SENSOR_PORT));\n * }\n * \\endcode\n */\nint32_t adi_port_get_value(uint8_t port);\n\n/**\n * Configures an ADI port to act as a given sensor type.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports.\n *\n * \\param port\n *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n * \\param type\n *        The configuration type for the port\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define ANALOG_SENSOR_PORT 1\n * \n * void initialize() {\n *   adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN);\n * }\n * \\endcode\n */\nint32_t adi_port_set_config(uint8_t port, adi_port_config_e_t type);\n\n/**\n * Sets the value for the given ADI port.\n *\n * This only works on ports configured as outputs, and the behavior will change\n * depending on the configuration of the port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO  - The given value is not within the range of ADI Ports.\n *\n * \\param port\n *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') for which the value\n *        will be set\n * \\param value\n *        The value to set the ADI port to\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define DIGITAL_SENSOR_PORT 1\n * \n * void initialize() {\n *   adi_port_set_config(DIGITAL_SENSOR_PORT, E_ADI_DIGITAL_OUT);\n *   adi_set_value(DIGITAL_SENSOR_PORT, HIGH);\n * }\n * \\endcode\n */\nint32_t adi_port_set_value(uint8_t port, int32_t value);\n\n/**\n * Calibrates the analog sensor on the specified port and returns the new\n * calibration value.\n *\n * This method assumes that the true sensor value is not actively changing at\n * this time and computes an average from approximately 500 samples, 1 ms apart,\n * for a 0.5 s period of calibration. The average value thus calculated is\n * returned and stored for later calls to the adi_analog_read_calibrated() and\n * adi_analog_read_calibrated_HR() functions. These functions will return\n * the difference between this value and the current sensor value when called.\n *\n * Do not use this function when the sensor value might be unstable\n * (gyro rotation, accelerometer movement).\n * \n * \\note The ADI currently returns data at 10ms intervals, in constrast to the\n * calibrate function’s 1ms sample rate. \n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n *\n * \\param port\n *        The ADI port to calibrate (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return The average sensor value computed by this function\n * \n * \\b Example\n * \\code\n * #define ANALOG_SENSOR_PORT 1\n * \n * void initialize() {\n *   adi_analog_calibrate(ANALOG_SENSOR_PORT);\n *   printf(\"Calibrated Reading: %d\\n\", adi_analog_read_calibrated(ANALOG_SENSOR_PORT));\n *   // All readings from then on will be calibrated\n * }\n * \\endcode\n */\nint32_t adi_analog_calibrate(uint8_t port);\n\n/**\n * Gets the 12-bit value of the specified port.\n *\n * The value returned is undefined if the analog pin has been switched to a\n * different mode.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an analog input\n *\n * \\param port\n *        The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be\n *        returned\n *\n * \\return The analog sensor value, where a value of 0 reflects an input voltage\n * of nearly 0 V and a value of 4095 reflects an input voltage of nearly 5 V\n * \n * \\b Example\n * \\code\n * #define ANALOG_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Sensor Reading: %d\\n\", adi_analog_read(ANALOG_SENSOR_PORT));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_analog_read(uint8_t port);\n\n/**\n * Gets the 12 bit calibrated value of an analog input port.\n *\n * The adi_analog_calibrate() function must be run first. This function is\n * inappropriate for sensor values intended for integration, as round-off error\n * can accumulate causing drift over time. Use adi_analog_read_calibrated_HR()\n * instead.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an analog input\n *\n * \\param port\n *        The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be\n *        returned\n *\n * \\return The difference of the sensor value from its calibrated default from\n * -4095 to 4095\n * \n * \\b Example\n * \\code\n * #define ANALOG_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Sensor Reading: %d\\n\", adi_analog_read_calibrated(ANALOG_SENSOR_PORT));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_analog_read_calibrated(uint8_t port);\n\n/**\n * Gets the 16 bit calibrated value of an analog input port.\n *\n * The adi_analog_calibrate() function must be run first. This is intended for\n * integrated sensor values such as gyros and accelerometers to reduce drift due\n * to round-off, and should not be used on a sensor such as a line tracker\n * or potentiometer.\n *\n * The value returned actually has 16 bits of \"precision\", even though the ADC\n * only reads 12 bits, so that error induced by the average value being between\n * two values when integrated over time is trivial. Think of the value as the\n * true value times 16.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an analog input\n *\n * \\param port\n *        The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be\n *        returned\n *\n * \\return The difference of the sensor value from its calibrated default from\n * -16384 to 16384\n * \n * \\b Example\n * \\code\n * #define ANALOG_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     adi_analog_calibrate(ANALOG_SENSOR_PORT);\n *     printf(\"Sensor Reading: %d\\n\", adi_analog_read_calibrated_HR(ANALOG_SENSOR_PORT));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_analog_read_calibrated_HR(uint8_t port);\n\n/**\n * Gets the digital value (1 or 0) of a port configured as a digital input.\n *\n * If the port is configured as some other mode, the digital value which\n * reflects the current state of the port is returned, which may or may not\n * differ from the currently set value. The return value is undefined for ports\n * configured as any mode other than a Digital Input.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a digital input\n *\n * \\param port\n *        The ADI port to read (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return True if the pin is HIGH, or false if it is LOW\n * \n * \\b Example\n * \\code\n * #define DIGITAL_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Sensor Value: %d\\n\", adi_digital_read(DIGITAL_SENSOR_PORT));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_digital_read(uint8_t port);\n\n/**\n * Gets a rising-edge case for a digital button press.\n *\n * This function is not thread-safe.\n * Multiple tasks polling a single button may return different results under the\n * same circumstances, so only one task should call this function for any given\n * button. E.g., Task A calls this function for buttons 1 and 2. Task B may call\n * this function for button 3, but should not for buttons 1 or 2. A typical\n * use-case for this function is to call inside opcontrol to detect new button\n * presses, and not in any other tasks.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a digital input\n *\n * \\param port\n *        The ADI port to read (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return 1 if the button is pressed and had not been pressed\n * the last time this function was called, 0 otherwise.\n * \n * \\b Example\n * \\code\n * #define DIGITAL_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     if (adi_digital_get_new_press(DIGITAL_SENSOR_PORT)) {\n *       // Toggle pneumatics or other state operations\n *     }\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_digital_get_new_press(uint8_t port);\n\n/**\n * Sets the digital value (1 or 0) of a port configured as a digital output.\n *\n * If the port is configured as some other mode, behavior is undefined.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a digital output\n *\n * \\param port\n *        The ADI port to read (from 1-8, 'a'-'h', 'A'-'H')\n * \\param value\n *        An expression evaluating to \"true\" or \"false\" to set the output to\n *        HIGH or LOW respectively, or the constants HIGH or LOW themselves\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define DIGITAL_SENSOR_PORT\n * \n * void opcontrol() {\n *   bool state = LOW;\n *   while (true) {\n *     state != state;\n *     adi_digital_write(DIGITAL_SENSOR_PORT, state);\n *     delay(5); // toggle the sensor value every 50ms\n *   }\n * }\n * \\endcode\n */\nint32_t adi_digital_write(uint8_t port, bool value);\n\n/**\n * Configures the port as an input or output with a variety of settings.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n *\n * \\param port\n *        The ADI port to read (from 1-8, 'a'-'h', 'A'-'H')\n * \\param mode\n *        One of INPUT, INPUT_ANALOG, INPUT_FLOATING, OUTPUT, or OUTPUT_OD\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define ANALOG_SENSOR_PORT 1\n * \n * void initialize() {\n *   adi_pin_mode(ANALOG_SENSOR_PORT, INPUT_ANALOG);\n * }\n * \\endcode\n */\nint32_t adi_pin_mode(uint8_t port, uint8_t mode);\n\n/**\n * Sets the speed of the motor on the given port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an motor\n *\n * \\param port\n *        The ADI port to set (from 1-8, 'a'-'h', 'A'-'H')\n * \\param speed\n *        The new signed speed; -127 is full reverse and 127 is full forward,\n *        with 0 being off\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define MOTOR_PORT 1\n * \n * void opcontrol() {\n *   adi_motor_set(MOTOR_PORT, 127); // Go full speed forward\n *   delay(1000);\n *   adi_motor_set(MOTOR_PORT, 0); // Stop the motor\n * }\n * \\endcode\n */\nint32_t adi_motor_set(uint8_t port, int8_t speed);\n\n/**\n * Gets the last set speed of the motor on the given port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an motor\n *\n * \\param port\n *        The ADI port to get (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return The last set speed of the motor on the given port\n * \n * \\b Example\n * \\code\n * #define MOTOR_PORT 1\n * \n * void opcontrol() {\n *   adi_motor_set(MOTOR_PORT, 127); // Go full speed forward\n *   printf(\"Commanded Motor Power: %d\\n\", adi_motor_get(MOTOR_PORT)); // Will display 127\n *   delay(1000);\n *   adi_motor_set(MOTOR_PORT, 0); // Stop the motor\n * }\n * \\endcode\n */\nint32_t adi_motor_get(uint8_t port);\n\n/**\n * Stops the motor on the given port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an motor\n *\n * \\param port\n *        The ADI port to set (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define MOTOR_PORT 1\n * \n * void opcontrol() {\n *   adi_motor_set(MOTOR_PORT, 127); // Go full speed forward\n *   delay(1000);\n *   // adi_motor_set(MOTOR_PORT, 0); // Stop the motor\n *   adi_motor_stop(MOTOR_PORT); // use this instead\n * }\n * \\endcode\n */\nint32_t adi_motor_stop(uint8_t port);\n\n/**\n * Reference type for an initialized encoder.\n *\n * This merely contains the port number for the encoder.\n */\ntypedef int32_t adi_encoder_t;\n\n/**\n * Gets the number of ticks recorded by the encoder.\n *\n * There are 360 ticks in one revolution.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an encoder\n *\n * \\param enc\n *        The adi_encoder_t object from adi_encoder_init() to read\n *\n * \\return The signed and cumulative number of counts since the last start or\n * reset\n * \n * \\b Example\n * \\code\n * #define PORT_TOP 1\n * #define PORT_BOTTOM 2\n * \n * void opcontrol() {\n *   adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false);\n *   while (true) {\n *   printf(\"Encoder Value: %d\\n\", adi_encoder_get(enc));\n *   delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_encoder_get(adi_encoder_t enc);\n\n/**\n * Creates an encoder object and configures the specified ports accordingly.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an encoder\n\n *\n * \\param port_top\n *        The \"top\" wire from the encoder sensor with the removable cover side\n *        up. This should be in port 1, 3, 5, or 7 ('A', 'C', 'E', or 'G').\n * \\param port_bottom\n *        The \"bottom\" wire from the encoder sensor\n * \\param reverse\n *        If \"true\", the sensor will count in the opposite direction\n *\n * \\return An adi_encoder_t object to be stored and used for later calls to\n * encoder functions\n * \n * \\b Example\n * \\code\n * #define PORT_TOP 1\n * #define PORT_BOTTOM 2\n * \n * void opcontrol() {\n *   adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false);\n *   while (true) {\n *     printf(\"Encoder Value: %d\\n\", adi_encoder_get(enc));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nadi_encoder_t adi_encoder_init(uint8_t port_top, uint8_t port_bottom, bool reverse);\n\n/**\n * Sets the encoder value to zero.\n *\n * It is safe to use this method while an encoder is enabled. It is not\n * necessary to call this method before stopping or starting an encoder.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an encoder\n\n *\n * \\param enc\n *        The adi_encoder_t object from adi_encoder_init() to reset\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define PORT_TOP 1\n * #define PORT_BOTTOM 2\n * \n * void opcontrol() {\n *   adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false);\n *   delay(1000); // Move the encoder around in this time\n *   adi_encoder_reset(enc); // The encoder is now zero again\n * }\n * \\endcode\n */\nint32_t adi_encoder_reset(adi_encoder_t enc);\n\n/**\n * Disables the encoder and voids the configuration on its ports.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an encoder\n *\n * \\param enc\n *        The adi_encoder_t object from adi_encoder_init() to stop\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define PORT_TOP 1\n * #define PORT_BOTTOM 2\n * \n * void opcontrol() {\n *   adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false);\n *   // Use the encoder\n *   adi_encoder_shutdown(enc);\n * }\n * \\endcode\n */\nint32_t adi_encoder_shutdown(adi_encoder_t enc);\n\n/**\n * Reference type for an initialized ultrasonic.\n *\n * This merely contains the port number for the ultrasonic.\n */\ntypedef int32_t adi_ultrasonic_t;\n\n/**\n * Gets the current ultrasonic sensor value in centimeters.\n *\n * If no object was found, zero is returned. If the ultrasonic sensor was never\n * started, the return value is undefined. Round and fluffy objects can cause\n * inaccurate values to be returned.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an ultrasonic\n *\n * \\param ult\n *        The adi_ultrasonic_t object from adi_ultrasonic_init() to read\n *\n * \\return The distance to the nearest object in m^-4 (10000 indicates 1 meter),\n * measured from the sensor's mounting points.\n * \n * \\b Example\n * \\code\n * #define PORT_PING 1\n * #define PORT_ECHO 2\n * \n * void opcontrol() {\n *   adi_ultrasonic_t ult = adi_ultrasonic_init(PORT_PING, PORT_ECHO);\n *   while (true) {\n *     // Print the distance read by the ultrasonic\n *     printf(\"Distance: %d\\n\", adi_ultrasonic_get(ult));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_ultrasonic_get(adi_ultrasonic_t ult);\n\n/**\n * Creates an ultrasonic object and configures the specified ports accordingly.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an ultrasonic\n *\n * \\param port_ping\n *        The port connected to the orange OUTPUT cable. This should be in port\n *        1, 3, 5, or 7 ('A', 'C', 'E', 'G').\n * \\param port_echo\n *        The port connected to the yellow INPUT cable. This should be in the\n *        next highest port following port_ping.\n *\n * \\return An adi_ultrasonic_t object to be stored and used for later calls to\n * ultrasonic functions\n * \n * \\b Example\n * \\code\n * #define PORT_PING 1\n * #define PORT_ECHO 2\n * \n * void opcontrol() {\n *   adi_ultrasonic_t ult = adi_ultrasonic_init(PORT_PING, PORT_ECHO);\n *     while (true) {\n *     // Print the distance read by the ultrasonic\n *     printf(\"Distance: %d\\n\", adi_ultrasonic_get(ult));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nadi_ultrasonic_t adi_ultrasonic_init(uint8_t port_ping, uint8_t port_echo);\n\n/**\n * Disables the ultrasonic sensor and voids the configuration on its ports.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as an ultrasonic\n *\n * \\param ult\n *        The adi_ultrasonic_t object from adi_ultrasonic_init() to stop\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define PORT_PING 1\n * #define PORT_ECHO 2\n * \n * void opcontrol() {\n *   adi_ultrasonic_t ult = adi_ultrasonic_init(PORT_PING, PORT_ECHO);\n *   while (true) {\n *     // Print the distance read by the ultrasonic\n *     printf(\"Distance: %d\\n\", adi_ultrasonic_get(ult));\n *     delay(5);\n *   }\n *   adi_ultrasonic_shutdown(ult);\n * }\n * \\endcode\n */\nint32_t adi_ultrasonic_shutdown(adi_ultrasonic_t ult);\n\n/**\n * Reference type for an initialized gyroscope.\n *\n * This merely contains the port number for the gyroscope.\n */\ntypedef int32_t adi_gyro_t;\n\n/**\n * Gets the current gyro angle in tenths of a degree. Unless a multiplier is\n * applied to the gyro, the return value will be a whole number representing\n * the number of degrees of rotation times 10.\n *\n * There are 360 degrees in a circle, thus the gyro will return 3600 for one\n * whole rotation.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a gyro\n *\n * \\param gyro\n *        The adi_gyro_t object for which the angle will be returned\n *\n * \\return The gyro angle in degrees.\n * \n * \\b Example\n * \\code\n * #define GYRO_PORT 1\n * #define GYRO_MULTIPLIER 1 // Standard behavior\n * \n * void opcontrol() {\n *   adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER);\n *   while (true) {\n *     // Print the gyro's heading\n *     printf(\"Heading: %lf\\n\", adi_gyro_get(gyro));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\ndouble adi_gyro_get(adi_gyro_t gyro);\n\n/**\n * Initializes a gyroscope on the given port. If the given port has not\n * previously been configured as a gyro, then this function starts a 1300 ms\n * calibration period.\n *\n * It is highly recommended that this function be called from initialize() when\n * the robot is stationary to ensure proper calibration.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a gyro\n *\n * \\param port\n *        The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H')\n * \\param multiplier\n *        A scalar value that will be multiplied by the gyro heading value\n *        supplied by the ADI\n *\n * \\return An adi_gyro_t object containing the given port, or PROS_ERR if the\n * initialization failed.\n * \n * \\b Example\n * \\code\n * #define GYRO_PORT 1\n * #define GYRO_MULTIPLIER 1 // Standard behavior\n * \n * void opcontrol() {\n *   adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER);\n *   while (true) {\n *     // Print the gyro's heading\n *     printf(\"Heading: %lf\\n\", adi_gyro_get(gyro));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nadi_gyro_t adi_gyro_init(uint8_t port, double multiplier);\n\n/**\n * Resets the gyroscope value to zero.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a gyro\n *\n * \\param gyro\n *        The adi_gyro_t object for which the angle will be returned\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define GYRO_PORT 1\n * #define GYRO_MULTIPLIER 1 // Standard behavior\n * \n * void opcontrol() {\n *   adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER);\n *   uint32_t now = millis();\n *   while (true) {\n *     // Print the gyro's heading\n *     printf(\"Heading: %lf\\n\", adi_gyro_get(gyro));\n * \n *     if (millis() - now > 2000) {\n *       // Reset the gyro every 2 seconds\n *       adi_gyro_reset(gyro);\n *       now = millis();\n *     }\n * \n *   delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_gyro_reset(adi_gyro_t gyro);\n\n/**\n * Disables the gyro and voids the configuration on its port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a gyro\n *\n * \\param gyro\n *        The adi_gyro_t object to be shut down\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define GYRO_PORT 1\n * #define GYRO_MULTIPLIER 1 // Standard behavior\n * \n * void opcontrol() {\n *   adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER);\n *   uint32_t now = millis();\n *   while (true) {\n *     // Print the gyro's heading\n *     printf(\"Heading: %lf\\n\", adi_gyro_get(gyro));\n * \n *     if (millis() - now > 2000) {\n *       adi_gyro_shutdown(gyro);\n *       // Shut down the gyro after two seconds\n *       break;\n *     }\n * \n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_gyro_shutdown(adi_gyro_t gyro);\n\n/**\n * Reference type for an initialized potentiometer.\n *\n * This merely contains the port number for the potentiometer.\n */\ntypedef int32_t adi_potentiometer_t;\n\n/**\n * Initializes a potentiometer on the given port of the original potentiometer.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a potentiometer\n *\n * \\param port\n *        The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return An adi_potentiometer_t object containing the given port, or PROS_ERR if the\n * initialization failed.\n * \n * \\b Example\n * \\code\n * #define POTENTIOMETER_PORT 1\n * \n * void opcontrol() {\n *   adi_potentiometer_t potentiometer = adi_potentiometer_init(POTENTIOMETER_PORT);\n *   while (true) {\n *     // Print the potentiometer's angle\n *     printf(\"Angle: %lf\\n\", adi_potentiometer_get_angle(potentiometer));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nadi_potentiometer_t adi_potentiometer_init(uint8_t port);\n\n/**\n * Initializes a potentiometer on the given port. \n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a potentiometer\n *\n * \\param port\n *        The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H')\n * \\param potentiometer_type\n *        An adi_potentiometer_type_e_t enum value specifying the potentiometer version type\n *\n * \\return An adi_potentiometer_t object containing the given port, or PROS_ERR if the\n * initialization failed.\n * \n * \\b Example\n * \\code\n * #define POTENTIOMETER_PORT 1\n * #define POTENTIOMETER_TYPE E_ADI_POT_EDR\n * \n * void opcontrol() {\n *   adi_potentiometer_t potentiometer = adi_potentiometer_type_init(POTENTIOMETER_PORT, POTENTIOMETER_TYPE);\n *   while (true) {\n *     // Print the potentiometer's angle\n *     printf(\"Angle: %lf\\n\", adi_potentiometer_get_angle(potentiometer));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nadi_potentiometer_t adi_potentiometer_type_init(uint8_t port, adi_potentiometer_type_e_t potentiometer_type);\n\n/**\n * Gets the current potentiometer angle in tenths of a degree.\n *\n * The original potentiometer rotates 250 degrees thus returning an angle between 0-250 degrees.\n * Potentiometer V2 rotates 330 degrees thus returning an angle between 0-330 degrees.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a potentiometer\n *\n * \\param potentiometer\n *        The adi_potentiometer_t object for which the angle will be returned\n *\n * \\return The potentiometer angle in degrees.\n * \n * \\b Example\n * \\code\n * #define POTENTIOMETER_PORT 1\n * \n * void opcontrol() {\n *   adi_potentiometer_t potentiometer = adi_potentiometer_t(POTENTIOMETER_PORT);\n *   while (true) {\n *     // Print the potnetiometer's angle\n *     printf(\"Angle: %lf\\n\", adi_potentiometer_get_angle(potentiometer));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\ndouble adi_potentiometer_get_angle(adi_potentiometer_t potentiometer);\n\n/**\n * Reference type for an initialized addressable led.\n *\n * This merely contains the port number for the led, unlike its use as an\n * object to store led data in the C++ API.\n */\ntypedef int32_t adi_led_t;\n\n/**\n * Initializes a led on the given port of the original led.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - The ADI port given is not a valid port as defined below\n * EADDRINUSE - The port is not configured for ADI output\n *\n * \\param port\n *        The ADI port to initialize as a led (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return An adi_led_t object containing the given port, or PROS_ERR if the\n * initialization failed, setting errno\n * \n * \\b Example\n * \\code\n * #define LED_PORT 1\n * \t\n * void opcontrol() {\n *   adi_led_t led = adi_led_init(LED_PORT);\n *   uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000};\n *   while (true) {\n *     // Set the led to the colors in the buffer\n *     adi_led_set(led, buffer, 10);\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nadi_led_t adi_led_init(uint8_t port);\n\n/**\n * @brief Clear the entire led strip of color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - A given value is not correct, or the buffer is null\n * EADDRINUSE - The port is not configured for ADI output\n *\n * @param led port of type adi_led_t\n * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw\n * @param buffer_length length of buffer to clear\n * @return PROS_SUCCESS if successful, PROS_ERR if not\n * \n * \\b Example\n * \\code\n * #define LED_PORT 1\n * \t\n * void opcontrol() {\n *   adi_led_t led = adi_led_init(LED_PORT);\n * \t uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000};\n *   while (true) {\n * \t   // Set the led to the colors in the buffer\n *     adi_led_set(led, buffer, 10);\n *     delay(5);\n * \n *     // Clear the led strip\n *     adi_led_clear(led);\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_led_clear_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_length);\n\n/**\n * @brief Set the entire led strip using the colors contained in the buffer\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - A given value is not correct, or the buffer is null\n * EADDRINUSE - The port is not configured for ADI output\n *\n * @param led port of type adi_led_t\n * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw\n * @param buffer_length length of buffer to clear\n * @return PROS_SUCCESS if successful, PROS_ERR if not\n * \n * \\b Example\n * \\code\n * #define LED_PORT 1\n * \t\n * void opcontrol() {\n *   adi_led_t led = adi_led_init(LED_PORT);\n *   uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000};\n *   while (true) {\n *     // Set the led strip to the colors in the buffer\n *     adi_led_set(led, buffer, 10);\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_led_set(adi_led_t led, uint32_t* buffer, uint32_t buffer_length);\n\n/**\n * @brief Set the entire led strip to one color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - A given value is not correct, or the buffer is null\n * EADDRINUSE - The port is not configured for ADI output\n *\n * @param led port of type adi_led_t\n * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw\n * @param buffer_length length of buffer to clear\n * @param color color to set all the led strip value to\n * @return PROS_SUCCESS if successful, PROS_ERR if not\n * \n * \\b Example\n * \\code\n * #define LED_PORT 1\n * \t\n * void opcontrol() {\n *   adi_led_t led = adi_led_init(LED_PORT);\n *   uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000};\n *   while (true) {\n *     // Set the led strip to red\n *     adi_led_set_all(led, buffer, 10, 0xFF0000);\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_led_set_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color);\n\n/**\n * @brief Set one pixel on the led strip\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - A given value is not correct, or the buffer is null\n * EADDRINUSE - The port is not configured for ADI output\n *\n * @param led port of type adi_led_t\n * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw\n * @param buffer_length length of the input buffer\n * @param color color to clear all the led strip to\n * @param pixel_position position of the pixel to clear\n * @return PROS_SUCCESS if successful, PROS_ERR if not\n * \t\n * \\b Example\n * \\code\n * #define LED_PORT 1\n * \n * void opcontrol() {\n *   adi_led_t led = adi_led_init(LED_PORT);\n *   uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000};\n *   while (true) {\n *     // Set the first pixel to red\n *     adi_led_set_pixel(led, buffer, 10, 0xFF0000, 0);\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_led_set_pixel(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color, uint32_t pixel_position);\n\n/**\n * @brief Clear one pixel on the led strip\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - A given value is not correct, or the buffer is null\n * EADDRINUSE - The port is not configured for ADI output\n *\n * @param led port of type adi_led_t\n * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw\n * @param buffer_length length of the input buffer\n * @param pixel_position position of the pixel to clear\n * @return PROS_SUCCESS if successful, PROS_ERR if not\n * \n * \\b Example\n * \\code\n * #define LED_PORT 1\n * \t\n * void opcontrol() {\n *   adi_led_t led = adi_led_init(LED_PORT);\n *   uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000};\n *   while (true) {\n *     // Set the first pixel to red\n *     adi_led_set_pixel(led, buffer, 10, 0xFF0000, 0);\n *     delay(5);\n * \n *     // Clear the first pixel\n *     adi_led_clear_pixel(led, buffer, 10, 0);\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t adi_led_clear_pixel(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t pixel_position);\n\n/**\n * \\name Ease of use macro definitions\n * These functions provide ease of use definitions for the ADI functions. \n * @{\n */\n\n/**\n * Used for adi_digital_write() to specify a logic HIGH state to output.\n *\n * In reality, using any non-zero expression or \"true\" will work to set a pin to\n * HIGH.\n */\n#define HIGH 1\n/**\n * Used for adi_digital_write() to specify a logic LOW state to output.\n *\n * In reality, using a zero expression or \"false\" will work to set a pin to LOW.\n */\n#define LOW 0\n\n/**\n * adi_pin_mode() state for a digital input.\n */\n#define INPUT 0x00\n/**\n * adi_pin_mode() state for a digital output.\n */\n#define OUTPUT 0x01\n/**\n * adi_pin_mode() state for an analog input.\n */\n#define INPUT_ANALOG 0x02\n\n/**\n * adi_pin_mode() state for an analog output.\n */\n#define OUTPUT_ANALOG 0x03\n\n/** @} Name: Ease of use macro definitions*/\n\n/** @} Add to group: c-adi*/\n\n#ifdef __cplusplus\n}  // namespace c\n}  // namespace pros\n}\n#endif\n\n#endif  // _PROS_ADI_H_\n"
  },
  {
    "path": "include/pros/adi.hpp",
    "content": "/**\n * \\file pros/adi.hpp\n * \\ingroup cpp-adi\n *\n * Contains prototypes for interfacing with the ADI.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-adi ADI (TriPort) C++ API\n * \\note The external ADI API can be found [here.](@ref ext-adi)\n * \\note Additional example code for this module can be found in its [Tutorial.](@ref adi)\n */\n\n#ifndef _PROS_ADI_HPP_\n#define _PROS_ADI_HPP_\n\n#include <cstdint>\n#include <iostream>\n#include <tuple>\n#include <utility>\n#include <vector>\n\n#include \"pros/adi.h\"\n\n#define LEGACY_TYPEDEF(old_name, new_name) using old_name [[deprecated(\"use \" #new_name \" instead\")]] = new_name\n\nnamespace pros {\nnamespace adi {\n\n/** type definition for the pair of smart port and adi port for the basic adi devices */\nusing ext_adi_port_pair_t = std::pair<std::uint8_t, std::uint8_t>;\n\n/** type definition for the triplet of smart port and two adi ports for the two wire adi devices*/\nusing ext_adi_port_tuple_t = std::tuple<std::uint8_t, std::uint8_t, std::uint8_t>;\n\n/**\n * \\ingroup cpp-adi\n */\nclass Port {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\n\tpublic:\n\t/**\n\t * Configures an ADI port to act as a given sensor type.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port\n\t *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t * \\param type\n\t *        The configuration type for the port\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define POTENTIOMETER_PORT 1\n\t * #define POTENTIOMETER_TYPE pros::E_ADI_POT_EDR\n\t *\n\t * void opcontrol() {\n\t *   pros::ADIPotentiometer potentiometer (POTENTIOMETER_PORT, POTENTIOMETER_TYPE);\n\t *   while (true) {\n\t *     // Get the potentiometer angle\n\t *     std::cout << \"Angle: \" << potnetiometer.get_angle();\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit Port(std::uint8_t adi_port, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED);\n\n\t/**\n\t * Configures an ADI port on an adi expander to act as a given sensor type.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param port_pair\n\t *        The pair of the smart port number (from 1-22) and the ADI port number\n\t * \t\t  (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t * \\param type\n\t * \t\t  The configuration type for the port\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ANALOG_SENSOR_PORT 'a'\n\t * #define EXT_ADI_SMART_PORT 1\n\t *\n\t * void initialize() {\n\t *   pros::adi::Port sensor ({EXT_ADI_SMART_PORT, ANALOG_SENSOR_PORT}, E_ADI_ANALOG_IN);\n\t *   // Displays the value of E_ADI_ANALOG_IN\n\t *   std::cout << \"Port Type: \" << sensor.get_config();\n\t * }\n\t * \\endcode\n\t */\n\texplicit Port(ext_adi_port_pair_t port_pair, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED);\n\n\t/**\n\t * Gets the configuration for the given ADI port.\n\t *\n\t * \\return The ADI configuration for the given port\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ANALOG_SENSOR_PORT 1\n\t *   void initialize() {\n\t *     adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN);\n\t *     // Displays the value of E_ADI_ANALOG_IN\n\t *     printf(\"Port Type: %d\\n\", adi_port_get_config(ANALOG_SENSOR_PORT));\n\t *   }\n\t * \\endcode\n\t */\n\tstd::int32_t get_config() const;\n\n\t/**\n\t * Gets the value for the given ADI port.\n\t *\n\t * \\return The value stored for the given port\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ANALOG_SENSOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Port sensor (ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN);\n\t *   std::cout << \"Port Value: \" << sensor.get_value();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_value() const;\n\n\t/**\n\t * Configures an ADI port to act as a given sensor type.\n\t *\n\t * \\param type\n\t *        The configuration type for the port\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ANALOG_SENSOR_PORT 1\n\t *\n\t * void initialize() {\n\t *   pros::adi::Port sensor (ANALOG_SENSOR_PORT, E_ADI_DIGITAL_IN);\n\t *   // Do things as a digital sensor\n\t *   // Digital is unplugged and an analog is plugged in\n\t *   sensor.set_config(E_ADI_ANALOG_IN);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_config(adi_port_config_e_t type) const;\n\n\t/**\n\t * Sets the value for the given ADI port.\n\t *\n\t * This only works on ports configured as outputs, and the behavior will\n\t * change depending on the configuration of the port.\n\t *\n\t * \\param value\n\t *        The value to set the ADI port to\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DIGITAL_SENSOR_PORT 1\n\t *\n\t * void initialize() {\n\t *   pros::adi::Port sensor (DIGITAL_SENSOR_PORT, E_ADI_DIGITAL_OUT);\n\t *   sensor.set_value(DIGITAL_SENSOR_PORT, HIGH);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_value(std::int32_t value) const;\n\n\t/**\n\t * Gets the port of the sensor.\n\t *\n\t * \\return returns a tuple of integer ports.\n\t *\n\t * \\note The parts of the tuple are {smart port, adi port, second adi port (when applicable)}.\n\t *\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DIGITAL_SENSOR_PORT 1 // 'A'\n\t *\n\t * void initialize() {\n\t *   pros::adi::AnalogIn sensor (DIGITAL_SENSOR_PORT);\n\t *\n\t * \t // Getting values from the tuple using std::get<index>\n\t * \t int sensorSmartPort = std::get<0>(sensor.get_port()); // First value\n\t *   int sensorAdiPort = std::get<1>(sensor.get_port()); // Second value\n\t *\n\t * \t // Prints the first and second value from the port tuple (The Adi Port. The first value is the Smart Port)\n\t *   printf(\"Sensor Smart Port: %d\\n\", sensorSmartPort);\n\t *   printf(\"Sensor Adi Port: %d\\n\", sensorAdiPort);\n\t * }\n\t * \\endcode\n\t */\n\tvirtual ext_adi_port_tuple_t get_port() const;\n\n\tprotected:\n\tstd::uint8_t _smart_port;\n\tstd::uint8_t _adi_port;\n};\n///@}\n\nclass AnalogIn : protected Port {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Configures an ADI port to act as an Analog Input.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port\n\t *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ANALOG_SENSOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::ADIAnalogIn sensor (ANALOG_SENSOR_PORT);\n\t *   while (true) {\n\t *     // Use the sensor\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit AnalogIn(std::uint8_t adi_port);\n\n\t/**\n\t * Configures an ADI port to act as an Analog Input.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port\n\t *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define EXT_ADI_SENSOR_PORT 1\n\t * #define ADI_PORT 'a'\n\t *\n\t * void opcontrol() {\n\t *   pros::ADIAnalogIn sensor ({EXT_ADI_SMART_PORT, ADI_PORT});\n\t *   while (true) {\n\t *     // Use the sensor\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit AnalogIn(ext_adi_port_pair_t port_pair);\n\n\t/**\n\t * Calibrates the analog sensor on the specified port and returns the new\n\t * calibration value.\n\t *\n\t * This method assumes that the true sensor value is not actively changing at\n\t * this time and computes an average from approximately 500 samples, 1 ms\n\t * apart, for a 0.5 s period of calibration. The average value thus calculated\n\t * is returned and stored for later calls to the\n\t * pros::AnalogIn::get_value_calibrated() and\n\t * pros::AnalogIn::get_value_calibrated_HR() functions. These functions\n\t * will return the difference between this value and the current sensor value\n\t * when called.\n\t *\n\t * Do not use this function when the sensor value might be unstable (gyro\n\t * rotation, accelerometer movement).\n\t *\n\t * \\note The ADI currently returns data at 10ms intervals, in contrast to the\n\t * calibrate function’s 1ms sample rate.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as an analog input\n\t *\n\t * \\return The average sensor value computed by this function\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ANALOG_SENSOR_PORT 1\n\t *\n\t * void initialize() {\n\t *   pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT);\n\t *   sensor.calibrate(ANALOG_SENSOR_PORT);\n\t *   std::cout << \"Calibrated Reading:\" << sensor.get_value_calibrated();\n\t *   // All readings from then on will be calibrated\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t calibrate() const;\n\n\t/**\n\t * Gets the 12 bit calibrated value of an analog input port.\n\t *\n\t * The pros::adi::AnalogIn::calibrate() function must be run first. This\n\t * function is inappropriate for sensor values intended for integration, as\n\t * round-off error can accumulate causing drift over time. Use\n\t * pros::adi::AnalogIn::get_value_calibrated_HR() instead.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as an analog input\n\t *\n\t * \\return The difference of the sensor value from its calibrated default from\n\t * -4095 to 4095\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ANALOG_SENSOR_PORT 1\n\t *\n\t * void initialize() {\n\t *   pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT);\n\t *   sensor.calibrate(ANALOG_SENSOR_PORT);\n\t *   std::cout << \"Calibrated Reading:\" << sensor.get_value_calibrated();\n\t *   // All readings from then on will be calibrated\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_value_calibrated() const;\n\n\t/**\n\t * Gets the 16 bit calibrated value of an analog input port.\n\t *\n\t * The pros::adi::AnalogIn::calibrate() function must be run first. This is\n\t * intended for integrated sensor values such as gyros and accelerometers to\n\t * reduce drift due to round-off, and should not be used on a sensor such as a\n\t * line tracker or potentiometer.\n\t *\n\t * The value returned actually has 16 bits of \"precision\", even though the ADC\n\t * only reads 12 bits, so that error induced by the average value being\n\t * between two values when integrated over time is trivial. Think of the value\n\t * as the true value times 16.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as an analog input\n\t *\n\t * \\return The difference of the sensor value from its calibrated default from\n\t * -16384 to 16384\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ANALOG_SENSOR_PORT 1\n\t *\n\t * void initialize() {\n\t *   pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT);\n\t *   sensor.calibrate(ANALOG_SENSOR_PORT);\n\t *   std::cout << \"Calibrated Reading:\" << sensor.get_value_calibrated();\n\t *   // All readings from then on will be calibrated\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_value_calibrated_HR() const;\n\n\t/**\n\t * Reads an analog input channel and returns the 12-bit value.\n\t *\n\t * The value returned is undefined if the analog pin has been switched to a different mode. The meaning of the\n\t * returned value varies depending on the sensor attached.\n\t *\n\t * Inherited from ADIPort::get_value.\n\t *\n\t * This function uses the following values of errno when an error state is reached:\n\t * EADDRINUSE - The port is not configured as an analog input (e.g. the port has been reconfigured)\n\t *\n\t * \\return The analog sensor value, where a value of 0 reflects an input\n\t * voltage of nearly 0 V and a value of 4095 reflects an input voltage of\n\t * nearly 5 V\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ANALOG_SENSOR_PORT 1\n\t *\n\t * void initialize() {\n\t *   pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT);\n\t *   std::cout << \"Sensor Reading:\" << sensor.get_value();\n\t * }\n\t * \\endcode\n\t */\n\tusing Port::get_value;\n\n\t/**\n\t * This is the overload for the << operator for printing to streams\n\t *\n\t * Prints in format(this below is all in one line with no new line):\n\t * AnalogIn [smart_port: analog_in._smart_port, adi_port: analog_in._adi_port,\n\t * value calibrated: (12 bit calibrated value),\n\t * value calibrated HR: (16 bit calibrated value), value: (12 bit value)]\n\t */\n\tfriend std::ostream& operator<<(std::ostream& os, pros::adi::AnalogIn& analog_in);\n\n\tusing Port::get_port;\n};\n\n///@}\n\n// using ADIPotentiometer = ADIAnalogIn;\nusing LineSensor = AnalogIn;\nusing LightSensor = AnalogIn;\nusing Accelerometer = AnalogIn;\n\nclass AnalogOut : private Port {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Configures an ADI port to act as an Analog Output.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port\n\t *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ANALOG_SENSOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::AnalogOut sensor (ANALOG_SENSOR_PORT);\n\t *   // Use the sensor\n\t * }\n\t * @endcode\n\t */\n\texplicit AnalogOut(std::uint8_t adi_port);\n\n\t/**\n\t * Configures an ADI port on an adi_expander to act as an Analog Output.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param port_pair\n\t *        The pair of the smart port number (from 1-22) and the\n\t * \t\t  ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define EXT_ADI_SMART_PORT 1\n\t * #define ADI_PORT 'a'\n\t *\n\t * void opcontrol() {\n\t *   pros::AnalogOut sensor ({EXT_ADI_SMART_PORT, ADI_PORT});\n\t *   // Use the sensor\n\t * }\n\t * \\endcode\n\t */\n\texplicit AnalogOut(ext_adi_port_pair_t port_pair);\n\n\t/**\n\t * Sets the output for the Analog Output from 0 (0V) to 4095 (5V).\n\t *\n\t * Inherited from ADIPort::set_value.\n\t *\n\t * This function uses the following values of errno when an error state is reached:\n\t * EACCES - Another resource is currently trying to access the ADI.\n\t *\n\t * \\param value\n\t *        The value to set the ADI port to\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ANALOG_SENSOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::AnalogOut sensor (ANALOG_SENSOR_PORT);\n\t *   sensor.set_value(4095); // Set the port to 5V\n\t * }\n\t * \\endcode\n\t */\n\tusing Port::set_value;\n\n\tusing Port::get_port;\n\n\t/**\n\t * This is the overload for the << operator for printing to streams\n\t *\n\t * Prints in format(this below is all in one line with no new line):\n\t * AnalogOut [smart_port: analog_out._smart_port, adi_port: analog_out._adi_port,\n\t * value: (value)]\n\t */\n\tfriend std::ostream& operator<<(std::ostream& os, pros::adi::AnalogOut& analog_out);\n};\n///@}\n\nclass DigitalOut : private Port {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Configures an ADI port to act as a Digital Output.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port\n\t *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t * \\param init_state\n\t *        The initial state for the port\n\t *\n\t * \\b Example\n\t * \\code\n\t * \t#define DIGITAL_SENSOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   bool state = LOW;\n\t *   pros::adi::DigitalOut sensor (DIGITAL_SENSOR_PORT, state);\n\t *   while (true) {\n\t *     state != state;\n\t *     sensor.set_value(state);\n\t *     pros::delay(10); // toggle the sensor value every 50ms\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit DigitalOut(std::uint8_t adi_port, bool init_state = LOW);\n\n\t/**\n\t * Configures an ADI port on an adi_expander to act as a Digital Output.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param port_pair\n\t *        The pair of the smart port number (from 1-22) and the\n\t * \t\t  ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t * \\param init_state\n\t *        The initial state for the port\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define EXT_ADI_SMART_PORT 1\n\t * #define ADI_PORT 'a'\n\t *\n\t * void opcontrol() {\n\t *   bool state = LOW;\n\t *   pros::adi::DigitalOut sensor ({EXT_ADI_SMART_PORT , ADI_PORT});\n\t *   while (true) {\n\t *     state != state;\n\t *     sensor.set_value(state);\n\t *     pros::delay(10); // toggle the sensor value every 50ms\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit DigitalOut(ext_adi_port_pair_t port_pair, bool init_state = LOW);\n\n\t/**\n\t * Sets the digital value (1 or 0) of a pin.\n\t *\n\t * Inherited from ADIPort::set_value.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EADDRINUSE - The port is not configured as a digital output (e.g. the port has been reconfigured)\n\t *\n\t * \\param value\n\t *        The value to set the ADI port to\n\t *\n\t * \\return if the operation was successful or PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DIGITAL_SENSOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   bool state = LOW;\n\t *   pros::adi::DigitalOut sensor (DIGITAL_SENSOR_PORT);\n\t *   while (true) {\n\t *     state != state;\n\t *     sensor.set_value(state);\n\t *     pros::delay(10); // toggle the sensor value every 50ms\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tusing Port::set_value;\n\n\tusing Port::get_port;\n\n\t/**\n\t * This is the overload for the << operator for printing to streams\n\t *\n\t * Prints in format(this below is all in one line with no new line):\n\t * DigitalOut [smart_port: digital_out._smart_port, adi_port: digital_out._adi_port,\n\t * value: (value)]\n\t */\n\tfriend std::ostream& operator<<(std::ostream& os, pros::adi::DigitalOut& digital_out);\n};\n///@}\n\nclass DigitalIn : private Port {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Configures an ADI port to act as a Digital Input.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port\n\t *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DIGITAL_SENSOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::DigitalIn sensor (ANALOG_SENSOR_PORT);\n\t *   // Use the sensor\n\t * }\n\t * \\endcode\n\t */\n\texplicit DigitalIn(std::uint8_t adi_port);\n\n\t/**\n\t * Configures an ADI port on an adi_expander to act as a Digital Input.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param port_pair\n\t *        The pair of the smart port number (from 1-22) and the\n\t *  \t  ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define EXT_ADI_SMART_PORT 1\n\t * #define ADI_PORT 'a'\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::DigitalIn sensor ({EXT_ADI_SMART_PORT, ADI_PORT});\n\t *   // Use the sensor\n\t * }\n\t * \\endcode\n\t */\n\texplicit DigitalIn(ext_adi_port_pair_t port_pair);\n\n\t/**\n\t * Gets a rising-edge case for a digital button press.\n\t *\n\t * This function is not thread-safe.\n\t * Multiple tasks polling a single button may return different results under\n\t * the same circumstances, so only one task should call this function for any\n\t * given button. E.g., Task A calls this function for buttons 1 and 2. Task B\n\t * may call this function for button 3, but should not for buttons 1 or 2. A\n\t * typical use-case for this function is to call inside opcontrol to detect\n\t * new button presses, and not in any other tasks.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as a digital input\n\t *\n\t * \\return 1 if the button is pressed and had not been pressed the last time\n\t * this function was called, 0 otherwise.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DIGITAL_SENSOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::DigitalIn sensor (DIGITAL_SENSOR_PORT);\n\t *   while (true) {\n\t *     if (sensor.get_new_press()) {\n\t *       // Toggle pneumatics or other state operations\n\t *     }\n\t *   pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_new_press() const;\n\n\t/**\n\t * Gets the digital value (1 or 0) of a pin.\n\t *\n\t * Inherited from ADIPort::get_value.\n\t *\n\t * This function uses the following values of errno when an error state is reached:\n\t *\n\t * EADDRINUSE - The port is not configured as a digital input (e.g. the port has been reconfigured)\n\t *\n\t * Analogous to adi_digital_read.\n\t *\n\t * \\return The value stored for the given port\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DIGITAL_SENSOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::DigitalIn sensor (DIGITAL_SENSOR_PORT);\n\t *   while (true) {\n\t *     std::cout << \"Sensor Value:\" << sensor.get_value();\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tusing Port::get_value;\n\n\t/**\n\t * This is the overload for the << operator for printing to streams\n\t *\n\t * Prints in format(this below is all in one line with no new line):\n\t * DigitalIn [smart_port: digital_in._smart_port, adi_port: digital_in._adi_port,\n\t * value: (value)]\n\t */\n\tfriend std::ostream& operator<<(std::ostream& os, pros::adi::DigitalIn& digital_in);\n\n\tusing Port::get_port;\n};\n\n///@}\n\n// Derived Class(es) from DigitalIn\nusing Button = DigitalIn;\n\nclass Motor : private Port {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Configures an ADI port to act as a Motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port\n\t *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define MOTOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Motor motor (MOTOR_PORT);\n\t *   motor.set_value(127); // Go full speed forward\n\t *   std::cout << \"Commanded Motor Power: \" << motor.get_value(); // Will display 127\n\t *   delay(1000);\n\t *   motor.set_value(0); // Stop the motor\n\t * }\n\t * \\endcode\n\t */\n\texplicit Motor(std::uint8_t adi_port);\n\n\t/**\n\t * Configures an ADI port on an adi_expander to act as a Motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param port_pair\n\t *        The pair of the smart port number (from 1-22) and the\n\t *  \t  ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define EXT_ADI_SMART_PORT 1\n\t * #define ADI_MOTOR_PORT 'a'\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Motor motor ({EXT_ADI_SMART_PORT, ADI_MOTOR_PORT});\n\t *   motor.set_value(127); // Go full speed forward\n\t *   std::cout << \"Commanded Motor Power: \" << motor.get_value(); // Will display 127\n\t *   delay(1000);\n\t *   motor.set_value(0); // Stop the motor\n\t * }\n\t * \\endcode\n\t */\n\texplicit Motor(ext_adi_port_pair_t port_pair);\n\n\t/**\n\t * Stops the motor on the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as a motor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define MOTOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Motor motor (MOTOR_PORT);\n\t *   motor.set_value(127); // Go full speed forward\n\t *   std::cout << \"Commanded Motor Power: \" << motor.get_value(); // Will display 127\n\t *   delay(1000);\n\t *   motor.stop(); // Stop the motor\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t stop() const;\n\n\t/**\n\t * Sets the speed of the motor on the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as a motor\n\t *\n\t * \\param value\n\t *        The new signed speed; -127 is full reverse and 127 is full forward,\n\t *        with 0 being off\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define MOTOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Motor motor (MOTOR_PORT);\n\t *   motor.set_value(127); // Go full speed forward\n\t *   std::cout << \"Commanded Motor Power: \" << motor.get_value(); // Will display 127\n\t *   delay(1000);\n\t *   motor.set_value(0); // Stop the motor\n\t * }\n\t * \\endcode\n\t */\n\tusing Port::set_value;\n\n\t/**\n\t * Gets the last set speed of the motor on the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as a motor\n\t *\n\t * \\return The last set speed of the motor on the given\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define MOTOR_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Motor motor (MOTOR_PORT);\n\t *   motor.set_value(127); // Go full speed forward\n\t *   std::cout << \"Commanded Motor Power: \" << motor.get_value(); // Will display 127\n\t *   delay(1000);\n\t *   motor.set_value(0); // Stop the motor\n\t * }\n\t * \\endcode\n\t */\n\tusing Port::get_value;\n\n\tusing Port::get_port;\n};\n\n///@}\n\nclass Encoder : private Port {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Configures a set of ADI ports to act as an Encoder.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port_top\n\t *        The  \"top\" wire from the encoder sensor with the removable cover side up\n\t * \\param adi_port_bottom\n\t *       The \"bottom\" wire from the encoder sensor\n\t * \\param reverse\n\t *        If \"true\", the sensor will count in the opposite direction\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define PORT_TOP 1\n\t * #define PORT_BOTTOM 2\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false);\n\t *   // Use the sensor\n\t * }\n\t * \\endcode\n\t */\n\texplicit Encoder(std::uint8_t adi_port_top, std::uint8_t adi_port_bottom, bool reversed = false);\n\n\t/**\n\t * Configures a set of ADI ports on an adi_expander to act as an Encoder.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param port_tuple\n\t *        The tuple of the smart port number, the \"top\" wire from the encoder\n\t * \t\t  sensor with the removable cover side up, and the \"bottom\" wire from\n\t * \t\t  the encoder sensor\n\t * \\param reverse\n\t *        If \"true\", the sensor will count in theopposite direction\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define PORT_TOP 'A'\n\t * #define PORT_BOTTOM 'B'\n\t * #define SMART_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Encoder sensor ({ SMART_PORT, PORT_TOP, PORT_BOTTOM }, false);\n\t *   // Use the sensor\n\t * }\n\t * \\endcode\n\t */\n\texplicit Encoder(ext_adi_port_tuple_t port_tuple, bool reversed = false);\n\n\t/**\n\t * Sets the encoder value to zero.\n\t *\n\t * It is safe to use this method while an encoder is enabled. It is not\n\t * necessary to call this method before stopping or starting an encoder.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as a motor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define PORT_TOP 1\n\t * #define PORT_BOTTOM 2\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false);\n\t *   delay(1000); // Move the encoder around in this time\n\t *   sensor.reset(); // The encoder is now zero again\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t reset() const;\n\n\t/**\n\t * Gets the number of ticks recorded by the encoder.\n\t *\n\t * There are 360 ticks in one revolution.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as a motor\n\t *\n\t * \\return The signed and cumulative number of counts since the last start or\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define PORT_TOP 1\n\t * #define PORT_BOTTOM 2\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false);\n\t *   while (true) {\n\t *     std::cout << \"Encoder Value: \" << sensor.get_value();\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_value() const;\n\n\t/**\n\t * This is the overload for the << operator for printing to streams\n\t *\n\t * Prints in format(this below is all in one line with no new line):\n\t * Encoder [smart_port: encoder._smart_port, adi_port: encoder._adi_port,\n\t * value: (value)]\n\t */\n\tfriend std::ostream& operator<<(std::ostream& os, pros::adi::Encoder& encoder);\n\text_adi_port_tuple_t get_port() const override;\n\n\tprivate:\n\text_adi_port_pair_t _port_pair;\n};\n\n///@}\n\nclass Ultrasonic : private Port {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Configures a set of ADI ports to act as an Ultrasonic sensor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param port_ping\n\t *        The port connected to the orange OUTPUT cable. This should be in port\n\t *        1, 3, 5, or 7 ('A', 'C', 'E', 'G').\n\t * \\param port_echo\n\t *        The port connected to the yellow INPUT cable. This should be in the\n\t *        next highest port following port_ping.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define PORT_PING 1\n\t * #define PORT_ECHO 2\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Ultrasonic sensor (PORT_PING, PORT_ECHO);\n\t *   while (true) {\n\t *     // Print the distance read by the ultrasonic\n\t *     std::cout << \"Distance: \" << sensor.get_value();\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit Ultrasonic(std::uint8_t adi_port_ping, std::uint8_t adi_port_echo);\n\n\t/**\n\t * Configures a set of ADI ports on an adi_expander to act as an Ultrasonic sensor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param port_tuple\n\t *        The tuple of the smart port number, the port connected to the orange\n\t * \t\t  OUTPUT cable (1, 3, 5, 7 or 'A', 'C', 'E', 'G'), and the port\n\t * \t\t  connected to the yellow INPUT cable (the next) highest port\n\t * \t\t  following port_ping).\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define PORT_PING 'A'\n\t * #define PORT_ECHO 'B'\n\t * #define SMART_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Ultrasonic sensor ( {{ SMART_PORT, PORT_PING, PORT_ECHO }} );\n\t *   while (true) {\n\t *     // Print the distance read by the ultrasonic\n\t *     std::cout << \"Distance: \" << sensor.get_value();\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit Ultrasonic(ext_adi_port_tuple_t port_tuple);\n\n\t/**\n\t * Gets the current ultrasonic sensor value in centimeters.\n\t *\n\t * If no object was found, zero is returned. If the ultrasonic sensor was\n\t * never started, the return value is undefined. Round and fluffy objects can\n\t * cause inaccurate values to be returned.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as an ultrasonic\n\t *\n\t * \\return The distance to the nearest object in m^-4 (10000 indicates 1\n\t * meter), measured from the sensor's mounting points.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define PORT_PING 1\n\t * #define PORT_ECHO 2\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Ultrasonic sensor (PORT_PING, PORT_ECHO);\n\t *   while (true) {\n\t *     // Print the distance read by the ultrasonic\n\t *     std::cout << \"Distance: \" << sensor.get_value();\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_value() const;\n\n\tusing Port::get_port;\n};\n\n///@}\n\nclass Gyro : private Port {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Initializes a gyroscope on the given port. If the given port has not\n\t * previously been configured as a gyro, then this function starts a 1300ms\n\t * calibration period.\n\t *\n\t * It is highly recommended that an Gyro object be created in initialize()\n\t * when the robot is stationary to ensure proper calibration. If an Gyro\n\t * object is declared at the global scope, a hardcoded 1300ms delay at the\n\t * beginning of initialize will be necessary to ensure that the gyro's\n\t * returned values are correct at the beginning of autonomous/opcontrol.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port\n\t *        The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H')\n\t * \\param multiplier\n\t *        A scalar value that will be multiplied by the gyro heading value\n\t *        supplied by the\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GYRO_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Gyro gyro (GYRO_PORT);\n\t *   while (true) {\n\t *     // Get the gyro heading\n\t *     std::cout << \"Distance: \" << gyro.get_value();\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit Gyro(std::uint8_t adi_port, double multiplier = 1);\n\n\t/**\n\t * Initializes a gyroscope on the given port of an adi expander. If the given\n\t * port has not previously been configured as a gyro, then this function starts\n\t * a 1300ms calibration period.\n\t *\n\t * It is highly recommended that an adi::Gyro object be created in initialize()\n\t * when the robot is stationary to ensure proper calibration. If an adi::Gyro\n\t * object is declared at the global scope, a hardcoded 1300ms delay at the\n\t * beginning of initialize will be necessary to ensure that the gyro's\n\t * returned values are correct at the beginning of autonomous/opcontrol.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param port_pair\n\t *        The pair of the smart port number (from 1-22) and the\n\t *  \t  ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t * \\param multiplier\n\t *        A scalar value that will be multiplied by the gyro heading value\n\t *        supplied by the\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ADI_GYRO_PORT 'a'\n\t * #define SMART_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Gyro gyro ({SMART_PORT ,ADI_GYRO_PORT});\n\t *   while (true) {\n\t *     // Get the gyro heading\n\t *   std::cout << \"Distance: \" << gyro.get_value();\n\t *   pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit Gyro(ext_adi_port_pair_t port_pair, double multiplier = 1);\n\n\t/**\n\t * Gets the current gyro angle in tenths of a degree. Unless a multiplier is\n\t * applied to the gyro, the return value will be a whole number representing\n\t * the number of degrees of rotation times 10.\n\t *\n\t * There are 360 degrees in a circle, thus the gyro will return 3600 for one\n\t * whole rotation.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as a gyro\n\t *\n\t * \\return The gyro angle in degrees.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GYRO_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Gyro gyro (GYRO_PORT);\n\t *   while (true) {\n\t *   // Get the gyro heading\n\t *   std::cout << \"Distance: \" << gyro.get_value();\n\t *   pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_value() const;\n\n\t/**\n\t * Resets the gyroscope value to zero.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as a gyro\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GYRO_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Gyro gyro (GYRO_PORT);\n\t *   std::uint32_t now = pros::millis();\n\t *   while (true) {\n\t *     // Get the gyro heading\n\t *     std::cout << \"Distance: \" << gyro.get_value();\n\t *\n\t *   if (pros::millis() - now > 2000) {\n\t *     // Reset the gyro every 2 seconds\n\t *     gyro.reset();\n\t *     now = pros::millis();\n\t *   }\n\t *\n\t *   pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t reset() const;\n\n\tusing Port::get_port;\n};\n\n///@}\n\nclass Potentiometer : public AnalogIn {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Configures an ADI port to act as a Potentiometer.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port\n\t *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t * \\param potentiometer_type\n\t *        An adi_potentiometer_type_e_t enum value specifying the potentiometer version type\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define POTENTIOMETER_PORT 1\n\t * #define POTENTIOMETER_TYPE pros::E_ADI_POT_EDR\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Potentiometer potentiometer (POTENTIOMETER_PORT, POTENTIOMETER_TYPE);\n\t *   while (true) {\n\t *     // Get the potentiometer angle\n\t *     std::cout << \"Angle: \" << potentiometer.get_angle();\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit Potentiometer(std::uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR);\n\n\t/**\n\t * Configures an ADI port on an adi_expander to act as a Potentiometer.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port\n\t *        The pair of the smart port number (from 1-22) and the\n\t *  \t  ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t * \\param potentiometer_type\n\t *        An adi_potentiometer_type_e_t enum value specifying the potentiometer version type\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ADI_POTENTIOMETER_PORT 'a'\n\t * #define SMART_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Potentiometer potentiometer ({SMART_PORT, ADI_POTENTIOMETER_PORT});\n\t *   while (true) {\n\t *     // Get the potentiometer angle\n\t *     std::cout << \"Angle: \" << potentiometer.get_angle();\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit Potentiometer(ext_adi_port_pair_t port_pair, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR);\n\n\t/**\n\t * Gets the current potentiometer angle in tenths of a degree.\n\t *\n\t * The original potentiometer rotates 250 degrees thus returning an angle between 0-250 degrees.\n\t * Potentiometer V2 rotates 330 degrees thus returning an angle between 0-330 degrees.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of ADI Ports\n\t * EADDRINUSE - The port is not configured as a potentiometer\n\t *\n\t * \\return The potentiometer angle in degrees.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ADI_POTENTIOMETER_PORT 'a'\n\t * #define SMART_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Potentiometer potentiometer ({{ SMART_PORT , ADI_POTENTIOMETER_PORT }});\n\t *   while (true) {\n\t *     // Get the potentiometer angle\n\t *     std::cout << \"Angle: \" << potentiometer.get_angle();\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_angle() const;\n\n\t/**\n\t * Gets the 12-bit value of the specified port.\n\t *\n\t * The value returned is undefined if the analog pin has been switched to a\n\t * different mode.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as a potentiometer\n\t *\n\t * \\return The analog sensor value, where a value of 0 reflects an input\n\t * voltage of nearly 0 V and a value of 4095 reflects an input voltage of\n\t * nearly 5 V\n\t */\n\tusing AnalogIn::get_value;\n\n\t/**\n\t * Calibrates the potentiometer on the specified port and returns the new\n\t * calibration value.\n\t *\n\t * This method assumes that the potentiometer value is not actively changing at\n\t * this time and computes an average from approximately 500 samples, 1 ms\n\t * apart, for a 0.5 s period of calibration. The average value thus calculated\n\t * is returned and stored for later calls to the\n\t * pros::adi::Potentiometer::get_value_calibrated() function. This function\n\t * will return the difference between this value and the current sensor value\n\t * when called.\n\t *\n\t * Do not use this function when the potentiometer value might be unstable (rotating the potentiometer)\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as a potentiometer\n\t *\n\t * \\return The average potentiometer value computed by this function\n\t */\n\tusing AnalogIn::calibrate;\n\n\t/**\n\t * Gets the 12 bit calibrated value of a potentiometer port.\n\t *\n\t * The pros::adi::Potentiometer::calibrate() function must be run first.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port is not configured as a potentiometer\n\t *\n\t * \\return The difference of the potentiometer value from its calibrated default from\n\t * -4095 to 4095\n\t */\n\tusing AnalogIn::get_value_calibrated;\n\n\t/**\n\t * This is the overload for the << operator for printing to streams\n\t * Potentiometer [value: (value), value calibrated: (calibrated value),\n\t * angle: (angle)]\n\t * Prints in format(this below is all in one line with no new line):\n\t */\n\tfriend std::ostream& operator<<(std::ostream& os, pros::adi::Potentiometer& potentiometer);\n\n\tusing Port::get_port;\n};\n\n///@}\n\nclass Led : protected Port {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * @brief Configures an ADI port to act as a LED.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param adi_port\n\t *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t * \\param length\n\t *        The number of LEDs in the chain\n\t *\n\t * \\b Example:\n\t * \\code\n\t * #define LED_PORT 'a'\n\t * #define LED_LENGTH 3\n\t *\n\t * void opcontrol() {\n\t *   pros::Led led (LED_PORT, LED_LENGTH);\n\t *   while (true) {\n\t * \t   // Set entire LED strip to red\n\t *     led.set_all(0xFF0000);\n\t * \t   pros::delay(20);\n\t * \t }\n\t * }\n\t * \\endcode\n\t *\n\t */\n\texplicit Led(std::uint8_t adi_port, std::uint32_t length);\n\n\t/**\n\t * @brief Configures an ADI port on a adi_expander to act as a LED.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - Either the ADI port value or the smart port value is not within its\n\t *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n\t *\n\t * \\param port_pair\n\t *        The pair of the smart port number (from 1-22) and the\n\t *  \t  ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t * \\param length\n\t * \t  The number of LEDs in the chain\n\t *\n\t * \\b Example:\n\t * \\code\n\t * #define LED_PORT 'a'\n\t * #define SMART_PORT 1\n\t * #define LED_LENGTH 3\n\t *\n\t * void opcontrol() {\n\t *   pros::Led led ({SMART_PORT, LED_PORT}, LED_LENGTH);\n\t *   while (true) {\n\t *     // Set entire LED strip to red\n\t *     led.set_all(0xFF0000);\n\t * \t   pros::delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit Led(ext_adi_port_pair_t port_pair, std::uint32_t length);\n\n\t/**\n\t * @brief Operator overload to access the buffer in the ADILed class, it is\n\t * recommended that you call .update(); after doing any operations with this.\n\t *\n\t * @param i 0 indexed pixel of the lED\n\t * @return uint32_t& the address of the buffer at i to modify\n\t *\n\t * \\b Example:\n\t * \\code\n\t * #define LED_PORT 'a'\n\t * #define LED_LENGTH 3\n\t *\n\t * void opcontrol() {\n\t *   pros::Led led (LED_PORT, LED_LENGTH);\n\t *   while (true) {\n\t * \t   // Set the first 3 pixels to red, green, and blue\n\t * \t   led.set_pixel(0xFF0000, 0);\n\t * \t   led.set_pixel(0x00FF00, 1);\n\t * \t   led.set_pixel(0x0000FF, 2);\n\t * \t   pros::delay(20);\n\t *\n\t * \t   // Use the [] operator to set the first pixel to black\n\t * \t   led.operator[](0) = 0x000000;\n\t * \t   led.update();\n\t * \t   pros::delay(20);\n\t *   }\n\t * }\n\t */\n\tstd::uint32_t& operator[](size_t i);\n\n\t/**\n\t * @brief Clear the entire led strip of color\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of ADI Ports\n\t * EINVAL - A parameter is out of bounds/incorrect\n\t * EADDRINUSE - The port is not configured for ADI output\n\t *\n\t * @return PROS_SUCCESS if successful, PROS_ERR if not\n\t *\n\t * \\b Example:\n\t * \\code\n\t * #define LED_PORT 'a'\n\t * #define LED_LENGTH 3\n\t *\n\t * void opcontrol() {\n\t *   pros::Led led (LED_PORT, LED_LENGTH);\n\t *   while (true) {\n\t * \t   // Set the first 3 pixels to red, green, and blue\n\t * \t   led.set_pixel(0xFF0000, 0);\n\t * \t   led.set_pixel(0x00FF00, 1);\n\t * \t   led.set_pixel(0x0000FF, 2);\n\t * \t   pros::delay(20);\n\t *\n\t * \t   // Clear the led strip of color\n\t * \t   led.clear();\n\t * \t   pros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t clear_all();\n\tstd::int32_t clear();\n\n\t/**\n\t * @brief Force the LED strip to update with the current buffered values, this\n\t * should be called after any changes to the buffer using the [] operator.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - A parameter is out of bounds/incorrect\n\t * EADDRINUSE - The port is not configured for ADI output\n\t *\n\t * @return PROS_SUCCESS if successful, PROS_ERR if not\n\t *\n\t * \\b Example:\n\t * \\code\n\t * #define LED_PORT 'a'\n\t * #define LED_LENGTH 3\n\t *\n\t * void opcontrol() {\n\t *   pros::Led led (LED_PORT, LED_LENGTH);\n\t *   while (true) {\n\t * \t   // Set the first 3 pixels to red, green, and blue\n\t * \t   led.set_pixel(0xFF0000, 0);\n\t * \t   led.set_pixel(0x00FF00, 1);\n\t * \t   led.set_pixel(0x0000FF, 2);\n\t * \t   pros::delay(20);\n\t *\n\t * \t   // Use the [] operator to set the first pixel to black\n\t * \t   led.operator[](0) = 0x000000;\n\t *      // Update the led strip with the new values\n\t * \t   led.update();\n\t * \t   pros::delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t update() const;\n\n\t/**\n\t * @brief Set the entire led strip to one color\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - A parameter is out of bounds/incorrect\n\t * EADDRINUSE - The port is not configured for ADI output\n\t *\n\t * @param color color to set all the led strip value to\n\t * @return PROS_SUCCESS if successful, PROS_ERR if not\n\t *\n\t * \\b Example:\n\t * \\code\n\t * #define LED_PORT 'a'\n\t * #define LED_LENGTH 3\n\t *\n\t * void opcontrol() {\n\t *   pros::Led led (LED_PORT, LED_LENGTH);\n\t *   while (true) {\n\t * \t   // Set the entire led strip to blue\n\t * \t   led.set_all(0x0000FF);\n\t * \t   pros::delay(20);\n\t * \t }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_all(uint32_t color);\n\n\t/**\n\t * @brief Set one pixel on the led strip\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - A parameter is out of bounds/incorrect\n\t * EADDRINUSE - The port is not configured for ADI output\n\t *\n\t * @param color color to clear all the led strip to\n\t * @param pixel_position position of the pixel to clear\n\t * @return PROS_SUCCESS if successful, PROS_ERR if not\n\t *\n\t * \\b Example:\n\t * \\code\n\t * #define LED_PORT 'a'\n\t * #define LED_LENGTH 3\n\t *\n\t * void opcontrol() {\n\t *   pros::Led led (LED_PORT, LED_LENGTH);\n\t *   while (true) {\n\t * \t   // Set the first pixel to blue\n\t * \t   led.set_pixel(0x0000FF, 0);\n\t * \t   pros::delay(20);\n\t * \t }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_pixel(uint32_t color, uint32_t pixel_position);\n\n\t/**\n\t * @brief Clear one pixel on the led strip\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - A parameter is out of bounds/incorrect\n\t * EADDRINUSE - The port is not configured for ADI output\n\t *\n\t * @param pixel_position position of the pixel to clear\n\t * @return PROS_SUCCESS if successful, PROS_ERR if not\n\t *\n\t * \\b Example:\n\t * \\code\n\t * #define LED_PORT 'a'\n\t * #define LED_LENGTH 3\n\t *\n\t * void opcontrol() {\n\t *   pros::Led led (LED_PORT, LED_LENGTH);\n\t *   while (true) {\n\t * \t   // Set the first pixel to blue\n\t * \t   led.set_pixel(0x0000FF, 0);\n\t * \t   pros::delay(20);\n\t *\n\t * \t   // Clear the first pixel\n\t * \t   led.clear_pixel(0);\n\t * \t   pros::delay(20);\n\t * \t}\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t clear_pixel(uint32_t pixel_position);\n\n\t/**\n\t * @brief Get the length of the led strip\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - A parameter is out of bounds/incorrect\n\t * EADDRINUSE - The port is not configured for ADI output\n\t *\n\t * @return The length (in pixels) of the LED strip\n\t *\n\t * \\b Example:\n\t * \\code\n\t * #define LED_PORT 'a'\n\t * #define LED_LENGTH 3\n\t *\n\t * void opcontrol() {\n\t *   pros::Led led (LED_PORT, LED_LENGTH);\n\t *   while (true) {\n\t * \t   // Get the length of the led strip\n\t * \t   int length = led.length();\n\t * \t   pros::lcd::print(1, \"Length: %d\", length);\n\t * \t   pros::delay(20);\n\t * \t }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t length();\n\n\tusing Port::get_port;\n\n\tprotected:\n\tstd::vector<uint32_t> _buffer;\n};\n///@}\n\n/// @brief Alias for ADILed\nusing LED = Led;\n\nclass Pneumatics : public DigitalOut {\n\t/**\n\t * \\addtogroup cpp-adi\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Creates a Pneumatics object for the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of ADI Ports\n\t *\n\t * \\param adi_port\n\t *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t * \\param start_extended\n\t * \t\t  If true, the pneumatic will start extended when the program starts.\n\t *\t\t  By default, the piston starts retracted when the program starts.\n\t * \\param extended_is_low\n\t * \t\t  A flag to set whether the the pneumatic is extended when the ADI\n\t * \t\t  it receives a high or a low value. When true, the extended state\n\t * \t\t  corresponds to a output low on the ADI port. This allows the user\n\t * \t\t  to reverse the behavior of the pneumatics if needed.\n\t *\n\t * /b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \t pros::adi::Pneumatics left_piston('a', false);\t\t\t// Starts retracted, extends when the ADI port is high\n\t *   pros::adi::Pneumatics right_piston('b', false, true);\t// Starts retracted, extends when the ADI port is low\n\t *\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *\n\t *   while (true) {\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L1)) {\n\t *       left_piston.extend();\n\t *     }\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L2)) {\n\t *       left_piston.retract();\n\t *     }\n\t *\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R1)) {\n\t *       left_piston.extend();\n\t *     }\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_2)) {\n\t *       left_piston.retract();\n\t *     }\n\t *\n\t *     pros::delay(10);\n\t *   }\n\t *\n\t * \\endcode\n\t */\n\texplicit Pneumatics(std::uint8_t adi_port, bool start_extended, bool extended_is_low = false);\n\n\t/**\n\t * Creates a Pneumatics object for the given port pair.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of ADI Ports\n\t *\n\t * \\param port_pair\n\t *        The pair of the smart port number (from 1-22) and the\n\t *  \t  ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n\t * \\param start_extended\n\t * \t\t  If true, the pneumatic will start extended when the program starts.\n\t *\t\t  By default, the piston starts retracted when the program starts.\n\t * \\param extended_is_low\n\t * \t\t  A flag to set whether the the pneumatic is extended when the ADI\n\t * \t\t  it receives a high or a low value. When true, the extended state\n\t * \t\t  corresponds to a output low on the ADI port. This allows the user\n\t * \t\t  to reverse the behavior of the pneumatics if needed.\n\t *\n\t * /b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \t pros::adi::Pneumatics left_piston({1, 'a'}, false);\t\t\t// Starts retracted, extends when the ADI port is high\n\t *   pros::adi::Pneumatics right_piston({1, 'b'}, false, true);\t    // Starts retracted, extends when the ADI port is\n\t *low\n\t *\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *\n\t *   while (true) {\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L1)) {\n\t *       left_piston.extend();\n\t *     }\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L2)) {\n\t *       left_piston.retract();\n\t *     }\n\t *\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R1)) {\n\t *       left_piston.extend();\n\t *     }\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R2)) {\n\t *       left_piston.retract();\n\t *     }\n\t *\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\texplicit Pneumatics(ext_adi_port_pair_t port_pair, bool start_extended, bool extended_is_low = false);\n\n\t/**\n\t * Extends the piston, if not already extended.\n\t *\n\t * \\return 1 if the piston newly extended, 0 if the piston was already\n\t *         extended, or PROS_ERR is the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \t pros::adi::Pneumatics piston({1, 'a'}, false);            // Starts retracted, extends when the ADI port is high\n\t *\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *\n\t *   while (true) {\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) {\n\t *       left_piston.extend();\n\t *     }\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) {\n\t *       left_piston.retract();\n\t *     }\n\t *     if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) {\n\t *       left_piston.toggle();\n\t *     }\n\t *\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t extend();\n\n\t/**\n\t * Retracts the piston, if not already retracted.\n\t *\n\t * \\return 1 if the piston newly retracted, 0 if the piston was already\n\t *         retracted, or PROS_ERR is the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \t pros::adi::Pneumatics piston({1, 'a'}, false);            // Starts retracted, extends when the ADI port is high\n\t *\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *\n\t *   while (true) {\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) {\n\t *       left_piston.extend();\n\t *     }\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) {\n\t *       left_piston.retract();\n\t *     }\n\t *     if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) {\n\t *       left_piston.toggle();\n\t *     }\n\t *\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t retract();\n\n\t/**\n\t * Puts the piston into the opposite state of its current state.\n\t * If it is retracted, it will extend. If it is extended, it will retract.\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\return 1 if the piston successfully toggled, or PROS_ERR if the\n\t *         operation failed, setting errno.\n\t *\n\t *\\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \t pros::adi::Pneumatics piston({1, 'a'}, false);            // Starts retracted, extends when the ADI port is high\n\t *\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *\n\t *   while (true) {\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) {\n\t *       left_piston.extend();\n\t *     }\n\t *     if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) {\n\t *       left_piston.retract();\n\t *     }\n\t *     if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) {\n\t *       left_piston.toggle();\n\t *     }\n\t *\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t toggle();\n\n\t/**\n\t * Returns whether the piston is extended or not.\n\t *\n\t * \\return true if the piston is extended, false if it is retracted.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ADI_PNEUMATICS_PORT 'a'\n\t *\n\t * void opcontrol() {\n\t *   pros::adi::Pneumatics pneumatics (ADI_PNEUMATICS_PORT);\n\t *   while (true) {\n\t *     // Check if the piston is extended\n\t *     if (pneumatics.is_extended()) {\n\t *       printf(\"The pneumatic is extended\\n\");\n\t *     }\n\t *     else {\n\t *       printf(\"The pneumatic is not extended\\n\");\n\t *     }\n\t *\n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tbool is_extended() const;\n\n\tprivate:\n\tbool state;            // Holds the physical state of the ADI port\n\tbool extended_is_low;  // A flag that sets whether extended corresponds to\n\t                       // a low signal\n};\n///@}\n\n}  // namespace adi\n\n/*\nPros4 upgrade backwards compatibility for ADI api.\n\nPrints a deprecated warning when user uses old pros::ADIDevice style API.\nRemove when and if fully removing old API.\n*/\nLEGACY_TYPEDEF(ADIPort, pros::adi::Port);\nLEGACY_TYPEDEF(ADIAnalogIn, pros::adi::AnalogIn);\nLEGACY_TYPEDEF(ADIAnalogOut, pros::adi::AnalogOut);\nLEGACY_TYPEDEF(ADIDigitalIn, pros::adi::DigitalIn);\nLEGACY_TYPEDEF(ADIDigitalOut, pros::adi::DigitalOut);\nLEGACY_TYPEDEF(ADIMotor, pros::adi::Motor);\nLEGACY_TYPEDEF(ADIGyro, pros::adi::Gyro);\nLEGACY_TYPEDEF(ADIEncoder, pros::adi::Encoder);\nLEGACY_TYPEDEF(ADIUltrasonic, pros::adi::Ultrasonic);\nLEGACY_TYPEDEF(LED, pros::adi::Led);\n\n// Backwards Compatibility for Derived Classes\nLEGACY_TYPEDEF(ADIPotentiometer, pros::adi::Potentiometer);\nLEGACY_TYPEDEF(ADILineSensor, pros::adi::LineSensor);\nLEGACY_TYPEDEF(ADILightSensor, pros::adi::LightSensor);\nLEGACY_TYPEDEF(ADIAccelerometer, pros::adi::Accelerometer);\nLEGACY_TYPEDEF(ADIButton, pros::adi::Button);\nLEGACY_TYPEDEF(ADIPneumatics, pros::adi::Pneumatics);\nLEGACY_TYPEDEF(ADILED, pros::adi::Led);\nLEGACY_TYPEDEF(ADILed, pros::adi::Led);\n\n}  // namespace pros\n\n#endif  // _PROS_ADI_HPP_"
  },
  {
    "path": "include/pros/ai_vision.h",
    "content": "/**\n * \\file pros/aivision.h\n * \\ingroup c-aivision\n *\n * Contains prototypes for the VEX AI Vision Sensor-related functions.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup c-aivision AI Vision Sensor C API\n * \\note Additional example code for this module can be found in its [Tutorial.](@ref aivision)\n */\n\n#ifndef _PROS_AIVISION_H_\n#define _PROS_AIVISION_H_\n\n/**\n * \\addtogroup c-aivision\n *  @{\n */\n\n/// \\name Macros\n/// Parameters given by VEX\n///@{\n\n#define AIVISION_MAX_OBJECT_COUNT 24\n#define AIVISION_MAX_CLASSNAME_COUNT 20\n#define AIVISION_MODE_TAG_SET_BIT (1 << 29)\n\n///@}\n\n///@}\n\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\n#endif\n\n/**\n * \\addtogroup c-aivision\n *  @{\n */\n\n/**\n * \\enum aivision_detected_type_e_t\n * This enumeration defines what kind of object is stored inside the union in aivision_object_s\n */\ntypedef enum aivision_detected_type {\n\tE_AIVISION_DETECTED_COLOR = (1 << 0),\n\tE_AIVISION_DETECTED_CODE = (1 << 1),\n\tE_AIVISION_DETECTED_OBJECT = (1 << 2),\n\tE_AIVISION_DETECTED_TAG = (1 << 3)\n} aivision_detected_type_e_t;\n\n/**\n * \\enum aivision_mode_type_e_t\n * This enumeration defines what kinds of objects the ai vision sensor will scan for:\n * tags (april tags), colors (user defined colors), and objects (game elements), and all (all objects)\n */\n\ntypedef enum aivision_mode_type {\n\tE_AIVISION_MODE_TAGS = (1 << 0),\n\tE_AIVISION_MODE_COLORS = (1 << 1),\n\tE_AIVISION_MODE_OBJECTS = (1 << 2),\n\tE_AIVISION_MODE_COLOR_MERGE = (1 << 4),\n\tE_AIVISION_MODE_ALL = (1 << 0) | (1 << 1) | (1 << 2),\n} aivision_mode_type_e_t;\n\n/**\n * \\struct aivision_color_s_t\n * This structure contains the parameters used by the AI Vision Sensor to define a color. hue_range and saturation_range\n * are ranges for hue and saturation that are acceptable.\n * For example, if a large hue range is specified for a blue color, colors that are more magenta or teal may be detected\n * as \"blue\".\n */\ntypedef struct aivision_color_s {\n\tuint8_t id;             /**< id of color descriptor, can range from 1-7 */\n\tuint8_t red;            /**< red value of color */\n\tuint8_t green;          /**< green value of color */\n\tuint8_t blue;           /**< blue value of color */\n\tfloat hue_range;        /**< range by which detected color's hue can vary from the base color, can range from 1-40 */\n\tfloat saturation_range; /**< range by which detected color's saturation can vary from base color, can range from 0.1-1 */\n} aivision_color_s_t;\n\n/**\n * \\struct aivision_code_s_t\n * This structure contains the parameters used by the AI Vision sensor to define a code.\n * Codes are a combination of color descriptors, and tells the AI Vision sensor to merge objects\n * close to each other that belong to the given color descriptors into a single object that matches\n * the code descriptor.\n * Codes must use at least 2, and no greater than 5, color descriptors.\n */\ntypedef struct aivision_code_s {\n\tuint8_t id;     /**< id of code descriptor, can range from 1-5 */\n\tuint8_t length; /**< number of color descriptors used by this code. */\n\tint16_t c1;     /**< id of first color descriptor */\n\tint16_t c2;     /**< id of second color descriptor */\n\tint16_t c3;     /**< id of third color descriptor */\n\tint16_t c4;     /**< id of fourth color descriptor */\n\tint16_t c5;     /**< id of fifth color descriptor */\n} aivision_code_s_t;\n\n/**\n * \\enum aivision_tag_family_e_t\n * This enumeration corresponds to a family of AprilTags.\n * \\see https://april.eecs.umich.edu/software/apriltag\n */\ntypedef enum aivision_tag_family_e {\n\tTAG_CIRCLE_21H7 = 0,\n\tTAG_16H5 = 1,\n\tTAG_25H9 = 2,\n\tTAG_61H11 = 3\n} aivision_tag_family_e_t;\n\n/**\n * \\struct aivision_object_color_s_t\n * This structure contains a detected color.\n */\ntypedef struct __attribute__((packed)) aivision_object_color_s {\n\tuint16_t xoffset;  // left edge (from camera's view)\n\tuint16_t yoffset;  // top edge\n\tuint16_t width;\n\tuint16_t height;\n\tuint16_t angle;  // angle, in tenths of a degree\n} aivision_object_color_s_t;\n\n/**\n * \\struct aivision_object_tag_s_t\n * This structure contains a detected tag.\n */\ntypedef struct __attribute__((packed)) aivision_object_tag_s {\n\tint16_t x0;\n\tint16_t y0;\n\tint16_t x1;\n\tint16_t y1;\n\tint16_t x2;\n\tint16_t y2;\n\tint16_t x3;\n\tint16_t y3;\n} aivision_object_tag_s_t;\n\ntypedef struct __attribute__((packed)) aivision_object_element_s {\n\tuint16_t xoffset;  // left\n\tuint16_t yoffset;  // top\n\tuint16_t width;\n\tuint16_t height;\n\tuint16_t score;  // confidence that this struct is\n} aivision_object_element_s_t;\n/**\n * \\struct aivision_object_s_t\n * This structure contains one of aivision_detected_type_e_t, stored in type\n *\n * If the object is a color, id stores the color's id\n * If the object is an April Tag, id stores the tag's id\n * If the object is an AI model element, id stores the element id as per\n * https://api.vex.com/v5/home/cpp/AiVision/AiObjdesc.html\n */\ntypedef struct __attribute__((packed)) aivision_object_s {\n\tuint8_t id;    // object id\n\tuint8_t type;  // object type\n\tunion {\n\t\taivision_object_color_s_t color;\n\t\taivision_object_tag_s_t tag;\n\t\taivision_object_element_s_t element;\n\t} object;\n} aivision_object_s_t;\n/// @}\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n/**\n * \\addtogroup c-aivision\n *  @{\n */\n/// \\name Functions\n\n/**\n * Resets the AI Vision sensor to the initial state.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n *\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define AIVISION_PORT 1\n * void initialize() {\n *   aivision_reset(AIVISION_PORT);\n * }\n * \\endcode\n */\nint32_t aivision_reset(uint8_t port);\n\n/**\n * Returns a bitfield of the types of objects the AI vision sensor is currently searching for,\n * as per aivision_mode_type_e_t.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\return the bitfield if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define AIVISION_PORT 1\n * void initialize() {\n *   aivision_get_enabled_detection_types(AIVISION_PORT);\n * }\n * \\endcode\n */\nint32_t aivision_get_enabled_detection_types(uint8_t port);\n\n/**\n * Modifies the types of objects the AI vision sensor is currently searching for, as per aivision_mode_type_e_t.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\b Example\n * aivision_set_enabled_detection_types(1, 0b010, 0b101) would disable the detection of tags and objects,\n * and leave the setting of colors alone.\n *\n * \\param port The V5 port number from 1-21\n * \\param bits the bits to set\n * \\param bitmask the bitmask to apply\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n */\nint32_t aivision_set_enabled_detection_types(uint8_t port, uint8_t bits, uint8_t bitmask);\n\n/**\n * Enable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.\n * Enabling any given type of object will not disable the detection of other objects.\n * This must be done explicitly.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\b Example\n * \\code\n * #define AIVISION_PORT 1\n * void initialize() {\n *   // start or continue looking for AI model objects\n * \t aivision_enable_detection_types(AIVISION_PORT, aivision_mode_type_e_t::E_AIVISION_MODE_OBJECTS);\n * }\n * \\endcode\n *\n * \\param port The V5 port number from 1-21\n * \\param types_mask The types to enable\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n */\nint32_t aivision_enable_detection_types(uint8_t port, uint8_t types_mask);\n\n/**\n * Disable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.\n * Disabling any given type of object will not affect the detection of other objects.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\b Example\n * \\code\n * #define AIVISION_PORT 1\n * void initialize() {\n *   // stop looking for AI model objects (competition elements, for example)\n * \t aivision_disable_detection_types(AIVISION_PORT, aivision_mode_type_e_t::E_AIVISION_MODE_OBJECTS);\n * }\n * \\endcode\n *\n * \\param port The V5 port number from 1-21\n * \\param types_mask The types to enable\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n */\nint32_t aivision_disable_detection_types(uint8_t port, uint8_t types_mask);\n\n/**\n * Sets the april tag family to detect. Use this function will override the enabled apriltag\n * detection family.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\param family the tag family to configure the AI Vision sensor to detect\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n */\nint32_t aivision_set_tag_family_override(uint8_t port, aivision_tag_family_e_t family);\n\n/**\n * Sets the april tag family to detect. Use this function will allow multiple apriltags\n * to be detected.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\param family the tag family to configure the AI Vision sensor to detect\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n */\nint32_t aivision_set_tag_family(uint8_t port, aivision_tag_family_e_t family);\n\n/**\n * Set a color configuration that the AI vision sensor will detect.\n * The color detection type must be separately enabled.\n * If a color with the same ID already is stored in the sensor, it will be overwritten.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\param color the color to configure the AI Vision sensor to detect\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno\n */\nint32_t aivision_set_color(uint8_t port, const aivision_color_s_t* color);\n\n/**\n * Get a color configuration that the AI vision sensor has stored.\n * If you attempt to get a color configuration that has not been previously used, the\n * behavior is not defined.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\param id the id of color from 1-7\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno\n */\naivision_color_s_t aivision_get_color(uint8_t port, uint32_t id);\n\n/**\n * Get a class name that the AI vision sensor has stored.\n * The AI Vision sensor may not correctly report classnames for the first several hundred milliseconds\n * of being plugged in.\n * By passing in -1 for the id, the function will return the number of class names the AI vision sensor reports.\n * For other values of id, the function return value is undefined\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\param id the id of the class name from 0-(AIVISION_MAX_CLASSNAME_COUNT - 1)\n * \\param class_name a string of length >=20 to store the classname.\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno\n */\nint32_t aivision_get_class_name(uint8_t port, int32_t id, uint8_t* class_name);\n\n/**\n * Enable or disable the bounding box overlay the AI Vision sensor outputs on the USB port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\param enabled if the overlay is enabled or disabled\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno\n */\nint32_t aivision_set_usb_bounding_box_overlay(uint8_t port, bool enabled);\n\n/**\n * Runs auto white balance to adjust to different lighting conditions.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno\n */\nint32_t aivision_start_awb(uint8_t port);\n\n/**\n * Get a code that the AI vision sensor has stored.\n *\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\param id The id from 1-5\n * \\return the code, or a struct with an invalid ID if the operation failed, setting errno\n */\naivision_code_s_t aivision_get_code(uint8_t port, uint32_t id);\n\n/**\n * Set a code that the AI vision sensor will detect for.\n * The id of the code is stored in the aivision_code_s_t struct. If there is already a code\n * stored in the AI vision sensor with the id, this function will overwrite.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\param code The code to set\n * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n * failed, setting errno\n */\nint32_t aivision_set_code(uint8_t port, const aivision_code_s_t* wcode);\n\n/**\n * Get the current number of objects detected by the AI vision sensor.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\return the number of objects if the operation was successful or PROS_ERR if the operation failed, setting errno\n */\nint32_t aivision_get_object_count(uint8_t port);\n\n/**\n * Get the detected object at a given object index; there are aivision_get_object_count objects and the index starts\n * from 0.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * @param port The V5 port number from 1-21\n * @param object_index the object index\n * @return the detected object if the operation was successful or an invalid object type if the operation failed,\n * setting errno\n */\naivision_object_s_t aivision_get_object(uint8_t port, uint32_t object_index);\n\n/**\n * Get the current reported temperature of the AI Vision sensor in degrees Celsius.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port The V5 port number from 1-21\n * \\return the temperature if the operation was successful or PROS_ERR_F if the operation failed, setting errno\n */\ndouble aivision_get_temperature(uint8_t port);\n\n///@}\n\n#ifdef __cplusplus\n}  // namespace c\n}  // namespace pros\n}\n#endif\n\n#endif  // _PROS_VISION_H_"
  },
  {
    "path": "include/pros/ai_vision.hpp",
    "content": "/**\n * \\file pros/aivision.hpp\n * \\ingroup cpp-aivision\n *\n * Contains prototypes for the VEX AI Vision Sensor-related functions in C++.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-aivision AI Vision Sensor C++ API\n * \\note Additional example code for this module can be found in its [Tutorial.](@ref aivision)\n */\n\n#ifndef _PROS_AIVISION_HPP_\n#define _PROS_AIVISION_HPP_\n\n#include <cstdint>\n#include <type_traits>\n#include <expected>\n\n#include \"pros/ai_vision.h\"\n#include \"pros/device.hpp\"\n\nnamespace pros {\ninline namespace v5 {\n\n/**\n * \\enum AivisionDetectType\n * \\ingroup cpp-aivision\n * Enum class for describing detection type of objects detected by the AI Vision Sensor.\n */\nenum class AivisionDetectType : uint8_t {\n\tcolor = (1 << 0), /**< object was detected based on color descriptor */\n\tcode = (1 << 1), /**< object was detected based on code descriptor */\n\tobject = (1 << 2), /**< object was detected using AI model */\n\ttag = (1 << 3) /**< object was detected as an AprilTag */\n};\n\n/**\n * \\enum AivisionModeType\n * \\ingroup cpp-aivision\n * Enum class for enabling/disabling detection types of AI Vision Sensor.\n */\nenum class AivisionModeType : uint8_t {\n\ttags = (1 << 0), /**< AprilTag detection */\n\tcolors = (1 << 1), /**< color and code detection */\n\tobjects = (1 << 2), /**< AI model object detection */\n\tcolor_merge = (1 << 4), /**< merge adjacent color detections */\n\tall = (1 << 0) | (1 << 1) | (1 << 2),\n};\n\n/**\n * \\enum AivisionTagFamily\n * \\ingroup cpp-aivision\n * Enum class for describing family of apriltags to detect.\n */\nenum class AivisionTagFamily { tag_21H7 = 0, tag_16H5 = 1, tag_25H9 = 2, tag_61H11 = 3 };\n\n/**\n * \\ingroup cpp-aivision\n */\nclass AIVision : public Device {\n\t/**\n\t * \\addtogroup cpp-aivision\n\t *  @{\n\t */\n\tpublic:\n\n\tusing Color = aivision_color_s_t;\n\tusing Code = aivision_code_s_t;\n\tusing Object = aivision_object_s_t;\n\n\t/**\n\t * Create a AI Vision Sensor object on the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an AI vision sensor\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::AIVision ai_sensor(2); // Creates a vision sensor on port two\n\t * }\n\t * \\endcode\n\t */\n\texplicit AIVision(const std::uint8_t port);\n\n\tAIVision(const Device& device) : AIVision(device.get_port()){};\n\n\t/**\n\t * Gets all vision sensors.\n\t *\n\t * \\return A vector of AIVision sensor objects.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   std::vector<AIVision> aivision_all = pros::AIVision::get_all_devices();  // All AI vision sensors that are\n\t * connected\n\t * }\n\t * \\endcode\n\t */\n\tstatic std::vector<AIVision> get_all_devices();\n\n\t/**\n\t * Check if the dected type is the same as the given type.\n\t *\n\t * \\return true if the type is the same, false otherwise\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::AIVision aivision(1);\n\t *   pros::AIVision::Object object = aivision.get_object(0);\n\t *   if (AIVision::is_type(AivisionDetectType::color, object)) {\n\t *       printf(\"is color\\n\");\n\t *   } else if (AIVision::is_type(AivisionDetectType::object, object)) {\n\t *       printf(\"is object\\n\");\n\t *   } else if (AIVision::is_type(AivisionDetectType::code, object)) {\n\t *       printf(\"is code\\n\");\n\t *   } else if (AIVision::is_type(AivisionDetectType::tag, object)) {\n\t *       printf(\"is tag\\n\");\n\t *   } else {\n\t *       printf(\"unknown\\n\");\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstatic bool is_type(const Object& object, AivisionDetectType type);\n\n\t/**\n\t * Resets the AI Vision sensor to the initial state.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\n\t *\n\t * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void initialize() {\n\t *   pros::AIVision aivision(AIVISION_PORT);\n\t *   aivision.reset();\n\t * }\n\t * \\endcode\n\t */\n\tint32_t reset();\n\n\t/**\n\t * Returns a bitfield of the types of objects the AI vision sensor is currently searching for,\n\t * as per AivisionModeType.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\n\t * \\return the bitfield if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void initialize() {\n\t *   pros::AIVision aivision(AIVISION_PORT);\n\t *   int32_t enabled_types = aivision.get_enabled_detection_types();\n\t *   printf(\"is tag: %d\\n\", enabled_types | AivisionModeType::tags);\n\t * }\n\t * \\endcode\n\t */\n\tint32_t get_enabled_detection_types();\n\n\t/**\n\t * Enable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.\n\t * Enabling any given type of object will not disable the detection of other objects.\n\t * This must be done explicitly.\n\t *\n\t * For this function you must use bitwise or to combine the types you want to enable.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void initialize() {\n\t *   pros::AIVision aivision(AIVISION_PORT);\n\t *   // start or continue looking for AI model objects\n\t *   // enable aivision to look for tags and objects\n\t * \t aivision.enable_detection_types(AivisionModeType::tags | AivisionModeType::objects);\n\t * }\n\t * \\endcode\n\t *\n\t * \\param types_mask The types to enable\n\t * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tint32_t enable_detection_types(AivisionModeType types_mask);\n\n\t/**\n\t * Enable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.\n\t * Enabling any given type of object will not disable the detection of other objects.\n\t * This must be done explicitly.\n\t *\n\t * For this function you can use comma separated values to combine the types you want to enable.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void initialize() {\n\t *   pros::AIVision aivision(AIVISION_PORT);\n\t *   // start or continue looking for AI model objects\n\t *   // enable aivision to look for tags and objects\n\t * \t aivision.enable_detection_types(AivisionModeType::tags, AivisionModeType::objects);\n\t * }\n\t * \\endcode\n\t *\n\t * \\param types_mask The types to enable\n\t * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\ttemplate <class... Flags>\n\t  requires((std::conjunction_v<std::is_same<AivisionModeType, Flags>...>))\n\tint32_t enable_detection_types(Flags... flags) {\n\t\tauto types_mask = (static_cast<uint8_t>(flags) | ...);\n\t\treturn c::aivision_enable_detection_types(this->_port, static_cast<uint8_t>(types_mask));\n\t}\n\n\t/**\n\t * Disable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.\n\t * Disabling any given type of object will not affect the detection of other objects.\n\t *\n\t * For this function you must use bitwise or to combine the types you want to disable.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void initialize() {\n\t *   pros::AIVision aivision(AIVISION_PORT);\n\t *   // stop looking for AI model objects (competition elements, for example)\n\t *   // disable aivision to look for tags and objects\n\t * \t aivision.disable_detection_types(AivisionModeType::tags | AivisionModeType::objects);\n\t * }\n\t * \\endcode\n\t *\n\t * \\param types_mask The types to enable\n\t * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tint32_t disable_detection_types(AivisionModeType types_mask);\n\n\t/**\n\t * Disable detecting these types of objects, a bitmask as per aivision_mode_type_e_t.\n\t * Disabling any given type of object will not affect the detection of other objects.\n\t *\n\t * For this function you can use comma separated values to combine the types you want to disable.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void initialize() {\n\t *   pros::AIVision aivision(AIVISION_PORT);\n\t *   // stop looking for AI model objects (competition elements, for example)\n\t *   // disable aivision to look for tags and objects\n\t * \t aivision.disable_detection_types(AivisionModeType::tags | AivisionModeType::objects);\n\t * }\n\t * \\endcode\n\t *\n\t * \\param types_mask The types to enable\n\t * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\ttemplate <class... Flags>\n\t  requires((std::conjunction_v<std::is_same<AivisionModeType, Flags>...>))\n\tint32_t disable_detection_types(Flags... flags) {\n\t\tauto types_mask = (static_cast<uint8_t>(flags) | ...);\n\t\treturn c::aivision_disable_detection_types(this->_port, static_cast<uint8_t>(types_mask));\n\t}\n\n\t/**\n\t * Sets the april tag family to detect.\n\t * If override is true, the AI vision sensor will only look for the given family.\n\t * Otherwise, it will add the given tag to the list of enabled tags.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void initialize() {\n\t *   pros::AIVision aivision(AIVISION_PORT);\n\t *   // set the only tag family to look for to 21H7\n\t *   aivision.set_tag_family(AivisionTagFamily::tag_21H7);\n\t *   // add 16H5 to the list of enabled tag families\n\t *   aivision.set_tag_family(AivisionTagFamily::tag_16H5);\n\t *   // set the only tag family to look for to 25H9\n\t *   aivision.set_tag_family(AivisionTagFamily::tag_25H9, true);\n\t * }\n\t * \\endcode\n\t *\n\t * \\param family the tag family to configure the AI Vision sensor to detect\n\t * \\param override if true, the given family will be set as the only enabled tag family.\n\t * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t */\n\tint32_t set_tag_family(AivisionTagFamily family, bool override = false);\n\n\t/**\n\t * Set a color configuration that the AI vision sensor will detect.\n\t * The color detection type must be separately enabled.\n\t * If a color with the same ID already is stored in the sensor, it will be overwritten.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void opcontrol() {\n\t *   pros::AIVision aivision(AIVISION_PORT);\n\t *   AIVision::Color color = {1, 207, 19, 25, 10.00, 0.20};\n\t *   aivision.set_color(color);\n\t * }\n\t * \\endcode\n\t *\n\t * \\param color the color to configure the AI Vision sensor to detect\n\t * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno\n\t */\n\tint32_t set_color(const Color& color);\n\n\t/**\n\t * Get a color configuration that the AI vision sensor has stored.\n\t * If you attempt to get a color configuration that has not been previously used, the\n\t * behavior is not defined.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t *\n\t * #define AIVISION_PORT 1\n\t * void opcontrol() {\n\t *  pros::AIVision aivision(AIVISION_PORT);\n\t *  AIVision::Code color = aivision.get_color(0);\n\t *  printf(\"id: %d, red: %d, green: %d, blue: %d, hue_range: %f, saturation_range: %f\\n\",\n\t *  color.id, color.red, color.green, color.blue, color.hue_range, color.saturation_range);\n\t * }\n\t *\n\t * \\param id the id of color from 1-7\n\t * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno\n\t */\n\tAIVision::Color get_color(uint32_t id);\n\n\t/**\n\t * Set a code that the AI vision sensor will detect for.\n\t * The id of the code is stored in the aivision_code_s_t struct. If there is already a code\n\t * stored in the AI vision sensor with the id, this function will overwrite.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\code\n\t *\n\t * #define AIVISION_PORT 1\n\t * void opcontrol() {\n\t *  pros::AIVision aivision(AIVISION_PORT);\n\t *  AIVision::Code code = {1, 207, 19, 25, 10.00, 0.20};\n\t *  aivision.set_code(code);\n\t * }\n\t *\n\t * \\endcode\n\t *\n\t * \\param code The code to set\n\t * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno\n\t */\n\tuint32_t set_code(const Code& code);\n\n\t/**\n\t * Get a code that the AI vision sensor has stored.\n\t *\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\code\n\t *\n\t * #define AIVISION_PORT 1\n\t * void opcontrol() {\n\t *  pros::AIVision aivision(AIVISION_PORT);\n\t *  AIVision::Code code = aivision.get_code(0);\n\t *  printf(\"id: %d, length: %d, c1: %d, c2: %d, c3: %d, c4: %d, c5: %d\\n\",\n\t *  code.id, code.length, code.c1, code.c2, code.c3, code.c4, code.c5);\n\t *  )\n\t * }\n\t *\n\t * \\endcode\n\t *\n\t * \\param id The id from 1-5\n\t * \\return the code, or a struct with an invalid ID if the operation failed, setting errno\n\t */\n\tAIVision::Code get_code(uint32_t id);\n\n\t/**\n\t * Runs auto white balance to adjust to different lighting conditions.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno\n\t */\n\tint32_t start_awb();\n\n\t/**\n\t * Get a class name that the AI vision sensor has stored.\n\t * The AI Vision sensor may not correctly report classnames for the first several hundred milliseconds\n\t * of being plugged in.\n\t * By passing in -1 for the id, the function will return the number of class names the AI vision sensor reports.\n\t * For other values of id, the function return value is undefined\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void opcontrol() {\n\t *  pros::AIVision aivision(AIVISION_PORT);\n\t *  char* class_name = new char[21];\n\t *  aivision.get_class_name(0, class_name);\n\t *  printf(\"%s\\n\", class_name);\n\t *  delete[] class_name;\n\t * }\n\t *\n\t * \\endcode\n\t *\n\t * \\param id the id of the class name from 0-(AIVISION_MAX_CLASSNAME_COUNT - 1)\n\t * \\param class_name a string of length >=20 to store the classname.\n\t * \\return PROS_SUCCESS if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno\n\t */\n\tint32_t get_class_name(int32_t id, char* class_name);\n\n\t/**\n\t * Get a class name that the AI vision sensor has stored.\n\t * The AI Vision sensor may not correctly report classnames for the first several hundred milliseconds\n\t * of being plugged in.\n\t * By passing in -1 for the id, the function will return the number of class names the AI vision sensor reports.\n\t * For other values of id, the function return value is undefined\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void opcontrol() {\n\t *  pros::AIVision aivision(AIVISION_PORT);\n\t *  auto name = aivision.get_class_name(1);\n\t *\n\t *  if(name.has_value()) {\n\t *\t  printf(\"Class name: %s\\n\", name.value().c_str());\n\t *  } else {\n\t *\t  printf(\"Error: %ld\\n\", errno);\n\t *  }\n\t * }\n\t *\n\t * \\endcode\n\t *\n\t * \\param id the id of the class name from 0-(AIVISION_MAX_CLASSNAME_COUNT - 1)\n\t * \\return the class name string in std::optional if the operation was successful\n\t * or an empty optional if the operation failed, setting errno\n\t */\n\tstd::optional<std::string> get_class_name(int32_t id);\n\n\t/**\n\t * Get the current number of objects detected by the AI vision sensor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void opcontrol() {\n\t *  pros::AIVision aivision(AIVISION_PORT);\n\t *  int32_t object_count = aivision.get_object_count();\n\t *  printf(\"%d\\n\", object_count);\n\t * }\n\t * \\endcode\n\t *\n\t * \\return the number of objects if the operation was successful or PROS_ERR if the operation failed, setting errno\n\t */\n\tint32_t get_object_count();\n\n\t/**\n\t * Get the detected object at a given object index; there are aivision_get_object_count objects and the index starts\n\t * from 0.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void opcontrol() {\n\t *  pros::AIVision aivision(AIVISION_PORT);\n\t *  int32_t object_count = aivision.get_object_count();\n\t *  for (int i = 0; i < object_count; i++) {\n\t *  \tpros::AIVision::Object object = aivision.get_object(i);\n\t *  \tprintf(\"Object %d: %d\\n\", i, object.type);\n\t *  }\n\t * }\n\t *\n\t * \\endcode\n\t *\n\t * @param object_index the object index\n\t * @return the detected object if the operation was successful or an invalid object type if the operation failed,\n\t * setting errno\n\t */\n\tObject get_object(uint32_t object_index);\n\n\t/**\n\t * Get all detected objects in a vector.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\code\n\t * #define AIVISION_PORT 1\n\t * void opcontrol() {\n\t *  pros::AIVision aivision(AIVISION_PORT);\n\t *  auto objects = aivision.get_all_objects();\n\t *  for (const auto& object : objects) {\n\t *    printf(\"Object %d: %d\\n\", object.id, object.type);\n\t *  }\n\t * }\n\t * \\endcode\n\t *\n\t * @return a vector of all detected objects\n\t */\n\tstd::vector<Object> get_all_objects();\n\t/// @}\n};\n}  // namespace v5\n}  // namespace pros\n#endif  // _PROS_VISION_HPP_\n"
  },
  {
    "path": "include/pros/apix.h",
    "content": "/**\n * \\file pros/apix.h\n * \\ingroup apix\n *\n * PROS Extended API header\n *\n * Contains additional declarations for use by advaned users of PROS. These\n * functions do not typically have as much error handling or require deeper\n * knowledge of real time operating systems.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup apix Extended API\n * \\note Also included in the Extended API is [LVGL.](https://lvgl.io/)\n */\n\n#ifndef _PROS_API_EXTENDED_H_\n#define _PROS_API_EXTENDED_H_\n\n#include \"api.h\"\n#include \"pros/device.h\"\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Wall\"\n#pragma GCC diagnostic pop\n#include \"pros/serial.h\"\n\n#ifdef __cplusplus\n#include \"pros/serial.hpp\"\nnamespace pros::c {\nextern \"C\" {\n#endif\n\n/**\n * \\ingroup apix\n */\n\n/**\n * \\addtogroup apix\n *  @{\n */\n\n/// \\name RTOS Facilities\n///@{\n\ntypedef void* queue_t;\ntypedef void* sem_t;\n\n/**\n * Unblocks a task in the Blocked state (e.g. waiting for a delay, on a\n * semaphore, etc.).\n *\n * \\param task\n *        The task to unblock\n *\n * \\return True if the task was unblocked, false otherwise\n * \n * \\b Example:\n * \\code\n * task_t task = task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn\");\n * task_delay(1000);\n * // in another task somewhere else, this will abort the task_delay bove:\n * task_abort_delay(task);\n * \\endcode\n */\nbool task_abort_delay(task_t task);\n\n/**\n * Notify a task when a target task is being deleted.\n *\n * \\param target_task\n *\t\t\t\tThe task being watched for deletion\n * \\param task_to_notify\n *        The task to notify when target_task is deleted\n * \\param value\n *\t\t\t\tThe value to supply to task_notify_ext\n * \\param notify_action\n * \t\t\t\tThe action to supply to task_notify_ext\n * \n    * \\b Example:\n    * \\code\n    * task_t task_to_delete = task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n    *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn\");\n    * task_t task_to_notify = task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n    *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn2\");\n    * \n    * task_notify_ext(task_to_notify, 0, NOTIFY_ACTION_INCREMENT, NULL);\n    * \n    * task_notify_when_deleting(task_to_delete, task_get_current(), 0, NOTIFY_ACTION_NONE);\n    * task_delete(task_to_delete);\n    * \\endcode\n */\nvoid task_notify_when_deleting(task_t target_task, task_t task_to_notify, uint32_t value,\n                               notify_action_e_t notify_action);\n\n/**\n * Returns a handle to the current owner of a mutex.\n *\n * \\param mutex\n *        A mutex handle\n *\n * \\return A handle to the current task that owns the mutex, or NULL if the\n * mutex isn't owned.\n * \n * \\b Example:\n * \\code\n * mutex_t mutex = mutex_create();\n *\n * void task_fn(void* param) {\n *   while(1) {\n *     mutex_take(mutex, 1000);\n *     // critical section\n *     mutex_give(mutex);\n *     task_delay(1000);\n *   }\n * }\n * task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn\");\n *\n * void opcontrol(void) {\n*   while (1) {\n*     if (joystick_get_digital(1, 7, JOY_UP)) {\n*       task_t owner = mutex_get_owner(mutex);\n*       if (owner != NULL) {\n*         printf(\"Mutex is owned by task %s\", task_get_name(owner));\n*       } else {\n*         printf(\"Mutex is not owned\");\n*       }\n*     }\n*     task_delay(20);\n*   }\n* }\n * \\endcode\n */\ntask_t mutex_get_owner(mutex_t mutex);\n\n/**\n * Creates a counting sempahore.\n *\n * \\param max_count\n *        The maximum count value that can be reached.\n * \\param init_count\n *        The initial count value assigned to the new semaphore.\n *\n * \\return A newly created semaphore. If an error occurred, NULL will be\n * returned and errno can be checked for hints as to why sem_create failed.\n *\n * \\b Example:\n * \\code\n * // Binary semaphore acts as a mutex\n * sem_t sem = sem_create(1, 0);\n *\n * void task_fn(void* param) {\n *   while(1) {\n *     sem_take(sem, 1000);\n *     // critical section\n *     sem_give(sem);\n *     task_delay(1000);\n *   }\n * }\n * task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn\");\n *\n * \\endcode\n */\nsem_t sem_create(uint32_t max_count, uint32_t init_count);\n\n/**\n * Deletes a semaphore (or binary semaphore)\n *\n * \\param sem\n * \t\t\t  Semaphore to delete\n *\n * \\b Example:\n * \\code\n * // Binary semaphore acts as a mutex\n * sem_t sem = sem_create(1, 0);\n * \n * void task_fn(void* param) { \n *   while(1) {\n *     sem_take(sem, 1000);\n *     // critical section\n *     sem_give(sem);\n *     task_delay(1000);\n *   }\n * }\n * task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn\");\n *\n * void opcontrol(void) {\n *   while (1) {\n *     if (joystick_get_digital(1, 7, JOY_UP)) {\n *       // honestly this is a bad example because you should never \n *       // delete a semaphore like this\n *       sem_delete(sem);\n *     }\n *     task_delay(20);\n *   }\n * }\n * \n * \\endcode\n */\nvoid sem_delete(sem_t sem);\n\n/**\n * Creates a binary semaphore.\n *\n * \\return A newly created semaphore.\n * \n * \\b Example:\n * \\code\n * // Binary semaphore acts as a mutex\n * sem_t sem = sem_binary_create();\n *\n * void task_fn(void* param) {\n *   while(1) {\n *     sem_take(sem, 1000);\n *     // critical section\n *     sem_give(sem);\n *     task_delay(1000);\n *   }\n * }\n * task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn\");\n *\n * \\endcode\n */\nsem_t sem_binary_create(void);\n\n/**\n * Waits for the semaphore's value to be greater than 0. If the value is already\n * greater than 0, this function immediately returns.\n *\n * \\param sem\n *        Semaphore to wait on\n * \\param timeout\n *        Time to wait before the semaphore's becomes available. A timeout of 0\n *        can be used to poll the sempahore. TIMEOUT_MAX can be used to block\n *        indefinitely.\n *\n * \\return True if the semaphore was successfully take, false otherwise. If\n * false is returned, then errno is set with a hint about why the sempahore\n * couldn't be taken.\n * \n * \\b Example:\n * \\code\n * // Binary semaphore acts as a mutex\n * sem_t sem = sem_create(1, 0);\n *\n * void task_fn(void* param) {\n *   while(1) {\n *     if(!sem_wait(sem, 1000)) {\n *       printf(\"Failed to take semaphore\");\n *       task_delay(1000);\n *       continue;\n *     }\n *     // critical section\n *     sem_give(sem);\n *     task_delay(1000);\n *   }\n * }\n * task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn\");\n *\n * void opcontrol(void) {\n *   while (1) {\n *     if (sem_wait(sem, 0))) {\n *       printf(\"Semaphore is available\");\n *     }\n *     task_delay(20);\n *   }\n * }\n * \\endcode\n */\nbool sem_wait(sem_t sem, uint32_t timeout);\n\n/**\n * Increments a semaphore's value.\n *\n * \\param sem\n *        Semaphore to post\n *\n * \\return True if the value was incremented, false otherwise. If false is\n * returned, then errno is set with a hint about why the semaphore couldn't be\n * taken.\n * \n * \\b Example:\n * \\code\n * // Binary semaphore acts as a mutex\n * sem_t sem = sem_create(1, 0);\n *\n * void task_fn(void* param) {\n *   while(1) {\n *     sem_post(sem); // increments, mimicking to \"claim\"\n *     // critical section\n *     sem_give(sem);\n *     task_delay(1000);\n *   }\n * }\n * task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn\");\n *\n * \\endcode\n */\nbool sem_post(sem_t sem);\n\n/**\n * Returns the current value of the semaphore.\n *\n * \\param sem\n *        A semaphore handle\n *\n * \\return The current value of the semaphore (e.g. the number of resources\n * available)\n * \n * \\b Example of sem_get_count:\n * \\code\n * // Binary semaphore acts as a mutex\n * sem_t sem = sem_create(1, 0);\n * printf(\"semaphore count: %d\", sem_get_count(sem));\n *  // semaphore count: 0\n * sem_take(sem, 1000);\n * printf(\"semaphore count: %d\", sem_get_count(sem));\n *  // semaphore count: 1\n * sem_give(sem);\n * printf(\"semaphore count: %d\", sem_get_count(sem));\n *  // semaphore count: 0\n *\n * \\endcode\n */\nuint32_t sem_get_count(sem_t sem);\n\n/**\n * Creates a queue.\n *\n * \\param length\n *        The maximum number of items that the queue can contain.\n * \\param item_size\n *        The number of bytes each item in the queue will require.\n *\n * \\return A handle to a newly created queue, or NULL if the queue cannot be\n * created.\n * \n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   queue_t queue = queue_create(10, sizeof(int));\n *   int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n *   queue_prepend(queue, item, 1000);\n *   queue_append(queue, item, 1000);\n *   printf(\"queue length: %d\", queue_get_length(queue));\n * }\n * \\endcode\n */\nqueue_t queue_create(uint32_t length, uint32_t item_size);\n\n/**\n * Posts an item to the front of a queue. The item is queued by copy, not by\n * reference.\n *\n * \\param queue\n *        The queue handle\n * \\param item\n *        A pointer to the item that will be placed on the queue.\n * \\param timeout\n *        Time to wait for space to become available. A timeout of 0 can be used\n *        to attempt to post without blocking. TIMEOUT_MAX can be used to block\n *        indefinitely.\n *\n * \\return True if the item was preprended, false otherwise.\n *\n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   queue_t queue = queue_create(10, sizeof(int));\n *   int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n *   queue_prepend(queue, item, 1000);\n *   queue_append(queue, item, 1000);\n *   printf(\"queue length: %d\", queue_get_length(queue));\n * }\n */\nbool queue_prepend(queue_t queue, const void* item, uint32_t timeout);\n\n/**\n * Posts an item to the end of a queue. The item is queued by copy, not by\n * reference.\n *\n * \\param queue\n *        The queue handle\n * \\param item\n *        A pointer to the item that will be placed on the queue.\n * \\param timeout\n *        Time to wait for space to become available. A timeout of 0 can be used\n *        to attempt to post without blocking. TIMEOUT_MAX can be used to block\n *        indefinitely.\n *\n * \\return True if the item was preprended, false otherwise.\n * \n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   queue_t queue = queue_create(10, sizeof(int));\n *   int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n *   queue_prepend(queue, item, 1000);\n *   queue_append(queue, item, 1000);\n *   printf(\"queue length: %d\", queue_get_length(queue));\n * }\n * \\endcode\n */\nbool queue_append(queue_t queue, const void* item, uint32_t timeout);\n\n/**\n * Receive an item from a queue without removing the item from the queue.\n *\n * \\param queue\n *        The queue handle\n * \\param buffer\n *        Pointer to a buffer to which the received item will be copied\n * \\param timeout\n *        The maximum amount of time the task should block waiting for an item to receive should the queue be empty at\n *        the time of the call. TIMEOUT_MAX can be used to block indefinitely.\n *\n * \\return True if an item was copied into the buffer, false otherwise.\n * \n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   queue_t queue = queue_create(10, sizeof(int));\n *   char* item = \"Hello! this is a test\";\n *   queue_prepend(queue, item, 1000);\n *   queue_append(queue, item, 1000);\n *   char* recv = malloc(sizeof(\"Hello! this is a test\"));\n *   queue_peek(queue, recv, 1000);\n *   printf(\"Queue: %s\", recv);\n *   free(recv);\n * }\n * \\endcode\n */\nbool queue_peek(queue_t queue, void* const buffer, uint32_t timeout);\n\n/**\n * Receive an item from the queue.\n *\n * \\param queue\n *        The queue handle\n * \\param buffer\n *        Pointer to a buffer to which the received item will be copied\n * \\param timeout\n *        The maximum amount of time the task should block\n *        waiting for an item to receive should the queue be empty at the time\n *        of the call. queue_recv() will return immediately if timeout\n *        is zero and the queue is empty.\n *\n * \\return True if an item was copied into the buffer, false otherwise.\n *\n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   queue_t queue = queue_create(10, sizeof(int));\n *   char* item = \"Hello! this is a test\";\n *   queue_prepend(queue, item, 1000);\n *   queue_append(queue, item, 1000);\n *   char* recv = malloc(sizeof(\"Hello! this is a test\"));\n *   queue_recv(queue, recv, 1000);\n *   printf(\"Queue: %s\", recv);\n *   free(recv);\n * }\n * \\endcode\n */\nbool queue_recv(queue_t queue, void* const buffer, uint32_t timeout);\n\n/**\n * Return the number of messages stored in a queue.\n *\n * \\param queue\n *        The queue handle.\n *\n * \\return The number of messages available in the queue.\n *\n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   queue_t queue = queue_create(10, sizeof(int));\n * \n *   int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n *   queue_prepend(queue, item, 1000);\n *   queue_append(queue, item, 1000);\n *   printf(\"queue waiting: %d\", queue_get_waiting(queue));\n * }\n * \\endcode\n */\nuint32_t queue_get_waiting(const queue_t queue);\n\n/**\n * Return the number of spaces left in a queue.\n *\n * \\param queue\n *        The queue handle.\n *\n * \\return The number of spaces available in the queue.\n *\n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   queue_t queue = queue_create(10, sizeof(int));\n * \n *   int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n *   queue_prepend(queue, item, 1000);\n *   queue_append(queue, item, 1000);\n *   printf(\"queue available: %d\", queue_get_available(queue));\n * }\n * \\endcode\n */\nuint32_t queue_get_available(const queue_t queue);\n\n/**\n * Delete a queue.\n *\n * \\param queue\n *        Queue handle to delete\n *\n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   queue_t queue = queue_create(10, sizeof(int));\n *   queue_delete(queue);\n * }\n * \\endcode\n */\nvoid queue_delete(queue_t queue);\n\n/**\n * Resets a queue to an empty state\n *\n * \\param queue\n *        Queue handle to reset\n * \n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   queue_t queue = queue_create(10, sizeof(int));\n *   int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n *   queue_prepend(queue, item, 1000);\n *   queue_append(queue, item, 1000);\n *   queue_reset(queue);\n * }\n * \\endcode\n */\nvoid queue_reset(queue_t queue);\n\n///@}\n\n/// \\name Device Registration\n///@{\n\n/**\n * Registers a device in the given zero-indexed port\n *\n * Registers a device of the given type in the given port into the registry, if\n * that type of device is detected to be plugged in to that port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (0-20), or a\n * a different device than specified is plugged in.\n * EADDRINUSE - The port is already registered to another device.\n *\n * \\param port\n *        The port number to register the device\n * \\param device\n *        The type of device to register\n *\n * \\return 1 upon success, PROS_ERR upon failure\n * \n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   registry_bind_port(1, E_DEVICE_MOTOR);\n * }\n * \\endcode\n */\nint registry_bind_port(uint8_t port, v5_device_e_t device_type);\n\n/**\n * Deregisters a devices from the given zero-indexed port\n *\n * Removes the device registed in the given port, if there is one.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (0-20).\n *\n * \\param port\n *        The port number to deregister\n *\n * \\return 1 upon success, PROS_ERR upon failure\n *\n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   registry_bind_port(1, E_DEVICE_MOTOR);\n *   registry_unbind_port(1);\n * }\n * \\endcode\n */\nint registry_unbind_port(uint8_t port);\n\n/**\n * Returns the type of device registered to the zero-indexed port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (0-20).\n *\n * \\param port\n *        The V5 port number from 0-20\n *\n * \\return The type of device that is registered into the port (NOT what is\n * plugged in)\n *\n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   registry_bind_port(1, E_DEVICE_MOTOR);\n *   printf(\"port 1 is registered to a motor: %d\", registry_get_bound_type(1) == E_DEVICE_MOTOR);\n * }\n * \\endcode\n */\nv5_device_e_t registry_get_bound_type(uint8_t port);\n\n/**\n * Returns the type of the device plugged into the zero-indexed port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (0-20).\n *\n * \\param port\n *        The V5 port number from 0-20\n *\n * \\return The type of device that is plugged into the port (NOT what is\n * registered)\n *\n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   registry_bind_port(1, E_DEVICE_MOTOR);\n *   printf(\"port 1 is registered to a motor: %d\", registry_get_plugged_type(1) == E_DEVICE_MOTOR);\n * }\n * \\endcode\n */\nv5_device_e_t registry_get_plugged_type(uint8_t port);\n\n///@}\n\n/// \\name Startup options\n///@{\n\n/**\n * Enable/disable the PROS banner printed to the serial stream.\n *\n * \\warning This function must be called BEFORE the PROS daemon starts.\n * The easiest way to acheive this is to NOT call this function directly, \n * and instead use the BANNER_ENABLE macro.\n *\n * \\param enable\n *          Whether the banner should be enabled or disabled.\n */\nvoid enable_banner(bool enabled);\n\n/**\n * This priority value, when used with __attribute__((constructor( ))), is \n * guaranteed to run before PROS initializes.\n */\n#define PRE_PROS_INIT_PRIORITY 101\n\n/**\n * Enable/disable the PROS banner printed to the serial stream.\n *\n * \\warning This macro must be used in global scope, outside of any function.\n *\n * \\param enable\n *          Whether the banner should be enabled or disabled.\n */\n#ifdef __cplusplus\n#define ENABLE_BANNER(enabled) static_assert(!__builtin_strcmp(__FUNCTION__, \"top level\"),                            \\\n                               \"Cannot use ENABLE_BANNER inside a function!\");                                        \\\n                               __attribute__((constructor(PRE_PROS_INIT_PRIORITY))) static void _enable_banner_impl() \\\n                               { pros::c::enable_banner(enabled); }\n#else\n#define ENABLE_BANNER(enabled) static_assert(!__builtin_strcmp(__FUNCTION__, \"top level\"),                            \\\n                               \"Cannot use ENABLE_BANNER inside a function!\");                                        \\\n                               __attribute__((constructor(PRE_PROS_INIT_PRIORITY))) static void _enable_banner_impl() \\\n                               { enable_banner(enabled); }\n#endif\n///@}\n\n/// \\name Filesystem\n///@{\n\n/**\n * Control settings of the serial driver.\n *\n * \\param action\n * \t\t\tAn action to perform on the serial driver. See the SERCTL_* macros for\n * \t\t\tdetails on the different actions.\n * \\param extra_arg\n * \t\t\tAn argument to pass in based on the action\n * \n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   serctl(SERCTL_SET_BAUDRATE, (void*) 9600);\n * }\n */\nint32_t serctl(const uint32_t action, void* const extra_arg);\n\n/*\n * Control settings of the microSD card driver.\n *\n * \\param action\n * \t\t\tAn action to perform on the microSD card driver. See the USDCTL_* macros\n *      for details on the different actions.\n * \\param extra_arg\n * \t\t   \tAn argument to pass in based on the action\n */\n// Not yet implemented\n// int32_t usdctl(const uint32_t action, void* const extra_arg);\n\n/**\n * Control settings of the way the file's driver treats the file\n *\n * \\param file\n * \t\t\tA valid file descriptor number\n * \\param action\n * \t\t\tAn action to perform on the file's driver. See the *CTL_* macros for\n * \t\t\tdetails on the different actions. Note that the action passed in must\n *      match the correct driver (e.g. don't perform a SERCTL_* action on a\n *      microSD card file)\n * \\param extra_arg\n * \t\t  \tAn argument to pass in based on the action\n *\n * \\b Example:\n * \\code\n * void opcontrol(void) {\n *   int32_t fd = open(\"serial\", O_RDWR);\n *   fdctl(fd, SERCTL_SET_BAUDRATE, (void*) 9600);\n * }\n * \\endcode\n */\nint32_t fdctl(int file, const uint32_t action, void* const extra_arg);\n\n/**\n * Sets the reverse flag for the motor.\n *\n * This will invert its movements and the values returned for its position.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param reverse\n *        True reverses the motor, false is default\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void autonomous() {\n *   motor_set_reversed(1, true);\n *   printf(\"Is this motor reversed? %d\\n\", motor_is_reversed(1));\n * }\n * \\endcode\n */\nint32_t motor_set_reversed(int8_t port, const bool reverse);\n\n/**\n * Gets the operation direction of the motor as set by the user.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return 1 if the motor has been reversed and 0 if the motor was not reversed,\n * or PROS_ERR if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Is the motor reversed? %d\\n\", motor_is_reversed(1));\n *   // Prints \"Is the motor reversed? 0\"\n * }\n * \\endcode\n */\nint32_t motor_is_reversed(int8_t port);\n\n/**\n * Action macro to pass into serctl or fdctl that activates the stream\n * identifier.\n *\n * When used with serctl, the extra argument must be the little endian\n * representation of the stream identifier (e.g. \"sout\" -> 0x74756f73)\n *\n */\n#define SERCTL_ACTIVATE 10\n\n/**\n * Action macro to pass into serctl or fdctl that deactivates the stream\n * identifier.\n *\n * When used with serctl, the extra argument must be the little endian\n * representation of the stream identifier (e.g. \"sout\" -> 0x74756f73)\n *\n */\n#define SERCTL_DEACTIVATE 11\n\n/**\n * Action macro to pass into fdctl that enables blocking writes for the file\n *\n * The extra argument is not used with this action, provide any value (e.g.\n * NULL) instead\n *\n */\n#define SERCTL_BLKWRITE 12\n\n/**\n * Action macro to pass into fdctl that makes writes non-blocking for the file\n *\n * The extra argument is not used with this action, provide any value (e.g.\n * NULL) instead\n *\n */\n#define SERCTL_NOBLKWRITE 13\n\n/**\n * Action macro to pass into serctl that enables advanced stream multiplexing\n * capabilities\n *\n * The extra argument is not used with this action, provide any value (e.g.\n * NULL) instead\n *\n */\n#define SERCTL_ENABLE_COBS 14\n\n/**\n * Action macro to pass into serctl that disables advanced stream multiplexing\n * capabilities\n *\n * The extra argument is not used with this action, provide any value (e.g.\n * NULL) instead\n *\n */\n#define SERCTL_DISABLE_COBS 15\n\n/**\n * Action macro to check if there is data available from the Generic Serial\n * Device\n *\n */\n#define DEVCTL_FIONREAD 16\n\n/**\n * Action macro to check if there is space available in the Generic Serial\n * Device's output buffer\n *\n */\n#define DEVCTL_FIONWRITE 18\n\n/**\n * Action macro to set the Generic Serial Device's baudrate.\n *\n * The extra argument is the baudrate.\n */\n#define DEVCTL_SET_BAUDRATE 17\n\n///@}\n\n///@}\n\n#ifdef __cplusplus\n}\n}\n#endif\n\n#endif  // _PROS_API_EXTENDED_H_\n"
  },
  {
    "path": "include/pros/colors.h",
    "content": "/**\n * \\file pros/colors.h\n *\n * Contains macro definitions of colors (as `uint32_t`)\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License v. 2.0. If a copy of the MPL was not distributed with this\n * file You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup c-colors Colors C API\n */\n\n/**\n * \\ingroup c-colors\n * \\note These functions can be used for dynamic device instantiation. \n */\n\n/**\n * \\addtogroup c-colors\n *  @{\n */\n\n#ifndef _PROS_COLORS_H_\n#define _PROS_COLORS_H_\n\n#define RGB2COLOR(R, G, B) ((R & 0xff) << 16 | (G & 0xff) << 8 | (B & 0xff))\n#define COLOR2R(COLOR) ((COLOR >> 16) & 0xff)\n#define COLOR2G(COLOR) ((COLOR >> 8) & 0xff)\n#define COLOR2B(COLOR) (COLOR & 0xff)\n\n#ifdef __cplusplus\nnamespace pros {\nnamespace c {\n#endif\n\n/**\n * \\enum color_e_t\n * @brief\n * Enum of possible colors\n *\n * Contains common colors, all members are self descriptive. \n */\ntypedef enum color_e {\n\tCOLOR_ALICE_BLUE = 0x00F0F8FF,\n\tCOLOR_ANTIQUE_WHITE = 0x00FAEBD7,\n\tCOLOR_AQUA = 0x0000FFFF,\n\tCOLOR_AQUAMARINE = 0x007FFFD4,\n\tCOLOR_AZURE = 0x00F0FFFF,\n\tCOLOR_BEIGE = 0x00F5F5DC,\n\tCOLOR_BISQUE = 0x00FFE4C4,\n\tCOLOR_BLACK = 0x00000000,\n\tCOLOR_BLANCHED_ALMOND = 0x00FFEBCD,\n\tCOLOR_BLUE = 0x000000FF,\n\tCOLOR_BLUE_VIOLET = 0x008A2BE2,\n\tCOLOR_BROWN = 0x00A52A2A,\n\tCOLOR_BURLY_WOOD = 0x00DEB887,\n\tCOLOR_CADET_BLUE = 0x005F9EA0,\n\tCOLOR_CHARTREUSE = 0x007FFF00,\n\tCOLOR_CHOCOLATE = 0x00D2691E,\n\tCOLOR_CORAL = 0x00FF7F50,\n\tCOLOR_CORNFLOWER_BLUE = 0x006495ED,\n\tCOLOR_CORNSILK = 0x00FFF8DC,\n\tCOLOR_CRIMSON = 0x00DC143C,\n\tCOLOR_CYAN = 0x0000FFFF,\n\tCOLOR_DARK_BLUE = 0x0000008B,\n\tCOLOR_DARK_CYAN = 0x00008B8B,\n\tCOLOR_DARK_GOLDENROD = 0x00B8860B,\n\tCOLOR_DARK_GRAY = 0x00A9A9A9,\n\tCOLOR_DARK_GREY = COLOR_DARK_GRAY,\n\tCOLOR_DARK_GREEN = 0x00006400,\n\tCOLOR_DARK_KHAKI = 0x00BDB76B,\n\tCOLOR_DARK_MAGENTA = 0x008B008B,\n\tCOLOR_DARK_OLIVE_GREEN = 0x00556B2F,\n\tCOLOR_DARK_ORANGE = 0x00FF8C00,\n\tCOLOR_DARK_ORCHID = 0x009932CC,\n\tCOLOR_DARK_RED = 0x008B0000,\n\tCOLOR_DARK_SALMON = 0x00E9967A,\n\tCOLOR_DARK_SEA_GREEN = 0x008FBC8F,\n\tCOLOR_DARK_SLATE_GRAY = 0x002F4F4F,\n\tCOLOR_DARK_SLATE_GREY = COLOR_DARK_SLATE_GRAY,\n\tCOLOR_DARK_TURQUOISE = 0x0000CED1,\n\tCOLOR_DARK_VIOLET = 0x009400D3,\n\tCOLOR_DEEP_PINK = 0x00FF1493,\n\tCOLOR_DEEP_SKY_BLUE = 0x0000BFFF,\n\tCOLOR_DIM_GRAY = 0x00696969,\n\tCOLOR_DIM_GREY = COLOR_DIM_GRAY,\n\tCOLOR_DODGER_BLUE = 0x001E90FF,\n\tCOLOR_FIRE_BRICK = 0x00B22222,\n\tCOLOR_FLORAL_WHITE = 0x00FFFAF0,\n\tCOLOR_FOREST_GREEN = 0x00228B22,\n\tCOLOR_FUCHSIA = 0x00FF00FF,\n\tCOLOR_GAINSBORO = 0x00DCDCDC,\n\tCOLOR_GHOST_WHITE = 0x00F8F8FF,\n\tCOLOR_GOLD = 0x00FFD700,\n\tCOLOR_GOLDENROD = 0x00DAA520,\n\tCOLOR_GRAY = 0x00808080,\n\tCOLOR_GREY = COLOR_GRAY,\n\tCOLOR_GREEN = 0x00008000,\n\tCOLOR_GREEN_YELLOW = 0x00ADFF2F,\n\tCOLOR_HONEYDEW = 0x00F0FFF0,\n\tCOLOR_HOT_PINK = 0x00FF69B4,\n\tCOLOR_INDIAN_RED = 0x00CD5C5C,\n\tCOLOR_INDIGO = 0x004B0082,\n\tCOLOR_IVORY = 0x00FFFFF0,\n\tCOLOR_KHAKI = 0x00F0E68C,\n\tCOLOR_LAVENDER = 0x00E6E6FA,\n\tCOLOR_LAVENDER_BLUSH = 0x00FFF0F5,\n\tCOLOR_LAWN_GREEN = 0x007CFC00,\n\tCOLOR_LEMON_CHIFFON = 0x00FFFACD,\n\tCOLOR_LIGHT_BLUE = 0x00ADD8E6,\n\tCOLOR_LIGHT_CORAL = 0x00F08080,\n\tCOLOR_LIGHT_CYAN = 0x00E0FFFF,\n\tCOLOR_LIGHT_GOLDENROD_YELLOW = 0x00FAFAD2,\n\tCOLOR_LIGHT_GREEN = 0x0090EE90,\n\tCOLOR_LIGHT_GRAY = 0x00D3D3D3,\n\tCOLOR_LIGHT_GREY = COLOR_LIGHT_GRAY,\n\tCOLOR_LIGHT_PINK = 0x00FFB6C1,\n\tCOLOR_LIGHT_SALMON = 0x00FFA07A,\n\tCOLOR_LIGHT_SEA_GREEN = 0x0020B2AA,\n\tCOLOR_LIGHT_SKY_BLUE = 0x0087CEFA,\n\tCOLOR_LIGHT_SLATE_GRAY = 0x00778899,\n\tCOLOR_LIGHT_SLATE_GREY = COLOR_LIGHT_SLATE_GRAY,\n\tCOLOR_LIGHT_STEEL_BLUE = 0x00B0C4DE,\n\tCOLOR_LIGHT_YELLOW = 0x00FFFFE0,\n\tCOLOR_LIME = 0x0000FF00,\n\tCOLOR_LIME_GREEN = 0x0032CD32,\n\tCOLOR_LINEN = 0x00FAF0E6,\n\tCOLOR_MAGENTA = 0x00FF00FF,\n\tCOLOR_MAROON = 0x00800000,\n\tCOLOR_MEDIUM_AQUAMARINE = 0x0066CDAA,\n\tCOLOR_MEDIUM_BLUE = 0x000000CD,\n\tCOLOR_MEDIUM_ORCHID = 0x00BA55D3,\n\tCOLOR_MEDIUM_PURPLE = 0x009370DB,\n\tCOLOR_MEDIUM_SEA_GREEN = 0x003CB371,\n\tCOLOR_MEDIUM_SLATE_BLUE = 0x007B68EE,\n\tCOLOR_MEDIUM_SPRING_GREEN = 0x0000FA9A,\n\tCOLOR_MEDIUM_TURQUOISE = 0x0048D1CC,\n\tCOLOR_MEDIUM_VIOLET_RED = 0x00C71585,\n\tCOLOR_MIDNIGHT_BLUE = 0x00191970,\n\tCOLOR_MINT_CREAM = 0x00F5FFFA,\n\tCOLOR_MISTY_ROSE = 0x00FFE4E1,\n\tCOLOR_MOCCASIN = 0x00FFE4B5,\n\tCOLOR_NAVAJO_WHITE = 0x00FFDEAD,\n\tCOLOR_NAVY = 0x00000080,\n\tCOLOR_OLD_LACE = 0x00FDF5E6,\n\tCOLOR_OLIVE = 0x00808000,\n\tCOLOR_OLIVE_DRAB = 0x006B8E23,\n\tCOLOR_ORANGE = 0x00FFA500,\n\tCOLOR_ORANGE_RED = 0x00FF4500,\n\tCOLOR_ORCHID = 0x00DA70D6,\n\tCOLOR_PALE_GOLDENROD = 0x00EEE8AA,\n\tCOLOR_PALE_GREEN = 0x0098FB98,\n\tCOLOR_PALE_TURQUOISE = 0x00AFEEEE,\n\tCOLOR_PALE_VIOLET_RED = 0x00DB7093,\n\tCOLOR_PAPAY_WHIP = 0x00FFEFD5,\n\tCOLOR_PEACH_PUFF = 0x00FFDAB9,\n\tCOLOR_PERU = 0x00CD853F,\n\tCOLOR_PINK = 0x00FFC0CB,\n\tCOLOR_PLUM = 0x00DDA0DD,\n\tCOLOR_POWDER_BLUE = 0x00B0E0E6,\n\tCOLOR_PURPLE = 0x00800080,\n\tCOLOR_RED = 0x00FF0000,\n\tCOLOR_ROSY_BROWN = 0x00BC8F8F,\n\tCOLOR_ROYAL_BLUE = 0x004169E1,\n\tCOLOR_SADDLE_BROWN = 0x008B4513,\n\tCOLOR_SALMON = 0x00FA8072,\n\tCOLOR_SANDY_BROWN = 0x00F4A460,\n\tCOLOR_SEA_GREEN = 0x002E8B57,\n\tCOLOR_SEASHELL = 0x00FFF5EE,\n\tCOLOR_SIENNA = 0x00A0522D,\n\tCOLOR_SILVER = 0x00C0C0C0,\n\tCOLOR_SKY_BLUE = 0x0087CEEB,\n\tCOLOR_SLATE_BLUE = 0x006A5ACD,\n\tCOLOR_SLATE_GRAY = 0x00708090,\n\tCOLOR_SLATE_GREY = COLOR_SLATE_GRAY,\n\tCOLOR_SNOW = 0x00FFFAFA,\n\tCOLOR_SPRING_GREEN = 0x0000FF7F,\n\tCOLOR_STEEL_BLUE = 0x004682B4,\n\tCOLOR_TAN = 0x00D2B48C,\n\tCOLOR_TEAL = 0x00008080,\n\tCOLOR_THISTLE = 0x00D8BFD8,\n\tCOLOR_TOMATO = 0x00FF6347,\n\tCOLOR_TURQUOISE = 0x0040E0D0,\n\tCOLOR_VIOLET = 0x00EE82EE,\n\tCOLOR_WHEAT = 0x00F5DEB3,\n\tCOLOR_WHITE = 0x00FFFFFF,\n\tCOLOR_WHITE_SMOKE = 0x00F5F5F5,\n\tCOLOR_YELLOW = 0x00FFFF00,\n\tCOLOR_YELLOW_GREEN = 0x009ACD32,\n} color_e_t;\n\n\t///@}\n\n#ifdef __cplusplus\n}  // namespace c\n}  // namespace pros\n#endif\n\n#endif  // _PROS_COLORS_H_\n"
  },
  {
    "path": "include/pros/colors.hpp",
    "content": "/**\n * \\file pros/colors.hpp\n *\n * Contains enum class definitions of colors\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License v. 2.0. If a copy of the MPL was not distributed with this\n * file You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-colors C++ Color API\n */\n#ifndef _PROS_COLORS_HPP_\n#define _PROS_COLORS_HPP_\n\n\nnamespace pros{\n/**\n * \\ingroup cpp-colors\n */\n\n/**\n * \\addtogroup cpp-colors\n *  @{\n */\n\n/**\n * \\enum Color\n * @brief\n * Enum class of possible colors\n *\n * Contains common colors, all members are self descriptive. \n */\nenum class Color {\n  alice_blue = 0x00F0F8FF,\n  antique_white = 0x00FAEBD7,\n  aqua = 0x0000FFFF,\n  aquamarine = 0x007FFFD4,\n  azure = 0x00F0FFFF,\n  beige = 0x00F5F5DC,\n  bisque = 0x00FFE4C4,\n  black = 0x00000000,\n  blanched_almond = 0x00FFEBCD,\n  blue = 0x000000FF,\n  blue_violet = 0x008A2BE2,\n  brown = 0x00A52A2A,\n  burly_wood = 0x00DEB887,\n  cadet_blue = 0x005F9EA0,\n  chartreuse = 0x007FFF00,\n  chocolate = 0x00D2691E,\n  coral = 0x00FF7F50,\n  cornflower_blue = 0x006495ED,\n  cornsilk = 0x00FFF8DC,\n  crimson = 0x00DC143C,\n  cyan = 0x0000FFFF,\n  dark_blue = 0x0000008B,\n  dark_cyan = 0x00008B8B,\n  dark_goldenrod = 0x00B8860B,\n  dark_gray = 0x00A9A9A9,\n  dark_grey = dark_gray,\n  dark_green = 0x00006400,\n  dark_khaki = 0x00BDB76B,\n  dark_magenta = 0x008B008B,\n  dark_olive_green = 0x00556B2F,\n  dark_orange = 0x00FF8C00,\n  dark_orchid = 0x009932CC,\n  dark_red = 0x008B0000,\n  dark_salmon = 0x00E9967A,\n  dark_sea_green = 0x008FBC8F,\n  dark_slate_gray = 0x002F4F4F,\n  dark_slate_grey = dark_slate_gray,\n  dark_turquoise = 0x0000CED1,\n  dark_violet = 0x009400D3,\n  deep_pink = 0x00FF1493,\n  deep_sky_blue = 0x0000BFFF,\n  dim_gray = 0x00696969,\n  dim_grey = dim_gray,\n  dodger_blue = 0x001E90FF,\n  fire_brick = 0x00B22222,\n  floral_white = 0x00FFFAF0,\n  forest_green = 0x00228B22,\n  fuchsia = 0x00FF00FF,\n  gainsboro = 0x00DCDCDC,\n  ghost_white = 0x00F8F8FF,\n  gold = 0x00FFD700,\n  goldenrod = 0x00DAA520,\n  gray = 0x00808080,\n  grey = gray,\n  green = 0x00008000,\n  green_yellow = 0x00ADFF2F,\n  honeydew = 0x00F0FFF0,\n  hot_pink = 0x00FF69B4,\n  indian_red = 0x00CD5C5C,\n  indigo = 0x004B0082,\n  ivory = 0x00FFFFF0,\n  khaki = 0x00F0E68C,\n  lavender = 0x00E6E6FA,\n  lavender_blush = 0x00FFF0F5,\n  lawn_green = 0x007CFC00,\n  lemon_chiffon = 0x00FFFACD,\n  light_blue = 0x00ADD8E6,\n  light_coral = 0x00F08080,\n  light_cyan = 0x00E0FFFF,\n  light_goldenrod_yellow = 0x00FAFAD2,\n  light_green = 0x0090EE90,\n  light_gray = 0x00D3D3D3,\n  light_grey = light_gray,\n  light_pink = 0x00FFB6C1,\n  light_salmon = 0x00FFA07A,\n  light_sea_green = 0x0020B2AA,\n  light_sky_blue = 0x0087CEFA,\n  light_slate_gray = 0x00778899,\n  light_slate_grey = light_slate_gray,\n  light_steel_blue = 0x00B0C4DE,\n  light_yellow = 0x00FFFFE0,\n  lime = 0x0000FF00,\n  lime_green = 0x0032CD32,\n  linen = 0x00FAF0E6,\n  magenta = 0x00FF00FF,\n  maroon = 0x00800000,\n  medium_aquamarine = 0x0066CDAA,\n  medium_blue = 0x000000CD,\n  medium_orchid = 0x00BA55D3,\n  medium_purple = 0x009370DB,\n  medium_sea_green = 0x003CB371,\n  medium_slate_blue = 0x007B68EE,\n  medium_spring_green = 0x0000FA9A,\n  medium_turquoise = 0x0048D1CC,\n  medium_violet_red = 0x00C71585,\n  midnight_blue = 0x00191970,\n  mint_cream = 0x00F5FFFA,\n  misty_rose = 0x00FFE4E1,\n  moccasin = 0x00FFE4B5,\n  navajo_white = 0x00FFDEAD,\n  navy = 0x00000080,\n  old_lace = 0x00FDF5E6,\n  olive = 0x00808000,\n  olive_drab = 0x006B8E23,\n  orange = 0x00FFA500,\n  orange_red = 0x00FF4500,\n  orchid = 0x00DA70D6,\n  pale_goldenrod = 0x00EEE8AA,\n  pale_green = 0x0098FB98,\n  pale_turquoise = 0x00AFEEEE,\n  pale_violet_red = 0x00DB7093,\n  papay_whip = 0x00FFEFD5,\n  peach_puff = 0x00FFDAB9,\n  peru = 0x00CD853F,\n  pink = 0x00FFC0CB,\n  plum = 0x00DDA0DD,\n  powder_blue = 0x00B0E0E6,\n  purple = 0x00800080,\n  red = 0x00FF0000,\n  rosy_brown = 0x00BC8F8F,\n  royal_blue = 0x004169E1,\n  saddle_brown = 0x008B4513,\n  salmon = 0x00FA8072,\n  sandy_brown = 0x00F4A460,\n  sea_green = 0x002E8B57,\n  seashell = 0x00FFF5EE,\n  sienna = 0x00A0522D,\n  silver = 0x00C0C0C0,\n  sky_blue = 0x0087CEEB,\n  slate_blue = 0x006A5ACD,\n  slate_gray = 0x00708090,\n  slate_grey = slate_gray,\n  snow = 0x00FFFAFA,\n  spring_green = 0x0000FF7F,\n  steel_blue = 0x004682B4,\n  tan = 0x00D2B48C,\n  teal = 0x00008080,\n  thistle = 0x00D8BFD8,\n  tomato = 0x00FF6347,\n  turquoise = 0x0040E0D0,\n  violet = 0x00EE82EE,\n  wheat = 0x00F5DEB3,\n  white = 0x00FFFFFF,\n  white_smoke = 0x00F5F5F5,\n  yellow = 0x00FFFF00,\n  yellow_green = 0x009ACD32,\n};\n} // namespace pros\n\n  ///@}\n\n#endif //_PROS_COLORS_HPP_\n"
  },
  {
    "path": "include/pros/device.h",
    "content": "/**\n * \\file pros/device.h\n *\n * Contains functions for interacting with VEX devices.\n *\n *\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup c-device VEX Generic Device C API (For Advanced Users)\n */\n\n#ifndef _PROS_DEVICE_H_\n#define _PROS_DEVICE_H_\n\n#include <stdint.h>\n\n#ifdef __cplusplus\nnamespace pros::c {\nextern \"C\" {\n#endif\n\n/**\n * \\ingroup c-device\n * \\note These functions can be used for dynamic device instantiation. \n */\n\n/**\n * \\addtogroup c-device\n *  @{\n */\n\n/**\n * \\enum v5_device_e\n * \\brief\n * List of possible v5 devices\n *\n * This list contains all current V5 Devices, and mirrors V5_DeviceType from the\n * api.\n */\ntypedef enum v5_device_e {\n\tE_DEVICE_NONE = 0, ///< No device is plugged into the port\n\tE_DEVICE_MOTOR = 2, ///< A motor is plugged into the port\n\tE_DEVICE_ROTATION = 4, ///< A rotation sensor is plugged into the port\n\tE_DEVICE_IMU = 6, ///< An inertial sensor is plugged into the port\n\tE_DEVICE_DISTANCE = 7, ///< A distance sensor is plugged into the port\n\tE_DEVICE_RADIO = 8, ///< A radio is plugged into the port\n\tE_DEVICE_VISION = 11, ///< A vision sensor is plugged into the port\n\tE_DEVICE_ADI = 12, ///< This port is an ADI expander\n\tE_DEVICE_OPTICAL = 16, ///< An optical sensor is plugged into the port\n\tE_DEVICE_GPS = 20, ///< A GPS sensor is plugged into the port\n\tE_DEVICE_AIVISION = 29, ///< An AI Vision sensor is plugged into the port\n\tE_DEVICE_SERIAL = 129, ///< A serial device is plugged into the port\n\tE_DEVICE_GENERIC __attribute__((deprecated(\"use E_DEVICE_SERIAL instead\"))) = E_DEVICE_SERIAL,\n\tE_DEVICE_UNDEFINED = 255 ///< The device type is not defined, or is not a valid device\n} v5_device_e_t;\n\n/**\n * Gets the type of device on given port.\n *\n * \\return The device type as an enum.\n *\n * \\b Example\n * \\code\n * #define DEVICE_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     v5_device_e_t pt = get_plugged_type(DEVICE_PORT);\n *     printf(\"device plugged type: {plugged type: %d}\\n\", pt);\n *     delay(20);\n *   }\n * }\n * \\endcode\n*/\nv5_device_e_t get_plugged_type(uint8_t port);\n\n///@}\n\n#ifdef __cplusplus\n} // namespace c\n} // namespace pros\n#endif\n\n#endif // _PROS_DEVICE_H_\n"
  },
  {
    "path": "include/pros/device.hpp",
    "content": "/**\n * \\file pros/device.hpp\n *\n * Base class for all smart devices.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-device VEX Generic Device C++ API (For Advanced Users)\n */\n\n#ifndef _PROS_DEVICE_HPP_\n#define _PROS_DEVICE_HPP_\n\n#include \"pros/misc.hpp\"\n#include \"pros/rtos.hpp\"\n\nnamespace pros {\ninline namespace v5 {\n/**\n * \\ingroup cpp-device\n * \\note These functions can be used for dynamic device instantiation. \n */\n\n/**\n * \\addtogroup cpp-device\n *  @{\n */\n\n/**\n * \\enum DeviceType\n * \\brief\n * Enum of possible v5 devices.\n *\n * Contains all current V5 Devices.\n */\nenum class DeviceType {\n\tnone = 0, ///< No device is plugged into the port\n\tmotor = 2, ///< A motor is plugged into the port\n\trotation = 4, ///< A rotation sensor is plugged into the port\n\timu = 6, ///< An inertial sensor is plugged into the port\n\tdistance = 7, ///< A distance sensor is plugged into the port\n\tradio = 8, ///< A radio is plugged into the port\n\tvision = 11, ///< A vision sensor is plugged into the port\n\tadi = 12, ///< This port is an ADI expander\n\toptical = 16, ///< An optical sensor is plugged into the port\n\tgps = 20, ///< A GPS sensor is plugged into the port\n\taivision = 29, ///< An AI vision sensor is plugged into the port\n\tserial = 129, ///< A serial device is plugged into the port\n\tundefined = 255 ///< The device type is not defined, or is not a valid device\n};\n\nclass Device {\n\tpublic:\n  \t/**\n\t * Creates a Device object.\n\t *\n\t * \\param port The V5 port number from 1-21\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DEVICE_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   Device device(DEVICE_PORT);\n\t * }\n\t * \\endcode\n\t */\n  \texplicit Device(const std::uint8_t port);\n  \n\t/**\n\t * Gets the port number of the Smart Device.\n\t *\n\t * \\return The smart device's port number.\n\t *\n\t* \\b Example\n \t * \\code\n \t * void opcontrol() {\n\t * #define DEVICE_PORT 1\n \t *   while (true) {\n\t *\tDevice device(DEVICE_PORT);\n \t *     printf(\"device plugged type: {port: %d}\\n\", device.get_port());\n \t *     delay(20);\n \t *   }\n \t * }\n \t * \\endcode\n\t */\n\tstd::uint8_t get_port(void) const;\n\n\t/**\n\t * Checks if the device is installed.\n\t * \n\t * \\return true if the corresponding device is installed, false otherwise.\n\t * \\b Example\n\t *\n \t * \\code\n\t * #define DEVICE_PORT 1\n\t *\n\t * void opcontrol() {\n\t *\tDevice device(DEVICE_PORT);\n\t *   while (true) {\n\t *     printf(\"device plugged type: {is_installed: %d}\\n\", device.is_installed());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t*/\n\tvirtual bool is_installed();\n\n  \t/**\n\t * Gets the type of device.\n\t * \n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Mutex of port cannot be taken (access denied).\n\t * \n\t * \\return The device type as an enum.\n\t *\n\t * \\b Example\n \t * \\code\n\t * #define DEVICE_PORT 1\n\t *\n\t * void opcontrol() {\n\t\tDevice device(DEVICE_PORT);\n\t *   while (true) { \n\t *     DeviceType dt = device.get_plugged_type();\n\t *     printf(\"device plugged type: {plugged type: %d}\\n\", dt);\n\t *     delay(20);\n\t *   }\n\t * }\n \t * \\endcode\n\t */\n\tpros::DeviceType get_plugged_type() const;\n\n\n\t/**\n\t * Gets the type of device on a given port.\n\t * \n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Mutex of port cannot be taken (access denied).\n\t * \n\t * \\param port The V5 port number from 1-21\n\t * \n\t * \\return The device type as an enum.\n\t *\n\t * \\b Example\n \t * \\code\n\t * #define DEVICE_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   while (true) { \n\t *     DeviceType dt = pros::Device::get_plugged_type(DEVICE_PORT);\n\t *     printf(\"device plugged type: {plugged type: %d}\\n\", dt);\n\t *     delay(20);\n\t *   }\n\t * }\n \t * \\endcode\n\t */\n\tstatic pros::DeviceType get_plugged_type(std::uint8_t port);\n\n\t/**\n\t * Gets all devices of a given device type.\n\t * \n\t * \\param device_type The pros::DeviceType enum that matches the type of device desired.\n\t * \n\t * \\return A vector of Device objects for the given device type.\n\t *\n\t * \\b Example\n \t * \\code\n\t * void opcontrol() {\n\t *   std::vector<Device> motor_devices = pros::Device::get_all_devices(pros::DeviceType::motor);  // All Device objects are motors\n\t * }\n \t * \\endcode\n\t */\n\n\tstatic std::vector<Device> get_all_devices(pros::DeviceType device_type = pros::DeviceType::undefined);\n\n\tprotected:\n\t/**\n\t * Creates a Device object.\n\t *\n\t * \\param port The V5 port number from 1-21\n\t * \n\t * \\param deviceType The type of the constructed device\n\t */\n\tDevice(const std::uint8_t port, const enum DeviceType deviceType) : \n\t\t\t\t\t\t\t\t_port(port), \n\t\t\t\t\t\t\t\t_deviceType(deviceType) {}\n\n\tprotected:\n\tconst std::uint8_t _port;\n\tconst enum DeviceType _deviceType = pros::DeviceType::none;\n\t\n\t///@}\n};\n}  // namespace v5\n}  // namespace pros\n\n#endif\n"
  },
  {
    "path": "include/pros/distance.h",
    "content": "/**\n * \\file pros/distance.h\n * \\ingroup c-distance\n *\n * Contains prototypes for functions related to the VEX Distance sensor.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup c-distance VEX Distance Sensor C API\n */\n\n#ifndef _PROS_DISTANCE_H_\n#define _PROS_DISTANCE_H_\n\n#include <stdbool.h>\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\nnamespace c {\n#endif\n\n/**\n * \\ingroup c-distance\n */\n\n/**\n * \\addtogroup c-distance\n *  @{\n */\n\n/**\n * Get the currently measured distance from the sensor in mm\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Distance Sensor\n *\n * \\param port The V5 Distance Sensor port number from 1-21\n * \\return The distance value or PROS_ERR if the operation failed, setting\n * errno.\n * \n * \\b Example\n * \\code\n * #define DISTANCE_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Distance Value: %d mm\\n\", distance_get(DISTANCE_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t distance_get(uint8_t port);\n\n/**\n * Get the confidence in the distance reading\n *\n * This is a value that has a range of 0 to 63. 63 means high confidence,\n * lower values imply less confidence. Confidence is only available\n * when distance is > 200mm (the value 10 is returned in this scenario).\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Distance Sensor\n *\n * \\param  port The V5 Distance Sensor port number from 1-21\n * \\return The confidence value or PROS_ERR if the operation failed, setting\n * errno.\n * \n * \\b Example\n * \\code\n * #define DISTANCE_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Distance Confidence Value: %d\\n\", distance_get_confidence(DISTANCE_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t distance_get_confidence(uint8_t port);\n\n/**\n * Get the current guess at relative object size\n *\n * This is a value that has a range of 0 to 400.\n * A 18\" x 30\" grey card will return a value of approximately 75\n * in typical room lighting.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Distance Sensor\n *\n * \\param  port The V5 Distance Sensor port number from 1-21\n * \\return The size value or PROS_ERR if the operation failed, setting\n * errno.\n * \n * \\b Example\n * \\code\n * #define DISTANCE_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Distance Object Size: %d\\n\", distance_get_object_size(DISTANCE_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t distance_get_object_size(uint8_t port);\n\n/**\n * Get the object velocity in m/s\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Distance Sensor\n *\n * \\param  port The V5 Distance Sensor port number from 1-21\n * \\return The velocity value or PROS_ERR if the operation failed, setting\n * errno.\n * \n * \\b Example\n * \\code\n * #define DISTANCE_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Distance Object Velocity: %f\\n\", distance_get_object_velocity(DISTANCE_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble distance_get_object_velocity(uint8_t port);\n\n///@}\n\n#ifdef __cplusplus\n}\n}\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "include/pros/distance.hpp",
    "content": "/**\n * \\file pros/distance.hpp\n * \\ingroup cpp-distance\n *\n * Contains prototypes for the V5 Distance Sensor-related functions.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-distance VEX Distance Sensor C++ API\n */\n\n#ifndef _PROS_DISTANCE_HPP_\n#define _PROS_DISTANCE_HPP_\n\n#include <cstdint>\n#include <iostream>\n\n#include \"pros/device.hpp\"\n#include \"pros/distance.h\"\n\nnamespace pros {\ninline namespace v5 {\n/**\n * \\ingroup cpp-distance\n */\nclass Distance : public Device {\n\t/**\n\t * \\addtogroup cpp-distance\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Creates a Distance Sensor object for the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a Distance Sensor\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DISTANCE_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   Distance distance(DISTANCE_PORT);\n\t * }\n\t * \\endcode\n\t */\n\tDistance(const std::uint8_t port);\n\n\tDistance(const Device& device) : Distance(device.get_port()){};\n\t/**\n\t * Get the currently measured distance from the sensor in mm\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Distance Sensor\n\t *\n\t * \\return The distance value or PROS_ERR if the operation failed, setting\n\t * errno. Will return 9999 if the sensor can not detect an object.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DISTANCE_PORT 1\n\t *\n\t * void opcontrol() {\n\t  Distance distance(DISTANCE_PORT);\n\t *   while (true) {\n\t *     printf(\"Distance: %d\\n\", distance.get());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get();\n\n\t/**\n\t * Get the currently measured distance from the sensor in mm.\n\t * \\note This function is identical to get().\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Distance Sensor\n\t *\n\t * \\return The distance value or PROS_ERR if the operation failed, setting\n\t * errno. Will return 9999 if the sensor can not detect an object.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DISTANCE_PORT 1\n\t *\n\t * void opcontrol() {\n\t  Distance distance(DISTANCE_PORT);\n\t *   while (true) {\n\t *     printf(\"Distance: %d\\n\", distance.get_distance());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get_distance();\n\n\t/**\n\t * Gets all distance sensors.\n\t *\n\t * \\return A vector of Distance sensor objects.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   std::vector<Distance> distance_all = pros::Distance::get_all_devices();  // All distance sensors that are\n\t * connected\n\t * }\n\t * \\endcode\n\t */\n\tstatic std::vector<Distance> get_all_devices();\n\n\t/**\n\t * Get the confidence in the distance reading\n\t *\n\t * This is a value that has a range of 0 to 63. 63 means high confidence,\n\t * lower values imply less confidence. Confidence is only available\n\t * when distance is > 200mm.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Distance Sensor\n\t *\n\t * \\return The confidence value or PROS_ERR if the operation failed, setting\n\t * errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DISTANCE_PORT 1\n\t *\n\t * void opcontrol() {\n\t  Distance distance(DISTANCE_PORT);\n\t *   while (true) {\n\t *     printf(\"Distance confidence: %d\\n\", distance.get_confidence());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get_confidence();\n\n\t/**\n\t * Get the current guess at relative object size\n\t *\n\t * This is a value that has a range of 0 to 400.\n\t * A 18\" x 30\" grey card will return a value of approximately 75\n\t * in typical room lighting.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Distance Sensor\n\t *\n\t * \\return The size value or PROS_ERR if the operation failed, setting\n\t * errno. Will return -1 if the sensor is not able to determine object size.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define DISTANCE_PORT 1\n\t *\n\t * void opcontrol() {\n\t  Distance distance(DISTANCE_PORT);\n\t *   while (true) {\n\t *     printf(\"Distance object size: %d\\n\", distance.get_object_size());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get_object_size();\n\n\t/**\n\t * Get the object velocity in m/s\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Distance Sensor\n\t *\n\t * \\return The velocity value or PROS_ERR if the operation failed, setting\n\t * errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * void opcontrol() {\n\t *\tDistance distance(DISTANCE_PORT);\n\t *   while (true) {\n\t *     printf(\"Distance object velocity: %f\\n\", distance.get_object_velocity());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_object_velocity();\n\n\t/**\n\t * This is the overload for the << operator for printing to streams\n\t *\n\t * Prints in format(this below is all in one line with no new line):\n\t * Distance [port: (port number), distance: (distance), confidence: (confidence),\n\t * object size: (object size), object velocity: (object velocity)]\n\t */\n\tfriend std::ostream& operator<<(std::ostream& os, pros::Distance& distance);\n\n\tprivate:\n\t///@}\n};\n\nnamespace literals {\n/**\n * Constructs a Distance sensor object from a literal ending in _dist via calling the constructor\n *\n * \\return a pros::Distance for the corresponding port\n *\n * \\b Example\n * \\code\n * using namespace pros::literals;\n * void opcontrol() {\n *\tpros::Distance dist = 2_dist; //Makes an dist object on port 2\n * }\n * \\endcode\n */\nconst pros::Distance operator\"\"_dist(const unsigned long long int d);\n}  // namespace literals\n}  // namespace v5\n}  // namespace pros\n\n#endif\n"
  },
  {
    "path": "include/pros/error.h",
    "content": "/**\n * \\file pros/error.h\n *\n * Contains macro definitions for return types, mostly errors\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n#ifndef _PROS_ERROR_H_\n#define _PROS_ERROR_H_\n\n#include \"limits.h\"\n\n// Different Byte Size Errors\n\n/// @brief\n/// Return This on Byte Sized Return Error\n#define PROS_ERR_BYTE (INT8_MAX)\n\n/// @brief\n/// Return This on 2 Byte Sized Return Error\n#define PROS_ERR_2_BYTE (INT16_MAX)\n\n/// @brief\n/// Return This on 4 Byte Sized Return Error\n#define PROS_ERR (INT32_MAX)\n\n/// @brief\n/// Return This on 8 Byte Sized Return Error\n#define PROS_ERR_F (INFINITY)\n\n/// @brief\n/// Return This on Success (1)\n#define PROS_SUCCESS (1)\n\n#endif\n"
  },
  {
    "path": "include/pros/ext_adi.h",
    "content": "/**\n * \\file pros/ext_adi.h\n * \\ingroup ext-adi\n *\n * Contains prototypes for interfacing with the 3-Wire Expander.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup ext-adi ADI Expander C API\n * \\note The internal ADI API can be found [here.](@ref c-adi)\n */\n\n#ifndef _PROS_EXT_ADI_H_\n#define _PROS_EXT_ADI_H_\n\n#include <stdbool.h>\n#include <stdint.h>\n\n#include \"adi.h\"\n#include \"pros/adi.h\"\n#ifndef PROS_ERR\n#define PROS_ERR (INT32_MAX)\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\n#endif\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n/**\n * \\ingroup ext-adi\n */\n\n/**\n * \\addtogroup ext-adi\n *  @{\n */\n\n/******************************************************************************/\n/**                         General ADI Use Functions                        **/\n/**                                                                          **/\n/**       These functions allow for interaction with any ADI port type       **/\n/******************************************************************************/\n\n/**\n * Gets the configuration for the given ADI port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *        The ADI port number (from 1-8, 'a'-'h', 'A'-'H') for which to return\n *        the configuration\n *\n * \\return The ADI configuration for the given port\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define ANALOG_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   ext_adi_port_set_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN);\n *   // Displays the value of E_ADI_ANALOG_IN\n *   printf(\"Port Type: %d\\n\", ext_adi_port_get_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT));\n * }\n * \\endcode\n */\nadi_port_config_e_t ext_adi_port_get_config(uint8_t smart_port, uint8_t adi_port);\n\n/**\n * Gets the value for the given ADI port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port number (from 1-8, 'a'-'h', 'A'-'H') for which to return\n *        the configuration\n *\n * \\return The value stored for the given port\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define ANALOG_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   ext_adi_port_set_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN);\n *   printf(\"Port Value: %d\\n\", ext_adi_get_value(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT));\n * }\n * \\endcode\n */\nint32_t ext_adi_port_get_value(uint8_t smart_port, uint8_t adi_port);\n\n/**\n * Configures an ADI port to act as a given sensor type.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n * \\param type\n *        The configuration type for the port\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define ANALOG_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   ext_adi_port_set_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN);\n * }\n * \\endcode\n */\nint32_t ext_adi_port_set_config(uint8_t smart_port, uint8_t adi_port, adi_port_config_e_t type);\n\n/**\n * Sets the value for the given ADI port.\n *\n * This only works on ports configured as outputs, and the behavior will change\n * depending on the configuration of the port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port number (from 1-8, 'a'-'h', 'A'-'H') for which the value\n *        will be set\n * \\param value\n *        The value to set the ADI port to\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define DIGITAL_SENSOR_PORT 1\n * \n * void initialize() {\n *   ext_adi_port_set_config(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT, E_ADI_DIGITAL_OUT);\n *   ext_adi_set_value(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT, HIGH);\n * }\n * \\endcode\n */\nint32_t ext_adi_port_set_value(uint8_t smart_port, uint8_t adi_port, int32_t value);\n\n/**\n * Calibrates the analog sensor on the specified port and returns the new\n * calibration value.\n *\n * This method assumes that the true sensor value is not actively changing at\n * this time and computes an average from approximately 500 samples, 1 ms apart,\n * for a 0.5 s period of calibration. The average value thus calculated is\n * returned and stored for later calls to the adi_analog_read_calibrated() and\n * adi_analog_read_calibrated_HR() functions. These functions will return\n * the difference between this value and the current sensor value when called.\n *\n * Do not use this function when the sensor value might be unstable\n * (gyro rotation, accelerometer movement).\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port to calibrate (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return The average sensor value computed by this function\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define ANALOG_SENSOR_PORT 1\n * \n * void initialize() {\n *   ext_adi_analog_calibrate(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT);\n *   printf(\"Calibrated Reading: %d\\n\",\n *     ext_adi_analog_read_calibrated(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT));\n *   // All readings from then on will be calibrated\n * }\n * \\endcode\n */\nint32_t ext_adi_analog_calibrate(uint8_t smart_port, uint8_t adi_port);\n\n/**\n * Gets the 12-bit value of the specified port.\n *\n * The value returned is undefined if the analog pin has been switched to a\n * different mode.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an analog input\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be\n *        returned\n *\n * \\return The analog sensor value, where a value of 0 reflects an input voltage\n * of nearly 0 V and a value of 4095 reflects an input voltage of nearly 5 V\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define ANALOG_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Sensor Reading: %d\\n\", ext_adi_analog_read(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_analog_read(uint8_t smart_port, uint8_t adi_port);\n\n/**\n * Gets the 12 bit calibrated value of an analog input port.\n *\n * The adi_analog_calibrate() function must be run first. This function is\n * inappropriate for sensor values intended for integration, as round-off error\n * can accumulate causing drift over time. Use adi_analog_read_calibrated_HR()\n * instead.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an analog input\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be\n *        returned\n *\n * \\return The difference of the sensor value from its calibrated default from\n * -4095 to 4095\n * \n * \\b Example\n * \\code\n *\n * #define ADI_EXPANDER_PORT 20\n * #define ANALOG_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Sensor Reading: %d\\n\", ext_adi_analog_read_calibrated(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_analog_read_calibrated(uint8_t smart_port, uint8_t adi_port);\n\n/**\n * Gets the 16 bit calibrated value of an analog input port.\n *\n * The adi_analog_calibrate() function must be run first. This is intended for\n * integrated sensor values such as gyros and accelerometers to reduce drift due\n * to round-off, and should not be used on a sensor such as a line tracker\n * or potentiometer.\n *\n * The value returned actually has 16 bits of \"precision\", even though the ADC\n * only reads 12 bits, so that error induced by the average value being between\n * two values when integrated over time is trivial. Think of the value as the\n * true value times 16.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an analog input\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port (from 1-8, 'a'-'h', 'A'-'H') for which the value will be\n *        returned\n *\n * \\return The difference of the sensor value from its calibrated default from\n * -16384 to 16384\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define ANALOG_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     ext_adi_analog_calibrate(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT);\n * \n *     printf(\"Sensor Reading: %d\\n\", ext_adi_analog_read_calibrated_HR(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_analog_read_calibrated_HR(uint8_t smart_port, uint8_t adi_port);\n\n/**\n * Gets the digital value (1 or 0) of a port configured as a digital input.\n *\n * If the port is configured as some other mode, the digital value which\n * reflects the current state of the port is returned, which may or may not\n * differ from the currently set value. The return value is undefined for ports\n * configured as any mode other than a Digital Input.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as a digital input\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port to read (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return True if the pin is HIGH, or false if it is LOW\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define DIGITAL_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(“Sensor Value: %dn”, \n *       ext_adi_digital_read(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT)); \n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_digital_read(uint8_t smart_port, uint8_t adi_port);\n\n/**\n * Gets a rising-edge case for a digital button press.\n *\n * This function is not thread-safe.\n * Multiple tasks polling a single button may return different results under the\n * same circumstances, so only one task should call this function for any given\n * button. E.g., Task A calls this function for buttons 1 and 2. Task B may call\n * this function for button 3, but should not for buttons 1 or 2. A typical\n * use-case for this function is to call inside opcontrol to detect new button\n * presses, and not in any other tasks.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as a digital input\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port to read (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return 1 if the button is pressed and had not been pressed\n * the last time this function was called, 0 otherwise.\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define DIGITAL_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     if (ext_adi_digital_get_new_press(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT)) {\n *       // Toggle pneumatics or other state operations\n *     }\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_digital_get_new_press(uint8_t smart_port, uint8_t adi_port);\n\n/**\n * Sets the digital value (1 or 0) of a port configured as a digital output.\n *\n * If the port is configured as some other mode, behavior is undefined.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as a digital output\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n * \\param value\n *        An expression evaluating to \"true\" or \"false\" to set the output to\n *        HIGH or LOW respectively, or the constants HIGH or LOW themselves\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define DIGITAL_SENSOR_PORT 1\n * \n * void opcontrol() {\n *   bool state = LOW;\n *   while (true) {\n *     state != state;\n *     ext_adi_digital_write(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT, state);\n * \n *     delay(5); // toggle the sensor value every 50ms\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_digital_write(uint8_t smart_port, uint8_t adi_port, bool value);\n\n/**\n * Configures the port as an input or output with a variety of settings.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n * \\param mode\n *        One of INPUT, INPUT_ANALOG, INPUT_FLOATING, OUTPUT, or OUTPUT_OD\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define ANALOG_SENSOR_PORT 1\n * \n * void initialize() {\n *   ext_adi_pin_mode(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, INPUT_ANALOG);\n * }\n * \\endcode\n */\nint32_t ext_adi_pin_mode(uint8_t smart_port, uint8_t adi_port, uint8_t mode);\n\n/**\n * Sets the speed of the motor on the given port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an motor\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure\n * \\param speed\n *        The new signed speed; -127 is full reverse and 127 is full forward,\n *        with 0 being off\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define MOTOR_PORT 1\n * \n * void opcontrol() {\n *   ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 127); // Go full speed forward\n *   delay(1000);\n *   ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 0); // Stop the motor\n * }\n * \\endcode\n */\nint32_t ext_adi_motor_set(uint8_t smart_port, uint8_t adi_port, int8_t speed);\n\n/**\n * Gets the last set speed of the motor on the given port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an motor\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port to get (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return The last set speed of the motor on the given port\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20 #\n * define MOTOR_PORT 1\n * \n * void opcontrol() {\n *   ext_adi_motor_set(ADI_EXPANDER_PORT,\n *     MOTOR_PORT, 127); // Go full speed forward \n *   printf(“Commanded Motor Power: %dn”,\n *     ext_adi_motor_get(ADI_EXPANDER_PORT, MOTOR_PORT)); // Will display 127\n *   delay(1000); \n *   ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 0); // Stop the motor\n * }\n * \\endcode\n */\nint32_t ext_adi_motor_get(uint8_t smart_port, uint8_t adi_port);\n\n/**\n * Stops the motor on the given port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an motor\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *\t      The ADI port to set (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define MOTOR_PORT 1\n * \n * void opcontrol() {\n *   ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 127); // Go full speed forward\n *   delay(1000);\n *   ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 0); // Stop the motor\n *   ext_adi_motor_stop(ADI_EXPANDER_PORT, MOTOR_PORT); // use this instead\n * }\n * \\endcode\n */\nint32_t ext_adi_motor_stop(uint8_t smart_port, uint8_t adi_port);\n\n/**\n * Reference type for an initialized encoder.\n *\n * This merely contains the port number for the encoder.\n */\ntypedef int32_t ext_adi_encoder_t;\n\n/**\n * Gets the number of ticks recorded by the encoder.\n *\n * There are 360 ticks in one revolution.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an encoder\n *\n * \\param enc\n *        The adi_encoder_t object from adi_encoder_init() to read\n *\n * \\return The signed and cumulative number of counts since the last start or\n * reset\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20 \n * #define PORT_TOP 1 #define PORT_BOTTOM 2\n * \n * void opcontrol() {\n *   ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT,\n *     PORT_TOP, PORT_BOTTOM, false); \n *   while (true) {\n *     printf(“Encoder Value: %dn”,\n *       ext_adi_encoder_get(enc));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_encoder_get(ext_adi_encoder_t enc);\n\n/**\n * Creates an encoder object and configures the specified ports accordingly.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an encoder\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port_top\n *        The \"top\" wire from the encoder sensor with the removable cover side\n *        up. This should be in port 1, 3, 5, or 7 ('A', 'C', 'E', or 'G').\n * \\param adi_port_bottom\n *        The \"bottom\" wire from the encoder sensor\n * \\param reverse\n *        If \"true\", the sensor will count in the opposite direction\n *\n * \\return An adi_encoder_t object to be stored and used for later calls to\n * encoder functions\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define PORT_TOP 1\n * #define PORT_BOTTOM 2\n * \n * void opcontrol() {\n *   ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT, PORT_TOP, PORT_BOTTOM, false);\n *   while (true) {\n *     printf(\"Encoder Value: %d\\n\", ext_adi_encoder_get(enc));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\next_adi_encoder_t ext_adi_encoder_init(uint8_t smart_port, uint8_t adi_port_top, uint8_t adi_port_bottom, bool reverse);\n\n/**\n * Sets the encoder value to zero.\n *\n * It is safe to use this method while an encoder is enabled. It is not\n * necessary to call this method before stopping or starting an encoder.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an encoder\n *\n * \\param enc\n *        The adi_encoder_t object from adi_encoder_init() to reset\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define PORT_TOP 1\n * #define PORT_BOTTOM 2\n * \n * void opcontrol() {\n *   ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT, PORT_TOP, PORT_BOTTOM, false);\n *   delay(1000); // Move the encoder around in this time\n *   ext_adi_encoder_reset(enc); // The encoder is now zero again\n * }\n * \\endcode\n */\nint32_t ext_adi_encoder_reset(ext_adi_encoder_t enc);\n\n/**\n * Disables the encoder and voids the configuration on its ports.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an encoder\n *\n * \\param enc\n *        The adi_encoder_t object from adi_encoder_init() to stop\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * \n * #define ADI_EXPANDER_PORT 20\n * #define PORT_TOP 1\n * #define PORT_BOTTOM 2\n * \n * void opcontrol() {\n *   ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT, PORT_TOP, PORT_BOTTOM, false);\n *   // Use the encoder\n *   ext_adi_encoder_shutdown(enc);\n * }\n * \\endcode\n */\nint32_t ext_adi_encoder_shutdown(ext_adi_encoder_t enc);\n\n/**\n * Reference type for an initialized ultrasonic.\n *\n * This merely contains the port number for the ultrasonic.\n */\ntypedef int32_t ext_adi_ultrasonic_t;\n\n/**\n * Gets the current ultrasonic sensor value in centimeters.\n *\n * If no object was found, zero is returned. If the ultrasonic sensor was never\n * started, the return value is undefined. Round and fluffy objects can cause\n * inaccurate values to be returned.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an ultrasonic\n *\n * \\param ult\n *        The adi_ultrasonic_t object from adi_ultrasonic_init() to read\n *\n * \\return The distance to the nearest object in m^-4 (10000 indicates 1 meter),\n * measured from the sensor's mounting points.\n * \n * \\b Example\n * \\code\n * \n * #define PORT_PING 1\n * #define PORT_ECHO 2\n * #define ADI_EXPANDER_PORT 20\n * \n * void opcontrol() {\n *   ext_adi_ultrasonic_t ult = ext_adi_ultrasonic_init(ADI_EXPANDER_PORT, PORT_PING, PORT_ECHO);\n *   while (true) {\n *     // Print the distance read by the ultrasonic\n *     printf(\"Distance: %d\\n\", ext_adi_ultrasonic_get(ult));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_ultrasonic_get(ext_adi_ultrasonic_t ult);\n\n/**\n * Creates an ultrasonic object and configures the specified ports accordingly.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an ultrasonic\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port_ping\n *        The port connected to the orange OUTPUT cable. This should be in port\n *        1, 3, 5, or 7 ('A', 'C', 'E', 'G').\n * \\param adi_port_echo\n *        The port connected to the yellow INPUT cable. This should be in the\n *        next highest port following port_ping.\n *\n * \\return An adi_ultrasonic_t object to be stored and used for later calls to\n * ultrasonic functions\n * \n * \\b Example\n * \\code\n * \n * #define PORT_PING 1\n * #define PORT_ECHO 2\n * #define ADI_EXPANDER_PORT 20\n * \n * void opcontrol() {\n *   ext_adi_ultrasonic_t ult = ext_adi_ultrasonic_init(ADI_EXPANDER_PORT, PORT_PING, PORT_ECHO);\n *   while (true) {\n *     // Print the distance read by the ultrasonic\n *     printf(\"Distance: %d\\n\", ext_adi_ultrasonic_get(ult));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\next_adi_ultrasonic_t ext_adi_ultrasonic_init(uint8_t smart_port, uint8_t adi_port_ping, uint8_t adi_port_echo);\n\n/**\n * Disables the ultrasonic sensor and voids the configuration on its ports.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as an ultrasonic\n *\n * \\param ult\n *        The adi_ultrasonic_t object from adi_ultrasonic_init() to stop\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * \n * #define PORT_PING 1\n * #define PORT_ECHO 2\n * #define ADI_EXPANDER_PORT 20\n * \n * void opcontrol() {\n *   ext_adi_ultrasonic_t ult = ext_adi_ultrasonic_init(ADI_EXPANDER_PORT, PORT_PING, PORT_ECHO);\n *   while (true) {\n *     // Print the distance read by the ultrasonic\n *     printf(\"Distance: %d\\n\", ext_adi_ultrasonic_get(ult));\n *     delay(5);\n *   }\n *   ext_adi_ultrasonic_shutdown(ult);\n * }\n * \\endcode\n */\nint32_t ext_adi_ultrasonic_shutdown(ext_adi_ultrasonic_t ult);\n\n/**\n * Reference type for an initialized gyroscope.\n *\n * This merely contains the port number for the gyroscope.\n *\n * (Might Be useless with the wire expander.)\n */\ntypedef int32_t ext_adi_gyro_t;\n\n/**\n * Gets the current gyro angle in tenths of a degree. Unless a multiplier is\n * applied to the gyro, the return value will be a whole number representing\n * the number of degrees of rotation times 10.\n *\n * There are 360 degrees in a circle, thus the gyro will return 3600 for one\n * whole rotation.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as a gyro\n *\n * \\param gyro\n *        The adi_gyro_t object for which the angle will be returned\n *\n * \\return The gyro angle in degrees.\n * \n * \\b Example\n * \\code\n * \n * #define GYRO_PORT 1\n * #define GYRO_MULTIPLIER 1 // Standard behavior\n * #define ADI_EXPANDER_PORT 20\n * \n * void opcontrol() {\n *   ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER);\n *   while (true) {\n *     // Print the gyro's heading\n *     printf(\"Heading: %lf\\n\", ext_adi_gyro_get(gyro));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\ndouble ext_adi_gyro_get(ext_adi_gyro_t gyro);\n\n/**\n * Initializes a gyroscope on the given port. If the given port has not\n * previously been configured as a gyro, then this function starts a 1300 ms\n * calibration period.\n *\n * It is highly recommended that this function be called from initialize() when\n * the robot is stationary to ensure proper calibration.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as a gyro\n *\n * \\param smart_port\n *        The smart port number that the ADI Expander is in\n * \\param adi_port\n *        The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H')\n * \\param multiplier\n *        A scalar value that will be multiplied by the gyro heading value\n *        supplied by the ADI\n *\n * \\return An adi_gyro_t object containing the given port, or PROS_ERR if the\n * initialization failed.\n * \n * \\b Example\n * \\code\n * \n * #define GYRO_PORT 1\n * #define GYRO_MULTIPLIER 1 // Standard behavior\n * #define ADI_EXPANDER_PORT 20\n * \n * void opcontrol() {\n *   ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER);\n *   while (true) {\n *     // Print the gyro's heading\n *     printf(\"Heading: %lf\\n\", ext_adi_gyro_get(gyro));\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\next_adi_gyro_t ext_adi_gyro_init(uint8_t smart_port, uint8_t adi_port, double multiplier);\n\n/**\n * Resets the gyroscope value to zero.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as a gyro\n *\n * \\param gyro\n *        The adi_gyro_t object for which the angle will be returned\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * \n * #define GYRO_PORT 1\n * #define GYRO_MULTIPLIER 1 // Standard behavior\n * #define ADI_EXPANDER_PORT 20\n * \n * void opcontrol() {\n *   ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER);\n *   uint32_t now = millis();\n *   while (true) {\n *     // Print the gyro's heading\n *     printf(\"Heading: %lf\\n\", ext_adi_gyro_get(gyro));\n *     \n *     if (millis() - now > 2000) {\n *       // Reset the gyro every 2 seconds\n *       ext_adi_gyro_reset(gyro);\n *       now = millis();\n *     }\n * \n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_gyro_reset(ext_adi_gyro_t gyro);\n\n/**\n * Disables the gyro and voids the configuration on its port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - Either the ADI port value or the smart port value is not within its\n *\t   valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).\n * EADDRINUSE - The port is not configured as a gyro\n *\n * \\param gyro\n *        The adi_gyro_t object to be shut down\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * \n * #define GYRO_PORT 1\n * #define GYRO_MULTIPLIER 1 // Standard behavior\n * #define ADI_EXPANDER_PORT 20\n * \n * void opcontrol() {\n *   ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER);\n *   uint32_t now = millis();\n *   while (true) {\n *     // Print the gyro's heading\n *     printf(\"Heading: %lf\\n\", ext_adi_gyro_get(gyro));\n *     \n *     if (millis() - now > 2000) {\n *       ext_adi_gyro_shutdown(gyro);\n *       // Shut down the gyro after two seconds\n *       break;\n *     }\n * \n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_gyro_shutdown(ext_adi_gyro_t gyro);\n\n/**\n * Reference type for an initialized potentiometer.\n *\n * This merely contains the port number for the potentiometer.\n */\ntypedef int32_t ext_adi_potentiometer_t;\n\n/**\n * Initializes a potentiometer on the given port. \n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a potentiometer\n *\n * \\param port\n *        The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H')\n * \\param potentiometer_type\n *        An adi_potentiometer_type_e_t enum value specifying the potentiometer version type\n *\n * \\return An adi_potentiometer_t object containing the given port, or PROS_ERR if the\n * initialization failed.\n */\next_adi_potentiometer_t ext_adi_potentiometer_init(uint8_t smart_port, uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type); \n\n/**\n * Gets the current potentiometer angle in tenths of a degree.\n *\n * The original potentiometer rotates 250 degrees thus returning an angle between 0-250 degrees.\n * Potentiometer V2 rotates 333 degrees thus returning an angle between 0-333 degrees.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EADDRINUSE - The port is not configured as a potentiometer\n *\n * \\param potentiometer\n *        The adi_potentiometer_t object for which the angle will be returned\n *\n * \\return The potentiometer angle in degrees.\n */\ndouble ext_adi_potentiometer_get_angle(ext_adi_potentiometer_t potentiometer);\n\n/**\n * Reference type for an initialized addressable led.\n *\n * This merely contains the port number for the led, unlike its use as an\n * object to store led data in the C++ API.\n */\ntypedef int32_t ext_adi_led_t;\n\n/**\n * Initializes a led on the given port. \n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - A given value is not correct, or the buffer is null\n * EADDRINUSE - The port is not configured for ADI output\n * \n * \\param smart_port\n *        The smart port with the adi expander (1-21)\n * \\param adi_port\n *        The ADI port to initialize as a led (from 1-8, 'a'-'h', 'A'-'H')\n *\n * \\return An ext_adi_led_t object containing the given port, or PROS_ERR if the\n * initialization failed.\n * \n * \\b Example:\n * \\code\n * #define SMART_PORT 1\n * #define ADI_PORT 'A'\n * \n * void opcontrol() {\n *   // Initialize a led on smart port 1 and adi port A\n *   ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT);\n *   // Initialize a buffer with a single color of red\n *   uint32_t buffer[1] = {0xFF0000};\n * \n *   while (true) {\n *    // Set the led to colors in the buffer\n *    ext_adi_led_set(led, buffer, 1);\n *    delay(5);\n *   }\n * }\n * \\endcode\n */\next_adi_led_t ext_adi_led_init(uint8_t smart_port, uint8_t adi_port);\n\n/**\n * @brief Clear the entire led strip of color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - A given value is not correct, or the buffer is null\n * EADDRINUSE - The port is not configured for ADI output\n *\n * @param led port of type adi_led_t\n * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw\n * @param buffer_length length of buffer to clear\n * @return PROS_SUCCESS if successful, PROS_ERR if not\n * \n * \\b Example:\n * \\code\n * #define SMART_PORT 1\n * #define ADI_PORT 'A'\n *  \n * void opcontrol() {\n *   // Initialize a led on smart port 1 and adi port A\n *   ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT);\n *   // Initialize a buffer with a single color of red\n *   uint32_t buffer[1] = {0xFF0000};\n * \n *   while (true) {\n *     // Set the led to colors in the buffer\n *     ext_adi_led_set(led, buffer, 1);\n *     delay(5);\n *   \n *     // Clear the led\n *     ext_adi_led_clear_all(led, buffer, 1);\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_led_clear_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length);\n\n/**\n * @brief Set the entire led strip using the colors contained in the buffer\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - A given value is not correct, or the buffer is null\n * EADDRINUSE - The port is not configured for ADI output\n *\n * @param led port of type adi_led_t\n * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw\n * @param buffer_length length of buffer to clear\n * @return PROS_SUCCESS if successful, PROS_ERR if not\n * \n * \\b Example:\n * \\code\n * #define SMART_PORT 1\n * #define ADI_PORT 'A'\n * \n * void opcontrol() {\n *   // Initialize a led on smart port 1 and adi port A\n *   ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT);\n *   // Initialize a buffer with a single color of red\n *   uint32_t buffer[1] = {0xFF0000};\n * \n *   while (true) {\n *     // Set the led to colors in the buffer\n *     ext_adi_led_set(led, buffer, 1);\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_led_set(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length);\n\n/**\n * @brief Set the entire led strip to one color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - A given value is not correct, or the buffer is null\n * EADDRINUSE - The port is not configured for ADI output\n *\n * @param led port of type adi_led_t\n * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw\n * @param buffer_length length of buffer to clear\n * @param color color to set all the led strip value to\n * @return PROS_SUCCESS if successful, PROS_ERR if not\n *  \n * \\b Example:\n * \\code\n * #define SMART_PORT 1\n * #define ADI_PORT 'A'\n *  \n * void opcontrol() {\n *   // Initialize a led on smart port 1 and adi port A\n *   ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT);\n *   // Initialize a buffer with a single color of red\n *   uint32_t buffer[1] = {0xFF0000};\n *   \n *   while (true) {\n *     // Set the entire led strip to red\n *     ext_adi_led_set_all(led, buffer, 1, 0xFF0000);\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_led_set_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color);\n\n/**\n * @brief Set one pixel on the led strip\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - A given value is not correct, or the buffer is null\n * EADDRINUSE - The port is not configured for ADI output\n *\n * @param led port of type adi_led_t\n * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw\n * @param buffer_length length of the input buffer\n * @param color color to clear all the led strip to\n * @param pixel_position position of the pixel to clear (0 indexed)\n * @return PROS_SUCCESS if successful, PROS_ERR if not\n * \n * \\b Example:\n * \\code\n * #define SMART_PORT 1\n * #define ADI_PORT 'A'\n * \n * void opcontrol() {\n *   // Initialize a led on smart port 1 and adi port A\n *   ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT);\n *   // Initialize a buffer with multiple colors\n *   uint32_t buffer[3] = {0xFF0000, 0x00FF00, 0x0000FF};\n * \n *   while (true) {\n *     // Set the first pixel to red\n *     ext_adi_led_set_pixel(led, buffer, 3, 0xFF0000, 0);\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_led_set_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color, uint32_t pixel_position);\n\n/**\n * @brief Clear one pixel on the led strip\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of ADI Ports\n * EINVAL - A given value is not correct, or the buffer is null\n * EADDRINUSE - The port is not configured for ADI output\n *\n * @param led port of type adi_led_t\n * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw\n * @param buffer_length length of the input buffer\n * @param pixel_position position of the pixel to clear (0 indexed)\n * @return PROS_SUCCESS if successful, PROS_ERR if not\n * \n * \\b Example:\n * \\code\n * #define SMART_PORT 1\n * #define ADI_PORT 'A'\n *  \n * void opcontrol() {\n *   // Initialize a led on smart port 1 and adi port A\n *   ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT);\n *   // Initialize a buffer with multiple colors\n *   uint32_t buffer[3] = {0xFF0000, 0x00FF00, 0x0000FF};\n * \n *   while (true) {\n *     // Set the first pixel to red\n *     ext_adi_led_set_pixel(led, buffer, 3, 0xFF0000, 0);\n *     delay(5);\n * \n *     // Clear the first pixel\n *     ext_adi_led_clear_pixel(led, buffer, 3, 0);\n *     delay(5);\n *   }\n * }\n * \\endcode\n */\nint32_t ext_adi_led_clear_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t pixel_position);\n\n///@}\n\n#ifdef __cplusplus\n}  // namespace c\n}  // namespace pros\n}\n#endif\n\n#endif  // _PROS_ADI_H_\n"
  },
  {
    "path": "include/pros/gps.h",
    "content": "/**\n * \\file pros/gps.h\n * \\ingroup c-gps\n *\n * Contains prototypes for functions related to the VEX GPS.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup c-gps VEX GPS Sensor C API\n * \\note For a pros-specific usage guide on the GPS, please check out our article [here.](@ref gps)\n */\n\n#ifndef _PROS_GPS_H_\n#define _PROS_GPS_H_\n\n#include <stdbool.h>\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\n#endif \n\n/**\n * \\ingroup c-gps\n */\n\n/**\n * \\addtogroup c-gps\n *  @{\n */\n\n/**\n * \\struct gps_position_s_t\n */\ntypedef struct __attribute__((__packed__)) gps_position_s {\n\t/// X Position (meters)\n\tdouble x;\n\t/// Y Position (meters)\n\tdouble y;\n} gps_position_s_t;\n\n/**\n * \\struct gps_status_s_t\n */\ntypedef struct __attribute__((__packed__)) gps_status_s {\n\t/// X Position (meters)\n\tdouble x;\n\t/// Y Position (meters)\n\tdouble y;\n\t/// Perceived Pitch based on GPS + IMU\n\tdouble pitch;\n\t/// Perceived Roll based on GPS + IMU\n\tdouble roll;\n\t/// Perceived Yaw based on GPS + IMU\n\tdouble yaw;\n} gps_status_s_t;\n\n/**\n * \\struct gps_orientation_s_t\n */\ntypedef struct __attribute__((__packed__)) gps_orientation_s {\n\t/// Perceived Pitch based on GPS + IMU\n\tdouble pitch;\n\t/// Perceived Roll based on GPS + IMU\n\tdouble roll;\n\t/// Perceived Yaw based on GPS + IMU\n\tdouble yaw;\n} gps_orientation_s_t;\n\n\n/**\n * \\struct gps_raw_s\n */\nstruct gps_raw_s {\n\t/// Perceived Pitch based on GPS + IMU\n\tdouble x;\n\t/// Perceived Roll based on GPS + IMU\n\tdouble y;\n\t/// Perceived Yaw based on GPS + IMU\n\tdouble z;\n};\n\n/**\n * \\struct gps_accel_s_t\n * \n */\ntypedef struct gps_raw_s gps_accel_s_t;\n\n/**\n * \\struct gps_gyro_s_t\n * \n */\ntypedef struct gps_raw_s gps_gyro_s_t;\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n\n/**\n * Set the GPS's offset relative to the center of turning in meters,\n * as well as its initial position.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \\param  xOffset\n * \t\t\t\t Cartesian 4-Quadrant X offset from center of turning (meters)\n * \\param  yOffset\n * \t\t\t\t Cartesian 4-Quadrant Y offset from center of turning (meters)\n * \\param  xInitial\n * \t\t\t\t Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)\n * \\param  yInitial\n * \t\t\t\t Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)\n * \\param  headingInitial\n *  \t\t\t Heading with 0 being north on the field, in degrees [0,360) going clockwise\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n * #define X_OFFSET .225\n * #define Y_OFFSET .223\n * #define X_INITIAL 1.54\n * #define Y_INITIAL 1.14\n * #define HEADING_INITIAL 90\n * \n * void initialize() {\n *   gps_initialize_full(GPS_PORT, X_OFFSET, Y_OFFSET, X_INITIAL, Y_INITIAL, HEADING_INITIAL);\n * }\n * \\endcode\n */\nint32_t gps_initialize_full(uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset,\n                            double yOffset);\n\n/**\n * Set the GPS's offset relative to the center of turning in meters.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \\param  xOffset\n * \t\t\t\t Cartesian 4-Quadrant X offset from center of turning (meters)\n * \\param  yOffset\n * \t\t\t\t Cartesian 4-Quadrant Y offset from center of turning (meters)\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n * #define X_OFFSET -.225\n * #define Y_OFFSET .225\n * \n * void initialize() {\n *   gps_set_offset(GPS_PORT, X_OFFSET, Y_OFFSET);\n * }\n * \\endcode\n */\nint32_t gps_set_offset(uint8_t port, double xOffset, double yOffset);\n\n/**\n * Get the GPS's cartesian location relative to the center of turning/origin in meters.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \\return A struct (gps_position_s_t) containing the X and Y values if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n * \n * void opcontrol() {\n *   gps_position_s_t pos;\n * \n *   while (true) {\n *     pos = gps_get_offset(GPS_PORT);\n *     screen_print(TEXT_MEDIUM, 1, \"X Offset: %4d, Y Offset: %4d\", pos.x, pos.y);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ngps_position_s_t gps_get_offset(uint8_t port);\n\n/**\n * Sets the robot's location relative to the center of the field in meters.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \\param  xInitial\n * \t\t\t\t Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)\n * \\param  yInitial\n * \t\t\t\t Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)\n * \\param  headingInitial\n *  \t\t\t Heading with 0 being north on the field, in degrees [0,360) going clockwise\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n * #define X_INITIAL -1.15\n * #define Y_INITIAL 1.45\n * #define HEADING_INITIAL 90\n * \n * void initialize() {\n *   gps_set_position(GPS_PORT, X_INITIAL, Y_INITIAL, HEADING_INITIAL);\n * }\n * \\endcode\n */\nint32_t gps_set_position(uint8_t port, double xInitial, double yInitial, double headingInitial);\n\n/**\n * Set the GPS sensor's data rate in milliseconds, only applies to IMU on GPS.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \\param  rate\n * \t\t\t\t Data rate in milliseconds (Minimum: 5 ms)\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n * #define GPS_DATA_RATE 5\n * \n * void initialize() {\n *   gps_set_data_rate(GPS_PORT, GPS_DATA_RATE);\n *   while (true) {\n *     // Do something\n *   }\n * }\n * \\endcode\n */\nint32_t gps_set_data_rate(uint8_t port, uint32_t rate);\n\n/**\n * Get the possible RMS (Root Mean Squared) error in meters for GPS position.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n *\n * \\return Possible RMS (Root Mean Squared) error in meters for GPS position.\n * If the operation failed, returns PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n * \n * void opcontrol() {\n *   double error;\n *   error = gps_get_error(GPS_PORT);\n *   screen_print(TEXT_MEDIUM, 1, \"Error: %4d\", error);\n * }\n * \\endcode\n */\ndouble gps_get_error(uint8_t port);\n\n/**\n * Gets the position and roll, yaw, and pitch of the GPS.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n *\n * \\return A struct (gps_status_s_t) containing values mentioned above.\n * If the operation failed, all the structure's members are filled with\n * PROS_ERR_F and errno is set.\n *\n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   gps_status_s_t status;\n *\n *   while (true) {\n *     status = gps_get_position_and_orientation(GPS_PORT);\n *     printf(\"X: %f, Y: %f, Pitch: %f, Roll: %f, Yaw: %f\\n\", status.x, status.y, status.pitch, status.roll, status.yaw);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ngps_status_s_t gps_get_position_and_orientation(uint8_t port);\n\n/**\n * Gets the x and y position on the field of the GPS in meters.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n *\n * \\return A struct (gps_position_s_t) containing values mentioned above.\n * If the operation failed, all the structure's members are filled with\n * PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   gps_position_s_t position;\n *\n *   while (true) {\n *     position = gps_get_position(GPS_PORT);\n *     printf(\"X: %f, Y: %f\\n\", position.x, position.y);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ngps_position_s_t gps_get_position(uint8_t port);\n\n/**\n * Gets the X position in meters of the robot relative to the starting position.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \n * \\return The X position in meters. If the operation failed,\n * returns PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double pos_x;\n *\n *   while (true) {\n *     pos_x = gps_get_position_x(GPS_PORT);\n *     printf(\"X: %f\\n\", pos_x);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble gps_get_position_x(uint8_t port);\n\n/**\n * Gets the Y position in meters of the robot relative to the starting position.\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \n * \\return The Y position in meters. If the operation failed,\n * returns PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double pos_y;\n *\n *   while (true) {\n *     pos_y = gps_get_position_y(GPS_PORT);\n *     printf(\"Y: %f\\n\", pos_y);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble gps_get_position_y(uint8_t port);\n\n/**\n * Gets the pitch, roll, and yaw of the GPS relative to the starting orientation.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n *\n * \\return A struct (gps_orientation_s_t) containing values mentioned above.\n * If the operation failed, all the structure's members are filled with\n * PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   gps_orientation_s_t orientation;\n *\n *   while (true) {\n *     orientation = gps_get_orientation(GPS_PORT);\n *     printf(\"pitch: %f, roll: %f, yaw: %f\\n\", orientation.pitch, orientation.roll, orientation.yaw);\n *     delay(20);\n *   }\n * }\n * \\endcode\n*/\ngps_orientation_s_t gps_get_orientation(uint8_t port);\n\n/**\n * Gets the pitch of the robot in degrees relative to the starting oreintation.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \n * \\return The pitch in [0,360) degree values. If the operation failed,\n * returns PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double pitch;\n *\n *   while (true) {\n *     pitch = gps_get_pitch(GPS_PORT);\n *     printf(\"pitch: %f\\n\", pitch);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble gps_get_pitch(uint8_t port);\n\n/**\n * Gets the roll of the robot in degrees relative to the starting oreintation.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \n * \\return The roll in [0,360) degree values. If the operation failed,\n * returns PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double roll;\n *\n *   while (true) {\n *     roll = gps_get_roll(GPS_PORT);\n *     printf(\"roll: %f\\n\", roll);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble gps_get_roll(uint8_t port);\n\n/**\n * Gets the yaw of the robot in degrees relative to the starting oreintation.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \n * \\return The yaw in [0,360) degree values. If the operation failed,\n * returns PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double yaw;\n *\n *   while (true) {\n *     yaw = gps_get_yaw(GPS_PORT);\n *     printf(\"yaw: %f\\n\", yaw);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble gps_get_yaw(uint8_t port);\n\n/**\n * Get the heading in [0,360) degree values.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n *\n * \\return The heading in [0,360) degree values. If the operation failed,\n * returns PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double heading;\n *\n *   while (true) {\n *     heading = gps_get_heading(GPS_PORT);\n *     printf(\"heading: %f\\n\", heading);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble gps_get_heading(uint8_t port);\n\n/**\n * Get the heading in the max double value and min double value scale.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n *\n * \\return The heading in [DOUBLE_MIN, DOUBLE_MAX] values. If the operation\n * fails, returns PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double heading_raw;\n *\n *   while (true) {\n *     heading_raw = gps_get_heading_raw(GPS_PORT);\n *     printf(\"heading_raw: %f\\n\", heading_raw);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble gps_get_heading_raw(uint8_t port);\n\n/**\n * Get the GPS's raw gyroscope values\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \\return A struct (gps_gyro_s_t) containing values mentioned above.\n * If the operation failed, all the\n * structure's members are filled with PROS_ERR_F and errno is set.\n *\n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   gps_gyro_s_t gyro;\n *\n *   while (true) {\n *     gyro = gps_get_gyro(GPS_PORT);\n *     printf(\"Gyro: %f %f %f\\n\", gyro.x, gyro.y, gyro.z);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ngps_gyro_s_t gps_get_gyro_rate(uint8_t port);\n\n/**\n * Get the GPS's raw gyroscope value in x-axis\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n * \n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \\return The raw gyroscope value in x-axis. If the operation fails, returns\n * PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double gyro_x;\n *\n *   while (true) {\n *     gyro_x = gps_get_gyro_x(GPS_PORT);\n *     printf(\"gyro_x: %f\\n\", gyro_x);\n *     delay(20);\n *   }\n * }\n * \\endcode\n*/\ndouble gps_get_gyro_rate_x(uint8_t port);\n\n/**\n * Get the GPS's raw gyroscope value in y-axis\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n * \n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \\return The raw gyroscope value in y-axis. If the operation fails, returns\n * PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double gyro_y;\n *\n *   while (true) {\n *     gyro_y = gps_get_gyro_y(GPS_PORT);\n *     printf(\"gyro_y: %f\\n\", gyro_y);\n *     delay(20);\n *   }\n * }\n * \\endcode\n*/\ndouble gps_get_gyro_rate_y(uint8_t port);\n\n/**\n * Get the GPS's raw gyroscope value in z-axis\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a GPS\n * EAGAIN - The sensor is still calibrating\n * \n * \\param  port\n * \t\t\t\t The V5 GPS port number from 1-21\n * \\return The raw gyroscope value in z-axis. If the operation fails, returns\n * PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double gyro_z;\n *\n *   while (true) {\n *     gyro_z = gps_get_gyro_z(GPS_PORT);\n *     printf(\"gyro_z: %f\\n\", gyro_z);\n *     delay(20);\n *   }\n * }\n * \\endcode\n*/\ndouble gps_get_gyro_rate_z(uint8_t port);\n\n/**\n * Get the GPS's raw accelerometer values\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an GPS\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 GPS's port number from 1-21\n * \\return A struct (gps_accel_s_t) containing values mentioned above.\n * If the operation failed, all the\n * structure's members are filled with PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   gps_accel_s_t accel;\n *\n *   while (true) {\n *     accel = gps_get_accel(GPS_PORT);\n *     printf(\"X: %f, Y: %f, Z: %f\\n\", accel.x, accel.y, accel.z);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ngps_accel_s_t gps_get_accel(uint8_t port);\n\n/**\n * Get the GPS's raw accelerometer value in x-axis\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an GPS\n * EAGAIN - The sensor is still calibrating\n * \n * \\param  port\n * \t\t\t\t The V5 GPS's port number from 1-21\n * \\return The raw accelerometer value in x-axis. If the operation fails, returns\n * PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double accel_x;\n *\n *   while (true) {\n *     accel_x = gps_get_accel_x(GPS_PORT);\n *     printf(\"accel_x: %f\\n\", accel_x);\n *     delay(20);\n *   }\n * }\n * \\endcode\n*/\ndouble gps_get_accel_x(uint8_t port);\n\n/**\n * Get the GPS's raw accelerometer value in y-axis\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an GPS\n * EAGAIN - The sensor is still calibrating\n * \n * \\param  port\n * \t\t\t\t The V5 GPS's port number from 1-21\n * \\return The raw accelerometer value in y-axis. If the operation fails, returns\n * PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double accel_y;\n *\n *   while (true) {\n *     accel_y = gps_get_accel_y(GPS_PORT);\n *     printf(\"accel_y: %f\\n\", accel_y);\n *     delay(20);\n *   }\n * }\n * \\endcode\n*/\ndouble gps_get_accel_y(uint8_t port);\n\n/**\n * Get the GPS's raw accelerometer value in z-axis\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an GPS\n * EAGAIN - The sensor is still calibrating\n * \n * \\param  port\n * \t\t\t\t The V5 GPS's port number from 1-21\n * \\return The raw accelerometer value in z-axis. If the operation fails, returns\n * PROS_ERR_F and errno is set.\n * \n * \\b Example\n * \\code\n * #define GPS_PORT 1\n *\n * void opcontrol() {\n *   double accel_z;\n *\n *   while (true) {\n *     accel_z = gps_get_accel_z(GPS_PORT);\n *     printf(\"accel_z: %f\\n\", accel_z);\n *     delay(20);\n *   }\n * }\n * \\endcode\n*/\ndouble gps_get_accel_z(uint8_t port);\n\n#ifdef __cplusplus\n}\n}\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "include/pros/gps.hpp",
    "content": "/**\n * \\file pros/gps.hpp\n * \\ingroup cpp-gps\n *\n * Contains prototypes for functions related to the VEX GPS.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-gps VEX GPS Sensor C API\n * \\note For a pros-specific usage guide on the GPS, please check out our article [here.](@ref gps)\n */\n\n#ifndef _PROS_GPS_HPP_\n#define _PROS_GPS_HPP_\n\n#include <stdbool.h>\n\n#include <cstdint>\n#include <iostream>\n\n#include \"pros/device.hpp\"\n#include \"pros/gps.h\"\n\nnamespace pros {\ninline namespace v5 {\n/**\n * \\ingroup cpp-gps\n *  @{\n */\nclass Gps : public Device {\n\t/**\n\t * \\addtogroup cpp-gps\n\t *  @{\n\t */\n\n\tpublic:\n\t/**\n\t * Creates a GPS object for the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t * \\b Example:\n\t * \\code\n\t * pros::Gps gps(1);\n\t * \\endcode\n\t *\n\t */\n\tGps(const std::uint8_t port) : Device(port, DeviceType::gps){};\n\n\tGps(const Device& device) : Gps(device.get_port()){};\n\n\t/**\n\t * Creates a GPS object for the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t * \\param xInitial\n\t * \t\t\t\t Cartesian 4-Quadrant X initial position (meters)\n\t * \\param yInitial\n\t * \t\t\t\t Cartesian 4-Quadrant Y initial position (meters)\n\t * \\param headingInitial\n\t * \t\t\t\t Initial heading (degrees)\n\t *\n\t * \\b Example:\n\t * \\code\n\t * pros::Gps gps(1, 1.30, 1.20, 90);\n\t * \\endcode\n\t *\n\t */\n\texplicit Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial)\n\t    : Device(port, DeviceType::gps) {\n\t\tpros::c::gps_set_position(port, xInitial, yInitial, headingInitial);\n\t};\n\n\t/**\n\t * Creates a GPS object for the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t * \\param xOffset\n\t * \t\t\t\t Cartesian 4-Quadrant X offset from center of turning (meters)\n\t * \\param yOffset\n\t * \t\t\t\t Cartesian 4-Quadrant Y offset from center of turning (meters)\n\t *\n\t * \\b Example:\n\t * \\code\n\t * pros::Gps gps(1, 1.30, 1.20);\n\t * \\endcode\n\t *\n\t */\n\texplicit Gps(const std::uint8_t port, double xOffset, double yOffset) : Device(port, DeviceType::gps) {\n\t\tpros::c::gps_set_offset(port, xOffset, yOffset);\n\t};\n\n\t/**\n\t * Creates a GPS object for the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t * \\param xInitial\n\t * \t\t\t\t Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)\n\t * \\param yInitial\n\t * \t\t\t\t Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)\n\t * \\param headingInitial\n\t * \t\t\t\t Initial Heading, with 0 being North, 90 being East, 180 being South, and 270 being West (degrees)\n\t * \\param xOffset\n\t * \t\t\t\t Cartesian 4-Quadrant X offset from center of turning (meters)\n\t * \\param yOffset\n\t * \t\t\t\t Cartesian 4-Quadrant Y offset from center of turning (meters)\n\t *\n\t * \\b Example:\n\t * \\code\n\t * pros::Gps gps(1, 1.30, 1.20, 180, 1.30, 1.20);\n\t * \\endcode\n\t *\n\t */\n\texplicit Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset,\n\t             double yOffset)\n\t    : Device(port, DeviceType::gps) {\n\t\tpros::c::gps_initialize_full(port, xInitial, yInitial, headingInitial, xOffset, yOffset);\n\t};\n\n\t/**\n\t * Set the GPS's offset relative to the center of turning in meters,\n\t * as well as its initial position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  xOffset\n\t * \t\t\t\t Cartesian 4-Quadrant X offset from center of turning (meters)\n\t * \\param  yOffset\n\t * \t\t\t\t Cartesian 4-Quadrant Y offset from center of turning (meters)\n\t * \\param  xInitial\n\t * \t\t\t\t Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)\n\t * \\param  yInitial\n\t * \t\t\t\t Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)\n\t * \\param  headingInitial\n\t *  \t\t\t Heading with 0 being north on the field, in degrees [0,360) going clockwise\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT, 1.1, 1.2, 180, .4, .4);\n\t *  // this is equivalent to the above line\n\t *  gps.initialize_full(1.1, 1.2, 180, .4, .4);\n\t *   while (true) {\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t initialize_full(double xInitial, double yInitial, double headingInitial, double xOffset,\n\t                                     double yOffset) const;\n\n\t/**\n\t * Set the GPS's offset relative to the center of turning in meters.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  xOffset\n\t * \t\t\t\t Cartesian 4-Quadrant X offset from center of turning (meters)\n\t * \\param  yOffset\n\t * \t\t\t\t Cartesian 4-Quadrant Y offset from center of turning (meters)\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT, 1.1, 1.2, 180, .4, .4);\n\t *  // this is equivalent to the above line\n\t *  gps.set_offset(.4, .4);\n\t *   while (true) {\n\t *\t \tdelay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_offset(double xOffset, double yOffset) const;\n\n\t/**\n\n\t * Gets all GPS sensors.\n\t *\n\t * \\return A vector of Gps sensor objects.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   std::vector<Gps> gps_all = pros::Gps::get_all_devices();  // All GPS sensors that are connected\n\t * }\n\t * \\endcode\n\t */\n\tstatic std::vector<Gps> get_all_devices();\n\n\t/**\n\t * Get the GPS's cartesian location relative to the center of turning/origin in meters.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 GPS port number from 1-21\n\t * \\return A struct (gps_position_s_t) containing the X and Y values if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   gps_position_s_t pos;\n\t * \tGps gps(GPS_PORT);\n\t *   while (true) {\n\t *     pos = gps.get_offset();\n\t *     screen_print(TEXT_MEDIUM, 1, \"X Offset: %4d, Y Offset: %4d\", pos.x, pos.y);\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::gps_position_s_t get_offset() const;\n\n\t/**\n\t * Sets the robot's location relative to the center of the field in meters.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  xInitial\n\t * \t\t\t\t Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)\n\t * \\param  yInitial\n\t * \t\t\t\t Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)\n\t * \\param  headingInitial\n\t *  \t\t\t Heading with 0 being north on the field, in degrees [0,360) going clockwise\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  gps.set_position(1.3, 1.4, 180);\n\t *   while (true) {\n\t *     printf(\"X: %f, Y: %f, Heading: %f\\n\", gps.get_position().x,\n\t * \t   gps.get_position().y, gps.get_position().heading);\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_position(double xInitial, double yInitial, double headingInitial) const;\n\n\t/**\n\t * Set the GPS sensor's data rate in milliseconds, only applies to IMU on GPS.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  rate\n\t * \t\t\t\t Data rate in milliseconds (Minimum: 5 ms)\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  gps.set_data_rate(10);\n\t *   while (true) {\n\t *\t \tprintf(\"X: %f, Y: %f, Heading: %f\\n\", gps.get_position().x,\n\t * \t   gps.get_position().y, gps.get_position().heading);\n\t *\t \tdelay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_data_rate(std::uint32_t rate) const;\n\n\t/**\n\t * Get the possible RMS (Root Mean Squared) error in meters for GPS position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return Possible RMS (Root Mean Squared) error in meters for GPS position.\n\t * If the operation failed, returns PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  double error = gps.get_error();\n\t *\tprintf(\"Error: %f\\n\", error);\n\t *  pros::delay(20);\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_error() const;\n\n\t/**\n\t * Gets the position and roll, yaw, and pitch of the GPS.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t *\n\t * \\return A struct (gps_status_s_t) containing values mentioned above.\n\t * If the operation failed, all the structure's members are filled with\n\t * PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  gps_status_s_t status;\n\t *   while (true) {\n\t *     status = gps.get_position_and_orientation();\n\t *     printf(\"X: %f, Y: %f, Roll: %f, Pitch: %f, Yaw: %f\\n\",\n\t * \t   status.x, status.y, status.roll, status.pitch, status.yaw);\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::gps_status_s_t get_position_and_orientation() const;\n\n\t/**\n\t * Gets the x and y position on the field of the GPS in meters.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return A struct (gps_position_s_t) containing values mentioned above.\n\t * If the operation failed, all the structure's members are filled with\n\t * PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  gps_position_s_t position;\n\t *   while (true) {\n\t *\t position = gps.get_position();\n\t *     printf(\"X: %f, Y: %f\\n\", position.x, position.y);\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::gps_position_s_t get_position() const;\n\n\t/**\n\t * Gets the X position in meters of the robot relative to the starting position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The X position in meters. If the operation failed,\n\t * returns PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble pos_x = gps.get_position_x();\n\t *\t\tprintf(\"X: %f\\n\", pos_x);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_position_x() const;\n\n\t/**\n\t * Gets the Y position in meters of the robot relative to the starting position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The Y position in meters. If the operation failed,\n\t * returns PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble pos_y = gps.get_position_y();\n\t *\t\tprintf(\"Y: %f\\n\", pos_y);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_position_y() const;\n\n\t/**\n\t * Gets the pitch, roll, and yaw of the GPS relative to the starting orientation.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return A struct (gps_orientation_s_t) containing values mentioned above.\n\t * If the operation failed, all the structure's members are filled with\n\t * PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  gps_orientation_s_t orientation;\n\t *   while (true) {\n\t *\t orientation = gps.get_orientation();\n\t *     printf(\"pitch: %f, roll: %f, yaw: %f\\n\", orientation.pitch,\n\t *         orientation.roll, orientation.yaw);\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::gps_orientation_s_t get_orientation() const;\n\n\t/**\n\t * Gets the pitch of the robot in degrees relative to the starting oreintation.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The pitch in [0,360) degree values. If the operation failed,\n\t * returns PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble pitch = gps.get_pitch();\n\t *\t\tprintf(\"pitch: %f\\n\", pitch);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_pitch() const;\n\n\t/**\n\t * Gets the roll of the robot in degrees relative to the starting oreintation.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The roll in [0,360) degree values. If the operation failed,\n\t * returns PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble roll = gps.get_roll();\n\t *\t\tprintf(\"roll: %f\\n\", roll);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_roll() const;\n\n\t/**\n\t * Gets the yaw of the robot in degrees relative to the starting oreintation.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The yaw in [0,360) degree values. If the operation failed,\n\t * returns PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble yaw = gps.get_yaw();\n\t *\t\tprintf(\"yaw: %f\\n\", yaw);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_yaw() const;\n\n\t/**\n\t * Get the heading in [0,360) degree values.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t *\n\t * \\return The heading in [0,360) degree values. If the operation failed,\n\t * returns PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble heading = gps.get_heading();\n\t *\t\tprintf(\"Heading: %f\\n\", heading);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_heading() const;\n\n\t/**\n\t * Get the heading in the max double value and min double value scale.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The heading in [DOUBLE_MIN, DOUBLE_MAX] values. If the operation\n\t * fails, returns PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble heading = gps.get_heading_raw();\n\t *\t\tprintf(\"Heading: %f\\n\", heading);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_heading_raw() const;\n\n\t/**\n\t * Get the GPS's raw gyroscope value in z-axis\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The raw gyroscope value in z-axis. If the operation fails, returns\n\t * PROS_ERR_F and errno is set.\n\t *\n\t \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble gyro_z = gps.get_gyro_z();\n\t *\t\tprintf(\"gyro_z: %f\\n\", gyro_z);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::gps_gyro_s_t get_gyro_rate() const;\n\n\t/**\n\t * Get the GPS's raw gyroscope value in x-axis\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The raw gyroscope value in x-axis. If the operation fails, returns\n\t * PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble gyro_x = gps.get_gyro_x();\n\t *\t\tprintf(\"gyro_x: %f\\n\", gyro_x);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_gyro_rate_x() const;\n\n\t/**\n\t * Get the GPS's raw gyroscope value in y-axis\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The raw gyroscope value in y-axis. If the operation fails, returns\n\t * PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble gyro_y = gps.get_gyro_y();\n\t *\t\tprintf(\"gyro_y: %f\\n\", gyro_y);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_gyro_rate_y() const;\n\n\t/**\n\t * Get the GPS's raw gyroscope value in z-axis\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The raw gyroscope value in z-axis. If the operation fails, returns\n\t * PROS_ERR_F and errno is set.\n\t *\n\t \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble gyro_z = gps.get_gyro_z();\n\t *\t\tprintf(\"gyro_z: %f\\n\", gyro_z);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t*/\n\tvirtual double get_gyro_rate_z() const;\n\n\t/**\n\t * Get the GPS's raw accelerometer values\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The raw accelerometer values. If the operation failed, all the\n\t * structure's members are filled with PROS_ERR_F and errno is set.\n\t */\n\tvirtual pros::gps_accel_s_t get_accel() const;\n\n\t/**\n\t * Get the GPS's raw accelerometer value in x-axis\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The raw accelerometer value in x-axis. If the operation fails, returns\n\t * PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble accel_x = gps.get_accel_x();\n\t *\t\tprintf(\"accel_x: %f\\n\", accel_x);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_accel_x() const;\n\n\t/**\n\t * Get the GPS's raw accelerometer value in y-axis\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The raw accelerometer value in y-axis. If the operation fails, returns\n\t * PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble accel_y = gps.get_accel_y();\n\t *\t\tprintf(\"accel_y: %f\\n\", accel_y);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_accel_y() const;\n\n\t/**\n\t * Get the GPS's raw accelerometer value in z-axis\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an GPS\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\return The raw accelerometer value in z-axis. If the operation fails, returns\n\t * PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tdouble accel_z = gps.get_accel_z();\n\t *\t\tprintf(\"accel_z: %f\\n\", accel_z);\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_accel_z() const;\n\n\t/**\n\t * This is the overload for the << operator for printing to streams\n\t *\n\t * Prints in format:\n\t * Gps [port: gps._port, x: (x position), y: (y position), heading: (gps heading), rotation: (gps rotation)]\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define GPS_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tGps gps(GPS_PORT);\n\t *  while(true) {\n\t *\t\tstd::cout << gps << std::endl;\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tfriend std::ostream& operator<<(std::ostream& os, const pros::Gps& gps);\n\n\t/**\n\t * Gets a gps sensor that is plugged in to the brain\n\t *\n\t * \\note The first time this function is called it returns the gps sensor at the lowest port\n\t * If this function is called multiple times, it will cycle through all the ports.\n\t * For example, if you have 1 gps sensor on the robot\n\t * this function will always return a gps sensor object for that port.\n\t * If you have 2 gps sensors, all the odd numered calls to this function will return objects\n\t * for the lower port number,\n\t * all the even number calls will return gps objects for the higher port number\n\t *\n\t *\n\t * This functions uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - No gps sensor is plugged into the brain\n\t *\n\t * \\return A gps object corresponding to a port that a gps sensor is connected to the brain\n\t * If no gps sensor is plugged in, it returns a gps sensor on port PROS_ERR_BYTE\n\t *\n\t */\n\tstatic Gps get_gps();\n\t///@}\n};  // Gps Class\n\nnamespace literals {\n/**\n * Constructs a Gps object with the given port number\n *\n * \\b Example\n * \\code\n * using namespace literals;\n *\n * void opcontrol() {\n * \t pros::Gps gps = 1_gps;\n *   while (true) {\n *     pos = gps.get_position();\n *     screen_print(TEXT_MEDIUM, 1, \"X Position: %4d, Y Position: %4d\", pos.x, pos.y);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nconst pros::Gps operator\"\"_gps(const unsigned long long int g);\n}  // namespace literals\n\n/// @brief\n/// Alias for Gps is GPS for user convenience.\nusing GPS = Gps;\n\n}  // namespace v5\n}  // namespace pros\n\n#endif\n"
  },
  {
    "path": "include/pros/imu.h",
    "content": "/**\n * \\file pros/imu.h\n * \\ingroup c-imu\n *\n * Contains prototypes for functions related to the VEX Inertial sensor.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup c-imu VEX Inertial Sensor C API\n */\n\n#ifndef _PROS_IMU_H_\n#define _PROS_IMU_H_\n\n#include <stdbool.h>\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\n#endif\n\n/**\n * \\ingroup c-imu\n * */\n\n/**\n * \\addtogroup c-imu\n *  @{\n */\n\n/**\n * \\enum imu_status_e_t\n * @brief Indicates IMU status.\n */\ntypedef enum imu_status_e {\n\tE_IMU_STATUS_READY = 0,  // IMU is connected but not currently calibrating\n\t/** The IMU is calibrating */\n\tE_IMU_STATUS_CALIBRATING = 1,\n\t/** Used to indicate that an error state was reached in the imu_get_status function,\\\n\tnot that the IMU is necessarily in an error state */\n\tE_IMU_STATUS_ERROR = 0xFF,\n} imu_status_e_t;\n\ntypedef enum imu_orientation_e {\n\tE_IMU_Z_UP = 0,                 // IMU has the Z axis UP (VEX Logo facing DOWN)\n\tE_IMU_Z_DOWN = 1,               // IMU has the Z axis DOWN (VEX Logo facing UP)\n\tE_IMU_X_UP = 2,                 // IMU has the X axis UP\n\tE_IMU_X_DOWN = 3,               // IMU has the X axis DOWN\n\tE_IMU_Y_UP = 4,                 // IMU has the Y axis UP\n\tE_IMU_Y_DOWN = 5,               // IMU has the Y axis DOWN\n\tE_IMU_ORIENTATION_ERROR = 0xFF  // NOTE: used for returning an error from the get_physical_orientation function, not\n\t                                // that the IMU is necessarily in an error state\n} imu_orientation_e_t;\n\n/**\n * \\struct quaternion_s_t\n */\ntypedef struct __attribute__((__packed__)) quaternion_s {\n\tdouble x;\n\tdouble y;\n\tdouble z;\n\tdouble w;\n} quaternion_s_t;\n\n/**\n * \\struct imu_raw_s\n *\n */\nstruct imu_raw_s {\n\tdouble x;\n\tdouble y;\n\tdouble z;\n};\n\n/**\n * \\struct imu_gyro_s_t\n *\n */\ntypedef struct imu_raw_s imu_gyro_s_t;\n\n/**\n * \\struct imu_accel_s_t\n *\n */\ntypedef struct imu_raw_s imu_accel_s_t;\n\n/**\n * \\struct euler_s_t\n *\n */\ntypedef struct __attribute__((__packed__)) euler_s {\n\tdouble pitch;\n\tdouble roll;\n\tdouble yaw;\n} euler_s_t;\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n/**\n * \\def IMU_MINIMUM_DATA_RATE\n */\n#ifdef PROS_USE_SIMPLE_NAMES\n#ifdef __cplusplus\n#define IMU_STATUS_CALIBRATING pros::E_IMU_STATUS_CALIBRATING\n#define IMU_STATUS_ERROR pros::E_IMU_STATUS_ERROR\n#else\n#define IMU_STATUS_CALIBRATING E_IMU_STATUS_CALIBRATING\n#define IMU_STATUS_ERROR E_IMU_STATUS_ERROR\n#endif\n#endif\n\n#define IMU_MINIMUM_DATA_RATE 5\n\n/**\n * Calibrate IMU\n *\n * Calibration takes approximately 2 seconds, but this function only blocks\n * until the IMU status flag is set properly to E_IMU_STATUS_CALIBRATING,\n * with a minimum blocking time of 5ms.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is already calibrating, or time out setting the status flag.\n *\n * \\param port\n *        The V5 Inertial Sensor port number from 1-21\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void initialize() {\n *   imu_reset(IMU_PORT);\n *   int time = millis();\n *   int iter = 0;\n *   while (imu_get_status(IMU_PORT) & E_IMU_STATUS_CALIBRATING) {\n *     printf(\"IMU calibrating... %d\\n\", iter);\n *     iter += 10;\n *     delay(10);\n *   }\n *   // should print about 2000 ms\n *   printf(\"IMU is done calibrating (took %d ms)\\n\", iter - time);\n * }\n * \\endcode\n */\nint32_t imu_reset(uint8_t port);\n\n/**\n * Calibrate IMU and Blocks while Calibrating\n *\n * Calibration takes approximately 2 seconds and blocks during this period,\n * with a timeout for this operation being set a 3 seconds as a safety margin.\n * Like the other reset function, this function also blocks until the IMU\n * status flag is set properly to E_IMU_STATUS_CALIBRATING, with a minimum\n * blocking time of 5ms and a timeout of 1 second if it's never set.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is already calibrating, or time out setting the status flag.\n *\n * \\param port\n *        The V5 Inertial Sensor port number from 1-21\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed (timing out or port claim failure), setting errno.\n */\nint32_t imu_reset_blocking(uint8_t port);\n/**\n * Set the Inertial Sensor's refresh interval in milliseconds.\n *\n * The rate may be specified in increments of 5ms, and will be rounded down to\n * the nearest increment. The minimum allowable refresh rate is 5ms. The default\n * rate is 10ms.\n *\n * As values are copied into the shared memory buffer only at 10ms intervals,\n * setting this value to less than 10ms does not mean that you can poll the\n * sensor's values any faster. However, it will guarantee that the data is as\n * recent as possible.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param port\n *\t\t  The V5 Inertial Sensor port number from 1-21\n * \\param rate The data refresh interval in milliseconds\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n *\n * \\endcode\n */\nint32_t imu_set_data_rate(uint8_t port, uint32_t rate);\n\n/**\n * Get the total number of degrees the Inertial Sensor has spun about the z-axis\n *\n * This value is theoretically unbounded. Clockwise rotations are represented\n * with positive degree values, while counterclockwise rotations are represented\n * with negative ones.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return The degree value or PROS_ERR_F if the operation failed, setting\n * errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     printf(\"IMU get rotation: %f degrees\\n\", imu_get_rotation(IMU_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble imu_get_rotation(uint8_t port);\n\n/**\n * Get the Inertial Sensor's heading relative to the initial direction of its\n * x-axis\n *\n * This value is bounded by [0,360). Clockwise rotations are represented with\n * positive degree values, while counterclockwise rotations are represented with\n * negative ones.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return The degree value or PROS_ERR_F if the operation failed, setting\n * errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     printf(\"IMU get heading: %f degrees\\n\", imu_get_heading(IMU_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble imu_get_heading(uint8_t port);\n\n/**\n * Get a quaternion representing the Inertial Sensor's orientation\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return The quaternion representing the sensor's orientation. If the\n * operation failed, all the quaternion's members are filled with PROS_ERR_F and\n * errno is set.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     quaternion_s_t qt = imu_get_quaternion(IMU_PORT);\n *     printf(\"IMU quaternion: {x: %f, y: %f, z: %f, w: %f}\\n\", qt.x, qt.y, qt.z, qt.w);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nquaternion_s_t imu_get_quaternion(uint8_t port);\n\n/**\n * Get the Euler angles representing the Inertial Sensor's orientation\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return The Euler angles representing the sensor's orientation. If the\n * operation failed, all the structure's members are filled with PROS_ERR_F and\n * errno is set.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     euler_s_t eu = imu_get_euler(IMU_PORT);\n *     printf(\"IMU euler angles: {pitch: %f, roll: %f, yaw: %f}\\n\", eu.pitch, eu.roll, eu.yaw);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\neuler_s_t imu_get_euler(uint8_t port);\n\n/**\n * Get the Inertial Sensor's raw gyroscope values\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return The pitch angle, or PROS_ERR_F if the operation failed, setting\n * errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     printf(\"IMU pitch: %f\\n\", imu_get_pitch(IMU_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nimu_gyro_s_t imu_get_gyro_rate(uint8_t port);\n\n/**\n * Get the Inertial Sensor's raw acceleroneter values\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return The roll angle, or PROS_ERR_F if the operation failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     printf(\"IMU roll: %f\\n\", imu_get_roll(IMU_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nimu_accel_s_t imu_get_accel(uint8_t port);\n\n/**\n * Get the Inertial Sensor's status\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return The yaw angle, or PROS_ERR_F if the operation failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     printf(\"IMU yaw: %f\\n\", imu_get_yaw(IMU_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nimu_status_e_t imu_get_status(uint8_t port);\n\n// Value set functions:\n/**\n * Sets the current reading of the Inertial Sensor's euler values to\n * target euler values. Will default to +/- 180 if target exceeds +/- 180.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return The raw gyroscope values. If the operation failed, all the\n * structure's members are filled with PROS_ERR_F and errno is set.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     int32_t val = imu_set_euler(IMU_PORT, {45, 60, 90});\n *     printf(\"IMU : {gyro vals: %d}\\n\", val);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_set_euler(uint8_t port, euler_s_t target);\n\n/**\n * Get the Inertial Sensor's pitch angle bounded by (-180,180)\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return The raw accelerometer values. If the operation failed, all the\n * structure's members are filled with PROS_ERR_F and errno is set.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     imu_accel_s_t accel = imu_get_accel(IMU_PORT);\n *     printf(\"IMU accel values: {x: %f, y: %f, z: %f}\\n\", accel.x, accel.y, accel.z);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble imu_get_pitch(uint8_t port);\n\n/**\n * Get the Inertial Sensor's roll angle bounded by (-180,180)\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return The Inertial Sensor's status code, or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void initialize() {\n *   imu_reset(IMU_PORT);\n *   int time = millis();\n *   int iter = 0;\n *   while (imu_get_status(IMU_PORT) & E_IMU_STATUS_CALIBRATING) {\n *     printf(\"IMU calibrating... %d\\n\", iter);\n *     iter += 10;\n *     delay(10);\n *   }\n *   // should print about 2000 ms\n *   printf(\"IMU is done calibrating (took %d ms)\\n\", iter - time);\n * }\n * \\endcode\n */\ndouble imu_get_roll(uint8_t port);\n\n/**\n * Get the Inertial Sensor's yaw angle bounded by (-180,180)\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return The yaw angle, or PROS_ERR_F if the operation failed, setting errno.\n */\ndouble imu_get_yaw(uint8_t port);\n\n// NOTE: not used\n// void imu_set_mode(uint8_t port, uint32_t mode);\n// uint32_t imu_get_mode(uint8_t port);\n\n/**\n * \\name Value Reset Functions\n * @{\n */\n\n/**\n * Resets the current reading of the Inertial Sensor's heading to zero\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_tare_heading(IMU_PORT);\n *     }\n *   pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_tare_heading(uint8_t port);\n\n/**\n * Resets the current reading of the Inertial Sensor's rotation to zero\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_tare_rotation(IMU_PORT);\n *     }\n *   pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_tare_rotation(uint8_t port);\n\n/**\n * Resets the current reading of the Inertial Sensor's pitch to zero\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_tare_pitch(IMU_PORT);\n *     }\n *   pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_tare_pitch(uint8_t port);\n\n/**\n * Resets the current reading of the Inertial Sensor's roll to zero\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_tare_roll(IMU_PORT);\n *     }\n *   pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_tare_roll(uint8_t port);\n\n/**\n * Resets the current reading of the Inertial Sensor's yaw to zero\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_tare_yaw(IMU_PORT);\n *     }\n *   pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_tare_yaw(uint8_t port);\n\n/**\n * Reset all 3 euler values of the Inertial Sensor to 0.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_tare_euler(IMU_PORT);\n *     }\n *   pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_tare_euler(uint8_t port);\n\n/**\n * Resets all 5 values of the Inertial Sensor to 0.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_tare(IMU_PORT);\n *     }\n *   pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_tare(uint8_t port);\n\n/** @} */\n\n/**\n * \\name Value Set Functions\n * @{\n */\n\n/**\n * Sets the current reading of the Inertial Sensor's euler values to\n * target euler values. Will default to +/- 180 if target exceeds +/- 180.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\param  target\n * \t\t\t\t Target euler values for the euler values to be set to\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_set_euler(IMU_PORT, {45,45,45});\n *     }\n *     pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_set_euler(uint8_t port, euler_s_t target);\n\n/**\n * Sets the current reading of the Inertial Sensor's rotation to target value\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\param  target\n * \t\t\t\t Target value for the rotation value to be set to\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_set_rotation(IMU_PORT, 45);\n *     }\n *     pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_set_rotation(uint8_t port, double target);\n\n/**\n * Sets the current reading of the Inertial Sensor's heading to target value\n * Target will default to 360 if above 360 and default to 0 if below 0.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\param  target\n * \t\t\t\t Target value for the heading value to be set to\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_set_heading(IMU_PORT, 45);\n *     }\n *     pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_set_heading(uint8_t port, double target);\n\n/**\n * Sets the current reading of the Inertial Sensor's pitch to target value\n * Will default to +/- 180 if target exceeds +/- 180.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\param  target\n * \t\t\t\t Target value for the pitch value to be set to\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_set_pitch(IMU_PORT, 45);\n *     }\n *     pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_set_pitch(uint8_t port, double target);\n\n/**\n * Sets the current reading of the Inertial Sensor's roll to target value\n * Will default to +/- 180 if target exceeds +/- 180.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\param  target\n * \t\t\t\t Target value for the roll value to be set to\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       imu_set_roll(IMU_PORT, 45);\n *     }\n *     pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_set_roll(uint8_t port, double target);\n\n/**\n * Sets the current reading of the Inertial Sensor's yaw to target value\n * Will default to +/- 180 if target exceeds +/- 180.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n * EAGAIN - The sensor is still calibrating\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\param  target\n * \t\t\t\t Target value for the yaw value to be set to\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * #define IMU_PORT 1void opcontrol() {\n *\n * while (true) {\n *   if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *     imu_set_yaw(IMU_PORT, 45);\n *   }\n *   pros::delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t imu_set_yaw(uint8_t port, double target);\n\n/**\n * Returns the physical orientation of the IMU\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Inertial Sensor\n *\n * \\param  port\n * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n * \\returns The orientation of the Inertial Sensor or PROS_ERR if an error occured.\n *\n */\nimu_orientation_e_t imu_get_physical_orientation(uint8_t port);\n\n/** @} */\n\n/** @} */\n\n#ifdef __cplusplus\n}\n}\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "include/pros/imu.hpp",
    "content": "/**\n * \\file pros/imu.hpp\n * \\ingroup cpp-imu\n *\n * Contains prototypes for functions related to the VEX Inertial sensor.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-imu VEX Inertial Sensor C++ API\n */\n#ifndef _PROS_IMU_HPP_\n#define _PROS_IMU_HPP_\n\n#include <cstdint>\n#include <iostream>\n\n#include \"pros/device.hpp\"\n#include \"pros/imu.h\"\n\nnamespace pros {\n/**\n * \\ingroup cpp-imu\n * */\n\n/**\n * \\addtogroup cpp-imu\n *  @{\n */\n\n/**\n * \\enum Imu_Status\n * @brief Indicates IMU status.\n */\n\nenum class ImuStatus {\n\tready = 0,\n\t/** The IMU is calibrating */\n\tcalibrating = 19,\n\t/** Used to indicate that an error state was reached in the imu_get_status function,\\\n\tnot that the IMU is necessarily in an error state */\n\terror = 0xFF,\n};\n\ninline namespace v5 {\n/**\n * \\ingroup cpp-imu\n */\nclass Imu : public Device {\n\t/**\n\t * \\addtogroup cpp-imu\n\t * @{\n\t */\n\n\tpublic:\n\t/**\n\t * Creates an Imu object for the given port\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t *\n\t * \\param port\n\t *        The V5 Inertial Sensor port number from 1-21\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Do something with the sensor data\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\n\n\tImu(const std::uint8_t port) : Device(port, DeviceType::imu){};\n\n\tImu(const Device& device) : Imu(device.get_port()){};\n\n\t/**\n\t * Gets a IMU sensor that is plugged in to the brain\n\t *\n\t * \\note The first time this function is called it returns the IMU sensor at the lowest port\n\t * If this function is called multiple times, it will cycle through all the ports.\n\t * For example, if you have 1 IMU sensor on the robot\n\t * this function will always return a IMU sensor object for that port.\n\t * If you have 2 IMU sensors, all the odd numered calls to this function will return objects\n\t * for the lower port number,\n\t * all the even number calls will return IMU objects for the higher port number\n\t *\n\t *\n\t * This functions uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - No IMU sensor is plugged into the brain\n\t *\n\t * \\return A IMU object corresponding to a port that a IMU sensor is connected to the brain\n\t * If no IMU sensor is plugged in, it returns a IMU sensor on port PROS_ERR_BYTE\n\t *\n\t */\n\tstatic Imu get_imu();\n\t/**\n\t * Calibrate IMU\n\t *\n\t * Calibration takes approximately 2 seconds and blocks during this period if\n\t * the blocking param is true, with a timeout for this operation being set a 3\n\t * seconds as a safety margin. This function also blocks until the IMU\n\t * status flag is set properly to E_IMU_STATUS_CALIBRATING, with a minimum\n\t * blocking time of 5ms and a timeout of 1 second if it's never set.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is already calibrating, or time out setting the status flag.\n\t *\n\t * \\param blocking\n\t *\t\t\tWhether this function blocks during calibration.\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   // Block until calibration is complete\n\t *   imu.reset(true);\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t reset(bool blocking = false) const;\n\t/**\n\t * Set the Inertial Sensor's refresh interval in milliseconds.\n\t *\n\t * The rate may be specified in increments of 5ms, and will be rounded down to\n\t * the nearest increment. The minimum allowable refresh rate is 5ms. The default\n\t * rate is 10ms.\n\t *\n\t * As values are copied into the shared memory buffer only at 10ms intervals,\n\t * setting this value to less than 10ms does not mean that you can poll the\n\t * sensor's values any faster. However, it will guarantee that the data is as\n\t * recent as possible.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param rate The data refresh interval in milliseconds\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the refresh rate to 5ms\n\t *     std::int32_t status = imu.set_data_rate(5);\n\t *     delay(20);\n\t *\n\t *     // Check if the operation was successful\n\t *     if (status == PROS_ERR) {\n\t *       // Do something with the error\n\t *     }\n\t *\n\t *     // Do something with the sensor data\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_data_rate(std::uint32_t rate) const;\n\n\n\t/**\n\t * Gets all IMU sensors.\n\t * \n\t * \\return A vector of Imu sensor objects.\n\t *\n\t * \\b Example\n \t * \\code\n\t * void opcontrol() {\n\t *   std::vector<Imu> imu_all = pros::Imu::get_all_devices();  // All IMU sensors that are connected\n\t * }\n \t * \\endcode\n\t */\n\n\tstatic std::vector<Imu> get_all_devices();\n\n\t/**\n\t * Get the total number of degrees the Inertial Sensor has spun about the z-axis\n\t *\n\t * This value is theoretically unbounded. Clockwise rotations are represented\n\t * with positive degree values, while counterclockwise rotations are represented\n\t * with negative ones.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return The degree value or PROS_ERR_F if the operation failed, setting\n\t * errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *    // Get the total number of degrees the sensor has spun\n\t *    printf(\"Total rotation: %f\\n\", imu.get_rotation());\n\t *    delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_rotation() const;\n\t/**\n\t * Get the Inertial Sensor's heading relative to the initial direction of its\n\t * x-axis\n\t *\n\t * This value is bounded by [0,360). Clockwise rotations are represented with\n\t * positive degree values, while counterclockwise rotations are represented with\n\t * negative ones.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return The degree value or PROS_ERR_F if the operation failed, setting\n\t * errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Get the sensor's heading\n\t *     printf(\"Heading: %f\\n\", imu.get_heading());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_heading() const;\n\t/**\n\t * Get a quaternion representing the Inertial Sensor's orientation\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return The quaternion representing the sensor's orientation. If the\n\t * operation failed, all the quaternion's members are filled with PROS_ERR_F and\n\t * errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Get the sensor's quaternion\n\t *     pros::quaternion_s_t quat = imu.get_quaternion();\n\t *     cout << \"Quaternion: \" << quat.w << \", \" << quat.x << \", \" << quat.y << \", \" << quat.z << endl;\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::quaternion_s_t get_quaternion() const;\n\t/**\n\t * Get the Euler angles representing the Inertial Sensor's orientation\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return The Euler angles representing the sensor's orientation. If the\n\t * operation failed, all the structure's members are filled with PROS_ERR_F and\n\t * errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Get the sensor's Euler angles\n\t *     pros::euler_s_t euler = imu.get_euler();\n\t *     cout << \"Euler: \" << euler.roll << \", \" << euler.pitch << \", \" << euler.yaw << endl;\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::euler_s_t get_euler() const;\n\t/**\n\t * Get the Inertial Sensor's pitch angle bounded by (-180,180)\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return The pitch angle, or PROS_ERR_F if the operation failed, setting\n\t * errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Get the sensor's pitch\n\t *     printf(\"Pitch: %f\\n\", imu.get_pitch());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_pitch() const;\n\t/**\n\t * Get the Inertial Sensor's roll angle bounded by (-180,180)\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return The roll angle, or PROS_ERR_F if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Get the sensor's roll\n\t *     printf(\"Roll: %f\\n\", imu.get_roll());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_roll() const;\n\t/**\n\t * Get the Inertial Sensor's yaw angle bounded by (-180,180)\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return The yaw angle, or PROS_ERR_F if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Get the sensor's yaw\n\t *     printf(\"Yaw: %f\\n\", imu.get_yaw());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_yaw() const;\n\t/**\n\t * Get the Inertial Sensor's raw gyroscope values\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return The raw gyroscope values. If the operation failed, all the\n\t * structure's members are filled with PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Get the sensor's raw gyroscope values\n\t *     pros::imu_gyro_s_t gyro = imu.get_gyro_rate();\n\t *     cout << \"Gyro: \" << gyro.x << \", \" << gyro.y << \", \" << gyro.z << endl;\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::imu_gyro_s_t get_gyro_rate() const;\n\t/**\n\t * Resets the current reading of the Inertial Sensor's rotation to zero\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the sensor's rotation value to 10\n\t *     imu.set_rotation(10);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *\n\t *     // Reset the sensor's rotation value to 0\n\t *     imu.tare_rotation();\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t tare_rotation() const;\n\t/**\n\t * Resets the current reading of the Inertial Sensor's heading to zero\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the sensor's heading value to 10\n\t *     imu.set_heading(10);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *\n\t *     // Reset the sensor's heading value to 0\n\t *     imu.tare_heading();\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t tare_heading() const;\n\t/**\n\t * Resets the current reading of the Inertial Sensor's pitch to zero\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the sensor's pitch value to 10\n\t *     imu.set_pitch(10);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *\n\t *     // Reset the sensor's pitch value to 0\n\t *     imu.tare_pitch();\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t tare_pitch() const;\n\t/**\n\t * Resets the current reading of the Inertial Sensor's yaw to zero\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the sensor's yaw value to 10\n\t *     imu.set_yaw(10);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *\n\t *     // Reset the sensor's yaw value to 0\n\t *     imu.tare_yaw();\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t tare_yaw() const;\n\t/**\n\t * Resets the current reading of the Inertial Sensor's roll to zero\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the sensor's roll value to 10\n\t *     imu.set_roll(10);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *\n\t *     // Reset the sensor's roll value to 0\n\t *     imu.tare_roll();\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t tare_roll() const;\n\t/**\n\t * Resets all 5 values of the Inertial Sensor to 0.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Reset all values of the sensor to 0\n\t *     imu.tare();\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t tare() const;\n\t/**\n\t * Reset all 3 euler values of the Inertial Sensor to 0.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Reset all euler values of the sensor to 0\n\t *     imu.tare_euler();\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t tare_euler() const;\n\t/**\n\t * Sets the current reading of the Inertial Sensor's heading to target value\n\t * Target will default to 360 if above 360 and default to 0 if below 0.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\param  target\n\t * \t\t\t\t Target value for the heading value to be set to\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the sensor's heading value to 10\n\t *     imu.set_heading(10);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_heading(const double target) const;\n\t/**\n\t * Sets the current reading of the Inertial Sensor's rotation to target value\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\param  target\n\t * \t\t\t\t Target value for the rotation value to be set to\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the sensor's rotation value to 10\n\t *     imu.set_rotation(10);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_rotation(const double target) const;\n\t/**\n\t * Sets the current reading of the Inertial Sensor's yaw to target value\n\t * Will default to +/- 180 if target exceeds +/- 180.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\param  target\n\t * \t\t\t\t Target value for yaw value to be set to\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the sensor's yaw value to 10\n\t *     imu.set_yaw(10);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_yaw(const double target) const;\n\t/**\n\t * Sets the current reading of the Inertial Sensor's pitch to target value\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\param  target\n\t * \t\t\t\t Target value for the pitch value to be set to\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the sensor's pitch value to 10\n\t *     imu.set_pitch(10);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_pitch(const double target) const;\n\t/**\n\t * Sets the current reading of the Inertial Sensor's roll to target value\n\t * Will default to +/- 180 if target exceeds +/- 180.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\param  target\n\t * \t\t\t\t Target euler values for the euler values to be set to\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the sensor's roll value to 100\n\t *     imu.set_roll(100);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_roll(const double target) const;\n\t/**\n\t * Sets the current reading of the Inertial Sensor's euler values to\n\t * target euler values. Will default to +/- 180 if target exceeds +/- 180.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\param  target\n\t * \t\t\t\t Target euler values for the euler values to be set to\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Set the sensor's euler values to 50\n\t *     imu.set_euler(50);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_euler(const pros::euler_s_t target) const;\n\t/**\n\t * Get the Inertial Sensor's raw accelerometer values\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return The raw accelerometer values. If the operation failed, all the\n\t * structure's members are filled with PROS_ERR_F and errno is set.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Get the sensor's raw accelerometer values\n\t *     pros::imu_accel_s_t accel = imu.get_accel();\n\t *     printf(\"x: %f, y: %f, z: %f\\n\", accel.x, accel.y, accel.z);\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::imu_accel_s_t get_accel() const;\n\t/**\n\t * Get the Inertial Sensor's status\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t * EAGAIN - The sensor is still calibrating\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\return The Inertial Sensor's status code, or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Get the sensor's status\n\t *     pros::ImuStatus status = imu.get_status();\n\t *     cout << \"Status: \" << status << endl;\n\t *     delay(20);\n\t *\n\t *     // Do something with sensor\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::ImuStatus get_status() const;\n\t/**\n\t * Check whether the IMU is calibrating\n\t *\n\t * \\return true if the V5 Inertial Sensor is calibrating or false\n\t * false if it is not.\n\t *\n\t * \\b Example\n\t * \\code\n\t *\n\t * #define IMU_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Imu imu(IMU_PORT);\n\t *\n\t *   while (true) {\n\t *     // Calibrate the sensor\n\t *     imu.reset();\n\t *     delay(20);\n\t *\n\t *     // Check if the sensor is calibrating\n\t *     if (imu.is_calibrating()) {\n\t *       printf(\"Calibrating...\\n\");\n\t *     }\n\t *\n\t *     // Do something with sensor\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual bool is_calibrating() const;\n\t/**\n\t * Returns the physical orientation of the IMU\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Inertial Sensor\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Inertial Sensor port number from 1-21\n\t * \\returns The physical orientation of the Inertial Sensor or PROS_ERR if an error occured.\n\t *\n\t */\n\tvirtual imu_orientation_e_t get_physical_orientation() const;\n\n\t/**\n\t * This is the overload for the << operator for printing to streams\n\t *\n\t * Prints in format(this below is all in one line with no new line):\n\t * Imu [port: imu._port, rotation: (rotation), heading: (heading),\n\t * pitch: (pitch angle), roll: (roll angle), yaw: (yaw angle),\n\t * gyro rate: {x,y,z}, get accel: {x,y,z}, calibrating: (calibrating boolean)]\n\t */\n\tfriend std::ostream& operator<<(std::ostream& os, const pros::Imu& imu);\n\n\t///@}\n};\n\nnamespace literals {\n/**\n * Constructs a Imu from a literal ending in _imu via calling the constructor\n *\n * \\return a pros::Imu for the corresponding port\n *\n * \\b Example\n * \\code\n * using namespace pros::literals;\n * void opcontrol() {\n *\tpros::Imu imu = 2_imu; //Makes an IMU object on port 2\n * }\n * \\endcode\n */\nconst pros::Imu operator\"\"_imu(const unsigned long long int i);\n}  // namespace literals\n\nusing IMU = Imu;\n}  // namespace v5\n}  // namespace pros\n\n#endif\n"
  },
  {
    "path": "include/pros/link.h",
    "content": "/**\n * \\file pros/link.h\n * \\ingroup c-link\n *\n * Contains prototypes for functions related to the robot to robot communications.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup c-link VEX Link C API\n */\n\n#ifndef _PROS_LINK_H_\n#define _PROS_LINK_H_\n\n#include <stdbool.h>\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\n#endif\n\n/**\n * \\ingroup c-link\n * */\n\n/**\n * \\addtogroup c-link\n *  @{\n */\n\n/**\n * \\enum link_type_e_t\n * \\brief Enum for the type of link (TX or RX)\n */\ntypedef enum link_type_e {\n\tE_LINK_RECIEVER = 0, ///< Indicates that the radio is a reciever.\n\tE_LINK_TRANSMITTER, ///< Indicates that the link is a transmitter.\n\tE_LINK_RX = E_LINK_RECIEVER, ///< Alias for E_LINK_RECIEVER\n\tE_LINK_TX = E_LINK_TRANSMITTER ///< Alias for E_LINK_TRANSMITTER\n} link_type_e_t;\n\n#ifdef PROS_USE_SIMPLE_NAMES\n#ifdef __cplusplus\n#define LINK_RECEIVER pros::E_LINK_RECEIVER\n#define LINK_TRANSMITTER pros::E_LINK_TRANSMITTER\n#define LINK_RX pros::E_LINK_RX\n#define LINK_TX pros::E_LINK_TX\n#else\n#define LINK_RECEIVER E_LINK_RECEIVER\n#define LINK_TRANSMITTER E_LINK_TRANSMITTER\n#define LINK_RX E_LINK_RX\n#define LINK_TX E_LINK_TX\n#endif\n#endif\n\n/// @brief\n/// The maximum size of a link buffer\n#define LINK_BUFFER_SIZE 512\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n/**\n * Initializes a link on a radio port, with an indicated type. There might be a\n * 1 to 2 second delay from when this function is called to when the link is initializes.\n * PROS currently only supports the use of one radio per brain.\n *\n * \\note This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a radio.\n * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n *\n * \\param port\n *      The port of the radio for the intended link.\n * \\param link_id\n *      Unique link ID in the form of a string, needs to be different from other links in\n *      the area.\n * \\param type\n *      Indicates whether the radio link on the brain is a transmitter or receiver,\n *      with the transmitter having double the transmitting bandwidth as the receiving\n *      end (1040 bytes/s vs 520 bytes/s).\n *\n * \\return PROS_ERR if initialization fails, 1 if the initialization succeeds.\n *\n * \\b Example\n * \\code\n * #define LINK_TRANSMITTER_PORT 1\n * #define LINK_ID \"ROBOT1\"\n *\n * void initialize() {\n *   link_init(LINK_TRANSMITTER_PORT, LINK_ID, E_LINK_TRANSMITTER);\n * }\n * \\endcode\n */\nuint32_t link_init(uint8_t port, const char* link_id, link_type_e_t type);\n\n/**\n * Initializes a link on a radio port, with an indicated type and the ability for\n * vexlink to override the controller radio. There might be a 1 to 2 second delay\n * from when this function is called to when the link is initializes.\n * PROS currently only supports the use of one radio per brain.\n *\n * \\note This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a radio.\n * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n *\n * \\param port\n *      The port of the radio for the intended link.\n * \\param link_id\n *      Unique link ID in the form of a string, needs to be different from other links in\n *      the area.\n * \\param type\n *      Indicates whether the radio link on the brain is a transmitter or receiver,\n *      with the transmitter having double the transmitting bandwidth as the receiving\n *      end (1040 bytes/s vs 520 bytes/s).\n *\n * \\return PROS_ERR if initialization fails, 1 if the initialization succeeds.\n *\n * \\b Example\n * \\code\n * #define LINK_PORT 1\n * #define LINK_ID \"ROBOT1\"\n *\n * void initialize() {\n *   link_init(LINK_PORT, LINK_ID, E_LINK_TRANSMITTER);\n *   link_init_override(LINK_PORT, LINK_ID, E_LINK_TRANSMITTER);\n * }\n * \\endcode\n */\nuint32_t link_init_override(uint8_t port, const char* link_id, link_type_e_t type);\n\n/**\n * Checks if a radio link on a port is active or not.\n *\n * \\note This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a radio.\n * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n *\n * \\param port\n *      The port of the radio for the intended link.\n *\n * \\return If a radio is connected to a port and it's connected to a link.\n *\n * \\b Example\n * \\code\n * #define LINK_TRANSMITTER_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     if (link_connected(LINK_TRANSMITTER_PORT)) {\n *       screen_print(TEXT_MEDIUM, 1, \"Link connected!\");\n *     }\n *   delay(20);\n *   }\n * }\n * \\endcode\n */\nbool link_connected(uint8_t port);\n\n/**\n * Returns the bytes of data available to be read\n *\n * \\note This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a radio.\n * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n *\n * \\param port\n *      The port of the radio for the intended link.\n *\n * \\return PROS_ERR if port is not a link/radio, else the bytes available to be\n * read by the user.\n *\n * \\b Example\n * \\code\n * #define LINK_RECIVER_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     uint32_t receiveable_size = link_raw_receivable_size(LINK_RECIVER_PORT);\n *     screen_print(TEXT_MEDIUM, 1, \"link_raw_receiveable_size: %d\", receiveable_size);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nuint32_t link_raw_receivable_size(uint8_t port);\n\n/**\n * Returns the bytes of data available in transmission buffer.\n *\n * \\note This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a radio.\n * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n *\n * \\param port\n *      The port of the radio for the intended link.\n *\n * \\return PROS_ERR if port is not a link/radio,\n *\n * \\b Example\n * \\code\n * #define LINK_TRANSMITTER_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     uint32_t transmittable_size = link_raw_transmittable_size(LINK_TRANSMITTER_PORT);\n *     screen_print(TEXT_MEDIUM, 1, \"link_raw_transmittable_size: %d\", transmittable_size);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nuint32_t link_raw_transmittable_size(uint8_t port);\n\n/**\n * Send raw serial data through vexlink.\n *\n * \\note This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a radio.\n * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no\n * room in the FIFO buffer (queue) to transmit the data.\n * EINVAL - The data given is NULL\n *\n * \\param port\n *      The port of the radio for the intended link.\n * \\param data\n *      Buffer with data to send\n * \\param data_size\n *      Bytes of data to be read to the destination buffer\n *\n * \\return PROS_ERR if port is not a link, and the successfully transmitted\n * data size if it succeeded.\n *\n * \\b Example\n * \\code\n * #define LINK_TRANSMITTER_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     char* data = \"Hello!\";\n *     link_transmit_raw(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nuint32_t link_transmit_raw(uint8_t port, void* data, uint16_t data_size);\n\n/**\n * Receive raw serial data through vexlink.\n *\n * \\note This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a radio.\n * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer\n * or destination buffer.\n *\n * \\param port\n *      The port of the radio for the intended link.\n * \\param dest\n *      Destination buffer to read data to\n * \\param data_size\n *      Bytes of data to be read to the destination buffer\n *\n * \\return PROS_ERR if port is not a link, and the successfully received\n * data size if it succeeded.\n *\n * \\b Example\n * \\code\n * #define LINK_RECIVER_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     char* result;\n *     char* expected = \"Hello!\";\n *     link_receive_raw(LINK_RECIVER_PORT, (void*)result, sizeof(*expected) * sizeof(expected));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nuint32_t link_receive_raw(uint8_t port, void* dest, uint16_t data_size);\n\n/**\n * Send packeted message through vexlink, with a checksum and start byte.\n *\n * \\note This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a radio.\n * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no\n * room in the FIFO buffer (queue) to transmit the data.\n * EINVAL - The data given is NULL\n *\n * \\param port\n *      The port of the radio for the intended link.\n * \\param data\n *      Buffer with data to send\n * \\param data_size\n *      Bytes of data to be read to the destination buffer\n *\n * \\return PROS_ERR if port is not a link, and the successfully transmitted\n * data size if it succeeded.\n *\n * \\b Example\n * \\code\n * #define LINK_TRANSMITTER_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     char* data = \"Hello!\";\n *     link_transmit(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nuint32_t link_transmit(uint8_t port, void* data, uint16_t data_size);\n\n/**\n * Receive packeted message through vexlink, with a checksum and start byte.\n *\n * \\note This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a radio.\n * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer\n * or destination buffer.\n * EBADMSG - Protocol error related to start byte, data size, or checksum.\n *\n * \\param port\n *      The port of the radio for the intended link.\n * \\param dest\n *      Destination buffer to read data to\n * \\param data_size\n *      Bytes of data to be read to the destination buffer\n *\n * \\return PROS_ERR if port is not a link or protocol error, and the successfully\n * transmitted data size if it succeeded.\n *\n * \\b Example\n * \\code\n * #define LINK_RECIVER_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     char* result;\n *     char* expected = \"Hello!\";\n *     link_receive(LINK_RECIVER_PORT, (void*)result, sizeof(*expected) * sizeof(expected));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nuint32_t link_receive(uint8_t port, void* dest, uint16_t data_size);\n\n/**\n * Clear the receive buffer of the link, and discarding the data.\n *\n * \\note This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a radio.\n * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n *\n * \\param port\n *      The port of the radio for the intended link.\n *\n * \\return PROS_ERR if port is not a link, and the successfully received\n * data size if it succeeded.\n *\n * \\b Example\n * \\code\n * #define LINK_TRANSMITTER_PORT 1\n *\n * void opcontrol() {\n *   while (true) {\n *     char* data = \"Hello!\";\n *     link_transmit(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data));\n *     link_clear_receive_buf(LINK_TRANSMITTER_PORT);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nuint32_t link_clear_receive_buf(uint8_t port);\n\n///@}\n\n#ifdef __cplusplus\n}\n}\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "include/pros/link.hpp",
    "content": "/**\n * \\file pros/link.hpp\n * \\ingroup cpp-link\n *\n * Contains prototypes for functions related to robot to robot communications.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup cpp-link VEX Link C++ API\n */\n#ifndef _PROS_LINK_HPP_\n#define _PROS_LINK_HPP_\n\n#include <cstdint>\n#include <string>\n\n#include \"pros/link.h\"\n#include \"pros/device.hpp\"\n\nnamespace pros {\n/**\n * \\ingroup cpp-link\n */\nclass Link : public Device {\n\t/**\n\t * \\addtogroup cpp-link\n\t * ///@{\n\t */\n\tprivate:\n\n\tpublic:\n\t/**\n\t * Initializes a link on a radio port, with an indicated type. There might be a\n\t * 1 to 2 second delay from when this function is called to when the link is initializes.\n\t *\n\t * \\note This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a radio.\n\t * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n\t *\n\t * \\param port\n\t *      The port of the radio for the intended link.\n\t * \\param link_id\n\t *      Unique link ID in the form of a string, needs to be different from other links in\n\t *      the area.\n\t * \\param type\n\t *      Indicates whether the radio link on the brain is a transmitter or receiver,\n\t *      with the transmitter having double the transmitting bandwidth as the receiving\n\t *      end (1040 bytes/s vs 520 bytes/s).\n\t * \\param ov\n\t * \t\tIndicates if the radio on the given port needs vexlink to override the controller radio. Defualts to True.\n\t *\n\t * \\return PROS_ERR if initialization fails, 1 if the initialization succeeds.\n\t * \n\t * \\b Example:\n\t * \\code\n\t * pros::Link link(1, \"my_link\", pros::E_LINK_TX);\n\t * \\endcode\n\t */\n\texplicit Link(const std::uint8_t port, const std::string link_id, link_type_e_t type, bool ov = true);\n\n\t/**\n\t * Checks if a radio link on a port is active or not.\n\t *\n\t * \\note This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a radio.\n\t * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n\t *\n\t * \\return If a radio is connected to a port and it's connected to a link.\n\t * \n\t * \\b Example:\n\t * \\code\n\t * pros::Link link(1, \"my_link\", pros::E_LINK_TX);\n\t * if (link.connected()) {\n\t * \t// do something\n\t * }\n\t * \\endcode\n\t */\n\tbool connected();\n\n\t/**\n\t * Returns the bytes of data number of without protocol available to be read\n\t *\n\t * \\note This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a radio.\n\t * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n\t *\n\t * \\return PROS_ERR if port is not a link/radio, else the bytes available to be\n\t * read by the user.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Link link(1, \"my_link\", pros::E_LINK_TX);\n\t * \tprintf(\"Bytes available to read: %d\", link.receivable_size());\n\t * }\n\t * \\endcode\n\t */\n\tstd::uint32_t raw_receivable_size();\n\n\t/**\n\t * Returns the bytes of data available in transmission buffer.\n\t *\n\t * \\note This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a radio.\n\t * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n\t *\n\t * \\return PROS_ERR if port is not a link/radio,\n\t * else the bytes available to be transmitted by the user.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Link link(1, \"my_link\", pros::E_LINK_TX);\n\t * \tprintf(\"Bytes available to transmit: %d\", link.transmittable_size());\n\t * }\n\t */\n\tstd::uint32_t raw_transmittable_size();\n\n\t/**\n\t * Send raw serial data through vexlink.\n\t *\n\t * \\note This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a radio.\n\t * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n\t * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no\n\t * room in the FIFO buffer (queue) to transmit the data.\n\t * EINVAL - The data given is NULL\n\t *\n\t * \\param data\n\t *      Buffer with data to send\n\t * \\param data_size\n\t *      Buffer with data to send\n\t *\n\t * \\return PROS_ERR if port is not a link, and the successfully transmitted \n\t * data size if it succeeded.\n\t * \n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Link link(1, \"my_link\", pros::E_LINK_TX);\n\t * \tstd::uint8_t data[4] = {0x01, 0x02, 0x03, 0x04};\n\t *  link.transmit_raw(data, 4);\n\t * }\n\t * \n\t * \\endcode\n\t */\n\tstd::uint32_t transmit_raw(void* data, std::uint16_t data_size);\n\n\t/**\n\t * Receive raw serial data through vexlink.\n\t *\n\t * \\note This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a radio.\n\t * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n\t * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer\n\t * or destination buffer.\n\t *\n\t * \\param dest\n\t *      Destination buffer to read data to\n\t * \\param data_size\n\t *      Bytes of data to be read to the destination buffer\n\t *\n\t * \\return PROS_ERR if port is not a link, and the successfully received \n\t * data size if it succeeded.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Link link(1, \"my_link\", pros::E_LINK_TX);\n\t * \tstd::uint8_t data[4];\n\t *  link.receive_raw(data, 4);\n\t * }\n\t * \\endcode\n\t */\n\tstd::uint32_t receive_raw(void* dest, std::uint16_t data_size);\n\n\t/**\n\t * Send packeted message through vexlink, with a checksum and start byte.\n\t *\n\t * \\note This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a radio.\n\t * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n\t * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no\n\t * room in the FIFO buffer (queue) to transmit the data.\n\t * EINVAL - The data given is NULL\n\t *\n\t * \\param data\n\t *      Buffer with data to send\n\t * \\param data_size\n\t *      Bytes of data to be read to the destination buffer\n\t *\n\t * \\return PROS_ERR if port is not a link, and the successfully transmitted \n\t * data size if it succeeded.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Link link(1, \"my_link\", pros::E_LINK_TX);\n\t * \tstd::uint8_t data[4] = {0x01, 0x02, 0x03, 0x04};\n\t *  link.transmit(data, 4);\n\t * }\n\t * \\endcode\n\t */\n\tstd::uint32_t transmit(void* data, std::uint16_t data_size);\n\n\t/**\n\t * Receive packeted message through vexlink, with a checksum and start byte.\n\t *\n\t * \\note This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a radio.\n\t * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n\t * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer\n\t * or destination buffer.\n\t * EBADMSG - Protocol error related to start byte, data size, or checksum.\n\n\t * \\param dest\n\t *      Destination buffer to read data to\n\t * \\param data_size\n\t *      Bytes of data to be read to the destination buffer\n\t *\n\t * \\return PROS_ERR if port is not a link, and the successfully received \n\t * data size if it succeeded.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Link link(1, \"my_link\", pros::E_LINK_TX);\n\t * \tstd::uint8_t data[4];\n\t *  link.receive(data, 4);\n\t * }\n\t * \\endcode\n\t */\n\tstd::uint32_t receive(void* dest, std::uint16_t data_size);\n\n\t/**\n\t * Clear the receive buffer of the link, and discarding the data.\n\t *\n\t * \\note This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a radio.\n\t * ENXIO - The sensor is still calibrating, or no link is connected via the radio.\n\t *\n\t * \\return PROS_ERR if port is not a link, 1 if the operation succeeded.\n\t * \n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Link link(1, \"my_link\", pros::E_LINK_TX);\n\t *  link.clear_receive_buf();\n\t * }\n\t * \\endcode\n\t */\n\tstd::uint32_t clear_receive_buf();\n  \n\t///@}\n};\n}  // namespace pros\n\n#endif\n"
  },
  {
    "path": "include/pros/llemu.h",
    "content": "#ifndef _PROS_LLEMU_H_\n#define _PROS_LLEMU_H_\n\n// TODO:? Should there be weak symbols for the C api in here as well?\n\n#include \"stdbool.h\"\n#include \"stdint.h\"\n\n/******************************************************************************/\n/**                        LLEMU Conditional Include                         **/\n/**                                                                          **/\n/**   When the libvgl versions of llemu.h is present, common.mk will         **/\n/**   define a macro which lets this file know that liblvgl's llemu.h   is   **/\n/**   present. If it is, we conditionally include it so that it gets         **/\n/**   included into api.h.                                                   **/\n/******************************************************************************/\n#ifdef _PROS_INCLUDE_LIBLVGL_LLEMU_H\n#include \"liblvgl/llemu.h\"\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\nnamespace c {\n#endif//__cplusplus\n\n/**\n * Displays a formatted string on the emulated three-button LCD screen.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO  - The LCD has not been initialized. Call lcd_initialize() first.\n * EINVAL - The line number specified is not in the range [0-7]\n *\n * \\param line\n *        The line on which to display the text [0-7]\n * \\param fmt\n *        Format string\n * \\param ...\n *        Optional list of arguments for the format string\n *\n * \\return True if the operation was successful, or false otherwise, setting\n * errno values as specified above.\n */\nbool __attribute__((weak)) lcd_print(__attribute__((unused)) int16_t line, __attribute__((unused)) const char* fmt, ...)  {\n    return false;\n}\n\n#ifdef __cplusplus\n} // namespace c\n} // namespace pros\n} // extern \"C\"\n#endif//__cplusplus\n\n#endif // _PROS_LLEMU_H_\n"
  },
  {
    "path": "include/pros/llemu.hpp",
    "content": "/**\n * \\file pros/llemu.hpp\n * \\ingroup cpp-llemu\n * \n * Legacy LCD Emulator\n *\n * \\details This file defines a high-level API for emulating the three-button, UART-based\n * VEX LCD, containing a set of functions that facilitate the use of a software-\n * emulated version of the classic VEX LCD module.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#ifndef _PROS_LLEMU_HPP_\n#define _PROS_LLEMU_HPP_\n\n#include <cstdint>\n#include <string>\n\n/******************************************************************************/\n/**                        LLEMU Conditional Include                         **/\n/**                                                                          **/\n/**   When the libvgl versions of llemu.hpp is present, common.mk will       **/\n/**   define a macro which lets this file know that liblvgl's llemu.hpp is   **/\n/**   present. If it is, we conditionally include it so that it gets         **/\n/**   included into api.h.                                                   **/\n/******************************************************************************/\n#ifdef _PROS_INCLUDE_LIBLVGL_LLEMU_HPP\n#include \"liblvgl/llemu.hpp\"\n#endif\n\n/******************************************************************************/\n/**                                 LLEMU Weak Stubs                         **/\n/**                                                                          **/\n/**   These functions allow main.cpp to be compiled without LVGL present     **/\n/******************************************************************************/\n\nnamespace pros {\n    \n/**\n * \\ingroup cpp-llemu \n */\n#if defined(_PROS_KERNEL_SUPPRESS_LLEMU_WARNING) || defined(_PROS_INCLUDE_LIBLVGL_LLEMU_HPP)\nnamespace lcd {\n#else\nnamespace [[deprecated(\"Without liblvgl, LLEMU functions will not display anything. To install liblvgl run \\\"pros c install liblvgl\\\" in the PROS terminal.\")]] lcd {\n#endif\n    #pragma GCC diagnostic push\n    #pragma GCC diagnostic ignored \"-Wunused-function\"\n    namespace {\n    template <typename T>\n    T convert_args(T arg) {\n        return arg;\n    }\n    const char* convert_args(const std::string& arg) {\n        return arg.c_str();\n    }\n    }  // namespace\n    #pragma GCC diagnostic pop\n\n    using lcd_btn_cb_fn_t = void (*)(void);\n\n    /* \n     * These weak symbols allow the example main.cpp in to compile even when \n     * the liblvgl template is missing from the project. \n     * \n     * For documentation on these functions, please see the doxygen comments for\n     * these functions in the libvgl llemu headers.\n     */\n    extern __attribute__((weak)) bool is_initialized(void);\n    extern __attribute__((weak)) bool initialize(void);\n    extern __attribute__((weak)) bool shutdown(void);\n    extern __attribute__((weak)) bool set_text(std::int16_t line, std::string text);\n    extern __attribute__((weak)) bool clear(void);\n    extern __attribute__((weak)) bool clear_line(std::int16_t line);\n    // TODO: Text_Align is defined in liblvgl so this ain't going to compile for now. \n    // extern __attribute__((weak)) void set_text_align(Text_Align text_align);\n    extern __attribute__((weak)) void register_btn0_cb(lcd_btn_cb_fn_t cb);\n    extern __attribute__((weak)) void register_btn1_cb(lcd_btn_cb_fn_t cb);\n    extern __attribute__((weak)) void register_btn2_cb(lcd_btn_cb_fn_t cb);\n    extern __attribute__((weak)) std::uint8_t read_buttons(void);\n    \n    /**\n     * \\addtogroup cpp-llemu\n     * @{ \n     */\n    \n    /*\n     * Note: This template resides in this file since the \n     */\n\n    /**\n     * Displays a formatted string on the emulated three-button LCD screen.\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * ENXIO  - The LCD has not been initialized. Call lcd_initialize() first.\n     * EINVAL - The line number specified is not in the range [0-7]\n     *\n     * \\param line\n     *        The line on which to display the text [0-7]\n     * \\param fmt\n     *        Format string\n     * \\param ...args\n     *        Optional list of arguments for the format string\n     *\n     * \\return True if the operation was successful, or false otherwise, setting\n     * errno values as specified above.\n     * \n     * \\b Example\n     * \\code\n     * #include \"pros/llemu.hpp\"\n     * \n     * void initialize() {\n     *   pros::lcd::initialize();\n     *   pros::lcd::print(0, \"My formatted text: %d!\", 2);\n     * }\n     * \\endcode\n     */\n    template <typename... Params>\n    bool print(std::int16_t line, const char* fmt, Params... args) {\n\t    return pros::c::lcd_print(line, fmt, convert_args(args)...);\n    }\n\n    #ifndef LCD_BTN_LEFT\n        #define LCD_BTN_LEFT 4\n    #endif\n\n    #ifndef LCD_BTN_CENTER\n        #define LCD_BTN_CENTER 2\n    #endif\n\n    #ifndef LCD_BTN_RIGHT\n        #define LCD_BTN_RIGHT 1\n    #endif\n    /// @}\n} // namespace lcd\n} // namespace pros\n\n#endif // _PROS_LLEMU_HPP_\n"
  },
  {
    "path": "include/pros/misc.h",
    "content": "/**\n * \\file pros/misc.h\n * \\ingroup c-misc\n *\n * Contains prototypes for miscellaneous functions pertaining to the controller,\n * battery, and competition control.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reservered.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup c-misc Miscellaneous C API\n * \\note Additional example code for this module can be found in its [Tutorial.](@ref controller)\n */\n\n#ifndef _PROS_MISC_H_\n#define _PROS_MISC_H_\n\n#include <stdint.h>\n\n#define NUM_V5_PORTS (22)\n\n/**\n * \\ingroup c-misc\n */\n\n/**\n * \\addtogroup c-misc\n *  @{\n */\n\n/// \\name V5 Competition\n//@{\n\n/*#define COMPETITION_DISABLED (1 << 0)\n#define COMPETITION_AUTONOMOUS (1 << 1)\n#define COMPETITION_CONNECTED (1 << 2)\n#define COMPETITION_SYSTEM (1 << 3)*/\ntypedef enum {\n\tCOMPETITION_DISABLED = 1 << 0,\n\tCOMPETITION_CONNECTED = 1 << 2,\n\tCOMPETITION_AUTONOMOUS = 1 << 1,\n\tCOMPETITION_SYSTEM = 1 << 3,\n} competition_status;\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\nnamespace c {\n#endif\n\n/**\n * \\fn competition_get_status(void)\n * Get the current status of the competition control.\n *\n * \\return The competition control status as a mask of bits with\n * COMPETITION_{ENABLED,AUTONOMOUS,CONNECTED}.\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   if (competition_get_status() & COMPETITION_CONNECTED == true) {\n *     // Field Control is Connected\n *     // Run LCD Selector code or similar\n *   }\n * }\n * \\endcode\n */\nuint8_t competition_get_status(void);\n\n/**\n * \\fn competition_is_disabled()\n *\n * \\return True if the V5 Brain is disabled, false otherwise.\n *\n * \\b Example\n * \\code\n * void my_task_fn(void* ignore) {\n *   while (!competition_is_disabled()) {\n *   // Run competition tasks (like Lift Control or similar)\n *   }\n * }\n *\n * void initialize() {\n *   task_t my_task = task_create(my_task_fn, NULL, TASK_PRIO_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n * }\n * \\endcode\n */\nuint8_t competition_is_disabled(void);\n\n/**\n * \\return True if the V5 Brain is connected to competition control, false otherwise.\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   if (competition_is_connected()) {\n *     // Field Control is Connected\n *     // Run LCD Selector code or similar\n *   }\n * }\n * \\endcode\n */\nuint8_t competition_is_connected(void);\n\n/**\n * \\return True if the V5 Brain is in autonomous mode, false otherwise.\n *\n * \\b Example\n * \\code\n * void my_task_fn(void* ignore) {\n *   while (!competition_is_autonomous()) {\n *     // Wait to do anything until autonomous starts\n *     delay(2);\n *   }\n *   while (competition_is_autonomous()) {\n *     // Run whatever code is desired to just execute in autonomous\n *     }\n * }\n *\n * void initialize() {\n *   task_t my_task = task_create(my_task_fn, NULL, TASK_PRIO_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n * }\n * \\endcode\n */\nuint8_t competition_is_autonomous(void);\n\n/**\n * \\return True if the V5 Brain is connected to VEXnet Field Controller, false otherwise.\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   if (competition_is_field()) {\n *     // connected to VEXnet Field Controller\n *   }\n * }\n * \\endcode\n */\nuint8_t competition_is_field(void);\n\n/**\n * \\return True if the V5 Brain is connected to VEXnet Competition Switch, false otherwise.\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   if (competition_is_switch()) {\n *     // connected to VEXnet Competition Switch\n *   }\n * }\n */\nuint8_t competition_is_switch(void);\n\n#ifdef __cplusplus\n}\n}\n}\n#endif\n///@}\n\n/// \\name V5 Controller\n///@{\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\n#endif\n\n/**\n * \\enum\n */\ntypedef enum {\n\t/// The master controller.\n\tE_CONTROLLER_MASTER = 0,\n\t/// The partner controller.\n\tE_CONTROLLER_PARTNER\n} controller_id_e_t;\n\n/**\n * \\enum\n */\ntypedef enum {\n\t/// The horizontal axis of the controller’s left analog stick.\n\tE_CONTROLLER_ANALOG_LEFT_X = 0,\n\t/// The vertical axis of the controller’s left analog stick.\n\tE_CONTROLLER_ANALOG_LEFT_Y,\n\t/// The horizontal axis of the controller’s right analog stick.\n\tE_CONTROLLER_ANALOG_RIGHT_X,\n\t/// The vertical axis of the controller’s right analog stick.\n\tE_CONTROLLER_ANALOG_RIGHT_Y\n} controller_analog_e_t;\n\n/**\n * \\enum\n */\ntypedef enum {\n\t/// The first trigger on the left side of the controller.\n\tE_CONTROLLER_DIGITAL_L1 = 6,\n\t/// The second trigger on the left side of the controller.\n\tE_CONTROLLER_DIGITAL_L2,\n\t/// The first trigger on the right side of the controller.\n\tE_CONTROLLER_DIGITAL_R1,\n\t/// The second trigger on the right side of the controller.\n\tE_CONTROLLER_DIGITAL_R2,\n\t/// The up arrow on the left arrow pad of the controller.\n\tE_CONTROLLER_DIGITAL_UP,\n\t/// The down arrow on the left arrow pad of the controller.\n\tE_CONTROLLER_DIGITAL_DOWN,\n\t/// The left arrow on the left arrow pad of the controller.\n\tE_CONTROLLER_DIGITAL_LEFT,\n\t/// The right arrow on the left arrow pad of the controller.\n\tE_CONTROLLER_DIGITAL_RIGHT,\n\t/// The ‘X’ button on the right button pad of the controller.\n\tE_CONTROLLER_DIGITAL_X,\n\t/// The ‘B’ button on the right button pad of the controller.\n\tE_CONTROLLER_DIGITAL_B,\n\t/// The ‘Y’ button on the right button pad of the controller.\n\tE_CONTROLLER_DIGITAL_Y,\n\t/// The ‘A’ button on the right button pad of the controller.\n\tE_CONTROLLER_DIGITAL_A,\n\t/// The power button on the front of the controller.\n\tE_CONTROLLER_DIGITAL_POWER\n} controller_digital_e_t;\n\n#ifdef PROS_USE_SIMPLE_NAMES\n#ifdef __cplusplus\n#define CONTROLLER_MASTER pros::E_CONTROLLER_MASTER\n#define CONTROLLER_PARTNER pros::E_CONTROLLER_PARTNER\n#define ANALOG_LEFT_X pros::E_CONTROLLER_ANALOG_LEFT_X\n#define ANALOG_LEFT_Y pros::E_CONTROLLER_ANALOG_LEFT_Y\n#define ANALOG_RIGHT_X pros::E_CONTROLLER_ANALOG_RIGHT_X\n#define ANALOG_RIGHT_Y pros::E_CONTROLLER_ANALOG_RIGHT_Y\n#define DIGITAL_L1 pros::E_CONTROLLER_DIGITAL_L1\n#define DIGITAL_L2 pros::E_CONTROLLER_DIGITAL_L2\n#define DIGITAL_R1 pros::E_CONTROLLER_DIGITAL_R1\n#define DIGITAL_R2 pros::E_CONTROLLER_DIGITAL_R2\n#define DIGITAL_UP pros::E_CONTROLLER_DIGITAL_UP\n#define DIGITAL_DOWN pros::E_CONTROLLER_DIGITAL_DOWN\n#define DIGITAL_LEFT pros::E_CONTROLLER_DIGITAL_LEFT\n#define DIGITAL_RIGHT pros::E_CONTROLLER_DIGITAL_RIGHT\n#define DIGITAL_X pros::E_CONTROLLER_DIGITAL_X\n#define DIGITAL_B pros::E_CONTROLLER_DIGITAL_B\n#define DIGITAL_Y pros::E_CONTROLLER_DIGITAL_Y\n#define DIGITAL_A pros::E_CONTROLLER_DIGITAL_A\n#define DIGITAL_POWER pros::E_CONTROLLER_DIGITAL_POWER\n#else\n#define CONTROLLER_MASTER E_CONTROLLER_MASTER\n#define CONTROLLER_PARTNER E_CONTROLLER_PARTNER\n#define ANALOG_LEFT_X E_CONTROLLER_ANALOG_LEFT_X\n#define ANALOG_LEFT_Y E_CONTROLLER_ANALOG_LEFT_Y\n#define ANALOG_RIGHT_X E_CONTROLLER_ANALOG_RIGHT_X\n#define ANALOG_RIGHT_Y E_CONTROLLER_ANALOG_RIGHT_Y\n#define DIGITAL_L1 E_CONTROLLER_DIGITAL_L1\n#define DIGITAL_L2 E_CONTROLLER_DIGITAL_L2\n#define DIGITAL_R1 E_CONTROLLER_DIGITAL_R1\n#define DIGITAL_R2 E_CONTROLLER_DIGITAL_R2\n#define DIGITAL_UP E_CONTROLLER_DIGITAL_UP\n#define DIGITAL_DOWN E_CONTROLLER_DIGITAL_DOWN\n#define DIGITAL_LEFT E_CONTROLLER_DIGITAL_LEFT\n#define DIGITAL_RIGHT E_CONTROLLER_DIGITAL_RIGHT\n#define DIGITAL_X E_CONTROLLER_DIGITAL_X\n#define DIGITAL_B E_CONTROLLER_DIGITAL_B\n#define DIGITAL_Y E_CONTROLLER_DIGITAL_Y\n#define DIGITAL_A E_CONTROLLER_DIGITAL_A\n#endif\n#endif\n\n/**\n * \\def Given an id and a port, this macro sets the port variable based on the id and allows the mutex to take that\n * port.\n *\n * \\returns error (in the function/scope it's in) if the controller failed to connect or an invalid id is given.\n */\n#define CONTROLLER_PORT_MUTEX_TAKE(id, port) \\\n\tswitch (id) {                              \\\n\t\tcase E_CONTROLLER_MASTER:                \\\n\t\t\tport = V5_PORT_CONTROLLER_1;           \\\n\t\t\tbreak;                                 \\\n\t\tcase E_CONTROLLER_PARTNER:               \\\n\t\t\tport = V5_PORT_CONTROLLER_2;           \\\n\t\t\tbreak;                                 \\\n\t\tdefault:                                 \\\n\t\t\terrno = EINVAL;                        \\\n\t\t\treturn PROS_ERR;                       \\\n\t}                                          \\\n\tif (!internal_port_mutex_take(port)) {     \\\n\t\terrno = EACCES;                          \\\n\t\treturn PROS_ERR;                         \\\n\t}\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n/**\n * Checks if the controller is connected.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is\n * given.\n * EACCES - Another resource is currently trying to access the controller port.\n *\n * \\param id\n *        The ID of the controller (e.g. the master or partner controller).\n *        Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER\n *\n * \\return 1 if the controller is connected, 0 otherwise\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   if (competition_is_connected()) {\n *     // Field Control is Connected\n *     // Run LCD Selector code or similar\n *   }\n * }\n * \\endcode\n */\nint32_t controller_is_connected(controller_id_e_t id);\n\n/**\n * Gets the value of an analog channel (joystick) on a controller.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is\n * given.\n * EACCES - Another resource is currently trying to access the controller port.\n *\n * \\param id\n *        The ID of the controller (e.g. the master or partner controller).\n *        Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER\n * \\param channel\n *        The analog channel to get.\n *        Must be one of ANALOG_LEFT_X, ANALOG_LEFT_Y, ANALOG_RIGHT_X,\n *        ANALOG_RIGHT_Y\n *\n * \\return The current reading of the analog channel: [-127, 127].\n * If the controller was not connected, then 0 is returned\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t controller_get_analog(controller_id_e_t id, controller_analog_e_t channel);\n\n/**\n * Gets the battery capacity of the given controller.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is\n * given.\n * EACCES - Another resource is currently trying to access the controller port.\n *\n * \\param id\n *        The ID of the controller (e.g. the master or partner controller).\n *        Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER\n *\n * \\return The controller's battery capacity\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Battery Capacity: %d\\n\", controller_get_battery_capacity(E_CONTROLLER_MASTER));\n * }\n * \\endcode\n */\nint32_t controller_get_battery_capacity(controller_id_e_t id);\n\n/**\n * Gets the battery level of the given controller.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is\n * given.\n * EACCES - Another resource is currently trying to access the controller port.\n *\n * \\param id\n *        The ID of the controller (e.g. the master or partner controller).\n *        Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER\n *\n * \\return The controller's battery level\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Battery Level: %d\\n\", controller_get_battery_level(E_CONTROLLER_MASTER));\n * }\n * \\endcode\n */\nint32_t controller_get_battery_level(controller_id_e_t id);\n\n/**\n * Checks if a digital channel (button) on the controller is currently pressed.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is\n * given.\n * EACCES - Another resource is currently trying to access the controller port.\n *\n * \\param id\n *        The ID of the controller (e.g. the master or partner controller).\n *        Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER\n * \\param button\n *        The button to read.\n *        Must be one of DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}\n *\n * \\return 1 if the button on the controller is pressed.\n * If the controller was not connected, then 0 is returned\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *   if (controller_get_digital(E_CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_A)) {\n *     motor_set(1, 100);\n *   }\n *   else {\n *     motor_set(1, 0);\n *   }\n *     delay(2);\n *   }\n * }\n\n * \\endcode\n */\nint32_t controller_get_digital(controller_id_e_t id, controller_digital_e_t button);\n\n/**\n * Returns a rising-edge case for a controller button press.\n *\n * This function is not thread-safe.\n * Multiple tasks polling a single button may return different results under the\n * same circumstances, so only one task should call this function for any given\n * button. E.g., Task A calls this function for buttons 1 and 2. Task B may call\n * this function for button 3, but should not for buttons 1 or 2. A typical\n * use-case for this function is to call inside opcontrol to detect new button\n * presses, and not in any other tasks.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is\n * given.\n * EACCES - Another resource is currently trying to access the controller port.\n *\n * \\param id\n *        The ID of the controller (e.g. the master or partner controller).\n *        Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER\n * \\param button\n * \t\t\t  The button to read. Must be one of\n *        DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}\n *\n * \\return 1 if the button on the controller is pressed and had not been pressed\n * the last time this function was called, 0 otherwise.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n * while (true) {\n *   if (controller_get_digital_new_press(E_CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_A)) {\n *     // Toggle pneumatics or other similar actions\n *   }\n *\n *   delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t controller_get_digital_new_press(controller_id_e_t id, controller_digital_e_t button);\n\n/**\n * Returns a falling-edge case for a controller button press.\n *\n * This function is not thread-safe.\n * Multiple tasks polling a single button may return different results under\n * the same circumstances, so only one task should call this function for any\n * given button. E.g., Task A calls this function for buttons 1 and 2.\n * Task B may call this function for button 3, but should not for buttons\n * 1 or 2. A typical use-case for this function is to call inside opcontrol\n * to detect new button releases, and not in any other tasks.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCES - Another resource is currently trying to access the controller\n * port.\n *\n * \\param button\n * \t\t\t  The button to read. Must be one of\n *        DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}\n *\n * \\return 1 if the button on the controller is not pressed and had been\n * pressed the last time this function was called, 0 otherwise.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n * \tpros::Controller master(pros::E_CONTROLLER_MASTER);\n * \twhile (true) {\n *   if (master.get_digital_new_release(pros::E_CONTROLLER_DIGITAL_A)) {\n *     // Toggle pneumatics or other similar actions\n *   }\n *\n *   delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t controller_get_digital_new_release(controller_id_e_t id, controller_digital_e_t button);\n\n/**\n * Sets text to the controller LCD screen.\n *\n * \\note Controller text setting is a slow process, so updates faster than 10ms\n * when on a wired connection or 50ms over Vexnet will not be applied to the controller.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is\n * given.\n * EACCES - Another resource is currently trying to access the controller port.\n * EAGAIN - Could not send the text to the controller.\n *\n * \\param id\n *        The ID of the controller (e.g. the master or partner controller).\n *        Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER\n * \\param line\n *        The line number at which the text will be displayed [0-2]\n * \\param col\n *        The column number at which the text will be displayed [0-14]\n * \\param fmt\n *        The format string to print to the controller\n * \\param ...\n *        The argument list for the format string\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   int count = 0;\n *   while (true) {\n *   if (!(count % 25)) {\n *     // Only print every 50ms, the controller text update rate is slow\n *     controller_print(E_CONTROLLER_MASTER, 0, 0, \"Counter: %d\", count);\n *   }\n *     count++;\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t controller_print(controller_id_e_t id, uint8_t line, uint8_t col, const char* fmt, ...);\n\n/**\n * Sets text to the controller LCD screen.\n *\n * \\note Controller text setting is a slow process, so updates faster than 10ms\n * when on a wired connection or 50ms over Vexnet will not be applied to the controller.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is\n * given.\n * EACCES - Another resource is currently trying to access the controller port.\n * EAGAIN - Could not send the text to the controller.\n *\n * \\param id\n *        The ID of the controller (e.g. the master or partner controller).\n *        Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER\n * \\param line\n *        The line number at which the text will be displayed [0-2]\n * \\param col\n *        The column number at which the text will be displayed [0-14]\n * \\param str\n *        The pre-formatted string to print to the controller\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   int count = 0;\n *   while (true) {\n *     if (!(count % 25)) {\n *       // Only print every 50ms, the controller text update rate is slow\n *       controller_set_text(E_CONTROLLER_MASTER, 0, 0, \"Example text\");\n *     }\n *   count++;\n *   delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t controller_set_text(controller_id_e_t id, uint8_t line, uint8_t col, const char* str);\n\n/**\n * Clears an individual line of the controller screen.\n *\n * \\note Controller text setting is currently in beta, so continuous, fast\n * updates will not work well.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is\n * given.\n * EACCES - Another resource is currently trying to access the controller port.\n *\n * \\param id\n *        The ID of the controller (e.g. the master or partner controller).\n *        Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER\n * \\param line\n *        The line number to clear [0-2]\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   controller_set_text(E_CONTROLLER_MASTER, 0, 0, \"Example\");\n *   delay(100);\n *   controller_clear_line(E_CONTROLLER_MASTER, 0);\n * }\n * \\endcode\n */\nint32_t controller_clear_line(controller_id_e_t id, uint8_t line);\n\n/**\n * Clears all of the lines on the controller screen.\n *\n * \\note Controller text setting is a slow process, so updates faster than 10ms\n * when on a wired connection or 50ms over Vexnet will not be applied to the controller.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is\n * given.\n * EACCES - Another resource is currently trying to access the controller port.\n * EAGAIN - Could not send the text to the controller.\n *\n * \\param id\n *        The ID of the controller (e.g. the master or partner controller).\n *        Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   controller_set_text(E_CONTROLLER_MASTER, 0, 0, \"Example\");\n *   delay(100);\n *   controller_clear(E_CONTROLLER_MASTER);\n * }\n * \\endcode\n */\nint32_t controller_clear(controller_id_e_t id);\n\n/**\n * Rumble the controller.\n *\n * \\note Controller rumble activation is a slow process, so updates faster than 10ms\n * when on a wired connection or 50ms over Vexnet will not be applied to the controller.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is\n * given.\n * EACCES - Another resource is currently trying to access the controller port.\n *\n * \\param id\n *\t\t\t\tThe ID of the controller (e.g. the master or partner controller).\n *\t\t\t\tMust be one of CONTROLLER_MASTER or CONTROLLER_PARTNER\n * \\param rumble_pattern\n *\t\t\t\tA string consisting of the characters '.', '-', and ' ', where dots\n *\t\t\t\tare short rumbles, dashes are long rumbles, and spaces are pauses.\n *\t\t\t\tMaximum supported length is 8 characters.\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   int count = 0;\n *   while (true) {\n *   if (!(count % 25)) {\n *     // Only send every 50ms, the controller update rate is slow\n *     controller_rumble(E_CONTROLLER_MASTER, \". - . -\");\n *   }\n *   count++;\n *   delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t controller_rumble(controller_id_e_t id, const char* rumble_pattern);\n\n/**\n * Gets the current voltage of the battery, as reported by VEXos.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCES - Another resource is currently trying to access the battery port.\n *\n * \\return The current voltage of the battery\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Battery's Voltage: %d\\n\", battery_get_voltage());\n * }\n * \\endcode\n */\nint32_t battery_get_voltage(void);\n\n/**\n * Gets the current current of the battery, as reported by VEXos.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCES - Another resource is currently trying to access the battery port.\n *\n * \\return The current current of the battery\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Battery Current: %d\\n\", battery_get_current());\n * }\n * \\endcode\n */\nint32_t battery_get_current(void);\n\n/**\n * Gets the current temperature of the battery, as reported by VEXos.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCES - Another resource is currently trying to access the battery port.\n *\n * \\return The current temperature of the battery\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Battery's Temperature: %d\\n\", battery_get_temperature());\n * }\n * \\endcode\n */\ndouble battery_get_temperature(void);\n\n/**\n * Gets the current capacity of the battery, as reported by VEXos.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCES - Another resource is currently trying to access the battery port.\n *\n * \\return The current capacity of the battery\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Battery Level: %d\\n\", battery_get_capacity());\n * }\n * \\endcode\n */\ndouble battery_get_capacity(void);\n\n/**\n * Checks if the SD card is installed.\n *\n * \\return 1 if the SD card is installed, 0 otherwise\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   printf(\"%i\", usd_is_installed());\n * }\n * \\endcode\n */\nint32_t usd_is_installed(void);\n\n/**\n * Lists the files in a directory specified by the path\n * Puts the list of file names (NOT DIRECTORIES) into the buffer seperated by newlines\n *\n * This function uses the following values of errno when an error state is\n * reached:\n *\n * EIO - Hard error occured in the low level disk I/O layer\n * EINVAL - file or directory is invalid, or length is invalid\n * EBUSY - THe physical drinve cannot work\n * ENOENT - cannot find the path or file\n * EINVAL - the path name format is invalid\n * EACCES - Access denied or directory full\n * EEXIST - Access denied\n * EROFS - SD card is write protected\n * ENXIO - drive number is invalid or not a FAT32 drive\n * ENOBUFS - drive has no work area\n * ENFILE - too many open files\n *\n *\n *\n * \\note use a path of \"\\\" to list the files in the main directory NOT \"/usd/\"\n *  DO NOT PREPEND YOUR PATHS WITH \"/usd/\"\n *\n * \\return 1 on success or PROS_ERR on failure setting errno\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n * \tchar* test = (char*) malloc(128);\n *\tpros::c::usd_list_files(\"/\", test, 128);\n *\tpros::delay(200);\n *\tprintf(\"%s\\n\", test); //Prints the file names in the root directory seperated by newlines\n *  pros::delay(100);\n *  pros::c::usd_list_files(\"/test\", test, 128);\n *\tpros::delay(200);\n *\tprintf(\"%s\\n\", test); //Prints the names of files in the folder named test seperated by newlines\n *  pros::delay(100);\n * }\n * \\endcode\n */\nint32_t usd_list_files(const char* path, char* buffer, int32_t len);\n\n/******************************************************************************/\n/**                              Date and Time                               **/\n/******************************************************************************/\n\nextern const char* baked_date;\nextern const char* baked_time;\n\ntypedef struct {\n\tuint16_t year;  // Year - 1980\n\tuint8_t day;\n\tuint8_t month;  // 1 = January\n} date_s_t;\n\ntypedef struct {\n\tuint8_t hour;\n\tuint8_t min;\n\tuint8_t sec;\n\tuint8_t sec_hund;  // hundredths of a second\n} time_s_t;\n\n///@}\n\n///@}\n\n#ifdef __cplusplus\n}\n}  // namespace pros\n}\n#endif\n\n#endif  // _PROS_MISC_H_\n"
  },
  {
    "path": "include/pros/misc.hpp",
    "content": "/**\n * \\file pros/misc.hpp\n * \\ingroup cpp-pros\n *\n * Contains prototypes for miscellaneous functions pertaining to the controller,\n * battery, and competition control.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reservered.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-misc Miscellaneous C++ API\n * \\note Additional example code for this module can be found in its [Tutorial.](@ref controller)\n */\n\n#ifndef _PROS_MISC_HPP_\n#define _PROS_MISC_HPP_\n\n#include <cstdint>\n#include <string>\n\n#include \"pros/misc.h\"\n\nnamespace pros {\ninline namespace v5 {\n/**\n * \\ingroup cpp-misc\n */\nclass Controller {\n\t/**\n\t * \\addtogroup cpp-misc\n\t * ///@{\n\t */\n\tpublic:\n\t/**\n\t * Creates a controller object for the given controller id.\n\t *\n\t * \\param id\n\t * \t\t\t  The ID of the controller (e.g. the master or partner controller).\n\t * \t\t\t  Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER\n\t */\n\texplicit Controller(controller_id_e_t id);\n\n\t/**\n\t * Checks if the controller is connected.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\return 1 if the controller is connected, 0 otherwise\n\t *\n\t * \\b Example\n\t * \\code\n\t * void status_display_controller(){\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *   if(!master.is_connected()) {\n\t * \t   pros::lcd::print(0, \"Main controller is not connected!\");\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t is_connected(void);\n\n\t/**\n\t * Gets the value of an analog channel (joystick) on a controller.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\param channel\n\t * \t\t\t  The analog channel to get.\n\t * \t\t\t  Must be one of ANALOG_LEFT_X, ANALOG_LEFT_Y, ANALOG_RIGHT_X,\n\t *        ANALOG_RIGHT_Y\n\t *\n\t * \\return The current reading of the analog channel: [-127, 127].\n\t * If the controller was not connected, then 0 is returned\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor_move(1, master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));\n\t *     delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_analog(controller_analog_e_t channel);\n\n\t/**\n\t * Gets the battery capacity of the controller.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\return The controller's battery capacity\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *   printf(\"Battery Capacity: %d\\n\", master.get_battery_capacity());\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_battery_capacity(void);\n\n\t/**\n\t * Gets the battery level of the controller.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\return The controller's battery level\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t * \t pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *   printf(\"Battery Level: %d\\n\", master.get_battery_level());\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_battery_level(void);\n\n\t/**\n\t * Checks if a digital channel (button) on the controller is currently\n\t * pressed.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\param button\n\t * \t\t\t  The button to read. Must be one of\n\t *        DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}\n\t *\n\t * \\return 1 if the button on the controller is pressed.\n\t * If the controller was not connected, then 0 is returned\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *   if (master.get_digital(pros::E_CONTROLLER_DIGITAL_A)) {\n\t *     motor_set(1, 100);\n\t *   }\n\t *   else {\n\t *     motor_set(1, 0);\n\t *   }\n\t *     delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_digital(controller_digital_e_t button);\n\n\t/**\n\t * Returns a rising-edge case for a controller button press.\n\t *\n\t * This function is not thread-safe.\n\t * Multiple tasks polling a single button may return different results under\n\t * the same circumstances, so only one task should call this function for any\n\t * given button. E.g., Task A calls this function for buttons 1 and 2.\n\t * Task B may call this function for button 3, but should not for buttons\n\t * 1 or 2. A typical use-case for this function is to call inside opcontrol\n\t * to detect new button presses, and not in any other tasks.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\param button\n\t * \t\t\t  The button to read. Must be one of\n\t *        DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}\n\t *\n\t * \\return 1 if the button on the controller is pressed and had not been\n\t * pressed the last time this function was called, 0 otherwise.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Controller master(pros::E_CONTROLLER_MASTER);\n\t * \twhile (true) {\n\t *   if (master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_A)) {\n\t *     // Toggle pneumatics or other similar actions\n\t *   }\n\t *\n\t *   delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_digital_new_press(controller_digital_e_t button);\n\n\t/**\n\t * Returns a falling-edge case for a controller button press.\n\t *\n\t * This function is not thread-safe.\n\t * Multiple tasks polling a single button may return different results under\n\t * the same circumstances, so only one task should call this function for any\n\t * given button. E.g., Task A calls this function for buttons 1 and 2.\n\t * Task B may call this function for button 3, but should not for buttons\n\t * 1 or 2. A typical use-case for this function is to call inside opcontrol\n\t * to detect new button releases, and not in any other tasks.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\param button\n\t * \t\t\t  The button to read. Must be one of\n\t *        DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}\n\t *\n\t * \\return 1 if the button on the controller is not pressed and had been\n\t * pressed the last time this function was called, 0 otherwise.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Controller master(pros::E_CONTROLLER_MASTER);\n\t * \twhile (true) {\n\t *   if (master.get_digital_new_release(pros::E_CONTROLLER_DIGITAL_A)) {\n\t *     // Toggle pneumatics or other similar actions\n\t *   }\n\t *\n\t *   delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_digital_new_release(controller_digital_e_t button);\n\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Wunused-function\"\n\ttemplate <typename T>\n\tT convert_args(T arg) {\n\t\treturn arg;\n\t}\n\tconst char* convert_args(const std::string& arg) {\n\t\treturn arg.c_str();\n\t}\n#pragma GCC diagnostic pop\n\n\t/**\n\t * Sets text to the controller LCD screen.\n\t *\n\t * \\note Controller text setting is currently in beta, so continuous, fast\n\t * updates will not work well.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\param line\n\t *        The line number at which the text will be displayed [0-2]\n\t * \\param col\n\t *        The column number at which the text will be displayed [0-14]\n\t * \\param fmt\n\t *        The format string to print to the controller\n\t * \\param ...\n\t *        The argument list for the format string\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   int count = 0;\n\t * \t pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *   if (!(count % 25)) {\n\t *     // Only print every 50ms, the controller text update rate is slow\n\t *     master.print(0, 0, \"Counter: %d\", count);\n\t *   }\n\t *     count++;\n\t *     delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\ttemplate <typename... Params>\n\tstd::int32_t print(std::uint8_t line, std::uint8_t col, const char* fmt, Params... args) {\n\t\treturn pros::c::controller_print(_id, line, col, fmt, convert_args(args)...);\n\t}\n\n\t/**\n\t * Sets text to the controller LCD screen.\n\t *\n\t * \\note Controller text setting is currently in beta, so continuous, fast\n\t * updates will not work well.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\param line\n\t *        The line number at which the text will be displayed [0-2]\n\t * \\param col\n\t *        The column number at which the text will be displayed [0-14]\n\t * \\param str\n\t *        The pre-formatted string to print to the controller\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   int count = 0;\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     if (!(count % 25)) {\n\t *       // Only print every 50ms, the controller text update rate is slow\n\t *       master.set_text(0, 0, \"Example text\");\n\t *     }\n\t *   count++;\n\t *   delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_text(std::uint8_t line, std::uint8_t col, const char* str);\n\tstd::int32_t set_text(std::uint8_t line, std::uint8_t col, const std::string& str);\n\n\t/**\n\t * Clears an individual line of the controller screen.\n\t *\n\t * \\note Controller text setting is currently in beta, so continuous, fast\n\t * updates will not work well.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\param line\n\t *        The line number to clear [0-2]\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *   master.set_text(0, 0, \"Example\");\n\t *   delay(100);\n\t *   master.clear_line(0);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t clear_line(std::uint8_t line);\n\n\t/**\n\t * Rumble the controller.\n\t *\n\t * \\note Controller rumble activation is currently in beta, so continuous, fast\n\t * updates will not work well.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\param rumble_pattern\n\t *\t\t\t\tA string consisting of the characters '.', '-', and ' ', where dots\n\t *\t\t\t\tare short rumbles, dashes are long rumbles, and spaces are pauses.\n\t *\t\t\t\tMaximum supported length is 8 characters.\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   int count = 0;\n\t *   pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *   if (!(count % 25)) {\n\t *     // Only send every 50ms, the controller update rate is slow\n\t *     master.rumble(\". - . -\");\n\t *   }\n\t *   count++;\n\t *   delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t rumble(const char* rumble_pattern);\n\n\t/**\n\t * Clears all of the lines on the controller screen.\n\t *\n\t * \\note Controller text setting is currently in beta, so continuous, fast\n\t * updates will not work well. On vexOS version 1.0.0 this function will\n\t * block for 110ms.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EACCES - Another resource is currently trying to access the controller\n\t * port.\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \t pros::Controller master(pros::E_CONTROLLER_MASTER);\n\t *   master.set_text(0, 0, \"Example\");\n\t *   delay(100);\n\t *   master.clear();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t clear(void);\n\n\tprivate:\n\tcontroller_id_e_t _id;\n\t///@}\n};\n}  //  namespace v5\n\nnamespace battery {\n/**\n * \\addtogroup cpp-misc\n * ///@{\n */\n/**\n * Gets the current voltage of the battery, as reported by VEXos.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCES - Another resource is currently trying to access the battery port.\n *\n * \\return The current voltage of the battery\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Battery Level: %.2f\\n\", get_capacity());\n * }\n * \\endcode\n */\ndouble get_capacity(void);\n\n/**\n * Gets the current current of the battery in milliamps, as reported by VEXos.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCES - Another resource is currently trying to access the battery port.\n *\n * \\return The current current of the battery\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Battery Current: %d\\n\", get_current());\n * }\n * \\endcode\n */\nint32_t get_current(void);\n\n/**\n * Gets the current temperature of the battery, as reported by VEXos.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCES - Another resource is currently trying to access the battery port.\n *\n * \\return The current temperature of the battery\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Battery's Temperature: %.2f\\n\", get_temperature());\n * }\n * \\endcode\n */\ndouble get_temperature(void);\n\n/**\n * Gets the current capacity of the battery in millivolts, as reported by VEXos.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCES - Another resource is currently trying to access the battery port.\n *\n * \\return The current capacity of the battery\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Battery's Voltage: %d\\n\", get_voltage());\n * }\n * \\endcode\n */\nint32_t get_voltage(void);\n///@}\n}  // namespace battery\n\nnamespace competition {\n/**\n * Get the current status of the competition control.\n *\n * \\return The competition control status as a mask of bits with\n * COMPETITION_{ENABLED,AUTONOMOUS,CONNECTED}.\n *\n * \\b Example\n * \\code\n * void status_display_task(){\n * \tif(!is_connected()) {\n * \t pros::lcd::print(0, \"V5 Brain is not connected!\");\n *  }\n *  if(is_autonomous()) {\n * \t pros::lcd::print(0, \"V5 Brain is in autonomous mode!\");\n *  }\n *  if(!is_disabled()) {\n * \t pros::lcd::print(0, \"V5 Brain is disabled!\");\n *  }\n * \\endcode\n */\nstd::uint8_t get_status(void);\nstd::uint8_t is_autonomous(void);\nstd::uint8_t is_connected(void);\nstd::uint8_t is_disabled(void);\nstd::uint8_t is_field_control(void);\nstd::uint8_t is_competition_switch(void);\n}  // namespace competition\n\nnamespace usd {\n/**\n * Checks if the SD card is installed.\n *\n * \\return 1 if the SD card is installed, 0 otherwise\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   printf(\"%i\", is_installed());\n * }\n * \\endcode\n */\nstd::int32_t is_installed(void);\n/**\n * Lists the files in a directory specified by the path\n * Puts the list of file names (NOT DIRECTORIES) into the buffer seperated by newlines\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * \n * EIO - Hard error occured in the low level disk I/O layer\n * EINVAL - file or directory is invalid, or length is invalid\n * EBUSY - THe physical drinve cannot work\n * ENOENT - cannot find the path or file\n * EINVAL - the path name format is invalid\n * EACCES - Access denied or directory full\n * EEXIST - Access denied\n * EROFS - SD card is write protected\n * ENXIO - drive number is invalid or not a FAT32 drive\n * ENOBUFS - drive has no work area\n * ENFILE - too many open files\n *\n *\n *\n * \\note use a path of \"\\\" to list the files in the main directory NOT \"/usd/\"\n *  DO NOT PREPEND YOUR PATHS WITH \"/usd/\"\n *\n * \\return 1 on success or PROS_ERR on failure setting errno\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n * \tchar* test = (char*) malloc(128);\n *\tpros::usd::list_files(\"/\", test, 128);\n *\tpros::delay(200);\n *\tprintf(\"%s\\n\", test); //Prints the file names in the root directory seperated by newlines\n *  pros::delay(100);\n *  pros::list_files(\"/test\", test, 128);\n *\tpros::delay(200);\n *\tprintf(\"%s\\n\", test); //Prints the names of files in the folder named test seperated by newlines\n *  pros::delay(100);\n * }\n * \\endcode\n */\n\nstd::int32_t list_files(const char* path, char* buffer, std::int32_t len);\n}  // namespace usd\n\n}  // namespace pros\n\n#endif  // _PROS_MISC_HPP_\n"
  },
  {
    "path": "include/pros/motor_group.hpp",
    "content": "/**\n * \\file pros/motor_group.hpp\n * \\ingroup cpp-motor-group\n *\n * Contains prototypes for the V5 Motor-related functions.\n *\n * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/motors.html to learn\n * more.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-motor-group Motors C++ API\n * \\note Additional example code for this module can be found in its [Tutorial](@ref motors).\n */\n\n#ifndef _PROS_MOTOR_GROUP_HPP_\n#define _PROS_MOTOR_GROUP_HPP_\n\n#include <cstdint>\n#include <iostream>\n\n#include \"pros/abstract_motor.hpp\"\n#include \"pros/colors.hpp\"\n#include \"pros/device.hpp\"\n#include \"pros/motors.h\"\n#include \"pros/motors.hpp\"\n#include \"rtos.hpp\"\n\nnamespace pros {\ninline namespace v5 {\nclass MotorGroup : public virtual AbstractMotor {\n\t/**\n\t * \\addtogroup cpp-motor-group\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Constructs a new MotorGroup object.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports |1-21|.\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param port\n\t *        A initializer list of V5 port numbers from 1 to 21, or from -21 to -1 for reversed motors.\n\t * \t\t  A reversed motor will reverse the input or output movement functions and movement related\n\t * \t\t  telemetry in order to produce consistant behavior with non-reversed motors\n\t *\n\t * \\param gearset = pros::v5::MotorGears::invalid\n\t * \t\t  Optional parameter for the gearset for the motor.\n\t * \t\t  Does not explicitly set the motor gearset if it is invalid or not specified\n\t *\n\t * \\param encoder_units = pros::v5::MotorUnits::invalid\n\t * \t\t  Optional parameter for the encoder units of the motor\n\t * \t\t  Does not explicitly set the motor units if it is invalid or not specified\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \tMotorGroup first_mg({1, -2}); //Creates a motor on port 1 and a reversed motor on port 2\n\t *  MotorGroup rotations_mg({4, 5}, pros::v5::MotorGears::blue, pros::v5::MotorUnits::rotations);\n\t *  //Creates a motor group on ports 4 and 5 with blue motors using rotaions as the encoder units\n\t * }\n\t * \\endcode\n\t */\n\tMotorGroup(const std::initializer_list<std::int8_t>,\n\t           const pros::v5::MotorGears gearset = pros::v5::MotorGears::invalid,\n\t           const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::invalid);\n\t/**\n\t * Constructs a new MotorGroup object.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENXIO - The given value is not within the range of V5 ports |1-21|.\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param port\n\t *        A initializer list of V5 port numbers from 1 to 21, or from -21 to -1 for reversed motors.\n\t * \t\t  A reversed motor will reverse the input or output movement functions and movement related\n\t * \t\t  telemetry in order to produce consistant behavior with non-reversed motors\n\t *\n\t * \\param gearset = pros::v5::MotorGears::invalid\n\t * \\param gearset = pros::v5::MotorGears::green\n\t * \t\t  Optional parameter for the gearset for the motor.\n\t * \t\t  Does not explicitly set the motor gearset if it is invalid or not specified\n\t *\n\t * \\param encoder_units = pros::v5::MotorUnits::invalid\n\t * \t\t  Optional parameter for the encoder units of the motor\n\t * \t\t  Does not explicitly set the motor units if it is invalid or not specified\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \tMotorGroup first_mg({1, -2}); //Creates a motor on port 1 and a reversed motor on port 2 with\n\t *  with both motors using the green gearset and degrees as the encoder units\n\t *  MotorGroup rotations_mg({4, 5}, pros::v5::MotorGears::blue, pros::v5::MotorUnits::rotations);\n\t *  //Creates a motor group on ports 4 and 5 with blue motors using rotaions as the encoder units\n\t * }\n\t * \\endcode\n\t */\n\tMotorGroup(const std::vector<std::int8_t>& ports, const pros::v5::MotorGears gearset = pros::v5::MotorGears::invalid,\n\t           const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::invalid);\n\n\t/**\n\t * Constructs a new MotorGroup object from an abstract motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENXIO - The given value is not within the range of V5 ports |1-21|.\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param abstract_motor\n\t * \t\t  The abstract motor to turn into a motor group\n\t * \t\t  Uses abstract_motor.get_port_all() to get the vector of ports\n\t *\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \tMotorGroup first_mg({1, -2}); //Creates a motor on port 1 and a reversed motor on port 2 with\n\t *  with both motors using the green gearset and degrees as the encoder units\n\t * \tAbstractMotor abs_mtr_group = first_mg;\n\t * \tMotorGroup new_mg = (MotorGroup) abs_mtr_group;\n\t * }\n\t * \\endcode\n\t */\n\n\tMotorGroup(AbstractMotor& motor_group);\n\n\t/// \\name Motor movement functions\n\t/// These functions allow programmers to make motors move\n\t///@{\n\n\t/**\n\t * Sets the voltage for the motor group from -127 to 127.\n\t *\n\t * This is designed to map easily to the input from the controller's analog\n\t * stick for simple opcontrol use. The actual behavior of the motor is\n\t * analogous to use of motor_move()\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param voltage\n\t *        The new voltage from -127 to 127\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup MotorGroup ({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg.move(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t move(std::int32_t voltage) const;\n\n\t/**\n\t * Sets the target absolute position for the motor group to move to.\n\t *\n\t * This movement is relative to the position of the motor when initialized or\n\t * the position when it was most recently reset with\n\t * pros::Motor::set_zero_position().\n\t *\n\t * \\note This function simply sets the target for the motor, it does not block\n\t * program execution until the movement finishes.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - the motor group has size 0\n\t *\n\t * \\param position\n\t *        The absolute position to move to in the motor's encoder units\n\t * \\param velocity\n\t *        The maximum allowable velocity for the movement in RPM\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::MotorGroup mg ({1,3});\n\t *   mg.move_absolute(100, 100); // Moves 100 units forward\n\t *   while (!((mg.get_position() < 105) && (mg.get_position() > 95))) {\n\t *     // Continue running this loop as long as the mg is not within +-5 units of its goal\n\t *     pros::delay(2);\n\t *   }\n\t *   mg.move_absolute(100, 100); // This does not cause a movement\n\t *   while (!((mg.get_position() < 105) && (mg.get_position() > 95))) {\n\t *     pros::delay(2);\n\t *   }\n\t *   mg.tare_position();\n\t *   mg.move_absolute(100, 100); // Moves 100 units forward\n\t *   while (!((mg.get_position() < 105) && (mg.get_position() > 95))) {\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t move_absolute(const double position, const std::int32_t velocity) const;\n\n\t/**\n\t * Sets the relative target position for the motor group to move to.\n\t *\n\t * This movement is relative to the current position of each motor as given in\n\t * pros::MotorGroup::get_position(). Providing 10.0 as the position parameter\n\t * would result in the motor moving 10 units, no matter what the\n\t * current position is.\n\t *\n\t * \\note This function simply sets the target for the motor, it does not block\n\t * program execution until the movement finishes.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param position\n\t *        The relative position to move to in the motor's encoder units\n\t * \\param velocity\n\t *        The maximum allowable velocity for the movement in RPM\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.move_relative(100, 100); // Moves 100 units forward\n\t *   while (!((mg.get_position() < 105) && (mg.get_position() > 95))) {\n\t *     // Continue running this loop as long as the motor is not within +-5 units of its goal\n\t *     pros::delay(2);\n\t *   }\n\t *   mg.move_relative(100, 100); // Also moves 100 units forward\n\t *   while (!((mg.get_position() < 205) && (mg.get_position() > 195))) {\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t move_relative(const double position, const std::int32_t velocity) const;\n\n\t/**\n\t * Sets the velocity for the motor group.\n\t *\n\t * This velocity corresponds to different actual speeds depending on the\n\t * gearset used for the motor. This results in a range of +-100 for\n\t * E_MOTOR_GEARSET_36, +-200 for E_MOTOR_GEARSET_18, and +-600 for\n\t * E_MOTOR_GEARSET_6. The velocity is held with PID to ensure consistent\n\t * speed, as opposed to setting the motor's voltage.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param velocity\n\t *        The new velocity from +-100, +-200, or +-600 depending on the\n\t *        motor's gearset\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.move_velocity(100);\n\t *   pros::delay(1000); // Move at 100 RPM for 1 second\n\t *   mg.move_velocity(0);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t move_velocity(const std::int32_t velocity) const;\n\n\t/**\n\t * Sets the output voltage for the motor group from -12000 to 12000 in millivolts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param voltage\n\t *        The new voltage value from -12000 to 12000\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   mg.move_voltage(12000);\n\t *   pros::delay(1000); // Move at max voltage for 1 second\n\t *   mg.move_voltage(0);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t move_voltage(const std::int32_t voltage) const;\n\n\t/**\n\t * Stops the motor group using the currently configured brake mode.\n\t *\n\t * This function sets motor velocity to zero, which will cause it to act\n\t * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD,\n\t * this function may behave differently than calling move_absolute(0)\n\t * or motor_move_relative(0).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *  void autonomous() {\n\t *\tMotor motor(1);\n\t *   mg.move_voltage(12000);\n\t *   pros::delay(1000); // Move at max voltage for 1 second\n\t *   motor.brake();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t brake(void) const;\n\n\t/**\n\t * Changes the output velocity for a profiled movement (move_absolute or\n\t * move_relative). This will have no effect if the motor group is not following\n\t * a profiled movement.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param velocity\n\t *        The new motor velocity from +-100, +-200, or +-600 depending on the\n\t *        motor's gearset\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t * \t pros::MotorGroup mg ({1,3});\n\t *   mg.move_absolute(100, 100);\n\t *   pros::delay(100);\n\t *   mg.modify_profiled_velocity(0); // Stop the motor group early\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t modify_profiled_velocity(const std::int32_t velocity) const;\n\n\t/**\n\t * Gets the target position set for a motor in the motor group, with a parameter\n\t * for the motor index.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The target position in its encoder units or PROS_ERR_F if the\n\t * operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.move_absolute(100, 100);\n\t * \t// get the target position from motor at index 1. (port 3)\n\t *   std::cout << \"Motor Target: \" << mg.get_target_position(1);\n\t *   // Prints 100\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_target_position(const std::uint8_t index) const;\n\n\t/**\n\t * Gets a vector of the the target positions set for the motor group\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The Motor group is empty\n\t *\n\t * \\return The a vector of the target positions in its encoder units or PROS_ERR_F if the\n\t * operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.move_absolute(100, 100);\n\t *   std::cout << \"Motor Target: \" << mg.get_target_position_all()[0];\n\t *   // Prints 100\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_target_position_all(void) const;\n\n\t/**\n\t * Gets the velocity commanded to the motor by the user at the index specified.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t * EDOM - The motor group was empty\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The commanded motor velocity from +-100, +-200, or +-600, or\n\t * PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg ({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));\n\t * \t\t// get the target velocity from motor at index 1. (port 3)\n\t *     std::cout << \"Motor Velocity: \" << mg.get_target_velocity(1);\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_target_velocity(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets a vector of the velocity commanded to the motor by the user\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - THe motor group is empty\n\t *\n\t * \\return A vector of the commanded motor velocity from +-100, +-200, or +-600, or\n\t * PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg ({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));\n\t *     std::cout << \"Motor Velocity: \" << mg.get_target_velocity_all();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_target_velocity_all(void) const;\n\n\t///@}\n\n\t/// \\name Motor telemetry functions\n\t/// These functions allow programmers to collect telemetry from motors\n\t///@{\n\n\t/**\n\t * Gets the actual velocity of a motor in the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - THe motor group is empty\n\t *\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The motor's actual velocity in RPM or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   while (true) {\n\t *     mg = controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y);\n\t *\t   // get the actual velocity from motor at index 1. (port 3)\n\t *     printf(\"Actual velocity: %lf\\n\", mg.get_actual_velocity(1));\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_actual_velocity(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets a vector of the the actual velocity of each motor the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - THe motor group is empty\n\t *\n\t * \\return A vector of the each motor's actual velocity in RPM or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   while (true) {\n\t *     mg = controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y);\n\t *\t   // get the target velocity from motor at index 1. (port 3)\n\t *     printf(\"Actual velocity: %lf\\n\", mg.get_actual_velocity(1));\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_actual_velocity_all(void) const;\n\n\t/**\n\t * Gets the current drawn by a motor in the motor group in mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - The motor group is empty\n\t *\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The motor's current in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t * \t   //Print the current draw for the motor at index 1. (port 3)\n\t *     std::cout << \"Motor Current Draw: \" << mg.get_current_draw(1);\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_current_draw(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector of the current drawn each motor in the motor group in mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - The motor group is empty\n\t *\n\t *\n\t * \\return A vector with each motor's current in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Current Draw: \" << mg.get_current_draw_all();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_current_draw_all(void) const;\n\n\t/**\n\t * Gets the direction of movement for a motor in the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - The motor group is empty\n\t *\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 for moving in the positive direction, -1 for moving in the\n\t * negative direction, and PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t * \t   //Print the motor direction for the motor at index 1. (port 3)\n\t *     std::cout << \"Motor Direction: \" << mg.get_direction();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_direction(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector of the directions of movement for each motor in the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return 1 for moving in the positive direction, -1 for moving in the\n\t * negative direction, and PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Direction: \" << mg.get_direction_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_direction_all(void) const;\n\n\t/**\n\t * Gets the efficiency of a motor in the motor group in percent.\n\t *\n\t * An efficiency of 100% means that the motor is moving electrically while\n\t * drawing no electrical power, and an efficiency of 0% means that the motor\n\t * is drawing power but not moving.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - The motor group is empty\n\t *\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The motor's efficiency in percent or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     //Prints the efficiency of the motor at index 1 (port 3)\n\t *     std::cout << \"Motor Efficiency: \" << mg.get_efficiency(1);\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_efficiency(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector of the efficiency of each motor in percent.\n\t *\n\t * An efficiency of 100% means that the motor is moving electrically while\n\t * drawing no electrical power, and an efficiency of 0% means that the motor\n\t * is drawing power but not moving.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - THe motor group is empty\n\t *\n\t * \\return A vector containing each motor's efficiency in percent or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Efficiency: \" << mg.get_efficiency_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_efficiency_all(void) const;\n\n\t/**\n\t * Gets the faults experienced by a motor in the motor group.\n\t *\n\t * Compare this bitfield to the bitmasks in pros::motor_fault_e_t.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - The motor group is empty\n\t *\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return A bitfield containing the motor's faults.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Faults: \" << mg.get_faults();\n\t * pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::uint32_t get_faults(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector of the faults experienced by each motor in the motor group.\n\t *\n\t * Compare these bitfields to the bitmasks in pros::motor_fault_e_t.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EDOM - The motor group is empty\n\t *\n\t *\n\t * \\return A vector containing the bitfields containing each motor's faults.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Faults: \" << mg.get_faults_all();\n\t * pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::uint32_t> get_faults_all(void) const;\n\t/**\n\t * Gets the flags set by a motor in the motor group's operation.\n\t *\n\t * Compare this bitfield to the bitmasks in pros::motor_flag_e_t.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return A bitfield containing the motor's flags.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Faults: \" << mg.get_faults(1);\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::uint32_t get_flags(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets a vector of the flags set by each motor in the motor groups's operation.\n\t *\n\t * Compare this bitfield to the bitmasks in pros::motor_flag_e_t.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A bitfield containing the motor's flags.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Faults: \" << mg.get_faults_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::uint32_t> get_flags_all(void) const;\n\n\t/**\n\t * Gets the absolute position of a motor in the motor group in its encoder units.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The motor's absolute position in its encoder units or PROS_ERR_F\n\t * if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Position: \" << mg.get_position(1);\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_position(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector of the absolute position of each motor in its encoder units.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A vector of the motor's absolute position in its encoder units or PROS_ERR_F\n\t * if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Position: \" << mg.get_position_all();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_position_all(void) const;\n\n\t/**\n\t * Gets the power drawn by a motor in the motor group in Watts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The motor's power draw in Watts or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Power: \" << mg.get_power();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_power(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector of the power drawn by each motor in the motor group in Watts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A vector of each motor's power draw in Watts or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Power: \" << mg.get_power_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_power_all(void) const;\n\t/**\n\t * Gets the raw encoder count of a motor in the motor group at a given timestamp.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t *\n\t * \\param timestamp\n\t *            A pointer to a time in milliseconds for which the encoder count\n\t *            will be returned. If NULL, the timestamp at which the encoder\n\t *            count was read will not be supplied\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The raw encoder count at the given timestamp or PROS_ERR if the\n\t * operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   std::uint32_t now = pros::millis();\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Position: \" << mg.get_raw_position(&now);\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_raw_position(std::uint32_t* const timestamp, const std::uint8_t index = 0) const;\n\t/**\n\t * Gets the raw encoder count of each motor at a given timestamp.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param timestamp\n\t *            A pointer to a time in milliseconds for which the encoder count\n\t *            will be returned. If NULL, the timestamp at which the encoder\n\t *            count was read will not be supplied\n\t *\n\t * \\return A vector of each raw encoder count at the given timestamp or PROS_ERR if the\n\t * operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   std::uint32_t now = pros::millis();\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Position: \" << mg.get_raw_position_all(&now)[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_raw_position_all(std::uint32_t* const timestamp) const;\n\n\t/**\n\t * Gets the temperature of a motor in the motor group in degrees Celsius.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The motor's temperature in degrees Celsius or PROS_ERR_F if the\n\t * operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Temperature: \" << mg.get_temperature();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_temperature(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets the temperature of each motor in the motor group in degrees Celsius.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A vector of each motor's temperature in degrees Celsius or PROS_ERR_F if the\n\t * operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Temperature: \" << mg.get_temperature_all()[1];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_temperature_all(void) const;\n\t/**\n\t * Gets the torque generated by a motor in the motor groupin Newton Meters (Nm).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The motor's torque in Nm or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Torque: \" << mg.get_torque();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_torque(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector of the torque generated by each motor in Newton Meters (Nm).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A vector containing each motor's torque in Nm or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Torque: \" << mg.get_torque();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_torque_all(void) const;\n\t/**\n\t * Gets the voltage delivered to a motor in the motor group in millivolts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The motor's voltage in mV or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Voltage: \" << mg.get_voltage();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_voltage(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector of the voltage delivered to each motor in millivolts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A vector of each motor's voltage in mV or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Voltage: \" << mg.get_voltage_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_voltage_all(void) const;\n\n\t/**\n\t * Checks if a motor in the motor group is drawing over its current limit.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 if the motor's current limit is being exceeded and 0 if the\n\t * current limit is not exceeded, or PROS_ERR if the operation failed, setting\n\t * errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Is the motor over its current limit?: \" << mg.is_over_current();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t is_over_current(const std::uint8_t index = 0) const;\n\t/**\n\t * Checks if each motor in the motor group is drawing over its current limit.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A vector containing the following for each motor: 1 if the motor's current limit is being exceeded and 0 if\n\t * the current limit is not exceeded, or PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Is the motor over its current limit?: \" << motor.is_over_current_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> is_over_current_all(void) const;\n\n\t/**\n\t * Gets the temperature limit flag for a motor in the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 if the temperature limit is exceeded and 0 if the temperature is\n\t * below the limit, or PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Is the motor over its temperature limit?: \" << motor.is_over_temp();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t is_over_temp(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector with the temperature limit flag for each motor in the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return 1 if the temperature limit is exceeded and 0 if the temperature is\n\t * below the limit, or PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Is the motor over its temperature limit?: \" << motor.is_over_temp();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> is_over_temp_all(void) const;\n\n\t///@}\n\n\t/// \\name Motor configuration functions\n\t/// These functions allow programmers to configure the behavior of motors\n\t///@{\n\n\t/**\n\t * Gets the brake mode that was set for a motor in the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return One of MotorBrake, according to what was set for the\n\t * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);\n\t *   std::cout << \"Brake Mode: \" << mg.get_brake_mode();\n\t * }\n\t * \\endcode\n\t */\n\tMotorBrake get_brake_mode(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector with the brake mode that was set for each motor in the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A vector with one of MotorBrake for each motor in the motor group, according to what was set for the\n\t * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);\n\t *   std::cout << \"Brake Mode: \" << mg.get_brake_mode_all()[0];\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<MotorBrake> get_brake_mode_all(void) const;\n\n\t/**\n\t * Gets the current limit for a motor in the motor group in mA.\n\t *\n\t * The default value is 2500 mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The motor's current limit in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   while (true) {\n\t *     std::cout << \"Motor Current Limit: \" << mg.get_current_limit();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_current_limit(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets a vector of the current limit for each motor in the motor group in mA.\n\t *\n\t * The default value is 2500 mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A vector of each motor's current limit in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   while (true) {\n\t *     std::cout << \"Motor Current Limit: \" << mg.get_current_limit_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_current_limit_all(void) const;\n\n\t/**\n\t * Gets the encoder units that were set for a motor in the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return One of MotorUnits according to what is set for the\n\t * motor or E_MOTOR_ENCODER_INVALID if the operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Encoder Units: \" << mg.get_encoder_units();\n\t * }\n\t * \\endcode\n\t */\n\tMotorUnits get_encoder_units(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets a vector of the encoder units that were set for each motor in the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A vector with the following for each motor, One of MotorUnits according to what is set for the\n\t * motor or E_MOTOR_ENCODER_INVALID if the operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Encoder Units: \" << mg.get_encoder_units_all()[0];\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<MotorUnits> get_encoder_units_all(void) const;\n\n\t/**\n\t * Gets the gearset that was set for a motor in the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t *\\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return One of MotorGears according to what is set for the motor,\n\t * or pros::MotorGears::invalid if the operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Gearing: \" << mg.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tMotorGears get_gearing(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector of the gearset that was set for each motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t *\n\t * \\return A vector with one of MotorGears according to what is set for the motor,\n\t * or pros::MotorGears::invalid if the operation failed for each motor.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Gearing: \" << mg.get_gearing_all()[0];\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<MotorGears> get_gearing_all(void) const;\n\n\t/**\n\t * Gets a vector with all the port numbers in the motor group.\n\t * A port will be negative if the motor in the motor group is reversed\n\t *\n\t * @return a vector with all the port numbers for the motor group\n\t */\n\tstd::vector<std::int8_t> get_port_all(void) const;\n\n\t/**\n\t * Gets the voltage limit of a motor in the motor group set by the user.\n\t *\n\t * Default value is 0V, which means that there is no software limitation\n\t * imposed on the voltage.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t *\\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The motor's voltage limit in V or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   std::cout << \"Motor Voltage Limit: \" << mg.get_voltage_limit(1);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_voltage_limit(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets a vector of the voltage limit of each motor in the motor group\n\t *\n\t * Default value is 0V, which means that there is no software limitation\n\t * imposed on the voltage.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The Motor group is empty\n\t *\n\t * \\return The motor's voltage limit in V or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   std::cout << \"Motor Voltage Limit: \" << mg.get_voltage_limit_all()[0];\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_voltage_limit_all(void) const;\n\n\t/**\n\t * Gets the operation direction of a motor in the motor group as set by the user.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t *\\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 if the motor has been reversed and 0 if the motor was not\n\t * reversed, or PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   std::cout << \"Is the motor reversed? \" << motor.is_reversed();\n\t *   // Prints \"0\"\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t is_reversed(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector of the operation direction of each motor in the motor group as set by the user.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A vector conatining the following for each motor: 1 if the motor has been reversed and 0 if the motor was\n\t * not reversed, or PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   std::cout << \"Is the motor reversed? \" << motor.is_reversed_all()[0];\n\t *   // Prints \"0\"\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> is_reversed_all(void) const;\n\n\t/**\n\t * Gets the type of a motor in the motor group.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t *\\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return One of MotorType according to the type of the motor,\n\t * or pros::MotorType::invalid if the operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Type: \" << mg.get_type();\n\t * }\n\t * \\endcode\n\t */\n\tMotorType get_type(const std::uint8_t index = 0) const;\n\t/**\n\t * Gets a vector of the type of each motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\return A vector with one of MotorType according to the type of the motor,\n\t * or pros::MotorType::invalid if the operation failed for each motor.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Type: \" << mg.get_type_all()[0];\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<MotorType> get_type_all(void) const;\n\n\t/**\n\t * Sets one of MotorBrake to a motor in the motor group. Works with the C enum\n\t * and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param mode\n\t *        The MotorBrake to set for the motor\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_brake_mode(pros::MotorBrake::brake, 1);\n\t *   std::cout << \"Brake Mode: \" << mg.get_brake_mode();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_brake_mode(const MotorBrake mode, const std::uint8_t index = 0) const;\n\t/**\n\t * Sets one of MotorBrake to a motor in the motor group. Works with the C enum\n\t * and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param mode\n\t *        The MotorBrake to set for the motor\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD, 1);\n\t *   std::cout << \"Brake Mode: \" << mg.get_brake_mode();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index = 0) const;\n\t/**\n\t * Sets one of MotorBrake all the motors in the motor group. Works with the C enum\n\t * and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param mode\n\t *        The MotorBrake to set for the motor\n\t *\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_brake_mode_all(pros::MotorBrake:brake);\n\t *   std::cout << \"Brake Mode: \" << mg.get_brake_mode();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_brake_mode_all(const MotorBrake mode) const;\n\t/**\n\t * Sets one of MotorBrake to a motor in the motor group. Works with the C enum\n\t * and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param mode\n\t *        The MotorBrake to set for the motor\n\t *\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_brake_mode_all(pros::E_MOTOR_BRAKE_HOLD);\n\t *   std::cout << \"Brake Mode: \" << mg.get_brake_mode();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const;\n\t/**\n\t * Sets the current limit for one motor in the motor group in mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param limit\n\t *        The new current limit in mA\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *\n\t * mg.set_current_limit(1000);\n\t * while (true) {\n\t *   mg = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *   // The motor will reduce its output at 1000 mA instead of the default 2500 mA\n\t *   pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_current_limit(const std::int32_t limit, const std::uint8_t index = 0) const;\n\t/**\n\t * Sets the current limit for every motor in the motor group in mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group was empty\n\t *\n\t * \\param limit\n\t *        The new current limit in mA\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *\n\t * mg.set_current_limit_all(1000);\n\t * while (true) {\n\t *   mg = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *   // The motor will reduce its output at 1000 mA instead of the default 2500 mA\n\t *   pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_current_limit_all(const std::int32_t limit) const;\n\t/**\n\t * Sets one of MotorUnits for one motor in the motor group's motor encoder. Works with the C\n\t * enum and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param units\n\t *        The new motor encoder units\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_encoder_units(E_MOTOR_ENCODER_DEGREES, 1);\n\t *   std::cout << \"Encoder Units: \" << mg.get_encoder_units();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_encoder_units(const MotorUnits units, const std::uint8_t index = 0) const;\n\t/**\n\t * Sets one of MotorUnits for one motor in the motor group's motor encoder. Works with the C\n\t * enum and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param units\n\t *        The new motor encoder units\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_encoder_units(E_MOTOR_ENCODER_DEGREES, 1);\n\t *   std::cout << \"Encoder Units: \" << mg.get_encoder_units();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index = 0) const;\n\t/**\n\t * Sets one of MotorUnits for every motor in the motor group's motor encoder. Works with the C\n\t * enum and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param units\n\t *        The new motor encoder units\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES);\n\t *   std::cout << \"Encoder Units: \" << mg.get_encoder_units();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_encoder_units_all(const MotorUnits units) const;\n\t/**\n\t * Sets one of MotorUnits for every motor in the motor group's motor encoder. Works with the C\n\t * enum and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param units\n\t *        The new motor encoder units\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES);\n\t *   std::cout << \"Encoder Units: \" << mg.get_encoder_units();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_encoder_units_all(const pros::motor_encoder_units_e_t units) const;\n\n\t/**\n\t * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with\n\t * the C++ enum class and the C enum.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * E2BIG - The size of the vector mismatches the number of motors in the motor group\n\t *\n\t * \\note If there are more motors than gearsets passed in,\n\t * \tonly the first n motors will have their gearsets changed where n is the number of gearsets passed in.\n\t *  If there are more gearsets passed in than motors, then the only the first m gearsets will be used,\n\t *  where m is the number of motors. In either case, errno will be set to E2BIG, but the operation still occurs\n\t *\n\t *\n\t * \\param gearset\n\t *        The new geatset of the motor\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_gearing(pros::MotorGears::blue, 1);\n\t *   std::cout << \"Gearset: \" << mg.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_gearing(std::vector<pros::motor_gearset_e_t> gearsets) const;\n\t/**\n\t * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with\n\t * the C++ enum class and the C enum.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param gearset\n\t *        The new geatset of the motor\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_gearing(E_MOTOR_GEARSET_06, 1);\n\t *   std::cout << \"Gearset: \" << mg.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_gearing(const pros::motor_gearset_e_t gearset, const std::uint8_t index = 0) const;\n\n\t/**\n\t * Sets the gear cartridge (red, green, blue) for each motor in the motor group by taking in a vector of the\n\t * cartridges. Usable with the C++ enum class and the C enum.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * E2BIG - The size of the vector mismatches the number of motors in the motor group\n\t *\n\t * \\note If there are more motors than gearsets passed in,\n\t * \tonly the first n motors will have their gearsets changed where n is the number of gearsets passed in.\n\t *  If there are more gearsets passed in than motors, then the only the first m gearsets will be used,\n\t *  where m is the number of motors. In either case, errno will be set to E2BIG, but the operation still occurs\n\t *\n\t * \\param gearset\n\t *        The a vector containing the new geatsets of the motors\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_gearing(pros::MotorGears::blue, 1);\n\t *   std::cout << \"Gearset: \" << mg.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_gearing(std::vector<MotorGears> gearsets) const;\n\n\t/**\n\t * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with\n\t * the C++ enum class and the C enum.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param gearset\n\t *        The new geatset of the motor\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_gearing(E_MOTOR_GEARSET_06, 1);\n\t *   std::cout << \"Gearset: \" << mg.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_gearing(const MotorGears gearset, const std::uint8_t index = 0) const;\n\t/**\n\t * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with\n\t * the C++ enum class and the C enum.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param gearset\n\t *        The new geatset of the motor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_gearing_all(E_MOTOR_GEARSET_06);\n\t *   std::cout << \"Gearset: \" << mg.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_gearing_all(const MotorGears gearset) const;\n\t/**\n\t * Sets one of the gear cartridge (red, green, blue) for every motor in the motor group. Usable with\n\t * the C++ enum class and the C enum.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param gearset\n\t *        The new geatset of the motor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_gearing_all(E_MOTOR_GEARSET_06);\n\t *   std::cout << \"Gearset: \" << mg.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const;\n\n\t/**\n\t * sets the reversal for a motor in the motor group.\n\t *\n\t * This will invert its movements and the values returned for its position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param reverse\n\t *        True reverses the motor, false is default\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t * \t\t//reverse the motor at index 1 (port 3)\n\t *   mg.set_reversed(true, 1);\n\t *   std::cout << \"Is this motor reversed? \" << motor.is_reversed(1);\n\t * pros::delay(100);\n\t * \t// unreverse the motor at index 1 (port 3)\n\t *   mg.set_reversed(false, 1);\n\t *   std::cout << \"Is this motor reversed? \" << motor.is_reversed(1);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_reversed(const bool reverse, const std::uint8_t index = 0);\n\t/**\n\t * Sets the reversal for all the motors in the motor group.\n\t *\n\t * This will invert its movements and the values returned for its position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param reverse\n\t *        True reverses the motor, false is default\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.set_reversed_all(true);\n\t *   std::cout << \"Is this motor reversed? \" << motor.is_reversed();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_reversed_all(const bool reverse);\n\n\t/**\n\t * Sets the voltage limit for a motor in the motor group in millivolts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param limit\n\t *        The new voltage limit in Volts\n\t *\n\t * \t\\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *\n\t *   mg.set_voltage_limit(10000, 1);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     // The motor on at index 1 (port 3) will not output more than 10 V\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_voltage_limit(const std::int32_t limit, const std::uint8_t index = 0) const;\n\n\t/**\n\t * Sets the voltage limit for every motor in the motor group in millivolts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param limit\n\t *        The new voltage limit in Volts\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *\n\t *   mg.set_voltage_limit_all(10000);\n\t *   while (true) {\n\t *     mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     // The motor will not output more than 10 V\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_voltage_limit_all(const std::int32_t limit) const;\n\n\t/**\n\t * Sets the position for a motor in the motor group in its encoder units.\n\t *\n\t * This will be the future reference point for the motor's \"absolute\"\n\t * position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param position\n\t *        The new reference position in its encoder units\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t  The zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.move_absolute(100, 100); // Moves 100 units forward\n\t *   mg.move_absolute(100, 100); // This does not cause a movement\n\t *   mg.set_zero_position(80);\n\t *   mg.set_zero_position(80, 1);\n\t *   mg.move_absolute(100, 100); // Moves 20 units forward\n\t * }\n\t * \\endcode\n\t *\n\t */\n\tstd::int32_t set_zero_position(const double position, const std::uint8_t index = 0) const;\n\t/**\n\t * Sets the position for every motor in the motor group in its encoder units.\n\t *\n\t * This will be the future reference point for the motor's \"absolute\"\n\t * position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t *\n\t * \\param position\n\t *        The new reference position in its encoder units\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.move_absolute(100, 100); // Moves 100 units forward\n\t *   mg.move_absolute(100, 100); // This does not cause a movement\n\t *\n\t *   mg.set_zero_position_all(80);\n\t *   mg.move_absolute(100, 100); // Moves 20 units forward\n\t * }\n\t * \\endcode\n\t *\n\t */\n\tstd::int32_t set_zero_position_all(const double position) const;\n\n\t/**\n\t * Sets the \"absolute\" zero position of a motor in the motor group to its current position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EDOM - The motor group is empty\n\t * EOVERFLOW - The index is greater than or equal to MotorGroup::size()\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.move_absolute(100, 100); // Moves 100 units forward\n\t *   mg.move_absolute(100, 100); // This does not cause a movement\n\t *\n\t *   mg.tare_position();\n\t *   mg.tare_position(1);\n\t *\n\t *   mg.move_absolute(100, 100); // Moves 100 units forward\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t tare_position(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Sets the \"absolute\" zero position of every motor in the motor group to its current position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::MotorGroup mg({1,3});\n\t *   mg.move_absolute(100, 100); // Moves 100 units forward\n\t *   mg.move_absolute(100, 100); // This does not cause a movement\n\t *   mg.tare_position_all();\n\t *   mg.move_absolute(100, 100); // Moves 100 units forward\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t tare_position_all(void) const;\n\n\t/**\n\t * Returns the number of motors in the motor group\n\t *\n\t * \\return the number of motors in the motor group\n\t */\n\tstd::int8_t size(void) const;\n\n\t/**\n\t * Gets the port of a motor in the motor group via index\n\t *\n\t * \\param index Optional parameter, 0 by default.\n\t * \t\t\t\tThe zero indexed index of the motor in the motor group\n\t *\n\t * \\return The port of the motor at the specified index.\n\t * The return value is negative if the corresponding motor is reversed\n\t */\n\tstd::int8_t get_port(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Appends all the motors in the other motor group reference to this motor group\n\t *\n\t * Maintains the order of the other motor group\n\t *\n\t */\n\tvoid operator+=(AbstractMotor&);\n\n\t/**\n\t * Appends all the motors in the other motor group reference to this motor group\n\t *\n\t * Maintains the order of the other motor group\n\t *\n\t */\n\tvoid append(AbstractMotor&);\n\n\t/**\n\t * Removes the all motors on the port (regardless of reversal) from the motor group\n\t *\n\t * \\param port The port to remove from the motor group\n\t *\n\t */\n\tvoid erase_port(std::int8_t port);\n\n\t///@}\n\tprivate:\n\t/**\n\t * The ordered vector of ports used by the motor group\n\t */\n\tstd::vector<std::int8_t> _ports;\n\tmutable pros::Mutex _MotorGroup_mutex;\n};\n}  // namespace v5\n}  // namespace pros\n#endif"
  },
  {
    "path": "include/pros/motors.h",
    "content": "/**\n * \\file pros/motors.h\n * \\ingroup c-motors\n *\n * Contains prototypes for the V5 Motor-related functions.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup c-motors Motors C API\n * \\note Additional example code for this module can be found in its [Tutorial](@ref motors).\n */\n\n#ifndef _PROS_MOTORS_H_\n#define _PROS_MOTORS_H_\n\n#include <stdbool.h>\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\nnamespace c {\n#endif\n\n/**\n * \\ingroup c-motors\n */\n\n/**\n * \\addtogroup c-motors\n *  @{\n */\n\n/// \\name Motor movement functions\n/// These functions allow programmers to make motors move\n///@{\n\n/**\n * Sets the voltage for the motor from -127 to 127.\n *\n * This is designed to map easily to the input from the controller's analog\n * stick for simple opcontrol use. The actual behavior of the motor is analogous\n * to use of motor_move_voltage().\n *\n * \\note This function will not respect brake modes, and simply sets the voltage to the desired value.\n * \n * \\note A negative port will negate the input voltage\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param voltage\n *        The new motor voltage from -127 to 127\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_move(int8_t port, int32_t voltage);\n\n/**\n * Stops the motor using the currently configured brake mode.\n * \n * This function sets motor velocity to zero, which will cause it to act\n * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD,\n * this function may behave differently than calling motor_move_absolute(port, 0)\n * or motor_move_relative(port, 0).\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n * \n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code \n * \tvoid autonomous() {\n * \t\tmotor_move(1, 127);\n * \t\tdelay(1000);\n * \t\tmotor_break(1);\n * }\n * \\endcode\n */\nint32_t motor_brake(int8_t port);\n\n/**\n * Sets the target absolute position for the motor to move to.\n *\n * This movement is relative to the position of the motor when initialized or\n * the position when it was most recently reset with motor_set_zero_position().\n *\n * \\note This function simply sets the target for the motor, it does not block program\n * execution until the movement finishes. The example code shows how to block until a movement is finished.\n *\n * \\note A negative port number will negate the target position \n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param position\n *        The absolute position to move to in the motor's encoder units\n * \\param velocity\n *        The maximum allowable velocity for the movement in RPM\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void autonomous() {\n *   motor_move_absolute(1, 100, 100); // Moves 100 units forward\n *   while (!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) {\n *     // Continue running this loop as long as the motor is not within +-5 units of its goal\n *     delay(2);\n *   }\n *   motor_move_absolute(1, 100, 100); // This will not cause a movement\n *   while(!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) {\n *     delay(2);\n *   }\n * \n *   motor_tare_position(1);\n *   motor_move_absolute(1, 100, 100); // Moves 100 units forward\n *   while (!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) {\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_move_absolute(int8_t port, double position, const int32_t velocity);\n\n/**\n * Sets the relative target position for the motor to move to.\n *\n * This movement is relative to the current position of the motor as given in\n * motor_get_position(). Providing 10.0 as the position parameter would result\n * in the motor moving clockwise 10 units, no matter what the current position\n * is.\n *\n * \\note This function simply sets the target for the motor, it does not block\n * program execution until the movement finishes. The example code shows how to\n * block until a movement is finished.\n *\n * \\note A negative port will negate the target position\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param position\n *        The relative position to move to in the motor's encoder units\n * \\param velocity\n *        The maximum allowable velocity for the movement in RPM\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void autonomous() {\n *   motor_move_relative(1, 100, 100); // Moves 100 units forward\n *   while (!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) {\n *     // Continue running this loop as long as the motor is not within +-5 units of its goal\n *     delay(2);\n *   }\n * \n *   motor_move_relative(1, 100, 100); // Also moves 100 units forward\n *   while (!((motor_get_position(1) < 205) && (motor_get_position(1) > 195))) {\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_move_relative(int8_t port, double position, const int32_t velocity);\n\n/**\n * Sets the velocity for the motor.\n *\n * This velocity corresponds to different actual speeds depending on the gearset\n * used for the motor. This results in a range of +-100 for E_MOTOR_GEARSET_36,\n * +-200 for E_MOTOR_GEARSET_18, and +-600 for E_MOTOR_GEARSET_6. The velocity\n * is held with PID to ensure consistent speed, as opposed to setting the\n * motor's voltage.\n *\n * \\note A negative port will negate the velocity\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param velocity\n *        The new motor velocity from +-100, +-200, or +-600 depending on the\n *        motor's gearset\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void autonomous() {\n *   motor_move_velocity(1, 100);\n *   delay(1000); // Move at 100 RPM for 1 second\n *   motor_move_velocity(1, 0);\n * }\n * \\endcode\n */\nint32_t motor_move_velocity(int8_t port, const int32_t velocity);\n\n/**\n * Sets the output voltage for the motor from -12000 to 12000 in millivolts.\n *\n * \\note A negative port negates the voltage\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n * \n * \\note This function will not respect brake modes, and simply sets the\n * voltage to the desired value.\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param voltage\n *        The new voltage value from -12000 to 12000\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void autonomous() {\n *   motor_move_voltage(1, 12000);\n *   delay(1000); // Move at max voltage for 1 second\n *   motor_move_voltage(1, 0);\n * }\n * \\endcode\n */\nint32_t motor_move_voltage(int8_t port, const int32_t voltage);\n\n/**\n * Changes the output velocity for a profiled movement (motor_move_absolute or\n * motor_move_relative). This will have no effect if the motor is not following\n * a profiled movement.\n *\n * \\note A negative port negates the velocity\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param velocity\n *        The new motor velocity from +-100, +-200, or +-600 depending on the\n *        motor's gearset\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void autonomous() {\n *   motor_move_absolute(1, 100, 100);\n *   delay(100);\n *   motor_modify_profiled_velocity(1, 0); // Stop the motor early\n * }\n * \\endcode\n */\nint32_t motor_modify_profiled_velocity(int8_t port, const int32_t velocity);\n\n/**\n * Gets the target position set for the motor by the user.\n *\n * \\note A negative port negates the return value\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The target position in its encoder units or PROS_ERR_F if the\n * operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * void autonomous() {\n *   motor_move_absolute(1, 100, 100);\n *   printf(\"Motor Target: %d\\n\", motor_get_target_position(1));\n *   // Prints 100\n * }\n * \\endcode\n */\ndouble motor_get_target_position(int8_t port);\n\n/**\n * Gets the velocity commanded to the motor by the user.\n *\n * \\note A negative port negates the return value\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The commanded motor velocity from +-100, +-200, or +-600, or PROS_ERR\n * if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move_velocity(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Commanded Velocity: %d\\n\", motor_get_target_velocity(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_get_target_velocity(int8_t port);\n\n///@}\n\n/// \\name Motor telemetry functions\n/// These functions allow programmers to collect telemetry from motors\n///@{\n\n/**\n * Gets the actual velocity of the motor.\n *\n * \\note A negative port negates the return value \n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The motor's actual velocity in RPM or PROS_ERR_F if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Actual velocity: %lf\\n\", motor_get_actual_velocity(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\ndouble motor_get_actual_velocity(int8_t port);\n\n/**\n * Gets the current drawn by the motor in mA.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The motor's current in mA or PROS_ERR if the operation failed,\n * setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Current Draw: %d\\n\", motor_get_current_draw(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_get_current_draw(int8_t port);\n\n/**\n * Gets the direction of movement for the motor.\n *\n * \\note A negative port number negates the return value. \n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return 1 for moving in the positive direction, -1 for moving in the\n * negative direction, or PROS_ERR if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Direction: %d\\n\", motor_get_direction(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_get_direction(int8_t port);\n\n/**\n * Gets the efficiency of the motor in percent.\n *\n * An efficiency of 100% means that the motor is moving electrically while\n * drawing no electrical power, and an efficiency of 0% means that the motor\n * is drawing power but not moving.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The motor's efficiency in percent or PROS_ERR_F if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Efficiency: %d\\n\", motor_get_efficiency(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\ndouble motor_get_efficiency(int8_t port);\n\n/**\n * Checks if the motor is drawing over its current limit.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return 1 if the motor's current limit is being exceeded and 0 if the current\n * limit is not exceeded, or PROS_ERR if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Current Limit Hit?: %d\\n\", motor_is_over_current(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_is_over_current(int8_t port);\n\n/**\n * Checks if the motor's temperature is above its limit.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return 1 if the temperature limit is exceeded and 0 if the the temperature\n * is below the limit, or PROS_ERR if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Temp Limit: %d\\n\", motor_is_over_temp(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_is_over_temp(int8_t port);\n\n\n\n#ifdef __cplusplus\n}  // namespace c\n#endif\n\n/**\n * \\enum motor_fault_e_t\n */\ntypedef enum motor_fault_e {\n\t/// No faults\n\tE_MOTOR_FAULT_NO_FAULTS = 0x00,\n\t/// Analogous to motor_is_over_temp()\n\tE_MOTOR_FAULT_MOTOR_OVER_TEMP = 0x01,\n\t/// Indicates a motor h-bridge fault\n\tE_MOTOR_FAULT_DRIVER_FAULT = 0x02,\n\t/// Analogous to motor_is_over_current()\n\tE_MOTOR_FAULT_OVER_CURRENT = 0x04,\n\t/// Indicates an h-bridge over current\n\tE_MOTOR_FAULT_DRV_OVER_CURRENT = 0x08\n} motor_fault_e_t;\n\n#ifdef PROS_USE_SIMPLE_NAMES\n#ifdef __cplusplus\n#define MOTOR_FAULT_NO_FAULTS pros::E_MOTOR_FAULT_NO_FAULTS\n#define MOTOR_FAULT_MOTOR_OVER_TEMP pros::E_MOTOR_FAULT_MOTOR_OVER_TEMP\n#define MOTOR_FAULT_DRIVER_FAULT pros::E_MOTOR_FAULT_DRIVER_FAULT\n#define MOTOR_FAULT_OVER_CURRENT pros::E_MOTOR_FAULT_DRV_OVER_CURRENT\n#define MOTOR_FAULT_DRV_OVER_CURRENT pros::E_MOTOR_FAULT_DRV_OVER_CURRENT\n#else\n#define MOTOR_FAULT_NO_FAULTS E_MOTOR_FAULT_NO_FAULTS\n#define MOTOR_FAULT_MOTOR_OVER_TEMP E_MOTOR_FAULT_MOTOR_OVER_TEMP\n#define MOTOR_FAULT_DRIVER_FAULT E_MOTOR_FAULT_DRIVER_FAULT\n#define MOTOR_FAULT_OVER_CURRENT E_MOTOR_FAULT_DRV_OVER_CURRENT\n#define MOTOR_FAULT_DRV_OVER_CURRENT E_MOTOR_FAULT_DRV_OVER_CURRENT\n#endif\n#endif\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n/**\n * Gets the faults experienced by the motor.\n *\n * Compare this bitfield to the bitmasks in motor_fault_e_t.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return A bitfield containing the motor's faults.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Faults: %d\\n\", motor_get_faults(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nuint32_t motor_get_faults(int8_t port);\n\n#ifdef __cplusplus\n}  // namespace c\n#endif\n\n/**\n * \\enum motor_flag_e_t\n * \n */\ntypedef enum motor_flag_e {\n\t///There are no flags raised\n\tE_MOTOR_FLAGS_NONE = 0x00,\n\t/// Cannot currently communicate to the motor\n\tE_MOTOR_FLAGS_BUSY = 0x01,\n\t/// Analogous to motor_is_stopped()\n\tE_MOTOR_FLAGS_ZERO_VELOCITY = 0x02,\n\t/// Analogous to motor_get_zero_position_flag()\n\tE_MOTOR_FLAGS_ZERO_POSITION = 0x04\n} motor_flag_e_t;\n\n#ifdef PROS_USE_SIMPLE_NAMES\n#ifdef __cplusplus\n#define MOTOR_FLAGS_NONE pros::E_MOTOR_FLAGS_NONE\n#define MOTOR_FLAGS_BUSY pros::E_MOTOR_FLAGS_BUSY\n#define MOTOR_FLAGS_ZERO_VELOCITY pros::E_MOTOR_FLAGS_ZERO_VELOCITY\n#define MOTOR_FLAGS_ZERO_POSITION pros::E_MOTOR_FLAGS_ZERO_POSITION\n#else\n#define MOTOR_FLAGS_NONE E_MOTOR_FLAGS_NONE\n#define MOTOR_FLAGS_BUSY E_MOTOR_FLAGS_BUSY\n#define MOTOR_FLAGS_ZERO_VELOCITY E_MOTOR_FLAGS_ZERO_VELOCITY\n#define MOTOR_FLAGS_ZERO_POSITION E_MOTOR_FLAGS_ZERO_POSITION\n#endif\n#endif\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n/**\n * Gets the flags set by the motor's operation.\n *\n * Compare this bitfield to the bitmasks in motor_flag_e_t.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return A bitfield containing the motor's flags.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Flags: %d\\n\", motor_get_flags(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nuint32_t motor_get_flags(int8_t port);\n\n/**\n * Gets the raw encoder count of the motor at a given timestamp.\n *\n * \\note A negative port value negates the return value\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param[in] timestamp\n *            A pointer to a time in milliseconds for which the encoder count\n *            will be returned. If NULL, the timestamp at which the encoder\n *            count was read will not be supplied\n *\n * \\return The raw encoder count at the given timestamp or PROS_ERR if the\n * operation failed.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   uint32_t now = millis();\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Encoder Count: %d\\n\", motor_get_raw_position(1, &now));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_get_raw_position(int8_t port, uint32_t* const timestamp);\n\n/**\n * Gets the absolute position of the motor in its encoder units.\n *\n * \\note A negative port value negates the return value\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The motor's absolute position in its encoder units or PROS_ERR_F\n * if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Position: %lf\\n\", motor_get_position(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\ndouble motor_get_position(int8_t port);\n\n/**\n * Gets the power drawn by the motor in Watts.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The motor's power draw in Watts or PROS_ERR_F if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   uint32_t now = millis();\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Power: %lf\\n\", motor_get_power(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\ndouble motor_get_power(int8_t port);\n\n/**\n * Gets the temperature of the motor in degrees Celsius.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The motor's temperature in degrees Celsius or PROS_ERR_F if the\n * operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Temperature: %lf\\n\", motor_get_temperature(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\ndouble motor_get_temperature(int8_t port);\n\n/**\n * Gets the torque generated by the motor in Newton Meters (Nm).\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The motor's torque in Nm or PROS_ERR_F if the operation failed,\n * setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Torque: %lf\\n\", motor_get_torque(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\ndouble motor_get_torque(int8_t port);\n\n/**\n * Gets the voltage delivered to the motor in millivolts.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The motor's voltage in mV or PROS_ERR_F if the operation failed,\n * setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     printf(\"Motor Voltage: %lf\\n\", motor_get_voltage(1));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_get_voltage(int8_t port);\n\n///@}\n\n/// \\name Motor configuration functions\n/// These functions allow programmers to configure the behavior of motors\n///@{\n\n#ifdef __cplusplus\n}  // namespace c\n#endif\n\n/**\n * \\enum motor_brake_mode_e_t\n * Indicates the current 'brake mode' of a motor.\n */\ntypedef enum motor_brake_mode_e {\n\t/// Motor coasts when stopped, traditional behavior\n\tE_MOTOR_BRAKE_COAST = 0,\n\t/// Motor brakes when stopped\n\tE_MOTOR_BRAKE_BRAKE = 1,\n\t/// Motor actively holds position when stopped\n\tE_MOTOR_BRAKE_HOLD = 2,\n\t/// Invalid brake mode\n\tE_MOTOR_BRAKE_INVALID = INT32_MAX\n} motor_brake_mode_e_t;\n\n/**\n * \\enum motor_encoder_units_e_t\n * Indicates the units used by the motor encoders.\n */\ntypedef enum motor_encoder_units_e {\n\t/// Position is recorded as angle in degrees as a floating point number\n\tE_MOTOR_ENCODER_DEGREES = 0,\n\t/// Position is recorded as angle in rotations as a floating point number\n\tE_MOTOR_ENCODER_ROTATIONS = 1,\n\t/// Position is recorded as raw encoder ticks as a whole number\n\tE_MOTOR_ENCODER_COUNTS = 2,     \n\t///Invalid motor encoder units\n\tE_MOTOR_ENCODER_INVALID = INT32_MAX\n} motor_encoder_units_e_t;\n\n/**\n * \\enum motor_gearset_e_t\n * Indicates the current internal gear ratio of a motor.\n */\ntypedef enum motor_gearset_e {\n\tE_MOTOR_GEARSET_36 = 0,  // 36:1, 100 RPM, Red gear set\n\tE_MOTOR_GEAR_RED = E_MOTOR_GEARSET_36, // 36:1, 100 RPM, Red gear set\n\tE_MOTOR_GEAR_100 = E_MOTOR_GEARSET_36, // 36:1, 100 RPM, Red gear set\n\tE_MOTOR_GEARSET_18 = 1,  // 18:1, 200 RPM, Green gear set\n\tE_MOTOR_GEAR_GREEN = E_MOTOR_GEARSET_18, // 18:1, 200 RPM, Green gear set\n\tE_MOTOR_GEAR_200 = E_MOTOR_GEARSET_18, // 18:1, 200 RPM, Green gear set\n\tE_MOTOR_GEARSET_06 = 2,  // 6:1, 600 RPM, Blue gear set\n\tE_MOTOR_GEAR_BLUE  = E_MOTOR_GEARSET_06, // 6:1, 600 RPM, Blue gear set\n\tE_MOTOR_GEAR_600 = E_MOTOR_GEARSET_06, // 6:1, 600 RPM, Blue gear set\n\tE_MOTOR_GEARSET_INVALID = INT32_MAX, // Error: Invalid Gearset\n} motor_gearset_e_t;\n\n/**\n * \\enum motor_type_e_t\n * Indicates the type of a motor\n */\ntypedef enum motor_type_e {\n\tE_MOTOR_TYPE_V5 = 0, // 11 watt V5 motor\n\tE_MOTOR_TYPE_EXP = 1, // 5.5 watt EXP motor\n\tE_MOTOR_TYPE_INVALID = INT32_MAX, // Error: invalid type\n} motor_type_e_t;\n\n#ifdef PROS_USE_SIMPLE_NAMES\n#ifdef __cplusplus\n#define MOTOR_BRAKE_COAST pros::E_MOTOR_BRAKE_COAST\n#define MOTOR_BRAKE_BRAKE pros::E_MOTOR_BRAKE_BRAKE\n#define MOTOR_BRAKE_HOLD pros::E_MOTOR_BRAKE_HOLD\n#define MOTOR_BRAKE_INVALID pros::E_MOTOR_BRAKE_INVALID\n#define MOTOR_ENCODER_DEGREES pros::E_MOTOR_ENCODER_DEGREES\n#define MOTOR_ENCODER_ROTATIONS pros::E_MOTOR_ENCODER_ROTATIONS\n#define MOTOR_ENCODER_COUNTS pros::E_MOTOR_ENCODER_COUNTS\n#define MOTOR_ENCODER_INVALID pros::E_MOTOR_ENCODER_INVALID\n#define MOTOR_GEARSET_36 pros::E_MOTOR_GEARSET_36\n#define MOTOR_GEAR_RED pros::E_MOTOR_GEAR_RED\n#define MOTOR_GEAR_100 pros::E_MOTOR_GEAR_100\n#define MOTOR_GEARSET_18 pros::E_MOTOR_GEARSET_18\n#define MOTOR_GEAR_GREEN pros::E_MOTOR_GEAR_GREEN\n#define MOTOR_GEAR_200 pros::E_MOTOR_GEAR_200\n#define MOTOR_GEARSET_06 pros::E_MOTOR_GEARSET_06\n#define MOTOR_GEARSET_6 pros::E_MOTOR_GEARSET_06\n#define MOTOR_GEAR_BLUE pros::E_MOTOR_GEAR_BLUE\n#define MOTOR_GEAR_600 pros::E_MOTOR_GEAR_600\n#define MOTOR_GEARSET_INVALID pros::E_MOTOR_GEARSET_INVALID\n#define MOTOR_TYPE_V5 pros::E_MOTOR_TYPE_V5\n#define MOTOR_TYPE_EXP pros::E_MOTOR_TYPE_EXP\n#define MOTOR_TYPE_INVALID pros::E_MOTOR_TYPE_INVALID\n#else\n#define MOTOR_BRAKE_COAST E_MOTOR_BRAKE_COAST\n#define MOTOR_BRAKE_BRAKE E_MOTOR_BRAKE_BRAKE\n#define MOTOR_BRAKE_HOLD E_MOTOR_BRAKE_HOLD\n#define MOTOR_BRAKE_INVALID E_MOTOR_BRAKE_INVALID\n#define MOTOR_ENCODER_DEGREES E_MOTOR_ENCODER_DEGREES\n#define MOTOR_ENCODER_ROTATIONS E_MOTOR_ENCODER_ROTATIONS\n#define MOTOR_ENCODER_COUNTS E_MOTOR_ENCODER_COUNTS\n#define MOTOR_ENCODER_INVALID E_MOTOR_ENCODER_INVALID\n#define MOTOR_GEARSET_36 E_MOTOR_GEARSET_36\n#define MOTOR_GEAR_RED E_MOTOR_GEAR_RED\n#define MOTOR_GEAR_100 E_MOTOR_GEAR_100\n#define MOTOR_GEARSET_18 E_MOTOR_GEARSET_18\n#define MOTOR_GEAR_GREEN E_MOTOR_GEAR_GREEN\n#define MOTOR_GEAR_200 E_MOTOR_GEAR_200\n#define MOTOR_GEARSET_06 E_MOTOR_GEARSET_06\n#define MOTOR_GEARSET_6 E_MOTOR_GEARSET_06\n#define MOTOR_GEAR_BLUE E_MOTOR_GEAR_BLUE\n#define MOTOR_GEAR_600 E_MOTOR_GEAR_600\n#define MOTOR_GEARSET_INVALID E_MOTOR_GEARSET_INVALID\n#define MOTOR_TYPE_V5 E_MOTOR_TYPE_V5\n#define MOTOR_TYPE_EXP E_MOTOR_TYPE_EXP\n#define MOTOR_TYPE_INVALID E_MOTOR_TYPE_INVALID\n#endif\n#endif\n\n/**\n * \\struct motor_pid_full_s_t\n * \n * Holds the information about a Motor's position or velocity PID controls.\n *\n * These values are in 4.4 format, meaning that a value of 0x20 represents 2.0,\n * 0x21 represents 2.0625, 0x22 represents 2.125, etc.\n */\ntypedef struct motor_pid_full_s {\n\t/// The feedforward constant\n\tuint8_t kf;\n\t/// The proportional constant\n\tuint8_t kp;\n\t/// The integral constants\n\tuint8_t ki;\n\t/// The derivative constant\n\tuint8_t kd;\n\t/// A constant used for filtering the profile acceleration         \n\tuint8_t filter;\n\t/// The integral limit\n\tuint16_t limit;\n\t/// The threshold for determining if a position movement hasreached its goa l. This has no effect for velocity PID calculations.\n\tuint8_t threshold;\n\t/// The rate at which the PID computation is run in ms\n\tuint8_t loopspeed;\n} motor_pid_full_s_t;\n\n/**\n * \\struct motor_pid_s_t\n * \n * Holds just the constants for a Motor's position or velocity PID controls.\n *\n * These values are in 4.4 format, meaning that a value of 0x20 represents 2.0,\n * 0x21 represents 2.0625, 0x22 represents 2.125, etc.\n */\ntypedef struct motor_pid_s {\n\t/// The feedforward constant\n\tuint8_t kf;\n\t/// The proportional constant\n\tuint8_t kp;\n\t/// The integral constants\n\tuint8_t ki;\n\t/// The derivative constant\n\tuint8_t kd;\n} motor_pid_s_t;\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n/**\n * Sets the position for the motor in its encoder units.\n *\n * This will be the future reference point for the motor's \"absolute\" position.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param position\n *        The new reference position in its encoder units\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \n * \\code\n * void autonomous() {\n *   motor_move_absolute(1, 100, 100); // Moves 100 units forward\n *   while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) {\n *     // Continue running this loop as long as the motor is not within +-5 units of its goal\n *     delay(2);\n *   }\n *   motor_move_absolute(1, 100, 100); // This does not cause a movement\n *   while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) {\n *     delay(2);\n *   }\n * \n *   motor_set_zero_position(1, 80);\n *   motor_move_absolute(1, 100, 100); // Moves 20 units forward\n *   while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) {\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_set_zero_position(int8_t port, const double position);\n\n/**\n * Sets the \"absolute\" zero position of the motor to its current position.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void autonomous() {\n *   motor_move_absolute(1, 100, 100); // Moves 100 units forward\n *   while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) {\n *     // Continue running this loop as long as the motor is not within +-5 units of its goal\n *     delay(2);\n *   }\n *   motor_move_absolute(1, 100, 100); // This does not cause a movement\n *   while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) {\n *     delay(2);\n *   }\n * \n *   motor_tare_position(1);\n *   motor_move_absolute(1, 100, 100); // Moves 100 units forward\n *   while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) {\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_tare_position(int8_t port);\n\n/**\n * Sets one of motor_brake_mode_e_t to the motor.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param mode\n *        The motor_brake_mode_e_t to set for the motor\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void initialize() {\n *   motor_set_brake_mode(1, E_MOTOR_BRAKE_HOLD);\n *   printf(\"Brake Mode: %d\\n\", motor_get_brake_mode(1));\n * }\n * \\endcode\n */\nint32_t motor_set_brake_mode(int8_t port, const motor_brake_mode_e_t mode);\n\n/**\n * Sets the current limit for the motor in mA.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param limit\n *        The new current limit in mA\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   motor_set_current_limit(1, 1000);\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     // The motor will reduce its output at 1000 mA instead of the default 2500 mA\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_set_current_limit(int8_t port, const int32_t limit);\n\n/**\n * Sets one of motor_encoder_units_e_t for the motor encoder.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param units\n *        The new motor encoder units\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   motor_set_encoder_units(1, E_MOTOR_ENCODER_DEGREES);\n *   printf(\"Encoder Units: %d\\n\", motor_get_encoder_units(1));\n * }\n * \\endcode\n */\nint32_t motor_set_encoder_units(int8_t port, const motor_encoder_units_e_t units);\n\n/**\n * Sets one of motor_gearset_e_t for the motor.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param gearset\n *        The new motor gearset\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void initialize() {\n *   motor_set_gearing(1, E_MOTOR_GEARSET_06);\n *   printf(\"Brake Mode: %d\\n\", motor_get_gearing(1));\n * }\n * \\endcode\n */\nint32_t motor_set_gearing(int8_t port, const motor_gearset_e_t gearset);\n\n/**\n * Sets the voltage limit for the motor in Volts.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n * \\param limit\n *        The new voltage limit in Volts\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * void autonomous() {\n *   motor_set_voltage_limit(1, 10000);\n *   while (true) {\n *     motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));\n *     // The motor will not output more than 10 V\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t motor_set_voltage_limit(int8_t port, const int32_t limit);\n\n/**\n * Gets the brake mode that was set for the motor.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return One of motor_brake_mode_e_t, according to what was set for the motor,\n * or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * void initialize() {\n *   motor_set_brake_mode(1, E_MOTOR_BRAKE_HOLD);\n *   printf(\"Brake Mode: %d\\n\", motor_get_brake_mode(1));\n * }\n * \\endcode\n */\nmotor_brake_mode_e_t motor_get_brake_mode(int8_t port);\n\n/**\n * Gets the current limit for the motor in mA.\n *\n * The default value is 2500 mA.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The motor's current limit in mA or PROS_ERR if the operation failed,\n * setting errno.\n * \n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Motor Current Limit: %d\\n\", motor_get_current_limit(1));\n *   // Prints \"Motor Current Limit: 2500\"\n * }\n * \\endcode\n */\nint32_t motor_get_current_limit(int8_t port);\n\n/**\n * Gets the encoder units that were set for the motor.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return One of motor_encoder_units_e_t according to what is set for the motor\n * or E_MOTOR_ENCODER_INVALID if the operation failed.\n */\nmotor_encoder_units_e_t motor_get_encoder_units(int8_t port);\n\n/**\n * Gets the gearset that was set for the motor.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return One of motor_gearset_e_t according to what is set for the motor,\n * or E_GEARSET_INVALID if the operation failed.\n * \n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Motor Encoder Units: %d\\n\", motor_get_encoder_units(1));\n *   // Prints E_MOTOR_ENCODER_DEGREES by default\n * }\n * \\endcode\n */\nmotor_gearset_e_t motor_get_gearing(int8_t port);\n\n/**\n * Gets the voltage limit set by the user.\n *\n * Default value is 0V, which means that there is no software limitation imposed\n * on the voltage.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|.\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return The motor's voltage limit in V or PROS_ERR if the operation failed,\n * setting errno.\n * \n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Motor Voltage Limit: %d\\n\", motor_get_voltage_limit(1));\n *   // Prints 0 by default, indicating no limit\n * }\n * \\endcode\n */\nint32_t motor_get_voltage_limit(int8_t port);\n\n/**\n * Get the type of the motor\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports |1-21|\n * ENODEV - The port cannot be configured as a motor\n *\n * \\param port\n *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors\n *\n * \\return One of motor_type_e_t according to the type of the motor, or\n * E_MOTOR_TYPE_INVALID if the operation failed.\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   printf(\"Motor Type: %d\\n\", motor_get_type(1));\n *   // Prints the type of the motor\n * }\n * \\endcode\n */\nmotor_type_e_t motor_get_type(int8_t port);\n\n///@}\n\n///@}\n\n#ifdef __cplusplus\n}  // namespace c\n}  // namespace pros\n}\n#endif\n\n#endif  // _PROS_MOTORS_H_\n"
  },
  {
    "path": "include/pros/motors.hpp",
    "content": "/**\n * \\file pros/motors.hpp\n * \\ingroup cpp-motors\n *\n * Contains prototypes for the V5 Motor-related functions.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-motors Motors C++ API\n * \\note Additional example code for this module can be found in its [Tutorial](@ref motors).\n */\n\n#ifndef _PROS_MOTORS_HPP_\n#define _PROS_MOTORS_HPP_\n\n#include <cstdint>\n#include <iostream>\n\n#include \"pros/abstract_motor.hpp\"\n#include \"pros/device.hpp\"\n#include \"pros/motors.h\"\n#include \"rtos.hpp\"\n\nnamespace pros {\ninline namespace v5 {\n\nclass Motor : public AbstractMotor, public Device {\n\tpublic:\n\t/**\n\t * \\addtogroup cpp-motors\n\t *  @{\n\t */\n\n\t/**\n\t * Constructs a new Motor object.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports |1-21|.\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param port\n\t *        The V5 port number from 1 to 21, or from -21 to -1 for reversed motors.\n\t * \t\t  A reversed motor will reverse the input or output movement functions and movement related\n\t * \t\t  telemetry in order to produce consistant behavior with non-reversed motors\n\t *\n\t * \\param gearset = pros::v5::MotorGears::green\n\t * \t\t  Optional parameter for the gearset for the motor.\n\t * \t\t  Does not explicitly set the gearset if not specified or if the gearset is invalid\n\t *\n\t * \\param encoder_units = pros::v5::MotorUnits::degrees\n\t * \t\t  Optional parameter for the encoder units of the motor\n\t * \t\t  Does not explicitly set the gearset if not specified or if the gearset is invalid\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \tMotor first_motor(1); //Creates a motor on port 1 without altering gearset or encoder units\n\t *  Motor reversed_motor(-2); //Creates a reversed motor on port 1 port 1 without altering gearset or encoder units\n\t *  Motor blue_motor(3, pros::v5::MotorGears::blue); //Creates a motor on port 3 with blue gear set\n\t *  Motor rotations_motor(4, pros::v5::MotorGears::green, pros::v5::MotorUnits::rotations); //port 4 w/ rotations\n\t *\n\t * }\n\t * \\endcode\n\t *\n\t */\n\tMotor(const std::int8_t port, const pros::v5::MotorGears gearset = pros::v5::MotorGears::invalid,\n\t      const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::invalid);\n\n\tMotor(const Device& device) : Motor(device.get_port()){};\n\n\t/// \\name Motor movement functions\n\t/// These functions allow programmers to make motors move\n\t///@{\n\n\t/**\n\t * Sets the voltage for the motor from -127 to 127.\n\t *\n\t * This is designed to map easily to the input from the controller's analog\n\t * stick for simple opcontrol use. The actual behavior of the motor is\n\t * analogous to use of motor_move().\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param voltage\n\t *        The new motor voltage from -127 to 127\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor Motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor.move(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t move(std::int32_t voltage) const;\n\n\t/**\n\t * Sets the target absolute position for the motor to move to.\n\t *\n\t * This movement is relative to the position of the motor when initialized or\n\t * the position when it was most recently reset with\n\t * pros::Motor::set_zero_position().\n\t *\n\t * \\note This function simply sets the target for the motor, it does not block\n\t * program execution until the movement finishes.\n\t *\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param position\n\t *        The absolute position to move to in the motor's encoder units\n\t * \\param velocity\n\t *        The maximum allowable velocity for the movement in RPM\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::Motor motor (1);\n\t *   motor.move_absolute(100, 100); // Moves 100 units forward\n\t *   while (!((motor.get_position() < 105) && (motor.get_position() > 95))) {\n\t *     // Continue running this loop as long as the motor is not within +-5 units of its goal\n\t *     pros::delay(2);\n\t *   }\n\t *   motor.move_absolute(100, 100); // This does not cause a movement\n\t *   while (!((motor.get_position() < 105) && (motor.get_position() > 95))) {\n\t *     pros::delay(2);\n\t *   }\n\t *   motor.tare_position();\n\t *   motor.move_absolute(100, 100); // Moves 100 units forward\n\t *   while (!((motor.get_position() < 105) && (motor.get_position() > 95))) {\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t move_absolute(const double position, const std::int32_t velocity) const;\n\n\t/**\n\t * Sets the relative target position for the motor to move to.\n\t *\n\t * This movement is relative to the current position of the motor as given in\n\t * pros::Motor::motor_get_position(). Providing 10.0 as the position parameter\n\t * would result in the motor moving clockwise 10 units (counter clockwise if reversed),\n\t * no matter what the current position is.\n\t *\n\t * \\note This function simply sets the target for the motor, it does not block\n\t * program execution until the movement finishes.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param position\n\t *        The relative position to move to in the motor's encoder units\n\t * \\param velocity\n\t *        The maximum allowable velocity for the movement in RPM\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::Motor motor (1);\n\t *   motor.move_relative(100, 100); // Moves 100 units forward\n\t *   while (!((motor.get_position() < 105) && (motor.get_position() > 95))) {\n\t *     // Continue running this loop as long as the motor is not within +-5 units of its goal\n\t *     pros::delay(2);\n\t *   }\n\t *   motor.move_relative(100, 100); // Also moves 100 units forward\n\t *   while (!((motor.get_position() < 205) && (motor.get_position() > 195))) {\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t move_relative(const double position, const std::int32_t velocity) const;\n\n\t/**\n\t * Sets the velocity for the motor.\n\t *\n\t * This velocity corresponds to different actual speeds depending on the\n\t * gearset used for the motor. This results in a range of +-100 for\n\t * E_MOTOR_GEARSET_36, +-200 for E_MOTOR_GEARSET_18, and +-600 for\n\t * E_MOTOR_GEARSET_6. The velocity is held with PID to ensure consistent\n\t * speed, as opposed to setting the motor's voltage.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param velocity\n\t *        The new motor velocity from -+-100, +-200, or +-600 depending on the\n\t *        motor's gearset\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::Motor motor (1);\n\t *   motor.move_velocity(100);\n\t *   pros::delay(1000); // Move at 100 RPM for 1 second\n\t *   motor.move_velocity(0);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t move_velocity(const std::int32_t velocity) const;\n\n\t/**\n\t * Sets the output voltage for the motor from -12000 to 12000 in millivolts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t * \\param voltage\n\t *        The new voltage value from -12000 to 12000\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   motor.move_voltage(12000);\n\t *   pros::delay(1000); // Move at max voltage for 1 second\n\t *   motor.move_voltage(0);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t move_voltage(const std::int32_t voltage) const;\n\n\t/**\n\t * Stops the motor using the currently configured brake mode.\n\t *\n\t * This function sets motor velocity to zero, which will cause it to act\n\t * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD,\n\t * this function may behave differently than calling move_absolute(0)\n\t * or motor_move_relative(0).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t *  void autonomous() {\n\t *  Motor motor(1);\n\t *   motor.move_voltage(12000);\n\t *   pros::delay(1000); // Move at max voltage for 1 second\n\t *   motor.brake();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t brake(void) const;\n\n\t/**\n\t * Changes the output velocity for a profiled movement (motor_move_absolute or\n\t * motor_move_relative). This will have no effect if the motor is not following\n\t * a profiled movement.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param velocity\n\t *        The new motor velocity from +-100, +-200, or +-600 depending on the\n\t *        motor's gearset\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t * \t pros::Motor motor (1);\n\t *   motor.move_absolute(100, 100);\n\t *   pros::delay(100);\n\t *   motor.modify_profiled_velocity(0); // Stop the motor early\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t modify_profiled_velocity(const std::int32_t velocity) const;\n\n\t///@}\n\n\t/// \\name Motor telemetry functions\n\t/// These functions allow programmers to collect telemetry from motors\n\t///@{\n\n\t/**\n\t * Gets the target position set for the motor by the user\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return The target position in its encoder units or PROS_ERR_F if the\n\t * operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::Motor motor (1);\n\t *   motor.move_absolute(100, 100);\n\t *   std::cout << \"Motor Target: \" << motor.get_target_position();\n\t *   // Prints 100\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_target_position(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the velocity commanded to the motor by the user at the index specified.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return The commanded motor velocity from +-100, +-200, or +-600, or\n\t * PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));\n\t *     std::cout << \"Motor Velocity: \" << motor.get_target_velocity();\n\t *     // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_target_velocity(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the actual velocity of the motor.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return The motor's actual velocity in RPM or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   while (true) {\n\t *     motor = controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     printf(\"Actual velocity: %lf\\n\", motor.get_actual_velocity());\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_actual_velocity(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the current drawn by the motor in mA.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return The motor's current in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Current Draw: \" << motor.get_current_draw();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_current_draw(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the direction of movement for the motor.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return 1 for moving in the positive direction, -1 for moving in the\n\t * negative direction, and PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Direction: \" << motor.get_direction();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_direction(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the efficiency of the motor in percent.\n\t *\n\t * An efficiency of 100% means that the motor is moving electrically while\n\t * drawing no electrical power, and an efficiency of 0% means that the motor\n\t * is drawing power but not moving.\n\t *\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return The motor's efficiency in percent or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Efficiency: \" << motor.get_efficiency();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_efficiency(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the faults experienced by the motor.\n\t *\n\t * Compare this bitfield to the bitmasks in pros::motor_fault_e_t.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t *\n\t * \\return A bitfield containing the motor's faults.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Faults: \" << motor.get_faults();pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::uint32_t get_faults(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the flags set by the motor's operation.\n\t *\n\t * Compare this bitfield to the bitmasks in pros::motor_flag_e_t.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return A bitfield containing the motor's flags.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Faults: \" << motor.get_faults();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::uint32_t get_flags(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the absolute position of the motor in its encoder units.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return The motor's absolute position in its encoder units or PROS_ERR_F\n\t * if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Position: \" << motor.get_position();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_position(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the power drawn by the motor in Watts.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return The motor's power draw in Watts or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Power: \" << motor.get_power();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_power(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the raw encoder count of the motor at a given timestamp.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t *\n\t * \\param timestamp\n\t *            A pointer to a time in milliseconds for which the encoder count\n\t *            will be returned. If NULL, the timestamp at which the encoder\n\t *            count was read will not be supplied\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t *\n\t *\n\t * \\return The raw encoder count at the given timestamp or PROS_ERR if the\n\t * operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   std::uint32_t now = pros::millis();\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Position: \" << motor.get_raw_position(&now);\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_raw_position(std::uint32_t* const timestamp, const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the temperature of the motor in degrees Celsius.\n\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return The motor's temperature in degrees Celsius or PROS_ERR_F if the\n\t * operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Temperature: \" << motor.get_temperature();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_temperature(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the torque generated by the motor in Newton Meters (Nm).\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return The motor's torque in Nm or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Torque: \" << motor.get_torque();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tdouble get_torque(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the voltage delivered to the motor in millivolts.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return The motor's voltage in mV or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Voltage: \" << motor.get_voltage();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_voltage(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Checks if the motor is drawing over its current limit.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return 1 if the motor's current limit is being exceeded and 0 if the\n\t * current limit is not exceeded, or PROS_ERR if the operation failed, setting\n\t * errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Is the motor over its current limit?: \" << motor.is_over_current();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t is_over_current(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the temperature limit flag for the motor.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return 1 if the temperature limit is exceeded and 0 if the temperature is\n\t * below the limit, or PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Is the motor over its temperature limit?: \" << motor.is_over_temp();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t is_over_temp(const std::uint8_t index = 0) const;\n\n\t///@}\n\n\t/// \\name Motor configuration functions\n\t/// These functions allow programmers to configure the behavior of motors\n\t///@{\n\n\t/**\n\t * Gets the brake mode that was set for the motor.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return One of MotorBrake, according to what was set for the\n\t * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);\n\t *   std::cout << \"Brake Mode: \" << motor.get_brake_mode();\n\t * }\n\t * \\endcode\n\t */\n\tMotorBrake get_brake_mode(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the current limit for the motor in mA.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return The motor's current limit in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   while (true) {\n\t *     std::cout << \"Motor Current Limit: \" << motor.get_current_limit();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_current_limit(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the encoder units that were set for the motor.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return One of MotorUnits according to what is set for the\n\t * motor or E_MOTOR_ENCODER_INVALID if the operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Encoder Units: \" << motor.get_encoder_units();\n\t * }\n\t * \\endcode\n\t */\n\tMotorUnits get_encoder_units(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the gearset that was set for the motor.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return One of MotorGears according to what is set for the motor,\n\t * or pros::MotorGears::invalid if the operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Gearing: \" << motor.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tMotorGears get_gearing(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the voltage limit set by the user.\n\t *\n\t * Default value is 0V, which means that there is no software limitation\n\t * imposed on the voltage.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   std::cout << \"Motor Voltage Limit: \" << motor.get_voltage_limit();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_voltage_limit(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets whether the motor is reversed or not\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return 1 if the motor has been reversed and 0 if the motor was not\n\t * reversed, or PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   std::cout << \"Is the motor reversed? \" << motor.is_reversed();\n\t *   // Prints \"0\"\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t is_reversed(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the type of the motor\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the type of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return One of MotorType according to the type of the motor,\n\t * or pros::MotorType::invalid if the operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Type: \" << motor.get_type();\n\t * }\n\t * \\endcode\n\t */\n\tMotorType get_type(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Sets one of Motor_Brake to the motor.\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t *\n\t * \\param mode\n\t *        The MotorBrake to set for the motor\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);\n\t *   std::cout << \"Brake Mode: \" << motor.get_brake_mode();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_brake_mode(const MotorBrake mode, const std::uint8_t index = 0) const;\n\t/**\n\t * Sets one of MotorBrake to the motor.\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t *\n\t * \\param mode\n\t *        The MotorBrake to set for the motor\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);\n\t *   std::cout << \"Brake Mode: \" << motor.get_brake_mode();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index = 0) const;\n\t/**\n\t * Sets the current limit for the motor in mA.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param limit\n\t *        The new current limit in mA\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *\n\t * motor.set_current_limit(1000);\n\t * while (true) {\n\t *   motor = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *   // The motor will reduce its output at 1000 mA instead of the default 2500 mA\n\t *   pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_current_limit(const std::int32_t limit, const std::uint8_t index = 0) const;\n\n\t/**\n\t * Sets one of MotorUnits for the motor encoder. Works with the C\n\t * enum and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param units\n\t *        The new motor encoder units\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_encoder_units(E_MOTOR_ENCODER_DEGREES);\n\t *   std::cout << \"Encoder Units: \" << motor.get_encoder_units();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_encoder_units(const MotorUnits units, const std::uint8_t index = 0) const;\n\t/**\n\t * Sets one of MotorUnits for the motor encoder. Works with the C\n\t * enum and the C++ enum class.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * * \\param units\n\t *        The new motor encoder units\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_encoder_units(E_MOTOR_ENCODER_DEGREES);\n\t *   std::cout << \"Encoder Units: \" << motor.get_encoder_units();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index = 0) const;\n\t/**\n\t * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with\n\t * the C++ enum class and the C enum.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t * \\param gearset\n\t *        The new motor gearset\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_gearing(E_MOTOR_GEARSET_06);\n\t *   std::cout << \"Gearset: \" << motor.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_gearing(const MotorGears gearset, const std::uint8_t index = 0) const;\n\n\t/**\n\t * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with\n\t * the C++ enum class and the C enum.\n\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param gearset\n\t *        The new motor gearset\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_gearing(E_MOTOR_GEARSET_06);\n\t *   std::cout << \"Gearset: \" << motor.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_gearing(const pros::motor_gearset_e_t gearset, const std::uint8_t index = 0) const;\n\n\t/**\n\t * Sets the reverse flag for the motor.\n\t *\n\t * This will invert its movements and the values returned for its position.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param reverse\n\t *        True reverses the motor, false is default direction\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_reversed(true);\n\t *   std::cout << \"Is this motor reversed? \" << motor.is_reversed();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_reversed(const bool reverse, const std::uint8_t index = 0);\n\n\t/**\n\t * Sets the voltage limit for the motor in Volts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param limit\n\t *        The new voltage limit in Volts\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *\n\t *   motor.set_voltage_limit(10000);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     // The motor will not output more than 10 V\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_voltage_limit(const std::int32_t limit, const std::uint8_t index = 0) const;\n\n\t/**\n\t * Sets the position for the motor in its encoder units.\n\t *\n\t * This will be the future reference point for the motor's \"absolute\"\n\t * position.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param position\n\t *        The new reference position in its encoder units\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::Motor motor (1);\n\t *   motor.move_absolute(100, 100); // Moves 100 units forward\n\t *   motor.move_absolute(100, 100); // This does not cause a movement\n\t *\n\t *   motor.set_zero_position(80);\n\t *   motor.move_absolute(100, 100); // Moves 20 units forward\n\t * }\n\t * \\endcode\n\t *\n\t */\n\tstd::int32_t set_zero_position(const double position, const std::uint8_t index = 0) const;\n\n\t/**\n\t * Sets the \"absolute\" zero position of the motor to its current position.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::Motor motor (1);\n\t *   motor.move_absolute(100, 100); // Moves 100 units forward\n\t *   motor.move_absolute(100, 100); // This does not cause a movement\n\t *\n\t *   motor.tare_position();\n\t *   motor.move_absolute(100, 100); // Moves 100 units forward\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t tare_position(const std::uint8_t index = 0) const;\n\n\t/**\n\t * Gets the number of motors.\n\t *\n\t * \\return Always returns 1\n\t *\n\t */\n\tstd::int8_t size(void) const;\n\n\t/**\n\t * Gets all motors.\n\t *\n\t * \\return A vector of Motor objects.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   std::vector<Motor> motor_all = pros::Motor::get_all_devices();  // All motors that are connected\n\t * }\n\t * \\endcode\n\t */\n\tstatic std::vector<Motor> get_all_devices();\n\n\t/**\n\t * gets the port number of the motor\n\t *\n\t * \\return The signed port of the motor. (negative if the motor is reversed)\n\t *\n\t */\n\tstd::int8_t get_port(const std::uint8_t index = 0) const;\n\n\t///@}\n\n\t/// \\name Additional motor functions\n\t/// These functions allow for motors and motor groups to be used interchangeably\n\t///@{\n\t/**\n\t * Gets a vector containing the target position set for the motor by the user\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t *\n\t * \\return A vector containing the target position in its encoder units or PROS_ERR_F if the\n\t * operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::Motor motor (1);\n\t *   motor.move_absolute(100, 100);\n\t *   std::cout << \"Motor Target: \" << motor.get_target_position_all()[0];\n\t *   // Prints 100\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_target_position_all(void) const;\n\n\t/**\n\t * Gets a vector containing the velocity commanded to the motor by the user\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing the commanded motor velocity from +-100,\n\t * +-200, or +-600, or PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));\n\t *     std::cout << \"Motor Velocity: \" << motor.get_target_velocity_all()[0];\n\t *     // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_target_velocity_all(void) const;\n\n\t/**\n\t * Gets a vector containing the actual velocity commanded of the motor\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing the motor's actual velocity in RPM or PROS_ERR_F\n\t * if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));\n\t *     std::cout << \"Motor Velocity: \" << motor.get_actual_velocity_all()[0];\n\t *     // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_actual_velocity_all(void) const;\n\n\t/**\n\t * Gets a vector containing the current drawn by the motor in mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t *\n\t * \\return A vector containing the motor's current in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Current Draw: \" << motor.get_current_draw_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_current_draw_all(void) const;\n\n\t/**\n\t * Gets a vector containing the direction of movement for the motor.\n\t *\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t *\n\t * \\return A vector containing 1 for moving in the positive direction, -1 for moving in the\n\t * negative direction, and PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Direction: \" << motor.get_direction_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_direction_all(void) const;\n\n\t/**\n\t * Gets a vector containing the efficiency of the motor in percent.\n\t *\n\t * An efficiency of 100% means that the motor is moving electrically while\n\t * drawing no electrical power, and an efficiency of 0% means that the motor\n\t * is drawing power but not moving.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t *\n\t * \\return A vector containing The motor's efficiency in percent or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Efficiency: \" << motor.get_efficiency();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_efficiency_all(void) const;\n\n\t/**\n\t * Gets a vector of the faults experienced by the motor.\n\t *\n\t * Compare this bitfield to the bitmasks in pros::motor_fault_e_t.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A bitfield containing the motor's faults.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Faults: \" << motor.get_faults_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::uint32_t> get_faults_all(void) const;\n\n\t/**\n\t * Gets a vector of the flags set by the motor's operation.\n\t *\n\t * Compare this bitfield to the bitmasks in pros::motor_flag_e_t.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t *\n\t * \\return A bitfield containing the motor's flags.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Faults: \" << motor.get_faults_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::uint32_t> get_flags_all(void) const;\n\n\t/**\n\t * Gets a vector containing the absolute position of the motor in its encoder units.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\n\t *\n\t * \\return A vector containing the motor's absolute position in its encoder units or PROS_ERR_F\n\t * if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Position: \" << motor.get_position_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_position_all(void) const;\n\n\t/**\n\t * Gets a vector containing the power drawn by the motor in Watts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing the motor's power draw in Watts or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Power: \" << motor.get_power_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_power_all(void) const;\n\n\t/**\n\t * Gets a vector of the raw encoder count of the motor at a given timestamp.\n\t *\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param timestamp\n\t *            A pointer to a time in milliseconds for which the encoder count\n\t *            will be returned. If NULL, the timestamp at which the encoder\n\t *            count was read will not be supplied\n\t *\n\t * \\return A vector containing the raw encoder count at the given timestamp or PROS_ERR if the\n\t * operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   std::uint32_t now = pros::millis();\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Position: \" << motor.get_raw_position(&now);\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_raw_position_all(std::uint32_t* const timestamp) const;\n\n\t/**\n\t * Gets a vector of the temperature of the motor in degrees Celsius.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector contaioning the motor's temperature in degrees Celsius\n\t * or PROS_ERR_F if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Temperature: \" << motor.get_temperature_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_temperature_all(void) const;\n\n\t/**\n\t * Gets a vector of the torque generated by the motor in Newton Meters (Nm).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing the motor's torque in Nm or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Torque: \" << motor.get_torque();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<double> get_torque_all(void) const;\n\n\t/**\n\t * Gets a vector of the voltage delivered to the motor in millivolts.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t *\n\t * \\return A vector of the motor's voltage in mV or PROS_ERR_F if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Motor Voltage: \" << motor.get_voltage_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_voltage_all(void) const;\n\n\t/**\n\t * Checks if the motor is drawing over its current limit.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing 1 if the motor's current limit is being exceeded and 0 if the\n\t * current limit is not exceeded, or PROS_ERR if the operation failed, setting\n\t * errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Is the motor over its current limit?: \" << motor.is_over_current_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> is_over_current_all(void) const;\n\n\t/**\n\t * Gets the temperature limit flag for the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing 1 if the temperature limit is exceeded and 0 if the temperature is\n\t * below the limit, or PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     std::cout << \"Is the motor over its temperature limit?: \" << motor.is_over_temp_all();\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> is_over_temp_all(void) const;\n\n\t/**\n\t * Gets a vector containing the brake mode that was set for the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return One of Motor_Brake, according to what was set for the\n\t * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD);\n\t *   std::cout << \"Brake Mode: \" << motor.get_brake_mode();\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<MotorBrake> get_brake_mode_all(void) const;\n\n\t/**\n\t * Gets a vector containing the current limit for the motor in mA.\n\t *\n\t * The default value is 2500 mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing the motor's current limit in mA or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   while (true) {\n\t *     std::cout << \"Motor Current Limit: \" << motor.get_current_limit_all()[0];\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_current_limit_all(void) const;\n\n\t/**\n\t * Gets a vector containing the encoder units that were set for the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing One of Motor_Units according to what is set for the\n\t * motor or E_MOTOR_ENCODER_INVALID if the operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Encoder Units: \" << motor.get_encoder_units_all()[0];\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<MotorUnits> get_encoder_units_all(void) const;\n\n\t/**\n\t * Gets a vector containing the gearset that was set for the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing one of Motor_Gears according to what is set for the motor,\n\t * or pros::Motor_Gears::invalid if the operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Gearing: \" << motor.get_gearing_all()[0];\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<MotorGears> get_gearing_all(void) const;\n\n\t/**\n\t * Gets returns a vector with all the port numbers in the motor group.\n\t *\n\t * \\return A vector containing the signed port of the motor. (negative if the motor is reversed)\n\t */\n\tstd::vector<std::int8_t> get_port_all(void) const;\n\n\t/**\n\t * Gets a vector of the voltage limit set by the user.\n\t *\n\t * Default value is 0V, which means that there is no software limitation\n\t * imposed on the voltage.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing the motor's voltage limit in V or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   std::cout << \"Motor Voltage Limit: \" << motor.get_voltage_limit_all()[0];\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> get_voltage_limit_all(void) const;\n\n\t/**\n\t * Gets a vector containg whether the motor is reversed or not\n\t *\n\t * \\return A vector containing 1 if the motor has been reversed and 0 if the motor was not\n\t * reversed, or PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   std::cout << \"Is the motor reversed? \" << motor.is_reversed_all()[0];\n\t *   // Prints \"0\"\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<std::int32_t> is_reversed_all(void) const;\n\n\t/**\n\t * Gets a vector containing the type of the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return A vector containing one of MotorType according to the type of the motor,\n\t * or pros::MotorType::invalid if the operation failed.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS);\n\t *   std::cout << \"Motor Type: \" << motor.get_type_all()[0];\n\t * }\n\t * \\endcode\n\t */\n\tstd::vector<MotorType> get_type_all(void) const;\n\n\t/**\n\t * Sets one of Motor_Brake to the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param mode\n\t *        The Motor_Brake to set for the motor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_brake_mode_all(pros::E_MOTOR_BRAKE_HOLD);\n\t *   std::cout << \"Brake Mode: \" << motor.get_brake_mode();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_brake_mode_all(const MotorBrake mode) const;\n\n\t/**\n\t * Sets one of Motor_Brake to the motor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param mode\n\t *        The Motor_Brake to set for the motor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_brake_mode_all(pros::E_MOTOR_BRAKE_HOLD);\n\t *   std::cout << \"Brake Mode: \" << motor.get_brake_mode();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const;\n\n\t/**\n\t * Sets the current limit for the motor in mA.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param limit\n\t *        The new current limit in mA\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *\n\t * motor.set_current_limit_all(1000);\n\t * while (true) {\n\t *   motor = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *   // The motor will reduce its output at 1000 mA instead of the default 2500 mA\n\t *   pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_current_limit_all(const std::int32_t limit) const;\n\n\t/**\n\t * Sets one of Motor_Units for the motor encoder. Works with the C\n\t * enum and the C++ enum class.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * * \\param units\n\t *        The new motor encoder units\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES);\n\t *   std::cout << \"Encoder Units: \" << motor.get_encoder_units();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_encoder_units_all(const MotorUnits units) const;\n\n\t/**\n\t * Sets one of Motor_Units for the motor encoder. Works with the C\n\t * enum and the C++ enum class.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param units\n\t *        The new motor encoder units\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES);\n\t *   std::cout << \"Encoder Units: \" << motor.get_encoder_units();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_encoder_units_all(const pros::motor_encoder_units_e_t units) const;\n\n\t/**\n\t * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with\n\t * the C++ enum class and the C enum.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param gearset\n\t *        The new motor gearset\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_gearing_all(E_MOTOR_GEARSET_06);\n\t *   std::cout << \"Gearset: \" << motor.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_gearing_all(const MotorGears gearset) const;\n\n\t/**\n\t * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with\n\t * the C++ enum class and the C enum.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param gearset\n\t *        The new motor gearset\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_gearing_all(E_MOTOR_GEARSET_06);\n\t *   std::cout << \"Gearset: \" << motor.get_gearing();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const;\n\n\t/**\n\t * Sets the reverse flag for the motor.\n\t *\n\t * This will invert its movements and the values returned for its position.\n\t *\n\t *\n\t * \\param reverse\n\t *        True reverses the motor, false is default direction\n\t *\n\t * \\return 1\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Motor motor (1);\n\t *   motor.set_reversed_all(true);\n\t *   std::cout << \"Is this motor reversed? \" << motor.is_reversed();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_reversed_all(const bool reverse);\n\n\t/**\n\t * Sets the voltage limit for the motor in Volts.\n\t *\n\t * \\note This is one of many Motor functions that takes in an optional index parameter.\n\t * \t\t This parameter can be ignored by most users but exists to give a shared base class\n\t * \t\t for motors and motor groups\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t *\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * EOVERFLOW - The index is non 0\n\t *\n\t * \\param limit\n\t *        The new voltage limit in Volts\n\t *\n\t * \\param index Optional parameter.\n\t * \t\t  The zero-indexed index of the motor to get the target position of.\n\t * \t\t  By default index is 0, and will return an error for a non-zero index\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::Motor motor (1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *\n\t *   motor.set_voltage_limit_all(10000);\n\t *   while (true) {\n\t *     motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y);\n\t *     // The motor will not output more than 10 V\n\t *     pros::delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_voltage_limit_all(const std::int32_t limit) const;\n\n\t/**\n\t * Sets the position for the motor in its encoder units.\n\t *\n\t * This will be the future reference point for the motor's \"absolute\"\n\t * position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\param position\n\t *        The new reference position in its encoder units\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::Motor motor (1);\n\t *   motor.move_absolute(100, 100); // Moves 100 units forward\n\t *   motor.move_absolute(100, 100); // This does not cause a movement\n\t *\n\t *   motor.set_zero_position_all(80);\n\t *   motor.move_absolute(100, 100); // Moves 20 units forward\n\t * }\n\t * \\endcode\n\t *\n\t */\n\tstd::int32_t set_zero_position_all(const double position) const;\n\n\t/**\n\t * Sets the \"absolute\" zero position of the motor to its current position.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a motor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void autonomous() {\n\t *   pros::Motor motor (1);\n\t *   motor.move_absolute(100, 100); // Moves 100 units forward\n\t *   motor.move_absolute(100, 100); // This does not cause a movement\n\t *\n\t *   motor.tare_position_all();\n\t *   motor.move_absolute(100, 100); // Moves 100 units forward\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t tare_position_all(void) const;\n\n\t///@}\n\n\tprivate:\n\t/**\n\t * The port of the motor. Negative ports indicate that the motor is reversed\n\t */\n\tstd::int8_t _port;\n};\nnamespace literals {\n/**\n * Constructs a Motor from a literal ending in _mtr\n *\n * \\return a pros::Motor for the corresponding port\n *\n * \\b Example\n * \\code\n * using namespace pros::literals;\n * void opcontrol() {\n *\tpros::Motor motor = 2_mtr; //Makes an Motor object on port 2\n * }\n * \\endcode\n */\nconst pros::Motor operator\"\"_mtr(const unsigned long long int m);\n/**\n * Constructs a reversed Motor from a literal ending in _rmtr\n *\n * \\return a pros::Motor for the corresponding port that is reversed\n *\n * \\b Example\n * \\code\n * using namespace pros::literals;\n * void opcontrol() {\n *\tpros::motor motor = 2_rmtr; //Makes an reversed Motor object on port 2\n * }\n * \\endcode\n */\nconst pros::Motor operator\"\"_rmtr(const unsigned long long int m);\n}  // namespace literals\n}  // namespace v5\n}  // namespace pros\n#endif  // _PROS_MOTORS_HPP_\n"
  },
  {
    "path": "include/pros/optical.h",
    "content": "/**\n * \\file pros/optical.h\n * \\ingroup c-optical\n *\n * Contains prototypes for functions related to the VEX Optical sensor.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup c-optical VEX Optical Sensor C API\n */\n\n#ifndef _PROS_OPTICAL_H_\n#define _PROS_OPTICAL_H_\n\n#include <stdbool.h>\n#include <stdint.h>\n#include \"error.h\"\n\n#define OPT_GESTURE_ERR (INT8_MAX)\n#define OPT_COUNT_ERR (INT16_MAX)\n#define OPT_TIME_ERR PROS_ERR\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\nnamespace c {\n#endif\n\n/**\n * \\ingroup c-optical\n */\n\n/**\n * \\addtogroup c-optical\n *  @{\n */\n\n/**\n * \\enum optical_direction_e_t\n */\ntypedef enum optical_direction_e { NO_GESTURE = 0,\n\t/// The direction indicating an upward gesture.\n\tUP = 1,\n\t/// The direction indicating a downward gesture.\n\tDOWN = 2,\n\t/// The direction indicating a rightward gesture.\n\tRIGHT = 3,\n\t/// The direction indicating a leftward gesture.\n\tLEFT = 4,\n\tERROR = PROS_ERR \n} optical_direction_e_t;\n\n/**\n * \\struct optical_rgb_s_t\n * The RGB and Brightness values for the optical sensor.\n */\ntypedef struct optical_rgb_s {\n\tdouble red;\n\tdouble green;\n\tdouble blue;\n\tdouble brightness;\n} optical_rgb_s_t;\n\n/**\n * \\struct optical_raw_s_t\n * The RGB and clear values for the optical sensor.\n */\ntypedef struct optical_raw_s {\n\tuint32_t clear;\n\tuint32_t red;\n\tuint32_t green;\n\tuint32_t blue;\n} optical_raw_s_t;\n\n/**\n * \\struct optical_gesture_s_t\n * This structure contains the raw gesture data.\n */\ntypedef struct optical_gesture_s {\n\tuint8_t udata;  ///Up data\n\tuint8_t ddata;  ///Down data\n\tuint8_t ldata;  ///Left data\n\tuint8_t rdata;  ///Right data\n\tuint8_t type;   ///Type of gesture\n\tuint8_t pad;    ///Padding\n\tuint16_t count; ///Number of gestures\n\tuint32_t time;  ///Time since gesture recognized\n} optical_gesture_s_t;\n\n/**\n * \\name Functions\n * @{\n */\n\n/**\n * Get the detected color hue\n *\n * This is not available if gestures are being detected. Hue has a\n * range of 0 to 359.999\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return hue value if the operation was successful or PROS_ERR_F if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Hue value: %lf \\n\", optical_get_hue(OPTICAL_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble optical_get_hue(uint8_t port);\n\n/**\n * Get the detected color saturation\n *\n * This is not available if gestures are being detected. Saturation has a\n * range of 0 to 1.0\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return saturation value if the operation was successful or PROS_ERR_F if\n * the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Saturation value: %lf \\n\", optical_get_saturation(OPTICAL_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble optical_get_saturation(uint8_t port);\n\n/**\n * Get the detected color brightness\n *\n * This is not available if gestures are being detected. Brightness has a\n * range of 0 to 1.0\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return brightness value if the operation was successful or PROS_ERR_F if\n * the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Brightness value: %lf \\n\", optical_get_brightness(OPTICAL_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\ndouble optical_get_brightness(uint8_t port);\n\n/**\n * Get the detected proximity value\n *\n * This is not available if gestures are being detected. proximity has\n * a range of 0 to 255.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return poximity value if the operation was successful or PROS_ERR if\n * the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Proximity value: %d \\n\", optical_get_proximity(OPTICAL_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t optical_get_proximity(uint8_t port);\n\n/**\n * Set the pwm value of the White LED\n *\n * value that ranges from 0 to 100\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return 1 if the operation is successful or PROS_ERR if the operation failed,\n * setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     optical_set_led_pwm(OPTICAL_PORT, 50);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t optical_set_led_pwm(uint8_t port, uint8_t value);\n\n/**\n * Get the pwm value of the White LED\n *\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return LED pwm value that ranges from 0 to 100 if the operation was \n * successful or PROS_ERR if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"PWM Value: %d \\n\", optical_get_led_pwm(OPTICAL_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t optical_get_led_pwm(uint8_t port);\n\n/**\n * Get the processed RGBC data from the sensor\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return rgb value if the operation was successful or an optical_rgb_s_t with\n * all fields set to PROS_ERR if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * optical_rgb_s_t RGB_values;\n * void opcontrol() {\n *   while (true) {\n *     RGB_values = optical_get_rgb(OPTICAL_PORT);\n *     printf(\"Red value: %lf \\n\", RGB_values.red);\n *     printf(\"Green value: %lf \\n\", RGB_values.green);\n *     printf(\"Blue value: %lf \\n\", RGB_values.blue);\n *     printf(\"Brightness value: %lf \\n\", RGB_values.brightness);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\noptical_rgb_s_t optical_get_rgb(uint8_t port);\n\n/**\n * Get the raw, unprocessed RGBC data from the sensor\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return raw rgb value if the operation was successful or an optical_raw_s_t \n * with all fields set to PROS_ERR if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * optical_raw_s_t raw_values;\n * void opcontrol() {\n * while (true) {\n *   raw_values = optical_get_raw(OPTICAL_PORT);\n *   printf(\"Red value: %ld \\n\", raw_values.red);\n *   printf(\"Green value: %ld \\n\", raw_values.green);\n *   printf(\"Blue value: %ld \\n\", raw_values.blue);\n *   printf(\"Clear value: %ld \\n\", raw_values.clear);\n *   delay(20);\n *   }\n * }\n * \\endcode\n */\noptical_raw_s_t optical_get_raw(uint8_t port);\n\n/**\n * Get the most recent gesture data from the sensor\n *\n * Gestures will be cleared after 500mS\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return gesture value if the operation was successful or PROS_ERR if\n * the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * optical_direction_e_t gesture;\n * void opcontrol() {\n *   while (true) {\n *     gesture = optical_get_gesture(OPTICAL_PORT);\n *     printf(\"Gesture value: %d \\n\", gesture);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\noptical_direction_e_t optical_get_gesture(uint8_t port);\n\n/**\n * Get the most recent raw gesture data from the sensor\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return gesture value if the operation was successful or an optical_gesture_s_t \n * with all fields set to PROS_ERR if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * optical_gesture_s_t raw_gesture;\n * void opcontrol() {\n *   while (true) {\n *     raw_gesture = optical_get_gesture_raw(OPTICAL_PORT);\n *     printf(\"Up data: %u \\n\", raw_gesture.udata);\n *     printf(\"Down data: %u \\n\", raw_gesture.ddata);\n *     printf(\"Left data: %u \\n\", raw_gesture.ldata);\n *     printf(\"Right data: %u \\n\", raw_gesture.rdata);\n *     printf(\"Type: %u \\n\", raw_gesture.type);\n *     printf(\"Count: %u \\n\", raw_gesture.count);\n *     printf(\"Time: %lu \\n\", raw_gesture.time);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\noptical_gesture_s_t optical_get_gesture_raw(uint8_t port);\n\n/**\n * Enable gesture detection on the sensor\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return 1 if the operation is successful or PROS_ERR if the operation failed,\n * setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     optical_enable_gesture(OPTICAL_PORT);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t optical_enable_gesture(uint8_t port);\n\n/**\n * Disable gesture detection on the sensor\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return 1 if the operation is successful or PROS_ERR if the operation failed,\n * setting errno.\n * \n * \\b Example\n * \\code\n * #define OPTICAL_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     optical_disable_gesture(OPTICAL_PORT);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t optical_disable_gesture(uint8_t port);\n\n/**\n * Get integration time (update rate) of the optical sensor in milliseconds, with\n * minimum time being \n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\return Integration time in milliseconds if the operation is successful \n * or PROS_ERR_F if the operation failed, setting errno.\n */\ndouble optical_get_integration_time(uint8_t port);\n\n/**\n * Set integration time (update rate) of the optical sensor in milliseconds.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Optical Sensor\n *\n * \\param port\n *        The V5 Optical Sensor port number from 1-21\n * \\param time\n *        The desired integration time in milliseconds\n * \\return 1 if the operation is successful or PROS_ERR if the operation failed,\n * setting errno.\n */\nint32_t optical_set_integration_time(uint8_t port, double time);\n\n///@}\n\n///@}\n\n#ifdef __cplusplus\n}\n}\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "include/pros/optical.hpp",
    "content": "/**\n * \\file pros/optical.hpp\n * \\ingroup cpp-optical\n *\n * Contains prototypes for functions related to the VEX Optical sensor.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-optical VEX Optical Sensor C++ API\n */\n\n#ifndef _PROS_OPTICAL_HPP_\n#define _PROS_OPTICAL_HPP_\n\n#include <stdbool.h>\n\n#include <cstdint>\n#include <iostream>\n\n#include \"pros/device.hpp\"\n#include \"pros/optical.h\"\n\nnamespace pros {\ninline namespace v5 {\n/**\n * \\ingroup cpp-optical\n */\nclass Optical : public Device {\n\t/**\n\t * \\addtogroup cpp-optical\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Creates an Optical Sensor object for the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * pros::Optical optical(1);\n\t * \\endcode\n\t */\n\tOptical(const std::uint8_t port);\n\n\tOptical(const Device& device) : Optical(device.get_port()){};\n\n\n\t/**\n\t * Gets all optical sensors.\n\t * \n\t * \\return A vector of Optical sensor objects.\n\t *\n\t * \\b Example\n \t * \\code\n\t * void opcontrol() {\n\t *   std::vector<Optical> optical_all = pros::Optical::get_all_devices();  // All optical sensors that are connected\n\t * }\n \t * \\endcode\n\t */\n\tstatic std::vector<Optical> get_all_devices();\n\n\t/**\n\t * Get the detected color hue\n\t *\n\t * This is not available if gestures are being detected. Hue has a\n\t * range of 0 to 359.999\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return hue value if the operation was successful or PROS_ERR_F if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void opcontrol() {\n\t * \t\tpros::Optical optical(1);\n\t * \t\tstd::cout << \"Hue: \" << optical.get_hue() << std::endl;\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_hue();\n\n\t/**\n\t * Get the detected color saturation\n\t *\n\t * This is not available if gestures are being detected. Saturation has a\n\t * range of 0 to 1.0\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return saturation value if the operation was successful or PROS_ERR_F if\n\t * the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void opcontrol() {\n\t * \t\tpros::Optical optical(1);\n\t * \t\tstd::cout << \"Saturation: \" << optical.get_saturation() << std::endl;\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_saturation();\n\n\t/**\n\t * Get the detected color brightness\n\t *\n\t * This is not available if gestures are being detected. Brightness has a\n\t * range of 0 to 1.0\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return brightness value if the operation was successful or PROS_ERR_F if\n\t * the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void opcontrol() {\n\t * \t\tpros::Optical optical(1);\n\t * \t\tstd::cout << \"Brightness: \" << optical.get_brightness() << std::endl;\n\t * }\n\t * \\endcode\n\t */\n\tvirtual double get_brightness();\n\n\t/**\n\t * Get the detected proximity value\n\t *\n\t * This is not available if gestures are being detected. proximity has\n\t * a range of 0 to 255.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return Proximity value if the operation was successful or PROS_ERR if\n\t * the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void opcontrol() {\n\t * \t\tpros::Optical optical(1);\n\t * \t\tstd::cout << \"Proximity: \" << optical.get_proximity() << std::endl;\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get_proximity();\n\n\t/**\n\t * Set the pwm value of the White LED on the sensor\n\t *\n\t * value that ranges from 0 to 100\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return The Error code encountered or PROS_SUCCESS.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void initialize() {\n\t * \t\tpros::Optical optical(1);\n\t * \t\toptical.set_led_pwm(100);\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_led_pwm(uint8_t value);\n\n\t/**\n\t * Get the pwm value of the White LED on the sensor\n\t *\n\t * value that ranges from 0 to 100\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return LED pwm value if the operation was successful or PROS_ERR if\n\t * the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void opcontrol() {\n\t * \t\tpros::Optical optical(1);\n\t *\t\toptical.set_led_pwm(100);\n\t * \t\tstd::cout << \"LED PWM: \" << optical.get_led_pwm() << std::endl;\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get_led_pwm();\n\n\t/**\n\t * Get the processed RGBC data from the sensor\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return rgb value if the operation was successful or an optical_rgb_s_t\n\t * with all fields set to PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void opcontrol() {\n\t * \t\tpros::Optical optical(1);\n\t * \t\tpros::c::optical_rgb_s_t rgb = optical.get_rgb();\n\t * \t\twhile(1) {\n\t * \t\t\tstd::cout << \"Red: \" << rgb.red << std::endl;\n\t * \t\t\tstd::cout << \"Green: \" << rgb.green << std::endl;\n\t * \t\t\tstd::cout << \"Blue: \" << rgb.blue << std::endl;\n\t * \t\t\tstd::cout << \"Brightness: \" << rgb.brightness << std::endl;\n\t * \t\t\tpros::delay(20);\n\t * \t\t}\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::c::optical_rgb_s_t get_rgb();\n\n\t/**\n\t * Get the raw un-processed RGBC data from the sensor\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return raw rgb value if the operation was successful or an optical_raw_s_t\n\t * with all fields set to PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void opcontrol() {\n\t * \t\tpros::Optical optical(1);\n\t * \t\tpros::c::optical_raw_s_t raw = optical.get_raw();\n\t * \t\twhile (1) {\n\t * \t\t\tstd::cout << \"Red: \" << raw.red << std::endl;\n\t * \t\t\tstd::cout << \"Green: \" << raw.green << std::endl;\n\t * \t\t\tstd::cout << \"Blue: \" << raw.blue << std::endl;\n\t * \t\t\tstd::cout << \"Clear: \" << raw.clear << std::endl;\n\t * \t\t\tpros::delay(20);\n\t * \t\t}\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::c::optical_raw_s_t get_raw();\n\n\t/**\n\t * Get the most recent gesture data from the sensor\n\t *\n\t * Gestures will be cleared after 500mS\n\t *\n\t * \n\t * 0 = no gesture,\n\t * 1 = up (towards cable),\n\t * 2 = down,\n\t * 3 = right,\n\t * 4 = left\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return gesture value if the operation was successful or PROS_ERR if\n\t * the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void opcontrol() {\n\t * \t\tpros::Optical optical(1);\n\t * \t\twhile(1) {\n\t * \t\t\tstd::cout << \"Gesture: \" << optical.get_gesture() << std::endl;\n\t * \t\t\tpros::delay(20);\n\t * \t\t}\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::c::optical_direction_e_t get_gesture();\n\n\t/**\n\t * Get the most recent raw gesture data from the sensor\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return gesture value if the operation was successful or an optical_gesture_s_t\n\t * with all fields set to PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void opcontrol() {\n\t * \t\tpros::Optical optical(1);\n\t *\t\toptical.enable_gesture();\n\t * \t\twhile(1) {\n\t * \t\t\tpros::c::optical_gesture_s_t gesture = optical.get_gesture_raw();\n\t * \t\t\tstd::cout << \"Gesture raw data: \" << std::endl;\n\t * \t\t\tstd::cout << \"Up data: \" << gesture.udata << std::endl;\n\t * \t\t\tstd::cout << \"Down data: \" << gesture.ddata << std::endl;\n\t * \t\t\tstd::cout << \"Left data: \" << gesture.ldata << std::endl;\n\t * \t\t\tstd::cout << \"Right data: \" << gesture.rdata << std::endl;\n\t * \t\t\tstd::cout << \"Type: \" << gesture.type << std::endl;\n\t * \t\t\tstd::cout << \"Count: \" << gesture.count << std::endl;\n\t * \t\t\tstd::cout << \"Time: \" << gesture.time << std::endl;\n\t * \t\t\tpros::delay(20);\n\t * \t\t}\n\t * }\n\t * \\endcode\n\t */\n\tvirtual pros::c::optical_gesture_s_t get_gesture_raw();\n\n\t/**\n\t * Enable gesture detection on the sensor\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return 1 if the operation is successful or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void opcontrol() {\n\t * \t\tpros::Optical optical(1);\n\t *\t\toptical.enable_gesture();\n\t * \t\twhile(1) {\n\t * \t\t\tpros::c::optical_gesture_s_t gesture = optical.get_gesture_raw();\n\t * \t\t\tstd::cout << \"Gesture raw data: \" << std::endl;\n\t * \t\t\tstd::cout << \"Up data: \" << gesture.udata << std::endl;\n\t * \t\t\tstd::cout << \"Down data: \" << gesture.ddata << std::endl;\n\t * \t\t\tstd::cout << \"Left data: \" << gesture.ldata << std::endl;\n\t * \t\t\tstd::cout << \"Right data: \" << gesture.rdata << std::endl;\n\t * \t\t\tstd::cout << \"Type: \" << gesture.type << std::endl;\n\t * \t\t\tstd::cout << \"Count: \" << gesture.count << std::endl;\n\t * \t\t\tstd::cout << \"Time: \" << gesture.time << std::endl;\n\t * \t\t\tpros::delay(20);\n\t * \t\t}\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t enable_gesture();\n\n\t/**\n\t * Disable gesture detection on the sensor\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return 1 if the operation is successful or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * void opcontrol() {\n\t * \t\tpros::Optical optical(1);\n\t *\t\toptical.enable_gesture();\n\t * \t\twhile(1) {\n\t * \t\t\tif(optical.get_gesture() != 0) {\n\t * \t\t\t\tstd::cout << \"Gesture detected!\"<< std::endl;\n\t * \t\t\t\toptical.disable_gesture();\n\t * \t\t\t}\n\t * \t\t\tpros::delay(20);\n\t * \t\t}\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t disable_gesture();\n\n\t/**\n\t * Get integration time (update rate) of the optical sensor in milliseconds.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n\t *\n\t * \\return Integration time in milliseconds if the operation is successful\n\t *  or PROS_ERR_F if the operation failed, setting errno.\n\t */\n\tdouble get_integration_time();\n\n\t/**\n\t * Set integration time (update rate) of the optical sensor in milliseconds, with\n\t * minimum time being 3 ms and maximum time being 712 ms. Default is 100 ms, with the\n\t * optical sensor communciating with the V5 brain every 20 ms.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Optical Sensor\n \t *\n\t * \\param time The desired integration time in milliseconds\n\t * \\return 1 if the operation is successful or PROS_ERR if the operation failed,\n\t * setting errno.\n\t */\n\tstd::int32_t set_integration_time(double time);\n\n\t/**\n\t * This is the overload for the << operator for printing to streams\n\t *\n\t * Prints in format(this below is all in one line with no new line):\n\t * Optical [port: (port number), hue: (hue), saturation: (saturation),\n\t * brightness: (brightness), proximity: (proximity), rgb: {red, green, blue}]\n\t *\n\t * \\b Example:\n\t * \\code{.cpp}\n\t * pros::Optical optical(1);\n\t * std::cout << optical << std::endl;\n\t * \\endcode\n\t */\n\tfriend std::ostream& operator<<(std::ostream& os, pros::Optical& optical);\n\n\tprivate:\n\t///@}\n};\n\nnamespace literals {\n/**\n * Constructs a Optical sensor from a literal ending in _opt\n *\n * \\return a pros::Optical for the corresponding port\n *\n * \\b Example\n * \\code\n * using namespace pros::literals;\n * void opcontrol() {\n *\tpros::Optical opt = 2_opt; //Makes an Optical object on port 2\n * }\n * \\endcode\n */\nconst pros::Optical operator\"\"_opt(const unsigned long long int o);\n}  // namespace literals\n}  // namespace v5\n}  // namespace pros\n\n#endif\n"
  },
  {
    "path": "include/pros/rotation.h",
    "content": "/**\n * \\file pros/rotation.h\n * \\ingroup c-rotation\n *\n * Contains prototypes for functions related to the VEX Rotation Sensor.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup c-rotation VEX Rotation Sensor C API\n */\n\n#ifndef _PROS_ROTATION_H_\n#define _PROS_ROTATION_H_\n\n#include <stdbool.h>\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\nnamespace c {\n#endif\n\n/**\n * \\ingroup c-rotation\n */\n\n/**\n * \\addtogroup c-rotation\n *  @{\n */\n\n#define ROTATION_MINIMUM_DATA_RATE 5\n\n/**\n * Reset Rotation Sensor \n *\n * Reset the current absolute position to be the same as the\n * Rotation Sensor angle.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Rotation Sensor\n *\n * \\param port\n *        The V5 Rotation Sensor port number from 1-21\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define ROTATION_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n * \n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       rotation_reset(ROTATION_PORT);\n *     }\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t rotation_reset(uint8_t port);\n\n/**\n * Set the Rotation Sensor's refresh interval in milliseconds.\n *\n * The rate may be specified in increments of 5ms, and will be rounded down to\n * the nearest increment. The minimum allowable refresh rate is 5ms. The default\n * rate is 10ms.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Rotation Sensor\n *\n * \\param port\n *        The V5 Rotation Sensor port number from 1-21\n * \\param rate The data refresh interval in milliseconds\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define ROTATION_PORT 1\n * \n * void initialize() {\n *   pros::Rotation rotation_sensor(ROTATION_PORT);\n *   rotation_set_data_rate(ROTATION_PORT, 5);\n * }\n * \\endcode\n */\nint32_t rotation_set_data_rate(uint8_t port, uint32_t rate);\n\n/**\n * Set the Rotation Sensor position reading to a desired rotation value\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Rotation Sensor\n *\n * \\param port\n *\t\t  The V5 Rotation Sensor port number from 1-21\n * \\param position \n * \t\t  The position in terms of ticks\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define ROTATION_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n * \n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       rotation_set_position(ROTATION_PORT, 600);\n *     }\n *   delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t rotation_set_position(uint8_t port, int32_t position);\n\n/**\n * Reset the Rotation Sensor position to 0\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Rotation Sensor\n *\n * \\param port\n *\t\t  The V5 Rotation Sensor port number from 1-21\n\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define ROTATION_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n * \n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       rotation_reset_position(ROTATION_PORT);\n *     }\n *       delay(20);\n *     }\n * }\n * \\endcode\n */\nint32_t rotation_reset_position(uint8_t port);\n\n/**\n * Get the Rotation Sensor's current position in centidegrees\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Rotation Sensor\n *\n * \\param  port\n * \t\t\t\t The V5 Rotation Sensor port number from 1-21\n * \\return The position value or PROS_ERR_F if the operation failed, setting\n * errno.\n * \n * \\b Example\n * \\code\n * #define ROTATION_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Position: %d centidegrees \\n\", rotation_get_position(ROTATION_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t rotation_get_position(uint8_t port);\n\n/**\n * Get the Rotation Sensor's current velocity in centidegrees per second\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Rotation Sensor\n *\n * \\param  port\n * \t\t\t\t The V5 Rotation Sensor port number from 1-21\n * \\return The velocity value or PROS_ERR_F if the operation failed, setting\n * errno.\n * \n * \\b Example\n * \\code\n * #define ROTATION_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Velocity: %d centidegrees per second \\n\", rotation_get_velocity(ROTATION_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t rotation_get_velocity(uint8_t port);\n\n/**\n * Get the Rotation Sensor's current angle in centidegrees (0-36000)\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Rotation Sensor\n *\n * \\param  port\n * \t\t\t\t The V5 Rotation Sensor port number from 1-21\n * \\return The angle value (0-36000) or PROS_ERR_F if the operation failed, setting\n * errno.\n * \n * \\b Example\n * \\code\n * #define ROTATION_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Angle: %d centidegrees \\n\", rotation_get_angle(ROTATION_PORT));\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t rotation_get_angle(uint8_t port);\n\n/**\n * Set the Rotation Sensor's direction reversed flag\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Rotation Sensor\n *\n * \\param  port\n * \t\t\t\t The V5 Rotation Sensor port number from 1-21\n * \\param  value\n * \t\t\t\t Determines if the direction of the Rotation Sensor is reversed or not.\n * \n * \\return 1 if operation succeeded or PROS_ERR if the operation failed, setting\n * errno.\n * \n * \\b Example\n * \\code\n * #define ROTATION_PORT 1\n * \n * void opcontrol() {\n *   Rotation rotation_sensor(ROTATION_PORT);\n *   while (true) {\n * \n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       rotation_set_reversed(ROTATION_PORT, true); // Reverses the Rotation Sensor on ROTATION_PORT\n *     }\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t rotation_set_reversed(uint8_t port, bool value);\n\n/**\n * Reverse the Rotation Sensor's direction\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Rotation Sensor\n *\n * \\param  port\n * \t\t\t\t The V5 Rotation Sensor port number from 1-21\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define ROTATION_PORT 1\n * \n * void opcontrol() {\n *   Rotation rotation_sensor(ROTATION_PORT);\n *   while (true) {\n * \n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       rotation_reverse(ROTATION_PORT);\n *     }\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t rotation_reverse(uint8_t port);\n\n/**\n * Initialize the Rotation Sensor with a reverse flag\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Rotation Sensor\n *\n * \\param  port\n * \t\t\t\t The V5 Rotation Sensor port number from 1-21\n * \\param  reverse_flag\n * \t\t\t\t Determines if the Rotation Sensor is reversed or not.\n * \n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define ROTATION_PORT 1\n * \n * void opcontrol() {\n *   Rotation rotation_sensor(ROTATION_PORT);\n *   bool reverse_flag = true;\n *   while (true) {\n * \n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       rotation_init_reverse(ROTATION_PORT, reverse_flag);\n *     }\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t rotation_init_reverse(uint8_t port, bool reverse_flag);\n\n/**\n * Get the Rotation Sensor's reversed flag\n * \n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as an Rotation Sensor\n *\n * \\param  port\n * \t\t\t\t The V5 Rotation Sensor port number from 1-21\n * \n * \\return Boolean value of if the Rotation Sensor's direction is reversed or not\n * or PROS_ERR if the operation failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define ROTATION_PORT 1\n * \n * void opcontrol() {\n *   Rotation rotation_sensor(ROTATION_PORT);\n *   while (true) {\n * \n *     if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){\n *       rotation_get_reversed(ROTATION_PORT);\n *     }\n *   delay(20);\n *   }\n * }\n * \\endcode\n */\nint32_t rotation_get_reversed(uint8_t port);\n\n///@}\n\n#ifdef __cplusplus\n} //namespace C\n} //namespace pros\n} //extern \"C\"\n#endif\n\n#endif\n"
  },
  {
    "path": "include/pros/rotation.hpp",
    "content": "/**\n * \\file pros/rotation.hpp\n * \\ingroup cpp-rotation\n *\n * Contains prototypes for functions related to the VEX Rotation Sensor.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-rotation VEX Rotation Sensor C++ API\n */\n#ifndef _PROS_ROTATION_HPP_\n#define _PROS_ROTATION_HPP_\n\n#include <cstdint>\n#include <iostream>\n\n#include \"pros/device.hpp\"\n#include \"pros/rotation.h\"\n\nnamespace pros {\ninline namespace v5 {\n/**\n * \\ingroup cpp-rotation\n */\nclass Rotation : public Device {\n\t/**\n\t * \\addtogroup cpp-rotation\n\t * @{\n\t */\n\n\tpublic:\n\t/**\n\t * Constructs a new Rotation Sensor object\n\t *\n\t * ENXIO - The given value is not within the range of V5 ports |1-21|.\n\t * ENODEV - The port cannot be configured as a Rotation Sensor\n\t *\n\t * \\param port\n\t *        The V5 port number from 1 to 21, or from -21 to -1 for reversed Rotation Sensors.\n\t *\n\t * \t\\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \t pros::Rotation rotation_sensor(1); //Creates a Rotation Sensor on port 1\n\t *   pros::Rotation reversed_rotation_sensor(-2); //Creates a reversed Rotation Sensor on port 2\n\t * }\n\t * \\endcode\n\t */\n\tRotation(const std::int8_t port);\n\n\tRotation(const Device& device) : Rotation(device.get_port()){};\n\n\n\t/**\n\t * Reset the Rotation Sensor\n\t *\n\t * Reset the current absolute position to be the same as the\n\t * Rotation Sensor angle.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Rotation Sensor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Rotation rotation_sensor(1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     if(master.get_analog(E_CONTROLLER_DIGITAL_X) {\n\t * \t     rotation_sensor.reset();\n\t *     }\n\t *     pros::delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t reset();\n\n\t/**\n\t * Set the Rotation Sensor's refresh interval in milliseconds.\n\t *\n\t * The rate may be specified in increments of 5ms, and will be rounded down to\n\t * the nearest increment. The minimum allowable refresh rate is 5ms. The default\n\t * rate is 10ms.\n\t *\n\t * As values are copied into the shared memory buffer only at 10ms intervals,\n\t * setting this value to less than 10ms does not mean that you can poll the\n\t * sensor's values any faster. However, it will guarantee that the data is as\n\t * recent as possible.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Rotation Sensor\n\t *\n\t * \\param rate The data refresh interval in milliseconds\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Rotation rotation_sensor(1);\n\t *   rotation_sensor.set_data_rate(5);\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_data_rate(std::uint32_t rate) const;\n\n\t/**\n\t * Set the Rotation Sensor position reading to a desired rotation value\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Rotation Sensor\n\t *\n\t * \\param position\n\t * \t\t  The position in terms of ticks\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Rotation rotation_sensor(1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     if(master.get_analog(E_CONTROLLER_DIGITAL_X) {\n\t * \t     rotation_sensor.set_position(600);\n\t *     }\n\t *     pros::delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_position(std::int32_t position) const;\n\n\t/**\n\t * Reset the Rotation Sensor position to 0\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Rotation Sensor\n\t *\n\t * \\param position\n\t * \t\t  The position in terms of ticks\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Rotation rotation_sensor(1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     if(master.get_analog(E_CONTROLLER_DIGITAL_X) {\n\t * \t     rotation_sensor.reset_position();\n\t *     }\n\t *     pros::delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t reset_position(void) const;\n\n\t/**\n\t * Gets all rotation sensors.\n\t * \n\t * \\return A vector of Rotation sensor objects.\n\t *\n\t * \\b Example\n \t * \\code\n\t * void opcontrol() {\n\t *   std::vector<Rotation> rotation_all = pros::Rotation::get_all_devices();  // All rotation sensors that are connected\n\t * }\n \t * \\endcode\n\t */\n\tstatic std::vector<Rotation> get_all_devices();\n\n\t/**\n\t * Get the Rotation Sensor's current position in centidegrees\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Rotation Sensor\n\t *\n\t * \\return The position value or PROS_ERR if the operation failed, setting\n\t * errno.\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \t pros::Rotation rotation_sensor(1);\n\t *   while (true) {\n\t *     printf(\"Position: %d Ticks \\n\", rotation_sensor.get_position());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get_position() const;\n\n\t/**\n\t * Get the Rotation Sensor's current velocity in centidegrees per second\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Rotation Sensor\n\t *\n\t * \\param  port\n\t * \t\t\t\t The V5 Rotation Sensor port number from 1-21\n\t * \\return The velocity value or PROS_ERR if the operation failed, setting\n\t * errno.\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \t pros::Rotation rotation_sensor(1);\n\t *   while (true) {\n\t *     printf(\"Velocity: %d centidegrees per second \\n\", rotation_sensor.get_velocity));\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get_velocity() const;\n\n\t/**\n\t * Get the Rotation Sensor's current position in centidegrees\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Rotation Sensor\n\t *\n\t * \\return The angle value or PROS_ERR if the operation failed, setting\n\t * errno.\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \t pros::Rotation rotation_sensor(1);\n\t *   while (true) {\n\t *     printf(\"Angle: %d centidegrees \\n\", rotation_sensor.get_angle());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get_angle() const;\n\n\t/**\n\t * Set the Rotation Sensor's direction reversed flag\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Rotation Sensor\n\t *\n\t * \\param  value\n\t * \t\t\t\t Determines if the direction of the rotational sensor is\n\t * \t\t\t\t reversed or not.\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Rotation rotation_sensor(1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     if(master.get_analog(E_CONTROLLER_DIGITAL_X) {\n\t * \t     rotation_sensor.set_reversed(true); // Reverses the Rotation Sensor\n\t *     }\n\t *     pros::delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_reversed(bool value) const;\n\n\t/**\n\t * Reverse the Rotation Sensor's direction.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Rotation Sensor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Rotation rotation_sensor(1);\n\t *   pros::Controller master (E_CONTROLLER_MASTER);\n\t *   while (true) {\n\t *     if(master.get_analog(E_CONTROLLER_DIGITAL_X) {\n\t * \t     rotation_sensor.reverse();\n\t *     }\n\t *     pros::delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t reverse() const;\n\n\t/**\n\t * Get the Rotation Sensor's reversed flag\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as an Rotation Sensor\n\t *\n\t * \\return Reversed value or PROS_ERR if the operation failed, setting\n\t * errno.\n\t *\n\t *  \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t * \t pros::Rotation rotation_sensor(1);\n\t *   while (true) {\n\t *     printf(\"Reversed: %d \\n\", rotation_sensor.get_reversed());\n\t *     delay(20);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get_reversed() const;\n\n\t/**\n\t * This is the overload for the << operator for printing to streams\n\t *\n\t * Prints in format(this below is all in one line with no new line):\n\t * Rotation [port: rotation._port, position: (rotation position), velocity: (rotation velocity),\n\t * angle: (rotation angle), reversed: (reversed boolean)]\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define ROTATION_PORT 1\n\t *\n\t * void opcontrol() {\n\t * \tpros::Rotation rotation_sensor(1);\n\t *  while(true) {\n\t *\t\tstd::cout << rotation_sensor << std::endl;\n\t *  \tpros::delay(20);\n\t *  }\n\t * }\n\t * \\endcode\n\t */\n\tfriend std::ostream& operator<<(std::ostream& os, const pros::Rotation& rotation);\n\n\t///@}\n};\n\nnamespace literals {\n/**\n * Constructs a Rotation sensor from a literal ending in _rot\n *\n * \\return a pros::Rotation for the corresponding port\n *\n * \\b Example\n * \\code\n * using namespace pros::literals;\n * void opcontrol() {\n *\tpros::Rotation rotation = 2_rot; //Makes an Motor object on port 2\n * }\n * \\endcode\n */\nconst pros::Rotation operator\"\"_rot(const unsigned long long int r);\n}  // namespace literals\n}  // namespace v5\n}  // namespace pros\n\n#endif\n"
  },
  {
    "path": "include/pros/rtos.h",
    "content": "/**\n * \\file pros/rtos.h\n * \\ingroup c-rtos\n *\n * Contains declarations for the PROS RTOS kernel for use by typical VEX\n * programmers.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup c-rtos RTOS Facilities C API\n * \\note Additional example code for this module can be found in its [Tutorial.](@ref multitasking)\n */\t\n\n#ifndef _PROS_RTOS_H_\n#define _PROS_RTOS_H_\n\n#include <stdbool.h>\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\n#endif\n\n/// \\ingroup c-rtos\n\n/// \\addtogroup c-rtos \n/// @{\n\n/// \\name Macros \n/// @{\n\n/**\n * The highest priority that can be assigned to a task.\n * \n * A task with this priority will always run if it is available to. Beware of\n * deadlocks when using this priority.\n */\n#define TASK_PRIORITY_MAX 16\n\n/**\n * The lowest priority that can be assigned to a task.\n *\n * This can cause severe performance problems and is generally not recommended\n * that users use this priority.\n */\n#define TASK_PRIORITY_MIN 1\n\n/**\n * The default task priority, which should be used for most tasks unless you\n * have a specific need for a higher or lower priority task.\n * \n * The default tasks, such as autonomous(), are run with this priority\n */\n#define TASK_PRIORITY_DEFAULT 8\n\n/**\n * The recommended stack size for a new task.\n * \n * This stack size is used for the default tasks such as autonomous(). This\n * size is 8,192 words, or 32,768 bytes. This should be enough for the majority\n * of tasks\n */\n#define TASK_STACK_DEPTH_DEFAULT 0x2000\n\n/**\n * The minimal stack size for a task.\n * \n * This equates to 512 words, or 2,048 bytes. \n */\n#define TASK_STACK_DEPTH_MIN 0x200\n\n/**\n * The maximum number of characters allowed in a task's name.\n */\n#define TASK_NAME_MAX_LEN 32\n\n/**\n * The maximum timeout value that can be given to, for instance, a mutex grab.\n */\n#define TIMEOUT_MAX ((uint32_t)0xffffffffUL)\n\n/// @} Name: Macros\n\n/// \\name Typedefs\n/// @{\n\n/**\n * An opaque type that points to a task handle. This is used for referencing a\n * task.\n */\ntypedef void* task_t;\n\n/**\n * A pointer to a task's function. \n * \n * Such a function is called when a task starts, and exiting said function will\n * terminate the task.\n */\ntypedef void (*task_fn_t)(void*);\n\n/// @} Name: Typedefs\n\n\n/// \\name Enumerations\n/// @{\n\n/**\n * The state of a task.\n */\ntypedef enum {\n\tE_TASK_STATE_RUNNING = 0, /**< The task is actively executing. */\n\tE_TASK_STATE_READY, /**< The task exists and is available to run, but is not currently running. */\n\tE_TASK_STATE_BLOCKED, /**< The task is delayed or blocked by a mutex, semaphore, or I/O operation. */\n\tE_TASK_STATE_SUSPENDED, /**< The task is supended using task_suspend. */\n\tE_TASK_STATE_DELETED, /**< The task has been deleted using task_delete. */\n\tE_TASK_STATE_INVALID /**< The task handle does not point to a current or past task.*/\n} task_state_e_t;\n\n/**\n * brief The action to take when a task is notified.\n */\ntypedef enum {\n\tE_NOTIFY_ACTION_NONE, /**< The task’s notification value will not be touched.*/\n\tE_NOTIFY_ACTION_BITS, /**< The task’s notification value will be bitwise ORed with the new value.*/\n\tE_NOTIFY_ACTION_INCR, /**< The task’s notification value will be incremented by one, effectively using it as a notification counter.*/\n\tE_NOTIFY_ACTION_OWRITE, /**< The task’s notification value will be unconditionally set to the new value.*/\n\tE_NOTIFY_ACTION_NO_OWRITE /**< The task’s notification value will be set to the new value if the task does not already have a pending notification.*/\n} notify_action_e_t;\n\n/// @} Name: Enumerations\n\n/// \\name Simple enum names\n/// @{\n\n#ifdef PROS_USE_SIMPLE_NAMES\n#ifdef __cplusplus\n#define TASK_STATE_RUNNING pros::E_TASK_STATE_RUNNING\n#define TASK_STATE_READY pros::E_TASK_STATE_READY\n#define TASK_STATE_BLOCKED pros::E_TASK_STATE_BLOCKED\n#define TASK_STATE_SUSPENDED pros::E_TASK_STATE_SUSPENDED\n#define TASK_STATE_DELETED pros::E_TASK_STATE_DELETED\n#define TASK_STATE_INVALID pros::E_TASK_STATE_INVALID\n#define NOTIFY_ACTION_NONE pros::E_NOTIFY_ACTION_NONE\n#define NOTIFY_ACTION_BITS pros::E_NOTIFY_ACTION_BITS\n#define NOTIFY_ACTION_INCR pros::E_NOTIFY_ACTION_INCR\n#define NOTIFY_ACTION_OWRITE pros::E_NOTIFY_ACTION_OWRITE\n#define NOTIFY_ACTION_NO_OWRITE pros::E_NOTIFY_ACTION_NO_OWRITE\n#else\n#define TASK_STATE_RUNNING E_TASK_STATE_RUNNING\n#define TASK_STATE_READY E_TASK_STATE_READY\n#define TASK_STATE_BLOCKED E_TASK_STATE_BLOCKED\n#define TASK_STATE_SUSPENDED E_TASK_STATE_SUSPENDED\n#define TASK_STATE_DELETED E_TASK_STATE_DELETED\n#define TASK_STATE_INVALID E_TASK_STATE_INVALID\n#define NOTIFY_ACTION_NONE E_NOTIFY_ACTION_NONE\n#define NOTIFY_ACTION_BITS E_NOTIFY_ACTION_BITS\n#define NOTIFY_ACTION_INCR E_NOTIFY_ACTION_INCR\n#define NOTIFY_ACTION_OWRITE E_NOTIFY_ACTION_OWRITE\n#define NOTIFY_ACTION_NO_OWRITE E_NOTIFY_ACTION_NO_OWRITE\n#endif\n#endif\n\n/// @} Name: Simple enum names\n\n/// \\name Typedefs\n\n/**\n * A [mutex.](@ref multitasking)\n * \n * A mutex is a synchronization object that can be used to protect a shared\n * resource from being accessed by multiple tasks at the same time. A mutex can \n * be claimed by a task, which will prevent other tasks from claiming it until\n * that task releases it.\n */\ntypedef void* mutex_t;\n\n/// @} Name: Typedefs\n\n/**\n * The task handle of the currently running task. \n */\n#ifdef __cplusplus\n#define CURRENT_TASK ((pros::task_t)NULL)\n#else\n#define CURRENT_TASK ((task_t)NULL)\n#endif\n\n/// @} (add to group: c-rtos)\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n/// \\ingroup c-rtos\n/// \\addtogroup c-rtos\n/// @{\n\n/**\n * Gets the number of milliseconds since PROS initialized.\n *\n * \\return The number of milliseconds since PROS initialized\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   uint32_t now = millis();\n *   while (true) {\n *     // Do opcontrol things\n *     task_delay_until(&now, 2);\n *   }\n * }\n * \\endcode\n */\nuint32_t millis(void);\n\n/**\n * Gets the number of microseconds since PROS initialized,\n * \n * \\return The number of microseconds since PROS initialized\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   uint64_t now = micros();\n *   while (true) {\n *     // Do opcontrol things\n *     task_delay_until(&now, 2000);\n *   }\n * }\n * \\endcode\n */\nuint64_t micros(void);\n\n/**\n * Creates a new task and add it to the list of tasks that are ready to run.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENOMEM - The stack cannot be used as the TCB was not created.\n *\n * \\param function\n *        Pointer to the task entry function\n * \\param parameters\n *        Pointer to memory that will be used as a parameter for the task being\n *        created. This memory should not typically come from stack, but rather\n *        from dynamically (i.e., malloc'd) or statically allocated memory.\n * \\param prio\n *        The priority at which the task should run.\n *        TASK_PRIO_DEFAULT plus/minus 1 or 2 is typically used.\n * \\param stack_depth\n *        The number of words (i.e. 4 * stack_depth) available on the task's\n *        stack. TASK_STACK_DEPTH_DEFAULT is typically sufficienct.\n * \\param name\n *        A descriptive name for the task.  This is mainly used to facilitate\n *        debugging. The name may be up to 32 characters long.\n *\n * \\return A handle by which the newly created task can be referenced. If an\n * error occurred, NULL will be returned and errno can be checked for hints as\n * to why task_create failed.\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* param) {\n *   printf(\"Hello %s\\n\", (char*)param);\n *   // ...\n * }\n * \n * void initialize() {\n *   task_t my_task = task_create(my_task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                               TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n * }\n * \\endcode\n */\ntask_t task_create(task_fn_t function, void* const parameters, uint32_t prio, const uint16_t stack_depth,\n                   const char* const name);\n\n/**\n * Removes a task from the RTOS real time kernel's management. The task being\n * deleted will be removed from all ready, blocked, suspended and event lists.\n *\n * Memory dynamically allocated by the task is not automatically freed, and\n * should be freed before the task is deleted.\n *\n * \\param task\n *        The handle of the task to be deleted.  Passing NULL will cause the\n *        calling task to be deleted.\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* param) {\n *   printf(\"Hello %s\\n\", (char*)param);\n *   // ...\n * }\n * \n * void initialize() {\n *   task_t my_task = task_create(my_task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                            TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n *   // Do other things\n *   task_delete(my_task);\n * }\n * \\endcode\n */\nvoid task_delete(task_t task);\n\n/**\n * Delays the current task for a given number of milliseconds.\n *\n * This is not the best method to have a task execute code at predefined\n * intervals, as the delay time is measured from when the delay is requested.\n * To delay cyclically, use task_delay_until().\n *\n * \\param milliseconds\n *        The number of milliseconds to wait (1000 milliseconds per second)\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   while (true) {\n *     // Do opcontrol things\n *     task_delay(2);\n *   }\n * }\n * \\endcode\n */\nvoid task_delay(const uint32_t milliseconds);\n\n/**\n * Delays the current task for a given number of milliseconds.\n * \n * This is not the best method to have a task execute code at predefined\n * intervals, as the delay time is measured from when the delay is requested.\n * To delay cyclically, use task_delay_until().\n * \n * \\param milliseconds\n *        The number of milliseconds to wait (1000 milliseconds per second)\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n * while (true) {\n *   // Do opcontrol things\n *   delay(2);\n *   }\n * }\n * \\endcode\n */\nvoid delay(const uint32_t milliseconds);\n\n/**\n * Delays the current task until a specified time.  This function can be used \n * by periodic tasks to ensure a constant execution frequency.\n *\n * The task will be woken up at the time *prev_time + delta, and *prev_time will\n * be updated to reflect the time at which the task will unblock.\n *\n * \\param prev_time\n *        A pointer to the location storing the setpoint time. This should\n *        typically be initialized to the return value of millis().\n * \\param delta\n *        The number of milliseconds to wait (1000 milliseconds per second)\n * \n * \\b Example\n * \\code\n * void opcontrol() {\n *   uint32_t now = millis();\n *   while (true) {\n *     // Do opcontrol things\n *     task_delay_until(&now, 2);\n *   }\n * }\n * \\endcode\n */\nvoid task_delay_until(uint32_t* const prev_time, const uint32_t delta);\n\n/**\n * Gets the priority of the specified task.\n *\n * \\param task\n *        The task to check\n *\n * \\return The priority of the task\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* param) {\n *   printf(\"Hello %s\\n\", (char*)param);\n *   // ...\n * }\n * \n * void initialize() {\n *   task_t my_task = task_create(my_task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                            TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n *   printf(\"Task Priority: %d\\n\", task_get_priority(my_task));\n * }\n * \\endcode\n */\nuint32_t task_get_priority(task_t task);\n\n/**\n * Sets the priority of the specified task.\n *\n * If the specified task's state is available to be scheduled (e.g. not blocked)\n * and new priority is higher than the currently running task, a context switch\n * may occur.\n *\n * \\param task\n *        The task to set\n * \\param prio\n *        The new priority of the task\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* ign) {\n *   // Do things\n * }\n * \n * void opcontrol() {\n *   task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT,\n *                             TASK_STACK_DEPTH_DEFAULT, \"Example Task\");\n *   task_set_priority(my_task, TASK_PRIORITY_DEFAULT + 1);\n * }\n * \\endcode\n */\nvoid task_set_priority(task_t task, uint32_t prio);\n\n/**\n * Gets the state of the specified task.\n *\n * \\param task\n *        The task to check\n *\n * \\return The state of the task\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* param) {\n *   printf(\"Hello %s\\n\", (char*)param);\n *   // ...\n * }\n * \n * void initialize() {\n *   task_t my_task = task_create(my_task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                            TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n *   printf(\"Task's State: %d\\n\", task_get_state(my_task));\n * }\n * \\endcode\n */\ntask_state_e_t task_get_state(task_t task);\n\n/**\n * Suspends the specified task, making it ineligible to be scheduled.\n *\n * \\param task\n *        The task to suspend\n * \n * \\b Example\n * \\code\n * mutex_t counter_mutex;\n * int counter = 0;\n * \n * void my_task_fn(void* param) {\n *   while(true) {\n *     mutex_take(counter_mutex, TIMEOUT_MAX);// Mutexes are used for protecting shared resources\n *     counter++;\n *     mutex_give(counter_mutex);\n *     pros::delay(10);\n *   }\n * }\n * \n * void opcontrol() {\n *   task_t task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT,;\n * \n *   while(true) {\n * \t   mutex_take(counter_mutex, TIMEOUT_MAX);\n *     if(counter > 100) {\n *       task_suspepend(task);\n * \t   }\n *     mutex_give(counter_mutex);\n *     pros::delay(10);\n *   }\n * }\n * \\endcode\n */\nvoid task_suspend(task_t task);\n\n/**\n * Resumes the specified task, making it eligible to be scheduled.\n *\n * \\param task\n *        The task to resume\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* param) {\n *   while(true) {\n *     // Do stuff\n *     delay(10);\n *   }\n * }\n * \n * task_t task;\n * \n * void initialize() {\n *   task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT,\n * \t\t\t\t\tTASK_STACK_DEPTH_DEFAULT, \"My Task\");\n * }\n * \n * void autonomous() {\n *   task_resume(task);\n * \n *   // Run autonomous , then suspend the task so it doesn't interfere run\n *   \n *   // outside of autonomous or opcontrol\n *   task_suspend(task);\n * }\n * \n * void opcontrol() {\n *   task_resume(task);\n *   // Opctonrol code here\n *   task_suspend(task);\n * }\n * \n * \\endcode\n */\nvoid task_resume(task_t task);\n\n/**\n * Gets the number of tasks the kernel is currently managing, including all\n * ready, blocked, or suspended tasks. A task that has been deleted, but not yet\n * reaped by the idle task will also be included in the count. Tasks recently\n * created may take one context switch to be counted.\n *\n * \\return The number of tasks that are currently being managed by the kernel.\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* param) {\n *   printf(\"Hello %s\\n\", (char*)param);\n *   // ...\n * }\n * \n * void initialize() {\n *   task_t my_task = task_create(my_task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                            TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n *   printf(\"Number of Running Tasks: %d\\n\", task_get_count());\n * }\n * \\endcode\n */\nuint32_t task_get_count(void);\n\n/**\n * Gets the name of the specified task.\n *\n * \\param task\n *        The task to check\n *\n * \\return A pointer to the name of the task\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* param) {\n *   printf(\"Hello %s\\n\", (char*)param);\n *   // ...\n * }\n * \n * void initialize() {\n *   task_t my_task = task_create(my_task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                            TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n *   printf(\"Task Name: %d\\n\", task_get_name(my_task));\n * }\n * \\endcode\n */\nchar* task_get_name(task_t task);\n\n/**\n * Gets a task handle from the specified name\n *\n * The operation takes a relatively long time and should be used sparingly.\n *\n * \\param name\n *        The name to query\n *\n * \\return A task handle with a matching name, or NULL if none were found.\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* param) {\n *   printf(\"Hello %s\\n\", (char*)param);\n *   // ...\n * }\n * \n * void initialize() {\n *   task_t my_task = task_create(my_task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                            TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n *   // Do other things\n *   task_delete(task_get_by_name(\"My Task\"));\n * }\n * \\endcode\n */\ntask_t task_get_by_name(const char* name);\n\n/**\n * Get the currently running task handle. This could be useful if a task\n * wants to tell another task about itself.\n *\n * \\return The currently running task handle.\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* param) {\n *   task_t this_task = task_get_current();\n *   if (task_get_state(this_take) == E_TASK_STATE_RUNNING) {\n *     printf(\"This task is currently running\\n\");\n *   }\n * // ...\n * }\n * \n * void initialize() {\n *   task_t my_task = task_create(my_task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                            TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n * }\n * \\endcode\n */\ntask_t task_get_current();\n\n/**\n * Sends a simple notification to task and increments the notification counter.\n *\n * \\param task\n *        The task to notify\n *\n * \\return Always returns true.\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* ign) {\n *   while(task_notify_take(true) == 0) {\n *     // Code while waiting\n *   }\n *   puts(\"I was unblocked!\");\n * }\n * \n * void opcontrol() {\n *   task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT,\n *                             TASK_STACK_DEPTH_DEFAULT, \"Notify me! Task\");\n *   while(true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) {\n *       task_notify(my_task);\n *     }\n *   }\n * }\n * \\endcode\n */\nuint32_t task_notify(task_t task);\n\n/**\n * \n * Utilizes task notifications to wait until specified task is complete and deleted,\n * then continues to execute the program. Analogous to std::thread::join in C++.\n * \n * \\param task\n *        The handle of the task to wait on.\n * \n * \\return void\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* ign) {\n *   lcd_print(1, \"%s running\", task_get_name(NULL));\n *   task_delay(1000);\n *   lcd_print(2, \"End of %s\", task_get_name(NULL));\n * }\n * \n * void opcontrol() {\n *   task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT,\n *                             TASK_STACK_DEPTH_DEFAULT, \"Example Task\");\n *   lcd_set_text(0, \"Running task.\");\n *   task_join(my_task);\n *   lcd_set_text(3, \"Task completed.\");\n * }\n * \\endcode\n */\nvoid task_join(task_t task);\n\n/**\n * Sends a notification to a task, optionally performing some action. Will also\n * retrieve the value of the notification in the target task before modifying\n * the notification value.\n *\n * \\param task\n *        The task to notify\n * \\param value\n *        The value used in performing the action\n * \\param action\n *        An action to optionally perform on the receiving task's notification\n *        value\n * \\param prev_value\n *        A pointer to store the previous value of the target task's\n *        notification, may be NULL\n *\n * \\return Dependent on the notification action.\n * For NOTIFY_ACTION_NO_WRITE: return 0 if the value could be written without\n * needing to overwrite, 1 otherwise.\n * For all other NOTIFY_ACTION values: always return 0\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* param) {\n *   while(true) {\n *     // Wait until we have been notified 20 times before running the code\n *     if(task_notify_take(false, TIMEOUT_MAX) == 20) {\n *       // ... Code to do stuff here ...\n * \n *       // Reset the notification counter\n *       task_notify_take(true, TIMEOUT_MAX);\n *     }\n *     delay(10);\n * \t }\n * }\n * \n * void opcontrol() {\n * \t task_t task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT,\n * \t\t\t\t\t\t   TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n *   \n *   int count = 0;\n *   \n *   while(true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) {\n *       task_notify_ext(task, 1, NOTIFY_ACTION_INCREMENT, &count);\n *     }\n *     \n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nuint32_t task_notify_ext(task_t task, uint32_t value, notify_action_e_t action, uint32_t* prev_value);\n\n/**\n * Waits for a notification to be nonzero.\n *\n * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for\n * details.\n *\n * \\param clear_on_exit\n *        If true (1), then the notification value is cleared.\n *        If false (0), then the notification value is decremented.\n * \\param timeout\n *        Specifies the amount of time to be spent waiting for a notification\n *        to occur.\n *\n * \\return The value of the task's notification value before it is decremented\n * or cleared\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* ign) {\n *   task_t current_task = task_get_current();\n *   while(task_notify_take(current_task, true, TIMEOUT_MAX)) {\n *     puts(\"I was unblocked!\");\n *   }\n * }\n * \n * void opcontrol() {\n *   task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT,\n *                             TASK_STACK_DEPTH_DEFAULT, \"Notify me! Task\");\n *   while(true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) {\n *       task_notify(my_task);\n *     }\n *   }\n * }\n * \\endcode\n */\nuint32_t task_notify_take(bool clear_on_exit, uint32_t timeout);\n\n/**\n * Clears the notification for a task.\n *\n * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for\n * details.\n *\n * \\param task\n *        The task to clear\n *\n * \\return False if there was not a notification waiting, true if there was\n * \n * \\b Example\n * \\code\n * void my_task_fn(void* param) {\n *   task_t task = task_get_current();\n *   while(true) {\n *     printf(\"Waiting for notification...\\n\");\n * \t   printf(\"Got a notification: %d\\n\", task_notify_take(task, false, TIMEOUT_MAX));\n * \n * \t   task_notify_clear(task);\n *     delay(10):\n *   }\n * }\n * \n * void opcontrol() {\n *  task_t task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT,\n *                            TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n * \n *   while(true) {\n *     if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) {\n *       task_notify(task);\n *     }\n *     delay(10);\n *   }\n * }\n * \\endcode\n */\nbool task_notify_clear(task_t task);\n\n/**\n * Creates a mutex.\n *\n * See https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html#mutexes\n * for details.\n *\n * \\return A handle to a newly created mutex. If an error occurred, NULL will be\n * returned and errno can be checked for hints as to why mutex_create failed.\n * \n * \\b Example\n * \\code\n * // Global variables for the robot's odometry, which the rest of the robot's\n * // subsystems will utilize\n * double odom_x = 0.0;\n * double odom_y = 0.0;\n * double odom_heading = 0.0;\n * \n * // This mutex protects the odometry data. Whenever we read or write to the\n * // odometry data, we should make copies into the local variables, and read\n * // all 3 values at once to avoid errors.\n * mutex_t odom_mutex;\n * \n * void odom_task(void* param) {\n *   while(true) {\n *     // First we fetch the odom coordinates from the previous iteration of the\n *     // odometry task. These are put into local variables so that we can\n *     // keep the size of the critical section as small as possible. This lets\n *     // other tasks that need to use the odometry data run until we need to\n *     // update it again.\n *     mutex_take(odom_mutex, MAX_DELAY);\n *     double x_old = odom_x;\n *     double y_old = odom_y;\n *     double heading_old = odom_heading;\n * \t   mutex_give(odom_mutex);\n * \n *     double x_new = 0.0;\n *     double y_new = 0.0;\n *     double heading_new = 0.0;\n *     \n *     // --- Calculate new pose for the robot here ---\n * \n *     // Now that we have the new pose, we can update the global variables\n *     mutex_take(odom_mutex, MAX_DELAY);\n *     odom_x = x_new;\n *     odom_y = y_new;\n *     odom_heading = heading_new;\n *     mutex_give(odom_mutex);\n *     \n *     delay(10);\n *   }\n * }\n * \n * void chassis_task(void* param) {\n *   while(true) {\n *     // Here we copy the current odom values into local variables so that\n *     // we can use them without worrying about the odometry task changing say,\n *     // the y value right after we've read the x. This ensures our values are\n *     // sound.\n *     mutex_take(odom_mutex, MAX_DELAY);\n *     double current_x = odom_x;\n *     double current_y = odom_y;\n *     double current_heading = odom_heading;\n *     mutex_give(odom_mutex);\n *     \n *     // ---- Move the robot using the current locations goes here ----\n *     \n *     delay(10);\n *   }\n * }\n * \n * void initialize() {\n *   odom_mutex = mutex_create();\n * \n *   task_create(odom_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"Odometry Task\");\n *   task_create(chassis_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"Chassis Task\");\n * }\n * \\endcode\n */\nmutex_t mutex_create(void);\n\n/**\n * Takes and locks a mutex, waiting for up to a certain number of milliseconds\n * before timing out.\n *\n * See https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html#mutexes\n * for details.\n *\n * \\param mutex\n *        Mutex to attempt to lock.\n * \\param timeout\n *        Time to wait before the mutex becomes available. A timeout of 0 can\n *        be used to poll the mutex. TIMEOUT_MAX can be used to block\n *        indefinitely.\n *\n * \\return True if the mutex was successfully taken, false otherwise. If false\n * is returned, then errno is set with a hint about why the the mutex\n * couldn't be taken.\n * \n * \\b Example\n * \\code\n * // Global variables for the robot's odometry, which the rest of the robot's\n * // subsystems will utilize\n * double odom_x = 0.0;\n * double odom_y = 0.0;\n * double odom_heading = 0.0;\n * \n * // This mutex protects the odometry data. Whenever we read or write to the\n * // odometry data, we should make copies into the local variables, and read\n * // all 3 values at once to avoid errors.\n * mutex_t odom_mutex;\n * \n * void odom_task(void* param) {\n *   while(true) {\n *     // First we fetch the odom coordinates from the previous iteration of the\n *     // odometry task. These are put into local variables so that we can\n *     // keep the size of the critical section as small as possible. This lets\n *     // other tasks that need to use the odometry data run until we need to\n *     // update it again.\n *     mutex_take(odom_mutex, MAX_DELAY);\n *     double x_old = odom_x;\n *     double y_old = odom_y;\n *     double heading_old = odom_heading;\n * \t   mutex_give(odom_mutex);\n * \n *     double x_new = 0.0;\n *     double y_new = 0.0;\n *     double heading_new = 0.0;\n *     \n *     // --- Calculate new pose for the robot here ---\n * \n *     // Now that we have the new pose, we can update the global variables\n *     mutex_take(odom_mutex, MAX_DELAY);\n *     odom_x = x_new;\n *     odom_y = y_new;\n *     odom_heading = heading_new;\n *     mutex_give(odom_mutex);\n *     \n *     delay(10);\n *   }\n * }\n * \n * void chassis_task(void* param) {\n *   while(true) {\n *     // Here we copy the current odom values into local variables so that\n *     // we can use them without worrying about the odometry task changing say,\n *     // the y value right after we've read the x. This ensures our values are\n *     // sound.\n *     mutex_take(odom_mutex, MAX_DELAY);\n *     double current_x = odom_x;\n *     double current_y = odom_y;\n *     double current_heading = odom_heading;\n *     mutex_give(odom_mutex);\n *     \n *     // ---- Move the robot using the current locations goes here ----\n *     \n *     delay(10);\n *   }\n * }\n * \n * void initialize() {\n *   odom_mutex = mutex_create();\n * \n *   task_create(odom_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"Odometry Task\");\n *   task_create(chassis_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"Chassis Task\");\n * }\n * \\endcode\n */\nbool mutex_take(mutex_t mutex, uint32_t timeout);\n\n/**\n * Unlocks a mutex.\n *\n * See https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html#mutexes\n * for details.\n *\n * \\param mutex\n *        Mutex to unlock.\n *\n * \\return True if the mutex was successfully returned, false otherwise. If\n * false is returned, then errno is set with a hint about why the mutex\n * couldn't be returned.\n * \n * \\b Example\n * \\code\n * // Global variables for the robot's odometry, which the rest of the robot's\n * // subsystems will utilize\n * double odom_x = 0.0;\n * double odom_y = 0.0;\n * double odom_heading = 0.0;\n * \n * // This mutex protects the odometry data. Whenever we read or write to the\n * // odometry data, we should make copies into the local variables, and read\n * // all 3 values at once to avoid errors.\n * mutex_t odom_mutex;\n * \n * void odom_task(void* param) {\n *   while(true) {\n *     // First we fetch the odom coordinates from the previous iteration of the\n *     // odometry task. These are put into local variables so that we can\n *     // keep the size of the critical section as small as possible. This lets\n *     // other tasks that need to use the odometry data run until we need to\n *     // update it again.\n *     mutex_take(odom_mutex, MAX_DELAY);\n *     double x_old = odom_x;\n *     double y_old = odom_y;\n *     double heading_old = odom_heading;\n * \t   mutex_give(odom_mutex);\n * \n *     double x_new = 0.0;\n *     double y_new = 0.0;\n *     double heading_new = 0.0;\n *     \n *     // --- Calculate new pose for the robot here ---\n * \n *     // Now that we have the new pose, we can update the global variables\n *     mutex_take(odom_mutex, MAX_DELAY);\n *     odom_x = x_new;\n *     odom_y = y_new;\n *     odom_heading = heading_new;\n *     mutex_give(odom_mutex);\n *     \n *     delay(10);\n *   }\n * }\n * \n * void chassis_task(void* param) {\n *   while(true) {\n *     // Here we copy the current odom values into local variables so that\n *     // we can use them without worrying about the odometry task changing say,\n *     // the y value right after we've read the x. This ensures our values are\n *     // sound.\n *     mutex_take(odom_mutex, MAX_DELAY);\n *     double current_x = odom_x;\n *     double current_y = odom_y;\n *     double current_heading = odom_heading;\n *     mutex_give(odom_mutex);\n *     \n *     // ---- Move the robot using the current locations goes here ----\n *     \n *     delay(10);\n *   }\n * }\n * \n * void initialize() {\n *   odom_mutex = mutex_create();\n * \n *   task_create(odom_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"Odometry Task\");\n *   task_create(chassis_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"Chassis Task\");\n * }\n * \\endcode\n */\nbool mutex_give(mutex_t mutex);\n\n/**\n * Creates a recursive mutex which can be locked recursively by the owner.\n *\n * \\return A newly created recursive mutex.\n * \n * \\b Example:\n * \\code\n * mutex_t mutex = mutex_recursive_create();\n * \n * void task_fn(void* param) {\n *   while(1) {\n *     mutex_recursive_take(mutex, 1000);\n *     // critical section\n *     mutex_recursive_give(mutex);\n *     task_delay(1000);\n *   }\n * }\n * task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn\");\n *\n * \\endcode\n */\nmutex_t mutex_recursive_create(void);\n\n/**\n * Takes a recursive mutex.\n *\n * \\param mutex\n *        A mutex handle created by mutex_recursive_create\n * \\param wait_time\n *        Amount of time to wait before timing out\n *\n * \\return 1 if the mutex was obtained, 0 otherwise\n * \n * \\b Example:\n * \\code\n * mutex_t mutex = mutex_recursive_create();\n *\n * void task_fn(void* param) {\n *   while(1) {\n *     mutex_recursive_take(mutex, 1000);\n *     // critical section\n *     mutex_recursive_give(mutex);\n *     task_delay(1000);\n *   }\n * }\n * task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn\");\n *\n * \\endcode\n */\nbool mutex_recursive_take(mutex_t mutex, uint32_t timeout);\n\n/**\n * Gives a recursive mutex.\n *\n * \\param mutex\n *        A mutex handle created by mutex_recursive_create\n *\n * \\return 1 if the mutex was obtained, 0 otherwise\n * \n * \\b Example:\n * \\code\n * mutex_t mutex = mutex_recursive_create();\n *\n * void task_fn(void* param) {\n *   while(1) {\n *     mutex_recursive_take(mutex, 1000);\n *     // critical section\n *     mutex_recursive_give(mutex);\n *     task_delay(1000);\n *   }\n * }\n * task_create(task_fn, (void*)\"PROS\", TASK_PRIORITY_DEFAULT,\n *                           TASK_STACK_DEPTH_DEFAULT, \"task_fn\");\n *\n * \\endcode\n */\nbool mutex_recursive_give(mutex_t mutex);\n\n/**\n * Deletes a mutex or recursive mutex\n *\n * \\param mutex\n *        Mutex to unlock.\n * \n * \\b Example\n * \\code\n * mutex_t mutex = mutex_create();\n * // Acquire the mutex; other tasks using this command will wait until the mutex is released\n * // timeout can specify the maximum time to wait, or MAX_DELAY to wait forever\n * // If the timeout expires, \"false\" will be returned, otherwise \"true\"\n * mutex_take(mutex, MAX_DELAY);\n * // do some work\n * // Release the mutex for other tasks\n * mutex_give(mutex);\n * // Delete the mutex\n * mutex_delete(mutex);\n * \\endcode\n */\nvoid mutex_delete(mutex_t mutex);\n\n/// @} Add to group: c-rtos\n\n#ifdef __cplusplus\n}  // namespace c\n}  // namespace pros\n}\n#endif\n\n#endif  // _PROS_RTOS_H_\n"
  },
  {
    "path": "include/pros/rtos.hpp",
    "content": "/**\n * \\file pros/rtos.hpp\n * \\ingroup cpp-rtos\n *\n * Contains declarations for the PROS RTOS kernel for use by typical VEX\n * programmers.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup cpp-rtos RTOS Facilities C++ API\n * \\note Additional example code for this module can be found in its [Tutorial.](@ref multitasking)\n */\n\n#ifndef _PROS_RTOS_HPP_\n#define _PROS_RTOS_HPP_\n\n#include \"pros/rtos.h\"\n#undef delay\n#include <atomic>\n#include <chrono>\n#include <cstdint>\n#include <cstdlib>\n#include <functional>\n#include <memory>\n#include <optional>\n#include <type_traits>\n\nnamespace pros {\ninline namespace rtos {\n/**\n * \\ingroup cpp-rtos\n */\nclass Task {\n\t/**\n\t * \\addtogroup cpp-rtos\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Creates a new task and add it to the list of tasks that are ready to run.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENOMEM - The stack cannot be used as the TCB was not created.\n\t *\n\t * \\param function\n\t *        Pointer to the task entry function\n\t * \\param parameters\n\t *        Pointer to memory that will be used as a parameter for the task\n\t *        being created. This memory should not typically come from stack,\n\t *        but rather from dynamically (i.e., malloc'd) or statically\n\t *        allocated memory.\n\t * \\param prio\n\t *        The priority at which the task should run.\n\t *        TASK_PRIO_DEFAULT plus/minus 1 or 2 is typically used.\n\t * \\param stack_depth\n\t *        The number of words (i.e. 4 * stack_depth) available on the task's\n\t *        stack. TASK_STACK_DEPTH_DEFAULT is typically sufficienct.\n\t * \\param name\n\t *        A descriptive name for the task.  This is mainly used to facilitate\n\t *        debugging. The name may be up to 32 characters long.\n\t * \n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   printf(\"Hello %s\\n\", (char*)param);\n\t *   // ...\n\t * }\n\t * \n\t * void initialize() {\n\t *   pros::Task my_task(my_task_fn, (void*)\"PROS\");\n\t * }\n\t * \\endcode\n\t */\n\tTask(task_fn_t function, void* parameters = nullptr, std::uint32_t prio = TASK_PRIORITY_DEFAULT,\n\t     std::uint16_t stack_depth = TASK_STACK_DEPTH_DEFAULT, const char* name = \"\");\n\n\t/**\n\t * Creates a new task and add it to the list of tasks that are ready to run.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENOMEM - The stack cannot be used as the TCB was not created.\n\t *\n\t * \\param function\n\t *        Pointer to the task entry function\n\t * \\param parameters\n\t *        Pointer to memory that will be used as a parameter for the task\n\t *        being created. This memory should not typically come from stack,\n\t *        but rather from dynamically (i.e., malloc'd) or statically\n\t *        allocated memory.\n\t * \\param name\n\t *        A descriptive name for the task.  This is mainly used to facilitate\n\t *        debugging. The name may be up to 32 characters long.\n\t * \n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   printf(\"Hello %s\\n\", (char*)param);\n\t *   // ...\n\t * }\n\t * \n\t * void initialize() {\n\t *   pros::Task my_task(my_task_fn, (void*)\"PROS\", \"My Task\");\n\t * }\n\t * \\endcode\n\t */\n\tTask(task_fn_t function, void* parameters, const char* name);\n\n\t/**\n\t * Creates a new task and add it to the list of tasks that are ready to run.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENOMEM - The stack cannot be used as the TCB was not created.\n\t *\n\t * \\param function\n\t *        Callable object to use as entry function\n\t * \\param prio\n\t *        The priority at which the task should run.\n\t *        TASK_PRIO_DEFAULT plus/minus 1 or 2 is typically used.\n\t * \\param stack_depth\n\t *        The number of words (i.e. 4 * stack_depth) available on the task's\n\t *        stack. TASK_STACK_DEPTH_DEFAULT is typically sufficienct.\n\t * \\param name\n\t *        A descriptive name for the task.  This is mainly used to facilitate\n\t *        debugging. The name may be up to 32 characters long.\n\t * \n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   printf(\"Hello %s\\n\", (char*)param);\n\t *   // ...\n\t * }\n\t * \n\t * void initialize() {\n\t *   pros::c::task_t my_task = pros::Task::create(my_task_fn, (void*)\"PROS\");\n\t * }\n\t * \\endcode\n\t */\n\ttemplate <class F>\n\tstatic task_t create(F&& function, std::uint32_t prio = TASK_PRIORITY_DEFAULT,\n\t                     std::uint16_t stack_depth = TASK_STACK_DEPTH_DEFAULT, const char* name = \"\") {\n\t\tstatic_assert(std::is_invocable_r_v<void, F>);\n\t\treturn pros::c::task_create(\n\t\t    [](void* parameters) {\n\t\t\t    std::unique_ptr<std::function<void()>> ptr{static_cast<std::function<void()>*>(parameters)};\n\t\t\t    (*ptr)();\n\t\t    },\n\t\t    new std::function<void()>(std::forward<F>(function)), prio, stack_depth, name);\n\t}\n\n\t/**\n\t * Creates a new task and add it to the list of tasks that are ready to run.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENOMEM - The stack cannot be used as the TCB was not created.\n\t *\n\t * \\param function\n\t *        Callable object to use as entry function\n\t * \\param name\n\t *        A descriptive name for the task.  This is mainly used to facilitate\n\t *        debugging. The name may be up to 32 characters long.\n\t * \n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   printf(\"Hello %s\\n\", (char*)param);\n\t *   // ...\n\t * }\n\t * \n\t * void initialize() {\n\t *   pros::c::task_t my_task = pros::Task::create(my_task_fn, \"My Task\");\n\t * }\n\t * \\endcode\n\t */\n\ttemplate <class F>\n\tstatic task_t create(F&& function, const char* name) {\n\t\treturn Task::create(std::forward<F>(function), TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, name);\n\t}\n\n\t/**\n\t * Creates a new task and add it to the list of tasks that are ready to run.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENOMEM - The stack cannot be used as the TCB was not created.\n\t *\n\t * \\param function\n\t *        Callable object to use as entry function\n\t * \\param prio\n\t *        The priority at which the task should run.\n\t *        TASK_PRIO_DEFAULT plus/minus 1 or 2 is typically used.\n\t * \\param stack_depth\n\t *        The number of words (i.e. 4 * stack_depth) available on the task's\n\t *        stack. TASK_STACK_DEPTH_DEFAULT is typically sufficient.\n\t * \\param name\n\t *        A descriptive name for the task.  This is mainly used to facilitate\n\t *        debugging. The name may be up to 32 characters long.\n\t * \n\t * \\b Example\n\t * \\code\n\t * \n\t * void initialize() {\n\t *   // Create a task function using lambdas\n\t *   auto task_fn = [](void* param) {\n\t *     printf(\"Hello %s\\n\", (char*)param);\n\t *   }\n\t * \n\t *   pros::Task my_task(task_fn, (void*)\"PROS\", \"My Task\");\n\t * }\n\t * \\endcode\n\t */\n\ttemplate <class F>\n\texplicit Task(F&& function, std::uint32_t prio = TASK_PRIORITY_DEFAULT,\n\t              std::uint16_t stack_depth = TASK_STACK_DEPTH_DEFAULT, const char* name = \"\")\n\t    : Task(\n\t          [](void* parameters) {\n\t\t          std::unique_ptr<std::function<void()>> ptr{static_cast<std::function<void()>*>(parameters)};\n\t\t          (*ptr)();\n\t          },\n\t          new std::function<void()>(std::forward<F>(function)), prio, stack_depth, name) {\n\t\tstatic_assert(std::is_invocable_r_v<void, F>);\n\t}\n\n\t/**\n\t * Creates a new task and add it to the list of tasks that are ready to run.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENOMEM - The stack cannot be used as the TCB was not created.\n\t *\n\t * \\param function\n\t *        Callable object to use as entry function\n\t * \\param name\n\t *        A descriptive name for the task.  This is mainly used to facilitate\n\t *        debugging. The name may be up to 32 characters long.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   printf(\"Hello %s\\n\", (char*)param);\n\t *   // ...\n\t * }\n\t * \n\t * void initialize() {\n\t *   pros::Task my_task(\n\t *     [](void* param) {\n\t *       printf(\"Inside the task!\\n\");\n\t *     },\n\t *     \"My Task\"\n\t *   );\n\t * }\n\t * \\endcode\n\t */\n\ttemplate <class F>\n\tTask(F&& function, const char* name)\n\t    : Task(std::forward<F>(function), TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, name) {}\n\n\t/**\n\t * Create a C++ task object from a task handle\n\t *\n\t * \\param task\n\t *        A task handle from task_create() for which to create a pros::Task\n\t *        object.\n\t * \n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   printf(\"Hello %s\\n\", (char*)param);\n\t *   // ...\n\t * }\n\t * \n\t * void initialize() {\n\t *   pros::c::task_t my_task = pros::Task::create(my_task_fn, \"My Task\");\n\t * \n\t *   pros::Task my_task_cpp(my_task);\n\t * }\n\t * \\endcode\n\t */\n\texplicit Task(task_t task);\n\n\t/**\n\t * Get the currently running Task\n\t * \n\t * @return The currently running Task.\n\t * \n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   printf(\"The name of this task is \\\"%s\\\"\\n\", pros::Task::current().get_name()\n\t * }\n\t * \n\t * void initialize() {\n\t *   pros::Task my_task(my_task_fn, pros::TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n\t * }\n\t * \\endcode\n\t */\n\tstatic Task current();\n\n\t/**\n\t * Creates a task object from the passed task handle.\n\t *\n\t * \\param in\n\t *        A task handle from task_create() for which to create a pros::Task\n\t *        object.\n\t * \n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   printf(\"The name of this task is \\\"%s\\\"\\n\", pros::Task::current().get_name()\n\t * }\n\t * \n\t * void initialize() {\n\t *   pros::c::task_t my_task = pros::Task::create(my_task_fn, \"My Task\");\n\t * \n\t *   pros::Task my_task_cpp = my_task;\n\t * }\n\t * \\endcode\n\t */\n\tTask& operator=(task_t in);\n\n\t/**\n\t * Removes the Task from the RTOS real time kernel's management. This task\n\t * will be removed from all ready, blocked, suspended and event lists.\n\t *\n\t * Memory dynamically allocated by the task is not automatically freed, and\n\t * should be freed before the task is deleted.\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* param) {\n     *   printf(\"Hello %s\\n\", (char*)param);\n     *   // ...\n     * }\n     * \n     * void initialize() {\n\t *   pros::Task my_task(my_task_fn, \"My Task\");\n\t *   \n\t *   my_task.remove();\n     * }\n     * \\endcode\n\t */\n\tvoid remove();\n\n\t/**\n\t * Gets the priority of the specified task.\n\t *\n\t * \\return The priority of the task\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* param) {\n     *   printf(\"Hello %s\\n\", (char*)param);\n     *   // ...\n     * }\n     * \n     * void initialize() {\n\t *   pros::Task my_task(my_task_fn, \"My Task\");\n\t * \n     *   printf(\"Task Priority: %d\\n\", my_task.get_priority());\n     * }\n     * \\endcode\n\t */\n\tstd::uint32_t get_priority();\n\n\t/**\n\t * Sets the priority of the specified task.\n\t *\n\t * If the specified task's state is available to be scheduled (e.g. not\n\t * blocked) and new priority is higher than the currently running task,\n\t * a context switch may occur.\n\t *\n\t * \\param prio\n\t *        The new priority of the task\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* param) {\n     *   printf(\"Hello %s\\n\", (char*)param);\n     *   // ...\n     * }\n     * \n     * void initialize() {\n\t *   pros::Task my_task(my_task_fn, \"My Task\");\n\t * \n\t *   Task.set_priority(pros::DEFAULT_PRIORITY + 1);\n     * }\n     * \\endcode\n\t */\n\tvoid set_priority(std::uint32_t prio);\n\n\t/**\n\t * Gets the state of the specified task.\n\t *\n\t * \\return The state of the task\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* param) {\n     *   printf(\"Hello %s\\n\", (char*)param);\n     *   // ...\n     * }\n     * \n     * void initialize() {\n\t *   pros::Task my_task(my_task_fn, \"My Task\");\n\t * \n     *   printf(\"Task State: %d\\n\", my_task.get_state());\n     * }\n     * \\endcode\n\t */\n\tstd::uint32_t get_state();\n\n\t/**\n\t * Suspends the specified task, making it ineligible to be scheduled.\n\t * \n\t * \\b Example\n     * \\code\n\t * pros::Mutex counter_mutex;\n     * int counter = 0;\n     * \n     * void my_task_fn(void* param) {\n     *   while(true) {\n\t * \t   counter_mutex.take(); // Mutexes are used for protecting shared resources\n     *     counter++;\n\t *     counter_mutex.give();\n     *     pros::delay(10);\n     *   }\n     * }\n     * \n     * void opcontrol() {\n\t *   pros::Task task(my_task_fn, \"My Task\");\n     * \n     *   while(true) {\n     *     counter_mutex.take();\n     *     if(counter > 100) {\n     *       task_suspepend(task);\n     * \t   }\n     *     counter_mutex.give();\n     *     pros::delay(10);\n     *   }\n     * }\n     * \\endcode\n\t */\n\tvoid suspend();\n\n\t/**\n\t * Resumes the specified task, making it eligible to be scheduled.\n\t *\n\t * \\param task\n\t *        The task to resume\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* param) {\n     *   while(true) {\n     *     // Do stuff\n     *     pros::delay(10);\n     *   }\n     * }\n     * \n     * pros::Task task(my_task_fn);\n     * \n     * void autonomous() {\n     *   task.resume();\n     * \n     *   // Run autonomous , then suspend the task so it doesn't interfere run\n     *   // outside of autonomous or opcontrol\n     *   task.suspend();\n     * }\n     * \n     * void opcontrol() {\n     *   task.resume();\n     *   // Opctonrol code here\n     *   task.suspend();\n     * }\n     * \n     * \\endcode\n\t */\n\tvoid resume();\n\n\t/**\n\t * Gets the name of the specified task.\n\t *\n\t * \\return A pointer to the name of the task\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* param) {\n     *   printf(\"Hello %s\\n\", (char*)param);\n     *   // ...\n     * }\n     * \n     * void initialize() {\n\t *   pros::Task my_task(my_task_fn, \"My Task\");\n     *   printf(\"Number of Running Tasks: %d\\n\", my_task.get_name());\n     * }\n     * \\endcode\n\t */\n\tconst char* get_name();\n\n\t/**\n\t * Convert this object to a C task_t handle\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* param) {\n     *   printf(\"Hello %s\\n\", (char*)param);\n     *   // ...\n     * }\n     * \n     * void initialize() {\n\t *   pros::Task my_task(my_task_fn, \"My Task\");\n\t * \n\t *   pros::c::task_t my_task_c = (pros::c::task_t)my_task;\n     * }\n     * \\endcode\n\t */\n\texplicit operator task_t() {\n\t\treturn task;\n\t}\n\n\t/**\n\t * Sends a simple notification to task and increments the notification\n\t * counter.\n\t *\n\t * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for\n\t * details.\n\t *\n\t * \\return Always returns true.\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* ign) {\n     *   while(pros::Task::current_task().notify_take(true) == 0) {\n\t *     // Code while waiting\n     *   }\n\t*    puts(\"I was unblocked!\");\n     * }\n     * \n     * void opcontrol() {\n     *   pros::Task my_task(my_task_fn);\n\t *   \n     *   while(true) {\n     *     if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) {\n     *       my_task.notify();\n     *     }\n     *   }\n     * }\n     * \\endcode\n\t */\n\tstd::uint32_t notify();\n\n\t/**\n\t * Utilizes task notifications to wait until specified task is complete and deleted,\n\t * then continues to execute the program. Analogous to std::thread::join in C++.\n\t *\n\t * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for\n\t * details.\n\t *\n\t * \\return void\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* ign) {\n     *   lcd_print(1, \"%s running\", pros::Task::current_task().get_name());\n     *   task_delay(1000);\n     *   lcd_print(2, \"End of %s\", pros::Task::current_task().get_name());\n     * }\n     * \n     * void opcontrol() {\n\t *   pros::Task my_task(my_task_fn);\n     *   pros::lcd::set_text(0, \"Running task.\");\n     *   my_task.join();\n     *   pros::lcd::lcd_set_text(3, \"Task completed.\");\n     * }\n     * \\endcode\n\t */\n\tvoid join();\n\n\t/**\n\t * Sends a notification to a task, optionally performing some action. Will\n\t * also retrieve the value of the notification in the target task before\n\t * modifying the notification value.\n\t *\n\t * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for\n\t * details.\n\t *\n\t * \\param value\n\t *        The value used in performing the action\n\t * \\param action\n\t *        An action to optionally perform on the receiving task's notification\n\t *        value\n\t * \\param prev_value\n\t *        A pointer to store the previous value of the target task's\n\t *        notification, may be NULL\n\t *\n\t * \\return Dependent on the notification action.\n\t * For NOTIFY_ACTION_NO_WRITE: return 0 if the value could be written without\n\t * needing to overwrite, 1 otherwise.\n\t * For all other NOTIFY_ACTION values: always return 0\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* param) {\n\t *   pros::Task task = pros::Task::current();\n\t * \n     *   while(true) {\n     *     // Wait until we have been notified 20 times before running the code\n     *     if(task.notify_take(false, TIMEOUT_MAX) == 20) {\n     *       // ... Code to do stuff here ...\n     * \n     *       // Reset the notification counter\n     *       task.notify_clear();\n     *     }\n     *     delay(10);\n     * \t }\n     * }\n     * \n     * void opcontrol() {\n\t *   pros::Task task(my_task_fn);\n     *   \n     *   int count = 0;\n     *   \n     *   while(true) {\n     *     if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) {\n     *       task.notify_ext(1, NOTIFY_ACTION_INCREMENT, &count);\n     *     }\n     *     \n     *     delay(20);\n     *   }\n     * }\n     * \\endcode\n\t */\n\tstd::uint32_t notify_ext(std::uint32_t value, notify_action_e_t action, std::uint32_t* prev_value);\n\n\t/**\n\t * Waits for a notification to be nonzero.\n\t *\n\t * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for\n\t * details.\n\t *\n\t * \\param clear_on_exit\n\t *        If true (1), then the notification value is cleared.\n\t *        If false (0), then the notification value is decremented.\n\t * \\param timeout\n\t *        Specifies the amount of time to be spent waiting for a notification\n\t *        to occur.\n\t *\n\t * \\return The value of the task's notification value before it is decremented\n\t * or cleared\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* ign) {\n     *   pros::Task task = pros::task::current();\n     *   while(task.notify_take(true, TIMEOUT_MAX)) {\n     *     puts(\"I was unblocked!\");\n     *   }\n     * }\n     * \n     * void opcontrol() {\n\t *   pros::Task task(my_task_fn);\n     *   while(true) {\n     *     if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) {\n     *       task.notify(my_task);\n     *     }\n     *   }\n     * }\n     * \\endcode\n\t */\n\tstatic std::uint32_t notify_take(bool clear_on_exit, std::uint32_t timeout);\n\n\t/**\n\t * Clears the notification for a task.\n\t *\n\t * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for\n\t * details.\n\t *\n\t * \\return False if there was not a notification waiting, true if there was\n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* param) {\n\t *   pros::Task task = pros::Task::current();\n     *   while(true) {\n     *     printf(\"Waiting for notification...\\n\");\n     * \t   printf(\"Got a notification: %d\\n\", task.notify_take(false, TIMEOUT_MAX));\n     * \n     * \t   tasK_notify(task);\n     *     delay(10):\n     *   }\n     * }\n     * \n     * void opcontrol() {\n\t *   pros::Task task(my_task_fn);\n     *   while(true) {\n     *     if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) {\n     *       task.notify();\n     *     }\n     *     delay(10);\n     *   }\n     * }\n     * \\endcode\n\t */\n\tbool notify_clear();\n\n\t/**\n\t * Delays the current task for a specified number of milliseconds.\n\t *\n\t * This is not the best method to have a task execute code at predefined\n\t * intervals, as the delay time is measured from when the delay is requested.\n\t * To delay cyclically, use task_delay_until().\n\t *\n\t * \\param milliseconds\n\t *        The number of milliseconds to wait (1000 milliseconds per second)\n\t * \n\t * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   while (true) {\n     *     // Do opcontrol things\n     *     pros::Task::delay(2);\n     *   }\n     * \\endcode\n\t */\n\tstatic void delay(const std::uint32_t milliseconds);\n\n\t/**\n\t * Delays the current Task until a specified time.  This function can be used by\n\t * periodic tasks to ensure a constant execution frequency.\n\t *\n\t * The task will be woken up at the time *prev_time + delta, and *prev_time\n\t * will be updated to reflect the time at which the task will unblock.\n\t *\n\t * \\param prev_time\n\t *        A pointer to the location storing the setpoint time. This should\n\t *        typically be initialized to the return value from pros::millis().\n\t * \\param delta\n\t *        The number of milliseconds to wait (1000 milliseconds per second)\n\t * \n\t * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   while (true) {\n     *     // Do opcontrol things\n     *     pros::Task::delay(2);\n     *   }\n\t * }\n     * \\endcode\n\t */\n\tstatic void delay_until(std::uint32_t* const prev_time, const std::uint32_t delta);\n\n\t/**\n\t * Gets the number of tasks the kernel is currently managing, including all\n\t * ready, blocked, or suspended tasks. A task that has been deleted, but not\n\t * yet reaped by the idle task will also be included in the count.\n\t * Tasks recently created may take one context switch to be counted.\n\t *\n\t * \\return The number of tasks that are currently being managed by the kernel.\n\t * \n\t * \\b Example\n     * \\code\n     * void my_task_fn(void* param) {\n     *   printf(\"Hello %s\\n\", (char*)param);\n     *   // ...\n     * }\n\t * \n     * void opcontrol() {\n\t *   pros::Task my_task(my_task_fn);\n     *   printf(\"There are %d tasks running\\n\", pros::Task::get_count());\n     * }\n     * \\endcode\n\t */\n\tstatic std::uint32_t get_count();\n\n\tprivate:\n\ttask_t task{};\n};\n\n// STL Clock compliant clock\nstruct Clock {\n\tusing rep = std::uint32_t;\n\tusing period = std::milli;\n\tusing duration = std::chrono::duration<rep, period>;\n\tusing time_point = std::chrono::time_point<Clock>;\n\tconst bool is_steady = true;\n\n\t/**\n\t * Gets the current time.\n\t *\n\t * Effectively a wrapper around pros::millis()\n\t *\n\t * \\return The current time\n\t * \n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Clock::time_point start = pros::Clock::now();\n\t *   pros::Clock::time_point end = pros::Clock::now();\n\t *   pros::Clock::duration duration = end - start;\n\t *   printf(\"Duration: %d\\n\", duration.count());\n\t * \n\t *   if(duration.count() == 500) {\n\t *     // If you see this comment in the DOCS, ping @pros in VTOW. \n\t *     // If you are the first person to do so, you will receive a free PROS \n\t * \t   // holo!\n\t *     printf(\"Duration is 500 milliseconds\\n\");\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstatic time_point now();\n};\n\nclass Mutex {\n\tstd::atomic<mutex_t> mutex{nullptr};\n\tmutex_t lazy_init();\n\tpublic:\n\tconstexpr Mutex() {\n\t\tif (!std::is_constant_evaluated()) {\n\t\t\tlazy_init();\n\t\t}\n\t}\n\n\t// disable copy and move construction and assignment per Mutex requirements\n\t// (see https://en.cppreference.com/w/cpp/named_req/Mutex)\n\tMutex(const Mutex&) = delete;\n\tMutex(Mutex&&) = delete;\n\n\tMutex& operator=(const Mutex&) = delete;\n\tMutex& operator=(Mutex&&) = delete;\n\n\t/**\n\t * Takes and locks a mutex indefinetly.\n\t *\n\t * See\n\t * https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html#mutexes\n\t * for details.\n\t *\n\t * \\return True if the mutex was successfully taken, false otherwise. If false\n\t * is returned, then errno is set with a hint about why the the mutex\n\t * couldn't be taken\n\t * \n\t * \\b Example\n     * \\code\n     * // Global variables for the robot's odometry, which the rest of the robot's\n     * // subsystems will utilize\n     * double odom_x = 0.0;\n     * double odom_y = 0.0;\n     * double odom_heading = 0.0;\n     * \n     * // This mutex protects the odometry data. Whenever we read or write to the\n     * // odometry data, we should make copies into the local variables, and read\n     * // all 3 values at once to avoid errors.\n     * pros::Mutex odom_mutex;\n     * \n     * void odom_task(void* param) {\n     *   while(true) {\n     *     // First we fetch the odom coordinates from the previous iteration of the\n     *     // odometry task. These are put into local variables so that we can\n     *     // keep the size of the critical section as small as possible. This lets\n     *     // other tasks that need to use the odometry data run until we need to\n     *     // update it again.\n\t *     odom_mutex.take();\n     *     double x_old = odom_x;\n     *     double y_old = odom_y;\n     *     double heading_old = odom_heading;\n\t *     odom_mutex.give();\n     * \n     *     double x_new = 0.0;\n     *     double y_new = 0.0;\n     *     double heading_new = 0.0;\n     *     \n     *     // --- Calculate new pose for the robot here ---\n     * \n     *     // Now that we have the new pose, we can update the global variables\n\t *     odom_mutex.take();\n     *     odom_x = x_new;\n     *     odom_y = y_new;\n     *     odom_heading = heading_new;\n\t *     odom_mutex.give();\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void chassis_task(void* param) {\n     *   while(true) {\n     *     // Here we copy the current odom values into local variables so that\n     *     // we can use them without worrying about the odometry task changing say,\n     *     // the y value right after we've read the x. This ensures our values are\n     *     // sound.\n\t *     odom_mutex.take();\n     *     double current_x = odom_x;\n     *     double current_y = odom_y;\n     *     double current_heading = odom_heading;\n\t *     odom_mutex.give();\n     *     \n     *     // ---- Move the robot using the current locations goes here ----\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void initialize() {\n\t *   odom_mutex = pros::Mutex();\n\t * \n\t *   pros::Task odom_task(odom_task, \"Odometry Task\");\n\t *   pros::Task chassis_task(odom_task, \"Chassis Control Task\");\n     * }\n     * \\endcode.\n\t */\n\tbool take();\n\n\t/**\n\t * Takes and locks a mutex, waiting for up to a certain number of milliseconds\n\t * before timing out.\n\t *\n\t * See\n\t * https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html#mutexes\n\t * for details.\n\t *\n\t * \\param timeout\n\t *        Time to wait before the mutex becomes available. A timeout of 0 can\n\t *        be used to poll the mutex. TIMEOUT_MAX can be used to block\n\t *        indefinitely.\n\t *\n\t * \\return True if the mutex was successfully taken, false otherwise. If false\n\t * is returned, then errno is set with a hint about why the the mutex\n\t * couldn't be taken.\n\t * \n\t * \\b Example\n     * \\code\n     * // Global variables for the robot's odometry, which the rest of the robot's\n     * // subsystems will utilize\n     * double odom_x = 0.0;\n     * double odom_y = 0.0;\n     * double odom_heading = 0.0;\n     * \n     * // This mutex protects the odometry data. Whenever we read or write to the\n     * // odometry data, we should make copies into the local variables, and read\n     * // all 3 values at once to avoid errors.\n     * pros::Mutex odom_mutex;\n     * \n     * void odom_task(void* param) {\n     *   while(true) {\n     *     // First we fetch the odom coordinates from the previous iteration of the\n     *     // odometry task. These are put into local variables so that we can\n     *     // keep the size of the critical section as small as possible. This lets\n     *     // other tasks that need to use the odometry data run until we need to\n     *     // update it again.\n\t *     odom_mutex.take();\n     *     double x_old = odom_x;\n     *     double y_old = odom_y;\n     *     double heading_old = odom_heading;\n\t *     odom_mutex.give();\n     * \n     *     double x_new = 0.0;\n     *     double y_new = 0.0;\n     *     double heading_new = 0.0;\n     *     \n     *     // --- Calculate new pose for the robot here ---\n     * \n     *     // Now that we have the new pose, we can update the global variables\n\t *     odom_mutex.take();\n     *     odom_x = x_new;\n     *     odom_y = y_new;\n     *     odom_heading = heading_new;\n\t *     odom_mutex.give();\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void chassis_task(void* param) {\n     *   while(true) {\n     *     // Here we copy the current odom values into local variables so that\n     *     // we can use them without worrying about the odometry task changing say,\n     *     // the y value right after we've read the x. This ensures our values are\n     *     // sound.\n\t *     odom_mutex.take();\n     *     double current_x = odom_x;\n     *     double current_y = odom_y;\n     *     double current_heading = odom_heading;\n\t *     odom_mutex.give();\n     *     \n     *     // ---- Move the robot using the current locations goes here ----\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void initialize() {\n\t *   odom_mutex = pros::Mutex();\n\t * \n\t *   pros::Task odom_task(odom_task, \"Odometry Task\");\n\t *   pros::Task chassis_task(odom_task, \"Chassis Control Task\");\n     * }\n     * \\endcode.\n\t */\n\tbool take(std::uint32_t timeout);\n\n\t/**\n\t * Unlocks a mutex.\n\t *\n\t * See\n\t * https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html#mutexes\n\t * for details.\n\t *\n\t * \\return True if the mutex was successfully returned, false otherwise. If\n\t * false is returned, then errno is set with a hint about why the mutex\n\t * couldn't be returned.\n\t * \n\t * \\b Example\n     * \\code\n     * // Global variables for the robot's odometry, which the rest of the robot's\n     * // subsystems will utilize\n     * double odom_x = 0.0;\n     * double odom_y = 0.0;\n     * double odom_heading = 0.0;\n     * \n     * // This mutex protects the odometry data. Whenever we read or write to the\n     * // odometry data, we should make copies into the local variables, and read\n     * // all 3 values at once to avoid errors.\n     * pros::Mutex odom_mutex;\n     * \n     * void odom_task(void* param) {\n     *   while(true) {\n     *     // First we fetch the odom coordinates from the previous iteration of the\n     *     // odometry task. These are put into local variables so that we can\n     *     // keep the size of the critical section as small as possible. This lets\n     *     // other tasks that need to use the odometry data run until we need to\n     *     // update it again.\n\t *     odom_mutex.take();\n     *     double x_old = odom_x;\n     *     double y_old = odom_y;\n     *     double heading_old = odom_heading;\n\t *     odom_mutex.give();\n     * \n     *     double x_new = 0.0;\n     *     double y_new = 0.0;\n     *     double heading_new = 0.0;\n     *     \n     *     // --- Calculate new pose for the robot here ---\n     * \n     *     // Now that we have the new pose, we can update the global variables\n\t *     odom_mutex.take();\n     *     odom_x = x_new;\n     *     odom_y = y_new;\n     *     odom_heading = heading_new;\n\t *     odom_mutex.give();\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void chassis_task(void* param) {\n     *   while(true) {\n     *     // Here we copy the current odom values into local variables so that\n     *     // we can use them without worrying about the odometry task changing say,\n     *     // the y value right after we've read the x. This ensures our values are\n     *     // sound.\n\t *     odom_mutex.take();\n     *     double current_x = odom_x;\n     *     double current_y = odom_y;\n     *     double current_heading = odom_heading;\n\t *     odom_mutex.give();\n     *     \n     *     // ---- Move the robot using the current locations goes here ----\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void initialize() {\n\t *   odom_mutex = pros::Mutex();\n\t * \n\t *   pros::Task odom_task(odom_task, \"Odometry Task\");\n\t *   pros::Task chassis_task(odom_task, \"Chassis Control Task\");\n     * }\n     * \\endcode.\n\t */\n\tbool give();\n\n\t/**\n\t * Takes and locks a mutex, waiting for up to TIMEOUT_MAX milliseconds.\n\t *\n\t * Effectively equivalent to calling pros::Mutex::take with TIMEOUT_MAX as\n\t * the parameter.\n\t *\n\t * Conforms to named requirment BasicLockable\n\t * \\see https://en.cppreference.com/w/cpp/named_req/BasicLockable\n\t *\n\t * \\note Consider using a std::unique_lock, std::lock_guard, or\n\t * \t\t std::scoped_lock instead of interacting with the Mutex directly.\n\t *\n\t * \\exception std::system_error Mutex could not be locked within TIMEOUT_MAX\n\t *\t\t\t  milliseconds. see errno for details.\n\t * \n\t * \\b Example\n     * \\code\n     * // Global variables for the robot's odometry, which the rest of the robot's\n     * // subsystems will utilize\n     * double odom_x = 0.0;\n     * double odom_y = 0.0;\n     * double odom_heading = 0.0;\n     * \n     * // This mutex protects the odometry data. Whenever we read or write to the\n     * // odometry data, we should make copies into the local variables, and read\n     * // all 3 values at once to avoid errors.\n     * pros::Mutex odom_mutex;\n     * \n     * void odom_task(void* param) {\n     *   while(true) {\n     *     // First we fetch the odom coordinates from the previous iteration of the\n     *     // odometry task. These are put into local variables so that we can\n     *     // keep the size of the critical section as small as possible. This lets\n     *     // other tasks that need to use the odometry data run until we need to\n     *     // update it again.\n\t *     odom_mutex.lock();\n     *     double x_old = odom_x;\n     *     double y_old = odom_y;\n     *     double heading_old = odom_heading;\n\t *     odom_mutex.unlock();\n     * \n     *     double x_new = 0.0;\n     *     double y_new = 0.0;\n     *     double heading_new = 0.0;\n     *     \n     *     // --- Calculate new pose for the robot here ---\n     * \n     *     // Now that we have the new pose, we can update the global variables\n\t *     odom_mutex.lock();\n     *     odom_x = x_new;\n     *     odom_y = y_new;\n     *     odom_heading = heading_new;\n\t *     odom_mutex.unlock();\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void chassis_task(void* param) {\n     *   while(true) {\n     *     // Here we copy the current odom values into local variables so that\n     *     // we can use them without worrying about the odometry task changing say,\n     *     // the y value right after we've read the x. This ensures our values are\n     *     // sound.\n\t *     odom_mutex.lock();\n     *     double current_x = odom_x;\n     *     double current_y = odom_y;\n     *     double current_heading = odom_heading;\n\t *     odom_mutex.unlock();\n     *     \n     *     // ---- Move the robot using the current locations goes here ----\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void initialize() {\n\t *   odom_mutex = pros::Mutex();\n\t * \n\t *   pros::Task odom_task(odom_task, \"Odometry Task\");\n\t *   pros::Task chassis_task(odom_task, \"Chassis Control Task\");\n     * }\n     * \\endcode.\n\t */\n\tvoid lock();\n\n\t/**\n\t * Unlocks a mutex.\n\t *\n\t * Equivalent to calling pros::Mutex::give.\n\t *\n\t * Conforms to named requirement BasicLockable\n\t * \\see https://en.cppreference.com/w/cpp/named_req/BasicLockable\n\t *\n\t * \\note Consider using a std::unique_lock, std::lock_guard, or\n\t * \t\t std::scoped_lock instead of interacting with the Mutex direcly.\n\t * \n\t * \\b Example\n     * \\code\n     * // Global variables for the robot's odometry, which the rest of the robot's\n     * // subsystems will utilize\n     * double odom_x = 0.0;\n     * double odom_y = 0.0;\n     * double odom_heading = 0.0;\n     * \n     * // This mutex protects the odometry data. Whenever we read or write to the\n     * // odometry data, we should make copies into the local variables, and read\n     * // all 3 values at once to avoid errors.\n     * pros::Mutex odom_mutex;\n     * \n     * void odom_task(void* param) {\n     *   while(true) {\n     *     // First we fetch the odom coordinates from the previous iteration of the\n     *     // odometry task. These are put into local variables so that we can\n     *     // keep the size of the critical section as small as possible. This lets\n     *     // other tasks that need to use the odometry data run until we need to\n     *     // update it again.\n\t *     odom_mutex.lock();\n     *     double x_old = odom_x;\n     *     double y_old = odom_y;\n     *     double heading_old = odom_heading;\n\t *     odom_mutex.unlock();\n     * \n     *     double x_new = 0.0;\n     *     double y_new = 0.0;\n     *     double heading_new = 0.0;\n     *     \n     *     // --- Calculate new pose for the robot here ---\n     * \n     *     // Now that we have the new pose, we can update the global variables\n\t *     odom_mutex.lock();\n     *     odom_x = x_new;\n     *     odom_y = y_new;\n     *     odom_heading = heading_new;\n\t *     odom_mutex.unlock();\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void chassis_task(void* param) {\n     *   while(true) {\n     *     // Here we copy the current odom values into local variables so that\n     *     // we can use them without worrying about the odometry task changing say,\n     *     // the y value right after we've read the x. This ensures our values are\n     *     // sound.\n\t *     odom_mutex.lock();\n     *     double current_x = odom_x;\n     *     double current_y = odom_y;\n     *     double current_heading = odom_heading;\n\t *     odom_mutex.unlock();\n     *     \n     *     // ---- Move the robot using the current locations goes here ----\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void initialize() {\n\t *   odom_mutex = pros::Mutex();\n\t * \n\t *   pros::Task odom_task(odom_task, \"Odometry Task\");\n\t *   pros::Task chassis_task(odom_task, \"Chassis Control Task\");\n     * }\n     * \\endcode.\n\t */\n\tvoid unlock();\n\n\t/**\n\t * Try to lock a mutex.\n\t *\n\t * Returns immediately if unsucessful.\n\t *\n\t * Conforms to named requirement Lockable\n\t * \\see https://en.cppreference.com/w/cpp/named_req/Lockable\n\t *\n\t * \\return True when lock was acquired succesfully, or false otherwise.\n\t * \n\t * pros::Mutex mutex;\n\t * \n\t * void my_task_fn(void* param) {\n\t *   while (true) {\n\t *     if(mutex.try_lock()) {\n\t *       printf(\"Mutex aquired successfully!\\n\");\n\t *       // Do stuff that requires the protected resource here\n\t *     }\n\t *     else {\n\t *       printf(\"Mutex not aquired!\\n\");\n\t *     }\n\t *   }\n\t * }\n\t */\n\t[[nodiscard]] bool try_lock();\n\n\t/**\n\t * Takes and locks a mutex, waiting for a specified duration.\n\t *\n\t * Equivalent to calling pros::Mutex::take with a duration specified in\n\t * milliseconds.\n\t *\n\t * Conforms to named requirement TimedLockable\n\t * \\see https://en.cppreference.com/w/cpp/named_req/TimedLockable\n\t *\n\t * \\param rel_time Time to wait before the mutex becomes available.\n\t * \\return True if the lock was acquired succesfully, otherwise false.\n\t * \n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   while (true) {\n\t *     if(mutex.try_lock_for(std::chrono::milliseconds(100))) {\n\t *       printf(\"Mutex aquired successfully!\\n\");\n\t *       // Do stuff that requires the protected resource here\n\t *     }\n\t *     else {\n\t *       printf(\"Mutex not aquired after 100 milliseconds!\\n\");\n\t *     }\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\ttemplate <typename Rep, typename Period>\n\t[[nodiscard]] bool try_lock_for(const std::chrono::duration<Rep, Period>& rel_time) {\n\t\treturn take(std::chrono::duration_cast<Clock::duration>(rel_time).count());\n\t}\n\n\t/**\n\t * Takes and locks a mutex, waiting until a specified time.\n\t *\n\t * Conforms to named requirement TimedLockable\n\t * \\see https://en.cppreference.com/w/cpp/named_req/TimedLockable\n\t *\n\t * \\param abs_time Time point until which to wait for the mutex.\n\t * \\return True if the lock was acquired succesfully, otherwise false.\n\t * \n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   while (true) {\n\t *     // Get the current time point\n\t *     auto now = std::chrono::system_clock::now();\n\t * \n\t *     // Calculate the time point 100 milliseconds from now\n\t *     auto abs_time = now + std::chrono::milliseconds(100);\n\t * \n\t *     if(mutex.try_lock_until(abs_time)) {\n\t *       printf(\"Mutex aquired successfully!\\n\");\n\t *       // Do stuff that requires the protected resource here\n\t *     }\n\t *     else {\n\t *       printf(\"Mutex not aquired after 100 milliseconds!\\n\");\n\t *     }\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\ttemplate <typename Duration>\n\tbool try_lock_until(const std::chrono::time_point<Clock, Duration>& abs_time) {\n\t\treturn take(std::max(static_cast<uint32_t>(0), (abs_time - Clock::now()).count()));\n\t}\n\t~Mutex();\n\t///@}\n};\n\nclass RecursiveMutex {\n\tstd::atomic<mutex_t> mutex{nullptr};\n\tmutex_t lazy_init();\n\tpublic:\n\tconstexpr RecursiveMutex() {\n\t\tif (!std::is_constant_evaluated()) {\n\t\t\tlazy_init();\n\t\t}\n\t}\n\n\t// disable copy and move construction and assignment per Mutex requirements\n\t// (see https://en.cppreference.com/w/cpp/named_req/Mutex)\n\tRecursiveMutex(const RecursiveMutex&) = delete;\n\tRecursiveMutex(RecursiveMutex&&) = delete;\n\n\tRecursiveMutex& operator=(const RecursiveMutex&) = delete;\n\tRecursiveMutex& operator=(RecursiveMutex&&) = delete;\n\n\t/**\n\t * Takes and locks a mutex indefinetly.\n\t *\n\t * See\n\t * https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html#mutexes\n\t * for details.\n\t *\n\t * \\return True if the mutex was successfully taken, false otherwise. If false\n\t * is returned, then errno is set with a hint about why the the mutex\n\t * couldn't be taken\n\t * \n\t * \\b Example\n     * \\code\n     * // Global variables for the robot's odometry, which the rest of the robot's\n     * // subsystems will utilize\n     * double odom_x = 0.0;\n     * double odom_y = 0.0;\n     * double odom_heading = 0.0;\n     * \n     * // This mutex protects the odometry data. Whenever we read or write to the\n     * // odometry data, we should make copies into the local variables, and read\n     * // all 3 values at once to avoid errors.\n     * pros::RecursiveMutex odom_mutex;\n     * \n     * void odom_task(void* param) {\n     *   while(true) {\n     *     // First we fetch the odom coordinates from the previous iteration of the\n     *     // odometry task. These are put into local variables so that we can\n     *     // keep the size of the critical section as small as possible. This lets\n     *     // other tasks that need to use the odometry data run until we need to\n     *     // update it again.\n\t *     odom_mutex.take();\n     *     double x_old = odom_x;\n     *     double y_old = odom_y;\n     *     double heading_old = odom_heading;\n\t *     odom_mutex.give();\n     * \n     *     double x_new = 0.0;\n     *     double y_new = 0.0;\n     *     double heading_new = 0.0;\n     *     \n     *     // --- Calculate new pose for the robot here ---\n     * \n     *     // Now that we have the new pose, we can update the global variables\n\t *     odom_mutex.take();\n     *     odom_x = x_new;\n     *     odom_y = y_new;\n     *     odom_heading = heading_new;\n\t *     odom_mutex.give();\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void chassis_task(void* param) {\n     *   while(true) {\n     *     // Here we copy the current odom values into local variables so that\n     *     // we can use them without worrying about the odometry task changing say,\n     *     // the y value right after we've read the x. This ensures our values are\n     *     // sound.\n\t *     odom_mutex.take();\n     *     double current_x = odom_x;\n     *     double current_y = odom_y;\n     *     double current_heading = odom_heading;\n\t *     odom_mutex.give();\n     *     \n     *     // ---- Move the robot using the current locations goes here ----\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void initialize() {\n\t *   odom_mutex = pros::RecursiveMutex();\n\t * \n\t *   pros::Task odom_task(odom_task, \"Odometry Task\");\n\t *   pros::Task chassis_task(odom_task, \"Chassis Control Task\");\n     * }\n     * \\endcode.\n\t */\n\tbool take();\n\n\t/**\n\t * Takes and locks a mutex, waiting for up to a certain number of milliseconds\n\t * before timing out.\n\t *\n\t * See\n\t * https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html#mutexes\n\t * for details.\n\t *\n\t * \\param timeout\n\t *        Time to wait before the mutex becomes available. A timeout of 0 can\n\t *        be used to poll the mutex. TIMEOUT_MAX can be used to block\n\t *        indefinitely.\n\t *\n\t * \\return True if the mutex was successfully taken, false otherwise. If false\n\t * is returned, then errno is set with a hint about why the the mutex\n\t * couldn't be taken.\n\t * \n\t * \\b Example\n     * \\code\n     * // Global variables for the robot's odometry, which the rest of the robot's\n     * // subsystems will utilize\n     * double odom_x = 0.0;\n     * double odom_y = 0.0;\n     * double odom_heading = 0.0;\n     * \n     * // This mutex protects the odometry data. Whenever we read or write to the\n     * // odometry data, we should make copies into the local variables, and read\n     * // all 3 values at once to avoid errors.\n     * pros::RecursiveMutex odom_mutex;\n     * \n     * void odom_task(void* param) {\n     *   while(true) {\n     *     // First we fetch the odom coordinates from the previous iteration of the\n     *     // odometry task. These are put into local variables so that we can\n     *     // keep the size of the critical section as small as possible. This lets\n     *     // other tasks that need to use the odometry data run until we need to\n     *     // update it again.\n\t *     odom_mutex.take();\n     *     double x_old = odom_x;\n     *     double y_old = odom_y;\n     *     double heading_old = odom_heading;\n\t *     odom_mutex.give();\n     * \n     *     double x_new = 0.0;\n     *     double y_new = 0.0;\n     *     double heading_new = 0.0;\n     *     \n     *     // --- Calculate new pose for the robot here ---\n     * \n     *     // Now that we have the new pose, we can update the global variables\n\t *     odom_mutex.take();\n     *     odom_x = x_new;\n     *     odom_y = y_new;\n     *     odom_heading = heading_new;\n\t *     odom_mutex.give();\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void chassis_task(void* param) {\n     *   while(true) {\n     *     // Here we copy the current odom values into local variables so that\n     *     // we can use them without worrying about the odometry task changing say,\n     *     // the y value right after we've read the x. This ensures our values are\n     *     // sound.\n\t *     odom_mutex.take();\n     *     double current_x = odom_x;\n     *     double current_y = odom_y;\n     *     double current_heading = odom_heading;\n\t *     odom_mutex.give();\n     *     \n     *     // ---- Move the robot using the current locations goes here ----\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void initialize() {\n\t *   odom_mutex = pros::RecursiveMutex();\n\t * \n\t *   pros::Task odom_task(odom_task, \"Odometry Task\");\n\t *   pros::Task chassis_task(odom_task, \"Chassis Control Task\");\n     * }\n     * \\endcode.\n\t */\n\tbool take(std::uint32_t timeout);\n\n\t/**\n\t * Unlocks a mutex.\n\t *\n\t * See\n\t * https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html#mutexes\n\t * for details.\n\t *\n\t * \\return True if the mutex was successfully returned, false otherwise. If\n\t * false is returned, then errno is set with a hint about why the mutex\n\t * couldn't be returned.\n\t * \n\t * \\b Example\n     * \\code\n     * // Global variables for the robot's odometry, which the rest of the robot's\n     * // subsystems will utilize\n     * double odom_x = 0.0;\n     * double odom_y = 0.0;\n     * double odom_heading = 0.0;\n     * \n     * // This mutex protects the odometry data. Whenever we read or write to the\n     * // odometry data, we should make copies into the local variables, and read\n     * // all 3 values at once to avoid errors.\n     * pros::RecursiveMutex odom_mutex;\n     * \n     * void odom_task(void* param) {\n     *   while(true) {\n     *     // First we fetch the odom coordinates from the previous iteration of the\n     *     // odometry task. These are put into local variables so that we can\n     *     // keep the size of the critical section as small as possible. This lets\n     *     // other tasks that need to use the odometry data run until we need to\n     *     // update it again.\n\t *     odom_mutex.take();\n     *     double x_old = odom_x;\n     *     double y_old = odom_y;\n     *     double heading_old = odom_heading;\n\t *     odom_mutex.give();\n     * \n     *     double x_new = 0.0;\n     *     double y_new = 0.0;\n     *     double heading_new = 0.0;\n     *     \n     *     // --- Calculate new pose for the robot here ---\n     * \n     *     // Now that we have the new pose, we can update the global variables\n\t *     odom_mutex.take();\n     *     odom_x = x_new;\n     *     odom_y = y_new;\n     *     odom_heading = heading_new;\n\t *     odom_mutex.give();\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void chassis_task(void* param) {\n     *   while(true) {\n     *     // Here we copy the current odom values into local variables so that\n     *     // we can use them without worrying about the odometry task changing say,\n     *     // the y value right after we've read the x. This ensures our values are\n     *     // sound.\n\t *     odom_mutex.take();\n     *     double current_x = odom_x;\n     *     double current_y = odom_y;\n     *     double current_heading = odom_heading;\n\t *     odom_mutex.give();\n     *     \n     *     // ---- Move the robot using the current locations goes here ----\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void initialize() {\n\t *   odom_mutex = pros::RecursiveMutex();\n\t * \n\t *   pros::Task odom_task(odom_task, \"Odometry Task\");\n\t *   pros::Task chassis_task(odom_task, \"Chassis Control Task\");\n     * }\n     * \\endcode.\n\t */\n\tbool give();\n\n\t/**\n\t * Takes and locks a mutex, waiting for up to TIMEOUT_MAX milliseconds.\n\t *\n\t * Effectively equivalent to calling pros::RecursiveMutex::take with TIMEOUT_MAX as\n\t * the parameter.\n\t *\n\t * Conforms to named requirment BasicLockable\n\t * \\see https://en.cppreference.com/w/cpp/named_req/BasicLockable\n\t *\n\t * \\note Consider using a std::unique_lock, std::lock_guard, or\n\t * \t\t std::scoped_lock instead of interacting with the Mutex directly.\n\t *\n\t * \\exception std::system_error Mutex could not be locked within TIMEOUT_MAX\n\t *\t\t\t  milliseconds. see errno for details.\n\t * \n\t * \\b Example\n     * \\code\n     * // Global variables for the robot's odometry, which the rest of the robot's\n     * // subsystems will utilize\n     * double odom_x = 0.0;\n     * double odom_y = 0.0;\n     * double odom_heading = 0.0;\n     * \n     * // This mutex protects the odometry data. Whenever we read or write to the\n     * // odometry data, we should make copies into the local variables, and read\n     * // all 3 values at once to avoid errors.\n     * pros::RecursiveMutex odom_mutex;\n     * \n     * void odom_task(void* param) {\n     *   while(true) {\n     *     // First we fetch the odom coordinates from the previous iteration of the\n     *     // odometry task. These are put into local variables so that we can\n     *     // keep the size of the critical section as small as possible. This lets\n     *     // other tasks that need to use the odometry data run until we need to\n     *     // update it again.\n\t *     odom_mutex.lock();\n     *     double x_old = odom_x;\n     *     double y_old = odom_y;\n     *     double heading_old = odom_heading;\n\t *     odom_mutex.unlock();\n     * \n     *     double x_new = 0.0;\n     *     double y_new = 0.0;\n     *     double heading_new = 0.0;\n     *     \n     *     // --- Calculate new pose for the robot here ---\n     * \n     *     // Now that we have the new pose, we can update the global variables\n\t *     odom_mutex.lock();\n     *     odom_x = x_new;\n     *     odom_y = y_new;\n     *     odom_heading = heading_new;\n\t *     odom_mutex.unlock();\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void chassis_task(void* param) {\n     *   while(true) {\n     *     // Here we copy the current odom values into local variables so that\n     *     // we can use them without worrying about the odometry task changing say,\n     *     // the y value right after we've read the x. This ensures our values are\n     *     // sound.\n\t *     odom_mutex.lock();\n     *     double current_x = odom_x;\n     *     double current_y = odom_y;\n     *     double current_heading = odom_heading;\n\t *     odom_mutex.unlock();\n     *     \n     *     // ---- Move the robot using the current locations goes here ----\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void initialize() {\n\t *   odom_mutex = pros::RecursiveMutex();\n\t * \n\t *   pros::Task odom_task(odom_task, \"Odometry Task\");\n\t *   pros::Task chassis_task(odom_task, \"Chassis Control Task\");\n     * }\n     * \\endcode.\n\t */\n\tvoid lock();\n\n\t/**\n\t * Unlocks a mutex.\n\t *\n\t * Equivalent to calling pros::RecursiveMutex::give.\n\t *\n\t * Conforms to named requirement BasicLockable\n\t * \\see https://en.cppreference.com/w/cpp/named_req/BasicLockable\n\t *\n\t * \\note Consider using a std::unique_lock, std::lock_guard, or\n\t * \t\t std::scoped_lock instead of interacting with the Mutex direcly.\n\t * \n\t * \\b Example\n     * \\code\n     * // Global variables for the robot's odometry, which the rest of the robot's\n     * // subsystems will utilize\n     * double odom_x = 0.0;\n     * double odom_y = 0.0;\n     * double odom_heading = 0.0;\n     * \n     * // This mutex protects the odometry data. Whenever we read or write to the\n     * // odometry data, we should make copies into the local variables, and read\n     * // all 3 values at once to avoid errors.\n     * pros::RecursiveMutex odom_mutex;\n     * \n     * void odom_task(void* param) {\n     *   while(true) {\n     *     // First we fetch the odom coordinates from the previous iteration of the\n     *     // odometry task. These are put into local variables so that we can\n     *     // keep the size of the critical section as small as possible. This lets\n     *     // other tasks that need to use the odometry data run until we need to\n     *     // update it again.\n\t *     odom_mutex.lock();\n     *     double x_old = odom_x;\n     *     double y_old = odom_y;\n     *     double heading_old = odom_heading;\n\t *     odom_mutex.unlock();\n     * \n     *     double x_new = 0.0;\n     *     double y_new = 0.0;\n     *     double heading_new = 0.0;\n     *     \n     *     // --- Calculate new pose for the robot here ---\n     * \n     *     // Now that we have the new pose, we can update the global variables\n\t *     odom_mutex.lock();\n     *     odom_x = x_new;\n     *     odom_y = y_new;\n     *     odom_heading = heading_new;\n\t *     odom_mutex.unlock();\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void chassis_task(void* param) {\n     *   while(true) {\n     *     // Here we copy the current odom values into local variables so that\n     *     // we can use them without worrying about the odometry task changing say,\n     *     // the y value right after we've read the x. This ensures our values are\n     *     // sound.\n\t *     odom_mutex.lock();\n     *     double current_x = odom_x;\n     *     double current_y = odom_y;\n     *     double current_heading = odom_heading;\n\t *     odom_mutex.unlock();\n     *     \n     *     // ---- Move the robot using the current locations goes here ----\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void initialize() {\n\t *   odom_mutex = pros::RecursiveMutex();\n\t * \n\t *   pros::Task odom_task(odom_task, \"Odometry Task\");\n\t *   pros::Task chassis_task(odom_task, \"Chassis Control Task\");\n     * }\n     * \\endcode.\n\t */\n\tvoid unlock();\n\n\t/**\n\t * Try to lock a mutex.\n\t *\n\t * Returns immediately if unsucessful.\n\t *\n\t * Conforms to named requirement Lockable\n\t * \\see https://en.cppreference.com/w/cpp/named_req/Lockable\n\t *\n\t * \\return True when lock was acquired succesfully, or false otherwise.\n\t * \n\t * pros::RecursiveMutex mutex;\n\t * \n\t * void my_task_fn(void* param) {\n\t *   while (true) {\n\t *     if(mutex.try_lock()) {\n\t *       printf(\"Mutex aquired successfully!\\n\");\n\t *       // Do stuff that requires the protected resource here\n\t *     }\n\t *     else {\n\t *       printf(\"Mutex not aquired!\\n\");\n\t *     }\n\t *   }\n\t * }\n\t */\n\t[[nodiscard]] bool try_lock();\n\n\t/**\n\t * Takes and locks a mutex, waiting for a specified duration.\n\t *\n\t * Equivalent to calling pros::RecursiveMutex::take with a duration specified in\n\t * milliseconds.\n\t *\n\t * Conforms to named requirement TimedLockable\n\t * \\see https://en.cppreference.com/w/cpp/named_req/TimedLockable\n\t *\n\t * \\param rel_time Time to wait before the mutex becomes available.\n\t * \\return True if the lock was acquired succesfully, otherwise false.\n\t * \n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   while (true) {\n\t *     if(mutex.try_lock_for(std::chrono::milliseconds(100))) {\n\t *       printf(\"Mutex aquired successfully!\\n\");\n\t *       // Do stuff that requires the protected resource here\n\t *     }\n\t *     else {\n\t *       printf(\"Mutex not aquired after 100 milliseconds!\\n\");\n\t *     }\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\ttemplate <typename Rep, typename Period>\n\t[[nodiscard]] bool try_lock_for(const std::chrono::duration<Rep, Period>& rel_time) {\n\t\treturn take(std::chrono::duration_cast<Clock::duration>(rel_time).count());\n\t}\n\n\t/**\n\t * Takes and locks a mutex, waiting until a specified time.\n\t *\n\t * Conforms to named requirement TimedLockable\n\t * \\see https://en.cppreference.com/w/cpp/named_req/TimedLockable\n\t *\n\t * \\param abs_time Time point until which to wait for the mutex.\n\t * \\return True if the lock was acquired succesfully, otherwise false.\n\t * \n\t * \\b Example\n\t * \\code\n\t * void my_task_fn(void* param) {\n\t *   while (true) {\n\t *     // Get the current time point\n\t *     auto now = std::chrono::system_clock::now();\n\t * \n\t *     // Calculate the time point 100 milliseconds from now\n\t *     auto abs_time = now + std::chrono::milliseconds(100);\n\t * \n\t *     if(mutex.try_lock_until(abs_time)) {\n\t *       printf(\"Mutex aquired successfully!\\n\");\n\t *       // Do stuff that requires the protected resource here\n\t *     }\n\t *     else {\n\t *       printf(\"Mutex not aquired after 100 milliseconds!\\n\");\n\t *     }\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\ttemplate <typename Duration>\n\tbool try_lock_until(const std::chrono::time_point<Clock, Duration>& abs_time) {\n\t\treturn take(std::max(static_cast<uint32_t>(0), (abs_time - Clock::now()).count()));\n\t}\n\n\t~RecursiveMutex();\n\t///@}\n};\n\ntemplate <typename Var>\nclass MutexVar;\n\ntemplate <typename Var>\nclass MutexVarLock {\n\tMutex& mutex;\n\tVar& var;\n\n\tfriend class MutexVar<Var>;\n\n\tconstexpr MutexVarLock(Mutex& mutex, Var& var) : mutex(mutex), var(var) {}\n\n\tpublic:\n\t/**\n\t * Accesses the value of the mutex-protected variable.\n\t */\n\tconstexpr Var& operator*() const {\n\t\treturn var;\n\t}\n\n\t/**\n\t * Accesses the value of the mutex-protected variable.\n\t */\n\tconstexpr Var* operator->() const {\n\t\treturn &var;\n\t}\n\n\t~MutexVarLock() {\n\t\tmutex.unlock();\n\t}\n};\n\ntemplate <typename Var>\nclass MutexVar {\n\tMutex mutex;\n\tVar var;\n\n\tpublic:\n\t/**\n\t * Creates a mutex-protected variable which is initialized with the given\n\t * constructor arguments.\n\t *\n\t * \\param args\n\t *        The arguments to provide to the Var constructor.\n     *\n     * \\b Example\n\t * \\code\n\t * // We create a pose class to contain all our odometry data in a single\n\t * // variable that can be protected by a MutexVar. Otherwise, we would have\n\t * // three seperate variables which could not be protected in a single \n\t * // MutexVar\n\t * struct Pose {\n\t *   double x;\n\t *   double y;\n\t *   double heading;\n\t * }\n\t * \n\t * pros::MutexVar<Pose> odom_pose(0.0, 0.0, 0.0);\n\t * \n\t * void odom_task(void* param) {\n     *   while(true) {\n\t *     Pose old_pose = *odom_pose.lock();\n     * \n\t *     Pose new_pose{0.0, 0.0, 0.0};\n     *     \n     *     // --- Calculate new pose for the robot here ---\n     * \n     *     // Now that we have the new pose, we can update the global variables\n\t * \n\t *     *odom_pose.take() = new_pose;\n\t *     \n\t *     delay(10);\n\t *   }\n\t * }\n     * \n     * void chassis_task(void* param) {\n     *   while(true) {\n\t * \n\t *     Pose cur_pose = *odom_pose.take();\n     *     \n     *     // ---- Move the robot using the current locations goes here ----\n     *     \n     *     delay(10);\n     *   }\n     * }\n     * \n     * void initialize() {\n\t *   odom_mutex = pros::Mutex();\n\t * \n\t *   pros::Task odom_task(odom_task, \"Odometry Task\");\n\t *   pros::Task chassis_task(odom_task, \"Chassis Control Task\");\n     * }\n\t * \n\t * \\endcode\n\t */\n\ttemplate <typename... Args>\n\tMutexVar(Args&&... args) : mutex(), var(std::forward<Args>(args)...) {}\n\n\t/**\n\t * Try to lock the mutex-protected variable.\n\t *\n\t * \\param timeout\n\t *        Time to wait before the mutex becomes available, in milliseconds. A\n\t *        timeout of 0 can be used to poll the mutex.\n\t *\n\t * \\return A std::optional which contains a MutexVarLock providing access to\n\t * the protected variable if locking is successful.\n\t * \n\t * \\b Example\n\t * \\code\n\t * pros::MutexVar<Pose> odom_pose;\n\t * \n\t * void my_task(void* param) {\n\t *   while(true) {\n\t *     std::optional<pros::MutexVar<Pose>> cur_pose_opt = odom_pose.try_lock(100);\n\t *     \n\t *     if(cur_pose_opt.has_value()) {\n\t *       Pose* cur_pose = **cur_pose_opt;\n\t *     }\n\t *     else {\n\t *       printf(\"Could not lock the mutex var!\");\n\t *     }\n\t * \n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::optional<MutexVarLock<Var>> try_lock(std::uint32_t timeout) {\n\t\tif (mutex.take(timeout)) {\n\t\t\treturn {{mutex, var}};\n\t\t} else {\n\t\t\treturn {};\n\t\t}\n\t}\n\n\t/**\n\t * Try to lock the mutex-protected variable.\n\t *\n\t * \\param timeout\n\t *        Time to wait before the mutex becomes available. A timeout of 0 can\n\t *        be used to poll the mutex.\n\t *\n\t * \\return A std::optional which contains a MutexVarLock providing access to\n\t * the protected variable if locking is successful.\n\t * \n\t * \\b Example\n\t * \\code\n\t * pros::MutexVar<Pose> odom_pose;\n\t * \n\t * void my_task(void* param) {\n\t *   while(true) {\n\t *     std::chrono::duration<int, std::milli> timeout(100);\n\t *     std::optional<pros::MutexVar<Pose>> cur_pose_opt = odom_pose.try_lock(timeout);\n\t *     \n\t *     if(cur_pose_opt.has_value()) {\n\t *       Pose* cur_pose = **cur_pose_opt;\n\t *     }\n\t *     else {\n\t *       printf(\"Could not lock the mutex var!\");\n\t *     }\n\t * \n\t *     pros::delay(10);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\ttemplate <typename Rep, typename Period>\n\tstd::optional<MutexVarLock<Var>> try_lock(const std::chrono::duration<Rep, Period>& rel_time) {\n\t\ttry_lock(std::chrono::duration_cast<Clock::duration>(rel_time).count());\n\t}\n\n\t/**\n\t * Lock the mutex-protected variable, waiting indefinitely.\n\t *\n\t * \\return A MutexVarLock providing access to the protected variable.\n\t * \n\t * \\b Example\n\t * \\code\n\t * pros::MutexVar<Pose> odom_pose;\n\t * \n\t * void my_task(void* param) {\n\t *   while(true) {\n\t *     pros::delay(10);\n\t * \n\t *     pros::MutexVarLock<Pose> cur_pose = odom_pose.lock();\n\t *     Pose cur_pose = *cur_pose;\n\t *      \n\t *     // do stuff with cur_pose\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tMutexVarLock<Var> lock() {\n\t\twhile (!mutex.take(TIMEOUT_MAX))\n\t\t\t;\n\t\treturn {mutex, var};\n\t}\n};\n\n/**\n * Gets the number of milliseconds since PROS initialized.\n *\n * \\return The number of milliseconds since PROS initialized\n */\nusing pros::c::millis;\n\n/**\n * Gets the number of microseconds since PROS initialized.\n *\n * \\return The number of microseconds since PROS initialized\n */\nusing pros::c::micros;\n\n/**\n * Delays a task for a given number of milliseconds.\n *\n * This is not the best method to have a task execute code at predefined\n * intervals, as the delay time is measured from when the delay is requested.\n * To delay cyclically, use task_delay_until().\n *\n * \\param milliseconds\n * \t\t  The number of milliseconds to wait (1000 milliseconds per second)\n */\nusing pros::c::delay;\n}  // namespace rtos\n}  // namespace pros\n\n#endif  // _PROS_RTOS_HPP_\n"
  },
  {
    "path": "include/pros/screen.h",
    "content": "/**\n * \\file screen.h\n * \\ingroup c-screen\n *\n * Brain screen display and touch functions.\n *\n * Contains user calls to the v5 screen for touching and displaying graphics.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup c-screen Simplified Brain Screen C API\n *\n */\n\n#ifndef _PROS_SCREEN_H_\n#define _PROS_SCREEN_H_\n\n#include <stdarg.h>\n#include <stdbool.h>\n#define _GNU_SOURCE\n#include <stdio.h>\n#undef _GNU_SOURCE\n#include <stdint.h>\n\n#include \"pros/colors.h\"  // c color macros\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\n#endif\n\n/**\n * \\ingroup c-screen\n */\n\n/**\n * \\addtogroup c-screen\n *  @{\n */\n\n/**\n * \\enum text_format_e_t\n * Different font sizes that can be used in printing text.\n */\ntypedef enum {\n\t/// Small text font size\n\tE_TEXT_SMALL = 0,\n\t/// Normal/Medium text font size\n\tE_TEXT_MEDIUM,\n\t/// Large text font size\n\tE_TEXT_LARGE,\n\t/// Medium centered text\n\tE_TEXT_MEDIUM_CENTER,\n\t/// Large centered text\n\tE_TEXT_LARGE_CENTER\n} text_format_e_t;\n\n/**\n * \\enum last_touch_e_t\n * Enum indicating what the current touch status is for the touchscreen.\n */\ntypedef enum {\n\t/// Last interaction with screen was a quick press\n\tE_TOUCH_RELEASED = 0,\n\t/// Last interaction with screen was a release\n\tE_TOUCH_PRESSED,\n\t/// User is holding screen down\n\tE_TOUCH_HELD,\n\t/// An error occured while taking/returning the mutex\n\tE_TOUCH_ERROR\n} last_touch_e_t;\n\n/**\n * \\struct screen_touch_status_s_t\n *  Struct representing screen touch status, screen last x, screen last y, press count, release count.\n */\ntypedef struct screen_touch_status_s {\n\tlast_touch_e_t touch_status; ///< Represents if the screen is being held, released, or pressed.\n\tint16_t x; ///< Represents the x value of the location of the touch.\n\tint16_t y; ///< Represents the y value of the location of the touch.\n\tint32_t press_count; ///< Represents how many times the screen has be pressed.\n\tint32_t release_count; ///< Represents how many times the user released after a touch on the screen.\n} screen_touch_status_s_t;\n\n#ifdef PROS_USE_SIMPLE_NAMES\n#ifdef __cplusplus\n#define TEXT_SMALL pros::E_TEXT_SMALL\n#define TEXT_MEDIUM pros::E_TEXT_MEDIUM\n#define TEXT_LARGE pros::E_TEXT_LARGE\n#define TEXT_MEDIUM_CENTER pros::E_TEXT_MEDIUM_CENTER\n#define TEXT_LARGE_CENTER pros::E_TEXT_LARGE_CENTER\n#define TOUCH_RELEASED pros::E_TOUCH_RELEASED\n#define TOUCH_PRESSED pros::E_TOUCH_PRESSED\n#define TOUCH_HELD pros::E_TOUCH_HELD\n#else\n#define TEXT_SMALL E_TEXT_SMALL\n#define TEXT_MEDIUM E_TEXT_MEDIUM\n#define TEXT_LARGE E_TEXT_LARGE\n#define TEXT_MEDIUM_CENTER E_TEXT_MEDIUM_CENTER\n#define TEXT_LARGE_CENTER E_TEXT_LARGE_CENTER\n#define TOUCH_RELEASED E_TOUCH_RELEASED\n#define TOUCH_PRESSED E_TOUCH_PRESSED\n#define TOUCH_HELD E_TOUCH_HELD\n#endif\n#endif\n\ntypedef void (*touch_event_cb_fn_t)();\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n/// \\name Screen Graphical Display Functions\n/// These functions allow programmers to display shapes on the v5 screen\n///@{\n\n/**\n * Set the pen color for subsequent graphics operations\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param color\tThe pen color to set (it is recommended to use values\n * \t\t from the enum defined in colors.h)\n *\n * \\return Returns 1 if the mutex was successfully returned, or PROS_ERR if\n *         there was an error either taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   screen_set_pen(COLOR_RED);\n * }\n *\n * void opcontrol() {\n *   int iter = 0;\n *   while(1){\n *     // This should print in red.\n *     screen_print(TEXT_MEDIUM, 1, \"%d\", iter++);\n *   }\n * }\n * \\endcode\n */\nuint32_t screen_set_pen(uint32_t color);\n\n/**\n * Set the eraser color for erasing and the current background.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param color\tThe background color to set (it is recommended to use values\n * \t\t\t\t\tfrom the enum defined in colors.h)\n *\n * \\return Returns 1 if the mutex was successfully returned, or\n * PROS_ERR if there was an error either taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   screen_set_eraser(COLOR_RED);\n * }\n *\n * void opcontrol() {\n *   while(1){\n *     // This should turn the screen red.\n *     screen_erase();\n *   }\n * }\n * \\endcode\n */\nuint32_t screen_set_eraser(uint32_t color);\n\n/**\n *  Get the current pen color.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\return The current pen color in the form of a value from the enum defined\n *         in colors.h, or PROS_ERR if there was an error taking or returning\n *         the screen mutex.\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   screen_set_pen(COLOR_RED);\n * }\n *\n * void opcontrol() {\n *   while(1){\n *     // Should print number equivalent to COLOR_RED defined in colors.h.\n *     screen_print(TEXT_MEDIUM, 1, \"%d\", screen_get_pen());\n *   }\n * }\n * \\endcode\n */\nuint32_t screen_get_pen(void);\n\n/**\n * Get the current eraser color.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\return The current eraser color in the form of a value from the enum\n *         defined in colors.h, or PROS_ERR if there was an error taking or\n *         returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   screen_set_eraser(COLOR_RED);\n * }\n *\n * void opcontrol() {\n *   while(1){\n *     // Should print number equivalent to COLOR_RED defined in colors.h.\n *     screen_print(TEXT_MEDIUM, 1, \"%d\", screen_get_eraser());\n *   }\n * }\n * \\endcode\n */\nuint32_t screen_get_eraser(void);\n\n/**\n * Clear display with eraser color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void initialize() {\n *   screen_set_eraser(COLOR_RED);\n * }\n *\n * void opcontrol() {\n *   while(1){\n *     // This should turn the screen red.\n *     screen_erase();\n *   }\n * }\n * \\endcode\n */\nuint32_t screen_erase(void);\n\n/**\n * Scroll lines on the display upwards.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param start_line    The line from which scrolling will start\n * \\param lines\t\t\tThe number of lines to scroll up\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   screen_print(TEXT_MEDIUM, 4, \"Line Here\");\n *   // Scroll 3 lines\n *   screen_scroll(4, 3);\n * }\n * \\endcode\n */\nuint32_t screen_scroll(int16_t start_line, int16_t lines);\n\n/**\n * Scroll lines within a region on the display\n *\n * This function behaves in the same way as `screen_scroll`, except that you\n * specify a rectangular region within which to scroll lines instead of a start\n * line.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x0, y0\tThe (x,y) coordinates of the first corner of the\n * \t\t\t\t\t\trectangular region\n * \\param x1, y1\tThe (x,y) coordinates of the second corner of the\n * \t\t\t\t\t\trectangular region\n * \\param lines \tThe number of lines to scroll upwards\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *           taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   screen_print(TEXT_MEDIUM, 1, \"Line Here\");\n *   // Scrolls area of screen upwards slightly. including line of text\n *   screen_scroll_area(0,0, 400, 200, 3);\n * }\n * \\endcode\n */\nuint32_t screen_scroll_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t lines);\n\n/**\n * Copy a screen region (designated by a rectangle) from an off-screen buffer\n * to the screen\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x0, y0 \tThe (x,y) coordinates of the first corner of the\n * \t\t\t\t\t\trectangular region of the screen\n * \\param x1, y1\tThe (x,y) coordinates of the second corner of the\n * \t\t\t\t\t\trectangular region of the screen\n * \\param buf\t\tOff-screen buffer containing screen data\n * \\param stride\tOff-screen buffer width in pixels, such that image size\n * \t\t\t\t\t\tis stride-padding\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   uint32_t* buf = malloc(sizeof(uint32_t) * 400 * 200);\n *   screen_print(TEXT_MEDIUM, 1, \"Line Here\");\n *   // Copies area of the screen including text\n *   screen_copy_area(0, 0, 400, 200, (uint32_t*)buf, 400 + 1);\n *   // Equation for stride is x2 - x1 + 1\n * }\n * \\endcode\n */\nuint32_t screen_copy_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32_t* buf, int32_t stride);\n\n/**\n * Draw a single pixel on the screen using the current pen color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x, y \tThe (x,y) coordinates of the pixel\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * int i = 0;\n * void opcontrol() {\n *   while(i < 200){\n *     screen_draw_pixel(100,i++);\n *     // Draws a line at x = 100 gradually down the screen, pixel by pixel\n *     delay(200);\n *   }\n * }\n * \\endcode\n */\nuint32_t screen_draw_pixel(int16_t x, int16_t y);\n\n/**\n * Erase a pixel from the screen (Sets the location)\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x, y \tThe (x,y) coordinates of the erased\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   // Color the Screen in Red\n *   screen_set_pen(COLOR_RED);\n *   screen_fill_rect(0,0,400,200);\n *   int i = 0;\n *   while(i < 200){\n *     screen_erase_pixel(100,i++);\n *     // Erases a line at x = 100 gradually down the screen, pixel by pixel\n *     delay(200);\n *   }\n * }\n * \\endcode\n */\nuint32_t screen_erase_pixel(int16_t x, int16_t y);\n\n/**\n * Draw a line on the screen using the current pen color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x0, y0\tThe (x, y) coordinates of the first point of the line\n * \\param x1, y1 \tThe (x, y) coordinates of the second point of the line\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n * \t screen_set_pen(COLOR_RED);\n *   // Draw line down the screen at x = 100\n *   screen_draw_line(100,0,100,200);\n * }\n * \\endcode\n */\nuint32_t screen_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1);\n\n/**\n * Erase a line on the screen using the current eraser color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x0, y0\tThe (x, y) coordinates of the first point of the line\n * \\param x1, y1 \tThe (x, y) coordinates of the second point of the line\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   // Color the Screen in Red\n *   screen_set_pen(COLOR_RED);\n *   screen_fill_rect(0,0,400,200);\n *   // Erase line down the screen at x = 100\n *   screen_erase_line(100,0,100,200);\n * }\n * \\endcode\n */\nuint32_t screen_erase_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1);\n\n/**\n * Draw a rectangle on the screen using the current pen color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x0, y0 \tThe (x,y) coordinates of the first point of the rectangle\n * \\param x1, y1 \tThe (x,y) coordinates of the second point of the rectangle\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   screen_set_pen(COLOR_RED);\n *   screen_draw_rect(1,1,480,200);\n * }\n * \\endcode\n */\nuint32_t screen_draw_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1);\n\n/**\n * Erase a rectangle on the screen using the current eraser color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x0, y0 \tThe (x,y) coordinates of the first point of the rectangle\n * \\param x1, y1 \tThe (x,y) coordinates of the second point of the rectangle\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   // Draw Box Around Half the Screen in Red\n *   screen_set_eraser(COLOR_RED);\n *   screen_erase_rect(5,5,240,200);\n * }\n * \\endcode\n */\nuint32_t screen_erase_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1);\n\n/**\n * Fill a rectangular region of the screen using the current pen\n * \t\t  color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x0, y0 \tThe (x,y) coordinates of the first point of the rectangle\n * \\param x1, y1 \tThe (x,y) coordinates of the second point of the rectangle\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   // Fill Around Half the Screen in Red\n *   screen_set_pen(COLOR_RED);\n *   screen_fill_rect(5,5,240,200);\n * }\n * \\endcode\n */\nuint32_t screen_fill_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1);\n\n/**\n * Draw a circle on the screen using the current pen color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x, y \tThe (x,y) coordinates of the center of the circle\n * \\param r \tThe radius of the circle\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   // Draw a circle with radius of 100 in red\n *   screen_set_pen(COLOR_RED);\n *   screen_draw_circle(240, 200, 100);\n * }\n * \\endcode\n */\nuint32_t screen_draw_circle(int16_t x, int16_t y, int16_t radius);\n\n/**\n * Erase a circle on the screen using the current eraser color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x, y \tThe (x,y) coordinates of the center of the circle\n * \\param r \tThe radius of the circle\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   screen_set_pen(COLOR_RED);\n *   screen_fill_rect(5,5,240,200);\n *   // Erase a circle with radius of 100 in COLOR_BLUE\n *   screen_set_pen(COLOR_BLUE);\n *   screen_erase_circle(240, 200, 100);\n * }\n * \\endcode\n */\nuint32_t screen_erase_circle(int16_t x, int16_t y, int16_t radius);\n\n/**\n * Fill a circular region of the screen using the current pen\n * \t\t  color\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param x, y \tThe (x,y) coordinates of the center of the circle\n * \\param r \tThe radius of the circle\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *         taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   screen_set_pen(COLOR_RED);\n *   screen_fill_rect(5,5,240,200);\n *   // Fill a circlular area with radius of 100 in COLOR_BLUE\n *   screen_set_pen(COLOR_BLUE);\n *   screen_fill_circle(240, 200, 100);\n * }\n * \\endcode\n */\nuint32_t screen_fill_circle(int16_t x, int16_t y, int16_t radius);\n\n///@}\n\n/// \\name Screen Text Display Functions\n/// These functions allow programmers to display text on the v5 screen\n///@{\n\n/**\n * Print a formatted string to the screen on the specified line\n *\n * Will default to a medium sized font by default if invalid txt_fmt is given.\n *\n * \\param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES\n * NOT SUPPORT SMALL) \\param line The line number on which to print \\param text  Format string \\param ...  Optional list\n * of arguments for the format string\n *\n *  \\return 1 if there were no errors, or PROS_ERR if an error occured\n *          taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   int i = 0;\n *\n *   screen_set_pen(COLOR_BLUE);\n *   while(1){\n *     // Will print seconds started since program started on line 3\n *     screen_print(TEXT_MEDIUM, 3, \"Seconds Passed: %3d\", i++);\n *     delay(1000);\n *   }\n * }\n * \\endcode\n */\nuint32_t screen_print(text_format_e_t txt_fmt, const int16_t line, const char* text, ...);\n\n/**\n * Print a formatted string to the screen at the specified point\n *\n * Will default to a medium sized font by default if invalid txt_fmt is given.\n *\n * Text formats medium_center and large_center will default to medium and large respectively.\n *\n * \\param txt_fmt Text format enum that determines if the text is small, medium, or large.\n * \\param x The y coordinate of the top left corner of the string\n * \\param y The x coordinate of the top left corner of the string\n * \\param text  Format string\n * \\param ...  Optional list of arguments for the format string\n *\n *  \\return 1 if there were no errors, or PROS_ERR if an error occured\n *          taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   int i = 0;\n *\n *   screen_set_pen(COLOR_BLUE);\n *   while(1){\n *     // Will print seconds started since program started.\n *     screen_print_at(TEXT_SMALL, 3, \"Seconds Passed: %3d\", i++);\n *     delay(1000);\n *   }\n * }\n * \\endcode\n */\nuint32_t screen_print_at(text_format_e_t txt_fmt, const int16_t x, const int16_t y, const char* text, ...);\n\n/**\n * Print a formatted string to the screen on the specified line\n *\n * Same as `display_printf` except that this uses a `va_list` instead of the\n * ellipsis operator so this can be used by other functions.\n *\n * Will default to a medium sized font by default if invalid txt_fmt is given.\n * Exposed mostly for writing libraries and custom functions.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES\n * NOT SUPPORT SMALL) \\param line The line number on which to print \\param text  Format string \\param args List of\n * arguments for the format string\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *          while taking or returning the screen mutex.\n *\n * \n */\nuint32_t screen_vprintf(text_format_e_t txt_fmt, const int16_t line, const char* text, va_list args);\n\n/**\n * Print a formatted string to the screen at the specified coordinates\n *\n * Same as `display_printf_at` except that this uses a `va_list` instead of the\n * ellipsis operator so this can be used by other functions.\n *\n * Will default to a medium sized font by default if invalid txt_fmt is given.\n *\n * Text formats medium_center and large_center will default to medium and large respectively.\n * Exposed mostly for writing libraries and custom functions.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param txt_fmt Text format enum that determines if the text is small, medium, or large.\n * \\param x, y The (x,y) coordinates of the top left corner of the string\n * \\param text  Format string\n * \\param args List of arguments for the format string\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *          while taking or returning the screen mutex.\n *\n */\nuint32_t screen_vprintf_at(text_format_e_t txt_fmt, const int16_t x, const int16_t y, const char* text, va_list args);\n\n///@}\n\n/// \\name Screen Touch Functions\n/// These functions allow programmers to access information about screen touches\n///@{\n\n/**\n * Gets the touch status of the last touch of the screen.\n *\n * \\return The last_touch_e_t enum specifier that indicates the last touch status of the screen (E_TOUCH_EVENT_RELEASE,\n * E_TOUCH_EVENT_PRESS, or E_TOUCH_EVENT_PRESS_AND_HOLD). This will be released by default if no action was taken. If an\n * error occured, the screen_touch_status_s_t will have its last_touch_e_t enum specifier set to E_TOUCH_ERR, and other\n * values set to -1.\n *\n * \\b Example\n * \\code\n * void opcontrol() {\n *   int i = 0;\n *   screen_touch_status_s_t status;\n *   while(1){\n *     status = screen_touch_status();\n *\n *     // Will print various information about the last touch\n *     screen_print(TEXT_MEDIUM, 1, \"Touch Status (Type): %d\", status.touch_status);\n *     screen_print(TEXT_MEDIUM, 2, \"Last X: %d\", status.x);\n *     screen_print(TEXT_MEDIUM, 3, \"Last Y: %d\", status.y);\n *     screen_print(TEXT_MEDIUM, 4, \"Press Count: %d\", status.press_count);\n *     screen_print(TEXT_MEDIUM, 5, \"Release Count: %d\", status.release_count);\n *     delay(20);\n *   }\n * }\n * \\endcode\n */\nscreen_touch_status_s_t screen_touch_status(void);\n\n/**\n * Assigns a callback function to be called when a certain touch event happens.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EACCESS - Another resource is currently trying to access the screen mutex.\n *\n * \\param cb Function pointer to callback when event type happens\n * \\param event_type Touch event that will trigger the callback.\n *\n * \\return 1 if there were no errors, or PROS_ERR if an error occured\n *          while taking or returning the screen mutex.\n *\n * \\b Example\n * \\code\n * touch_event_cb_fn_t changePixel(){\n *   screen_touch_status_s_t status = screen_touch_status();\n *   screen_draw_pixel(status.x,status.y);\n *   return NULL;\n * }\n *\n * void opcontrol() {\n *   screen_touch_callback(changePixel(), TOUCH_PRESSED);\n *   while(1) delay(20);\n * }\n * \\endcode\n */\nuint32_t screen_touch_callback(touch_event_cb_fn_t cb, last_touch_e_t event_type);\n\n///@}\n\n///@}\n\n#ifdef __cplusplus\n}  // namespace c\n}  // namespace pros\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "include/pros/screen.hpp",
    "content": "/**\n * \\file screen.hpp\n * \\ingroup cpp-screen\n *\n * Brain screen display and touch functions.\n *\n * Contains user calls to the v5 screen for touching and displaying graphics.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup cpp-screen Simplified Brain Screen C++ API\n */\n\n#ifndef _PROS_SCREEN_HPP_\n#define _PROS_SCREEN_HPP_\n\n#include \"pros/screen.h\"\n#include \"pros/colors.hpp\"\n#include <cstdint>\n#include <string>\n\nnamespace pros {\nnamespace screen {\n\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Wunused-function\"\n\nnamespace {\ntemplate <typename T>\nT convert_args(T arg) {\n\treturn arg;\n}\nconst char* convert_args(const std::string& arg) {\n\treturn arg.c_str();\n}\n}  // namespace\n\n#pragma GCC diagnostic pop\n\n/**\n * \\ingroup cpp-screen\n */\n\n/**\n * \\addtogroup cpp-screen\n *  @{\n */\n\n    /******************************************************************************/\n    /**                  Screen Graphical Display Functions                      **/\n    /**                                                                          **/\n    /**   These functions allow programmers to display shapes on the v5 screen   **/\n    /******************************************************************************/\n\n    /**\n     * Set the pen color for subsequent graphics operations\n     * \n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param color\tThe pen color to set (it is recommended to use values\n     * \t\t from the enum defined in colors.hpp)\n     * \n     * \\return Returns 1 if the mutex was successfully returned, or PROS_ERR if \n     * there was an error either taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void initialize() {\n     *   pros::screen::set_pen(red);\n     * }\n     * \n     * void opcontrol() {\n     * int iter = 0;\n     *  while(1){\n     *   // This should print in red.\n     *   pros::screen::print(TEXT_MEDIUM, 1, \"%d\", iter++);\n     *  }\n     * }\n     *\n     * \\endcode\n     */\n    std::uint32_t set_pen(pros::Color color);\n\n    /**\n     * Set the pen color for subsequent graphics operations\n     * \n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param color\tThe pen color to set (in hex form)\n     * \n     * \\return Returns 1 if the mutex was successfully returned, or PROS_ERR if \n     * there was an error either taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void initialize() {\n     *   //set pen color to red\n     *   pros::screen::set_pen(0x00FF0000);\n     * }\n     * \n     * void opcontrol() {\n     * int iter = 0;\n     *  while(1){\n     *   // This should print in red.\n     *   pros::screen::print(TEXT_MEDIUM, 1, \"%d\", iter++);\n     *  }\n     * }\n     *\n     * \\endcode\n     */\n    std::uint32_t set_pen(std::uint32_t color);\n\n    /**\n     * Set the eraser color for erasing and the current background.\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     * \n     * \\param color\tThe background color to set (it is recommended to use values\n     * \t\t\t\t\tfrom the enum defined in colors.hpp)\n     * \n     * \\return Returns 1 if the mutex was successfully returned, or PROS_ERR\n     *  if there was an error either taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void initialize() {\n     *   //set eraser color to red\n     *   set_eraser(red);\n     * }\n     * \n     * void opcontrol() {\n     * int iter = 0;\n     *  while(1){\n     *   // This should print in red.\n     *   pros::screen::print(TEXT_MEDIUM, 1, \"%d\", iter++);\n     *  }\n     * }\n     *\n     * \\endcode\n     */\n    std::uint32_t set_eraser(pros::Color color);\n\n    /**\n     * Set the eraser color for erasing and the current background.\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     * \n     * \\param color\tThe background color to set to set (in hex form)\n     * \n     * \\return Returns 1 if the mutex was successfully returned, or PROS_ERR\n     *  if there was an error either taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void initialize() {\n     *   //set eraser color to red\n     *   pros::screen::set_eraser(0x00FF0000);\n     * }\n     * \n     * void opcontrol() {\n     *   while(1){\n     *   // This should turn the screen red.\n     *   pros::screen::erase();\n     *   }\n     * }\n     * \\endcode\n     */\n    std::uint32_t set_eraser(std::uint32_t color);\n\n    /**\n     *  Get the current pen color.\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     * \n     * \\return The current pen color in the form of a value from the enum \n     * defined in colors.h, or PROS_ERR if there was an error taking or \n     * returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void initialize() {\n     *   pros::screen::set_pen(red);\n     * }\n     *\n     * void opcontrol() {\n     *   while(1){\n     *     // Should print number equivalent to red defined in colors.hpp.\n     *     pros::screen::print(TEXT_MEDIUM, 1, \"%d\", get_pen());\n     *   }\n     * }\n     * \\endcode\n     */\n    std::uint32_t get_pen();\n\n    /**\n     * Get the current eraser color.\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\return The current eraser color in the form of a value from the enum\n     *  defined in colors.h, or PROS_ERR if there was an error taking or \n     *  returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void initialize() {\n     *   pros::screen::set_eraser(red);\n     * }\n     *\n     * void opcontrol() {\n     *   while(1){\n     *     // Should print number equivalent to red defined in colors.h.\n     *     pros::screen::print(TEXT_MEDIUM, 1, \"%d\", get_eraser());\n     *   }\n     * }\n     * \\endcode\n     */\n    std::uint32_t get_eraser();\n\n    /**\n     * Clear display with eraser color\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     *         taking or returning the screen mutex.\n     * \n     *  * \\b Example\n     * \\code\n     * void initialize() {\n     *   pros::screen::set_eraser(red);\n     * }\n     *\n     * void opcontrol() {\n     *   while(1){\n     *     // This should turn the screen red.\n     *     pros::screen::erase();\n     *   }\n     * }\n     * \\endcode\n     */\n    std::uint32_t erase();\n\n    /**\n     * Scroll lines on the display upwards.\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param start_line    The line from which scrolling will start\n     * \\param lines\t\t\tThe number of lines to scroll up\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured\n     *  taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   pros::screen::print(TEXT_MEDIUM, 4, \"Line Here\");\n     *   // Scroll 3 lines\n     *   pros::screen::scroll(4, 3);\n     * }\n     * \\endcode\n     */\n    std::uint32_t scroll(const std::int16_t start_line, const std::int16_t lines);\n\n    /**\n     * Scroll lines within a region on the display\n     *\n     * This function behaves in the same way as `screen_scroll`, except that you\n     * specify a rectangular region within which to scroll lines instead of a start\n     * line.\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x0, y0\tThe (x,y) coordinates of the first corner of the\n     * \t\t\t\t\t\trectangular region\n     * \\param x1, y1\tThe (x,y) coordinates of the second corner of the\n     * \t\t\t\t\t\trectangular region\n     * \\param lines \tThe number of lines to scroll upwards\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   pros::screen::print(TEXT_MEDIUM, 1, \"Line Here\");\n     *   // Scrolls area of screen upwards slightly. including line of text\n     *   pros::screen::scroll_area(0,0, 400, 200, 3);\n     * }\n     * \\endcode\n     */\n    std::uint32_t scroll_area(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1, std::int16_t lines);\n\n    /**\n     * Copy a screen region (designated by a rectangle) from an off-screen buffer \n     * to the screen\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x0, y0 \tThe (x,y) coordinates of the first corner of the\n     * \t\t\t\t\t\trectangular region of the screen\n     * \\param x1, y1\tThe (x,y) coordinates of the second corner of the\n     * \t\t\t\t\t\trectangular region of the screen\n     * \\param buf\t\tOff-screen buffer containing screen data\n     * \\param stride\tOff-screen buffer width in pixels, such that image size\n     * \t\t\t\t\t\tis stride-padding\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured taking\n     *  or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   uint32_t* buf = malloc(sizeof(uint32_t) * 400 * 200);\n     *   pros::screen::print(TEXT_MEDIUM, 1, \"Line Here\");\n     *   // Copies area of the screen including text\n     *   pros::screen::copy_area(0, 0, 400, 200, (uint32_t*)buf, 400 + 1);\n     *   // Equation for stride is x2 - x1 + 1\n     * }\n     * \\endcode\n     */\n    std::uint32_t copy_area(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1, uint32_t* buf, const std::int32_t stride);\n\n    /**\n     * Draw a single pixel on the screen using the current pen color\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x, y \tThe (x,y) coordinates of the pixel\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * int i = 0;\n     * void opcontrol() {\n     *   while(i < 200){\n     *     pros::screen::draw_pixel(100,i++);\n     *     // Draws a line at x = 100 gradually down the screen, pixel by pixel\n     *     pros::delay(200);\n     *   }\n     * }\n     * \\endcode\n     */\n    std::uint32_t draw_pixel(const std::int16_t x, const std::int16_t y);\n\n    /**\n     * Erase a pixel from the screen (Sets the location)\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x, y \tThe (x,y) coordinates of the erased\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   // Color the Screen in Red\n     *   pros::screen::set_pen(red);\n     *   pros::screen::fill_rect(0,0,400,200);\n     *   int i = 0;\n     *   while(i < 200){\n     *     pros::screen::erase_pixel(100,i++);\n     *     // Erases a line at x = 100 gradually down the screen, pixel by pixel\n     *     pros::delay(200);\n     *   }\n     * }\n     * \\endcode\n     */\n    std::uint32_t erase_pixel(const std::int16_t x, const std::int16_t y);\n\n    /**\n     * Draw a line on the screen using the current pen color\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x0, y0\tThe (x, y) coordinates of the first point of the line\n     * \\param x1, y1 \tThe (x, y) coordinates of the second point of the line\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     * \t pros::screen::set_pen(red);\n     *   // Draw line down the screen at x = 100\n     *   pros::screen::draw_line(100,0,100,200);\n     * }\n     * \\endcode\n     */\n    std::uint32_t draw_line(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1);\n\n    /**\n     * Erase a line on the screen using the current eraser color\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x0, y0\tThe (x, y) coordinates of the first point of the line\n     * \\param x1, y1 \tThe (x, y) coordinates of the second point of the line\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   // Color the Screen in Red\n     *   pros::screen::set_pen(red);\n     *   pros::screen::fill_rect(0,0,400,200);\n     *   // Erase line down the screen at x = 100\n     *   pros::screen::erase_line(100,0,100,200);\n     * }\n     * \\endcode\n     */\n    std::uint32_t erase_line(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1);\n\n    /**\n     * Draw a rectangle on the screen using the current pen color\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x0, y0 \tThe (x,y) coordinates of the first point of the rectangle\n     * \\param x1, y1 \tThe (x,y) coordinates of the second point of the rectangle\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   pros::screen::set_pen(red);\n     *   pros::screen::draw_rect(1,1,480,200);\n     * }\n     * \\endcode\n     */\n    std::uint32_t draw_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1);\n\n    /**\n     * Erase a rectangle on the screen using the current eraser color\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x0, y0 \tThe (x,y) coordinates of the first point of the rectangle\n     * \\param x1, y1 \tThe (x,y) coordinates of the second point of the rectangle\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   // Draw Box Around Half the Screen in Red\n     *   pros::screen::set_eraser(red);\n     *   pros::screen::erase_rect(5,5,240,200);\n     * }\n     * \\endcode\n     */\n    std::uint32_t erase_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1);\n\n    /**\n     * Fill a rectangular region of the screen using the current pen\n     * \t\t  color\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x0, y0 \tThe (x,y) coordinates of the first point of the rectangle\n     * \\param x1, y1 \tThe (x,y) coordinates of the second point of the rectangle\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   // Fill Around Half the Screen in Red\n     *   pros::screen::set_pen(red);\n     *   pros::screen::fill_rect(5,5,240,200);\n     * }\n     * \\endcode\n     */\n    std::uint32_t fill_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1);\n\n    /**\n     * Draw a circle on the screen using the current pen color\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x, y \tThe (x,y) coordinates of the center of the circle\n     * \\param r \tThe radius of the circle\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   // Draw a circle with radius of 100 in red\n     *   pros::screen::set_pen(red);\n     *   pros::screen::draw_circle(240, 200, 100);\n     * }\n     * \\endcode\n     */\n    std::uint32_t draw_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius);\n\n    /**\n     * Erase a circle on the screen using the current eraser color\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x, y \tThe (x,y) coordinates of the center of the circle\n     * \\param r \tThe radius of the circle\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   pros::screen::set_pen(red);\n     *   pros::screen::fill_rect(5,5,240,200);\n     *   // Erase a circle with radius of 100 in blue\n     *   pros::screen::set_pen(blue);\n     *   pros::screen::erase_circle(240, 200, 100);\n     * }\n     * \\endcode\n     */\n    std::uint32_t erase_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius);\n\n    /**\n     * Fill a circular region of the screen using the current pen\n     * \t\t  color\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     *\n     * \\param x, y \tThe (x,y) coordinates of the center of the circle\n     * \\param r \tThe radius of the circle\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n    * void opcontrol() {\n     *   pros::screen::set_pen(red);\n     *   pros::screen::fill_rect(5,5,240,200);\n     *   // Fill a circlular area with radius of 100 in blue\n     *   pros::screen::set_pen(blue);\n     *   pros::screen::fill_circle(240, 200, 100);\n     * }\n     * \\endcode\n     */\n    std::uint32_t fill_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius);\n\n    /******************************************************************************/\n    /**                       Screen Text Display Functions                      **/\n    /**                                                                          **/\n    /**     These functions allow programmers to display text on the v5 screen   **/\n    /******************************************************************************/\n\n    /**\n     * Print a formatted string to the screen, overwrite available for printing at location too.\n     * \n     * Will default to a medium sized font by default if invalid txt_fmt is given.\n     * \n     * \\param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES NOT SUPPORT SMALL)\n     * \\param line The line number on which to print\n     * \\param x The (x,y) coordinates of the top left corner of the string\n     * \\param y The (x,y) coordinates of the top left corner of the string\n     * \\param fmt  Format string\n     * \\param ...  Optional list of arguments for the format string\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *    int i = 0;\n     *    pros::screen::set_pen(blue);\n     *    while(1){\n     *       // Will print seconds started since program started on line 3\n     *       pros::screen::print(pros::TEXT_MEDIUM, 3, \"Seconds Passed: %3d\", i++);\n     *       pros::delay(1000);\n     *    }\n     * }\n     */\n    template <typename... Params>\n    void print(pros::text_format_e_t txt_fmt, const std::int16_t line, const char* text, Params... args){\n\t    pros::c::screen_print(txt_fmt, line, text, convert_args(args)...);\n    }\n\n    template <typename... Params>\n    void print(pros::text_format_e_t txt_fmt, const std::int16_t x, const std::int16_t y, const char* text, Params... args){\n\t    pros::c::screen_print_at(txt_fmt, x, y, text, convert_args(args)...);\n    }\n    \n    /******************************************************************************/\n    /**                         Screen Touch Functions                           **/\n    /**                                                                          **/\n    /**               These functions allow programmers to access                **/\n    /**                    information about screen touches                      **/\n    /******************************************************************************/\n    \n   /**\n     * Gets the touch status of the last touch of the screen.\n     * \n     * \\return The last_touch_e_t enum specifier that indicates the last touch status of the screen (E_TOUCH_EVENT_RELEASE, E_TOUCH_EVENT_PRESS, or E_TOUCH_EVENT_PRESS_AND_HOLD).\n     * This will be released by default if no action was taken. \n     * If an error occured, the screen_touch_status_s_t will have its \n     * last_touch_e_t enum specifier set to E_TOUCH_ERR, and other values set to -1.\n     * \n     * \\b Example\n     * \\code\n     * void opcontrol() {\n     *   int i = 0;\n     *   pros::screen_touch_status_s_t status;\n     *   while(1){\n     *     status = pros::touch_status();\n     *\n     *     // Will print various information about the last touch\n     *     pros::screen::print(TEXT_MEDIUM, 1, \"Touch Status (Type): %d\", status.touch_status);\n     *     pros::screen::print(TEXT_MEDIUM, 2, \"Last X: %d\", status.x);\n     *     pros::screen::print(TEXT_MEDIUM, 3, \"Last Y: %d\", status.y);\n     *     pros::screen::print(TEXT_MEDIUM, 4, \"Press Count: %d\", status.press_count);\n     *     pros::screen::print(TEXT_MEDIUM, 5, \"Release Count: %d\", status.release_count);\n     *     pros::delay(20);\n     *   }\n     * }\n     * \\endcode\n     */\n    screen_touch_status_s_t touch_status();\n    \n    /**\n     * Assigns a callback function to be called when a certain touch event happens.\n     *\n     * This function uses the following values of errno when an error state is\n     * reached:\n     * EACCESS - Another resource is currently trying to access the screen mutex.\n     * \n     * \\param cb Function pointer to callback when event type happens\n     * \\param event_type Touch event that will trigger the callback.\n     * \n     * \\return 1 if there were no errors, or PROS_ERR if an error occured \n     * while taking or returning the screen mutex.\n     * \n     * \\b Example\n     * \\code\n     * touch_event_cb_fn_t changePixel(){\n     *   pros::screen_touch_status_s_t status = pros::screen::touch_status();\n     *   pros::screen::draw_pixel(status.x,status.y);\n     *   return NULL;\n     * }\n     *\n     * void opcontrol() {\n     *   pros::screen::touch_callback(changePixel(), TOUCH_PRESSED);\n     *   while(1) {\n     *     pros::delay(20);\n     *   }\n     * }\n     * \\endcode\n     */\n    std::uint32_t touch_callback(touch_event_cb_fn_t cb, last_touch_e_t event_type);\n\n} // namespace screen\n\n\n} // namespace pros\n\nextern __attribute__((weak)) void lvgl_init() {}\n///@}\n#endif //header guard\n"
  },
  {
    "path": "include/pros/serial.h",
    "content": "/**\n * \\file pros/serial.h\n * \\ingroup c-serial\n *\n * Contains prototypes for the V5 Generic Serial related functions.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup c-serial Generic Serial C API\n */\n\n#ifndef _PROS_SERIAL_H_\n#define _PROS_SERIAL_H_\n\n#include <stdbool.h>\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\nnamespace c {\n#endif\n\n/**\n * \\ingroup c-serial\n */\n\n/**\n * \\addtogroup c-serial\n *  @{\n */\n\n/// \\name Serial communication functions\n/// These functions allow programmers to communicate using UART over RS485\n///@{\n\n/**\n * Enables generic serial on the given port.\n *\n * \\note This function must be called before any of the generic serial\n * functions will work.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - The given value is not within the range of V5 ports (1-21).\n * EACCES - Another resource is currently trying to access the port.\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example: \n * \\code{.c}\n * void opcontrol() {\n * \tserial_enable(1);\n * \tserial_set_baudrate(1, 9600);\n * }\n * \\endcode\n */\nint32_t serial_enable(uint8_t port);\n\n/**\n * Sets the baudrate for the serial port to operate at.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - The given value is not within the range of V5 ports (1-21).\n * EACCES - Another resource is currently trying to access the port.\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param baudrate\n *        The baudrate to operate at\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example:\n * \\code{.c}\n * void opcontrol() {\n * \tserial_enable(1);\n * \tserial_set_baudrate(1, 9600);\n * \twhile (true) {\n * \t\tserial_write(1, \"Hello World!\", 12);\n * \t\tdelay(100);\n * \t}\n * }\n * \\endcode\n */\nint32_t serial_set_baudrate(uint8_t port, int32_t baudrate);\n\n/**\n * Clears the internal input and output FIFO buffers.\n *\n * This can be useful to reset state and remove old, potentially unneeded data\n * from the input FIFO buffer or to cancel sending any data in the output FIFO\n * buffer.\n *\n * \\note This function does not cause the data in the output buffer to be\n * written, it simply clears the internal buffers. Unlike stdout, generic\n * serial does not use buffered IO (the FIFO buffers are written as soon\n * as possible).\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - The given value is not within the range of V5 ports (1-21).\n * EACCES - Another resource is currently trying to access the port.\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example:\n * \\code{.c}\n * void opcontrol() {\n * \tserial_enable(1);\n * \tserial_set_baudrate(1, 9600);\n * \twhile (true) {\n * \t\tserial_flush(1);\n * \t\tserial_write(1, \"Hello World!\", 12);\n * \t\tdelay(100);\n * \t}\n * }\n * \\endcode\n */\nint32_t serial_flush(uint8_t port);\n\n/**\n * Returns the number of bytes available to be read in the the port's FIFO\n * input buffer.\n *\n * \\note This function does not actually read any bytes, is simply returns the\n * number of bytes available to be read.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - The given value is not within the range of V5 ports (1-21).\n * EACCES - Another resource is currently trying to access the port.\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return The number of bytes avaliable to be read or PROS_ERR if the operation\n * failed, setting errno.\n *\n * \\b Example:\n * \\code{.c}\n * void opcontrol() {\n * \tserial_enable(1);\n * \tserial_set_baudrate(1, 9600);\n * \twhile (true) {\n * \t\tif (serial_get_read_avail(1) >= 12) {\n * \t\t\tchar buffer[12];\n * \t\t\tserial_read(1, buffer, 12);\n * \t\t\tprintf(\"%s\", buffer);\n * \t\t}\n * \t\tdelay(100);\n * \t}\n * }\n * \\endcode\n\n */\nint32_t serial_get_read_avail(uint8_t port);\n\n/**\n * Returns the number of bytes free in the port's FIFO output buffer.\n *\n * \\note This function does not actually write any bytes, is simply returns the\n * number of bytes free in the port's buffer.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - The given value is not within the range of V5 ports (1-21).\n * EACCES - Another resource is currently trying to access the port.\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return The number of bytes free or PROS_ERR if the operation failed,\n * setting errno.\n * \n * \\b Example:\n * \\code{.c}\n * void opcontrol() {\n * \tserial_enable(1);\n * \tserial_set_baudrate(1, 9600);\n * \twhile (true) {\n * \t\tif (serial_get_write_free(1) >= 12) {\n * \t\t\tserial_write(1, \"Hello World!\", 12);\n * \t\t}\n * \t\tdelay(100);\n * \t}\n * }\n * \\endcode\n */\nint32_t serial_get_write_free(uint8_t port);\n\n/**\n * Reads the next byte avaliable in the port's input buffer without removing it.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - The given value is not within the range of V5 ports (1-21).\n * EACCES - Another resource is currently trying to access the port.\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return The next byte avaliable to be read, -1 if none are available, or\n * PROS_ERR if the operation failed, setting errno.\n * \n * \\b Example:\n * \\code{.c}\n * void opcontrol() {\n * \tserial_enable(1);\n * \tserial_set_baudrate(1, 9600);\n * \twhile (true) {\n * \t\tif (serial_peek_byte(1) == 'H') {\n * \t\t\tchar buffer[12];\n * \t\t\tserial_read(1, buffer, 12);\n * \t\t\tprintf(\"%s\", buffer);\n * \t\t}\n * \t\tdelay(100);\n * \t}\n * }\n * \\endcode\n */\nint32_t serial_peek_byte(uint8_t port);\n\n/**\n * Reads the next byte avaliable in the port's input buffer.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - The given value is not within the range of V5 ports (1-21).\n * EACCES - Another resource is currently trying to access the port.\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return The next byte avaliable to be read, -1 if none are available, or\n * PROS_ERR if the operation failed, setting errno.\n * \n * \\b Example:\n * \\code{.c}\n * void opcontrol() {\n * \tserial_enable(1);\n * \tserial_set_baudrate(1, 9600);\n * \twhile (true) {\n * \t\tif (serial_read_byte(1) == 'H') {\n * \t\t\tchar buffer[12];\n * \t\t\tserial_read(1, buffer, 12);\n * \t\t\tprintf(\"%s\", buffer);\n * \t\t}\n * \t\tdelay(100);\n * \t}\n * }\n * \\endcode\n */\nint32_t serial_read_byte(uint8_t port);\n\n/**\n * Reads up to the next length bytes from the port's input buffer and places\n * them in the user supplied buffer.\n *\n * \\note This function will only return bytes that are currently avaliable to be\n * read and will not block waiting for any to arrive.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - The given value is not within the range of V5 ports (1-21).\n * EACCES - Another resource is currently trying to access the port.\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param buffer\n *        The location to place the data read\n * \\param length\n *        The maximum number of bytes to read\n *\n * \\return The number of bytes read or PROS_ERR if the operation failed, setting\n * errno.\n * \n * \\b Example:\n * \\code{.c}\n * void opcontrol() {\n * \tserial_enable(1);\n * \tserial_set_baudrate(1, 9600);\n * \twhile (true) {\n * \t\tif (serial_get_read_avail(1) >= 12) {\n * \t\t\tchar buffer[12];\n * \t\t\tserial_read(1, buffer, 12);\n * \t\t\tprintf(\"%s\", buffer);\n * \t\t}\n * \t\tdelay(100);\n * \t}\n * }\n * \\endcode\n */\nint32_t serial_read(uint8_t port, uint8_t* buffer, int32_t length);\n\n/**\n * Write the given byte to the port's output buffer.\n *\n * \\note Data in the port's output buffer is written to the serial port as soon\n * as possible on a FIFO basis and can not be done manually by the user.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - The given value is not within the range of V5 ports (1-21).\n * EACCES - Another resource is currently trying to access the port.\n * EIO - Serious internal write error.\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param buffer\n *        The byte to write\n *\n * \\return The number of bytes written or PROS_ERR if the operation failed,\n * setting errno.\n *\n * \\b Example:\n * \\code{.c}\n * void opcontrol() {\n * \tserial_enable(1);\n * \tserial_set_baudrate(1, 9600);\n * \twhile (true) {\n * \t\tif (serial_get_write_free(1) >= 12) {\n * \t\t\tserial_write_byte(1, 'H');\n * \t\t\tserial_write_byte(1, 'e');\n * \t\t\tserial_write_byte(1, 'l');\n * \t\t\tserial_write_byte(1, 'l');\n * \t\t\tserial_write_byte(1, 'o');\n * \t\t\tserial_write_byte(1, ' ');\n * \t\t\tserial_write_byte(1, 'W');\n * \t\t\tserial_write_byte(1, 'o');\n * \t\t\tserial_write_byte(1, 'r');\n * \t\t\tserial_write_byte(1, 'l');\n * \t\t\tserial_write_byte(1, 'd');\n * \t\t\tserial_write_byte(1, '!');\n * \t\t    serial_write_byte(1, '\\n');\n * \t\t}\n * \t\tdelay(100);\n * \t}\n * }\n * \\endcode\n */\nint32_t serial_write_byte(uint8_t port, uint8_t buffer);\n\n/**\n * Writes up to length bytes from the user supplied buffer to the port's output\n * buffer.\n *\n * \\note Data in the port's output buffer is written to the serial port as soon\n * as possible on a FIFO basis and can not be done manually by the user.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - The given value is not within the range of V5 ports (1-21).\n * EACCES - Another resource is currently trying to access the port.\n * EIO - Serious internal write error.\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param buffer\n *        The data to write\n * \\param length\n *        The maximum number of bytes to write\n *\n * \\return The number of bytes written or PROS_ERR if the operation failed,\n * setting errno.\n *\n * \\b Example:\n * \\code{.c}\n * void opcontrol() {\n * \tserial_enable(1);\n * \tserial_set_baudrate(1, 9600);\n * \twhile (true) {\n * \t\tif (serial_get_write_free(1) >= 12) {\n * \t\t\tserial_write(1, \"Hello World!\\n\", 12);\n * \t\t}\n * \t\tdelay(100);\n * \t}\n * }\n * \\endcode\n */\nint32_t serial_write(uint8_t port, uint8_t* buffer, int32_t length);\n\n///@}\n\n///@}\n\n#ifdef __cplusplus\n}  // namespace c\n}  // namespace pros\n}\n#endif\n\n#endif  // _PROS_SERIAL_H_"
  },
  {
    "path": "include/pros/serial.hpp",
    "content": "/**\n * \\file pros/serial.hpp\n * \\ingroup cpp-serial\n *\n * Contains prototypes for the V5 Generic Serial related functions.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-serial Generic Serial C++ API\n */\n\n#ifndef _PROS_SERIAL_HPP_\n#define _PROS_SERIAL_HPP_\n\n#include <cstdint>\n\n#include \"pros/device.hpp\"\n#include \"pros/serial.h\"\n\nnamespace pros {\n/**\n * \\ingroup cpp-serial\n *  @{\n */\nclass Serial : public Device {\n\t/**\n\t * \\addtogroup cpp-serial\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Creates a Serial object for the given port and specifications.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - The given value is not within the range of V5 ports (1-21).\n\t * EACCES - Another resource is currently trying to access the port.\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t * \\param baudrate\n\t *        The baudrate to run the port at\n\t *\n\t * \\b Example:\n\t * \\code\n\t * pros::Serial serial(1, 9600);\n\t * \\endcode\n\t */\n\texplicit Serial(std::uint8_t port, std::int32_t baudrate);\n\n\t/**\n\t * Creates a Serial object for the given port without a set baudrate.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - The given value is not within the range of V5 ports (1-21).\n\t * EACCES - Another resource is currently trying to access the port.\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t *\n\t * \\b Example:\n\t * \\code\n\t * pros::Serial serial(1);\n\t * \\endcode\n\t */\n\texplicit Serial(std::uint8_t port);\n\n\t/******************************************************************************/\n\t/**                      Serial communication functions                      **/\n\t/**                                                                          **/\n\t/**  These functions allow programmers to communicate using UART over RS485  **/\n\t/******************************************************************************/\n\n\t/**\n\t * Sets the baudrate for the serial port to operate at.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - The given value is not within the range of V5 ports (1-21).\n\t * EACCES - Another resource is currently trying to access the port.\n\t *\n\t * \\param baudrate\n\t *        The baudrate to operate at\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * pros::Serial serial(1);\n\t * serial.set_baudrate(9600);\n\t * \\endcode\n\t */\n\tvirtual std::int32_t set_baudrate(std::int32_t baudrate) const;\n\n\t/**\n\t * Clears the internal input and output FIFO buffers.\n\t *\n\t * This can be useful to reset state and remove old, potentially unneeded data\n\t * from the input FIFO buffer or to cancel sending any data in the output FIFO\n\t * buffer.\n\t *\n\t * \\note This function does not cause the data in the output buffer to be\n\t * written, it simply clears the internal buffers. Unlike stdout, generic\n\t * serial does not use buffered IO (the FIFO buffers are written as soon\n\t * as possible).\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - The given value is not within the range of V5 ports (1-21).\n\t * EACCES - Another resource is currently trying to access the port.\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * pros::Serial serial(1);\n\t * serial.flush();\n\t * \\endcode\n\t */\n\tvirtual std::int32_t flush() const;\n\n\t/**\n\t * Returns the number of bytes available to be read in the the port's FIFO\n\t * input buffer.\n\t *\n\t * \\note This function does not actually read any bytes, is simply returns the\n\t * number of bytes available to be read.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - The given value is not within the range of V5 ports (1-21).\n\t * EACCES - Another resource is currently trying to access the port.\n\t *\n\t * \\return The number of bytes avaliable to be read or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Serial serial(1);\n\t * \tif(serial.get_read_avail() > 0) {\n\t *  \t std::uint8_t byte = serial.read_byte();\n\t * \t}\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get_read_avail() const;\n\n\t/**\n\t * Returns the number of bytes free in the port's FIFO output buffer.\n\t *\n\t * \\note This function does not actually write any bytes, is simply returns the\n\t * number of bytes free in the port's buffer.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - The given value is not within the range of V5 ports (1-21).\n\t * EACCES - Another resource is currently trying to access the port.\n\t *\n\t * \\return The number of bytes free or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * pros::Serial serial(1);\n\t * \tif(serial.get_write_free() > 0) {\n\t * \t\tserial.write_byte(0x01);\n\t *  \tpros::delay(10);\n\t * \t}\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t get_write_free() const;\n\n\t/**\n\t * Reads the next byte avaliable in the port's input buffer without removing it.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - The given value is not within the range of V5 ports (1-21).\n\t * EACCES - Another resource is currently trying to access the port.\n\t *\n\t * \\return The next byte avaliable to be read, -1 if none are available, or\n\t * PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Serial serial(1);\n\t * \tif(serial.peek_byte() == 0x01) {\n\t * \t\tserial.read_byte();\n\t * \t}\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t peek_byte() const;\n\n\t/**\n\t * Reads the next byte avaliable in the port's input buffer.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - The given value is not within the range of V5 ports (1-21).\n\t * EACCES - Another resource is currently trying to access the port.\n\t *\n\t * \\return The next byte avaliable to be read, -1 if none are available, or\n\t * PROS_ERR if the operation failed, setting errno.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Serial serial(1);\n\t * \tif(serial.read_byte() == 0x01) {\n\t * \t\t// Do something\n\t * \t}\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t read_byte() const;\n\n\t/**\n\t * Reads up to the next length bytes from the port's input buffer and places\n\t * them in the user supplied buffer.\n\t *\n\t * \\note This function will only return bytes that are currently avaliable to be\n\t * read and will not block waiting for any to arrive.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - The given value is not within the range of V5 ports (1-21).\n\t * EACCES - Another resource is currently trying to access the port.\n\t *\n\t * \\param buffer\n\t *        The location to place the data read\n\t * \\param length\n\t *        The maximum number of bytes to read\n\t *\n\t * \\return The number of bytes read or PROS_ERR if the operation failed, setting\n\t * errno.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Serial serial(1);\n\t * \tstd::uint8_t buffer[10];\n\t * \tserial.read(buffer, 10);\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t read(std::uint8_t* buffer, std::int32_t length) const;\n\n\t/**\n\t * Write the given byte to the port's output buffer.\n\t *\n\t * \\note Data in the port's output buffer is written to the serial port as soon\n\t * as possible on a FIFO basis and can not be done manually by the user.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - The given value is not within the range of V5 ports (1-21).\n\t * EACCES - Another resource is currently trying to access the port.\n\t * EIO - Serious internal write error.\n\t *\n\t * \\param buffer\n\t *        The byte to write\n\t *\n\t * \\return The number of bytes written or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Serial serial(1);\n\t * \tserial.write_byte(0x01);\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t write_byte(std::uint8_t buffer) const;\n\n\t/**\n\t * Writes up to length bytes from the user supplied buffer to the port's output\n\t * buffer.\n\t *\n\t * \\note Data in the port's output buffer is written to the serial port as soon\n\t * as possible on a FIFO basis and can not be done manually by the user.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - The given value is not within the range of V5 ports (1-21).\n\t * EACCES - Another resource is currently trying to access the port.\n\t * EIO - Serious internal write error.\n\t *\n\t * \\param buffer\n\t *        The data to write\n\t * \\param length\n\t *        The maximum number of bytes to write\n\t *\n\t * \\return The number of bytes written or PROS_ERR if the operation failed,\n\t * setting errno.\n\t *\n\t * \\b Example:\n\t * \\code\n\t * void opcontrol() {\n\t * \tpros::Serial serial(1);\n\t * \tstd::uint8_t buffer[10];\n\t * \tserial.write(buffer, 10);\n\t * }\n\t * \\endcode\n\t */\n\tvirtual std::int32_t write(std::uint8_t* buffer, std::int32_t length) const;\n\n\tprivate:\n\t///@}\n};\n\nnamespace literals {\n/**\n * Constructs a Serial device from a litteral ending in _ser\n *\n * \\return a pros::Serial for the corresponding port\n *\n * \\b Example\n * \\code\n * using namespace pros::literals;\n * void opcontrol() {\n *\tpros::Serial serial = 2_ser; //Makes an Serial device object on port 2\n * }\n * \\endcode\n */\nconst pros::Serial operator\"\"_ser(const unsigned long long int m);\n}  // namespace literals\n}  // namespace pros\n#endif  // _PROS_SERIAL_HPP_\n"
  },
  {
    "path": "include/pros/version.h",
    "content": "/**\n* \\file version.h\n*\n* PROS Version Information\n*\n* Contains PROS kernel version information\n*\n*\n* \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n* All rights reserved.\n*\n* This Source Code Form is subject to the terms of the Mozilla Public\n* License, v. 2.0. If a copy of the MPL was not distributed with this\n* file, You can obtain one at http://mozilla.org/MPL/2.0/.\n*/\n\n#pragma once\n\n#define PROS_VERSION_MAJOR 4\n#define PROS_VERSION_MINOR 2\n\n#define PROS_VERSION_PATCH 1\n#define PROS_VERSION_STRING \"4.2.1\"\n"
  },
  {
    "path": "include/pros/vision.h",
    "content": "/**\n * \\file pros/vision.h\n * \\ingroup c-vision\n *\n * Contains prototypes for the VEX Vision Sensor-related functions.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n * \n * \\defgroup c-vision Vision Sensor C API\n * \\note Additional example code for this module can be found in its [Tutorial.](@ref vision)\n */\n\n#ifndef _PROS_VISION_H_\n#define _PROS_VISION_H_\n\n/**\n * \\ingroup c-vision\n */\n\n/**\n * \\addtogroup c-vision\n *  @{\n */\n\n/// \\name Macros\n///Parameters given by VEX\n///@{\n\n#define VISION_OBJECT_ERR_SIG 255\n\n/**\n * The width of the Vision Sensor’s field of view.\n */\n#define VISION_FOV_WIDTH 316\n\n/**\n * The height of the Vision Sensor’s field of view.\n */\n#define VISION_FOV_HEIGHT 212\n\n///@}\n\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\nnamespace pros {\n#endif\n\n/**\n * \\enum vision_object_type_e_t\n * This enumeration defines the different types of objects that can be detected by the Vision Sensor\n */\ntypedef enum vision_object_type {\n\tE_VISION_OBJECT_NORMAL = 0,\n\tE_VISION_OBJECT_COLOR_CODE = 1,\n\tE_VISION_OBJECT_LINE = 2\n} vision_object_type_e_t;\n\n/**\n * \\struct vision_signature_s_t\n * This structure contains the parameters used by the Vision Sensor to detect objects.\n */\ntypedef struct __attribute__((__packed__)) vision_signature {\n\tuint8_t id;\n\tuint8_t _pad[3];\n\tfloat range;\n\tint32_t u_min;\n\tint32_t u_max;\n\tint32_t u_mean;\n\tint32_t v_min;\n\tint32_t v_max;\n\tint32_t v_mean;\n\tuint32_t rgb;\n\tuint32_t type;\n} vision_signature_s_t;\n\n/**\n * \\typedef vision_color_code_t\n * Color codes are just signatures with multiple IDs and a different type.\n */\ntypedef uint16_t vision_color_code_t;\n\n/**\n * \\struct vision_object_s_t\n * This structure contains a descriptor of an object detected by the Vision Sensor\n */\ntypedef struct __attribute__((__packed__)) vision_object {\n\t/// Object signature\n\tuint16_t signature;\n\t/// Object type, e.g. normal, color code, or line detection\n\tvision_object_type_e_t type;\n\t/// Left boundary coordinate of the object\n\tint16_t left_coord;\n\t/// Top boundary coordinate of the object\n\tint16_t top_coord;\n\t/// Width of the object\n\tint16_t width;\n\t/// Height of the object\n\tint16_t height;\n\t/// Angle of a color code object in 0.1 degree units (e.g. 10 -> 1 degree, 155 -> 15.5 degrees)\n\tuint16_t angle;\n\t/// Coordinates of the middle of the object (computed from the values above)\n\tint16_t x_middle_coord;\n\t/// Coordinates of the middle of the object (computed from the values above)\n\tint16_t y_middle_coord;\n} vision_object_s_t;\n\n/**\n * \\enum vision_zero\n * This enumeration defines different zero points for returned vision objects.\n */\ntypedef enum vision_zero {\n\t/// (0,0) coordinate is the top left of the FOV\n\tE_VISION_ZERO_TOPLEFT = 0,\n\t/// (0,0) coordinate is the center of the FOV\n\tE_VISION_ZERO_CENTER = 1\n} vision_zero_e_t;\n\n#ifdef PROS_USE_SIMPLE_NAMES\n#ifdef __cplusplus\n#define VISION_OBJECT_NORMAL pros::E_VISION_OBJECT_NORMAL\n#define VISION_OBJECT_COLOR_CODE pros::E_VISION_OBJECT_COLOR_CODE\n#define VISION_OBJECT_LINE pros::E_VISION_OBJECT_LINE\n#define VISION_ZERO_TOPLEFT pros::E_VISION_ZERO_TOPLEFT\n#define VISION_ZERO_CENTER pros::E_VISION_ZERO_CENTER\n#else\n#define VISION_OBJECT_NORMAL E_VISION_OBJECT_NORMAL\n#define VISION_OBJECT_COLOR_CODE E_VISION_OBJECT_COLOR_CODE\n#define VISION_OBJECT_LINE E_VISION_OBJECT_LINE\n#define VISION_ZERO_TOPLEFT E_VISION_ZERO_TOPLEFT\n#define VISION_ZERO_CENTER E_VISION_ZERO_CENTER\n#endif\n#endif\n\n#ifdef __cplusplus\nnamespace c {\n#endif\n\n/// \\name Functions\n///@{\n\n/**\n * Clears the vision sensor LED color, reseting it back to its default behavior,\n * displaying the most prominent object signature color.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * void initialize() {\n *   vision_clear_led(VISION_PORT);\n * }\n * \\endcode\n */\nint32_t vision_clear_led(uint8_t port);\n\n/**\n * Creates a signature from the vision sensor utility\n *\n * \\param id\n *        The signature ID\n * \\param u_min\n *        Minimum value on U axis\n * \\param u_max\n *        Maximum value on U axis\n * \\param u_mean\n *        Mean value on U axis\n * \\param v_min\n *        Minimum value on V axis\n * \\param v_max\n *        Maximum value on V axis\n * \\param v_mean\n *        Mean value on V axis\n * \\param range\n *        Scale factor\n * \\param type\n *        Signature type\n *\n * \\return A vision_signature_s_t that can be set using vision_set_signature\n *\n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define EXAMPLE_SIG 1\n *\n * void opcontrol() {\n * // values acquired from the vision utility\n * vision_signature_s_t RED_SIG =\n *   vision_signature_from_utility(EXAMPLE_SIG, 8973, 11143, 10058, -2119, -1053, -1586, 5.4, 0);\n * vision_set_signature(VISION_PORT, EXAMPLE_SIG, &RED_SIG);\n * while (true) {\n *   vision_signature_s_t rtn = vision_get_by_sig(VISION_PORT, 0, EXAMPLE_SIG);\n *   // Gets the largest object of the EXAMPLE_SIG signature\n *   printf(\"sig: %d\", rtn.signature);\n *   // Prints \"sig: 1\"\n *   delay(2);\n *   }\n * }\n * \\endcode\n */\nvision_signature_s_t vision_signature_from_utility(const int32_t id, const int32_t u_min, const int32_t u_max,\n                                                   const int32_t u_mean, const int32_t v_min, const int32_t v_max,\n                                                   const int32_t v_mean, const float range, const int32_t type);\n\n/**\n * Creates a color code that represents a combination of the given signature\n * IDs. If fewer than 5 signatures are to be a part of the color code, pass 0\n * for the additional function parameters.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * EINVAL - Fewer than two signatures have been provided or one of the\n *          signatures is out of its [1-7] range (or 0 when omitted).\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param sig_id1\n *        The first signature id [1-7] to add to the color code\n * \\param sig_id2\n *        The second signature id [1-7] to add to the color code\n * \\param sig_id3\n *        The third signature id [1-7] to add to the color code\n * \\param sig_id4\n *        The fourth signature id [1-7] to add to the color code\n * \\param sig_id5\n *        The fifth signature id [1-7] to add to the color code\n *\n * \\return A vision_color_code_t object containing the color code information.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define EXAMPLE_SIG 1\n * #define OTHER_SIG 2\n * \n * void opcontrol() {\n *   vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG);\n * }\n * \\endcode\n */\nvision_color_code_t vision_create_color_code(uint8_t port, const uint32_t sig_id1, const uint32_t sig_id2,\n                                             const uint32_t sig_id3, const uint32_t sig_id4, const uint32_t sig_id5);\n\n/**\n * Gets the nth largest object according to size_id.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n * EDOM - size_id is greater than the number of available objects.\n * EHOSTDOWN - Reading the vision sensor failed for an unknown reason.\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param size_id\n *        The object to read from a list roughly ordered by object size\n *        (0 is the largest item, 1 is the second largest, etc.)\n *\n * \\return The vision_object_s_t object corresponding to the given size id, or\n * PROS_ERR if an error occurred.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * \n * void opcontrol() {\n * while (true) {\n *   vision_object_s_t rtn = vision_get_by_size(VISION_PORT, 0);\n *   // Gets the largest object\n *   printf(\"sig: %d\", rtn.signature);\n *   delay(2);\n *   }\n * }\n * \\endcode\n */\nvision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id);\n\n/**\n * Gets the nth largest object of the given signature according to size_id.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n * EINVAL - sig_id is outside the range [1-8]\n * EDOM - size_id is greater than the number of available objects.\n * EAGAIN - Reading the vision sensor failed for an unknown reason.\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param size_id\n *        The object to read from a list roughly ordered by object size\n *        (0 is the largest item, 1 is the second largest, etc.)\n * \\param signature\n *        The signature ID [1-7] for which an object will be returned.\n *\n * \\return The vision_object_s_t object corresponding to the given signature and\n * size_id, or PROS_ERR if an error occurred.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define EXAMPLE_SIG 1\n * \n * void opcontrol() {\n * while (true) {\n *   vision_object_s_t rtn = vision_get_by_sig(VISION_PORT, 0, EXAMPLE_SIG);\n *   // Gets the largest object of the EXAMPLE_SIG signature\n *   printf(\"sig: %d\", rtn.signature);\n *   // Prints \"sig: 1\"\n *   delay(2);\n *   }\n * }\n * \\endcode\n */\nvision_object_s_t vision_get_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id);\n\n/**\n * Gets the nth largest object of the given color code according to size_id.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n * EAGAIN - Reading the vision sensor failed for an unknown reason.\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param size_id\n *        The object to read from a list roughly ordered by object size\n *        (0 is the largest item, 1 is the second largest, etc.)\n * \\param color_code\n *        The vision_color_code_t for which an object will be returned\n *\n * \\return The vision_object_s_t object corresponding to the given color code\n * and size_id, or PROS_ERR if an error occurred.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define EXAMPLE_SIG 1\n * #define OTHER_SIG 2\n * \n * void opcontrol() {\n *   vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG);\n *   while (true) {\n *     vision_object_s_t rtn = vision_get_by_code(VISION_PORT, 0, code1);\n *     // Gets the largest object\n *     printf(\"sig: %d\", rtn.signature);\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nvision_object_s_t vision_get_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code);\n\n/**\n * Gets the exposure parameter of the Vision Sensor. \n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return The current exposure setting from [0,150], PROS_ERR if an error\n * occurred\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * \n * void initialize() {\n *   if (vision_get_exposure(VISION_PORT) < 50)\n *   vision_set_exposure(VISION_PORT, 50);\n * }\n * \\endcode\n */\nint32_t vision_get_exposure(uint8_t port);\n\n/**\n * Gets the number of objects currently detected by the Vision Sensor.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return The number of objects detected on the specified vision sensor.\n * Returns PROS_ERR if the port was invalid or an error occurred.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * \n * void opcontrol() {\n *   while (true) {\n *     printf(\"Number of Objects Detected: %d\\n\", vision_get_object_count(VISION_PORT));\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t vision_get_object_count(uint8_t port);\n\n/**\n * Get the white balance parameter of the Vision Sensor.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port\n * \t\t    The V5 port number from 1-21\n *\n * \\return The current RGB white balance setting of the sensor\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define VISION_WHITE 0xff\n * \n * void initialize() {\n *   if (vision_get_white_balance(VISION_PORT) != VISION_WHITE)\n *   vision_set_white_balance(VISION_PORT, VISION_WHITE);\n * }\n * \\endcode\n */\nint32_t vision_get_white_balance(uint8_t port);\n\n/**\n * Prints the contents of the signature as an initializer list to the terminal.\n *\n * \\param sig\n *        The signature for which the contents will be printed\n *\n * \\return 1 if no errors occured, PROS_ERR otherwise\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define EXAMPLE_SIG 1\n * \n * void opcontrol() {\n *   vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG);\n *   vision_print_signature(sig);\n * }\n * \\endcode\n */\nint32_t vision_print_signature(const vision_signature_s_t sig);\n\n/**\n * Reads up to object_count object descriptors into object_arr.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21), or\n *          fewer than object_count number of objects were found.\n * ENODEV - The port cannot be configured as a vision sensor\n * EDOM - size_id is greater than the number of available objects.\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param size_id\n *        The object to read from a list roughly ordered by object size\n *        (0 is the largest item, 1 is the second largest, etc.)\n * \\param object_count\n *        The number of objects to read\n * \\param[out] object_arr\n *             A pointer to copy the objects into\n *\n * \\return The number of object signatures copied. This number will be less than\n * object_count if there are fewer objects detected by the vision sensor.\n * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects\n * than size_id were found. All objects in object_arr that were not found are\n * given VISION_OBJECT_ERR_SIG as their signature.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define NUM_VISION_OBJECTS 4\n * \n * void opcontrol() {\n *   vision_object_s_t object_arr[NUM_VISION_OBJECTS];\n *   while (true) {\n *     vision_read_by_size(VISION_PORT, 0, NUM_VISION_OBJECTS, object_arr);\n *     printf(\"sig: %d\", object_arr[0].signature);\n *     // Prints the signature of the largest object found\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t object_count,\n                            vision_object_s_t* const object_arr);\n\n/**\n * Reads up to object_count object descriptors into object_arr.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21), or\n *          fewer than object_count number of objects were found.\n * ENODEV - The port cannot be configured as a vision sensor\n * EDOM - size_id is greater than the number of available objects.\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param object_count\n *        The number of objects to read\n * \\param size_id\n *        The object to read from a list roughly ordered by object size\n *        (0 is the largest item, 1 is the second largest, etc.)\n * \\param signature\n *        The signature ID [1-7] for which objects will be returned.\n * \\param[out] object_arr\n *             A pointer to copy the objects into\n *\n * \\return The number of object signatures copied. This number will be less than\n * object_count if there are fewer objects detected by the vision sensor.\n * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects\n * than size_id were found. All objects in object_arr that were not found are\n * given VISION_OBJECT_ERR_SIG as their signature.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define EXAMPLE_SIG 1\n * #define NUM_VISION_OBJECTS 4\n * \n * void opcontrol() {\n *   vision_object_s_t object_arr[NUM_VISION_OBJECTS];\n *   while (true) {\n *     vision_read_by_sig(VISION_PORT, 0, EXAMPLE_SIG, NUM_VISION_OBJECTS, object_arr);\n *     printf(\"sig: %d\", object_arr[0].signature);\n *     // Prints \"sig: 1\"\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id, const uint32_t object_count,\n                           vision_object_s_t* const object_arr);\n\n/**\n * Reads up to object_count object descriptors into object_arr.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21), or\n *          fewer than object_count number of objects were found.\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param object_count\n *        The number of objects to read\n * \\param size_id\n *        The object to read from a list roughly ordered by object size\n *        (0 is the largest item, 1 is the second largest, etc.)\n * \\param color_code\n *        The vision_color_code_t for which objects will be returned\n * \\param[out] object_arr\n *             A pointer to copy the objects into\n *\n * \\return The number of object signatures copied. This number will be less than\n * object_count if there are fewer objects detected by the vision sensor.\n * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects\n * than size_id were found. All objects in object_arr that were not found are\n * given VISION_OBJECT_ERR_SIG as their signature.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define EXAMPLE_SIG 1\n * #define OTHER_SIG 2\n * #define NUM_VISION_OBJECTS 4\n * \n * void opcontrol() {\n *   vision_object_s_t object_arr[NUM_VISION_OBJECTS];\n *   vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG, 0, 0, 0);\n *   while (true) {\n *     vision_read_by_code(VISION_PORT, 0, code1, NUM_VISION_OBJECTS, object_arr);\n *     printf(\"sig: %d\", object_arr[0].signature);\n *     // Prints the signature of the largest object found\n *     delay(2);\n *   }\n * }\n * \\endcode\n */\nint32_t vision_read_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code,\n                            const uint32_t object_count, vision_object_s_t* const object_arr);\n\n/**\n * Gets the object detection signature with the given id number.\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param signature_id\n *        The signature id to read\n *\n * \\return A vision_signature_s_t containing information about the signature.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define EXAMPLE_SIG 1\n * \n * void opcontrol() {\n *   vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG);\n *   vision_print_signature(sig);\n * }\n * \\endcode\n */\nvision_signature_s_t vision_get_signature(uint8_t port, const uint8_t signature_id);\n\n/**\n * Stores the supplied object detection signature onto the vision sensor.\n *\n * \\note This saves the signature in volatile memory, and the signature will be\n * lost as soon as the sensor is powered down.\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param signature_id\n *        The signature id to store into\n * \\param[in] signature_ptr\n *            A pointer to the signature to save\n *\n * \\return 1 if no errors occured, PROS_ERR otherwise\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define EXAMPLE_SIG 1\n * \n * void opcontrol() {\n *   vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG);\n *   sig.range = 10.0;\n *   vision_set_signature(VISION_PORT, EXAMPLE_SIG, &sig);\n * }\n * \\endcode\n */\nint32_t vision_set_signature(uint8_t port, const uint8_t signature_id, vision_signature_s_t* const signature_ptr);\n\n/**\n * Enables/disables auto white-balancing on the Vision Sensor.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n * EINVAL - enable was not 0 or 1\n *\n * \\param port\n * \t\t    The V5 port number from 1-21\n * \\param enabled\n * \t\t    Pass 0 to disable, 1 to enable\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * \n * void initialize() {\n *   vision_set_auto_white_balance(VISION_PORT, true);\n * }\n * \\endcode\n */\nint32_t vision_set_auto_white_balance(uint8_t port, const uint8_t enable);\n\n/**\n * Sets the exposure parameter of the Vision Sensor. \n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param percent\n *        The new exposure setting from [0,150]\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * \n * void initialize() {\n *   if (vision_get_exposure(VISION_PORT) < 50)\n *   vision_set_exposure(VISION_PORT, 50);\n * }\n * \\endcode\n */\nint32_t vision_set_exposure(uint8_t port, const uint8_t exposure);\n\n/**\n * Sets the vision sensor LED color, overriding the automatic behavior.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param rgb\n *        An RGB code to set the LED to\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * \n * void initialize() {\n *   vision_set_led(VISION_PORT, COLOR_BLANCHED_ALMOND);\n * }\n * \\endcode\n */\nint32_t vision_set_led(uint8_t port, const int32_t rgb);\n\n/**\n * Sets the white balance parameter of the Vision Sensor.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port\n * \t\t    The V5 port number from 1-21\n * \\param rgb\n *        The new RGB white balance setting of the sensor\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * #define VISION_WHITE 0xff\n * \n * void initialize() {\n *   vision_set_white_balance(VISION_PORT, VISION_WHITE);\n * }\n * \\endcode\n */\nint32_t vision_set_white_balance(uint8_t port, const int32_t rgb);\n\n/**\n * Sets the (0,0) coordinate for the Field of View.\n *\n * This will affect the coordinates returned for each request for a\n * vision_object_s_t from the sensor, so it is recommended that this function\n * only be used to configure the sensor at the beginning of its use.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * ENODEV - The port cannot be configured as a vision sensor\n *\n * \\param port\n * \t\t    The V5 port number from 1-21\n * \\param zero_point\n *        One of vision_zero_e_t to set the (0,0) coordinate for the FOV\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * \n * void initialize() {\n *   vision_set_zero_point(VISION_PORT, E_VISION_ZERO_CENTER);\n * }\n * \\endcode\n */\nint32_t vision_set_zero_point(uint8_t port, vision_zero_e_t zero_point);\n\n/**\n * Sets the Wi-Fi mode of the Vision sensor\n *\n * This functions uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given port is not within the range of V5 ports (1-21)\n * EACCESS - Anothe resources is currently trying to access the port\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param enable\n *        Disable Wi-Fi on the Vision sensor if 0, enable otherwise (e.g. 1)\n *\n * \\return 1 if the operation was successful or PROS_ERR if the operation\n * failed, setting errno.\n * \n * \\b Example\n * \\code\n * #define VISION_PORT 1\n * \n * void initialize() {\n *   vision_set_wifi_mode(VISION_PORT, 0);\n * }\n * \\endcode\n */\nint32_t vision_set_wifi_mode(uint8_t port, const uint8_t enable);\n\n///@}\n\n///@}\n\n#ifdef __cplusplus\n}  // namespace c\n}  // namespace pros\n}\n#endif\n\n#endif  // _PROS_VISION_H_\n"
  },
  {
    "path": "include/pros/vision.hpp",
    "content": "/**\n * \\file pros/vision.hpp\n * \\ingroup cpp-vision\n *\n * Contains prototypes for the VEX Vision Sensor-related functions in C++.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n *\n * \\defgroup cpp-vision Vision Sensor C++ API\n * \\note Additional example code for this module can be found in its [Tutorial.](@ref vision)\n */\n\n#ifndef _PROS_VISION_HPP_\n#define _PROS_VISION_HPP_\n\n#include <cstdint>\n\n#include \"pros/device.hpp\"\n#include \"pros/vision.h\"\n\nnamespace pros {\ninline namespace v5 {\n/**\n * \\ingroup cpp-vision\n */\nclass Vision : public Device {\n\t/**\n\t * \\addtogroup cpp-vision\n\t *  @{\n\t */\n\tpublic:\n\t/**\n\t * Create a Vision Sensor object on the given port.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENXIO - The given value is not within the range of V5 ports (1-21).\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\param port\n\t *        The V5 port number from 1-21\n\t * \\param zero_point\n\t *        One of vision_zero_e_t to set the (0,0) coordinate for the FOV\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   pros::Vision vision_sensor(1); // Creates a vision sensor on port one, with the zero point set to top left\n\t * }\n\t * \\endcode\n\t */\n\tVision(std::uint8_t port, vision_zero_e_t zero_point = E_VISION_ZERO_TOPLEFT);\n\n\tVision(const Device& device) : Vision(device.get_port()){};\n\n\t/**\n\t * Clears the vision sensor LED color, reseting it back to its default\n\t * behavior, displaying the most prominent object signature color.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void initialize() {\n\t *   pros::Vision vision_sensor(1);\n\t *   vision_sensor.clear_led();\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t clear_led(void) const;\n\n\t/**\n\t * Creates a signature from the vision sensor utility\n\t *\n\t * \\param id\n\t *        The signature ID\n\t * \\param u_min\n\t *        Minimum value on U axis\n\t * \\param u_max\n\t *        Maximum value on U axis\n\t * \\param u_mean\n\t *        Mean value on U axis\n\t * \\param v_min\n\t *        Minimum value on V axis\n\t * \\param v_max\n\t *        Maximum value on V axis\n\t * \\param v_mean\n\t *        Mean value on V axis\n\t * \\param rgb\n\t *        Scale factor\n\t * \\param type\n\t *        Signature type\n\t *\n\t * \\return A vision_signature_s_t that can be set using Vision::set_signature\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define EXAMPLE_SIG 1\n\t *\n\t * void opcontrol() {\n\t * pros::Vision vision_sensor(VISION_PORT);\n\t * // values acquired from the vision utility\n\t * vision_signature_s_t RED_SIG =\n\t *   vision_signature_from_utility(EXAMPLE_SIG, 8973, 11143, 10058, -2119, -1053, -1586, 5.4, 0);\n\t * vision_sensor.set_signature(EXAMPLE_SIG, &RED_SIG);\n\t * while (true) {\n\t *   vision_signature_s_t rtn = vision_sensor.get_by_sig(VISION_PORT, 0, EXAMPLE_SIG);\n\t *   // Gets the largest object of the EXAMPLE_SIG signature\n\t *   printf(\"sig: %d\", rtn.signature);\n\t *   // Prints \"sig: 1\"\n\t *   delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstatic vision_signature_s_t signature_from_utility(const std::int32_t id, const std::int32_t u_min,\n\t                                                   const std::int32_t u_max, const std::int32_t u_mean,\n\t                                                   const std::int32_t v_min, const std::int32_t v_max,\n\t                                                   const std::int32_t v_mean, const float range,\n\t                                                   const std::int32_t type);\n\n\t/**\n\t * Creates a color code that represents a combination of the given signature\n\t * IDs.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EINVAL - Fewer than two signatures have been provided or one of the\n\t *          signatures is out of its [1-7] range (or 0 when omitted).\n\t *\n\t * \\param sig_id1\n\t *        The first signature id [1-7] to add to the color code\n\t * \\param sig_id2\n\t *        The second signature id [1-7] to add to the color code\n\t * \\param sig_id3\n\t *        The third signature id [1-7] to add to the color code\n\t * \\param sig_id4\n\t *        The fourth signature id [1-7] to add to the color code\n\t * \\param sig_id5\n\t *        The fifth signature id [1-7] to add to the color code\n\t *\n\t * \\return A vision_color_code_t object containing the color code information.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define EXAMPLE_SIG 1\n\t * #define OTHER_SIG 2\n\t *\n\t * void opcontrol() {\n\t *   pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG);\n\t * }\n\t * \\endcode\n\t */\n\tvision_color_code_t create_color_code(const std::uint32_t sig_id1, const std::uint32_t sig_id2,\n\t                                      const std::uint32_t sig_id3 = 0, const std::uint32_t sig_id4 = 0,\n\t                                      const std::uint32_t sig_id5 = 0) const;\n\n\t/**\n\t * Gets all vision sensors.\n\t *\n\t * \\return A vector of Vision sensor objects.\n\t *\n\t * \\b Example\n\t * \\code\n\t * void opcontrol() {\n\t *   std::vector<Vision> vision_all = pros::Vision::get_all_devices();  // All vision sensors that are connected\n\t * }\n\t * \\endcode\n\t */\n\tstatic std::vector<Vision> get_all_devices();\n\n\t/**\n\t * Gets the nth largest object according to size_id.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t * EDOM - size_id is greater than the number of available objects.\n\t * EAGAIN - Reading the vision sensor failed for an unknown reason.\n\t *\n\t * \\param size_id\n\t *        The object to read from a list roughly ordered by object size\n\t *        (0 is the largest item, 1 is the second largest, etc.)\n\t *\n\t * \\return The vision_object_s_t object corresponding to the given size id, or\n\t * PROS_ERR if an error occurred.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t *\n\t * void opcontrol() {\n\t * pros::Vision vision_sensor(VISION_PORT);\n\t * while (true) {\n\t *   vision_object_s_t rtn = vision_sensor.get_by_size(0);\n\t *   // Gets the largest object\n\t *   printf(\"sig: %d\", rtn.signature);\n\t *   delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvision_object_s_t get_by_size(const std::uint32_t size_id) const;\n\n\t/**\n\t * Gets the nth largest object of the given signature according to size_id.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t * EDOM - size_id is greater than the number of available objects.\n\t * EINVAL - sig_id is outside the range [1-8]\n\t * EAGAIN - Reading the vision sensor failed for an unknown reason.\n\t *\n\t * \\param size_id\n\t *        The object to read from a list roughly ordered by object size\n\t *        (0 is the largest item, 1 is the second largest, etc.)\n\t * \\param signature\n\t *        The vision_signature_s_t signature for which an object will be\n\t *        returned.\n\t *\n\t * \\return The vision_object_s_t object corresponding to the given signature\n\t * and size_id, or PROS_ERR if an error occurred.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define EXAMPLE_SIG 1\n\t *\n\t * void opcontrol() {\n\t * pros::Vision vision_sensor(VISION_PORT);\n\t * while (true) {\n\t *   vision_object_s_t rtn = vision_sensor.get_by_sig(0, EXAMPLE_SIG);\n\t *   // Gets the largest object of the EXAMPLE_SIG signature\n\t *   printf(\"sig: %d\", rtn.signature);\n\t *   // Prints \"sig: 1\"\n\t *   delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvision_object_s_t get_by_sig(const std::uint32_t size_id, const std::uint32_t sig_id) const;\n\n\t/**\n\t * Gets the nth largest object of the given color code according to size_id.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t * EAGAIN - Reading the Vision Sensor failed for an unknown reason.\n\t *\n\t * \\param size_id\n\t *        The object to read from a list roughly ordered by object size\n\t *        (0 is the largest item, 1 is the second largest, etc.)\n\t * \\param color_code\n\t *        The vision_color_code_t for which an object will be returned\n\t *\n\t * \\return The vision_object_s_t object corresponding to the given color code\n\t * and size_id, or PROS_ERR if an error occurred.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define EXAMPLE_SIG 1\n\t * #define OTHER_SIG 2\n\t *\n\t * void opcontrol() {\n\t * \t pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG);\n\t *   while (true) {\n\t *     vision_object_s_t rtn = vision_sensor.get_by_code(0, code1);\n\t *     // Gets the largest object\n\t *     printf(\"sig: %d\", rtn.signature);\n\t *     delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tvision_object_s_t get_by_code(const std::uint32_t size_id, const vision_color_code_t color_code) const;\n\n\t/**\n\t * Gets the exposure parameter of the Vision Sensor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\return The current exposure parameter from [0,150],\n\t * PROS_ERR if an error occurred\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t *\n\t * void initialize() {\n\t *   pros::Vision vision_sensor(VISION_PORT);\n\t *   if (vision_sensor.get_exposure() < 50)\n\t *   vision_sensor.set_exposure(50);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_exposure(void) const;\n\n\t/**\n\t * Gets the number of objects currently detected by the Vision Sensor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\return The number of objects detected on the specified vision sensor.\n\t * Returns PROS_ERR if the port was invalid or an error occurred.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Vision vision_sensor(VISION_PORT);\n\t *   while (true) {\n\t *     printf(\"Number of Objects Detected: %d\\n\", vision_sensor.get_object_count());\n\t *     delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_object_count(void) const;\n\n\t/**\n\t * Gets the object detection signature with the given id number.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\param signature_id\n\t *        The signature id to read\n\t *\n\t * \\return A vision_signature_s_t containing information about the signature.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define EXAMPLE_SIG 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_signature_s_t sig = vision_sensor.get_signature(EXAMPLE_SIG);\n\t *   vision_sensor.print_signature(sig);\n\t * }\n\t * \\endcode\n\t */\n\tvision_signature_s_t get_signature(const std::uint8_t signature_id) const;\n\n\t/**\n\t * Get the white balance parameter of the Vision Sensor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\return The current RGB white balance setting of the sensor\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define VISION_WHITE 0xff\n\t *\n\t * void initialize() {\n\t * \t pros::Vision vision_sensor(VISION_PORT);\n\t *   if (vision_sensor.get_white_balance() != VISION_WHITE)\n\t *   vision_sensor.set_white_balance(VISION_WHITE);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t get_white_balance(void) const;\n\n\t/**\n\t * Reads up to object_count object descriptors into object_arr.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t * EDOM - size_id is greater than the number of available objects.\n\t * EAGAIN - Reading the vision sensor failed for an unknown reason.\n\t *\n\t * \\param size_id\n\t *        The object to read from a list roughly ordered by object size\n\t *        (0 is the largest item, 1 is the second largest, etc.)\n\t * \\param object_count\n\t *        The number of objects to read\n\t * \\param[out] object_arr\n\t *             A pointer to copy the objects into\n\t *\n\t * \\return The number of object signatures copied. This number will be less than\n\t * object_count if there are fewer objects detected by the vision sensor.\n\t * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects\n\t * than size_id were found. All objects in object_arr that were not found are\n\t * given VISION_OBJECT_ERR_SIG as their signature.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define NUM_VISION_OBJECTS 4\n\t *\n\t * void opcontrol() {\n\t *   pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_object_s_t object_arr[NUM_VISION_OBJECTS];\n\t *   while (true) {\n\t *     vision_sensor.read_by_size(0, NUM_VISION_OBJECTS, object_arr);\n\t *     printf(\"sig: %d\", object_arr[0].signature);\n\t *     // Prints the signature of the largest object found\n\t *     delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t read_by_size(const std::uint32_t size_id, const std::uint32_t object_count,\n\t                          vision_object_s_t* const object_arr) const;\n\n\t/**\n\t * Reads up to object_count object descriptors into object_arr.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t * EDOM - size_id is greater than the number of available objects.\n\t * EINVAL - sig_id is outside the range [1-8]\n\t * EAGAIN - Reading the vision sensor failed for an unknown reason.\n\t *\n\t * \\param object_count\n\t *        The number of objects to read\n\t * \\param size_id\n\t *        The object to read from a list roughly ordered by object size\n\t *        (0 is the largest item, 1 is the second largest, etc.)\n\t * \\param signature\n\t *        The vision_signature_s_t signature for which an object will be\n\t *        returned.\n\t * \\param[out] object_arr\n\t *             A pointer to copy the objects into\n\t *\n\t * \\return The number of object signatures copied. This number will be less than\n\t * object_count if there are fewer objects detected by the vision sensor.\n\t * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects\n\t * than size_id were found. All objects in object_arr that were not found are\n\t * given VISION_OBJECT_ERR_SIG as their signature.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define EXAMPLE_SIG 1\n\t * #define NUM_VISION_OBJECTS 4\n\t *\n\t * void opcontrol() {\n\t *   pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_object_s_t object_arr[NUM_VISION_OBJECTS];\n\t *   while (true) {\n\t *     vision_sensor.read_by_sig(0, EXAMPLE_SIG, NUM_VISION_OBJECTS, object_arr);\n\t *     printf(\"sig: %d\", object_arr[0].signature);\n\t *     // Prints \"sig: 1\"\n\t *     delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t read_by_sig(const std::uint32_t size_id, const std::uint32_t sig_id, const std::uint32_t object_count,\n\t                         vision_object_s_t* const object_arr) const;\n\n\t/**\n\t * Reads up to object_count object descriptors into object_arr.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * EDOM - size_id is greater than the number of available objects.\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t * EAGAIN - Reading the vision sensor failed for an unknown reason.\n\t *\n\t * \\param object_count\n\t *        The number of objects to read\n\t * \\param size_id\n\t *        The object to read from a list roughly ordered by object size\n\t *        (0 is the largest item, 1 is the second largest, etc.)\n\t * \\param color_code\n\t *        The vision_color_code_t for which objects will be returned\n\t * \\param[out] object_arr\n\t *             A pointer to copy the objects into\n\t *\n\t * \\return The number of object signatures copied. This number will be less than\n\t * object_count if there are fewer objects detected by the vision sensor.\n\t * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects\n\t * than size_id were found. All objects in object_arr that were not found are\n\t * given VISION_OBJECT_ERR_SIG as their signature.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define EXAMPLE_SIG 1\n\t * #define OTHER_SIG 2\n\t * #define NUM_VISION_OBJECTS 4\n\t *\n\t * void opcontrol() {\n\t *   pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_object_s_t object_arr[NUM_VISION_OBJECTS];\n\t *   vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG, 0, 0, 0);\n\t *   while (true) {\n\t *     vision_sensor.read_by_code(0, code1, NUM_VISION_OBJECTS, object_arr);\n\t *     printf(\"sig: %d\", object_arr[0].signature);\n\t *     // Prints the signature of the largest object found\n\t *     delay(2);\n\t *   }\n\t * }\n\t * \\endcode\n\t */\n\tint32_t read_by_code(const std::uint32_t size_id, const vision_color_code_t color_code,\n\t                     const std::uint32_t object_count, vision_object_s_t* const object_arr) const;\n\n\t/**\n\t * Prints the contents of the signature as an initializer list to the terminal.\n\t *\n\t * \\param sig\n\t *        The signature for which the contents will be printed\n\t *\n\t * \\return 1 if no errors occured, PROS_ERR otherwise\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define EXAMPLE_SIG 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_signature_s_t sig = visionsensor.get_signature(EXAMPLE_SIG);\n\t *   vision_print_signature(sig);\n\t * }\n\t * \\endcode\n\t */\n\tstatic std::int32_t print_signature(const vision_signature_s_t sig);\n\n\t/**\n\t * Enables/disables auto white-balancing on the Vision Sensor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\param enabled\n\t * \t\t    Pass 0 to disable, 1 to enable\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t *\n\t * void initialize() {\n\t * \t pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_sensor.set_auto_white_balance(true);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_auto_white_balance(const std::uint8_t enable) const;\n\n\t/**\n\t * Sets the exposure parameter of the Vision Sensor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\param percent\n\t *        The new exposure setting from [0,150].\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t *\n\t * void initialize() {\n\t * \t pros::Vision vision_sensor(VISION_PORT);\n\t *   if (vision_sensor.get_exposure() < 50)\n\t *   vision_sensor.set_exposure(50);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_exposure(const std::uint8_t exposure) const;\n\n\t/**\n\t * Sets the vision sensor LED color, overriding the automatic behavior.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\param rgb\n\t *        An RGB code to set the LED to\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t *\n\t * void initialize() {\n\t *\t pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_sensor.set_led(COLOR_BLANCHED_ALMOND);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_led(const std::int32_t rgb) const;\n\n\t/**\n\t * Stores the supplied object detection signature onto the vision sensor.\n\t *\n\t * NOTE: This saves the signature in volatile memory, and the signature will be\n\t * lost as soon as the sensor is powered down.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t * EINVAL - sig_id is outside the range [1-8]\n\t *\n\t * \\param signature_id\n\t *        The signature id to store into\n\t * \\param[in] signature_ptr\n\t *            A pointer to the signature to save\n\t *\n\t * \\return 1 if no errors occured, PROS_ERR otherwise\n\t *\n\t *  \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define EXAMPLE_SIG 1\n\t *\n\t * void opcontrol() {\n\t *   pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_signature_s_t sig = vision_sensor.get_signature(EXAMPLE_SIG);\n\t *   sig.range = 10.0;\n\t *   vision_sensor.set_signature(EXAMPLE_SIG, &sig);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_signature(const std::uint8_t signature_id, vision_signature_s_t* const signature_ptr) const;\n\n\t/**\n\t * Sets the white balance parameter of the Vision Sensor.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\param rgb\n\t *        The new RGB white balance setting of the sensor\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t * #define VISION_WHITE 0xff\n\t *\n\t * void initialize() {\n\t *   pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_sensor.set_white_balance(VISION_WHITE);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_white_balance(const std::int32_t rgb) const;\n\n\t/**\n\t * Sets the (0,0) coordinate for the Field of View.\n\t *\n\t * This will affect the coordinates returned for each request for a\n\t * vision_object_s_t from the sensor, so it is recommended that this function\n\t * only be used to configure the sensor at the beginning of its use.\n\t *\n\t * This function uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\param zero_point\n\t *        One of vision_zero_e_t to set the (0,0) coordinate for the FOV\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t * \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t *\n\t * void initialize() {\n\t * \t pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_sensor.set_zero_point(E_VISION_ZERO_CENTER);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_zero_point(vision_zero_e_t zero_point) const;\n\n\t/**\n\t * Sets the Wi-Fi mode of the Vision sensor\n\t *\n\t * This functions uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - The port cannot be configured as a vision sensor\n\t *\n\t * \\param enable\n\t *        Disable Wi-Fi on the Vision sensor if 0, enable otherwise (e.g. 1)\n\t *\n\t * \\return 1 if the operation was successful or PROS_ERR if the operation\n\t * failed, setting errno.\n\t *\n\t *  \\b Example\n\t * \\code\n\t * #define VISION_PORT 1\n\t *\n\t * void initialize() {\n\t * \t pros::Vision vision_sensor(VISION_PORT);\n\t *   vision_sensor.set_wifi_mode(0);\n\t * }\n\t * \\endcode\n\t */\n\tstd::int32_t set_wifi_mode(const std::uint8_t enable) const;\n\n\t/**\n\t * Gets a vision sensor that is plugged in to the brain\n\t *\n\t * \\note The first time this function is called it returns the vision sensor at the lowest port\n\t * If this function is called multiple times, it will cycle through all the ports.\n\t * For example, if you have 1 vision sensor on the robot\n\t * this function will always return a vision sensor object for that port.\n\t * If you have 2 vision sensors, all the odd numered calls to this function will return objects\n\t * for the lower port number,\n\t * all the even number calls will return vision objects for the higher port number\n\t *\n\t *\n\t * This functions uses the following values of errno when an error state is\n\t * reached:\n\t * ENODEV - No vision sensor is plugged into the brain\n\t *\n\t * \\return A vision object corresponding to a port that a vision sensor is connected to the brain\n\t * If no vision sensor is plugged in, it returns a vision sensor on port PROS_ERR_BYTE\n\t *\n\t */\n\tstatic Vision get_vision();\n\n\tprivate:\n\t///@}\n};\n}  // namespace v5\nnamespace literals {\n/**\n * Constructs a Vision sensor from a litteral ending in _vis\n *\n * \\return a pros::Vision for the corresponding port\n *\n * \\b Example\n * \\code\n * using namespace pros::literals;\n * void opcontrol() {\n *\tpros::Vision vision = 2_vis; //Makes an Vision sensor object on port 2\n * }\n * \\endcode\n */\nconst pros::Vision operator\"\"_vis(const unsigned long long int m);\n}  // namespace literals\n}  // namespace pros\n#endif  // _PROS_VISION_HPP_\n"
  },
  {
    "path": "include/rtos/FreeRTOS.h",
    "content": "/*\r\n * FreeRTOS Kernel V10.0.1\r\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\r\n * this software and associated documentation files (the \"Software\"), to deal in\r\n * the Software without restriction, including without limitation the rights to\r\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r\n * the Software, and to permit persons to whom the Software is furnished to do so,\r\n * subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n *\r\n * http://www.FreeRTOS.org\r\n * http://aws.amazon.com/freertos\r\n *\r\n * 1 tab == 4 spaces!\r\n */\r\n\r\n#ifndef INC_FREERTOS_H\r\n#define INC_FREERTOS_H\r\n\r\n/*\r\n * Include the generic headers required for the FreeRTOS port being used.\r\n */\r\n#include <stddef.h>\r\n#include <stdint.h>\r\n#include <stdbool.h>\r\n#include <errno.h>\r\n\r\n/*\r\n * If stdint.h cannot be located then:\r\n *   + If using GCC ensure the -nostdint options is *not* being used.\r\n *   + Ensure the project's include path includes the directory in which your\r\n *     compiler stores stdint.h.\r\n *   + Set any compiler options necessary for it to support C99, as technically\r\n *     stdint.h is only mandatory with C99 (FreeRTOS does not require C99 in any\r\n *     other way).\r\n *   + The FreeRTOS download includes a simple stdint.h definition that can be\r\n *     used in cases where none is provided by the compiler.  The files only\r\n *     contains the typedefs required to build FreeRTOS.  Read the instructions\r\n *     in FreeRTOS/source/stdint.readme for more information.\r\n */\r\n#include <stdint.h> /* READ COMMENT ABOVE. */\r\n\r\n#ifdef __cplusplus\r\nextern \"C\" {\r\n#endif\r\n\r\n/* Application specific configuration options. */\r\n#include \"FreeRTOSConfig.h\"\r\n\r\n/* Basic FreeRTOS definitions. */\r\n#include \"projdefs.h\"\r\n\r\n/* Definitions specific to the port being used. */\r\n#include \"portable.h\"\r\n\r\n/* Must be defaulted before configUSE_NEWLIB_REENTRANT is used below. */\r\n#ifndef configUSE_NEWLIB_REENTRANT\r\n\t#define configUSE_NEWLIB_REENTRANT 0\r\n#endif\r\n\r\n/* Required if struct _reent is used. */\r\n#if ( configUSE_NEWLIB_REENTRANT == 1 )\r\n\t#include <reent.h>\r\n#endif\r\n/*\r\n * Check all the required application specific macros have been defined.\r\n * These macros are application specific and (as downloaded) are defined\r\n * within FreeRTOSConfig.h.\r\n */\r\n\r\n#ifndef configMINIMAL_STACK_SIZE\r\n\t#error Missing definition:  configMINIMAL_STACK_SIZE must be defined in FreeRTOSConfig.h.  configMINIMAL_STACK_SIZE defines the size (in words) of the stack allocated to the idle task.  Refer to the demo project provided for your port for a suitable value.\r\n#endif\r\n\r\n#ifndef configMAX_PRIORITIES\r\n\t#error Missing definition:  configMAX_PRIORITIES must be defined in FreeRTOSConfig.h.  See the Configuration section of the FreeRTOS API documentation for details.\r\n#endif\r\n\r\n#if configMAX_PRIORITIES < 1\r\n\t#error configMAX_PRIORITIES must be defined to be greater than or equal to 1.\r\n#endif\r\n\r\n#ifndef configUSE_PREEMPTION\r\n\t#error Missing definition:  configUSE_PREEMPTION must be defined in FreeRTOSConfig.h as either 1 or 0.  See the Configuration section of the FreeRTOS API documentation for details.\r\n#endif\r\n\r\n#ifndef configUSE_IDLE_HOOK\r\n\t#error Missing definition:  configUSE_IDLE_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0.  See the Configuration section of the FreeRTOS API documentation for details.\r\n#endif\r\n\r\n#ifndef configUSE_TICK_HOOK\r\n\t#error Missing definition:  configUSE_TICK_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0.  See the Configuration section of the FreeRTOS API documentation for details.\r\n#endif\r\n\r\n#ifndef configUSE_16_BIT_TICKS\r\n\t#error Missing definition:  configUSE_16_BIT_TICKS must be defined in FreeRTOSConfig.h as either 1 or 0.  See the Configuration section of the FreeRTOS API documentation for details.\r\n#endif\r\n\r\n#ifndef configUSE_CO_ROUTINES\r\n\t#define configUSE_CO_ROUTINES 0\r\n#endif\r\n\r\n#ifndef INCLUDE_vTaskPrioritySet\r\n\t#define INCLUDE_vTaskPrioritySet 0\r\n#endif\r\n\r\n#ifndef INCLUDE_uxTaskPriorityGet\r\n\t#define INCLUDE_uxTaskPriorityGet 0\r\n#endif\r\n\r\n#ifndef INCLUDE_vTaskDelete\r\n\t#define INCLUDE_vTaskDelete 0\r\n#endif\r\n\r\n#ifndef INCLUDE_vTaskSuspend\r\n\t#define INCLUDE_vTaskSuspend 0\r\n#endif\r\n\r\n#ifndef INCLUDE_vTaskDelayUntil\r\n\t#define INCLUDE_vTaskDelayUntil 0\r\n#endif\r\n\r\n#ifndef INCLUDE_vTaskDelay\r\n\t#define INCLUDE_vTaskDelay 0\r\n#endif\r\n\r\n#ifndef INCLUDE_xTaskGetIdleTaskHandle\r\n\t#define INCLUDE_xTaskGetIdleTaskHandle 0\r\n#endif\r\n\r\n#ifndef INCLUDE_xTaskAbortDelay\r\n\t#define INCLUDE_xTaskAbortDelay 0\r\n#endif\r\n\r\n#ifndef INCLUDE_xQueueGetMutexHolder\r\n\t#define INCLUDE_xQueueGetMutexHolder 0\r\n#endif\r\n\r\n#ifndef INCLUDE_xSemaphoreGetMutexHolder\r\n\t#define INCLUDE_xSemaphoreGetMutexHolder INCLUDE_xQueueGetMutexHolder\r\n#endif\r\n\r\n#ifndef INCLUDE_xTaskGetHandle\r\n\t#define INCLUDE_xTaskGetHandle 0\r\n#endif\r\n\r\n#ifndef INCLUDE_uxTaskGetStackHighWaterMark\r\n\t#define INCLUDE_uxTaskGetStackHighWaterMark 0\r\n#endif\r\n\r\n#ifndef INCLUDE_eTaskGetState\r\n\t#define INCLUDE_eTaskGetState 0\r\n#endif\r\n\r\n#ifndef INCLUDE_xTaskResumeFromISR\r\n\t#define INCLUDE_xTaskResumeFromISR 1\r\n#endif\r\n\r\n#ifndef INCLUDE_xTimerPendFunctionCall\r\n\t#define INCLUDE_xTimerPendFunctionCall 0\r\n#endif\r\n\r\n#ifndef INCLUDE_xTaskGetSchedulerState\r\n\t#define INCLUDE_xTaskGetSchedulerState 0\r\n#endif\r\n\r\n#ifndef INCLUDE_xTaskGetCurrentTaskHandle\r\n\t#define INCLUDE_xTaskGetCurrentTaskHandle 0\r\n#endif\r\n\r\n#if configUSE_CO_ROUTINES != 0\r\n\t#ifndef configMAX_CO_ROUTINE_PRIORITIES\r\n\t\t#error configMAX_CO_ROUTINE_PRIORITIES must be greater than or equal to 1.\r\n\t#endif\r\n#endif\r\n\r\n#ifndef configUSE_DAEMON_TASK_STARTUP_HOOK\r\n\t#define configUSE_DAEMON_TASK_STARTUP_HOOK 0\r\n#endif\r\n\r\n#ifndef configUSE_APPLICATION_TASK_TAG\r\n\t#define configUSE_APPLICATION_TASK_TAG 0\r\n#endif\r\n\r\n#ifndef configNUM_THREAD_LOCAL_STORAGE_POINTERS\r\n\t#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 0\r\n#endif\r\n\r\n#ifndef configUSE_RECURSIVE_MUTEXES\r\n\t#define configUSE_RECURSIVE_MUTEXES 0\r\n#endif\r\n\r\n#ifndef configUSE_MUTEXES\r\n\t#define configUSE_MUTEXES 0\r\n#endif\r\n\r\n#ifndef configUSE_TIMERS\r\n\t#define configUSE_TIMERS 0\r\n#endif\r\n\r\n#ifndef configUSE_COUNTING_SEMAPHORES\r\n\t#define configUSE_COUNTING_SEMAPHORES 0\r\n#endif\r\n\r\n#ifndef configUSE_ALTERNATIVE_API\r\n\t#define configUSE_ALTERNATIVE_API 0\r\n#endif\r\n\r\n#ifndef portCRITICAL_NESTING_IN_TCB\r\n\t#define portCRITICAL_NESTING_IN_TCB 0\r\n#endif\r\n\r\n#ifndef configMAX_TASK_NAME_LEN\r\n\t#define configMAX_TASK_NAME_LEN 16\r\n#endif\r\n\r\n#ifndef configIDLE_SHOULD_YIELD\r\n\t#define configIDLE_SHOULD_YIELD\t\t1\r\n#endif\r\n\r\n#if configMAX_TASK_NAME_LEN < 1\r\n\t#error configMAX_TASK_NAME_LEN must be set to a minimum of 1 in FreeRTOSConfig.h\r\n#endif\r\n\r\n#ifndef configASSERT\r\n\t#define configASSERT( x )\r\n\t#define configASSERT_DEFINED 0\r\n#else\r\n\t#define configASSERT_DEFINED 1\r\n#endif\r\n\r\n/* The timers module relies on xTaskGetSchedulerState(). */\r\n#if configUSE_TIMERS == 1\r\n\r\n\t#ifndef configTIMER_TASK_PRIORITY\r\n\t\t#error If configUSE_TIMERS is set to 1 then configTIMER_TASK_PRIORITY must also be defined.\r\n\t#endif /* configTIMER_TASK_PRIORITY */\r\n\r\n\t#ifndef configTIMER_QUEUE_LENGTH\r\n\t\t#error If configUSE_TIMERS is set to 1 then configTIMER_QUEUE_LENGTH must also be defined.\r\n\t#endif /* configTIMER_QUEUE_LENGTH */\r\n\r\n\t#ifndef configTIMER_TASK_STACK_DEPTH\r\n\t\t#error If configUSE_TIMERS is set to 1 then configTIMER_TASK_STACK_DEPTH must also be defined.\r\n\t#endif /* configTIMER_TASK_STACK_DEPTH */\r\n\r\n#endif /* configUSE_TIMERS */\r\n\r\n#ifndef portSET_INTERRUPT_MASK_FROM_ISR\r\n\t#define portSET_INTERRUPT_MASK_FROM_ISR() 0\r\n#endif\r\n\r\n#ifndef portCLEAR_INTERRUPT_MASK_FROM_ISR\r\n\t#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue\r\n#endif\r\n\r\n#ifndef portCLEAN_UP_TCB\r\n\t#define portCLEAN_UP_TCB( pxTCB ) ( void ) pxTCB\r\n#endif\r\n\r\n#ifndef portPRE_TASK_DELETE_HOOK\r\n\t#define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxYieldPending )\r\n#endif\r\n\r\n#ifndef portSETUP_TCB\r\n\t#define portSETUP_TCB( pxTCB ) ( void ) pxTCB\r\n#endif\r\n\r\n#ifndef configQUEUE_REGISTRY_SIZE\r\n\t#define configQUEUE_REGISTRY_SIZE 0U\r\n#endif\r\n\r\n#if ( configQUEUE_REGISTRY_SIZE < 1 )\r\n\t#define vQueueAddToRegistry( xQueue, pcName )\r\n\t#define vQueueUnregisterQueue( xQueue )\r\n\t#define pcQueueGetName( xQueue )\r\n#endif\r\n\r\n#ifndef portPOINTER_SIZE_TYPE\r\n\t#define portPOINTER_SIZE_TYPE uint32_t\r\n#endif\r\n\r\n/* Remove any unused trace macros. */\r\n#ifndef traceSTART\r\n\t/* Used to perform any necessary initialisation - for example, open a file\r\n\tinto which trace is to be written. */\r\n\t#define traceSTART()\r\n#endif\r\n\r\n#ifndef traceEND\r\n\t/* Use to close a trace, for example close a file into which trace has been\r\n\twritten. */\r\n\t#define traceEND()\r\n#endif\r\n\r\n#ifndef traceTASK_SWITCHED_IN\r\n\t/* Called after a task has been selected to run.  pxCurrentTCB holds a pointer\r\n\tto the task control block of the selected task. */\r\n\t#define traceTASK_SWITCHED_IN()\r\n#endif\r\n\r\n#ifndef traceINCREASE_TICK_COUNT\r\n\t/* Called before stepping the tick count after waking from tickless idle\r\n\tsleep. */\r\n\t#define traceINCREASE_TICK_COUNT( x )\r\n#endif\r\n\r\n#ifndef traceLOW_POWER_IDLE_BEGIN\r\n\t/* Called immediately before entering tickless idle. */\r\n\t#define traceLOW_POWER_IDLE_BEGIN()\r\n#endif\r\n\r\n#ifndef\ttraceLOW_POWER_IDLE_END\r\n\t/* Called when returning to the Idle task after a tickless idle. */\r\n\t#define traceLOW_POWER_IDLE_END()\r\n#endif\r\n\r\n#ifndef traceTASK_SWITCHED_OUT\r\n\t/* Called before a task has been selected to run.  pxCurrentTCB holds a pointer\r\n\tto the task control block of the task being switched out. */\r\n\t#define traceTASK_SWITCHED_OUT()\r\n#endif\r\n\r\n#ifndef traceTASK_PRIORITY_INHERIT\r\n\t/* Called when a task attempts to take a mutex that is already held by a\r\n\tlower priority task.  pxTCBOfMutexHolder is a pointer to the TCB of the task\r\n\tthat holds the mutex.  uxInheritedPriority is the priority the mutex holder\r\n\twill inherit (the priority of the task that is attempting to obtain the\r\n\tmuted. */\r\n\t#define traceTASK_PRIORITY_INHERIT( pxTCBOfMutexHolder, uxInheritedPriority )\r\n#endif\r\n\r\n#ifndef traceTASK_PRIORITY_DISINHERIT\r\n\t/* Called when a task releases a mutex, the holding of which had resulted in\r\n\tthe task inheriting the priority of a higher priority task.\r\n\tpxTCBOfMutexHolder is a pointer to the TCB of the task that is releasing the\r\n\tmutex.  uxOriginalPriority is the task's configured (base) priority. */\r\n\t#define traceTASK_PRIORITY_DISINHERIT( pxTCBOfMutexHolder, uxOriginalPriority )\r\n#endif\r\n\r\n#ifndef traceBLOCKING_ON_QUEUE_RECEIVE\r\n\t/* Task is about to block because it cannot read from a\r\n\tqueue/mutex/semaphore.  pxQueue is a pointer to the queue/mutex/semaphore\r\n\tupon which the read was attempted.  pxCurrentTCB points to the TCB of the\r\n\ttask that attempted the read. */\r\n\t#define traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue )\r\n#endif\r\n\r\n#ifndef traceBLOCKING_ON_QUEUE_PEEK\r\n\t/* Task is about to block because it cannot read from a\r\n\tqueue/mutex/semaphore.  pxQueue is a pointer to the queue/mutex/semaphore\r\n\tupon which the read was attempted.  pxCurrentTCB points to the TCB of the\r\n\ttask that attempted the read. */\r\n\t#define traceBLOCKING_ON_QUEUE_PEEK( pxQueue )\r\n#endif\r\n\r\n#ifndef traceBLOCKING_ON_QUEUE_SEND\r\n\t/* Task is about to block because it cannot write to a\r\n\tqueue/mutex/semaphore.  pxQueue is a pointer to the queue/mutex/semaphore\r\n\tupon which the write was attempted.  pxCurrentTCB points to the TCB of the\r\n\ttask that attempted the write. */\r\n\t#define traceBLOCKING_ON_QUEUE_SEND( pxQueue )\r\n#endif\r\n\r\n#ifndef configCHECK_FOR_STACK_OVERFLOW\r\n\t#define configCHECK_FOR_STACK_OVERFLOW 0\r\n#endif\r\n\r\n#ifndef configRECORD_STACK_HIGH_ADDRESS\r\n\t#define configRECORD_STACK_HIGH_ADDRESS 0\r\n#endif\r\n\r\n#ifndef configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H\r\n\t#define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 0\r\n#endif\r\n\r\n/* The following event macros are embedded in the kernel API calls. */\r\n\r\n#ifndef traceMOVED_TASK_TO_READY_STATE\r\n\t#define traceMOVED_TASK_TO_READY_STATE( pxTCB )\r\n#endif\r\n\r\n#ifndef tracePOST_MOVED_TASK_TO_READY_STATE\r\n\t#define tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB )\r\n#endif\r\n\r\n#ifndef traceQUEUE_CREATE\r\n\t#define traceQUEUE_CREATE( pxNewQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_CREATE_FAILED\r\n\t#define traceQUEUE_CREATE_FAILED( ucQueueType )\r\n#endif\r\n\r\n#ifndef traceCREATE_MUTEX\r\n\t#define traceCREATE_MUTEX( pxNewQueue )\r\n#endif\r\n\r\n#ifndef traceCREATE_MUTEX_FAILED\r\n\t#define traceCREATE_MUTEX_FAILED()\r\n#endif\r\n\r\n#ifndef traceGIVE_MUTEX_RECURSIVE\r\n\t#define traceGIVE_MUTEX_RECURSIVE( pxMutex )\r\n#endif\r\n\r\n#ifndef traceGIVE_MUTEX_RECURSIVE_FAILED\r\n\t#define traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex )\r\n#endif\r\n\r\n#ifndef traceTAKE_MUTEX_RECURSIVE\r\n\t#define traceTAKE_MUTEX_RECURSIVE( pxMutex )\r\n#endif\r\n\r\n#ifndef traceTAKE_MUTEX_RECURSIVE_FAILED\r\n\t#define traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex )\r\n#endif\r\n\r\n#ifndef traceCREATE_COUNTING_SEMAPHORE\r\n\t#define traceCREATE_COUNTING_SEMAPHORE()\r\n#endif\r\n\r\n#ifndef traceCREATE_COUNTING_SEMAPHORE_FAILED\r\n\t#define traceCREATE_COUNTING_SEMAPHORE_FAILED()\r\n#endif\r\n\r\n#ifndef traceQUEUE_SEND\r\n\t#define traceQUEUE_SEND( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_SEND_FAILED\r\n\t#define traceQUEUE_SEND_FAILED( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_RECEIVE\r\n\t#define traceQUEUE_RECEIVE( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_PEEK\r\n\t#define traceQUEUE_PEEK( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_PEEK_FAILED\r\n\t#define traceQUEUE_PEEK_FAILED( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_PEEK_FROM_ISR\r\n\t#define traceQUEUE_PEEK_FROM_ISR( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_RECEIVE_FAILED\r\n\t#define traceQUEUE_RECEIVE_FAILED( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_SEND_FROM_ISR\r\n\t#define traceQUEUE_SEND_FROM_ISR( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_SEND_FROM_ISR_FAILED\r\n\t#define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_RECEIVE_FROM_ISR\r\n\t#define traceQUEUE_RECEIVE_FROM_ISR( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_RECEIVE_FROM_ISR_FAILED\r\n\t#define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_PEEK_FROM_ISR_FAILED\r\n\t#define traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue )\r\n#endif\r\n\r\n#ifndef traceQUEUE_DELETE\r\n\t#define traceQUEUE_DELETE( pxQueue )\r\n#endif\r\n\r\n#ifndef traceTASK_CREATE\r\n\t#define traceTASK_CREATE( pxNewTCB )\r\n#endif\r\n\r\n#ifndef traceTASK_CREATE_FAILED\r\n\t#define traceTASK_CREATE_FAILED()\r\n#endif\r\n\r\n#ifndef traceTASK_DELETE\r\n\t#define traceTASK_DELETE( pxTaskToDelete )\r\n#endif\r\n\r\n#ifndef traceTASK_DELAY_UNTIL\r\n\t#define traceTASK_DELAY_UNTIL( x )\r\n#endif\r\n\r\n#ifndef traceTASK_DELAY\r\n\t#define traceTASK_DELAY()\r\n#endif\r\n\r\n#ifndef traceTASK_PRIORITY_SET\r\n\t#define traceTASK_PRIORITY_SET( pxTask, uxNewPriority )\r\n#endif\r\n\r\n#ifndef traceTASK_SUSPEND\r\n\t#define traceTASK_SUSPEND( pxTaskToSuspend )\r\n#endif\r\n\r\n#ifndef traceTASK_RESUME\r\n\t#define traceTASK_RESUME( pxTaskToResume )\r\n#endif\r\n\r\n#ifndef traceTASK_RESUME_FROM_ISR\r\n\t#define traceTASK_RESUME_FROM_ISR( pxTaskToResume )\r\n#endif\r\n\r\n#ifndef traceTASK_INCREMENT_TICK\r\n\t#define traceTASK_INCREMENT_TICK( xTickCount )\r\n#endif\r\n\r\n#ifndef traceTIMER_CREATE\r\n\t#define traceTIMER_CREATE( pxNewTimer )\r\n#endif\r\n\r\n#ifndef traceTIMER_CREATE_FAILED\r\n\t#define traceTIMER_CREATE_FAILED()\r\n#endif\r\n\r\n#ifndef traceTIMER_COMMAND_SEND\r\n\t#define traceTIMER_COMMAND_SEND( xTimer, xMessageID, xMessageValueValue, xReturn )\r\n#endif\r\n\r\n#ifndef traceTIMER_EXPIRED\r\n\t#define traceTIMER_EXPIRED( pxTimer )\r\n#endif\r\n\r\n#ifndef traceTIMER_COMMAND_RECEIVED\r\n\t#define traceTIMER_COMMAND_RECEIVED( pxTimer, xMessageID, xMessageValue )\r\n#endif\r\n\r\n#ifndef traceMALLOC\r\n    #define traceMALLOC( pvAddress, uiSize )\r\n#endif\r\n\r\n#ifndef traceFREE\r\n    #define traceFREE( pvAddress, uiSize )\r\n#endif\r\n\r\n#ifndef traceEVENT_GROUP_CREATE\r\n\t#define traceEVENT_GROUP_CREATE( xEventGroup )\r\n#endif\r\n\r\n#ifndef traceEVENT_GROUP_CREATE_FAILED\r\n\t#define traceEVENT_GROUP_CREATE_FAILED()\r\n#endif\r\n\r\n#ifndef traceEVENT_GROUP_SYNC_BLOCK\r\n\t#define traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor )\r\n#endif\r\n\r\n#ifndef traceEVENT_GROUP_SYNC_END\r\n\t#define traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred ) ( void ) xTimeoutOccurred\r\n#endif\r\n\r\n#ifndef traceEVENT_GROUP_WAIT_BITS_BLOCK\r\n\t#define traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor )\r\n#endif\r\n\r\n#ifndef traceEVENT_GROUP_WAIT_BITS_END\r\n\t#define traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred ) ( void ) xTimeoutOccurred\r\n#endif\r\n\r\n#ifndef traceEVENT_GROUP_CLEAR_BITS\r\n\t#define traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear )\r\n#endif\r\n\r\n#ifndef traceEVENT_GROUP_CLEAR_BITS_FROM_ISR\r\n\t#define traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear )\r\n#endif\r\n\r\n#ifndef traceEVENT_GROUP_SET_BITS\r\n\t#define traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet )\r\n#endif\r\n\r\n#ifndef traceEVENT_GROUP_SET_BITS_FROM_ISR\r\n\t#define traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet )\r\n#endif\r\n\r\n#ifndef traceEVENT_GROUP_DELETE\r\n\t#define traceEVENT_GROUP_DELETE( xEventGroup )\r\n#endif\r\n\r\n#ifndef tracePEND_FUNC_CALL\r\n\t#define tracePEND_FUNC_CALL(xFunctionToPend, pvParameter1, ulParameter2, ret)\r\n#endif\r\n\r\n#ifndef tracePEND_FUNC_CALL_FROM_ISR\r\n\t#define tracePEND_FUNC_CALL_FROM_ISR(xFunctionToPend, pvParameter1, ulParameter2, ret)\r\n#endif\r\n\r\n#ifndef traceQUEUE_REGISTRY_ADD\r\n\t#define traceQUEUE_REGISTRY_ADD(xQueue, pcQueueName)\r\n#endif\r\n\r\n#ifndef traceTASK_NOTIFY_TAKE_BLOCK\r\n\t#define traceTASK_NOTIFY_TAKE_BLOCK()\r\n#endif\r\n\r\n#ifndef traceTASK_NOTIFY_TAKE\r\n\t#define traceTASK_NOTIFY_TAKE()\r\n#endif\r\n\r\n#ifndef traceTASK_NOTIFY_WAIT_BLOCK\r\n\t#define traceTASK_NOTIFY_WAIT_BLOCK()\r\n#endif\r\n\r\n#ifndef traceTASK_NOTIFY_WAIT\r\n\t#define traceTASK_NOTIFY_WAIT()\r\n#endif\r\n\r\n#ifndef traceTASK_NOTIFY\r\n\t#define traceTASK_NOTIFY()\r\n#endif\r\n\r\n#ifndef traceTASK_NOTIFY_FROM_ISR\r\n\t#define traceTASK_NOTIFY_FROM_ISR()\r\n#endif\r\n\r\n#ifndef traceTASK_NOTIFY_GIVE_FROM_ISR\r\n\t#define traceTASK_NOTIFY_GIVE_FROM_ISR()\r\n#endif\r\n\r\n#ifndef traceSTREAM_BUFFER_CREATE_FAILED\r\n\t#define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer )\r\n#endif\r\n\r\n#ifndef traceSTREAM_BUFFER_CREATE_STATIC_FAILED\r\n\t#define traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer )\r\n#endif\r\n\r\n#ifndef traceSTREAM_BUFFER_CREATE\r\n\t#define traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer )\r\n#endif\r\n\r\n#ifndef traceSTREAM_BUFFER_DELETE\r\n\t#define traceSTREAM_BUFFER_DELETE( xStreamBuffer )\r\n#endif\r\n\r\n#ifndef traceSTREAM_BUFFER_RESET\r\n\t#define traceSTREAM_BUFFER_RESET( xStreamBuffer )\r\n#endif\r\n\r\n#ifndef traceBLOCKING_ON_STREAM_BUFFER_SEND\r\n\t#define traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer )\r\n#endif\r\n\r\n#ifndef traceSTREAM_BUFFER_SEND\r\n\t#define traceSTREAM_BUFFER_SEND( xStreamBuffer, xBytesSent )\r\n#endif\r\n\r\n#ifndef traceSTREAM_BUFFER_SEND_FAILED\r\n\t#define traceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer )\r\n#endif\r\n\r\n#ifndef traceSTREAM_BUFFER_SEND_FROM_ISR\r\n\t#define traceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xBytesSent )\r\n#endif\r\n\r\n#ifndef traceBLOCKING_ON_STREAM_BUFFER_RECEIVE\r\n\t#define traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer )\r\n#endif\r\n\r\n#ifndef traceSTREAM_BUFFER_RECEIVE\r\n\t#define traceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength )\r\n#endif\r\n\r\n#ifndef traceSTREAM_BUFFER_RECEIVE_FAILED\r\n\t#define traceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer )\r\n#endif\r\n\r\n#ifndef traceSTREAM_BUFFER_RECEIVE_FROM_ISR\r\n\t#define traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength )\r\n#endif\r\n\r\n#ifndef configGENERATE_RUN_TIME_STATS\r\n\t#define configGENERATE_RUN_TIME_STATS 0\r\n#endif\r\n\r\n#if ( configGENERATE_RUN_TIME_STATS == 1 )\r\n\r\n\t#ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS\r\n\t\t#error If configGENERATE_RUN_TIME_STATS is defined then portCONFIGURE_TIMER_FOR_RUN_TIME_STATS must also be defined.  portCONFIGURE_TIMER_FOR_RUN_TIME_STATS should call a port layer function to setup a peripheral timer/counter that can then be used as the run time counter time base.\r\n\t#endif /* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS */\r\n\r\n\t#ifndef portGET_RUN_TIME_COUNTER_VALUE\r\n\t\t#ifndef portALT_GET_RUN_TIME_COUNTER_VALUE\r\n\t\t\t#error If configGENERATE_RUN_TIME_STATS is defined then either portGET_RUN_TIME_COUNTER_VALUE or portALT_GET_RUN_TIME_COUNTER_VALUE must also be defined.  See the examples provided and the FreeRTOS web site for more information.\r\n\t\t#endif /* portALT_GET_RUN_TIME_COUNTER_VALUE */\r\n\t#endif /* portGET_RUN_TIME_COUNTER_VALUE */\r\n\r\n#endif /* configGENERATE_RUN_TIME_STATS */\r\n\r\n#ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS\r\n\t#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()\r\n#endif\r\n\r\n#ifndef configUSE_MALLOC_FAILED_HOOK\r\n\t#define configUSE_MALLOC_FAILED_HOOK 0\r\n#endif\r\n\r\n#ifndef portPRIVILEGE_BIT\r\n\t#define portPRIVILEGE_BIT ( ( uint32_t ) 0x00 )\r\n#endif\r\n\r\n#ifndef portYIELD_WITHIN_API\r\n\t#define portYIELD_WITHIN_API portYIELD\r\n#endif\r\n\r\n#ifndef portSUPPRESS_TICKS_AND_SLEEP\r\n\t#define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime )\r\n#endif\r\n\r\n#ifndef configEXPECTED_IDLE_TIME_BEFORE_SLEEP\r\n\t#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2\r\n#endif\r\n\r\n#if configEXPECTED_IDLE_TIME_BEFORE_SLEEP < 2\r\n\t#error configEXPECTED_IDLE_TIME_BEFORE_SLEEP must not be less than 2\r\n#endif\r\n\r\n#ifndef configUSE_TICKLESS_IDLE\r\n\t#define configUSE_TICKLESS_IDLE 0\r\n#endif\r\n\r\n#ifndef configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING\r\n\t#define configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING( x )\r\n#endif\r\n\r\n#ifndef configPRE_SLEEP_PROCESSING\r\n\t#define configPRE_SLEEP_PROCESSING( x )\r\n#endif\r\n\r\n#ifndef configPOST_SLEEP_PROCESSING\r\n\t#define configPOST_SLEEP_PROCESSING( x )\r\n#endif\r\n\r\n#ifndef configUSE_QUEUE_SETS\r\n\t#define configUSE_QUEUE_SETS 0\r\n#endif\r\n\r\n#ifndef portTASK_USES_FLOATING_POINT\r\n\t#define portTASK_USES_FLOATING_POINT()\r\n#endif\r\n\r\n#ifndef portTASK_CALLS_SECURE_FUNCTIONS\r\n\t#define portTASK_CALLS_SECURE_FUNCTIONS()\r\n#endif\r\n\r\n#ifndef configUSE_TIME_SLICING\r\n\t#define configUSE_TIME_SLICING 1\r\n#endif\r\n\r\n#ifndef configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS\r\n\t#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0\r\n#endif\r\n\r\n#ifndef configUSE_STATS_FORMATTING_FUNCTIONS\r\n\t#define configUSE_STATS_FORMATTING_FUNCTIONS 0\r\n#endif\r\n\r\n#ifndef portASSERT_IF_INTERRUPT_PRIORITY_INVALID\r\n\t#define portASSERT_IF_INTERRUPT_PRIORITY_INVALID()\r\n#endif\r\n\r\n#ifndef configUSE_TRACE_FACILITY\r\n\t#define configUSE_TRACE_FACILITY 0\r\n#endif\r\n\r\n#ifndef mtCOVERAGE_TEST_MARKER\r\n\t#define mtCOVERAGE_TEST_MARKER()\r\n#endif\r\n\r\n#ifndef mtCOVERAGE_TEST_DELAY\r\n\t#define mtCOVERAGE_TEST_DELAY()\r\n#endif\r\n\r\n#ifndef portASSERT_IF_IN_ISR\r\n\t#define portASSERT_IF_IN_ISR()\r\n#endif\r\n\r\n#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION\r\n\t#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0\r\n#endif\r\n\r\n#ifndef configAPPLICATION_ALLOCATED_HEAP\r\n\t#define configAPPLICATION_ALLOCATED_HEAP 0\r\n#endif\r\n\r\n#ifndef configUSE_TASK_NOTIFICATIONS\r\n\t#define configUSE_TASK_NOTIFICATIONS 1\r\n#endif\r\n\r\n#ifndef portTICK_TYPE_IS_ATOMIC\r\n\t#define portTICK_TYPE_IS_ATOMIC 0\r\n#endif\r\n\r\n#ifndef configSUPPORT_STATIC_ALLOCATION\r\n\t/* Defaults to 0 for backward compatibility. */\r\n\t#define configSUPPORT_STATIC_ALLOCATION 0\r\n#endif\r\n\r\n#ifndef configSUPPORT_DYNAMIC_ALLOCATION\r\n\t/* Defaults to 1 for backward compatibility. */\r\n\t#define configSUPPORT_DYNAMIC_ALLOCATION 1\r\n#endif\r\n\r\n#ifndef configSTACK_DEPTH_TYPE\r\n\t/* Defaults to uint16_t for backward compatibility, but can be overridden\r\n\tin FreeRTOSConfig.h if uint16_t is too restrictive. */\r\n\t#define configSTACK_DEPTH_TYPE uint16_t\r\n#endif\r\n\r\n/* Sanity check the configuration. */\r\n#if( configUSE_TICKLESS_IDLE != 0 )\r\n\t#if( INCLUDE_vTaskSuspend != 1 )\r\n\t\t#error INCLUDE_vTaskSuspend must be set to 1 if configUSE_TICKLESS_IDLE is not set to 0\r\n\t#endif /* INCLUDE_vTaskSuspend */\r\n#endif /* configUSE_TICKLESS_IDLE */\r\n\r\n#if( ( configSUPPORT_STATIC_ALLOCATION == 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) )\r\n\t#error configSUPPORT_STATIC_ALLOCATION and configSUPPORT_DYNAMIC_ALLOCATION cannot both be 0, but can both be 1.\r\n#endif\r\n\r\n#if( ( configUSE_RECURSIVE_MUTEXES == 1 ) && ( configUSE_MUTEXES != 1 ) )\r\n\t#error configUSE_MUTEXES must be set to 1 to use recursive mutexes\r\n#endif\r\n\r\n#ifndef configINITIAL_TICK_COUNT\r\n\t#define configINITIAL_TICK_COUNT 0\r\n#endif\r\n\r\n#if( portTICK_TYPE_IS_ATOMIC == 0 )\r\n\t/* Either variables of tick type cannot be read atomically, or\r\n\tportTICK_TYPE_IS_ATOMIC was not set - map the critical sections used when\r\n\tthe tick count is returned to the standard critical section macros. */\r\n\t#define portTICK_TYPE_ENTER_CRITICAL() portENTER_CRITICAL()\r\n\t#define portTICK_TYPE_EXIT_CRITICAL() portEXIT_CRITICAL()\r\n\t#define portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()\r\n\t#define portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( ( x ) )\r\n#else\r\n\t/* The tick type can be read atomically, so critical sections used when the\r\n\ttick count is returned can be defined away. */\r\n\t#define portTICK_TYPE_ENTER_CRITICAL()\r\n\t#define portTICK_TYPE_EXIT_CRITICAL()\r\n\t#define portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR() 0\r\n\t#define portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( x ) ( void ) x\r\n#endif\r\n\r\n/* Definitions to allow backward compatibility with FreeRTOS versions prior to\r\nV8 if desired. */\r\n#ifndef configENABLE_BACKWARD_COMPATIBILITY\r\n\t#define configENABLE_BACKWARD_COMPATIBILITY 1\r\n#endif\r\n\r\n#ifndef configPRINTF\r\n\t/* configPRINTF() was not defined, so define it away to nothing.  To use\r\n\tconfigPRINTF() then define it as follows (where MyPrintFunction() is\r\n\tprovided by the application writer):\r\n\r\n\tvoid MyPrintFunction(const char *pcFormat, ... );\r\n\t#define configPRINTF( X )   MyPrintFunction X\r\n\r\n\tThen call like a standard printf() function, but placing brackets around\r\n\tall parameters so they are passed as a single parameter.  For example:\r\n\tconfigPRINTF( (\"Value = %d\", MyVariable) ); */\r\n\t#define configPRINTF( X )\r\n#endif\r\n\r\n#ifndef configMAX\r\n\t/* The application writer has not provided their own MAX macro, so define\r\n\tthe following generic implementation. */\r\n\t#define configMAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )\r\n#endif\r\n\r\n#ifndef configMIN\r\n\t/* The application writer has not provided their own MAX macro, so define\r\n\tthe following generic implementation. */\r\n\t#define configMIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )\r\n#endif\r\n\r\n#if configENABLE_BACKWARD_COMPATIBILITY == 1\r\n\t#define eTaskStateGet task_get_state\r\n\t#define portTickType uint32_t\r\n\t#define xTaskHandle task_t\r\n\t#define xQueueHandle queue_t\r\n\t#define xSemaphoreHandle sem_t\r\n\t#define xQueueSetHandle QueueSetHandle_t\r\n\t#define xQueueSetMemberHandle QueueSetMemberHandle_t\r\n\t#define xTimeOutType TimeOut_t\r\n\t#define xMemoryRegion MemoryRegion_t\r\n\t#define xTaskParameters TaskParameters_t\r\n\t#define xTaskStatusType\tTaskStatus_t\r\n\t#define xTimerHandle TimerHandle_t\r\n\t#define xCoRoutineHandle CoRoutineHandle_t\r\n\t#define pdTASK_HOOK_CODE TaskHookFunction_t\r\n\t#define portTICK_RATE_MS portTICK_PERIOD_MS\r\n\t#define pcTaskGetTaskName task_get_name\r\n\t#define pcTimerGetTimerName pcTimerGetName\r\n\t#define pcQueueGetQueueName pcQueueGetName\r\n\t#define vTaskGetTaskInfo vTaskGetInfo\r\n\r\n\t/* Backward compatibility within the scheduler code only - these definitions\r\n\tare not really required but are included for completeness. */\r\n\t#define tmrTIMER_CALLBACK TimerCallbackFunction_t\r\n\t#define pdTASK_CODE task_fn_t\r\n\t#define xListItem list_item_t\r\n\t#define xList List_t\r\n#endif /* configENABLE_BACKWARD_COMPATIBILITY */\r\n\r\n#if( configUSE_ALTERNATIVE_API != 0 )\r\n\t#error The alternative API was deprecated some time ago, and was removed in FreeRTOS V9.0 0\r\n#endif\r\n\r\n/* Set configUSE_TASK_FPU_SUPPORT to 0 to omit floating point support even\r\nif floating point hardware is otherwise supported by the FreeRTOS port in use.\r\nThis constant is not supported by all FreeRTOS ports that include floating\r\npoint support. */\r\n#ifndef configUSE_TASK_FPU_SUPPORT\r\n\t#define configUSE_TASK_FPU_SUPPORT 1\r\n#endif\r\n\r\n/*\r\n * In line with software engineering best practice, FreeRTOS implements a strict\r\n * data hiding policy, so the real structures used by FreeRTOS to maintain the\r\n * state of tasks, queues, semaphores, etc. are not accessible to the application\r\n * code.  However, if the application writer wants to statically allocate such\r\n * an object then the size of the object needs to be know.  Dummy structures\r\n * that are guaranteed to have the same size and alignment requirements of the\r\n * real objects are used for this purpose.  The dummy list and list item\r\n * structures below are used for inclusion in such a dummy structure.\r\n */\r\nstruct xSTATIC_LIST_ITEM\r\n{\r\n\tuint32_t xDummy1;\r\n\tvoid *pvDummy2[ 4 ];\r\n};\r\ntypedef struct xSTATIC_LIST_ITEM StaticListItem_t;\r\n\r\n/* See the comments above the struct xSTATIC_LIST_ITEM definition. */\r\nstruct xSTATIC_MINI_LIST_ITEM\r\n{\r\n\tuint32_t xDummy1;\r\n\tvoid *pvDummy2[ 2 ];\r\n};\r\ntypedef struct xSTATIC_MINI_LIST_ITEM StaticMiniListItem_t;\r\n\r\n/* See the comments above the struct xSTATIC_LIST_ITEM definition. */\r\ntypedef struct xSTATIC_LIST\r\n{\r\n\tuint32_t uxDummy1;\r\n\tvoid *pvDummy2;\r\n\tStaticMiniListItem_t xDummy3;\r\n} StaticList_t;\r\n\r\n/*\r\n * In line with software engineering best practice, especially when supplying a\r\n * library that is likely to change in future versions, FreeRTOS implements a\r\n * strict data hiding policy.  This means the Task structure used internally by\r\n * FreeRTOS is not accessible to application code.  However, if the application\r\n * writer wants to statically allocate the memory required to create a task then\r\n * the size of the task object needs to be know.  The static_task_s_t structure\r\n * below is provided for this purpose.  Its sizes and alignment requirements are\r\n * guaranteed to match those of the genuine structure, no matter which\r\n * architecture is being used, and no matter how the values in FreeRTOSConfig.h\r\n * are set.  Its contents are somewhat obfuscated in the hope users will\r\n * recognise that it would be unwise to make direct use of the structure members.\r\n */\r\ntypedef struct xSTATIC_TCB\r\n{\r\n\tvoid\t\t\t\t*pxDummy1;\r\n\t#if ( portUSING_MPU_WRAPPERS == 1 )\r\n\t\txMPU_SETTINGS\txDummy2;\r\n\t#endif\r\n\tStaticListItem_t\txDummy3[ 2 ];\r\n\tuint32_t\t\t\tuxDummy5;\r\n\tvoid\t\t\t\t*pxDummy6;\r\n\tuint8_t\t\t\t\tucDummy7[ configMAX_TASK_NAME_LEN ];\r\n\t#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )\r\n\t\tvoid\t\t\t*pxDummy8;\r\n\t#endif\r\n\t#if ( portCRITICAL_NESTING_IN_TCB == 1 )\r\n\t\tuint32_t\t\tuxDummy9;\r\n\t#endif\r\n\t#if ( configUSE_TRACE_FACILITY == 1 )\r\n\t\tuint32_t\t\tuxDummy10[ 2 ];\r\n\t#endif\r\n\t#if ( configUSE_MUTEXES == 1 )\r\n\t\tuint32_t\t\tuxDummy12[ 2 ];\r\n\t#endif\r\n\t#if ( configUSE_APPLICATION_TASK_TAG == 1 )\r\n\t\tvoid\t\t\t*pxDummy14;\r\n\t#endif\r\n\t#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )\r\n\t\tvoid\t\t\t*pvDummy15[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];\r\n\t#endif\r\n\t#if ( configGENERATE_RUN_TIME_STATS == 1 )\r\n\t\tuint32_t\t\tulDummy16;\r\n\t#endif\r\n\t#if ( configUSE_NEWLIB_REENTRANT == 1 )\r\n\t\tstruct\t_reent\txDummy17;\r\n\t#endif\r\n\t#if ( configUSE_TASK_NOTIFICATIONS == 1 )\r\n\t\tuint32_t \t\tulDummy18;\r\n\t\tuint8_t \t\tucDummy19;\r\n\t#endif\r\n\t#if( ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) || ( portUSING_MPU_WRAPPERS == 1 ) )\r\n\t\tuint8_t\t\t\tuxDummy20;\r\n\t#endif\r\n\r\n\t#if( INCLUDE_xTaskAbortDelay == 1 )\r\n\t\tuint8_t ucDummy21;\r\n\t#endif\r\n\r\n} static_task_s_t;\r\n\r\n/*\r\n * In line with software engineering best practice, especially when supplying a\r\n * library that is likely to change in future versions, FreeRTOS implements a\r\n * strict data hiding policy.  This means the Queue structure used internally by\r\n * FreeRTOS is not accessible to application code.  However, if the application\r\n * writer wants to statically allocate the memory required to create a queue\r\n * then the size of the queue object needs to be know.  The static_queue_s_t\r\n * structure below is provided for this purpose.  Its sizes and alignment\r\n * requirements are guaranteed to match those of the genuine structure, no\r\n * matter which architecture is being used, and no matter how the values in\r\n * FreeRTOSConfig.h are set.  Its contents are somewhat obfuscated in the hope\r\n * users will recognise that it would be unwise to make direct use of the\r\n * structure members.\r\n */\r\ntypedef struct xSTATIC_QUEUE\r\n{\r\n\tvoid *pvDummy1[ 3 ];\r\n\r\n\tunion\r\n\t{\r\n\t\tvoid *pvDummy2;\r\n\t\tuint32_t uxDummy2;\r\n\t} u;\r\n\r\n\tStaticList_t xDummy3[ 2 ];\r\n\tuint32_t uxDummy4[ 3 ];\r\n\tuint8_t ucDummy5[ 2 ];\r\n\r\n\t#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r\n\t\tuint8_t ucDummy6;\r\n\t#endif\r\n\r\n\t#if ( configUSE_QUEUE_SETS == 1 )\r\n\t\tvoid *pvDummy7;\r\n\t#endif\r\n\r\n\t#if ( configUSE_TRACE_FACILITY == 1 )\r\n\t\tuint32_t uxDummy8;\r\n\t\tuint8_t ucDummy9;\r\n\t#endif\r\n\r\n} static_queue_s_t;\r\ntypedef static_queue_s_t static_sem_s_t;\r\n\r\n/*\r\n * In line with software engineering best practice, especially when supplying a\r\n * library that is likely to change in future versions, FreeRTOS implements a\r\n * strict data hiding policy.  This means the event group structure used\r\n * internally by FreeRTOS is not accessible to application code.  However, if\r\n * the application writer wants to statically allocate the memory required to\r\n * create an event group then the size of the event group object needs to be\r\n * know.  The StaticEventGroup_t structure below is provided for this purpose.\r\n * Its sizes and alignment requirements are guaranteed to match those of the\r\n * genuine structure, no matter which architecture is being used, and no matter\r\n * how the values in FreeRTOSConfig.h are set.  Its contents are somewhat\r\n * obfuscated in the hope users will recognise that it would be unwise to make\r\n * direct use of the structure members.\r\n */\r\ntypedef struct xSTATIC_EVENT_GROUP\r\n{\r\n\tuint32_t xDummy1;\r\n\tStaticList_t xDummy2;\r\n\r\n\t#if( configUSE_TRACE_FACILITY == 1 )\r\n\t\tuint32_t uxDummy3;\r\n\t#endif\r\n\r\n\t#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r\n\t\t\tuint8_t ucDummy4;\r\n\t#endif\r\n\r\n} StaticEventGroup_t;\r\n\r\n/*\r\n * In line with software engineering best practice, especially when supplying a\r\n * library that is likely to change in future versions, FreeRTOS implements a\r\n * strict data hiding policy.  This means the software timer structure used\r\n * internally by FreeRTOS is not accessible to application code.  However, if\r\n * the application writer wants to statically allocate the memory required to\r\n * create a software timer then the size of the queue object needs to be know.\r\n * The StaticTimer_t structure below is provided for this purpose.  Its sizes\r\n * and alignment requirements are guaranteed to match those of the genuine\r\n * structure, no matter which architecture is being used, and no matter how the\r\n * values in FreeRTOSConfig.h are set.  Its contents are somewhat obfuscated in\r\n * the hope users will recognise that it would be unwise to make direct use of\r\n * the structure members.\r\n */\r\ntypedef struct xSTATIC_TIMER\r\n{\r\n\tvoid\t\t\t\t*pvDummy1;\r\n\tStaticListItem_t\txDummy2;\r\n\tuint32_t\t\t\txDummy3;\r\n\tuint32_t\t\t\tuxDummy4;\r\n\tvoid \t\t\t\t*pvDummy5[ 2 ];\r\n\t#if( configUSE_TRACE_FACILITY == 1 )\r\n\t\tuint32_t\t\tuxDummy6;\r\n\t#endif\r\n\r\n\t#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r\n\t\tuint8_t \t\tucDummy7;\r\n\t#endif\r\n\r\n} StaticTimer_t;\r\n\r\n/*\r\n* In line with software engineering best practice, especially when supplying a\r\n* library that is likely to change in future versions, FreeRTOS implements a\r\n* strict data hiding policy.  This means the stream buffer structure used\r\n* internally by FreeRTOS is not accessible to application code.  However, if\r\n* the application writer wants to statically allocate the memory required to\r\n* create a stream buffer then the size of the stream buffer object needs to be\r\n* know.  The static_stream_buf_s_t structure below is provided for this purpose.\r\n* Its size and alignment requirements are guaranteed to match those of the\r\n* genuine structure, no matter which architecture is being used, and no matter\r\n* how the values in FreeRTOSConfig.h are set.  Its contents are somewhat\r\n* obfuscated in the hope users will recognise that it would be unwise to make\r\n* direct use of the structure members.\r\n*/\r\ntypedef struct xSTATIC_STREAM_BUFFER\r\n{\r\n\tsize_t uxDummy1[ 4 ];\r\n\tvoid * pvDummy2[ 3 ];\r\n\tuint8_t ucDummy3;\r\n\t#if ( configUSE_TRACE_FACILITY == 1 )\r\n\t\tuint32_t uxDummy4;\r\n\t#endif\r\n} static_stream_buf_s_t;\r\n\r\n/* Message buffers are built on stream buffers. */\r\ntypedef static_stream_buf_s_t static_msg_buf_s_t;\r\n\r\n#ifdef __cplusplus\r\n}\r\n#endif\r\n\r\n#endif /* INC_FREERTOS_H */\r\n\r\n"
  },
  {
    "path": "include/rtos/FreeRTOSConfig.h",
    "content": "/*\n    FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.\n    All rights reserved\n\n    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\n\n    This file is part of the FreeRTOS distribution.\n\n    FreeRTOS is free software; you can redistribute it and/or modify it under\n    the terms of the GNU General Public License (version 2) as published by the\n    Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\n\n    ***************************************************************************\n    >>!   NOTE: The modification to the GPL is included to allow you to     !<<\n    >>!   distribute a combined work that includes FreeRTOS without being   !<<\n    >>!   obliged to provide the source code for proprietary components     !<<\n    >>!   outside of the FreeRTOS kernel.                                   !<<\n    ***************************************************************************\n\n    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\n    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n    FOR A PARTICULAR PURPOSE.  Full license text is available on the following\n    link: http://www.freertos.org/a00114.html\n\n    ***************************************************************************\n     *                                                                       *\n     *    FreeRTOS provides completely free yet professionally developed,    *\n     *    robust, strictly quality controlled, supported, and cross          *\n     *    platform software that is more than just the market leader, it     *\n     *    is the industry's de facto standard.                               *\n     *                                                                       *\n     *    Help yourself get started quickly while simultaneously helping     *\n     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\n     *    tutorial book, reference manual, or both:                          *\n     *    http://www.FreeRTOS.org/Documentation                              *\n     *                                                                       *\n    ***************************************************************************\n\n    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\n    the FAQ page \"My application does not run, what could be wrong?\".  Have you\n    defined configASSERT()?\n\n    http://www.FreeRTOS.org/support - In return for receiving this top quality\n    embedded software for free we request you assist our global community by\n    participating in the support forum.\n\n    http://www.FreeRTOS.org/training - Investing in training allows your team to\n    be as productive as possible as early as possible.  Now you can receive\n    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\n    Ltd, and the world's leading authority on the world's leading RTOS.\n\n    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\n    including FreeRTOS+Trace - an indispensable productivity tool, a DOS\n    compatible FAT file system, and our tiny thread aware UDP/IP stack.\n\n    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\n    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\n\n    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\n    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\n    licenses offer ticketed support, indemnification and commercial middleware.\n\n    http://www.SafeRTOS.com - High Integrity Systems also provide a safety\n    engineered and independently SIL3 certified version for use in safety and\n    mission critical applications that require provable dependability.\n\n    1 tab == 4 spaces!\n*/\n\n#ifndef FREERTOS_CONFIG_H\n#define FREERTOS_CONFIG_H\n\n//#include \"xparameters.h\"\n// fix memset warnings\n#include \"string.h\"\n\n/*-----------------------------------------------------------\n * Application specific definitions.\n *\n * These definitions should be adjusted for your particular hardware and\n * application requirements.\n *\n * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE\n * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.\n *\n * See http://www.freertos.org/a00110.html.\n *----------------------------------------------------------*/\n\n/*\n * The FreeRTOS Cortex-A port implements a full interrupt nesting model.\n *\n * Interrupts that are assigned a priority at or below\n * configMAX_API_CALL_INTERRUPT_PRIORITY (which counter-intuitively in the ARM\n * generic interrupt controller [GIC] means a priority that has a numerical\n * value above configMAX_API_CALL_INTERRUPT_PRIORITY) can call FreeRTOS safe API\n * functions and will nest.\n *\n * Interrupts that are assigned a priority above\n * configMAX_API_CALL_INTERRUPT_PRIORITY (which in the GIC means a numerical\n * value below configMAX_API_CALL_INTERRUPT_PRIORITY) cannot call any FreeRTOS\n * API functions, will nest, and will not be masked by FreeRTOS critical\n * sections (although it is necessary for interrupts to be globally disabled\n * extremely briefly as the interrupt mask is updated in the GIC).\n *\n * FreeRTOS functions that can be called from an interrupt are those that end in\n * \"FromISR\".  FreeRTOS maintains a separate interrupt safe API to enable\n * interrupt entry to be shorter, faster, simpler and smaller.\n *\n * The Zynq implements 256 unique interrupt priorities.  For the purpose of\n * setting configMAX_API_CALL_INTERRUPT_PRIORITY 255 represents the lowest\n * priority.\n */\n#define configMAX_API_CALL_INTERRUPT_PRIORITY   18\n\n#define configCPU_CLOCK_HZ                      100000000UL\n#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1\n#define configUSE_TICKLESS_IDLE                 0\n#define configTICK_RATE_HZ                      ( ( uint32_t ) 1000 )\n#define configPERIPHERAL_CLOCK_HZ               ( 33333000UL )\n#define configUSE_PREEMPTION                    1\n#define configUSE_IDLE_HOOK                     1\n#define configUSE_TICK_HOOK                     0\n#define configMAX_PRIORITIES                    ( 16 )\n#define configMINIMAL_STACK_SIZE                ( ( unsigned short ) 250 )\n// allocate 1 MB for FreeRTOS heap\n#define configTOTAL_HEAP_SIZE                   ( 0x100000 )\n#define configMAX_TASK_NAME_LEN                 ( 32 )\n#define configUSE_TRACE_FACILITY                1\n#define INCLUDE_uxTaskGetStackHighWaterMark     1\n#define configUSE_16_BIT_TICKS                  0\n#define configIDLE_SHOULD_YIELD                 1\n#define configUSE_MUTEXES                       1\n#define configQUEUE_REGISTRY_SIZE               8\n#define configCHECK_FOR_STACK_OVERFLOW          2\n#define configUSE_RECURSIVE_MUTEXES             1\n#define configUSE_MALLOC_FAILED_HOOK            1\n#define configUSE_APPLICATION_TASK_TAG          0\n#define configUSE_COUNTING_SEMAPHORES           1\n#define configUSE_QUEUE_SETS                    0\n#define configSUPPORT_STATIC_ALLOCATION         1\n#define configUSE_NEWLIB_REENTRANT              1\n#define configSTACK_DEPTH_TYPE                  size_t\n\n#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 2\n\n/* Include the query-heap CLI command to query the free heap space. */\n#define configINCLUDE_QUERY_HEAP_COMMAND        1\n\n/* Software timer definitions. */\n#define configUSE_TIMERS                        1\n#define configTIMER_TASK_PRIORITY               ( configMAX_PRIORITIES - 1 )\n#define configTIMER_QUEUE_LENGTH                5\n#define configTIMER_TASK_STACK_DEPTH            ( configMINIMAL_STACK_SIZE * 2 )\n\n/* If configUSE_TASK_FPU_SUPPORT is set to 1 (or undefined) then each task will\nbe created without an FPU context, and a task must call vTaskUsesFPU() before\nmaking use of any FPU registers.  If configUSE_TASK_FPU_SUPPORT is set to 2 then\ntasks are created with an FPU context by default, and calling vTaskUsesFPU() has\nno effect. */\n#define configUSE_TASK_FPU_SUPPORT              2\n\n/* Set the following definitions to 1 to include the API function, or zero\nto exclude the API function. */\n#define INCLUDE_vTaskPrioritySet                1\n#define INCLUDE_uxTaskPriorityGet               1\n#define INCLUDE_vTaskDelete                     1\n#define INCLUDE_vTaskCleanUpResources           1\n#define INCLUDE_vTaskSuspend                    1\n#define INCLUDE_vTaskDelayUntil                 1\n#define INCLUDE_vTaskDelay                      1\n#define INCLUDE_xTimerPendFunctionCall          1\n#define INCLUDE_eTaskGetState                   1\n#define INCLUDE_xTaskAbortDelay                 1\n#define INCLUDE_xTaskGetTaskHandle              1\n#define INCLUDE_xTaskGetHandle                  1\n#define INCLUDE_xTaskGetSchedulerState          1\n#define INCLUDE_xQueueGetMutexHolder            1\n\n/* This demo makes use of one or more example stats formatting functions.  These\nformat the raw data provided by the uxTaskGetSystemState() function in to human\nreadable ASCII form.  See the notes in the implementation of vTaskList() within\nFreeRTOS/Source/tasks.c for limitations. */\n#define configUSE_STATS_FORMATTING_FUNCTIONS    1\n\n/* The private watchdog is used to generate run time stats. */\nextern void vInitialiseTimerForRunTimeStats( void );\nextern uint32_t vexSystemWatchdogGet( void );\n#define configGENERATE_RUN_TIME_STATS 1\n#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vInitialiseTimerForRunTimeStats()\n#define portGET_RUN_TIME_COUNTER_VALUE()         vexSystemWatchdogGet()\n\n/* The size of the global output buffer that is available for use when there\nare multiple command interpreters running at once (for example, one on a UART\nand one on TCP/IP).  This is done to prevent an output buffer being defined by\neach implementation - which would waste RAM.  In this case, there is only one\ncommand interpreter running. */\n#define configCOMMAND_INT_MAX_OUTPUT_SIZE 2096\n\n/* Normal assert() semantics without relying on the provision of an assert.h\nheader file. */\nvoid vAssertCalled( const char * pcFile, unsigned long ulLine );\n#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ );\n\n/* If configTASK_RETURN_ADDRESS is not defined then a task that attempts to\nreturn from its implementing function will end up in a \"task exit error\"\nfunction - which contains a call to configASSERT().  However this can give GCC\nsome problems when it tries to unwind the stack, as the exit error function has\nnothing to return to.  To avoid this define configTASK_RETURN_ADDRESS to 0.  */\n#define configTASK_RETURN_ADDRESS   NULL\n\n\n/****** Hardware specific settings. *******************************************/\n\n/*\n * The application must provide a function that configures a peripheral to\n * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()\n * in FreeRTOSConfig.h to call the function.  This file contains a function\n * that is suitable for use on the Zynq MPU.  FreeRTOS_Tick_Handler() must\n * be installed as the peripheral's interrupt handler.\n */\nvoid rtos_tick_interrupt_config( void );\n#define configSETUP_TICK_INTERRUPT() rtos_tick_interrupt_config()\n\nvoid rtos_tick_interrupt_clear( void );\n#define configCLEAR_TICK_INTERRUPT() rtos_tick_interrupt_clear()\n\n/* The following constant describe the hardware, and are correct for the\nZynq MPU. */\n//#define configINTERRUPT_CONTROLLER_BASE_ADDRESS         ( XPAR_PS7_SCUGIC_0_DIST_BASEADDR )\n#define configINTERRUPT_CONTROLLER_BASE_ADDRESS         ( 0xF8F01000 )\n#define configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ( -0xf00 )\n#define configUNIQUE_INTERRUPT_PRIORITIES               32\n\n#endif /* FREERTOS_CONFIG_H */\n"
  },
  {
    "path": "include/rtos/StackMacros.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n#ifndef STACK_MACROS_H\n#define STACK_MACROS_H\n\n#ifndef _MSC_VER /* Visual Studio doesn't support #warning. */\n\t#warning The name of this file has changed to stack_macros.h.  Please update your code accordingly.  This source file (which has the original name) will be removed in future released.\n#endif\n\n/*\n * Call the stack overflow hook function if the stack of the task being swapped\n * out is currently overflowed, or looks like it might have overflowed in the\n * past.\n *\n * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check\n * the current stack state only - comparing the current top of stack value to\n * the stack limit.  Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1\n * will also cause the last few stack bytes to be checked to ensure the value\n * to which the bytes were set when the task was created have not been\n * overwritten.  Note this second test does not guarantee that an overflowed\n * stack will always be recognised.\n */\n\n/*-----------------------------------------------------------*/\n\n#if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) )\n\n\t/* Only the current stack state is to be checked. */\n\t#define taskCHECK_FOR_STACK_OVERFLOW()\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t/* Is the currently saved stack pointer within the stack limit? */\t\t\t\t\t\t\t\t\\\n\t\tif( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack )\t\t\t\t\t\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tvApplicationStackOverflowHook( ( task_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t}\n\n#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\n/*-----------------------------------------------------------*/\n\n#if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) )\n\n\t/* Only the current stack state is to be checked. */\n\t#define taskCHECK_FOR_STACK_OVERFLOW()\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t/* Is the currently saved stack pointer within the stack limit? */\t\t\t\t\t\t\t\t\\\n\t\tif( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack )\t\t\t\t\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tvApplicationStackOverflowHook( ( task_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t}\n\n#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\n/*-----------------------------------------------------------*/\n\n#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )\n\n\t#define taskCHECK_FOR_STACK_OVERFLOW()\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tconst uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack;\t\t\t\t\t\t\t\\\n\t\tconst uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5;\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tif( ( pulStack[ 0 ] != ulCheckValue ) ||\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t( pulStack[ 1 ] != ulCheckValue ) ||\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t( pulStack[ 2 ] != ulCheckValue ) ||\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t( pulStack[ 3 ] != ulCheckValue ) )\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tvApplicationStackOverflowHook( ( task_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t}\n\n#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\n/*-----------------------------------------------------------*/\n\n#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )\n\n\t#define taskCHECK_FOR_STACK_OVERFLOW()\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tint8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tstatic const uint8_t ucExpectedStackBytes[] = {\ttskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\ttskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\ttskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\ttskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\ttskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE };\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tpcEndOfStack -= sizeof( ucExpectedStackBytes );\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t/* Has the extremity of the task stack ever been written over? */\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tif( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tvApplicationStackOverflowHook( ( task_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );\t\t\t\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t}\n\n#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\n/*-----------------------------------------------------------*/\n\n/* Remove stack overflow macro if not being used. */\n#ifndef taskCHECK_FOR_STACK_OVERFLOW\n\t#define taskCHECK_FOR_STACK_OVERFLOW()\n#endif\n\n\n\n#endif /* STACK_MACROS_H */\n\n"
  },
  {
    "path": "include/rtos/list.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n/*\n * This is the list implementation used by the scheduler.  While it is tailored\n * heavily for the schedulers needs, it is also available for use by\n * application code.\n *\n * list_ts can only store pointers to list_item_ts.  Each list_item_t contains a\n * numeric value (xItemValue).  Most of the time the lists are sorted in\n * descending item value order.\n *\n * Lists are created already containing one list item.  The value of this\n * item is the maximum possible that can be stored, it is therefore always at\n * the end of the list and acts as a marker.  The list member pxHead always\n * points to this marker - even though it is at the tail of the list.  This\n * is because the tail contains a wrap back pointer to the true head of\n * the list.\n *\n * In addition to it's value, each list item contains a pointer to the next\n * item in the list (pxNext), a pointer to the list it is in (pxContainer)\n * and a pointer to back to the object that contains it.  These later two\n * pointers are included for efficiency of list manipulation.  There is\n * effectively a two way link between the object containing the list item and\n * the list item itself.\n *\n *\n * \\page ListIntroduction List Implementation\n * \\ingroup FreeRTOSIntro\n */\n\n#ifndef INC_FREERTOS_H\n\t#error FreeRTOS.h must be included before list.h\n#endif\n\n#ifndef LIST_H\n#define LIST_H\n\n/*\n * The list structure members are modified from within interrupts, and therefore\n * by rights should be declared volatile.  However, they are only modified in a\n * functionally atomic way (within critical sections of with the scheduler\n * suspended) and are either passed by reference into a function or indexed via\n * a volatile variable.  Therefore, in all use cases tested so far, the volatile\n * qualifier can be omitted in order to provide a moderate performance\n * improvement without adversely affecting functional behaviour.  The assembly\n * instructions generated by the IAR, ARM and GCC compilers when the respective\n * compiler's options were set for maximum optimisation has been inspected and\n * deemed to be as intended.  That said, as compiler technology advances, and\n * especially if aggressive cross module optimisation is used (a use case that\n * has not been exercised to any great extend) then it is feasible that the\n * volatile qualifier will be needed for correct optimisation.  It is expected\n * that a compiler removing essential code because, without the volatile\n * qualifier on the list structure members and with aggressive cross module\n * optimisation, the compiler deemed the code unnecessary will result in\n * complete and obvious failure of the scheduler.  If this is ever experienced\n * then the volatile qualifier can be inserted in the relevant places within the\n * list structures by simply defining configLIST_VOLATILE to volatile in\n * FreeRTOSConfig.h (as per the example at the bottom of this comment block).\n * If configLIST_VOLATILE is not defined then the preprocessor directives below\n * will simply #define configLIST_VOLATILE away completely.\n *\n * To use volatile list structure members then add the following line to\n * FreeRTOSConfig.h (without the quotes):\n * \"#define configLIST_VOLATILE volatile\"\n */\n#ifndef configLIST_VOLATILE\n\t#define configLIST_VOLATILE\n#endif /* configSUPPORT_CROSS_MODULE_OPTIMISATION */\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/* Macros that can be used to place known values within the list structures,\nthen check that the known values do not get corrupted during the execution of\nthe application.   These may catch the list data structures being overwritten in\nmemory.  They will not catch data errors caused by incorrect configuration or\nuse of FreeRTOS.*/\n#if( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 0 )\n\t/* Define the macros to do nothing. */\n\t#define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE\n\t#define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE\n\t#define listFIRST_LIST_INTEGRITY_CHECK_VALUE\n\t#define listSECOND_LIST_INTEGRITY_CHECK_VALUE\n\t#define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )\n\t#define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )\n\t#define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList )\n\t#define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList )\n\t#define listTEST_LIST_ITEM_INTEGRITY( pxItem )\n\t#define listTEST_LIST_INTEGRITY( pxList )\n#else\n\t/* Define macros that add new members into the list structures. */\n\t#define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE\t\t\t\tuint32_t xListItemIntegrityValue1;\n\t#define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE\t\t\t\tuint32_t xListItemIntegrityValue2;\n\t#define listFIRST_LIST_INTEGRITY_CHECK_VALUE\t\t\t\t\tuint32_t xListIntegrityValue1;\n\t#define listSECOND_LIST_INTEGRITY_CHECK_VALUE\t\t\t\t\tuint32_t xListIntegrityValue2;\n\n\t/* Define macros that set the new structure members to known values. */\n\t#define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )\t\t( pxItem )->xListItemIntegrityValue1 = pdINTEGRITY_CHECK_VALUE\n\t#define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )\t( pxItem )->xListItemIntegrityValue2 = pdINTEGRITY_CHECK_VALUE\n\t#define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList )\t\t( pxList )->xListIntegrityValue1 = pdINTEGRITY_CHECK_VALUE\n\t#define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList )\t\t( pxList )->xListIntegrityValue2 = pdINTEGRITY_CHECK_VALUE\n\n\t/* Define macros that will assert if one of the structure members does not\n\tcontain its expected value. */\n\t#define listTEST_LIST_ITEM_INTEGRITY( pxItem )\t\tconfigASSERT( ( ( pxItem )->xListItemIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxItem )->xListItemIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) )\n\t#define listTEST_LIST_INTEGRITY( pxList )\t\t\tconfigASSERT( ( ( pxList )->xListIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxList )->xListIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) )\n#endif /* configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES */\n\n\n/*\n * Definition of the only type of object that a list can contain.\n */\nstruct xLIST_ITEM\n{\n\tlistFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE\t\t\t/*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */\n\tconfigLIST_VOLATILE uint32_t xItemValue;\t\t\t/*< The value being listed.  In most cases this is used to sort the list in descending order. */\n\tstruct xLIST_ITEM * configLIST_VOLATILE pxNext;\t\t/*< Pointer to the next list_item_t in the list. */\n\tstruct xLIST_ITEM * configLIST_VOLATILE pxPrevious;\t/*< Pointer to the previous list_item_t in the list. */\n\tvoid * pvOwner;\t\t\t\t\t\t\t\t\t\t/*< Pointer to the object (normally a TCB) that contains the list item.  There is therefore a two way link between the object containing the list item and the list item itself. */\n\tvoid * configLIST_VOLATILE pvContainer;\t\t\t\t/*< Pointer to the list in which this list item is placed (if any). */\n\tlistSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE\t\t\t/*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */\n};\ntypedef struct xLIST_ITEM list_item_t;\t\t\t\t\t/* For some reason lint wants this as two separate definitions. */\n\nstruct xMINI_LIST_ITEM\n{\n\tlistFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE\t\t\t/*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */\n\tconfigLIST_VOLATILE uint32_t xItemValue;\n\tstruct xLIST_ITEM * configLIST_VOLATILE pxNext;\n\tstruct xLIST_ITEM * configLIST_VOLATILE pxPrevious;\n};\ntypedef struct xMINI_LIST_ITEM MiniListItem_t;\n\n/*\n * Definition of the type of queue used by the scheduler.\n */\ntypedef struct xLIST\n{\n\tlistFIRST_LIST_INTEGRITY_CHECK_VALUE\t\t\t\t/*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */\n\tvolatile uint32_t uxNumberOfItems;\n\tlist_item_t * configLIST_VOLATILE pxIndex;\t\t\t/*< Used to walk through the list.  Points to the last item returned by a call to listGET_OWNER_OF_NEXT_ENTRY (). */\n\tMiniListItem_t xListEnd;\t\t\t\t\t\t\t/*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */\n\tlistSECOND_LIST_INTEGRITY_CHECK_VALUE\t\t\t\t/*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */\n} List_t;\n\n/*\n * Access macro to set the owner of a list item.  The owner of a list item\n * is the object (usually a TCB) that contains the list item.\n *\n * \\page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER\n * \\ingroup LinkedList\n */\n#define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner )\t\t( ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) )\n\n/*\n * Access macro to get the owner of a list item.  The owner of a list item\n * is the object (usually a TCB) that contains the list item.\n *\n * \\page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER\n * \\ingroup LinkedList\n */\n#define listGET_LIST_ITEM_OWNER( pxListItem )\t( ( pxListItem )->pvOwner )\n\n/*\n * Access macro to set the value of the list item.  In most cases the value is\n * used to sort the list in descending order.\n *\n * \\page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE\n * \\ingroup LinkedList\n */\n#define listSET_LIST_ITEM_VALUE( pxListItem, xValue )\t( ( pxListItem )->xItemValue = ( xValue ) )\n\n/*\n * Access macro to retrieve the value of the list item.  The value can\n * represent anything - for example the priority of a task, or the time at\n * which a task should be unblocked.\n *\n * \\page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE\n * \\ingroup LinkedList\n */\n#define listGET_LIST_ITEM_VALUE( pxListItem )\t( ( pxListItem )->xItemValue )\n\n/*\n * Access macro to retrieve the value of the list item at the head of a given\n * list.\n *\n * \\page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE\n * \\ingroup LinkedList\n */\n#define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList )\t( ( ( pxList )->xListEnd ).pxNext->xItemValue )\n\n/*\n * Return the list item at the head of the list.\n *\n * \\page listGET_HEAD_ENTRY listGET_HEAD_ENTRY\n * \\ingroup LinkedList\n */\n#define listGET_HEAD_ENTRY( pxList )\t( ( ( pxList )->xListEnd ).pxNext )\n\n/*\n * Return the list item at the head of the list.\n *\n * \\page listGET_NEXT listGET_NEXT\n * \\ingroup LinkedList\n */\n#define listGET_NEXT( pxListItem )\t( ( pxListItem )->pxNext )\n\n/*\n * Return the list item that marks the end of the list\n *\n * \\page listGET_END_MARKER listGET_END_MARKER\n * \\ingroup LinkedList\n */\n#define listGET_END_MARKER( pxList )\t( ( list_item_t const * ) ( &( ( pxList )->xListEnd ) ) )\n\n/*\n * Access macro to determine if a list contains any items.  The macro will\n * only have the value true if the list is empty.\n *\n * \\page listLIST_IS_EMPTY listLIST_IS_EMPTY\n * \\ingroup LinkedList\n */\n#define listLIST_IS_EMPTY( pxList )\t( ( int32_t ) ( ( pxList )->uxNumberOfItems == ( uint32_t ) 0 ) )\n\n/*\n * Access macro to return the number of items in the list.\n */\n#define listCURRENT_LIST_LENGTH( pxList )\t( ( pxList )->uxNumberOfItems )\n\n/*\n * Access function to obtain the owner of the next entry in a list.\n *\n * The list member pxIndex is used to walk through a list.  Calling\n * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list\n * and returns that entry's pxOwner parameter.  Using multiple calls to this\n * function it is therefore possible to move through every item contained in\n * a list.\n *\n * The pxOwner parameter of a list item is a pointer to the object that owns\n * the list item.  In the scheduler this is normally a task control block.\n * The pxOwner parameter effectively creates a two way link between the list\n * item and its owner.\n *\n * @param pxTCB pxTCB is set to the address of the owner of the next list item.\n * @param pxList The list from which the next item owner is to be returned.\n *\n * \\page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY\n * \\ingroup LinkedList\n */\n#define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList )\t\t\t\t\t\t\t\t\t\t\\\n{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\nList_t * const pxConstList = ( pxList );\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t/* Increment the index to the next item and return the item, ensuring */\t\t\t\t\\\n\t/* we don't return the marker used at the end of the list.  */\t\t\t\t\t\t\t\\\n\t( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext;\t\t\t\t\t\t\t\\\n\tif( ( void * ) ( pxConstList )->pxIndex == ( void * ) &( ( pxConstList )->xListEnd ) )\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext;\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t( pxTCB ) = ( pxConstList )->pxIndex->pvOwner;\t\t\t\t\t\t\t\t\t\t\t\\\n}\n\n\n/*\n * Access function to obtain the owner of the first entry in a list.  Lists\n * are normally sorted in ascending item value order.\n *\n * This function returns the pxOwner member of the first item in the list.\n * The pxOwner parameter of a list item is a pointer to the object that owns\n * the list item.  In the scheduler this is normally a task control block.\n * The pxOwner parameter effectively creates a two way link between the list\n * item and its owner.\n *\n * @param pxList The list from which the owner of the head item is to be\n * returned.\n *\n * \\page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY\n * \\ingroup LinkedList\n */\n#define listGET_OWNER_OF_HEAD_ENTRY( pxList )  ( (&( ( pxList )->xListEnd ))->pxNext->pvOwner )\n\n/*\n * Check to see if a list item is within a list.  The list item maintains a\n * \"container\" pointer that points to the list it is in.  All this macro does\n * is check to see if the container and the list match.\n *\n * @param pxList The list we want to know if the list item is within.\n * @param pxListItem The list item we want to know if is in the list.\n * @return pdTRUE if the list item is in the list, otherwise pdFALSE.\n */\n#define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( int32_t ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) ) )\n\n/*\n * Return the list a list item is contained within (referenced from).\n *\n * @param pxListItem The list item being queried.\n * @return A pointer to the List_t object that references the pxListItem\n */\n#define listLIST_ITEM_CONTAINER( pxListItem ) ( ( pxListItem )->pvContainer )\n\n/*\n * This provides a crude means of knowing if a list has been initialised, as\n * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise()\n * function.\n */\n#define listLIST_IS_INITIALISED( pxList ) ( ( pxList )->xListEnd.xItemValue == portMAX_DELAY )\n\n/*\n * Must be called before a list is used!  This initialises all the members\n * of the list structure and inserts the xListEnd item into the list as a\n * marker to the back of the list.\n *\n * @param pxList Pointer to the list being initialised.\n *\n * \\page vListInitialise vListInitialise\n * \\ingroup LinkedList\n */\nvoid vListInitialise( List_t * const pxList ) ;\n\n/*\n * Must be called before a list item is used.  This sets the list container to\n * null so the item does not think that it is already contained in a list.\n *\n * @param pxItem Pointer to the list item being initialised.\n *\n * \\page vListInitialiseItem vListInitialiseItem\n * \\ingroup LinkedList\n */\nvoid vListInitialiseItem( list_item_t * const pxItem ) ;\n\n/*\n * Insert a list item into a list.  The item will be inserted into the list in\n * a position determined by its item value (descending item value order).\n *\n * @param pxList The list into which the item is to be inserted.\n *\n * @param pxNewListItem The item that is to be placed in the list.\n *\n * \\page vListInsert vListInsert\n * \\ingroup LinkedList\n */\nvoid vListInsert( List_t * const pxList, list_item_t * const pxNewListItem ) ;\n\n/*\n * Insert a list item into a list.  The item will be inserted in a position\n * such that it will be the last item within the list returned by multiple\n * calls to listGET_OWNER_OF_NEXT_ENTRY.\n *\n * The list member pxIndex is used to walk through a list.  Calling\n * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list.\n * Placing an item in a list using vListInsertEnd effectively places the item\n * in the list position pointed to by pxIndex.  This means that every other\n * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before\n * the pxIndex parameter again points to the item being inserted.\n *\n * @param pxList The list into which the item is to be inserted.\n *\n * @param pxNewListItem The list item to be inserted into the list.\n *\n * \\page vListInsertEnd vListInsertEnd\n * \\ingroup LinkedList\n */\nvoid vListInsertEnd( List_t * const pxList, list_item_t * const pxNewListItem ) ;\n\n/*\n * Remove an item from a list.  The list item has a pointer to the list that\n * it is in, so only the list item need be passed into the function.\n *\n * @param uxListRemove The item to be removed.  The item will remove itself from\n * the list pointed to by it's pxContainer parameter.\n *\n * @return The number of items that remain in the list after the list item has\n * been removed.\n *\n * \\page uxListRemove uxListRemove\n * \\ingroup LinkedList\n */\nuint32_t uxListRemove( list_item_t * const pxItemToRemove ) ;\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n\n"
  },
  {
    "path": "include/rtos/message_buffer.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n\n/*\n * Message buffers build functionality on top of FreeRTOS stream buffers.\n * Whereas stream buffers are used to send a continuous stream of data from one\n * task or interrupt to another, message buffers are used to send variable\n * length discrete messages from one task or interrupt to another.  Their\n * implementation is light weight, making them particularly suited for interrupt\n * to task and core to core communication scenarios.\n *\n * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer\n * implementation (so also the message buffer implementation, as message buffers\n * are built on top of stream buffers) assumes there is only one task or\n * interrupt that will write to the buffer (the writer), and only one task or\n * interrupt that will read from the buffer (the reader).  It is safe for the\n * writer and reader to be different tasks or interrupts, but, unlike other\n * FreeRTOS objects, it is not safe to have multiple different writers or\n * multiple different readers.  If there are to be multiple different writers\n * then the application writer must place each call to a writing API function\n * (such as msg_buf_send()) inside a critical section and set the send\n * block time to 0.  Likewise, if there are to be multiple different readers\n * then the application writer must place each call to a reading API function\n * (such as xMessageBufferRead()) inside a critical section and set the receive\n * timeout to 0.\n *\n * Message buffers hold variable length messages.  To enable that, when a\n * message is written to the message buffer an additional sizeof( size_t ) bytes\n * are also written to store the message's length (that happens internally, with\n * the API function).  sizeof( size_t ) is typically 4 bytes on a 32-bit\n * architecture, so writing a 10 byte message to a message buffer on a 32-bit\n * architecture will actually reduce the available space in the message buffer\n * by 14 bytes (10 byte are used by the message, and 4 bytes to hold the length\n * of the message).\n */\n\n#ifndef FREERTOS_MESSAGE_BUFFER_H\n#define FREERTOS_MESSAGE_BUFFER_H\n\n/* Message buffers are built onto of stream buffers. */\n#include \"stream_buffer.h\"\n\n#if defined( __cplusplus )\nextern \"C\" {\n#endif\n\n/**\n * Type by which message buffers are referenced.  For example, a call to\n * xMessageBufferCreate() returns an msg_buf_t variable that can\n * then be used as a parameter to msg_buf_send(), msg_buf_recv(),\n * etc.\n */\ntypedef void * msg_buf_t;\n\n/*-----------------------------------------------------------*/\n\n/**\n * message_buffer.h\n *\n<pre>\nmsg_buf_t xMessageBufferCreate( size_t xBufferSizeBytes );\n</pre>\n *\n * Creates a new message buffer using dynamically allocated memory.  See\n * xMessageBufferCreateStatic() for a version that uses statically allocated\n * memory (memory that is allocated at compile time).\n *\n * configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in\n * FreeRTOSConfig.h for xMessageBufferCreate() to be available.\n *\n * @param xBufferSizeBytes The total number of bytes (not messages) the message\n * buffer will be able to hold at any one time.  When a message is written to\n * the message buffer an additional sizeof( size_t ) bytes are also written to\n * store the message's length.  sizeof( size_t ) is typically 4 bytes on a\n * 32-bit architecture, so on most 32-bit architectures a 10 byte message will\n * take up 14 bytes of message buffer space.\n *\n * @return If NULL is returned, then the message buffer cannot be created\n * because there is insufficient heap memory available for FreeRTOS to allocate\n * the message buffer data structures and storage area.  A non-NULL value being\n * returned indicates that the message buffer has been created successfully -\n * the returned value should be stored as the handle to the created message\n * buffer.\n *\n * Example use:\n<pre>\n\nvoid vAFunction( void )\n{\nmsg_buf_t xMessageBuffer;\nconst size_t xMessageBufferSizeBytes = 100;\n\n    // Create a message buffer that can hold 100 bytes.  The memory used to hold\n    // both the message buffer structure and the messages themselves is allocated\n    // dynamically.  Each message added to the buffer consumes an additional 4\n    // bytes which are used to hold the lengh of the message.\n    xMessageBuffer = xMessageBufferCreate( xMessageBufferSizeBytes );\n\n    if( xMessageBuffer == NULL )\n    {\n        // There was not enough heap memory space available to create the\n        // message buffer.\n    }\n    else\n    {\n        // The message buffer was created successfully and can now be used.\n    }\n\n</pre>\n * \\defgroup xMessageBufferCreate xMessageBufferCreate\n * \\ingroup MessageBufferManagement\n */\n#define xMessageBufferCreate( xBufferSizeBytes ) ( msg_buf_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE )\n\n/**\n * message_buffer.h\n *\n<pre>\nmsg_buf_t xMessageBufferCreateStatic( size_t xBufferSizeBytes,\n                                                  uint8_t *pucMessageBufferStorageArea,\n                                                  static_msg_buf_s_t *pxStaticMessageBuffer );\n</pre>\n * Creates a new message buffer using statically allocated memory.  See\n * xMessageBufferCreate() for a version that uses dynamically allocated memory.\n *\n * @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the\n * pucMessageBufferStorageArea parameter.  When a message is written to the\n * message buffer an additional sizeof( size_t ) bytes are also written to store\n * the message's length.  sizeof( size_t ) is typically 4 bytes on a 32-bit\n * architecture, so on most 32-bit architecture a 10 byte message will take up\n * 14 bytes of message buffer space.  The maximum number of bytes that can be\n * stored in the message buffer is actually (xBufferSizeBytes - 1).\n *\n * @param pucMessageBufferStorageArea Must point to a uint8_t array that is at\n * least xBufferSizeBytes + 1 big.  This is the array to which messages are\n * copied when they are written to the message buffer.\n *\n * @param pxStaticMessageBuffer Must point to a variable of type\n * static_msg_buf_s_t, which will be used to hold the message buffer's data\n * structure.\n *\n * @return If the message buffer is created successfully then a handle to the\n * created message buffer is returned. If either pucMessageBufferStorageArea or\n * pxStaticmessageBuffer are NULL then NULL is returned.\n *\n * Example use:\n<pre>\n\n// Used to dimension the array used to hold the messages.  The available space\n// will actually be one less than this, so 999.\n#define STORAGE_SIZE_BYTES 1000\n\n// Defines the memory that will actually hold the messages within the message\n// buffer.\nstatic uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];\n\n// The variable used to hold the message buffer structure.\nstatic_msg_buf_s_t xMessageBufferStruct;\n\nvoid MyFunction( void )\n{\nmsg_buf_t xMessageBuffer;\n\n    xMessageBuffer = xMessageBufferCreateStatic( sizeof( ucBufferStorage ),\n                                                 ucBufferStorage,\n                                                 &xMessageBufferStruct );\n\n    // As neither the pucMessageBufferStorageArea or pxStaticMessageBuffer\n    // parameters were NULL, xMessageBuffer will not be NULL, and can be used to\n    // reference the created message buffer in other message buffer API calls.\n\n    // Other code that uses the message buffer can go here.\n}\n\n</pre>\n * \\defgroup xMessageBufferCreateStatic xMessageBufferCreateStatic\n * \\ingroup MessageBufferManagement\n */\n#define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) ( msg_buf_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer )\n\n/**\n * message_buffer.h\n *\n<pre>\nsize_t msg_buf_send( msg_buf_t xMessageBuffer,\n                           const void *pvTxData,\n                           size_t xDataLengthBytes,\n                           uint32_t xTicksToWait );\n<pre>\n *\n * Sends a discrete message to the message buffer.  The message can be any\n * length that fits within the buffer's free space, and is copied into the\n * buffer.\n *\n * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer\n * implementation (so also the message buffer implementation, as message buffers\n * are built on top of stream buffers) assumes there is only one task or\n * interrupt that will write to the buffer (the writer), and only one task or\n * interrupt that will read from the buffer (the reader).  It is safe for the\n * writer and reader to be different tasks or interrupts, but, unlike other\n * FreeRTOS objects, it is not safe to have multiple different writers or\n * multiple different readers.  If there are to be multiple different writers\n * then the application writer must place each call to a writing API function\n * (such as msg_buf_send()) inside a critical section and set the send\n * block time to 0.  Likewise, if there are to be multiple different readers\n * then the application writer must place each call to a reading API function\n * (such as xMessageBufferRead()) inside a critical section and set the receive\n * block time to 0.\n *\n * Use msg_buf_send() to write to a message buffer from a task.  Use\n * xMessageBufferSendFromISR() to write to a message buffer from an interrupt\n * service routine (ISR).\n *\n * @param xMessageBuffer The handle of the message buffer to which a message is\n * being sent.\n *\n * @param pvTxData A pointer to the message that is to be copied into the\n * message buffer.\n *\n * @param xDataLengthBytes The length of the message.  That is, the number of\n * bytes to copy from pvTxData into the message buffer.  When a message is\n * written to the message buffer an additional sizeof( size_t ) bytes are also\n * written to store the message's length.  sizeof( size_t ) is typically 4 bytes\n * on a 32-bit architecture, so on most 32-bit architecture setting\n * xDataLengthBytes to 20 will reduce the free space in the message buffer by 24\n * bytes (20 bytes of message data and 4 bytes to hold the message length).\n *\n * @param xTicksToWait The maximum amount of time the calling task should remain\n * in the Blocked state to wait for enough space to become available in the\n * message buffer, should the message buffer have insufficient space when\n * msg_buf_send() is called.  The calling task will never block if\n * xTicksToWait is zero.  The block time is specified in tick periods, so the\n * absolute time it represents is dependent on the tick frequency.  The macro\n * pdMS_TO_TICKS() can be used to convert a time specified in milliseconds into\n * a time specified in ticks.  Setting xTicksToWait to portMAX_DELAY will cause\n * the task to wait indefinitely (without timing out), provided\n * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h.  Tasks do not use any\n * CPU time when they are in the Blocked state.\n *\n * @return The number of bytes written to the message buffer.  If the call to\n * msg_buf_send() times out before there was enough space to write the\n * message into the message buffer then zero is returned.  If the call did not\n * time out then xDataLengthBytes is returned.\n *\n * Example use:\n<pre>\nvoid vAFunction( msg_buf_t xMessageBuffer )\n{\nsize_t xBytesSent;\nuint8_t ucArrayToSend[] = { 0, 1, 2, 3 };\nchar *pcStringToSend = \"String to send\";\nconst uint32_t x100ms = pdMS_TO_TICKS( 100 );\n\n    // Send an array to the message buffer, blocking for a maximum of 100ms to\n    // wait for enough space to be available in the message buffer.\n    xBytesSent = msg_buf_send( xMessageBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );\n\n    if( xBytesSent != sizeof( ucArrayToSend ) )\n    {\n        // The call to msg_buf_send() times out before there was enough\n        // space in the buffer for the data to be written.\n    }\n\n    // Send the string to the message buffer.  Return immediately if there is\n    // not enough space in the buffer.\n    xBytesSent = msg_buf_send( xMessageBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );\n\n    if( xBytesSent != strlen( pcStringToSend ) )\n    {\n        // The string could not be added to the message buffer because there was\n        // not enough free space in the buffer.\n    }\n}\n</pre>\n * \\defgroup msg_buf_send msg_buf_send\n * \\ingroup MessageBufferManagement\n */\n#define msg_buf_send( xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait ) stream_buf_send( ( stream_buf_t ) xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait )\n\n/**\n * message_buffer.h\n *\n<pre>\nsize_t xMessageBufferSendFromISR( msg_buf_t xMessageBuffer,\n                                  const void *pvTxData,\n                                  size_t xDataLengthBytes,\n                                  int32_t *pxHigherPriorityTaskWoken );\n<pre>\n *\n * Interrupt safe version of the API function that sends a discrete message to\n * the message buffer.  The message can be any length that fits within the\n * buffer's free space, and is copied into the buffer.\n *\n * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer\n * implementation (so also the message buffer implementation, as message buffers\n * are built on top of stream buffers) assumes there is only one task or\n * interrupt that will write to the buffer (the writer), and only one task or\n * interrupt that will read from the buffer (the reader).  It is safe for the\n * writer and reader to be different tasks or interrupts, but, unlike other\n * FreeRTOS objects, it is not safe to have multiple different writers or\n * multiple different readers.  If there are to be multiple different writers\n * then the application writer must place each call to a writing API function\n * (such as msg_buf_send()) inside a critical section and set the send\n * block time to 0.  Likewise, if there are to be multiple different readers\n * then the application writer must place each call to a reading API function\n * (such as xMessageBufferRead()) inside a critical section and set the receive\n * block time to 0.\n *\n * Use msg_buf_send() to write to a message buffer from a task.  Use\n * xMessageBufferSendFromISR() to write to a message buffer from an interrupt\n * service routine (ISR).\n *\n * @param xMessageBuffer The handle of the message buffer to which a message is\n * being sent.\n *\n * @param pvTxData A pointer to the message that is to be copied into the\n * message buffer.\n *\n * @param xDataLengthBytes The length of the message.  That is, the number of\n * bytes to copy from pvTxData into the message buffer.  When a message is\n * written to the message buffer an additional sizeof( size_t ) bytes are also\n * written to store the message's length.  sizeof( size_t ) is typically 4 bytes\n * on a 32-bit architecture, so on most 32-bit architecture setting\n * xDataLengthBytes to 20 will reduce the free space in the message buffer by 24\n * bytes (20 bytes of message data and 4 bytes to hold the message length).\n *\n * @param pxHigherPriorityTaskWoken  It is possible that a message buffer will\n * have a task blocked on it waiting for data.  Calling\n * xMessageBufferSendFromISR() can make data available, and so cause a task that\n * was waiting for data to leave the Blocked state.  If calling\n * xMessageBufferSendFromISR() causes a task to leave the Blocked state, and the\n * unblocked task has a priority higher than the currently executing task (the\n * task that was interrupted), then, internally, xMessageBufferSendFromISR()\n * will set *pxHigherPriorityTaskWoken to pdTRUE.  If\n * xMessageBufferSendFromISR() sets this value to pdTRUE, then normally a\n * context switch should be performed before the interrupt is exited.  This will\n * ensure that the interrupt returns directly to the highest priority Ready\n * state task.  *pxHigherPriorityTaskWoken should be set to pdFALSE before it\n * is passed into the function.  See the code example below for an example.\n *\n * @return The number of bytes actually written to the message buffer.  If the\n * message buffer didn't have enough free space for the message to be stored\n * then 0 is returned, otherwise xDataLengthBytes is returned.\n *\n * Example use:\n<pre>\n// A message buffer that has already been created.\nmsg_buf_t xMessageBuffer;\n\nvoid vAnInterruptServiceRoutine( void )\n{\nsize_t xBytesSent;\nchar *pcStringToSend = \"String to send\";\nint32_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.\n\n    // Attempt to send the string to the message buffer.\n    xBytesSent = xMessageBufferSendFromISR( xMessageBuffer,\n                                            ( void * ) pcStringToSend,\n                                            strlen( pcStringToSend ),\n                                            &xHigherPriorityTaskWoken );\n\n    if( xBytesSent != strlen( pcStringToSend ) )\n    {\n        // The string could not be added to the message buffer because there was\n        // not enough free space in the buffer.\n    }\n\n    // If xHigherPriorityTaskWoken was set to pdTRUE inside\n    // xMessageBufferSendFromISR() then a task that has a priority above the\n    // priority of the currently executing task was unblocked and a context\n    // switch should be performed to ensure the ISR returns to the unblocked\n    // task.  In most FreeRTOS ports this is done by simply passing\n    // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the\n    // variables value, and perform the context switch if necessary.  Check the\n    // documentation for the port in use for port specific instructions.\n    taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );\n}\n</pre>\n * \\defgroup xMessageBufferSendFromISR xMessageBufferSendFromISR\n * \\ingroup MessageBufferManagement\n */\n#define xMessageBufferSendFromISR( xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ) xStreamBufferSendFromISR( ( stream_buf_t ) xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken )\n\n/**\n * message_buffer.h\n *\n<pre>\nsize_t msg_buf_recv( msg_buf_t xMessageBuffer,\n                              void *pvRxData,\n                              size_t xBufferLengthBytes,\n                              uint32_t xTicksToWait );\n</pre>\n *\n * Receives a discrete message from a message buffer.  Messages can be of\n * variable length and are copied out of the buffer.\n *\n * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer\n * implementation (so also the message buffer implementation, as message buffers\n * are built on top of stream buffers) assumes there is only one task or\n * interrupt that will write to the buffer (the writer), and only one task or\n * interrupt that will read from the buffer (the reader).  It is safe for the\n * writer and reader to be different tasks or interrupts, but, unlike other\n * FreeRTOS objects, it is not safe to have multiple different writers or\n * multiple different readers.  If there are to be multiple different writers\n * then the application writer must place each call to a writing API function\n * (such as msg_buf_send()) inside a critical section and set the send\n * block time to 0.  Likewise, if there are to be multiple different readers\n * then the application writer must place each call to a reading API function\n * (such as xMessageBufferRead()) inside a critical section and set the receive\n * block time to 0.\n *\n * Use msg_buf_recv() to read from a message buffer from a task.  Use\n * xMessageBufferReceiveFromISR() to read from a message buffer from an\n * interrupt service routine (ISR).\n *\n * @param xMessageBuffer The handle of the message buffer from which a message\n * is being received.\n *\n * @param pvRxData A pointer to the buffer into which the received message is\n * to be copied.\n *\n * @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData\n * parameter.  This sets the maximum length of the message that can be received.\n * If xBufferLengthBytes is too small to hold the next message then the message\n * will be left in the message buffer and 0 will be returned.\n *\n * @param xTicksToWait The maximum amount of time the task should remain in the\n * Blocked state to wait for a message, should the message buffer be empty.\n * msg_buf_recv() will return immediately if xTicksToWait is zero and\n * the message buffer is empty.  The block time is specified in tick periods, so\n * the absolute time it represents is dependent on the tick frequency.  The\n * macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds\n * into a time specified in ticks.  Setting xTicksToWait to portMAX_DELAY will\n * cause the task to wait indefinitely (without timing out), provided\n * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h.  Tasks do not use any\n * CPU time when they are in the Blocked state.\n *\n * @return The length, in bytes, of the message read from the message buffer, if\n * any.  If msg_buf_recv() times out before a message became available\n * then zero is returned.  If the length of the message is greater than\n * xBufferLengthBytes then the message will be left in the message buffer and\n * zero is returned.\n *\n * Example use:\n<pre>\nvoid vAFunction( MessageBuffer_t xMessageBuffer )\n{\nuint8_t ucRxData[ 20 ];\nsize_t xReceivedBytes;\nconst uint32_t xBlockTime = pdMS_TO_TICKS( 20 );\n\n    // Receive the next message from the message buffer.  Wait in the Blocked\n    // state (so not using any CPU processing time) for a maximum of 100ms for\n    // a message to become available.\n    xReceivedBytes = msg_buf_recv( xMessageBuffer,\n                                            ( void * ) ucRxData,\n                                            sizeof( ucRxData ),\n                                            xBlockTime );\n\n    if( xReceivedBytes > 0 )\n    {\n        // A ucRxData contains a message that is xReceivedBytes long.  Process\n        // the message here....\n    }\n}\n</pre>\n * \\defgroup msg_buf_recv msg_buf_recv\n * \\ingroup MessageBufferManagement\n */\n#define msg_buf_recv( xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ) stream_buf_recv( ( stream_buf_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait )\n\n\n/**\n * message_buffer.h\n *\n<pre>\nsize_t xMessageBufferReceiveFromISR( msg_buf_t xMessageBuffer,\n                                     void *pvRxData,\n                                     size_t xBufferLengthBytes,\n                                     int32_t *pxHigherPriorityTaskWoken );\n</pre>\n *\n * An interrupt safe version of the API function that receives a discrete\n * message from a message buffer.  Messages can be of variable length and are\n * copied out of the buffer.\n *\n * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer\n * implementation (so also the message buffer implementation, as message buffers\n * are built on top of stream buffers) assumes there is only one task or\n * interrupt that will write to the buffer (the writer), and only one task or\n * interrupt that will read from the buffer (the reader).  It is safe for the\n * writer and reader to be different tasks or interrupts, but, unlike other\n * FreeRTOS objects, it is not safe to have multiple different writers or\n * multiple different readers.  If there are to be multiple different writers\n * then the application writer must place each call to a writing API function\n * (such as msg_buf_send()) inside a critical section and set the send\n * block time to 0.  Likewise, if there are to be multiple different readers\n * then the application writer must place each call to a reading API function\n * (such as xMessageBufferRead()) inside a critical section and set the receive\n * block time to 0.\n *\n * Use msg_buf_recv() to read from a message buffer from a task.  Use\n * xMessageBufferReceiveFromISR() to read from a message buffer from an\n * interrupt service routine (ISR).\n *\n * @param xMessageBuffer The handle of the message buffer from which a message\n * is being received.\n *\n * @param pvRxData A pointer to the buffer into which the received message is\n * to be copied.\n *\n * @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData\n * parameter.  This sets the maximum length of the message that can be received.\n * If xBufferLengthBytes is too small to hold the next message then the message\n * will be left in the message buffer and 0 will be returned.\n *\n * @param pxHigherPriorityTaskWoken  It is possible that a message buffer will\n * have a task blocked on it waiting for space to become available.  Calling\n * xMessageBufferReceiveFromISR() can make space available, and so cause a task\n * that is waiting for space to leave the Blocked state.  If calling\n * xMessageBufferReceiveFromISR() causes a task to leave the Blocked state, and\n * the unblocked task has a priority higher than the currently executing task\n * (the task that was interrupted), then, internally,\n * xMessageBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE.\n * If xMessageBufferReceiveFromISR() sets this value to pdTRUE, then normally a\n * context switch should be performed before the interrupt is exited.  That will\n * ensure the interrupt returns directly to the highest priority Ready state\n * task.  *pxHigherPriorityTaskWoken should be set to pdFALSE before it is\n * passed into the function.  See the code example below for an example.\n *\n * @return The length, in bytes, of the message read from the message buffer, if\n * any.\n *\n * Example use:\n<pre>\n// A message buffer that has already been created.\nMessageBuffer_t xMessageBuffer;\n\nvoid vAnInterruptServiceRoutine( void )\n{\nuint8_t ucRxData[ 20 ];\nsize_t xReceivedBytes;\nint32_t xHigherPriorityTaskWoken = pdFALSE;  // Initialised to pdFALSE.\n\n    // Receive the next message from the message buffer.\n    xReceivedBytes = xMessageBufferReceiveFromISR( xMessageBuffer,\n                                                  ( void * ) ucRxData,\n                                                  sizeof( ucRxData ),\n                                                  &xHigherPriorityTaskWoken );\n\n    if( xReceivedBytes > 0 )\n    {\n        // A ucRxData contains a message that is xReceivedBytes long.  Process\n        // the message here....\n    }\n\n    // If xHigherPriorityTaskWoken was set to pdTRUE inside\n    // xMessageBufferReceiveFromISR() then a task that has a priority above the\n    // priority of the currently executing task was unblocked and a context\n    // switch should be performed to ensure the ISR returns to the unblocked\n    // task.  In most FreeRTOS ports this is done by simply passing\n    // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the\n    // variables value, and perform the context switch if necessary.  Check the\n    // documentation for the port in use for port specific instructions.\n    taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );\n}\n</pre>\n * \\defgroup xMessageBufferReceiveFromISR xMessageBufferReceiveFromISR\n * \\ingroup MessageBufferManagement\n */\n#define xMessageBufferReceiveFromISR( xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ) xStreamBufferReceiveFromISR( ( stream_buf_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken )\n\n/**\n * message_buffer.h\n *\n<pre>\nvoid vMessageBufferDelete( msg_buf_t xMessageBuffer );\n</pre>\n *\n * Deletes a message buffer that was previously created using a call to\n * xMessageBufferCreate() or xMessageBufferCreateStatic().  If the message\n * buffer was created using dynamic memory (that is, by xMessageBufferCreate()),\n * then the allocated memory is freed.\n *\n * A message buffer handle must not be used after the message buffer has been\n * deleted.\n *\n * @param xMessageBuffer The handle of the message buffer to be deleted.\n *\n */\n#define vMessageBufferDelete( xMessageBuffer ) vStreamBufferDelete( ( stream_buf_t ) xMessageBuffer )\n\n/**\n * message_buffer.h\n<pre>\nint32_t msg_buf_is_full( msg_buf_t xMessageBuffer ) );\n</pre>\n *\n * Tests to see if a message buffer is full.  A message buffer is full if it\n * cannot accept any more messages, of any size, until space is made available\n * by a message being removed from the message buffer.\n *\n * @param xMessageBuffer The handle of the message buffer being queried.\n *\n * @return If the message buffer referenced by xMessageBuffer is full then\n * pdTRUE is returned.  Otherwise pdFALSE is returned.\n */\n#define msg_buf_is_full( xMessageBuffer ) stream_buf_is_full( ( stream_buf_t ) xMessageBuffer )\n\n/**\n * message_buffer.h\n<pre>\nint32_t msg_buf_is_empty( msg_buf_t xMessageBuffer ) );\n</pre>\n *\n * Tests to see if a message buffer is empty (does not contain any messages).\n *\n * @param xMessageBuffer The handle of the message buffer being queried.\n *\n * @return If the message buffer referenced by xMessageBuffer is empty then\n * pdTRUE is returned.  Otherwise pdFALSE is returned.\n *\n */\n#define msg_buf_is_empty( xMessageBuffer ) stream_buf_is_empty( ( stream_buf_t ) xMessageBuffer )\n\n/**\n * message_buffer.h\n<pre>\nint32_t msg_buf_reset( msg_buf_t xMessageBuffer );\n</pre>\n *\n * Resets a message buffer to its initial empty state, discarding any message it\n * contained.\n *\n * A message buffer can only be reset if there are no tasks blocked on it.\n *\n * @param xMessageBuffer The handle of the message buffer being reset.\n *\n * @return If the message buffer was reset then pdPASS is returned.  If the\n * message buffer could not be reset because either there was a task blocked on\n * the message queue to wait for space to become available, or to wait for a\n * a message to be available, then pdFAIL is returned.\n *\n * \\defgroup msg_buf_reset msg_buf_reset\n * \\ingroup MessageBufferManagement\n */\n#define msg_buf_reset( xMessageBuffer ) stream_buf_reset( ( stream_buf_t ) xMessageBuffer )\n\n\n/**\n * message_buffer.h\n<pre>\nsize_t xMessageBufferSpaceAvailable( msg_buf_t xMessageBuffer ) );\n</pre>\n * Returns the number of bytes of free space in the message buffer.\n *\n * @param xMessageBuffer The handle of the message buffer being queried.\n *\n * @return The number of bytes that can be written to the message buffer before\n * the message buffer would be full.  When a message is written to the message\n * buffer an additional sizeof( size_t ) bytes are also written to store the\n * message's length.  sizeof( size_t ) is typically 4 bytes on a 32-bit\n * architecture, so if msg_buf_get_unused() returns 10, then the size\n * of the largest message that can be written to the message buffer is 6 bytes.\n *\n * \\defgroup xMessageBufferSpaceAvailable xMessageBufferSpaceAvailable\n * \\ingroup MessageBufferManagement\n */\n#define xMessageBufferSpaceAvailable( xMessageBuffer ) stream_buf_get_unused( ( stream_buf_t ) xMessageBuffer )\n\n/**\n * message_buffer.h\n *\n<pre>\nint32_t xMessageBufferSendCompletedFromISR( msg_buf_t xStreamBuffer, int32_t *pxHigherPriorityTaskWoken );\n</pre>\n *\n * For advanced users only.\n *\n * The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when\n * data is sent to a message buffer or stream buffer.  If there was a task that\n * was blocked on the message or stream buffer waiting for data to arrive then\n * the sbSEND_COMPLETED() macro sends a notification to the task to remove it\n * from the Blocked state.  xMessageBufferSendCompletedFromISR() does the same\n * thing.  It is provided to enable application writers to implement their own\n * version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME.\n *\n * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for\n * additional information.\n *\n * @param xStreamBuffer The handle of the stream buffer to which data was\n * written.\n *\n * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be\n * initialised to pdFALSE before it is passed into\n * xMessageBufferSendCompletedFromISR().  If calling\n * xMessageBufferSendCompletedFromISR() removes a task from the Blocked state,\n * and the task has a priority above the priority of the currently running task,\n * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a\n * context switch should be performed before exiting the ISR.\n *\n * @return If a task was removed from the Blocked state then pdTRUE is returned.\n * Otherwise pdFALSE is returned.\n *\n * \\defgroup xMessageBufferSendCompletedFromISR xMessageBufferSendCompletedFromISR\n * \\ingroup StreamBufferManagement\n */\n#define xMessageBufferSendCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) xStreamBufferSendCompletedFromISR( ( stream_buf_t ) xMessageBuffer, pxHigherPriorityTaskWoken )\n\n/**\n * message_buffer.h\n *\n<pre>\nint32_t xMessageBufferReceiveCompletedFromISR( msg_buf_t xStreamBuffer, int32_t *pxHigherPriorityTaskWoken );\n</pre>\n *\n * For advanced users only.\n *\n * The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when\n * data is read out of a message buffer or stream buffer.  If there was a task\n * that was blocked on the message or stream buffer waiting for data to arrive\n * then the sbRECEIVE_COMPLETED() macro sends a notification to the task to\n * remove it from the Blocked state.  xMessageBufferReceiveCompletedFromISR()\n * does the same thing.  It is provided to enable application writers to\n * implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT\n * ANY OTHER TIME.\n *\n * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for\n * additional information.\n *\n * @param xStreamBuffer The handle of the stream buffer from which data was\n * read.\n *\n * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be\n * initialised to pdFALSE before it is passed into\n * xMessageBufferReceiveCompletedFromISR().  If calling\n * xMessageBufferReceiveCompletedFromISR() removes a task from the Blocked state,\n * and the task has a priority above the priority of the currently running task,\n * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a\n * context switch should be performed before exiting the ISR.\n *\n * @return If a task was removed from the Blocked state then pdTRUE is returned.\n * Otherwise pdFALSE is returned.\n *\n * \\defgroup xMessageBufferReceiveCompletedFromISR xMessageBufferReceiveCompletedFromISR\n * \\ingroup StreamBufferManagement\n */\n#define xMessageBufferReceiveCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) xStreamBufferReceiveCompletedFromISR( ( stream_buf_t ) xMessageBuffer, pxHigherPriorityTaskWoken )\n\n#if defined( __cplusplus )\n} /* extern \"C\" */\n#endif\n\n#endif\t/* !defined( FREERTOS_MESSAGE_BUFFER_H ) */\n"
  },
  {
    "path": "include/rtos/portable.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n/*-----------------------------------------------------------\n * Portable layer API.  Each function must be defined for each port.\n *----------------------------------------------------------*/\n\n#ifndef PORTABLE_H\n#define PORTABLE_H\n\n/* If portENTER_CRITICAL is not defined then including deprecated_definitions.h\ndid not result in a portmacro.h header file being included - and it should be\nincluded here.  In this case the path to the correct portmacro.h header file\nmust be set in the compiler's include path. */\n#ifndef portENTER_CRITICAL\n\t#include \"portmacro.h\"\n#endif\n\n#if portBYTE_ALIGNMENT == 32\n\t#define portBYTE_ALIGNMENT_MASK ( 0x001f )\n#endif\n\n#if portBYTE_ALIGNMENT == 16\n\t#define portBYTE_ALIGNMENT_MASK ( 0x000f )\n#endif\n\n#if portBYTE_ALIGNMENT == 8\n\t#define portBYTE_ALIGNMENT_MASK ( 0x0007 )\n#endif\n\n#if portBYTE_ALIGNMENT == 4\n\t#define portBYTE_ALIGNMENT_MASK\t( 0x0003 )\n#endif\n\n#if portBYTE_ALIGNMENT == 2\n\t#define portBYTE_ALIGNMENT_MASK\t( 0x0001 )\n#endif\n\n#if portBYTE_ALIGNMENT == 1\n\t#define portBYTE_ALIGNMENT_MASK\t( 0x0000 )\n#endif\n\n#ifndef portBYTE_ALIGNMENT_MASK\n\t#error \"Invalid portBYTE_ALIGNMENT definition\"\n#endif\n\n#ifndef portNUM_CONFIGURABLE_REGIONS\n\t#define portNUM_CONFIGURABLE_REGIONS 1\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/*\n * Setup the stack of a new task so it is ready to be placed under the\n * scheduler control.  The registers have to be placed on the stack in\n * the order that the port expects to find them.\n *\n */\ntask_stack_t *pxPortInitialiseStack( task_stack_t *pxTopOfStack, task_fn_t pxCode, void *pvParameters ) ;\n\n/* Used by heap_5.c. */\ntypedef struct HeapRegion\n{\n\tuint8_t *pucStartAddress;\n\tsize_t xSizeInBytes;\n} HeapRegion_t;\n\n/*\n * Used to define multiple heap regions for use by heap_5.c.  This function\n * must be called before any calls to kmalloc() - not creating a task,\n * queue, semaphore, mutex, software timer, event group, etc. will result in\n * kmalloc being called.\n *\n * pxHeapRegions passes in an array of HeapRegion_t structures - each of which\n * defines a region of memory that can be used as the heap.  The array is\n * terminated by a HeapRegions_t structure that has a size of 0.  The region\n * with the lowest start address must appear first in the array.\n */\nvoid vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) ;\n\n\n/*\n * Map to the memory management routines required for the port.\n */\nvoid *kmalloc( size_t xSize ) ;\nvoid kfree( void *pv ) ;\nvoid vPortInitialiseBlocks( void ) ;\nsize_t xPortGetFreeHeapSize( void ) ;\nsize_t xPortGetMinimumEverFreeHeapSize( void ) ;\n\n/*\n * Setup the hardware ready for the scheduler to take control.  This generally\n * sets up a tick interrupt and sets timers for the correct tick frequency.\n */\nint32_t xPortStartScheduler( void ) ;\n\n/*\n * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so\n * the hardware is left in its original condition after the scheduler stops\n * executing.\n */\nvoid vPortEndScheduler( void ) ;\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* PORTABLE_H */\n"
  },
  {
    "path": "include/rtos/portmacro.h",
    "content": "/*\n    FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.\n    All rights reserved\n\n    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\n\n    This file is part of the FreeRTOS distribution.\n\n    FreeRTOS is free software; you can redistribute it and/or modify it under\n    the terms of the GNU General Public License (version 2) as published by the\n    Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\n\n    ***************************************************************************\n    >>!   NOTE: The modification to the GPL is included to allow you to     !<<\n    >>!   distribute a combined work that includes FreeRTOS without being   !<<\n    >>!   obliged to provide the source code for proprietary components     !<<\n    >>!   outside of the FreeRTOS kernel.                                   !<<\n    ***************************************************************************\n\n    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\n    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n    FOR A PARTICULAR PURPOSE.  Full license text is available on the following\n    link: http://www.freertos.org/a00114.html\n\n    ***************************************************************************\n     *                                                                       *\n     *    FreeRTOS provides completely free yet professionally developed,    *\n     *    robust, strictly quality controlled, supported, and cross          *\n     *    platform software that is more than just the market leader, it     *\n     *    is the industry's de facto standard.                               *\n     *                                                                       *\n     *    Help yourself get started quickly while simultaneously helping     *\n     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\n     *    tutorial book, reference manual, or both:                          *\n     *    http://www.FreeRTOS.org/Documentation                              *\n     *                                                                       *\n    ***************************************************************************\n\n    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\n    the FAQ page \"My application does not run, what could be wrong?\".  Have you\n    defined configASSERT()?\n\n    http://www.FreeRTOS.org/support - In return for receiving this top quality\n    embedded software for free we request you assist our global community by\n    participating in the support forum.\n\n    http://www.FreeRTOS.org/training - Investing in training allows your team to\n    be as productive as possible as early as possible.  Now you can receive\n    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\n    Ltd, and the world's leading authority on the world's leading RTOS.\n\n    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\n    including FreeRTOS+Trace - an indispensable productivity tool, a DOS\n    compatible FAT file system, and our tiny thread aware UDP/IP stack.\n\n    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\n    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\n\n    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\n    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\n    licenses offer ticketed support, indemnification and commercial middleware.\n\n    http://www.SafeRTOS.com - High Integrity Systems also provide a safety\n    engineered and independently SIL3 certified version for use in safety and\n    mission critical applications that require provable dependability.\n\n    1 tab == 4 spaces!\n*/\n\n#ifndef PORTMACRO_H\n#define PORTMACRO_H\n\n#ifdef __cplusplus\n\textern \"C\" {\n#endif\n\n/*-----------------------------------------------------------\n * Port specific definitions.\n *\n * The settings in this file configure FreeRTOS correctly for the given hardware\n * and compiler.\n *\n * These settings should not be altered.\n *-----------------------------------------------------------\n */\n\n/* Type definitions. */\n#define portCHAR\t\tchar\n#define portFLOAT\t\tfloat\n#define portDOUBLE\t\tdouble\n#define portLONG\t\tlong\n#define portSHORT\t\tshort\n#define portSTACK_TYPE\tuint32_t\n#define portBASE_TYPE\tlong\n\ntypedef portSTACK_TYPE task_stack_t;\ntypedef long int32_t;\ntypedef unsigned long uint32_t;\n\ntypedef uint32_t uint32_t;\n#define portMAX_DELAY ( uint32_t ) 0xffffffffUL\n\n/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do\nnot need to be guarded with a critical section. */\n#define portTICK_TYPE_IS_ATOMIC 1\n\n/*-----------------------------------------------------------*/\n\n/* Hardware specifics. */\n#define portSTACK_GROWTH\t\t\t( -1 )\n#define portTICK_PERIOD_MS\t\t\t( ( uint32_t ) 1000 / configTICK_RATE_HZ )\n#define portBYTE_ALIGNMENT\t\t\t8\n\n/*-----------------------------------------------------------*/\n\n/* Task utilities. */\n\n/* Called at the end of an ISR that can cause a context switch. */\n#define portEND_SWITCHING_ISR( xSwitchRequired )\\\n{\t\t\t\t\t\t\t\t\t\t\t\t\\\nextern uint32_t ulPortYieldRequired;\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tif( xSwitchRequired != pdFALSE )\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tulPortYieldRequired = pdTRUE;\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n}\n\n#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )\n#define portYIELD() __asm volatile ( \"SWI 0\" );\n\n\n/*-----------------------------------------------------------\n * Critical section control\n *----------------------------------------------------------*/\n\nextern void vPortEnterCritical( void );\nextern void vPortExitCritical( void );\nextern uint32_t ulPortSetInterruptMask( void );\nextern void vPortClearInterruptMask( uint32_t ulNewMaskValue );\nextern void vPortInstallFreeRTOSVectorTable( void );\n\n/* These macros do not globally disable/enable interrupts.  They do mask off\ninterrupts that have a priority below configMAX_API_CALL_INTERRUPT_PRIORITY. */\n#define portENTER_CRITICAL()\t\tvPortEnterCritical();\n#define portEXIT_CRITICAL()\t\t\tvPortExitCritical();\n#define portDISABLE_INTERRUPTS()\tulPortSetInterruptMask()\n#define portENABLE_INTERRUPTS()\t\tvPortClearInterruptMask( 0 )\n#define portSET_INTERRUPT_MASK_FROM_ISR()\t\tulPortSetInterruptMask()\n#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x)\tvPortClearInterruptMask(x)\n\n/*-----------------------------------------------------------*/\n\n/* Task function macros as described on the FreeRTOS.org WEB site.  These are\nnot required for this port but included in case common demo code that uses these\nmacros is used. */\n#define portTASK_FUNCTION_PROTO( vFunction, pvParameters )\tvoid vFunction( void *pvParameters )\n#define portTASK_FUNCTION( vFunction, pvParameters )\tvoid vFunction( void *pvParameters )\n\n/* Prototype of the FreeRTOS tick handler.  This must be installed as the\nhandler for whichever peripheral is used to generate the RTOS tick. */\nvoid FreeRTOS_Tick_Handler( void );\n\n/* If configUSE_TASK_FPU_SUPPORT is set to 1 (or left undefined) then tasks are\ncreated without an FPU context and must call vPortTaskUsesFPU() to give\nthemselves an FPU context before using any FPU instructions.  If\nconfigUSE_TASK_FPU_SUPPORT is set to 2 then all tasks will have an FPU context\nby default. */\n#if( configUSE_TASK_FPU_SUPPORT != 2 )\n\tvoid vPortTaskUsesFPU( void );\n#else\n\t/* Each task has an FPU context already, so define this function away to\n\tnothing to prevent it being called accidentally. */\n\t#define vPortTaskUsesFPU()\n#endif\n#define portTASK_USES_FLOATING_POINT() vPortTaskUsesFPU()\n\n#define portLOWEST_INTERRUPT_PRIORITY ( ( ( uint32_t ) configUNIQUE_INTERRUPT_PRIORITIES ) - 1UL )\n#define portLOWEST_USABLE_INTERRUPT_PRIORITY ( portLOWEST_INTERRUPT_PRIORITY - 1UL )\n\n/* Architecture specific optimisations. */\n#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION\n\t#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1\n#endif\n\n#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\n\n\t/* Store/clear the ready priorities in a bit map. */\n\t#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\n\t#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\n\n\t/*-----------------------------------------------------------*/\n\n\t#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __builtin_clz( uxReadyPriorities ) )\n\n#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\n\n#ifdef configASSERT\n\tvoid vPortValidateInterruptPriority( void );\n\t#define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() \tvPortValidateInterruptPriority()\n#endif /* configASSERT */\n\n#define portNOP() __asm volatile( \"NOP\" )\n#define portINLINE __inline\n\n#ifdef __cplusplus\n\t} /* extern C */\n#endif\n\n\n/* The number of bits to shift for an interrupt priority is dependent on the\nnumber of bits implemented by the interrupt controller. */\n#if configUNIQUE_INTERRUPT_PRIORITIES == 16\n\t#define portPRIORITY_SHIFT 4\n\t#define portMAX_BINARY_POINT_VALUE\t3\n#elif configUNIQUE_INTERRUPT_PRIORITIES == 32\n\t#define portPRIORITY_SHIFT 3\n\t#define portMAX_BINARY_POINT_VALUE\t2\n#elif configUNIQUE_INTERRUPT_PRIORITIES == 64\n\t#define portPRIORITY_SHIFT 2\n\t#define portMAX_BINARY_POINT_VALUE\t1\n#elif configUNIQUE_INTERRUPT_PRIORITIES == 128\n\t#define portPRIORITY_SHIFT 1\n\t#define portMAX_BINARY_POINT_VALUE\t0\n#elif configUNIQUE_INTERRUPT_PRIORITIES == 256\n\t#define portPRIORITY_SHIFT 0\n\t#define portMAX_BINARY_POINT_VALUE\t0\n#else\n\t#error Invalid configUNIQUE_INTERRUPT_PRIORITIES setting.  configUNIQUE_INTERRUPT_PRIORITIES must be set to the number of unique priorities implemented by the target hardware\n#endif\n\n/* Interrupt controller access addresses. */\n#define portICCPMR_PRIORITY_MASK_OFFSET  \t\t\t\t\t\t( 0x04 )\n#define portICCIAR_INTERRUPT_ACKNOWLEDGE_OFFSET \t\t\t\t( 0x0C )\n#define portICCEOIR_END_OF_INTERRUPT_OFFSET \t\t\t\t\t( 0x10 )\n#define portICCBPR_BINARY_POINT_OFFSET\t\t\t\t\t\t\t( 0x08 )\n#define portICCRPR_RUNNING_PRIORITY_OFFSET\t\t\t\t\t\t( 0x14 )\n\n#define portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS \t\t( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET )\n#define portICCPMR_PRIORITY_MASK_REGISTER \t\t\t\t\t( *( ( volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCPMR_PRIORITY_MASK_OFFSET ) ) )\n#define portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS \t( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCIAR_INTERRUPT_ACKNOWLEDGE_OFFSET )\n#define portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS \t\t( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCEOIR_END_OF_INTERRUPT_OFFSET )\n#define portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS \t\t\t( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCPMR_PRIORITY_MASK_OFFSET )\n#define portICCBPR_BINARY_POINT_REGISTER \t\t\t\t\t( *( ( const volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCBPR_BINARY_POINT_OFFSET ) ) )\n#define portICCRPR_RUNNING_PRIORITY_REGISTER \t\t\t\t( *( ( const volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCRPR_RUNNING_PRIORITY_OFFSET ) ) )\n\n#endif /* PORTMACRO_H */\n\n"
  },
  {
    "path": "include/rtos/projdefs.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n#ifndef PROJDEFS_H\n#define PROJDEFS_H\n\n/*\n * Defines the prototype to which task functions must conform.  Defined in this\n * file to ensure the type is known before portable.h is included.\n */\ntypedef void (*task_fn_t)( void * );\n\n/* Converts a time in milliseconds to a time in ticks.  This macro can be\noverridden by a macro of the same name defined in FreeRTOSConfig.h in case the\ndefinition here is not suitable for your application. */\n#ifndef pdMS_TO_TICKS\n\t#define pdMS_TO_TICKS( xTimeInMs ) ( ( uint32_t ) ( ( ( uint32_t ) ( xTimeInMs ) * ( uint32_t ) configTICK_RATE_HZ ) / ( uint32_t ) 1000 ) )\n#endif\n\n#define pdFALSE\t\t\t( ( int32_t ) 0 )\n#define pdTRUE\t\t\t( ( int32_t ) 1 )\n\n#define pdPASS\t\t\t( pdTRUE )\n#define pdFAIL\t\t\t( pdFALSE )\n#define errQUEUE_EMPTY\t( ( int32_t ) 0 )\n#define errQUEUE_FULL\t( ( int32_t ) 0 )\n\n/* FreeRTOS error definitions. */\n#define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY\t( -1 )\n#define errQUEUE_BLOCKED\t\t\t\t\t\t( -4 )\n#define errQUEUE_YIELD\t\t\t\t\t\t\t( -5 )\n\n/* Macros used for basic data corruption checks. */\n#ifndef configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES\n\t#define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0\n#endif\n\n#if( configUSE_16_BIT_TICKS == 1 )\n\t#define pdINTEGRITY_CHECK_VALUE 0x5a5a\n#else\n\t#define pdINTEGRITY_CHECK_VALUE 0x5a5a5a5aUL\n#endif\n\n/* The following errno values are used by FreeRTOS+ components, not FreeRTOS\nitself. */\n#define pdFREERTOS_ERRNO_NONE\t\t\t0\t/* No errors */\n#define\tpdFREERTOS_ERRNO_ENOENT\t\t\t2\t/* No such file or directory */\n#define\tpdFREERTOS_ERRNO_EINTR\t\t\t4\t/* Interrupted system call */\n#define\tpdFREERTOS_ERRNO_EIO\t\t\t5\t/* I/O error */\n#define\tpdFREERTOS_ERRNO_ENXIO\t\t\t6\t/* No such device or address */\n#define\tpdFREERTOS_ERRNO_EBADF\t\t\t9\t/* Bad file number */\n#define\tpdFREERTOS_ERRNO_EAGAIN\t\t\t11\t/* No more processes */\n#define\tpdFREERTOS_ERRNO_EWOULDBLOCK\t11\t/* Operation would block */\n#define\tpdFREERTOS_ERRNO_ENOMEM\t\t\t12\t/* Not enough memory */\n#define\tpdFREERTOS_ERRNO_EACCES\t\t\t13\t/* Permission denied */\n#define\tpdFREERTOS_ERRNO_EFAULT\t\t\t14\t/* Bad address */\n#define\tpdFREERTOS_ERRNO_EBUSY\t\t\t16\t/* Mount device busy */\n#define\tpdFREERTOS_ERRNO_EEXIST\t\t\t17\t/* File exists */\n#define\tpdFREERTOS_ERRNO_EXDEV\t\t\t18\t/* Cross-device link */\n#define\tpdFREERTOS_ERRNO_ENODEV\t\t\t19\t/* No such device */\n#define\tpdFREERTOS_ERRNO_ENOTDIR\t\t20\t/* Not a directory */\n#define\tpdFREERTOS_ERRNO_EISDIR\t\t\t21\t/* Is a directory */\n#define\tpdFREERTOS_ERRNO_EINVAL\t\t\t22\t/* Invalid argument */\n#define\tpdFREERTOS_ERRNO_ENOSPC\t\t\t28\t/* No space left on device */\n#define\tpdFREERTOS_ERRNO_ESPIPE\t\t\t29\t/* Illegal seek */\n#define\tpdFREERTOS_ERRNO_EROFS\t\t\t30\t/* Read only file system */\n#define\tpdFREERTOS_ERRNO_EUNATCH\t\t42\t/* Protocol driver not attached */\n#define\tpdFREERTOS_ERRNO_EBADE\t\t\t50\t/* Invalid exchange */\n#define\tpdFREERTOS_ERRNO_EFTYPE\t\t\t79\t/* Inappropriate file type or format */\n#define\tpdFREERTOS_ERRNO_ENMFILE\t\t89\t/* No more files */\n#define\tpdFREERTOS_ERRNO_ENOTEMPTY\t\t90\t/* Directory not empty */\n#define\tpdFREERTOS_ERRNO_ENAMETOOLONG \t91\t/* File or path name too long */\n#define\tpdFREERTOS_ERRNO_EOPNOTSUPP\t\t95\t/* Operation not supported on transport endpoint */\n#define\tpdFREERTOS_ERRNO_ENOBUFS\t\t105\t/* No buffer space available */\n#define\tpdFREERTOS_ERRNO_ENOPROTOOPT\t109\t/* Protocol not available */\n#define\tpdFREERTOS_ERRNO_EADDRINUSE\t\t112\t/* Address already in use */\n#define\tpdFREERTOS_ERRNO_ETIMEDOUT\t\t116\t/* Connection timed out */\n#define\tpdFREERTOS_ERRNO_EINPROGRESS\t119\t/* Connection already in progress */\n#define\tpdFREERTOS_ERRNO_EALREADY\t\t120\t/* Socket already connected */\n#define\tpdFREERTOS_ERRNO_EADDRNOTAVAIL \t125\t/* Address not available */\n#define\tpdFREERTOS_ERRNO_EISCONN\t\t127\t/* Socket is already connected */\n#define\tpdFREERTOS_ERRNO_ENOTCONN\t\t128\t/* Socket is not connected */\n#define\tpdFREERTOS_ERRNO_ENOMEDIUM\t\t135\t/* No medium inserted */\n#define\tpdFREERTOS_ERRNO_EILSEQ\t\t\t138\t/* An invalid UTF-16 sequence was encountered. */\n#define\tpdFREERTOS_ERRNO_ECANCELED\t\t140\t/* Operation canceled. */\n\n/* The following endian values are used by FreeRTOS+ components, not FreeRTOS\nitself. */\n#define pdFREERTOS_LITTLE_ENDIAN\t\t0\n#define pdFREERTOS_BIG_ENDIAN\t\t\t1\n\n/* Re-defining endian values for generic naming. */\n#define pdLITTLE_ENDIAN\t\t\t\t\tpdFREERTOS_LITTLE_ENDIAN\n#define pdBIG_ENDIAN\t\t\t\t\tpdFREERTOS_BIG_ENDIAN\n\n\n#endif /* PROJDEFS_H */\n\n\n\n"
  },
  {
    "path": "include/rtos/queue.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n\n#ifndef QUEUE_H\n#define QUEUE_H\n\n#ifndef INC_FREERTOS_H\n\t#error \"include FreeRTOS.h\" must appear in source files before \"include queue.h\"\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n\n/**\n * Type by which queues are referenced.  For example, a call to queue_create()\n * returns an queue_t variable that can then be used as a parameter to\n * xQueueSend(), queue_recv(), etc.\n */\ntypedef void * queue_t;\n\n/**\n * Type by which queue sets are referenced.  For example, a call to\n * xQueueCreateSet() returns an xQueueSet variable that can then be used as a\n * parameter to xQueueSelectFromSet(), xQueueAddToSet(), etc.\n */\ntypedef void * QueueSetHandle_t;\n\n/**\n * Queue sets can contain both queues and semaphores, so the\n * QueueSetMemberHandle_t is defined as a type to be used where a parameter or\n * return value can be either an queue_t or an sem_t.\n */\ntypedef void * QueueSetMemberHandle_t;\n\n/* For internal use only. */\n#define\tqueueSEND_TO_BACK\t\t( ( int32_t ) 0 )\n#define\tqueueSEND_TO_FRONT\t\t( ( int32_t ) 1 )\n#define queueOVERWRITE\t\t\t( ( int32_t ) 2 )\n\n/* For internal use only.  These definitions *must* match those in queue.c. */\n#define queueQUEUE_TYPE_BASE\t\t\t\t( ( uint8_t ) 0U )\n#define queueQUEUE_TYPE_SET\t\t\t\t\t( ( uint8_t ) 0U )\n#define queueQUEUE_TYPE_MUTEX \t\t\t\t( ( uint8_t ) 1U )\n#define queueQUEUE_TYPE_COUNTING_SEMAPHORE\t( ( uint8_t ) 2U )\n#define queueQUEUE_TYPE_BINARY_SEMAPHORE\t( ( uint8_t ) 3U )\n#define queueQUEUE_TYPE_RECURSIVE_MUTEX\t\t( ( uint8_t ) 4U )\n\n/**\n * queue. h\n * <pre>\n queue_t queue_create(\n\t\t\t\t\t\t\t  uint32_t uxQueueLength,\n\t\t\t\t\t\t\t  uint32_t uxItemSize\n\t\t\t\t\t\t  );\n * </pre>\n *\n * Creates a new queue instance, and returns a handle by which the new queue\n * can be referenced.\n *\n * Internally, within the FreeRTOS implementation, queues use two blocks of\n * memory.  The first block is used to hold the queue's data structures.  The\n * second block is used to hold items placed into the queue.  If a queue is\n * created using queue_create() then both blocks of memory are automatically\n * dynamically allocated inside the queue_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a queue is created using\n * queue_create_static() then the application writer must provide the memory that\n * will get used by the queue.  queue_create_static() therefore allows a queue to\n * be created without using any dynamic memory allocation.\n *\n * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html\n *\n * @param uxQueueLength The maximum number of items that the queue can contain.\n *\n * @param uxItemSize The number of bytes each item in the queue will require.\n * Items are queued by copy, not by reference, so this is the number of bytes\n * that will be copied for each posted item.  Each item on the queue must be\n * the same size.\n *\n * @return If the queue is successfully create then a handle to the newly\n * created queue is returned.  If the queue cannot be created then 0 is\n * returned.\n *\n * Example usage:\n   <pre>\n struct AMessage\n {\n\tchar ucMessageID;\n\tchar ucData[ 20 ];\n };\n\n void vATask( void *pvParameters )\n {\n queue_t xQueue1, xQueue2;\n\n\t// Create a queue capable of containing 10 uint32_t values.\n\txQueue1 = queue_create( 10, sizeof( uint32_t ) );\n\tif( xQueue1 == 0 )\n\t{\n\t\t// Queue was not created and must not be used.\n\t}\n\n\t// Create a queue capable of containing 10 pointers to AMessage structures.\n\t// These should be passed by pointer as they contain a lot of data.\n\txQueue2 = queue_create( 10, sizeof( struct AMessage * ) );\n\tif( xQueue2 == 0 )\n\t{\n\t\t// Queue was not created and must not be used.\n\t}\n\n\t// ... Rest of task code.\n }\n </pre>\n * \\defgroup queue_create queue_create\n * \\ingroup QueueManagement\n */\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\tqueue_t queue_create(uint32_t uxQueueLength, uint32_t uxItemSize);\n#endif\n\n/**\n * queue. h\n * <pre>\n queue_t queue_create_static(\n\t\t\t\t\t\t\t  uint32_t uxQueueLength,\n\t\t\t\t\t\t\t  uint32_t uxItemSize,\n\t\t\t\t\t\t\t  uint8_t *pucQueueStorageBuffer,\n\t\t\t\t\t\t\t  static_queue_s_t *pxQueueBuffer\n\t\t\t\t\t\t  );\n * </pre>\n *\n * Creates a new queue instance, and returns a handle by which the new queue\n * can be referenced.\n *\n * Internally, within the FreeRTOS implementation, queues use two blocks of\n * memory.  The first block is used to hold the queue's data structures.  The\n * second block is used to hold items placed into the queue.  If a queue is\n * created using queue_create() then both blocks of memory are automatically\n * dynamically allocated inside the queue_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a queue is created using\n * queue_create_static() then the application writer must provide the memory that\n * will get used by the queue.  queue_create_static() therefore allows a queue to\n * be created without using any dynamic memory allocation.\n *\n * http://www.FreeRTOS.org/Embedded-RTOS-Queues.html\n *\n * @param uxQueueLength The maximum number of items that the queue can contain.\n *\n * @param uxItemSize The number of bytes each item in the queue will require.\n * Items are queued by copy, not by reference, so this is the number of bytes\n * that will be copied for each posted item.  Each item on the queue must be\n * the same size.\n *\n * @param pucQueueStorageBuffer If uxItemSize is not zero then\n * pucQueueStorageBuffer must point to a uint8_t array that is at least large\n * enough to hold the maximum number of items that can be in the queue at any\n * one time - which is ( uxQueueLength * uxItemsSize ) bytes.  If uxItemSize is\n * zero then pucQueueStorageBuffer can be NULL.\n *\n * @param pxQueueBuffer Must point to a variable of type static_queue_s_t, which\n * will be used to hold the queue's data structure.\n *\n * @return If the queue is created then a handle to the created queue is\n * returned.  If pxQueueBuffer is NULL then NULL is returned.\n *\n * Example usage:\n   <pre>\n struct AMessage\n {\n\tchar ucMessageID;\n\tchar ucData[ 20 ];\n };\n\n #define QUEUE_LENGTH 10\n #define ITEM_SIZE sizeof( uint32_t )\n\n // xQueueBuffer will hold the queue structure.\n static_queue_s_t xQueueBuffer;\n\n // ucQueueStorage will hold the items posted to the queue.  Must be at least\n // [(queue length) * ( queue item size)] bytes long.\n uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];\n\n void vATask( void *pvParameters )\n {\n queue_t xQueue1;\n\n\t// Create a queue capable of containing 10 uint32_t values.\n\txQueue1 = queue_create( QUEUE_LENGTH, // The number of items the queue can hold.\n\t\t\t\t\t\t\tITEM_SIZE\t  // The size of each item in the queue\n\t\t\t\t\t\t\t&( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.\n\t\t\t\t\t\t\t&xQueueBuffer ); // The buffer that will hold the queue structure.\n\n\t// The queue is guaranteed to be created successfully as no dynamic memory\n\t// allocation is used.  Therefore xQueue1 is now a handle to a valid queue.\n\n\t// ... Rest of task code.\n }\n </pre>\n * \\defgroup queue_create_static queue_create_static\n * \\ingroup QueueManagement\n */\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\tqueue_t queue_create_static(uint32_t uxQueueLength, uint32_t uxItemSize,\n\t                           uint8_t *pucQueueStorageBuffer, static_queue_s_t *pxQueueBuffer);\n#endif /* configSUPPORT_STATIC_ALLOCATION */\n\n/**\n * queue. h\n * <pre>\n int32_t queue_prepend(\n\t\t\t\t\t\t\t\t   queue_t\txQueue,\n\t\t\t\t\t\t\t\t   const void\t\t*pvItemToQueue,\n\t\t\t\t\t\t\t\t   uint32_t\t\txTicksToWait\n\t\t\t\t\t\t\t   );\n * </pre>\n *\n * Post an item to the front of a queue.  The item is queued by copy, not by\n * reference.  This function must not be called from an interrupt service\n * routine.  See xQueueSendFromISR () for an alternative which may be used\n * in an ISR.\n *\n * @param xQueue The handle to the queue on which the item is to be posted.\n *\n * @param pvItemToQueue A pointer to the item that is to be placed on the\n * queue.  The size of the items the queue will hold was defined when the\n * queue was created, so this many bytes will be copied from pvItemToQueue\n * into the queue storage area.\n *\n * @param xTicksToWait The maximum amount of time the task should block\n * waiting for space to become available on the queue, should it already\n * be full.  The call will return immediately if this is set to 0 and the\n * queue is full.  The time is defined in tick periods so the constant\n * portTICK_PERIOD_MS should be used to convert to real time if this is required.\n *\n * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.\n *\n * Example usage:\n   <pre>\n struct AMessage\n {\n\tchar ucMessageID;\n\tchar ucData[ 20 ];\n } xMessage;\n\n uint32_t ulVar = 10UL;\n\n void vATask( void *pvParameters )\n {\n queue_t xQueue1, xQueue2;\n struct AMessage *pxMessage;\n\n\t// Create a queue capable of containing 10 uint32_t values.\n\txQueue1 = queue_create( 10, sizeof( uint32_t ) );\n\n\t// Create a queue capable of containing 10 pointers to AMessage structures.\n\t// These should be passed by pointer as they contain a lot of data.\n\txQueue2 = queue_create( 10, sizeof( struct AMessage * ) );\n\n\t// ...\n\n\tif( xQueue1 != 0 )\n\t{\n\t\t// Send an uint32_t.  Wait for 10 ticks for space to become\n\t\t// available if necessary.\n\t\tif( queue_prepend( xQueue1, ( void * ) &ulVar, ( uint32_t ) 10 ) != pdPASS )\n\t\t{\n\t\t\t// Failed to post the message, even after 10 ticks.\n\t\t}\n\t}\n\n\tif( xQueue2 != 0 )\n\t{\n\t\t// Send a pointer to a struct AMessage object.  Don't block if the\n\t\t// queue is already full.\n\t\tpxMessage = & xMessage;\n\t\tqueue_prepend( xQueue2, ( void * ) &pxMessage, ( uint32_t ) 0 );\n\t}\n\n\t// ... Rest of task code.\n }\n </pre>\n * \\defgroup xQueueSend xQueueSend\n * \\ingroup QueueManagement\n */\nbool queue_prepend(queue_t queue, const void* item, uint32_t timeout);\n\n/**\n * queue. h\n * <pre>\n int32_t queue_append(\n\t\t\t\t\t\t\t\t   queue_t\txQueue,\n\t\t\t\t\t\t\t\t   const void\t\t*pvItemToQueue,\n\t\t\t\t\t\t\t\t   uint32_t\t\txTicksToWait\n\t\t\t\t\t\t\t   );\n * </pre>\n *\n * This is a macro that calls xQueueGenericSend().\n *\n * Post an item to the back of a queue.  The item is queued by copy, not by\n * reference.  This function must not be called from an interrupt service\n * routine.  See xQueueSendFromISR () for an alternative which may be used\n * in an ISR.\n *\n * @param xQueue The handle to the queue on which the item is to be posted.\n *\n * @param pvItemToQueue A pointer to the item that is to be placed on the\n * queue.  The size of the items the queue will hold was defined when the\n * queue was created, so this many bytes will be copied from pvItemToQueue\n * into the queue storage area.\n *\n * @param xTicksToWait The maximum amount of time the task should block\n * waiting for space to become available on the queue, should it already\n * be full.  The call will return immediately if this is set to 0 and the queue\n * is full.  The  time is defined in tick periods so the constant\n * portTICK_PERIOD_MS should be used to convert to real time if this is required.\n *\n * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.\n *\n * Example usage:\n   <pre>\n struct AMessage\n {\n\tchar ucMessageID;\n\tchar ucData[ 20 ];\n } xMessage;\n\n uint32_t ulVar = 10UL;\n\n void vATask( void *pvParameters )\n {\n queue_t xQueue1, xQueue2;\n struct AMessage *pxMessage;\n\n\t// Create a queue capable of containing 10 uint32_t values.\n\txQueue1 = queue_create( 10, sizeof( uint32_t ) );\n\n\t// Create a queue capable of containing 10 pointers to AMessage structures.\n\t// These should be passed by pointer as they contain a lot of data.\n\txQueue2 = queue_create( 10, sizeof( struct AMessage * ) );\n\n\t// ...\n\n\tif( xQueue1 != 0 )\n\t{\n\t\t// Send an uint32_t.  Wait for 10 ticks for space to become\n\t\t// available if necessary.\n\t\tif( queue_append( xQueue1, ( void * ) &ulVar, ( uint32_t ) 10 ) != pdPASS )\n\t\t{\n\t\t\t// Failed to post the message, even after 10 ticks.\n\t\t}\n\t}\n\n\tif( xQueue2 != 0 )\n\t{\n\t\t// Send a pointer to a struct AMessage object.  Don't block if the\n\t\t// queue is already full.\n\t\tpxMessage = & xMessage;\n\t\tqueue_append( xQueue2, ( void * ) &pxMessage, ( uint32_t ) 0 );\n\t}\n\n\t// ... Rest of task code.\n }\n </pre>\n * \\defgroup xQueueSend xQueueSend\n * \\ingroup QueueManagement\n */\nbool queue_append(queue_t queue, const void* item, uint32_t timeout);\n\n/**\n * queue. h\n * <pre>\n int32_t xQueueSend(\n\t\t\t\t\t\t\t  queue_t xQueue,\n\t\t\t\t\t\t\t  const void * pvItemToQueue,\n\t\t\t\t\t\t\t  uint32_t xTicksToWait\n\t\t\t\t\t\t );\n * </pre>\n *\n * This is a macro that calls xQueueGenericSend().  It is included for\n * backward compatibility with versions of FreeRTOS.org that did not\n * include the queue_prepend() and queue_append() macros.  It is\n * equivalent to queue_append().\n *\n * Post an item on a queue.  The item is queued by copy, not by reference.\n * This function must not be called from an interrupt service routine.\n * See xQueueSendFromISR () for an alternative which may be used in an ISR.\n *\n * @param xQueue The handle to the queue on which the item is to be posted.\n *\n * @param pvItemToQueue A pointer to the item that is to be placed on the\n * queue.  The size of the items the queue will hold was defined when the\n * queue was created, so this many bytes will be copied from pvItemToQueue\n * into the queue storage area.\n *\n * @param xTicksToWait The maximum amount of time the task should block\n * waiting for space to become available on the queue, should it already\n * be full.  The call will return immediately if this is set to 0 and the\n * queue is full.  The time is defined in tick periods so the constant\n * portTICK_PERIOD_MS should be used to convert to real time if this is required.\n *\n * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.\n *\n * Example usage:\n   <pre>\n struct AMessage\n {\n\tchar ucMessageID;\n\tchar ucData[ 20 ];\n } xMessage;\n\n uint32_t ulVar = 10UL;\n\n void vATask( void *pvParameters )\n {\n queue_t xQueue1, xQueue2;\n struct AMessage *pxMessage;\n\n\t// Create a queue capable of containing 10 uint32_t values.\n\txQueue1 = queue_create( 10, sizeof( uint32_t ) );\n\n\t// Create a queue capable of containing 10 pointers to AMessage structures.\n\t// These should be passed by pointer as they contain a lot of data.\n\txQueue2 = queue_create( 10, sizeof( struct AMessage * ) );\n\n\t// ...\n\n\tif( xQueue1 != 0 )\n\t{\n\t\t// Send an uint32_t.  Wait for 10 ticks for space to become\n\t\t// available if necessary.\n\t\tif( xQueueSend( xQueue1, ( void * ) &ulVar, ( uint32_t ) 10 ) != pdPASS )\n\t\t{\n\t\t\t// Failed to post the message, even after 10 ticks.\n\t\t}\n\t}\n\n\tif( xQueue2 != 0 )\n\t{\n\t\t// Send a pointer to a struct AMessage object.  Don't block if the\n\t\t// queue is already full.\n\t\tpxMessage = & xMessage;\n\t\txQueueSend( xQueue2, ( void * ) &pxMessage, ( uint32_t ) 0 );\n\t}\n\n\t// ... Rest of task code.\n }\n </pre>\n * \\defgroup xQueueSend xQueueSend\n * \\ingroup QueueManagement\n */\n#define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )\n\n/**\n * queue. h\n * <pre>\n int32_t queue_overwrite(\n\t\t\t\t\t\t\t  queue_t xQueue,\n\t\t\t\t\t\t\t  const void * pvItemToQueue\n\t\t\t\t\t\t );\n * </pre>\n *\n * Only for use with queues that have a length of one - so the queue is either\n * empty or full.\n *\n * Post an item on a queue.  If the queue is already full then overwrite the\n * value held in the queue.  The item is queued by copy, not by reference.\n *\n * This function must not be called from an interrupt service routine.\n * See xQueueOverwriteFromISR () for an alternative which may be used in an ISR.\n *\n * @param xQueue The handle of the queue to which the data is being sent.\n *\n * @param pvItemToQueue A pointer to the item that is to be placed on the\n * queue.  The size of the items the queue will hold was defined when the\n * queue was created, so this many bytes will be copied from pvItemToQueue\n * into the queue storage area.\n *\n * @return queue_overwrite() is a macro that calls xQueueGenericSend(), and\n * therefore has the same return values as queue_prepend().  However, pdPASS\n * is the only value that can be returned because queue_overwrite() will write\n * to the queue even when the queue is already full.\n *\n * Example usage:\n   <pre>\n\n void vFunction( void *pvParameters )\n {\n queue_t xQueue;\n uint32_t ulVarToSend, ulValReceived;\n\n\t// Create a queue to hold one uint32_t value.  It is strongly\n\t// recommended *not* to use queue_overwrite() on queues that can\n\t// contain more than one value, and doing so will trigger an assertion\n\t// if configASSERT() is defined.\n\txQueue = queue_create( 1, sizeof( uint32_t ) );\n\n\t// Write the value 10 to the queue using queue_overwrite().\n\tulVarToSend = 10;\n\tqueue_overwrite( xQueue, &ulVarToSend );\n\n\t// Peeking the queue should now return 10, but leave the value 10 in\n\t// the queue.  A block time of zero is used as it is known that the\n\t// queue holds a value.\n\tulValReceived = 0;\n\tqueue_peek( xQueue, &ulValReceived, 0 );\n\n\tif( ulValReceived != 10 )\n\t{\n\t\t// Error unless the item was removed by a different task.\n\t}\n\n\t// The queue is still full.  Use queue_overwrite() to overwrite the\n\t// value held in the queue with 100.\n\tulVarToSend = 100;\n\tqueue_overwrite( xQueue, &ulVarToSend );\n\n\t// This time read from the queue, leaving the queue empty once more.\n\t// A block time of 0 is used again.\n\tqueue_recv( xQueue, &ulValReceived, 0 );\n\n\t// The value read should be the last value written, even though the\n\t// queue was already full when the value was written.\n\tif( ulValReceived != 100 )\n\t{\n\t\t// Error!\n\t}\n\n\t// ...\n}\n </pre>\n * \\defgroup queue_overwrite queue_overwrite\n * \\ingroup QueueManagement\n */\n#define queue_overwrite( xQueue, pvItemToQueue ) xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), 0, queueOVERWRITE )\n\n\n/**\n * queue. h\n * <pre>\n int32_t xQueueGenericSend(\n\t\t\t\t\t\t\t\t\tqueue_t xQueue,\n\t\t\t\t\t\t\t\t\tconst void * pvItemToQueue,\n\t\t\t\t\t\t\t\t\tuint32_t xTicksToWait\n\t\t\t\t\t\t\t\t\tint32_t xCopyPosition\n\t\t\t\t\t\t\t\t);\n * </pre>\n *\n * It is preferred that the macros xQueueSend(), queue_prepend() and\n * queue_append() are used in place of calling this function directly.\n *\n * Post an item on a queue.  The item is queued by copy, not by reference.\n * This function must not be called from an interrupt service routine.\n * See xQueueSendFromISR () for an alternative which may be used in an ISR.\n *\n * @param xQueue The handle to the queue on which the item is to be posted.\n *\n * @param pvItemToQueue A pointer to the item that is to be placed on the\n * queue.  The size of the items the queue will hold was defined when the\n * queue was created, so this many bytes will be copied from pvItemToQueue\n * into the queue storage area.\n *\n * @param xTicksToWait The maximum amount of time the task should block\n * waiting for space to become available on the queue, should it already\n * be full.  The call will return immediately if this is set to 0 and the\n * queue is full.  The time is defined in tick periods so the constant\n * portTICK_PERIOD_MS should be used to convert to real time if this is required.\n *\n * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the\n * item at the back of the queue, or queueSEND_TO_FRONT to place the item\n * at the front of the queue (for high priority messages).\n *\n * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.\n *\n * Example usage:\n   <pre>\n struct AMessage\n {\n\tchar ucMessageID;\n\tchar ucData[ 20 ];\n } xMessage;\n\n uint32_t ulVar = 10UL;\n\n void vATask( void *pvParameters )\n {\n queue_t xQueue1, xQueue2;\n struct AMessage *pxMessage;\n\n\t// Create a queue capable of containing 10 uint32_t values.\n\txQueue1 = queue_create( 10, sizeof( uint32_t ) );\n\n\t// Create a queue capable of containing 10 pointers to AMessage structures.\n\t// These should be passed by pointer as they contain a lot of data.\n\txQueue2 = queue_create( 10, sizeof( struct AMessage * ) );\n\n\t// ...\n\n\tif( xQueue1 != 0 )\n\t{\n\t\t// Send an uint32_t.  Wait for 10 ticks for space to become\n\t\t// available if necessary.\n\t\tif( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( uint32_t ) 10, queueSEND_TO_BACK ) != pdPASS )\n\t\t{\n\t\t\t// Failed to post the message, even after 10 ticks.\n\t\t}\n\t}\n\n\tif( xQueue2 != 0 )\n\t{\n\t\t// Send a pointer to a struct AMessage object.  Don't block if the\n\t\t// queue is already full.\n\t\tpxMessage = & xMessage;\n\t\txQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( uint32_t ) 0, queueSEND_TO_BACK );\n\t}\n\n\t// ... Rest of task code.\n }\n </pre>\n * \\defgroup xQueueSend xQueueSend\n * \\ingroup QueueManagement\n */\nint32_t xQueueGenericSend( queue_t xQueue, const void * const pvItemToQueue, uint32_t xTicksToWait, const int32_t xCopyPosition ) ;\n\n/**\n * queue. h\n * <pre>\n int32_t queue_peek(\n\t\t\t\t\t\t\t queue_t xQueue,\n\t\t\t\t\t\t\t void * const pvBuffer,\n\t\t\t\t\t\t\t uint32_t xTicksToWait\n\t\t\t\t\t\t );</pre>\n *\n * Receive an item from a queue without removing the item from the queue.\n * The item is received by copy so a buffer of adequate size must be\n * provided.  The number of bytes copied into the buffer was defined when\n * the queue was created.\n *\n * Successfully received items remain on the queue so will be returned again\n * by the next call, or a call to queue_recv().\n *\n * This macro must not be used in an interrupt service routine.  See\n * xQueuePeekFromISR() for an alternative that can be called from an interrupt\n * service routine.\n *\n * @param xQueue The handle to the queue from which the item is to be\n * received.\n *\n * @param pvBuffer Pointer to the buffer into which the received item will\n * be copied.\n *\n * @param xTicksToWait The maximum amount of time the task should block\n * waiting for an item to receive should the queue be empty at the time\n * of the call.\t The time is defined in tick periods so the constant\n * portTICK_PERIOD_MS should be used to convert to real time if this is required.\n * queue_peek() will return immediately if xTicksToWait is 0 and the queue\n * is empty.\n *\n * @return pdTRUE if an item was successfully received from the queue,\n * otherwise pdFALSE.\n *\n * Example usage:\n   <pre>\n struct AMessage\n {\n\tchar ucMessageID;\n\tchar ucData[ 20 ];\n } xMessage;\n\n queue_t xQueue;\n\n // Task to create a queue and post a value.\n void vATask( void *pvParameters )\n {\n struct AMessage *pxMessage;\n\n\t// Create a queue capable of containing 10 pointers to AMessage structures.\n\t// These should be passed by pointer as they contain a lot of data.\n\txQueue = queue_create( 10, sizeof( struct AMessage * ) );\n\tif( xQueue == 0 )\n\t{\n\t\t// Failed to create the queue.\n\t}\n\n\t// ...\n\n\t// Send a pointer to a struct AMessage object.  Don't block if the\n\t// queue is already full.\n\tpxMessage = & xMessage;\n\txQueueSend( xQueue, ( void * ) &pxMessage, ( uint32_t ) 0 );\n\n\t// ... Rest of task code.\n }\n\n // Task to peek the data from the queue.\n void vADifferentTask( void *pvParameters )\n {\n struct AMessage *pxRxedMessage;\n\n\tif( xQueue != 0 )\n\t{\n\t\t// Peek a message on the created queue.  Block for 10 ticks if a\n\t\t// message is not immediately available.\n\t\tif( queue_peek( xQueue, &( pxRxedMessage ), ( uint32_t ) 10 ) )\n\t\t{\n\t\t\t// pcRxedMessage now points to the struct AMessage variable posted\n\t\t\t// by vATask, but the item still remains on the queue.\n\t\t}\n\t}\n\n\t// ... Rest of task code.\n }\n </pre>\n * \\defgroup queue_peek queue_peek\n * \\ingroup QueueManagement\n */\nint32_t queue_peek( queue_t xQueue, void * const pvBuffer, uint32_t xTicksToWait ) ;\n\n/**\n * queue. h\n * <pre>\n int32_t xQueuePeekFromISR(\n\t\t\t\t\t\t\t\t\tqueue_t xQueue,\n\t\t\t\t\t\t\t\t\tvoid *pvBuffer,\n\t\t\t\t\t\t\t\t);</pre>\n *\n * A version of queue_peek() that can be called from an interrupt service\n * routine (ISR).\n *\n * Receive an item from a queue without removing the item from the queue.\n * The item is received by copy so a buffer of adequate size must be\n * provided.  The number of bytes copied into the buffer was defined when\n * the queue was created.\n *\n * Successfully received items remain on the queue so will be returned again\n * by the next call, or a call to queue_recv().\n *\n * @param xQueue The handle to the queue from which the item is to be\n * received.\n *\n * @param pvBuffer Pointer to the buffer into which the received item will\n * be copied.\n *\n * @return pdTRUE if an item was successfully received from the queue,\n * otherwise pdFALSE.\n *\n * \\defgroup xQueuePeekFromISR xQueuePeekFromISR\n * \\ingroup QueueManagement\n */\nint32_t xQueuePeekFromISR( queue_t xQueue, void * const pvBuffer ) ;\n\n/**\n * queue. h\n * <pre>\n int32_t queue_recv(\n\t\t\t\t\t\t\t\t queue_t xQueue,\n\t\t\t\t\t\t\t\t void *pvBuffer,\n\t\t\t\t\t\t\t\t uint32_t xTicksToWait\n\t\t\t\t\t\t\t);</pre>\n *\n * Receive an item from a queue.  The item is received by copy so a buffer of\n * adequate size must be provided.  The number of bytes copied into the buffer\n * was defined when the queue was created.\n *\n * Successfully received items are removed from the queue.\n *\n * This function must not be used in an interrupt service routine.  See\n * xQueueReceiveFromISR for an alternative that can.\n *\n * @param xQueue The handle to the queue from which the item is to be\n * received.\n *\n * @param pvBuffer Pointer to the buffer into which the received item will\n * be copied.\n *\n * @param xTicksToWait The maximum amount of time the task should block\n * waiting for an item to receive should the queue be empty at the time\n * of the call.\t queue_recv() will return immediately if xTicksToWait\n * is zero and the queue is empty.  The time is defined in tick periods so the\n * constant portTICK_PERIOD_MS should be used to convert to real time if this is\n * required.\n *\n * @return pdTRUE if an item was successfully received from the queue,\n * otherwise pdFALSE.\n *\n * Example usage:\n   <pre>\n struct AMessage\n {\n\tchar ucMessageID;\n\tchar ucData[ 20 ];\n } xMessage;\n\n queue_t xQueue;\n\n // Task to create a queue and post a value.\n void vATask( void *pvParameters )\n {\n struct AMessage *pxMessage;\n\n\t// Create a queue capable of containing 10 pointers to AMessage structures.\n\t// These should be passed by pointer as they contain a lot of data.\n\txQueue = queue_create( 10, sizeof( struct AMessage * ) );\n\tif( xQueue == 0 )\n\t{\n\t\t// Failed to create the queue.\n\t}\n\n\t// ...\n\n\t// Send a pointer to a struct AMessage object.  Don't block if the\n\t// queue is already full.\n\tpxMessage = & xMessage;\n\txQueueSend( xQueue, ( void * ) &pxMessage, ( uint32_t ) 0 );\n\n\t// ... Rest of task code.\n }\n\n // Task to receive from the queue.\n void vADifferentTask( void *pvParameters )\n {\n struct AMessage *pxRxedMessage;\n\n\tif( xQueue != 0 )\n\t{\n\t\t// Receive a message on the created queue.  Block for 10 ticks if a\n\t\t// message is not immediately available.\n\t\tif( queue_recv( xQueue, &( pxRxedMessage ), ( uint32_t ) 10 ) )\n\t\t{\n\t\t\t// pcRxedMessage now points to the struct AMessage variable posted\n\t\t\t// by vATask.\n\t\t}\n\t}\n\n\t// ... Rest of task code.\n }\n </pre>\n * \\defgroup queue_recv queue_recv\n * \\ingroup QueueManagement\n */\nint32_t queue_recv( queue_t xQueue, void * const pvBuffer, uint32_t xTicksToWait ) ;\n\n/**\n * queue. h\n * <pre>uint32_t queue_get_waiting( const queue_t xQueue );</pre>\n *\n * Return the number of messages stored in a queue.\n *\n * @param xQueue A handle to the queue being queried.\n *\n * @return The number of messages available in the queue.\n *\n * \\defgroup queue_get_waiting queue_get_waiting\n * \\ingroup QueueManagement\n */\nuint32_t queue_get_waiting( const queue_t xQueue ) ;\n\n/**\n * queue. h\n * <pre>uint32_t queue_get_available( const queue_t xQueue );</pre>\n *\n * Return the number of free spaces available in a queue.  This is equal to the\n * number of items that can be sent to the queue before the queue becomes full\n * if no items are removed.\n *\n * @param xQueue A handle to the queue being queried.\n *\n * @return The number of spaces available in the queue.\n *\n * \\defgroup queue_get_waiting queue_get_waiting\n * \\ingroup QueueManagement\n */\nuint32_t queue_get_available( const queue_t xQueue ) ;\n\n/**\n * queue. h\n * <pre>void queue_delete( queue_t xQueue );</pre>\n *\n * Delete a queue - freeing all the memory allocated for storing of items\n * placed on the queue.\n *\n * @param xQueue A handle to the queue to be deleted.\n *\n * \\defgroup queue_delete queue_delete\n * \\ingroup QueueManagement\n */\nvoid queue_delete( queue_t xQueue ) ;\n\n/**\n * queue. h\n * <pre>\n int32_t xQueueSendToFrontFromISR(\n\t\t\t\t\t\t\t\t\t\t queue_t xQueue,\n\t\t\t\t\t\t\t\t\t\t const void *pvItemToQueue,\n\t\t\t\t\t\t\t\t\t\t int32_t *pxHigherPriorityTaskWoken\n\t\t\t\t\t\t\t\t\t  );\n </pre>\n *\n * This is a macro that calls xQueueGenericSendFromISR().\n *\n * Post an item to the front of a queue.  It is safe to use this macro from\n * within an interrupt service routine.\n *\n * Items are queued by copy not reference so it is preferable to only\n * queue small items, especially when called from an ISR.  In most cases\n * it would be preferable to store a pointer to the item being queued.\n *\n * @param xQueue The handle to the queue on which the item is to be posted.\n *\n * @param pvItemToQueue A pointer to the item that is to be placed on the\n * queue.  The size of the items the queue will hold was defined when the\n * queue was created, so this many bytes will be copied from pvItemToQueue\n * into the queue storage area.\n *\n * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set\n * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task\n * to unblock, and the unblocked task has a priority higher than the currently\n * running task.  If xQueueSendToFromFromISR() sets this value to pdTRUE then\n * a context switch should be requested before the interrupt is exited.\n *\n * @return pdTRUE if the data was successfully sent to the queue, otherwise\n * errQUEUE_FULL.\n *\n * Example usage for buffered IO (where the ISR can obtain more than one value\n * per call):\n   <pre>\n void vBufferISR( void )\n {\n char cIn;\n int32_t xHigherPrioritTaskWoken;\n\n\t// We have not woken a task at the start of the ISR.\n\txHigherPriorityTaskWoken = pdFALSE;\n\n\t// Loop until the buffer is empty.\n\tdo\n\t{\n\t\t// Obtain a byte from the buffer.\n\t\tcIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );\n\n\t\t// Post the byte.\n\t\txQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );\n\n\t} while( portINPUT_BYTE( BUFFER_COUNT ) );\n\n\t// Now the buffer is empty we can switch context if necessary.\n\tif( xHigherPriorityTaskWoken )\n\t{\n\t\ttaskYIELD ();\n\t}\n }\n </pre>\n *\n * \\defgroup xQueueSendFromISR xQueueSendFromISR\n * \\ingroup QueueManagement\n */\n#define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )\n\n\n/**\n * queue. h\n * <pre>\n int32_t xQueueSendToBackFromISR(\n\t\t\t\t\t\t\t\t\t\t queue_t xQueue,\n\t\t\t\t\t\t\t\t\t\t const void *pvItemToQueue,\n\t\t\t\t\t\t\t\t\t\t int32_t *pxHigherPriorityTaskWoken\n\t\t\t\t\t\t\t\t\t  );\n </pre>\n *\n * This is a macro that calls xQueueGenericSendFromISR().\n *\n * Post an item to the back of a queue.  It is safe to use this macro from\n * within an interrupt service routine.\n *\n * Items are queued by copy not reference so it is preferable to only\n * queue small items, especially when called from an ISR.  In most cases\n * it would be preferable to store a pointer to the item being queued.\n *\n * @param xQueue The handle to the queue on which the item is to be posted.\n *\n * @param pvItemToQueue A pointer to the item that is to be placed on the\n * queue.  The size of the items the queue will hold was defined when the\n * queue was created, so this many bytes will be copied from pvItemToQueue\n * into the queue storage area.\n *\n * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set\n * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task\n * to unblock, and the unblocked task has a priority higher than the currently\n * running task.  If xQueueSendToBackFromISR() sets this value to pdTRUE then\n * a context switch should be requested before the interrupt is exited.\n *\n * @return pdTRUE if the data was successfully sent to the queue, otherwise\n * errQUEUE_FULL.\n *\n * Example usage for buffered IO (where the ISR can obtain more than one value\n * per call):\n   <pre>\n void vBufferISR( void )\n {\n char cIn;\n int32_t xHigherPriorityTaskWoken;\n\n\t// We have not woken a task at the start of the ISR.\n\txHigherPriorityTaskWoken = pdFALSE;\n\n\t// Loop until the buffer is empty.\n\tdo\n\t{\n\t\t// Obtain a byte from the buffer.\n\t\tcIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );\n\n\t\t// Post the byte.\n\t\txQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );\n\n\t} while( portINPUT_BYTE( BUFFER_COUNT ) );\n\n\t// Now the buffer is empty we can switch context if necessary.\n\tif( xHigherPriorityTaskWoken )\n\t{\n\t\ttaskYIELD ();\n\t}\n }\n </pre>\n *\n * \\defgroup xQueueSendFromISR xQueueSendFromISR\n * \\ingroup QueueManagement\n */\n#define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )\n\n/**\n * queue. h\n * <pre>\n int32_t xQueueOverwriteFromISR(\n\t\t\t\t\t\t\t  queue_t xQueue,\n\t\t\t\t\t\t\t  const void * pvItemToQueue,\n\t\t\t\t\t\t\t  int32_t *pxHigherPriorityTaskWoken\n\t\t\t\t\t\t );\n * </pre>\n *\n * A version of queue_overwrite() that can be used in an interrupt service\n * routine (ISR).\n *\n * Only for use with queues that can hold a single item - so the queue is either\n * empty or full.\n *\n * Post an item on a queue.  If the queue is already full then overwrite the\n * value held in the queue.  The item is queued by copy, not by reference.\n *\n * @param xQueue The handle to the queue on which the item is to be posted.\n *\n * @param pvItemToQueue A pointer to the item that is to be placed on the\n * queue.  The size of the items the queue will hold was defined when the\n * queue was created, so this many bytes will be copied from pvItemToQueue\n * into the queue storage area.\n *\n * @param pxHigherPriorityTaskWoken xQueueOverwriteFromISR() will set\n * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task\n * to unblock, and the unblocked task has a priority higher than the currently\n * running task.  If xQueueOverwriteFromISR() sets this value to pdTRUE then\n * a context switch should be requested before the interrupt is exited.\n *\n * @return xQueueOverwriteFromISR() is a macro that calls\n * xQueueGenericSendFromISR(), and therefore has the same return values as\n * xQueueSendToFrontFromISR().  However, pdPASS is the only value that can be\n * returned because xQueueOverwriteFromISR() will write to the queue even when\n * the queue is already full.\n *\n * Example usage:\n   <pre>\n\n queue_t xQueue;\n\n void vFunction( void *pvParameters )\n {\n \t// Create a queue to hold one uint32_t value.  It is strongly\n\t// recommended *not* to use xQueueOverwriteFromISR() on queues that can\n\t// contain more than one value, and doing so will trigger an assertion\n\t// if configASSERT() is defined.\n\txQueue = queue_create( 1, sizeof( uint32_t ) );\n}\n\nvoid vAnInterruptHandler( void )\n{\n// xHigherPriorityTaskWoken must be set to pdFALSE before it is used.\nint32_t xHigherPriorityTaskWoken = pdFALSE;\nuint32_t ulVarToSend, ulValReceived;\n\n\t// Write the value 10 to the queue using xQueueOverwriteFromISR().\n\tulVarToSend = 10;\n\txQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );\n\n\t// The queue is full, but calling xQueueOverwriteFromISR() again will still\n\t// pass because the value held in the queue will be overwritten with the\n\t// new value.\n\tulVarToSend = 100;\n\txQueueOverwriteFromISR( xQueue, &ulVarToSend, &xHigherPriorityTaskWoken );\n\n\t// Reading from the queue will now return 100.\n\n\t// ...\n\n\tif( xHigherPrioritytaskWoken == pdTRUE )\n\t{\n\t\t// Writing to the queue caused a task to unblock and the unblocked task\n\t\t// has a priority higher than or equal to the priority of the currently\n\t\t// executing task (the task this interrupt interrupted).  Perform a context\n\t\t// switch so this interrupt returns directly to the unblocked task.\n\t\tportYIELD_FROM_ISR(); // or portEND_SWITCHING_ISR() depending on the port.\n\t}\n}\n </pre>\n * \\defgroup xQueueOverwriteFromISR xQueueOverwriteFromISR\n * \\ingroup QueueManagement\n */\n#define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueOVERWRITE )\n\n/**\n * queue. h\n * <pre>\n int32_t xQueueSendFromISR(\n\t\t\t\t\t\t\t\t\t queue_t xQueue,\n\t\t\t\t\t\t\t\t\t const void *pvItemToQueue,\n\t\t\t\t\t\t\t\t\t int32_t *pxHigherPriorityTaskWoken\n\t\t\t\t\t\t\t\t);\n </pre>\n *\n * This is a macro that calls xQueueGenericSendFromISR().  It is included\n * for backward compatibility with versions of FreeRTOS.org that did not\n * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()\n * macros.\n *\n * Post an item to the back of a queue.  It is safe to use this function from\n * within an interrupt service routine.\n *\n * Items are queued by copy not reference so it is preferable to only\n * queue small items, especially when called from an ISR.  In most cases\n * it would be preferable to store a pointer to the item being queued.\n *\n * @param xQueue The handle to the queue on which the item is to be posted.\n *\n * @param pvItemToQueue A pointer to the item that is to be placed on the\n * queue.  The size of the items the queue will hold was defined when the\n * queue was created, so this many bytes will be copied from pvItemToQueue\n * into the queue storage area.\n *\n * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set\n * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task\n * to unblock, and the unblocked task has a priority higher than the currently\n * running task.  If xQueueSendFromISR() sets this value to pdTRUE then\n * a context switch should be requested before the interrupt is exited.\n *\n * @return pdTRUE if the data was successfully sent to the queue, otherwise\n * errQUEUE_FULL.\n *\n * Example usage for buffered IO (where the ISR can obtain more than one value\n * per call):\n   <pre>\n void vBufferISR( void )\n {\n char cIn;\n int32_t xHigherPriorityTaskWoken;\n\n\t// We have not woken a task at the start of the ISR.\n\txHigherPriorityTaskWoken = pdFALSE;\n\n\t// Loop until the buffer is empty.\n\tdo\n\t{\n\t\t// Obtain a byte from the buffer.\n\t\tcIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );\n\n\t\t// Post the byte.\n\t\txQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );\n\n\t} while( portINPUT_BYTE( BUFFER_COUNT ) );\n\n\t// Now the buffer is empty we can switch context if necessary.\n\tif( xHigherPriorityTaskWoken )\n\t{\n\t\t// Actual macro used here is port specific.\n\t\tportYIELD_FROM_ISR ();\n\t}\n }\n </pre>\n *\n * \\defgroup xQueueSendFromISR xQueueSendFromISR\n * \\ingroup QueueManagement\n */\n#define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )\n\n/**\n * queue. h\n * <pre>\n int32_t xQueueGenericSendFromISR(\n\t\t\t\t\t\t\t\t\t\t   queue_t\t\txQueue,\n\t\t\t\t\t\t\t\t\t\t   const\tvoid\t*pvItemToQueue,\n\t\t\t\t\t\t\t\t\t\t   int32_t\t*pxHigherPriorityTaskWoken,\n\t\t\t\t\t\t\t\t\t\t   int32_t\txCopyPosition\n\t\t\t\t\t\t\t\t\t   );\n </pre>\n *\n * It is preferred that the macros xQueueSendFromISR(),\n * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place\n * of calling this function directly.  xQueueGiveFromISR() is an\n * equivalent for use by semaphores that don't actually copy any data.\n *\n * Post an item on a queue.  It is safe to use this function from within an\n * interrupt service routine.\n *\n * Items are queued by copy not reference so it is preferable to only\n * queue small items, especially when called from an ISR.  In most cases\n * it would be preferable to store a pointer to the item being queued.\n *\n * @param xQueue The handle to the queue on which the item is to be posted.\n *\n * @param pvItemToQueue A pointer to the item that is to be placed on the\n * queue.  The size of the items the queue will hold was defined when the\n * queue was created, so this many bytes will be copied from pvItemToQueue\n * into the queue storage area.\n *\n * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set\n * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task\n * to unblock, and the unblocked task has a priority higher than the currently\n * running task.  If xQueueGenericSendFromISR() sets this value to pdTRUE then\n * a context switch should be requested before the interrupt is exited.\n *\n * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the\n * item at the back of the queue, or queueSEND_TO_FRONT to place the item\n * at the front of the queue (for high priority messages).\n *\n * @return pdTRUE if the data was successfully sent to the queue, otherwise\n * errQUEUE_FULL.\n *\n * Example usage for buffered IO (where the ISR can obtain more than one value\n * per call):\n   <pre>\n void vBufferISR( void )\n {\n char cIn;\n int32_t xHigherPriorityTaskWokenByPost;\n\n\t// We have not woken a task at the start of the ISR.\n\txHigherPriorityTaskWokenByPost = pdFALSE;\n\n\t// Loop until the buffer is empty.\n\tdo\n\t{\n\t\t// Obtain a byte from the buffer.\n\t\tcIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );\n\n\t\t// Post each byte.\n\t\txQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );\n\n\t} while( portINPUT_BYTE( BUFFER_COUNT ) );\n\n\t// Now the buffer is empty we can switch context if necessary.  Note that the\n\t// name of the yield function required is port specific.\n\tif( xHigherPriorityTaskWokenByPost )\n\t{\n\t\ttaskYIELD_YIELD_FROM_ISR();\n\t}\n }\n </pre>\n *\n * \\defgroup xQueueSendFromISR xQueueSendFromISR\n * \\ingroup QueueManagement\n */\nint32_t xQueueGenericSendFromISR( queue_t xQueue, const void * const pvItemToQueue, int32_t * const pxHigherPriorityTaskWoken, const int32_t xCopyPosition ) ;\nint32_t xQueueGiveFromISR( queue_t xQueue, int32_t * const pxHigherPriorityTaskWoken ) ;\n\n/**\n * queue. h\n * <pre>\n int32_t xQueueReceiveFromISR(\n\t\t\t\t\t\t\t\t\t   queue_t\txQueue,\n\t\t\t\t\t\t\t\t\t   void\t*pvBuffer,\n\t\t\t\t\t\t\t\t\t   int32_t *pxTaskWoken\n\t\t\t\t\t\t\t\t   );\n * </pre>\n *\n * Receive an item from a queue.  It is safe to use this function from within an\n * interrupt service routine.\n *\n * @param xQueue The handle to the queue from which the item is to be\n * received.\n *\n * @param pvBuffer Pointer to the buffer into which the received item will\n * be copied.\n *\n * @param pxTaskWoken A task may be blocked waiting for space to become\n * available on the queue.  If xQueueReceiveFromISR causes such a task to\n * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will\n * remain unchanged.\n *\n * @return pdTRUE if an item was successfully received from the queue,\n * otherwise pdFALSE.\n *\n * Example usage:\n   <pre>\n\n queue_t xQueue;\n\n // Function to create a queue and post some values.\n void vAFunction( void *pvParameters )\n {\n char cValueToPost;\n const uint32_t xTicksToWait = ( uint32_t )0xff;\n\n\t// Create a queue capable of containing 10 characters.\n\txQueue = queue_create( 10, sizeof( char ) );\n\tif( xQueue == 0 )\n\t{\n\t\t// Failed to create the queue.\n\t}\n\n\t// ...\n\n\t// Post some characters that will be used within an ISR.  If the queue\n\t// is full then this task will block for xTicksToWait ticks.\n\tcValueToPost = 'a';\n\txQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );\n\tcValueToPost = 'b';\n\txQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );\n\n\t// ... keep posting characters ... this task may block when the queue\n\t// becomes full.\n\n\tcValueToPost = 'c';\n\txQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );\n }\n\n // ISR that outputs all the characters received on the queue.\n void vISR_Routine( void )\n {\n int32_t xTaskWokenByReceive = pdFALSE;\n char cRxedChar;\n\n\twhile( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )\n\t{\n\t\t// A character was received.  Output the character now.\n\t\tvOutputCharacter( cRxedChar );\n\n\t\t// If removing the character from the queue woke the task that was\n\t\t// posting onto the queue cTaskWokenByReceive will have been set to\n\t\t// pdTRUE.  No matter how many times this loop iterates only one\n\t\t// task will be woken.\n\t}\n\n\tif( cTaskWokenByPost != ( char ) pdFALSE;\n\t{\n\t\ttaskYIELD ();\n\t}\n }\n </pre>\n * \\defgroup xQueueReceiveFromISR xQueueReceiveFromISR\n * \\ingroup QueueManagement\n */\nint32_t xQueueReceiveFromISR( queue_t xQueue, void * const pvBuffer, int32_t * const pxHigherPriorityTaskWoken ) ;\n\n/*\n * Utilities to query queues that are safe to use from an ISR.  These utilities\n * should be used only from witin an ISR, or within a critical section.\n */\nint32_t xQueueIsQueueEmptyFromISR( const queue_t xQueue ) ;\nint32_t xQueueIsQueueFullFromISR( const queue_t xQueue ) ;\nuint32_t uxQueueMessagesWaitingFromISR( const queue_t xQueue ) ;\n\n/*\n * The functions defined above are for passing data to and from tasks.  The\n * functions below are the equivalents for passing data to and from\n * co-routines.\n *\n * These functions are called from the co-routine macro implementation and\n * should not be called directly from application code.  Instead use the macro\n * wrappers defined within croutine.h.\n */\nint32_t xQueueCRSendFromISR( queue_t xQueue, const void *pvItemToQueue, int32_t xCoRoutinePreviouslyWoken );\nint32_t xQueueCRReceiveFromISR( queue_t xQueue, void *pvBuffer, int32_t *pxTaskWoken );\nint32_t xQueueCRSend( queue_t xQueue, const void *pvItemToQueue, uint32_t xTicksToWait );\nint32_t xQueueCRReceive( queue_t xQueue, void *pvBuffer, uint32_t xTicksToWait );\n\n/*\n * For internal use only.  Use mutex_create(),\n * sem_create() or mutex_get_owner() instead of calling\n * these functions directly.\n */\nqueue_t xQueueCreateMutex( const uint8_t ucQueueType ) ;\nqueue_t xQueueCreateMutexStatic( const uint8_t ucQueueType, static_queue_s_t *pxStaticQueue ) ;\nqueue_t xQueueCreateCountingSemaphore( const uint32_t uxMaxCount, const uint32_t uxInitialCount ) ;\nqueue_t xQueueCreateCountingSemaphoreStatic( const uint32_t uxMaxCount, const uint32_t uxInitialCount, static_queue_s_t *pxStaticQueue ) ;\nint32_t xQueueSemaphoreTake( queue_t xQueue, uint32_t xTicksToWait ) ;\nvoid* xQueueGetMutexHolder( queue_t xSemaphore ) ;\nvoid* xQueueGetMutexHolderFromISR( queue_t xSemaphore ) ;\n\n/*\n * For internal use only.  Use xSemaphoreTakeMutexRecursive() or\n * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.\n */\nint32_t xQueueTakeMutexRecursive( queue_t xMutex, uint32_t xTicksToWait ) ;\nint32_t xQueueGiveMutexRecursive( queue_t pxMutex ) ;\n\n/*\n * Reset a queue back to its original empty state.  The return value is now\n * obsolete and is always set to pdPASS.\n */\nvoid queue_reset(queue_t queue);\n\n/*\n * The registry is provided as a means for kernel aware debuggers to\n * locate queues, semaphores and mutexes.  Call vQueueAddToRegistry() add\n * a queue, semaphore or mutex handle to the registry if you want the handle\n * to be available to a kernel aware debugger.  If you are not using a kernel\n * aware debugger then this function can be ignored.\n *\n * configQUEUE_REGISTRY_SIZE defines the maximum number of handles the\n * registry can hold.  configQUEUE_REGISTRY_SIZE must be greater than 0\n * within FreeRTOSConfig.h for the registry to be available.  Its value\n * does not effect the number of queues, semaphores and mutexes that can be\n * created - just the number that the registry can hold.\n *\n * @param xQueue The handle of the queue being added to the registry.  This\n * is the handle returned by a call to queue_create().  Semaphore and mutex\n * handles can also be passed in here.\n *\n * @param pcName The name to be associated with the handle.  This is the\n * name that the kernel aware debugger will display.  The queue registry only\n * stores a pointer to the string - so the string must be persistent (global or\n * preferably in ROM/Flash), not on the stack.\n */\n#if( configQUEUE_REGISTRY_SIZE > 0 )\n\tvoid vQueueAddToRegistry( queue_t xQueue, const char *pcName ) ; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n#endif\n\n/*\n * The registry is provided as a means for kernel aware debuggers to\n * locate queues, semaphores and mutexes.  Call vQueueAddToRegistry() add\n * a queue, semaphore or mutex handle to the registry if you want the handle\n * to be available to a kernel aware debugger, and vQueueUnregisterQueue() to\n * remove the queue, semaphore or mutex from the register.  If you are not using\n * a kernel aware debugger then this function can be ignored.\n *\n * @param xQueue The handle of the queue being removed from the registry.\n */\n#if( configQUEUE_REGISTRY_SIZE > 0 )\n\tvoid vQueueUnregisterQueue( queue_t xQueue ) ;\n#endif\n\n/*\n * The queue registry is provided as a means for kernel aware debuggers to\n * locate queues, semaphores and mutexes.  Call pcQueueGetName() to look\n * up and return the name of a queue in the queue registry from the queue's\n * handle.\n *\n * @param xQueue The handle of the queue the name of which will be returned.\n * @return If the queue is in the registry then a pointer to the name of the\n * queue is returned.  If the queue is not in the registry then NULL is\n * returned.\n */\n#if( configQUEUE_REGISTRY_SIZE > 0 )\n\tconst char *pcQueueGetName( queue_t xQueue ) ; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n#endif\n\n/*\n * Generic version of the function used to creaet a queue using dynamic memory\n * allocation.  This is called by other functions and macros that create other\n * RTOS objects that use the queue structure as their base.\n */\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\tqueue_t xQueueGenericCreate( const uint32_t uxQueueLength, const uint32_t uxItemSize, const uint8_t ucQueueType ) ;\n#endif\n\n/*\n * Generic version of the function used to creaet a queue using dynamic memory\n * allocation.  This is called by other functions and macros that create other\n * RTOS objects that use the queue structure as their base.\n */\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\tqueue_t xQueueGenericCreateStatic( const uint32_t uxQueueLength, const uint32_t uxItemSize, uint8_t *pucQueueStorage, static_queue_s_t *pxStaticQueue, const uint8_t ucQueueType ) ;\n#endif\n\n/*\n * Queue sets provide a mechanism to allow a task to block (pend) on a read\n * operation from multiple queues or semaphores simultaneously.\n *\n * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this\n * function.\n *\n * A queue set must be explicitly created using a call to xQueueCreateSet()\n * before it can be used.  Once created, standard FreeRTOS queues and semaphores\n * can be added to the set using calls to xQueueAddToSet().\n * xQueueSelectFromSet() is then used to determine which, if any, of the queues\n * or semaphores contained in the set is in a state where a queue read or\n * semaphore take operation would be successful.\n *\n * Note 1:  See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html\n * for reasons why queue sets are very rarely needed in practice as there are\n * simpler methods of blocking on multiple objects.\n *\n * Note 2:  Blocking on a queue set that contains a mutex will not cause the\n * mutex holder to inherit the priority of the blocked task.\n *\n * Note 3:  An additional 4 bytes of RAM is required for each space in a every\n * queue added to a queue set.  Therefore counting semaphores that have a high\n * maximum count value should not be added to a queue set.\n *\n * Note 4:  A receive (in the case of a queue) or take (in the case of a\n * semaphore) operation must not be performed on a member of a queue set unless\n * a call to xQueueSelectFromSet() has first returned a handle to that set member.\n *\n * @param uxEventQueueLength Queue sets store events that occur on\n * the queues and semaphores contained in the set.  uxEventQueueLength specifies\n * the maximum number of events that can be queued at once.  To be absolutely\n * certain that events are not lost uxEventQueueLength should be set to the\n * total sum of the length of the queues added to the set, where binary\n * semaphores and mutexes have a length of 1, and counting semaphores have a\n * length set by their maximum count value.  Examples:\n *  + If a queue set is to hold a queue of length 5, another queue of length 12,\n *    and a binary semaphore, then uxEventQueueLength should be set to\n *    (5 + 12 + 1), or 18.\n *  + If a queue set is to hold three binary semaphores then uxEventQueueLength\n *    should be set to (1 + 1 + 1 ), or 3.\n *  + If a queue set is to hold a counting semaphore that has a maximum count of\n *    5, and a counting semaphore that has a maximum count of 3, then\n *    uxEventQueueLength should be set to (5 + 3), or 8.\n *\n * @return If the queue set is created successfully then a handle to the created\n * queue set is returned.  Otherwise NULL is returned.\n */\nQueueSetHandle_t xQueueCreateSet( const uint32_t uxEventQueueLength ) ;\n\n/*\n * Adds a queue or semaphore to a queue set that was previously created by a\n * call to xQueueCreateSet().\n *\n * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this\n * function.\n *\n * Note 1:  A receive (in the case of a queue) or take (in the case of a\n * semaphore) operation must not be performed on a member of a queue set unless\n * a call to xQueueSelectFromSet() has first returned a handle to that set member.\n *\n * @param xQueueOrSemaphore The handle of the queue or semaphore being added to\n * the queue set (cast to an QueueSetMemberHandle_t type).\n *\n * @param xQueueSet The handle of the queue set to which the queue or semaphore\n * is being added.\n *\n * @return If the queue or semaphore was successfully added to the queue set\n * then pdPASS is returned.  If the queue could not be successfully added to the\n * queue set because it is already a member of a different queue set then pdFAIL\n * is returned.\n */\nint32_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) ;\n\n/*\n * Removes a queue or semaphore from a queue set.  A queue or semaphore can only\n * be removed from a set if the queue or semaphore is empty.\n *\n * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this\n * function.\n *\n * @param xQueueOrSemaphore The handle of the queue or semaphore being removed\n * from the queue set (cast to an QueueSetMemberHandle_t type).\n *\n * @param xQueueSet The handle of the queue set in which the queue or semaphore\n * is included.\n *\n * @return If the queue or semaphore was successfully removed from the queue set\n * then pdPASS is returned.  If the queue was not in the queue set, or the\n * queue (or semaphore) was not empty, then pdFAIL is returned.\n */\nint32_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) ;\n\n/*\n * xQueueSelectFromSet() selects from the members of a queue set a queue or\n * semaphore that either contains data (in the case of a queue) or is available\n * to take (in the case of a semaphore).  xQueueSelectFromSet() effectively\n * allows a task to block (pend) on a read operation on all the queues and\n * semaphores in a queue set simultaneously.\n *\n * See FreeRTOS/Source/Demo/Common/Minimal/QueueSet.c for an example using this\n * function.\n *\n * Note 1:  See the documentation on http://wwwFreeRTOS.org/RTOS-queue-sets.html\n * for reasons why queue sets are very rarely needed in practice as there are\n * simpler methods of blocking on multiple objects.\n *\n * Note 2:  Blocking on a queue set that contains a mutex will not cause the\n * mutex holder to inherit the priority of the blocked task.\n *\n * Note 3:  A receive (in the case of a queue) or take (in the case of a\n * semaphore) operation must not be performed on a member of a queue set unless\n * a call to xQueueSelectFromSet() has first returned a handle to that set member.\n *\n * @param xQueueSet The queue set on which the task will (potentially) block.\n *\n * @param xTicksToWait The maximum time, in ticks, that the calling task will\n * remain in the Blocked state (with other tasks executing) to wait for a member\n * of the queue set to be ready for a successful queue read or semaphore take\n * operation.\n *\n * @return xQueueSelectFromSet() will return the handle of a queue (cast to\n * a QueueSetMemberHandle_t type) contained in the queue set that contains data,\n * or the handle of a semaphore (cast to a QueueSetMemberHandle_t type) contained\n * in the queue set that is available, or NULL if no such queue or semaphore\n * exists before before the specified block time expires.\n */\nQueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const uint32_t xTicksToWait ) ;\n\n/*\n * A version of xQueueSelectFromSet() that can be used from an ISR.\n */\nQueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet ) ;\n\n/* Not public API functions. */\nvoid vQueueWaitForMessageRestricted( queue_t xQueue, uint32_t xTicksToWait, const int32_t xWaitIndefinitely ) ;\nint32_t xQueueGenericReset( queue_t xQueue, int32_t xNewQueue ) ;\nvoid vQueueSetQueueNumber( queue_t xQueue, uint32_t uxQueueNumber ) ;\nuint32_t uxQueueGetQueueNumber( queue_t xQueue ) ;\nuint8_t ucQueueGetQueueType( queue_t xQueue ) ;\n\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* QUEUE_H */\n"
  },
  {
    "path": "include/rtos/semphr.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n#ifndef SEMAPHORE_H\n#define SEMAPHORE_H\n\n#ifndef INC_FREERTOS_H\n\t#error \"include FreeRTOS.h\" must appear in source files before \"include semphr.h\"\n#endif\n\n#include \"queue.h\"\n#include \"task.h\"\n\ntypedef queue_t sem_t;\ntypedef queue_t mutex_t;\n\n#define semBINARY_SEMAPHORE_QUEUE_LENGTH\t( ( uint8_t ) 1U )\n#define semSEMAPHORE_QUEUE_ITEM_LENGTH\t\t( ( uint8_t ) 0U )\n#define semGIVE_BLOCK_TIME\t\t\t\t\t( ( uint32_t ) 0U )\n\n\n/**\n * semphr. h\n * <pre>vSemaphoreCreateBinary( sem_t xSemaphore )</pre>\n *\n * In many usage scenarios it is faster and more memory efficient to use a\n * direct to task notification in place of a binary semaphore!\n * http://www.freertos.org/RTOS-task-notifications.html\n *\n * This old vSemaphoreCreateBinary() macro is now deprecated in favour of the\n * sem_binary_create() function.  Note that binary semaphores created using\n * the vSemaphoreCreateBinary() macro are created in a state such that the\n * first call to 'take' the semaphore would pass, whereas binary semaphores\n * created using sem_binary_create() are created in a state such that the\n * the semaphore must first be 'given' before it can be 'taken'.\n *\n * <i>Macro</i> that implements a semaphore by using the existing queue mechanism.\n * The queue length is 1 as this is a binary semaphore.  The data size is 0\n * as we don't want to actually store any data - we just want to know if the\n * queue is empty or full.\n *\n * This type of semaphore can be used for pure synchronisation between tasks or\n * between an interrupt and a task.  The semaphore need not be given back once\n * obtained, so one task/interrupt can continuously 'give' the semaphore while\n * another continuously 'takes' the semaphore.  For this reason this type of\n * semaphore does not use a priority inheritance mechanism.  For an alternative\n * that does use priority inheritance see mutex_create().\n *\n * @param xSemaphore Handle to the created semaphore.  Should be of type sem_t.\n *\n * Example usage:\n <pre>\n sem_t xSemaphore = NULL;\n\n void vATask( void * pvParameters )\n {\n    // Semaphore cannot be used before a call to vSemaphoreCreateBinary ().\n    // This is a macro so pass the variable in directly.\n    vSemaphoreCreateBinary( xSemaphore );\n\n    if( xSemaphore != NULL )\n    {\n        // The semaphore was created successfully.\n        // The semaphore can now be used.\n    }\n }\n </pre>\n * \\defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary\n * \\ingroup Semaphores\n */\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\t#define vSemaphoreCreateBinary( xSemaphore )\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t( xSemaphore ) = xQueueGenericCreate( ( uint32_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE );\t\\\n\t\t\tif( ( xSemaphore ) != NULL )\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t( void ) sem_post( ( xSemaphore ) );\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t}\n#endif\n\n/**\n * semphr. h\n * <pre>sem_t sem_binary_create( void )</pre>\n *\n * Creates a new binary semaphore instance, and returns a handle by which the\n * new semaphore can be referenced.\n *\n * In many usage scenarios it is faster and more memory efficient to use a\n * direct to task notification in place of a binary semaphore!\n * http://www.freertos.org/RTOS-task-notifications.html\n *\n * Internally, within the FreeRTOS implementation, binary semaphores use a block\n * of memory, in which the semaphore structure is stored.  If a binary semaphore\n * is created using sem_binary_create() then the required memory is\n * automatically dynamically allocated inside the sem_binary_create()\n * function.  (see http://www.freertos.org/a00111.html).  If a binary semaphore\n * is created using xSemaphoreCreateBinaryStatic() then the application writer\n * must provide the memory.  xSemaphoreCreateBinaryStatic() therefore allows a\n * binary semaphore to be created without using any dynamic memory allocation.\n *\n * The old vSemaphoreCreateBinary() macro is now deprecated in favour of this\n * sem_binary_create() function.  Note that binary semaphores created using\n * the vSemaphoreCreateBinary() macro are created in a state such that the\n * first call to 'take' the semaphore would pass, whereas binary semaphores\n * created using sem_binary_create() are created in a state such that the\n * the semaphore must first be 'given' before it can be 'taken'.\n *\n * This type of semaphore can be used for pure synchronisation between tasks or\n * between an interrupt and a task.  The semaphore need not be given back once\n * obtained, so one task/interrupt can continuously 'give' the semaphore while\n * another continuously 'takes' the semaphore.  For this reason this type of\n * semaphore does not use a priority inheritance mechanism.  For an alternative\n * that does use priority inheritance see mutex_create().\n *\n * @return Handle to the created semaphore, or NULL if the memory required to\n * hold the semaphore's data structures could not be allocated.\n *\n * Example usage:\n <pre>\n sem_t xSemaphore = NULL;\n\n void vATask( void * pvParameters )\n {\n    // Semaphore cannot be used before a call to sem_binary_create().\n    // This is a macro so pass the variable in directly.\n    xSemaphore = sem_binary_create();\n\n    if( xSemaphore != NULL )\n    {\n        // The semaphore was created successfully.\n        // The semaphore can now be used.\n    }\n }\n </pre>\n * \\defgroup sem_binary_create sem_binary_create\n * \\ingroup Semaphores\n */\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\tsem_t sem_binary_create();\n#endif\n\n/**\n * semphr. h\n * <pre>sem_t xSemaphoreCreateBinaryStatic( static_sem_s_t *pxSemaphoreBuffer )</pre>\n *\n * Creates a new binary semaphore instance, and returns a handle by which the\n * new semaphore can be referenced.\n *\n * NOTE: In many usage scenarios it is faster and more memory efficient to use a\n * direct to task notification in place of a binary semaphore!\n * http://www.freertos.org/RTOS-task-notifications.html\n *\n * Internally, within the FreeRTOS implementation, binary semaphores use a block\n * of memory, in which the semaphore structure is stored.  If a binary semaphore\n * is created using sem_binary_create() then the required memory is\n * automatically dynamically allocated inside the sem_binary_create()\n * function.  (see http://www.freertos.org/a00111.html).  If a binary semaphore\n * is created using xSemaphoreCreateBinaryStatic() then the application writer\n * must provide the memory.  xSemaphoreCreateBinaryStatic() therefore allows a\n * binary semaphore to be created without using any dynamic memory allocation.\n *\n * This type of semaphore can be used for pure synchronisation between tasks or\n * between an interrupt and a task.  The semaphore need not be given back once\n * obtained, so one task/interrupt can continuously 'give' the semaphore while\n * another continuously 'takes' the semaphore.  For this reason this type of\n * semaphore does not use a priority inheritance mechanism.  For an alternative\n * that does use priority inheritance see mutex_create().\n *\n * @param pxSemaphoreBuffer Must point to a variable of type static_sem_s_t,\n * which will then be used to hold the semaphore's data structure, removing the\n * need for the memory to be allocated dynamically.\n *\n * @return If the semaphore is created then a handle to the created semaphore is\n * returned.  If pxSemaphoreBuffer is NULL then NULL is returned.\n *\n * Example usage:\n <pre>\n sem_t xSemaphore = NULL;\n static_sem_s_t xSemaphoreBuffer;\n\n void vATask( void * pvParameters )\n {\n    // Semaphore cannot be used before a call to sem_binary_create().\n    // The semaphore's data structures will be placed in the xSemaphoreBuffer\n    // variable, the address of which is passed into the function.  The\n    // function's parameter is not NULL, so the function will not attempt any\n    // dynamic memory allocation, and therefore the function will not return\n    // return NULL.\n    xSemaphore = sem_binary_create( &xSemaphoreBuffer );\n\n    // Rest of task code goes here.\n }\n </pre>\n * \\defgroup xSemaphoreCreateBinaryStatic xSemaphoreCreateBinaryStatic\n * \\ingroup Semaphores\n */\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\t#define xSemaphoreCreateBinaryStatic( pxStaticSemaphore ) xQueueGenericCreateStatic( ( uint32_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticSemaphore, queueQUEUE_TYPE_BINARY_SEMAPHORE )\n#endif /* configSUPPORT_STATIC_ALLOCATION */\n\n/**\n * semphr. h\n * <pre>sem_wait(\n *                   sem_t xSemaphore,\n *                   uint32_t xBlockTime\n *               )</pre>\n *\n * <i>Macro</i> to obtain a semaphore.  The semaphore must have previously been\n * created with a call to sem_binary_create(), mutex_create() or\n * sem_create().\n *\n * @param xSemaphore A handle to the semaphore being taken - obtained when\n * the semaphore was created.\n *\n * @param xBlockTime The time in ticks to wait for the semaphore to become\n * available.  The macro portTICK_PERIOD_MS can be used to convert this to a\n * real time.  A block time of zero can be used to poll the semaphore.  A block\n * time of portMAX_DELAY can be used to block indefinitely (provided\n * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h).\n *\n * @return pdTRUE if the semaphore was obtained.  pdFALSE\n * if xBlockTime expired without the semaphore becoming available.\n *\n * Example usage:\n <pre>\n sem_t xSemaphore = NULL;\n\n // A task that creates a semaphore.\n void vATask( void * pvParameters )\n {\n    // Create the semaphore to guard a shared resource.\n    xSemaphore = sem_binary_create();\n }\n\n // A task that uses the semaphore.\n void vAnotherTask( void * pvParameters )\n {\n    // ... Do other things.\n\n    if( xSemaphore != NULL )\n    {\n        // See if we can obtain the semaphore.  If the semaphore is not available\n        // wait 10 ticks to see if it becomes free.\n        if( sem_wait( xSemaphore, ( uint32_t ) 10 ) == pdTRUE )\n        {\n            // We were able to obtain the semaphore and can now access the\n            // shared resource.\n\n            // ...\n\n            // We have finished accessing the shared resource.  Release the\n            // semaphore.\n            sem_post( xSemaphore );\n        }\n        else\n        {\n            // We could not obtain the semaphore and can therefore not access\n            // the shared resource safely.\n        }\n    }\n }\n </pre>\n * \\defgroup sem_wait sem_wait\n * \\ingroup Semaphores\n */\nuint8_t sem_wait(sem_t sem, uint32_t block_time);\n\n/**\n * semphr. h\n * mutex_recursive_take(\n *                          sem_t xMutex,\n *                          uint32_t xBlockTime\n *                        )\n *\n * <i>Macro</i> to recursively obtain, or 'take', a mutex type semaphore.\n * The mutex must have previously been created using a call to\n * mutex_recursive_create();\n *\n * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this\n * macro to be available.\n *\n * This macro must not be used on mutexes created using mutex_create().\n *\n * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex\n * doesn't become available again until the owner has called\n * mutex_recursive_give() for each successful 'take' request.  For example,\n * if a task successfully 'takes' the same mutex 5 times then the mutex will\n * not be available to any other task until it has also  'given' the mutex back\n * exactly five times.\n *\n * @param xMutex A handle to the mutex being obtained.  This is the\n * handle returned by mutex_recursive_create();\n *\n * @param xBlockTime The time in ticks to wait for the semaphore to become\n * available.  The macro portTICK_PERIOD_MS can be used to convert this to a\n * real time.  A block time of zero can be used to poll the semaphore.  If\n * the task already owns the semaphore then mutex_recursive_take() will\n * return immediately no matter what the value of xBlockTime.\n *\n * @return pdTRUE if the semaphore was obtained.  pdFALSE if xBlockTime\n * expired without the semaphore becoming available.\n *\n * Example usage:\n <pre>\n sem_t xMutex = NULL;\n\n // A task that creates a mutex.\n void vATask( void * pvParameters )\n {\n    // Create the mutex to guard a shared resource.\n    xMutex = mutex_recursive_create();\n }\n\n // A task that uses the mutex.\n void vAnotherTask( void * pvParameters )\n {\n    // ... Do other things.\n\n    if( xMutex != NULL )\n    {\n        // See if we can obtain the mutex.  If the mutex is not available\n        // wait 10 ticks to see if it becomes free.\n        if( mutex_recursive_take( xSemaphore, ( uint32_t ) 10 ) == pdTRUE )\n        {\n            // We were able to obtain the mutex and can now access the\n            // shared resource.\n\n            // ...\n            // For some reason due to the nature of the code further calls to\n            // mutex_recursive_take() are made on the same mutex.  In real\n            // code these would not be just sequential calls as this would make\n            // no sense.  Instead the calls are likely to be buried inside\n            // a more complex call structure.\n            mutex_recursive_take( xMutex, ( uint32_t ) 10 );\n            mutex_recursive_take( xMutex, ( uint32_t ) 10 );\n\n            // The mutex has now been 'taken' three times, so will not be\n            // available to another task until it has also been given back\n            // three times.  Again it is unlikely that real code would have\n            // these calls sequentially, but instead buried in a more complex\n            // call structure.  This is just for illustrative purposes.\n            mutex_recursive_give( xMutex );\n            mutex_recursive_give( xMutex );\n            mutex_recursive_give( xMutex );\n\n            // Now the mutex can be taken by other tasks.\n        }\n        else\n        {\n            // We could not obtain the mutex and can therefore not access\n            // the shared resource safely.\n        }\n    }\n }\n </pre>\n * \\defgroup mutex_recursive_take mutex_recursive_take\n * \\ingroup Semaphores\n */\n#if( configUSE_RECURSIVE_MUTEXES == 1 )\n\tuint8_t mutex_recursive_take(mutex_t mutex, uint32_t block_time);\n#endif\n\n/**\n * semphr. h\n * <pre>sem_post( sem_t xSemaphore )</pre>\n *\n * <i>Macro</i> to release a semaphore.  The semaphore must have previously been\n * created with a call to sem_binary_create(), mutex_create() or\n * sem_create(). and obtained using sSemaphoreTake().\n *\n * This macro must not be used from an ISR.  See xSemaphoreGiveFromISR () for\n * an alternative which can be used from an ISR.\n *\n * This macro must also not be used on semaphores created using\n * mutex_recursive_create().\n *\n * @param xSemaphore A handle to the semaphore being released.  This is the\n * handle returned when the semaphore was created.\n *\n * @return pdTRUE if the semaphore was released.  pdFALSE if an error occurred.\n * Semaphores are implemented using queues.  An error can occur if there is\n * no space on the queue to post a message - indicating that the\n * semaphore was not first obtained correctly.\n *\n * Example usage:\n <pre>\n sem_t xSemaphore = NULL;\n\n void vATask( void * pvParameters )\n {\n    // Create the semaphore to guard a shared resource.\n    xSemaphore = vSemaphoreCreateBinary();\n\n    if( xSemaphore != NULL )\n    {\n        if( sem_post( xSemaphore ) != pdTRUE )\n        {\n            // We would expect this call to fail because we cannot give\n            // a semaphore without first \"taking\" it!\n        }\n\n        // Obtain the semaphore - don't block if the semaphore is not\n        // immediately available.\n        if( sem_wait( xSemaphore, ( uint32_t ) 0 ) )\n        {\n            // We now have the semaphore and can access the shared resource.\n\n            // ...\n\n            // We have finished accessing the shared resource so can free the\n            // semaphore.\n            if( sem_post( xSemaphore ) != pdTRUE )\n            {\n                // We would not expect this call to fail because we must have\n                // obtained the semaphore to get here.\n            }\n        }\n    }\n }\n </pre>\n * \\defgroup sem_post sem_post\n * \\ingroup Semaphores\n */\nuint8_t sem_post(sem_t sem);\n\n/**\n * semphr. h\n * <pre>mutex_recursive_give( sem_t xMutex )</pre>\n *\n * <i>Macro</i> to recursively release, or 'give', a mutex type semaphore.\n * The mutex must have previously been created using a call to\n * mutex_recursive_create();\n *\n * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this\n * macro to be available.\n *\n * This macro must not be used on mutexes created using mutex_create().\n *\n * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex\n * doesn't become available again until the owner has called\n * mutex_recursive_give() for each successful 'take' request.  For example,\n * if a task successfully 'takes' the same mutex 5 times then the mutex will\n * not be available to any other task until it has also  'given' the mutex back\n * exactly five times.\n *\n * @param xMutex A handle to the mutex being released, or 'given'.  This is the\n * handle returned by mutex_create();\n *\n * @return pdTRUE if the semaphore was given.\n *\n * Example usage:\n <pre>\n sem_t xMutex = NULL;\n\n // A task that creates a mutex.\n void vATask( void * pvParameters )\n {\n    // Create the mutex to guard a shared resource.\n    xMutex = mutex_recursive_create();\n }\n\n // A task that uses the mutex.\n void vAnotherTask( void * pvParameters )\n {\n    // ... Do other things.\n\n    if( xMutex != NULL )\n    {\n        // See if we can obtain the mutex.  If the mutex is not available\n        // wait 10 ticks to see if it becomes free.\n        if( mutex_recursive_take( xMutex, ( uint32_t ) 10 ) == pdTRUE )\n        {\n            // We were able to obtain the mutex and can now access the\n            // shared resource.\n\n            // ...\n            // For some reason due to the nature of the code further calls to\n\t\t\t// mutex_recursive_take() are made on the same mutex.  In real\n\t\t\t// code these would not be just sequential calls as this would make\n\t\t\t// no sense.  Instead the calls are likely to be buried inside\n\t\t\t// a more complex call structure.\n            mutex_recursive_take( xMutex, ( uint32_t ) 10 );\n            mutex_recursive_take( xMutex, ( uint32_t ) 10 );\n\n            // The mutex has now been 'taken' three times, so will not be\n\t\t\t// available to another task until it has also been given back\n\t\t\t// three times.  Again it is unlikely that real code would have\n\t\t\t// these calls sequentially, it would be more likely that the calls\n\t\t\t// to mutex_recursive_give() would be called as a call stack\n\t\t\t// unwound.  This is just for demonstrative purposes.\n            mutex_recursive_give( xMutex );\n\t\t\tmutex_recursive_give( xMutex );\n\t\t\tmutex_recursive_give( xMutex );\n\n\t\t\t// Now the mutex can be taken by other tasks.\n        }\n        else\n        {\n            // We could not obtain the mutex and can therefore not access\n            // the shared resource safely.\n        }\n    }\n }\n </pre>\n * \\defgroup mutex_recursive_give mutex_recursive_give\n * \\ingroup Semaphores\n */\n#if( configUSE_RECURSIVE_MUTEXES == 1 )\n\tuint8_t mutex_recursive_give(mutex_t mutex);\n#endif\n\n/**\n * semphr. h\n * <pre>\n xSemaphoreGiveFromISR(\n                          sem_t xSemaphore,\n                          int32_t *pxHigherPriorityTaskWoken\n                      )</pre>\n *\n * <i>Macro</i> to  release a semaphore.  The semaphore must have previously been\n * created with a call to sem_binary_create() or sem_create().\n *\n * Mutex type semaphores (those created using a call to mutex_create())\n * must not be used with this macro.\n *\n * This macro can be used from an ISR.\n *\n * @param xSemaphore A handle to the semaphore being released.  This is the\n * handle returned when the semaphore was created.\n *\n * @param pxHigherPriorityTaskWoken xSemaphoreGiveFromISR() will set\n * *pxHigherPriorityTaskWoken to pdTRUE if giving the semaphore caused a task\n * to unblock, and the unblocked task has a priority higher than the currently\n * running task.  If xSemaphoreGiveFromISR() sets this value to pdTRUE then\n * a context switch should be requested before the interrupt is exited.\n *\n * @return pdTRUE if the semaphore was successfully given, otherwise errQUEUE_FULL.\n *\n * Example usage:\n <pre>\n \\#define LONG_TIME 0xffff\n \\#define TICKS_TO_WAIT\t10\n sem_t xSemaphore = NULL;\n\n // Repetitive task.\n void vATask( void * pvParameters )\n {\n    for( ;; )\n    {\n        // We want this task to run every 10 ticks of a timer.  The semaphore\n        // was created before this task was started.\n\n        // Block waiting for the semaphore to become available.\n        if( sem_wait( xSemaphore, LONG_TIME ) == pdTRUE )\n        {\n            // It is time to execute.\n\n            // ...\n\n            // We have finished our task.  Return to the top of the loop where\n            // we will block on the semaphore until it is time to execute\n            // again.  Note when using the semaphore for synchronisation with an\n\t\t\t// ISR in this manner there is no need to 'give' the semaphore back.\n        }\n    }\n }\n\n // Timer ISR\n void vTimerISR( void * pvParameters )\n {\n static uint8_t ucLocalTickCount = 0;\n static int32_t xHigherPriorityTaskWoken;\n\n    // A timer tick has occurred.\n\n    // ... Do other time functions.\n\n    // Is it time for vATask () to run?\n\txHigherPriorityTaskWoken = pdFALSE;\n    ucLocalTickCount++;\n    if( ucLocalTickCount >= TICKS_TO_WAIT )\n    {\n        // Unblock the task by releasing the semaphore.\n        xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );\n\n        // Reset the count so we release the semaphore again in 10 ticks time.\n        ucLocalTickCount = 0;\n    }\n\n    if( xHigherPriorityTaskWoken != pdFALSE )\n    {\n        // We can force a context switch here.  Context switching from an\n        // ISR uses port specific syntax.  Check the demo task for your port\n        // to find the syntax required.\n    }\n }\n </pre>\n * \\defgroup xSemaphoreGiveFromISR xSemaphoreGiveFromISR\n * \\ingroup Semaphores\n */\n#define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken )\txQueueGiveFromISR( ( queue_t ) ( xSemaphore ), ( pxHigherPriorityTaskWoken ) )\n\n/**\n * semphr. h\n * <pre>\n xSemaphoreTakeFromISR(\n                          sem_t xSemaphore,\n                          int32_t *pxHigherPriorityTaskWoken\n                      )</pre>\n *\n * <i>Macro</i> to  take a semaphore from an ISR.  The semaphore must have\n * previously been created with a call to sem_binary_create() or\n * sem_create().\n *\n * Mutex type semaphores (those created using a call to mutex_create())\n * must not be used with this macro.\n *\n * This macro can be used from an ISR, however taking a semaphore from an ISR\n * is not a common operation.  It is likely to only be useful when taking a\n * counting semaphore when an interrupt is obtaining an object from a resource\n * pool (when the semaphore count indicates the number of resources available).\n *\n * @param xSemaphore A handle to the semaphore being taken.  This is the\n * handle returned when the semaphore was created.\n *\n * @param pxHigherPriorityTaskWoken xSemaphoreTakeFromISR() will set\n * *pxHigherPriorityTaskWoken to pdTRUE if taking the semaphore caused a task\n * to unblock, and the unblocked task has a priority higher than the currently\n * running task.  If xSemaphoreTakeFromISR() sets this value to pdTRUE then\n * a context switch should be requested before the interrupt is exited.\n *\n * @return pdTRUE if the semaphore was successfully taken, otherwise\n * pdFALSE\n */\n#define xSemaphoreTakeFromISR( xSemaphore, pxHigherPriorityTaskWoken )\txQueueReceiveFromISR( ( queue_t ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ) )\n\n/**\n * semphr. h\n * <pre>sem_t mutex_create( void )</pre>\n *\n * Creates a new mutex type semaphore instance, and returns a handle by which\n * the new mutex can be referenced.\n *\n * Internally, within the FreeRTOS implementation, mutex semaphores use a block\n * of memory, in which the mutex structure is stored.  If a mutex is created\n * using mutex_create() then the required memory is automatically\n * dynamically allocated inside the mutex_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a mutex is created using\n * mutex_create_static() then the application writer must provided the\n * memory.  mutex_create_static() therefore allows a mutex to be created\n * without using any dynamic memory allocation.\n *\n * Mutexes created using this function can be accessed using the sem_wait()\n * and sem_post() macros.  The mutex_recursive_take() and\n * mutex_recursive_give() macros must not be used.\n *\n * This type of semaphore uses a priority inheritance mechanism so a task\n * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the\n * semaphore it is no longer required.\n *\n * Mutex type semaphores cannot be used from within interrupt service routines.\n *\n * See sem_binary_create() for an alternative implementation that can be\n * used for pure synchronisation (where one task or interrupt always 'gives' the\n * semaphore and another always 'takes' the semaphore) and from within interrupt\n * service routines.\n *\n * @return If the mutex was successfully created then a handle to the created\n * semaphore is returned.  If there was not enough heap to allocate the mutex\n * data structures then NULL is returned.\n *\n * Example usage:\n <pre>\n sem_t xSemaphore;\n\n void vATask( void * pvParameters )\n {\n    // Semaphore cannot be used before a call to mutex_create().\n    // This is a macro so pass the variable in directly.\n    xSemaphore = mutex_create();\n\n    if( xSemaphore != NULL )\n    {\n        // The semaphore was created successfully.\n        // The semaphore can now be used.\n    }\n }\n </pre>\n * \\defgroup mutex_create mutex_create\n * \\ingroup Semaphores\n */\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\tmutex_t mutex_create();\n#endif\n\n/**\n * semphr. h\n * <pre>sem_t mutex_create_static( static_sem_s_t *pxMutexBuffer )</pre>\n *\n * Creates a new mutex type semaphore instance, and returns a handle by which\n * the new mutex can be referenced.\n *\n * Internally, within the FreeRTOS implementation, mutex semaphores use a block\n * of memory, in which the mutex structure is stored.  If a mutex is created\n * using mutex_create() then the required memory is automatically\n * dynamically allocated inside the mutex_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a mutex is created using\n * mutex_create_static() then the application writer must provided the\n * memory.  mutex_create_static() therefore allows a mutex to be created\n * without using any dynamic memory allocation.\n *\n * Mutexes created using this function can be accessed using the sem_wait()\n * and sem_post() macros.  The mutex_recursive_take() and\n * mutex_recursive_give() macros must not be used.\n *\n * This type of semaphore uses a priority inheritance mechanism so a task\n * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the\n * semaphore it is no longer required.\n *\n * Mutex type semaphores cannot be used from within interrupt service routines.\n *\n * See sem_binary_create() for an alternative implementation that can be\n * used for pure synchronisation (where one task or interrupt always 'gives' the\n * semaphore and another always 'takes' the semaphore) and from within interrupt\n * service routines.\n *\n * @param pxMutexBuffer Must point to a variable of type static_sem_s_t,\n * which will be used to hold the mutex's data structure, removing the need for\n * the memory to be allocated dynamically.\n *\n * @return If the mutex was successfully created then a handle to the created\n * mutex is returned.  If pxMutexBuffer was NULL then NULL is returned.\n *\n * Example usage:\n <pre>\n sem_t xSemaphore;\n static_sem_s_t xMutexBuffer;\n\n void vATask( void * pvParameters )\n {\n    // A mutex cannot be used before it has been created.  xMutexBuffer is\n    // into mutex_create_static() so no dynamic memory allocation is\n    // attempted.\n    xSemaphore = mutex_create_static( &xMutexBuffer );\n\n    // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,\n    // so there is no need to check it.\n }\n </pre>\n * \\defgroup mutex_create_static mutex_create_static\n * \\ingroup Semaphores\n */\n #if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\tmutex_t mutex_create_static(static_sem_s_t* pxMutexBuffer);\n#endif /* configSUPPORT_STATIC_ALLOCATION */\n\n\n/**\n * semphr. h\n * <pre>sem_t mutex_recursive_create( void )</pre>\n *\n * Creates a new recursive mutex type semaphore instance, and returns a handle\n * by which the new recursive mutex can be referenced.\n *\n * Internally, within the FreeRTOS implementation, recursive mutexs use a block\n * of memory, in which the mutex structure is stored.  If a recursive mutex is\n * created using mutex_recursive_create() then the required memory is\n * automatically dynamically allocated inside the\n * mutex_recursive_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a recursive mutex is created using\n * xSemaphoreCreateRecursiveMutexStatic() then the application writer must\n * provide the memory that will get used by the mutex.\n * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to\n * be created without using any dynamic memory allocation.\n *\n * Mutexes created using this macro can be accessed using the\n * mutex_recursive_take() and mutex_recursive_give() macros.  The\n * sem_wait() and sem_post() macros must not be used.\n *\n * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex\n * doesn't become available again until the owner has called\n * mutex_recursive_give() for each successful 'take' request.  For example,\n * if a task successfully 'takes' the same mutex 5 times then the mutex will\n * not be available to any other task until it has also  'given' the mutex back\n * exactly five times.\n *\n * This type of semaphore uses a priority inheritance mechanism so a task\n * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the\n * semaphore it is no longer required.\n *\n * Mutex type semaphores cannot be used from within interrupt service routines.\n *\n * See sem_binary_create() for an alternative implementation that can be\n * used for pure synchronisation (where one task or interrupt always 'gives' the\n * semaphore and another always 'takes' the semaphore) and from within interrupt\n * service routines.\n *\n * @return xSemaphore Handle to the created mutex semaphore.  Should be of type\n * sem_t.\n *\n * Example usage:\n <pre>\n sem_t xSemaphore;\n\n void vATask( void * pvParameters )\n {\n    // Semaphore cannot be used before a call to mutex_create().\n    // This is a macro so pass the variable in directly.\n    xSemaphore = mutex_recursive_create();\n\n    if( xSemaphore != NULL )\n    {\n        // The semaphore was created successfully.\n        // The semaphore can now be used.\n    }\n }\n </pre>\n * \\defgroup mutex_recursive_create mutex_recursive_create\n * \\ingroup Semaphores\n */\n#if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) )\n\tmutex_t mutex_recursive_create();\n#endif\n\n/**\n * semphr. h\n * <pre>sem_t xSemaphoreCreateRecursiveMutexStatic( static_sem_s_t *pxMutexBuffer )</pre>\n *\n * Creates a new recursive mutex type semaphore instance, and returns a handle\n * by which the new recursive mutex can be referenced.\n *\n * Internally, within the FreeRTOS implementation, recursive mutexs use a block\n * of memory, in which the mutex structure is stored.  If a recursive mutex is\n * created using mutex_recursive_create() then the required memory is\n * automatically dynamically allocated inside the\n * mutex_recursive_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a recursive mutex is created using\n * xSemaphoreCreateRecursiveMutexStatic() then the application writer must\n * provide the memory that will get used by the mutex.\n * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to\n * be created without using any dynamic memory allocation.\n *\n * Mutexes created using this macro can be accessed using the\n * mutex_recursive_take() and mutex_recursive_give() macros.  The\n * sem_wait() and sem_post() macros must not be used.\n *\n * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex\n * doesn't become available again until the owner has called\n * mutex_recursive_give() for each successful 'take' request.  For example,\n * if a task successfully 'takes' the same mutex 5 times then the mutex will\n * not be available to any other task until it has also  'given' the mutex back\n * exactly five times.\n *\n * This type of semaphore uses a priority inheritance mechanism so a task\n * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the\n * semaphore it is no longer required.\n *\n * Mutex type semaphores cannot be used from within interrupt service routines.\n *\n * See sem_binary_create() for an alternative implementation that can be\n * used for pure synchronisation (where one task or interrupt always 'gives' the\n * semaphore and another always 'takes' the semaphore) and from within interrupt\n * service routines.\n *\n * @param pxMutexBuffer Must point to a variable of type static_sem_s_t,\n * which will then be used to hold the recursive mutex's data structure,\n * removing the need for the memory to be allocated dynamically.\n *\n * @return If the recursive mutex was successfully created then a handle to the\n * created recursive mutex is returned.  If pxMutexBuffer was NULL then NULL is\n * returned.\n *\n * Example usage:\n <pre>\n sem_t xSemaphore;\n static_sem_s_t xMutexBuffer;\n\n void vATask( void * pvParameters )\n {\n    // A recursive semaphore cannot be used before it is created.  Here a\n    // recursive mutex is created using xSemaphoreCreateRecursiveMutexStatic().\n    // The address of xMutexBuffer is passed into the function, and will hold\n    // the mutexes data structures - so no dynamic memory allocation will be\n    // attempted.\n    xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xMutexBuffer );\n\n    // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,\n    // so there is no need to check it.\n }\n </pre>\n * \\defgroup xSemaphoreCreateRecursiveMutexStatic xSemaphoreCreateRecursiveMutexStatic\n * \\ingroup Semaphores\n */\n#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) )\n\t#define xSemaphoreCreateRecursiveMutexStatic( pxStaticSemaphore ) xQueueCreateMutexStatic( queueQUEUE_TYPE_RECURSIVE_MUTEX, pxStaticSemaphore )\n#endif /* configSUPPORT_STATIC_ALLOCATION */\n\n/**\n * semphr. h\n * <pre>sem_t sem_create( uint32_t uxMaxCount, uint32_t uxInitialCount )</pre>\n *\n * Creates a new counting semaphore instance, and returns a handle by which the\n * new counting semaphore can be referenced.\n *\n * In many usage scenarios it is faster and more memory efficient to use a\n * direct to task notification in place of a counting semaphore!\n * http://www.freertos.org/RTOS-task-notifications.html\n *\n * Internally, within the FreeRTOS implementation, counting semaphores use a\n * block of memory, in which the counting semaphore structure is stored.  If a\n * counting semaphore is created using sem_create() then the\n * required memory is automatically dynamically allocated inside the\n * sem_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a counting semaphore is created\n * using sem_create_static() then the application writer can\n * instead optionally provide the memory that will get used by the counting\n * semaphore.  sem_create_static() therefore allows a counting\n * semaphore to be created without using any dynamic memory allocation.\n *\n * Counting semaphores are typically used for two things:\n *\n * 1) Counting events.\n *\n *    In this usage scenario an event handler will 'give' a semaphore each time\n *    an event occurs (incrementing the semaphore count value), and a handler\n *    task will 'take' a semaphore each time it processes an event\n *    (decrementing the semaphore count value).  The count value is therefore\n *    the difference between the number of events that have occurred and the\n *    number that have been processed.  In this case it is desirable for the\n *    initial count value to be zero.\n *\n * 2) Resource management.\n *\n *    In this usage scenario the count value indicates the number of resources\n *    available.  To obtain control of a resource a task must first obtain a\n *    semaphore - decrementing the semaphore count value.  When the count value\n *    reaches zero there are no free resources.  When a task finishes with the\n *    resource it 'gives' the semaphore back - incrementing the semaphore count\n *    value.  In this case it is desirable for the initial count value to be\n *    equal to the maximum count value, indicating that all resources are free.\n *\n * @param uxMaxCount The maximum count value that can be reached.  When the\n *        semaphore reaches this value it can no longer be 'given'.\n *\n * @param uxInitialCount The count value assigned to the semaphore when it is\n *        created.\n *\n * @return Handle to the created semaphore.  Null if the semaphore could not be\n *         created.\n *\n * Example usage:\n <pre>\n sem_t xSemaphore;\n\n void vATask( void * pvParameters )\n {\n sem_t xSemaphore = NULL;\n\n    // Semaphore cannot be used before a call to sem_create().\n    // The max value to which the semaphore can count should be 10, and the\n    // initial value assigned to the count should be 0.\n    xSemaphore = sem_create( 10, 0 );\n\n    if( xSemaphore != NULL )\n    {\n        // The semaphore was created successfully.\n        // The semaphore can now be used.\n    }\n }\n </pre>\n * \\defgroup sem_create sem_create\n * \\ingroup Semaphores\n */\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\tsem_t sem_create(uint32_t uxMaxCount, uint32_t uxInitialCount);\n#endif\n\n/**\n * semphr. h\n * <pre>sem_t sem_create_static( uint32_t uxMaxCount, uint32_t uxInitialCount, static_sem_s_t *pxSemaphoreBuffer )</pre>\n *\n * Creates a new counting semaphore instance, and returns a handle by which the\n * new counting semaphore can be referenced.\n *\n * In many usage scenarios it is faster and more memory efficient to use a\n * direct to task notification in place of a counting semaphore!\n * http://www.freertos.org/RTOS-task-notifications.html\n *\n * Internally, within the FreeRTOS implementation, counting semaphores use a\n * block of memory, in which the counting semaphore structure is stored.  If a\n * counting semaphore is created using sem_create() then the\n * required memory is automatically dynamically allocated inside the\n * sem_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a counting semaphore is created\n * using sem_create_static() then the application writer must\n * provide the memory.  sem_create_static() therefore allows a\n * counting semaphore to be created without using any dynamic memory allocation.\n *\n * Counting semaphores are typically used for two things:\n *\n * 1) Counting events.\n *\n *    In this usage scenario an event handler will 'give' a semaphore each time\n *    an event occurs (incrementing the semaphore count value), and a handler\n *    task will 'take' a semaphore each time it processes an event\n *    (decrementing the semaphore count value).  The count value is therefore\n *    the difference between the number of events that have occurred and the\n *    number that have been processed.  In this case it is desirable for the\n *    initial count value to be zero.\n *\n * 2) Resource management.\n *\n *    In this usage scenario the count value indicates the number of resources\n *    available.  To obtain control of a resource a task must first obtain a\n *    semaphore - decrementing the semaphore count value.  When the count value\n *    reaches zero there are no free resources.  When a task finishes with the\n *    resource it 'gives' the semaphore back - incrementing the semaphore count\n *    value.  In this case it is desirable for the initial count value to be\n *    equal to the maximum count value, indicating that all resources are free.\n *\n * @param uxMaxCount The maximum count value that can be reached.  When the\n *        semaphore reaches this value it can no longer be 'given'.\n *\n * @param uxInitialCount The count value assigned to the semaphore when it is\n *        created.\n *\n * @param pxSemaphoreBuffer Must point to a variable of type static_sem_s_t,\n * which will then be used to hold the semaphore's data structure, removing the\n * need for the memory to be allocated dynamically.\n *\n * @return If the counting semaphore was successfully created then a handle to\n * the created counting semaphore is returned.  If pxSemaphoreBuffer was NULL\n * then NULL is returned.\n *\n * Example usage:\n <pre>\n sem_t xSemaphore;\n static_sem_s_t xSemaphoreBuffer;\n\n void vATask( void * pvParameters )\n {\n sem_t xSemaphore = NULL;\n\n    // Counting semaphore cannot be used before they have been created.  Create\n    // a counting semaphore using sem_create_static().  The max\n    // value to which the semaphore can count is 10, and the initial value\n    // assigned to the count will be 0.  The address of xSemaphoreBuffer is\n    // passed in and will be used to hold the semaphore structure, so no dynamic\n    // memory allocation will be used.\n    xSemaphore = sem_create( 10, 0, &xSemaphoreBuffer );\n\n    // No memory allocation was attempted so xSemaphore cannot be NULL, so there\n    // is no need to check its value.\n }\n </pre>\n * \\defgroup sem_create_static sem_create_static\n * \\ingroup Semaphores\n */\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\tsem_t sem_create_static(uint32_t uxMaxCount, uint32_t uxInitialCount, static_sem_s_t* pxSemaphoreBuffer);\n#endif /* configSUPPORT_STATIC_ALLOCATION */\n\n/**\n * semphr. h\n * <pre>void sem_delete( sem_t xSemaphore );</pre>\n *\n * Delete a semaphore.  This function must be used with care.  For example,\n * do not delete a mutex type semaphore if the mutex is held by a task.\n *\n * @param xSemaphore A handle to the semaphore to be deleted.\n *\n * \\defgroup sem_delete sem_delete\n * \\ingroup Semaphores\n */\nvoid sem_delete(sem_t xSemaphore);\n\n/**\n * semphr.h\n * <pre>task_t mutex_get_owner( sem_t xMutex );</pre>\n *\n * If xMutex is indeed a mutex type semaphore, return the current mutex holder.\n * If xMutex is not a mutex type semaphore, or the mutex is available (not held\n * by a task), return NULL.\n *\n * Note: This is a good way of determining if the calling task is the mutex\n * holder, but not a good way of determining the identity of the mutex holder as\n * the holder may change between the function exiting and the returned value\n * being tested.\n */\ntask_t mutex_get_owner(sem_t xMutex);\n\n/**\n * semphr.h\n * <pre>task_t xSemaphoreGetMutexHolderFromISR( sem_t xMutex );</pre>\n *\n * If xMutex is indeed a mutex type semaphore, return the current mutex holder.\n * If xMutex is not a mutex type semaphore, or the mutex is available (not held\n * by a task), return NULL.\n *\n */\n#define xSemaphoreGetMutexHolderFromISR( xSemaphore ) xQueueGetMutexHolderFromISR( ( xSemaphore ) )\n\n/**\n * semphr.h\n * <pre>uint32_t sem_get_count( sem_t xSemaphore );</pre>\n *\n * If the semaphore is a counting semaphore then sem_get_count() returns\n * its current count value.  If the semaphore is a binary semaphore then\n * sem_get_count() returns 1 if the semaphore is available, and 0 if the\n * semaphore is not available.\n *\n */\nuint32_t sem_get_count(sem_t xSemaphore);\n\n#endif /* SEMAPHORE_H */\n\n\n"
  },
  {
    "path": "include/rtos/stack_macros.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n#ifndef STACK_MACROS_H\n#define STACK_MACROS_H\n\n/*\n * Call the stack overflow hook function if the stack of the task being swapped\n * out is currently overflowed, or looks like it might have overflowed in the\n * past.\n *\n * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check\n * the current stack state only - comparing the current top of stack value to\n * the stack limit.  Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1\n * will also cause the last few stack bytes to be checked to ensure the value\n * to which the bytes were set when the task was created have not been\n * overwritten.  Note this second test does not guarantee that an overflowed\n * stack will always be recognised.\n */\n\n/*-----------------------------------------------------------*/\n\n#if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) )\n\n\t/* Only the current stack state is to be checked. */\n\t#define taskCHECK_FOR_STACK_OVERFLOW()\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t/* Is the currently saved stack pointer within the stack limit? */\t\t\t\t\t\t\t\t\\\n\t\tif( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack )\t\t\t\t\t\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tvApplicationStackOverflowHook( ( task_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t}\n\n#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\n/*-----------------------------------------------------------*/\n\n#if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) )\n\n\t/* Only the current stack state is to be checked. */\n\t#define taskCHECK_FOR_STACK_OVERFLOW()\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t/* Is the currently saved stack pointer within the stack limit? */\t\t\t\t\t\t\t\t\\\n\t\tif( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack )\t\t\t\t\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tvApplicationStackOverflowHook( ( task_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t}\n\n#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\n/*-----------------------------------------------------------*/\n\n#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )\n\n\t#define taskCHECK_FOR_STACK_OVERFLOW()\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tconst uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack;\t\t\t\t\t\t\t\\\n\t\tconst uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5;\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tif( ( pulStack[ 0 ] != ulCheckValue ) ||\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t( pulStack[ 1 ] != ulCheckValue ) ||\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t( pulStack[ 2 ] != ulCheckValue ) ||\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t( pulStack[ 3 ] != ulCheckValue ) )\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tvApplicationStackOverflowHook( ( task_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t}\n\n#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\n/*-----------------------------------------------------------*/\n\n#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )\n\n\t#define taskCHECK_FOR_STACK_OVERFLOW()\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tint8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tstatic const uint8_t ucExpectedStackBytes[] = {\ttskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\ttskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\ttskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\ttskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\ttskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE };\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tpcEndOfStack -= sizeof( ucExpectedStackBytes );\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t/* Has the extremity of the task stack ever been written over? */\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tif( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tvApplicationStackOverflowHook( ( task_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );\t\t\t\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t}\n\n#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\n/*-----------------------------------------------------------*/\n\n/* Remove stack overflow macro if not being used. */\n#ifndef taskCHECK_FOR_STACK_OVERFLOW\n\t#define taskCHECK_FOR_STACK_OVERFLOW()\n#endif\n\n\n\n#endif /* STACK_MACROS_H */\n\n"
  },
  {
    "path": "include/rtos/stream_buffer.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n/*\n * Stream buffers are used to send a continuous stream of data from one task or\n * interrupt to another.  Their implementation is light weight, making them\n * particularly suited for interrupt to task and core to core communication\n * scenarios.\n *\n * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer\n * implementation (so also the message buffer implementation, as message buffers\n * are built on top of stream buffers) assumes there is only one task or\n * interrupt that will write to the buffer (the writer), and only one task or\n * interrupt that will read from the buffer (the reader).  It is safe for the\n * writer and reader to be different tasks or interrupts, but, unlike other\n * FreeRTOS objects, it is not safe to have multiple different writers or\n * multiple different readers.  If there are to be multiple different writers\n * then the application writer must place each call to a writing API function\n * (such as stream_buf_send()) inside a critical section and set the send\n * block time to 0.  Likewise, if there are to be multiple different readers\n * then the application writer must place each call to a reading API function\n * (such as xStreamBufferRead()) inside a critical section section and set the\n * receive block time to 0.\n *\n */\n\n#ifndef STREAM_BUFFER_H\n#define STREAM_BUFFER_H\n\n#if defined( __cplusplus )\nextern \"C\" {\n#endif\n\n/**\n * Type by which stream buffers are referenced.  For example, a call to\n * stream_buf_create() returns an stream_buf_t variable that can\n * then be used as a parameter to stream_buf_send(), stream_buf_recv(),\n * etc.\n */\ntypedef void * stream_buf_t;\n\n\n/**\n * message_buffer.h\n *\n<pre>\nstream_buf_t stream_buf_create( size_t xBufferSizeBytes, size_t xTriggerLevelBytes );\n</pre>\n *\n * Creates a new stream buffer using dynamically allocated memory.  See\n * stream_buf_create_static() for a version that uses statically allocated\n * memory (memory that is allocated at compile time).\n *\n * configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in\n * FreeRTOSConfig.h for stream_buf_create() to be available.\n *\n * @param xBufferSizeBytes The total number of bytes the stream buffer will be\n * able to hold at any one time.\n *\n * @param xTriggerLevelBytes The number of bytes that must be in the stream\n * buffer before a task that is blocked on the stream buffer to wait for data is\n * moved out of the blocked state.  For example, if a task is blocked on a read\n * of an empty stream buffer that has a trigger level of 1 then the task will be\n * unblocked when a single byte is written to the buffer or the task's block\n * time expires.  As another example, if a task is blocked on a read of an empty\n * stream buffer that has a trigger level of 10 then the task will not be\n * unblocked until the stream buffer contains at least 10 bytes or the task's\n * block time expires.  If a reading task's block time expires before the\n * trigger level is reached then the task will still receive however many bytes\n * are actually available.  Setting a trigger level of 0 will result in a\n * trigger level of 1 being used.  It is not valid to specify a trigger level\n * that is greater than the buffer size.\n *\n * @return If NULL is returned, then the stream buffer cannot be created\n * because there is insufficient heap memory available for FreeRTOS to allocate\n * the stream buffer data structures and storage area.  A non-NULL value being\n * returned indicates that the stream buffer has been created successfully -\n * the returned value should be stored as the handle to the created stream\n * buffer.\n *\n * Example use:\n<pre>\n\nvoid vAFunction( void )\n{\nstream_buf_t xStreamBuffer;\nconst size_t xStreamBufferSizeBytes = 100, xTriggerLevel = 10;\n\n    // Create a stream buffer that can hold 100 bytes.  The memory used to hold\n    // both the stream buffer structure and the data in the stream buffer is\n    // allocated dynamically.\n    xStreamBuffer = stream_buf_create( xStreamBufferSizeBytes, xTriggerLevel );\n\n    if( xStreamBuffer == NULL )\n    {\n        // There was not enough heap memory space available to create the\n        // stream buffer.\n    }\n    else\n    {\n        // The stream buffer was created successfully and can now be used.\n    }\n}\n</pre>\n * \\defgroup stream_buf_create stream_buf_create\n * \\ingroup StreamBufferManagement\n */\n#define stream_buf_create( xBufferSizeBytes, xTriggerLevelBytes ) xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE )\n\n/**\n * stream_buffer.h\n *\n<pre>\nstream_buf_t stream_buf_create_static( size_t xBufferSizeBytes,\n                                                size_t xTriggerLevelBytes,\n                                                uint8_t *pucStreamBufferStorageArea,\n                                                static_stream_buf_s_t *pxStaticStreamBuffer );\n</pre>\n * Creates a new stream buffer using statically allocated memory.  See\n * stream_buf_create() for a version that uses dynamically allocated memory.\n *\n * configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h for\n * stream_buf_create_static() to be available.\n *\n * @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the\n * pucStreamBufferStorageArea parameter.\n *\n * @param xTriggerLevelBytes The number of bytes that must be in the stream\n * buffer before a task that is blocked on the stream buffer to wait for data is\n * moved out of the blocked state.  For example, if a task is blocked on a read\n * of an empty stream buffer that has a trigger level of 1 then the task will be\n * unblocked when a single byte is written to the buffer or the task's block\n * time expires.  As another example, if a task is blocked on a read of an empty\n * stream buffer that has a trigger level of 10 then the task will not be\n * unblocked until the stream buffer contains at least 10 bytes or the task's\n * block time expires.  If a reading task's block time expires before the\n * trigger level is reached then the task will still receive however many bytes\n * are actually available.  Setting a trigger level of 0 will result in a\n * trigger level of 1 being used.  It is not valid to specify a trigger level\n * that is greater than the buffer size.\n *\n * @param pucStreamBufferStorageArea Must point to a uint8_t array that is at\n * least xBufferSizeBytes + 1 big.  This is the array to which streams are\n * copied when they are written to the stream buffer.\n *\n * @param pxStaticStreamBuffer Must point to a variable of type\n * static_stream_buf_s_t, which will be used to hold the stream buffer's data\n * structure.\n *\n * @return If the stream buffer is created successfully then a handle to the\n * created stream buffer is returned. If either pucStreamBufferStorageArea or\n * pxStaticstreamBuffer are NULL then NULL is returned.\n *\n * Example use:\n<pre>\n\n// Used to dimension the array used to hold the streams.  The available space\n// will actually be one less than this, so 999.\n#define STORAGE_SIZE_BYTES 1000\n\n// Defines the memory that will actually hold the streams within the stream\n// buffer.\nstatic uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];\n\n// The variable used to hold the stream buffer structure.\nstatic_stream_buf_s_t xStreamBufferStruct;\n\nvoid MyFunction( void )\n{\nstream_buf_t xStreamBuffer;\nconst size_t xTriggerLevel = 1;\n\n    xStreamBuffer = stream_buf_create_static( sizeof( ucBufferStorage ),\n                                               xTriggerLevel,\n                                               ucBufferStorage,\n                                               &xStreamBufferStruct );\n\n    // As neither the pucStreamBufferStorageArea or pxStaticStreamBuffer\n    // parameters were NULL, xStreamBuffer will not be NULL, and can be used to\n    // reference the created stream buffer in other stream buffer API calls.\n\n    // Other code that uses the stream buffer can go here.\n}\n\n</pre>\n * \\defgroup stream_buf_create_static stream_buf_create_static\n * \\ingroup StreamBufferManagement\n */\n#define stream_buf_create_static( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pucStreamBufferStorageArea, pxStaticStreamBuffer )\n\n/**\n * stream_buffer.h\n *\n<pre>\nsize_t stream_buf_send( stream_buf_t xStreamBuffer,\n                          const void *pvTxData,\n                          size_t xDataLengthBytes,\n                          uint32_t xTicksToWait );\n<pre>\n *\n * Sends bytes to a stream buffer.  The bytes are copied into the stream buffer.\n *\n * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer\n * implementation (so also the message buffer implementation, as message buffers\n * are built on top of stream buffers) assumes there is only one task or\n * interrupt that will write to the buffer (the writer), and only one task or\n * interrupt that will read from the buffer (the reader).  It is safe for the\n * writer and reader to be different tasks or interrupts, but, unlike other\n * FreeRTOS objects, it is not safe to have multiple different writers or\n * multiple different readers.  If there are to be multiple different writers\n * then the application writer must place each call to a writing API function\n * (such as stream_buf_send()) inside a critical section and set the send\n * block time to 0.  Likewise, if there are to be multiple different readers\n * then the application writer must place each call to a reading API function\n * (such as xStreamBufferRead()) inside a critical section and set the receive\n * block time to 0.\n *\n * Use stream_buf_send() to write to a stream buffer from a task.  Use\n * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt\n * service routine (ISR).\n *\n * @param xStreamBuffer The handle of the stream buffer to which a stream is\n * being sent.\n *\n * @param pvTxData A pointer to the buffer that holds the bytes to be copied\n * into the stream buffer.\n *\n * @param xDataLengthBytes   The maximum number of bytes to copy from pvTxData\n * into the stream buffer.\n *\n * @param xTicksToWait The maximum amount of time the task should remain in the\n * Blocked state to wait for enough space to become available in the stream\n * buffer, should the stream buffer contain too little space to hold the\n * another xDataLengthBytes bytes.  The block time is specified in tick periods,\n * so the absolute time it represents is dependent on the tick frequency.  The\n * macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds\n * into a time specified in ticks.  Setting xTicksToWait to portMAX_DELAY will\n * cause the task to wait indefinitely (without timing out), provided\n * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h.  If a task times out\n * before it can write all xDataLengthBytes into the buffer it will still write\n * as many bytes as possible.  A task does not use any CPU time when it is in\n * the blocked state.\n *\n * @return The number of bytes written to the stream buffer.  If a task times\n * out before it can write all xDataLengthBytes into the buffer it will still\n * write as many bytes as possible.\n *\n * Example use:\n<pre>\nvoid vAFunction( stream_buf_t xStreamBuffer )\n{\nsize_t xBytesSent;\nuint8_t ucArrayToSend[] = { 0, 1, 2, 3 };\nchar *pcStringToSend = \"String to send\";\nconst uint32_t x100ms = pdMS_TO_TICKS( 100 );\n\n    // Send an array to the stream buffer, blocking for a maximum of 100ms to\n    // wait for enough space to be available in the stream buffer.\n    xBytesSent = stream_buf_send( xStreamBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );\n\n    if( xBytesSent != sizeof( ucArrayToSend ) )\n    {\n        // The call to stream_buf_send() times out before there was enough\n        // space in the buffer for the data to be written, but it did\n        // successfully write xBytesSent bytes.\n    }\n\n    // Send the string to the stream buffer.  Return immediately if there is not\n    // enough space in the buffer.\n    xBytesSent = stream_buf_send( xStreamBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );\n\n    if( xBytesSent != strlen( pcStringToSend ) )\n    {\n        // The entire string could not be added to the stream buffer because\n        // there was not enough free space in the buffer, but xBytesSent bytes\n        // were sent.  Could try again to send the remaining bytes.\n    }\n}\n</pre>\n * \\defgroup stream_buf_send stream_buf_send\n * \\ingroup StreamBufferManagement\n */\nsize_t stream_buf_send( stream_buf_t xStreamBuffer,\n\t\t\t\t\t\t  const void *pvTxData,\n\t\t\t\t\t\t  size_t xDataLengthBytes,\n\t\t\t\t\t\t  uint32_t xTicksToWait ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nsize_t xStreamBufferSendFromISR( stream_buf_t xStreamBuffer,\n                                 const void *pvTxData,\n                                 size_t xDataLengthBytes,\n                                 int32_t *pxHigherPriorityTaskWoken );\n<pre>\n *\n * Interrupt safe version of the API function that sends a stream of bytes to\n * the stream buffer.\n *\n * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer\n * implementation (so also the message buffer implementation, as message buffers\n * are built on top of stream buffers) assumes there is only one task or\n * interrupt that will write to the buffer (the writer), and only one task or\n * interrupt that will read from the buffer (the reader).  It is safe for the\n * writer and reader to be different tasks or interrupts, but, unlike other\n * FreeRTOS objects, it is not safe to have multiple different writers or\n * multiple different readers.  If there are to be multiple different writers\n * then the application writer must place each call to a writing API function\n * (such as stream_buf_send()) inside a critical section and set the send\n * block time to 0.  Likewise, if there are to be multiple different readers\n * then the application writer must place each call to a reading API function\n * (such as xStreamBufferRead()) inside a critical section and set the receive\n * block time to 0.\n *\n * Use stream_buf_send() to write to a stream buffer from a task.  Use\n * xStreamBufferSendFromISR() to write to a stream buffer from an interrupt\n * service routine (ISR).\n *\n * @param xStreamBuffer The handle of the stream buffer to which a stream is\n * being sent.\n *\n * @param pvTxData A pointer to the data that is to be copied into the stream\n * buffer.\n *\n * @param xDataLengthBytes The maximum number of bytes to copy from pvTxData\n * into the stream buffer.\n *\n * @param pxHigherPriorityTaskWoken  It is possible that a stream buffer will\n * have a task blocked on it waiting for data.  Calling\n * xStreamBufferSendFromISR() can make data available, and so cause a task that\n * was waiting for data to leave the Blocked state.  If calling\n * xStreamBufferSendFromISR() causes a task to leave the Blocked state, and the\n * unblocked task has a priority higher than the currently executing task (the\n * task that was interrupted), then, internally, xStreamBufferSendFromISR()\n * will set *pxHigherPriorityTaskWoken to pdTRUE.  If\n * xStreamBufferSendFromISR() sets this value to pdTRUE, then normally a\n * context switch should be performed before the interrupt is exited.  This will\n * ensure that the interrupt returns directly to the highest priority Ready\n * state task.  *pxHigherPriorityTaskWoken should be set to pdFALSE before it\n * is passed into the function.  See the example code below for an example.\n *\n * @return The number of bytes actually written to the stream buffer, which will\n * be less than xDataLengthBytes if the stream buffer didn't have enough free\n * space for all the bytes to be written.\n *\n * Example use:\n<pre>\n// A stream buffer that has already been created.\nstream_buf_t xStreamBuffer;\n\nvoid vAnInterruptServiceRoutine( void )\n{\nsize_t xBytesSent;\nchar *pcStringToSend = \"String to send\";\nint32_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.\n\n    // Attempt to send the string to the stream buffer.\n    xBytesSent = xStreamBufferSendFromISR( xStreamBuffer,\n                                           ( void * ) pcStringToSend,\n                                           strlen( pcStringToSend ),\n                                           &xHigherPriorityTaskWoken );\n\n    if( xBytesSent != strlen( pcStringToSend ) )\n    {\n        // There was not enough free space in the stream buffer for the entire\n        // string to be written, ut xBytesSent bytes were written.\n    }\n\n    // If xHigherPriorityTaskWoken was set to pdTRUE inside\n    // xStreamBufferSendFromISR() then a task that has a priority above the\n    // priority of the currently executing task was unblocked and a context\n    // switch should be performed to ensure the ISR returns to the unblocked\n    // task.  In most FreeRTOS ports this is done by simply passing\n    // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the\n    // variables value, and perform the context switch if necessary.  Check the\n    // documentation for the port in use for port specific instructions.\n    taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );\n}\n</pre>\n * \\defgroup xStreamBufferSendFromISR xStreamBufferSendFromISR\n * \\ingroup StreamBufferManagement\n */\nsize_t xStreamBufferSendFromISR( stream_buf_t xStreamBuffer,\n\t\t\t\t\t\t\t\t const void *pvTxData,\n\t\t\t\t\t\t\t\t size_t xDataLengthBytes,\n\t\t\t\t\t\t\t\t int32_t * const pxHigherPriorityTaskWoken ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nsize_t stream_buf_recv( stream_buf_t xStreamBuffer,\n                             void *pvRxData,\n                             size_t xBufferLengthBytes,\n                             uint32_t xTicksToWait );\n</pre>\n *\n * Receives bytes from a stream buffer.\n *\n * ***NOTE***:  Uniquely among FreeRTOS objects, the stream buffer\n * implementation (so also the message buffer implementation, as message buffers\n * are built on top of stream buffers) assumes there is only one task or\n * interrupt that will write to the buffer (the writer), and only one task or\n * interrupt that will read from the buffer (the reader).  It is safe for the\n * writer and reader to be different tasks or interrupts, but, unlike other\n * FreeRTOS objects, it is not safe to have multiple different writers or\n * multiple different readers.  If there are to be multiple different writers\n * then the application writer must place each call to a writing API function\n * (such as stream_buf_send()) inside a critical section and set the send\n * block time to 0.  Likewise, if there are to be multiple different readers\n * then the application writer must place each call to a reading API function\n * (such as xStreamBufferRead()) inside a critical section and set the receive\n * block time to 0.\n *\n * Use stream_buf_recv() to read from a stream buffer from a task.  Use\n * xStreamBufferReceiveFromISR() to read from a stream buffer from an\n * interrupt service routine (ISR).\n *\n * @param xStreamBuffer The handle of the stream buffer from which bytes are to\n * be received.\n *\n * @param pvRxData A pointer to the buffer into which the received bytes will be\n * copied.\n *\n * @param xBufferLengthBytes The length of the buffer pointed to by the\n * pvRxData parameter.  This sets the maximum number of bytes to receive in one\n * call.  stream_buf_recv will return as many bytes as possible up to a\n * maximum set by xBufferLengthBytes.\n *\n * @param xTicksToWait The maximum amount of time the task should remain in the\n * Blocked state to wait for data to become available if the stream buffer is\n * empty.  stream_buf_recv() will return immediately if xTicksToWait is\n * zero.  The block time is specified in tick periods, so the absolute time it\n * represents is dependent on the tick frequency.  The macro pdMS_TO_TICKS() can\n * be used to convert a time specified in milliseconds into a time specified in\n * ticks.  Setting xTicksToWait to portMAX_DELAY will cause the task to wait\n * indefinitely (without timing out), provided INCLUDE_vTaskSuspend is set to 1\n * in FreeRTOSConfig.h.  A task does not use any CPU time when it is in the\n * Blocked state.\n *\n * @return The number of bytes actually read from the stream buffer, which will\n * be less than xBufferLengthBytes if the call to stream_buf_recv() timed\n * out before xBufferLengthBytes were available.\n *\n * Example use:\n<pre>\nvoid vAFunction( StreamBuffer_t xStreamBuffer )\n{\nuint8_t ucRxData[ 20 ];\nsize_t xReceivedBytes;\nconst uint32_t xBlockTime = pdMS_TO_TICKS( 20 );\n\n    // Receive up to another sizeof( ucRxData ) bytes from the stream buffer.\n    // Wait in the Blocked state (so not using any CPU processing time) for a\n    // maximum of 100ms for the full sizeof( ucRxData ) number of bytes to be\n    // available.\n    xReceivedBytes = stream_buf_recv( xStreamBuffer,\n                                           ( void * ) ucRxData,\n                                           sizeof( ucRxData ),\n                                           xBlockTime );\n\n    if( xReceivedBytes > 0 )\n    {\n        // A ucRxData contains another xReceivedBytes bytes of data, which can\n        // be processed here....\n    }\n}\n</pre>\n * \\defgroup stream_buf_recv stream_buf_recv\n * \\ingroup StreamBufferManagement\n */\nsize_t stream_buf_recv( stream_buf_t xStreamBuffer,\n\t\t\t\t\t\t\t void *pvRxData,\n\t\t\t\t\t\t\t size_t xBufferLengthBytes,\n\t\t\t\t\t\t\t uint32_t xTicksToWait ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nsize_t xStreamBufferReceiveFromISR( stream_buf_t xStreamBuffer,\n                                    void *pvRxData,\n                                    size_t xBufferLengthBytes,\n                                    int32_t *pxHigherPriorityTaskWoken );\n</pre>\n *\n * An interrupt safe version of the API function that receives bytes from a\n * stream buffer.\n *\n * Use stream_buf_recv() to read bytes from a stream buffer from a task.\n * Use xStreamBufferReceiveFromISR() to read bytes from a stream buffer from an\n * interrupt service routine (ISR).\n *\n * @param xStreamBuffer The handle of the stream buffer from which a stream\n * is being received.\n *\n * @param pvRxData A pointer to the buffer into which the received bytes are\n * copied.\n *\n * @param xBufferLengthBytes The length of the buffer pointed to by the\n * pvRxData parameter.  This sets the maximum number of bytes to receive in one\n * call.  stream_buf_recv will return as many bytes as possible up to a\n * maximum set by xBufferLengthBytes.\n *\n * @param pxHigherPriorityTaskWoken  It is possible that a stream buffer will\n * have a task blocked on it waiting for space to become available.  Calling\n * xStreamBufferReceiveFromISR() can make space available, and so cause a task\n * that is waiting for space to leave the Blocked state.  If calling\n * xStreamBufferReceiveFromISR() causes a task to leave the Blocked state, and\n * the unblocked task has a priority higher than the currently executing task\n * (the task that was interrupted), then, internally,\n * xStreamBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE.\n * If xStreamBufferReceiveFromISR() sets this value to pdTRUE, then normally a\n * context switch should be performed before the interrupt is exited.  That will\n * ensure the interrupt returns directly to the highest priority Ready state\n * task.  *pxHigherPriorityTaskWoken should be set to pdFALSE before it is\n * passed into the function.  See the code example below for an example.\n *\n * @return The number of bytes read from the stream buffer, if any.\n *\n * Example use:\n<pre>\n// A stream buffer that has already been created.\nStreamBuffer_t xStreamBuffer;\n\nvoid vAnInterruptServiceRoutine( void )\n{\nuint8_t ucRxData[ 20 ];\nsize_t xReceivedBytes;\nint32_t xHigherPriorityTaskWoken = pdFALSE;  // Initialised to pdFALSE.\n\n    // Receive the next stream from the stream buffer.\n    xReceivedBytes = xStreamBufferReceiveFromISR( xStreamBuffer,\n                                                  ( void * ) ucRxData,\n                                                  sizeof( ucRxData ),\n                                                  &xHigherPriorityTaskWoken );\n\n    if( xReceivedBytes > 0 )\n    {\n        // ucRxData contains xReceivedBytes read from the stream buffer.\n        // Process the stream here....\n    }\n\n    // If xHigherPriorityTaskWoken was set to pdTRUE inside\n    // xStreamBufferReceiveFromISR() then a task that has a priority above the\n    // priority of the currently executing task was unblocked and a context\n    // switch should be performed to ensure the ISR returns to the unblocked\n    // task.  In most FreeRTOS ports this is done by simply passing\n    // xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the\n    // variables value, and perform the context switch if necessary.  Check the\n    // documentation for the port in use for port specific instructions.\n    taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );\n}\n</pre>\n * \\defgroup xStreamBufferReceiveFromISR xStreamBufferReceiveFromISR\n * \\ingroup StreamBufferManagement\n */\nsize_t xStreamBufferReceiveFromISR( stream_buf_t xStreamBuffer,\n\t\t\t\t\t\t\t\t\tvoid *pvRxData,\n\t\t\t\t\t\t\t\t\tsize_t xBufferLengthBytes,\n\t\t\t\t\t\t\t\t\tint32_t * const pxHigherPriorityTaskWoken ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nvoid vStreamBufferDelete( stream_buf_t xStreamBuffer );\n</pre>\n *\n * Deletes a stream buffer that was previously created using a call to\n * stream_buf_create() or stream_buf_create_static().  If the stream\n * buffer was created using dynamic memory (that is, by stream_buf_create()),\n * then the allocated memory is freed.\n *\n * A stream buffer handle must not be used after the stream buffer has been\n * deleted.\n *\n * @param xStreamBuffer The handle of the stream buffer to be deleted.\n *\n * \\defgroup vStreamBufferDelete vStreamBufferDelete\n * \\ingroup StreamBufferManagement\n */\nvoid vStreamBufferDelete( stream_buf_t xStreamBuffer ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nint32_t stream_buf_is_full( stream_buf_t xStreamBuffer );\n</pre>\n *\n * Queries a stream buffer to see if it is full.  A stream buffer is full if it\n * does not have any free space, and therefore cannot accept any more data.\n *\n * @param xStreamBuffer The handle of the stream buffer being queried.\n *\n * @return If the stream buffer is full then pdTRUE is returned.  Otherwise\n * pdFALSE is returned.\n *\n * \\defgroup stream_buf_is_full stream_buf_is_full\n * \\ingroup StreamBufferManagement\n */\nint32_t stream_buf_is_full( stream_buf_t xStreamBuffer ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nint32_t stream_buf_is_empty( stream_buf_t xStreamBuffer );\n</pre>\n *\n * Queries a stream buffer to see if it is empty.  A stream buffer is empty if\n * it does not contain any data.\n *\n * @param xStreamBuffer The handle of the stream buffer being queried.\n *\n * @return If the stream buffer is empty then pdTRUE is returned.  Otherwise\n * pdFALSE is returned.\n *\n * \\defgroup stream_buf_is_empty stream_buf_is_empty\n * \\ingroup StreamBufferManagement\n */\nint32_t stream_buf_is_empty( stream_buf_t xStreamBuffer ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nint32_t stream_buf_reset( stream_buf_t xStreamBuffer );\n</pre>\n *\n * Resets a stream buffer to its initial, empty, state.  Any data that was in\n * the stream buffer is discarded.  A stream buffer can only be reset if there\n * are no tasks blocked waiting to either send to or receive from the stream\n * buffer.\n *\n * @param xStreamBuffer The handle of the stream buffer being reset.\n *\n * @return If the stream buffer is reset then pdPASS is returned.  If there was\n * a task blocked waiting to send to or read from the stream buffer then the\n * stream buffer is not reset and pdFAIL is returned.\n *\n * \\defgroup stream_buf_reset stream_buf_reset\n * \\ingroup StreamBufferManagement\n */\nint32_t stream_buf_reset( stream_buf_t xStreamBuffer ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nsize_t stream_buf_get_unused( stream_buf_t xStreamBuffer );\n</pre>\n *\n * Queries a stream buffer to see how much free space it contains, which is\n * equal to the amount of data that can be sent to the stream buffer before it\n * is full.\n *\n * @param xStreamBuffer The handle of the stream buffer being queried.\n *\n * @return The number of bytes that can be written to the stream buffer before\n * the stream buffer would be full.\n *\n * \\defgroup stream_buf_get_unused stream_buf_get_unused\n * \\ingroup StreamBufferManagement\n */\nsize_t stream_buf_get_unused( stream_buf_t xStreamBuffer ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nsize_t stream_buf_get_used( stream_buf_t xStreamBuffer );\n</pre>\n *\n * Queries a stream buffer to see how much data it contains, which is equal to\n * the number of bytes that can be read from the stream buffer before the stream\n * buffer would be empty.\n *\n * @param xStreamBuffer The handle of the stream buffer being queried.\n *\n * @return The number of bytes that can be read from the stream buffer before\n * the stream buffer would be empty.\n *\n * \\defgroup stream_buf_get_used stream_buf_get_used\n * \\ingroup StreamBufferManagement\n */\nsize_t stream_buf_get_used( stream_buf_t xStreamBuffer ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nint32_t stream_buf_set_trigger( stream_buf_t xStreamBuffer, size_t xTriggerLevel );\n</pre>\n *\n * A stream buffer's trigger level is the number of bytes that must be in the\n * stream buffer before a task that is blocked on the stream buffer to\n * wait for data is moved out of the blocked state.  For example, if a task is\n * blocked on a read of an empty stream buffer that has a trigger level of 1\n * then the task will be unblocked when a single byte is written to the buffer\n * or the task's block time expires.  As another example, if a task is blocked\n * on a read of an empty stream buffer that has a trigger level of 10 then the\n * task will not be unblocked until the stream buffer contains at least 10 bytes\n * or the task's block time expires.  If a reading task's block time expires\n * before the trigger level is reached then the task will still receive however\n * many bytes are actually available.  Setting a trigger level of 0 will result\n * in a trigger level of 1 being used.  It is not valid to specify a trigger\n * level that is greater than the buffer size.\n *\n * A trigger level is set when the stream buffer is created, and can be modified\n * using stream_buf_set_trigger().\n *\n * @param xStreamBuffer The handle of the stream buffer being updated.\n *\n * @param xTriggerLevel The new trigger level for the stream buffer.\n *\n * @return If xTriggerLevel was less than or equal to the stream buffer's length\n * then the trigger level will be updated and pdTRUE is returned.  Otherwise\n * pdFALSE is returned.\n *\n * \\defgroup stream_buf_set_trigger stream_buf_set_trigger\n * \\ingroup StreamBufferManagement\n */\nint32_t stream_buf_set_trigger( stream_buf_t xStreamBuffer, size_t xTriggerLevel ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nint32_t xStreamBufferSendCompletedFromISR( stream_buf_t xStreamBuffer, int32_t *pxHigherPriorityTaskWoken );\n</pre>\n *\n * For advanced users only.\n *\n * The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when\n * data is sent to a message buffer or stream buffer.  If there was a task that\n * was blocked on the message or stream buffer waiting for data to arrive then\n * the sbSEND_COMPLETED() macro sends a notification to the task to remove it\n * from the Blocked state.  xStreamBufferSendCompletedFromISR() does the same\n * thing.  It is provided to enable application writers to implement their own\n * version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME.\n *\n * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for\n * additional information.\n *\n * @param xStreamBuffer The handle of the stream buffer to which data was\n * written.\n *\n * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be\n * initialised to pdFALSE before it is passed into\n * xStreamBufferSendCompletedFromISR().  If calling\n * xStreamBufferSendCompletedFromISR() removes a task from the Blocked state,\n * and the task has a priority above the priority of the currently running task,\n * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a\n * context switch should be performed before exiting the ISR.\n *\n * @return If a task was removed from the Blocked state then pdTRUE is returned.\n * Otherwise pdFALSE is returned.\n *\n * \\defgroup xStreamBufferSendCompletedFromISR xStreamBufferSendCompletedFromISR\n * \\ingroup StreamBufferManagement\n */\nint32_t xStreamBufferSendCompletedFromISR( stream_buf_t xStreamBuffer, int32_t *pxHigherPriorityTaskWoken ) ;\n\n/**\n * stream_buffer.h\n *\n<pre>\nint32_t xStreamBufferReceiveCompletedFromISR( stream_buf_t xStreamBuffer, int32_t *pxHigherPriorityTaskWoken );\n</pre>\n *\n * For advanced users only.\n *\n * The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when\n * data is read out of a message buffer or stream buffer.  If there was a task\n * that was blocked on the message or stream buffer waiting for data to arrive\n * then the sbRECEIVE_COMPLETED() macro sends a notification to the task to\n * remove it from the Blocked state.  xStreamBufferReceiveCompletedFromISR()\n * does the same thing.  It is provided to enable application writers to\n * implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT\n * ANY OTHER TIME.\n *\n * See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for\n * additional information.\n *\n * @param xStreamBuffer The handle of the stream buffer from which data was\n * read.\n *\n * @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be\n * initialised to pdFALSE before it is passed into\n * xStreamBufferReceiveCompletedFromISR().  If calling\n * xStreamBufferReceiveCompletedFromISR() removes a task from the Blocked state,\n * and the task has a priority above the priority of the currently running task,\n * then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a\n * context switch should be performed before exiting the ISR.\n *\n * @return If a task was removed from the Blocked state then pdTRUE is returned.\n * Otherwise pdFALSE is returned.\n *\n * \\defgroup xStreamBufferReceiveCompletedFromISR xStreamBufferReceiveCompletedFromISR\n * \\ingroup StreamBufferManagement\n */\nint32_t xStreamBufferReceiveCompletedFromISR( stream_buf_t xStreamBuffer, int32_t *pxHigherPriorityTaskWoken ) ;\n\n/* Functions below here are not part of the public API. */\nstream_buf_t xStreamBufferGenericCreate( size_t xBufferSizeBytes,\n\t\t\t\t\t\t\t\t\t\t\t\t size_t xTriggerLevelBytes,\n\t\t\t\t\t\t\t\t\t\t\t\t int32_t xIsMessageBuffer ) ;\n\nstream_buf_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,\n\t\t\t\t\t\t\t\t\t\t\t\t\t   size_t xTriggerLevelBytes,\n\t\t\t\t\t\t\t\t\t\t\t\t\t   int32_t xIsMessageBuffer,\n\t\t\t\t\t\t\t\t\t\t\t\t\t   uint8_t * const pucStreamBufferStorageArea,\n\t\t\t\t\t\t\t\t\t\t\t\t\t   static_stream_buf_s_t * const pxStaticStreamBuffer ) ;\n\n#if( configUSE_TRACE_FACILITY == 1 )\n\tvoid vStreamBufferSetStreamBufferNumber( stream_buf_t xStreamBuffer, uint32_t uxStreamBufferNumber ) ;\n\tuint32_t uxStreamBufferGetStreamBufferNumber( stream_buf_t xStreamBuffer ) ;\n\tuint8_t ucStreamBufferGetStreamBufferType( stream_buf_t xStreamBuffer ) ;\n#endif\n\n#if defined( __cplusplus )\n}\n#endif\n\n#endif\t/* !defined( STREAM_BUFFER_H ) */\n"
  },
  {
    "path": "include/rtos/task.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n#include \"FreeRTOS.h\"\n\n#ifndef INC_TASK_H\n#define INC_TASK_H\n\n#ifndef INC_FREERTOS_H\n\t#error \"include FreeRTOS.h must appear in source files before include task.h\"\n#endif\n\n#include \"list.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/*-----------------------------------------------------------\n * MACROS AND DEFINITIONS\n *----------------------------------------------------------*/\n\n#define tskKERNEL_VERSION_NUMBER \"V10.0.1\"\n#define tskKERNEL_VERSION_MAJOR 10\n#define tskKERNEL_VERSION_MINOR 0\n#define tskKERNEL_VERSION_BUILD 1\n\n/**\n * task. h\n *\n * Type by which tasks are referenced.  For example, a call to task_create\n * returns (via a pointer parameter) an task_t variable that can then\n * be used as a parameter to task_delete to delete the task.\n *\n * \\defgroup task_t task_t\n * \\ingroup Tasks\n */\ntypedef void * task_t;\n\n/*\n * Defines the prototype to which the application task hook function must\n * conform.\n */\ntypedef int32_t (*TaskHookFunction_t)( void * );\n\n/* Task states returned by task_get_state. */\ntypedef enum\n{\n\tE_TASK_STATE_RUNNING = 0,\t/* A task is querying the state of itself, so must be running. */\n\tE_TASK_STATE_READY,\t\t\t/* The task being queried is in a read or pending ready list. */\n\tE_TASK_STATE_BLOCKED,\t\t/* The task being queried is in the Blocked state. */\n\tE_TASK_STATE_SUSPENDED,\t\t/* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */\n\tE_TASK_STATE_DELETED,\t\t/* The task being queried has been deleted, but its TCB has not yet been freed. */\n\tE_TASK_STATE_INVALID\t\t\t/* Used as an 'invalid state' value. */\n} task_state_e_t;\n\n/* Actions that can be performed when vTaskNotify() is called. */\ntypedef enum\n{\n\tE_NOTIFY_ACTION_NONE = 0,\t\t\t\t/* Notify the task without updating its notify value. */\n\tE_NOTIFY_ACTION_BITS,\t\t\t\t\t/* Set bits in the task's notification value. */\n\tE_NOTIFY_ACTION_INCR,\t\t\t\t\t/* Increment the task's notification value. */\n\tE_NOTIFY_ACTION_OWRITE,\t\t/* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */\n\tE_NOTIFY_ACTION_NO_OWRITE\t/* Set the task's notification value if the previous value has been read by the task. */\n} notify_action_e_t;\n\n/*\n * Used internally only.\n */\ntypedef struct xTIME_OUT\n{\n\tint32_t xOverflowCount;\n\tuint32_t xTimeOnEntering;\n} TimeOut_t;\n\n\n/*\n * Parameters required to create an MPU protected task.\n */\ntypedef struct xTASK_PARAMETERS\n{\n\ttask_fn_t pvTaskCode;\n\tconst char * const pcName;\t/*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\tuint16_t usStackDepth;\n\tvoid *pvParameters;\n\tuint32_t uxPriority;\n\ttask_stack_t *puxStackBuffer;\n} TaskParameters_t;\n\n/* Used with the uxTaskGetSystemState() function to return the state of each task\nin the system. */\ntypedef struct xTASK_STATUS\n{\n\ttask_t xHandle;\t\t\t/* The handle of the task to which the rest of the information in the structure relates. */\n\tconst char *pcTaskName;\t\t\t/* A pointer to the task's name.  This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\tuint32_t xTaskNumber;\t\t/* A number unique to the task. */\n\ttask_state_e_t eCurrentState;\t\t/* The state in which the task existed when the structure was populated. */\n\tuint32_t uxCurrentPriority;\t/* The priority at which the task was running (may be inherited) when the structure was populated. */\n\tuint32_t uxBasePriority;\t\t/* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex.  Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */\n\tuint32_t ulRunTimeCounter;\t\t/* The total run time allocated to the task so far, as defined by the run time stats clock.  See http://www.freertos.org/rtos-run-time-stats.html.  Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */\n\ttask_stack_t *pxStackBase;\t\t/* Points to the lowest address of the task's stack area. */\n\tuint16_t usStackHighWaterMark;\t/* The minimum amount of stack space that has remained for the task since the task was created.  The closer this value is to zero the closer the task has come to overflowing its stack. */\n} TaskStatus_t;\n\n/* Possible return values for eTaskConfirmSleepModeStatus(). */\ntypedef enum\n{\n\teAbortSleep = 0,\t\t/* A task has been made ready or a context switch pended since portSUPPORESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */\n\teStandardSleep,\t\t\t/* Enter a sleep mode that will not last any longer than the expected idle time. */\n\teNoTasksWaitingTimeout\t/* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */\n} eSleepModeStatus;\n\n/**\n * Defines the priority used by the idle task.  This must not be modified.\n *\n * \\ingroup TaskUtils\n */\n#define tskIDLE_PRIORITY\t\t\t( ( uint32_t ) 0U )\n\n/**\n * task. h\n *\n * Macro for forcing a context switch.\n *\n * \\defgroup taskYIELD taskYIELD\n * \\ingroup SchedulerControl\n */\n#define taskYIELD()\t\t\t\t\tportYIELD()\n\n/**\n * task. h\n *\n * Macro to mark the start of a critical code region.  Preemptive context\n * switches cannot occur when in a critical region.\n *\n * NOTE: This may alter the stack (depending on the portable implementation)\n * so must be used with care!\n *\n * \\defgroup taskENTER_CRITICAL taskENTER_CRITICAL\n * \\ingroup SchedulerControl\n */\n#define taskENTER_CRITICAL()\t\tportENTER_CRITICAL()\n#define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()\n\n/**\n * task. h\n *\n * Macro to mark the end of a critical code region.  Preemptive context\n * switches cannot occur when in a critical region.\n *\n * NOTE: This may alter the stack (depending on the portable implementation)\n * so must be used with care!\n *\n * \\defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL\n * \\ingroup SchedulerControl\n */\n#define taskEXIT_CRITICAL()\t\t\tportEXIT_CRITICAL()\n#define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )\n/**\n * task. h\n *\n * Macro to disable all maskable interrupts.\n *\n * \\defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS\n * \\ingroup SchedulerControl\n */\n#define taskDISABLE_INTERRUPTS()\tportDISABLE_INTERRUPTS()\n\n/**\n * task. h\n *\n * Macro to enable microcontroller interrupts.\n *\n * \\defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS\n * \\ingroup SchedulerControl\n */\n#define taskENABLE_INTERRUPTS()\t\tportENABLE_INTERRUPTS()\n\n/* Definitions returned by xTaskGetSchedulerState().  taskSCHEDULER_SUSPENDED is\n0 to generate more optimal code when configASSERT() is defined as the constant\nis used in assert() statements. */\n#define taskSCHEDULER_SUSPENDED\t\t( ( int32_t ) 0 )\n#define taskSCHEDULER_NOT_STARTED\t( ( int32_t ) 1 )\n#define taskSCHEDULER_RUNNING\t\t( ( int32_t ) 2 )\n\n\n/*-----------------------------------------------------------\n * TASK CREATION API\n *----------------------------------------------------------*/\n\n/**\n * task. h\n *<pre>\n int32_t task_create(\n\t\t\t\t\t\t\t  task_fn_t pvTaskCode,\n\t\t\t\t\t\t\t  const char * const pcName,\n\t\t\t\t\t\t\t  configSTACK_DEPTH_TYPE usStackDepth,\n\t\t\t\t\t\t\t  void *pvParameters,\n\t\t\t\t\t\t\t  uint32_t uxPriority,\n\t\t\t\t\t\t\t  task_t *pvCreatedTask\n\t\t\t\t\t\t  );</pre>\n *\n * Create a new task and add it to the list of tasks that are ready to run.\n *\n * Internally, within the FreeRTOS implementation, tasks use two blocks of\n * memory.  The first block is used to hold the task's data structures.  The\n * second block is used by the task as its stack.  If a task is created using\n * task_create() then both blocks of memory are automatically dynamically\n * allocated inside the task_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a task is created using\n * task_create_static() then the application writer must provide the required\n * memory.  task_create_static() therefore allows a task to be created without\n * using any dynamic memory allocation.\n *\n * See task_create_static() for a version that does not use any dynamic memory\n * allocation.\n *\n * task_create() can only be used to create a task that has unrestricted\n * access to the entire microcontroller memory map.  Systems that include MPU\n * support can alternatively create an MPU constrained task using\n * xTaskCreateRestricted().\n *\n * @param pvTaskCode Pointer to the task entry function.  Tasks\n * must be implemented to never return (i.e. continuous loop).\n *\n * @param pcName A descriptive name for the task.  This is mainly used to\n * facilitate debugging.  Max length defined by configMAX_TASK_NAME_LEN - default\n * is 16.\n *\n * @param usStackDepth The size of the task stack specified as the number of\n * variables the stack can hold - not the number of bytes.  For example, if\n * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes\n * will be allocated for stack storage.\n *\n * @param pvParameters Pointer that will be used as the parameter for the task\n * being created.\n *\n * @param uxPriority The priority at which the task should run.  Systems that\n * include MPU support can optionally create tasks in a privileged (system)\n * mode by setting bit portPRIVILEGE_BIT of the priority parameter.  For\n * example, to create a privileged task at priority 2 the uxPriority parameter\n * should be set to ( 2 | portPRIVILEGE_BIT ).\n *\n * @param pvCreatedTask Used to pass back a handle by which the created task\n * can be referenced.\n *\n * @return pdPASS if the task was successfully created and added to a ready\n * list, otherwise an error code defined in the file projdefs.h\n *\n * Example usage:\n   <pre>\n // Task to be created.\n void vTaskCode( void * pvParameters )\n {\n\t for( ;; )\n\t {\n\t\t // Task code goes here.\n\t }\n }\n\n // Function that creates a task.\n void vOtherFunction( void )\n {\n static uint8_t ucParameterToPass;\n task_t xHandle = NULL;\n\n\t // Create the task, storing the handle.  Note that the passed parameter ucParameterToPass\n\t // must exist for the lifetime of the task, so in this case is declared static.  If it was just an\n\t // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time\n\t // the new task attempts to access it.\n\t task_create( vTaskCode, \"NAME\", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );\n     configASSERT( xHandle );\n\n\t // Use the handle to delete the task.\n     if( xHandle != NULL )\n     {\n\t     task_delete( xHandle );\n     }\n }\n   </pre>\n * \\defgroup task_create task_create\n * \\ingroup Tasks\n */\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\ttask_t task_create(task_fn_t function, void* const parameters,\n\t                   uint32_t prio, const uint16_t stack_depth,\n\t                   const char* const name);\n#endif\n\n/**\n * task. h\n *<pre>\n task_t task_create_static( task_fn_t pvTaskCode,\n\t\t\t\t\t\t\t\t const char * const pcName,\n\t\t\t\t\t\t\t\t uint32_t ulStackDepth,\n\t\t\t\t\t\t\t\t void *pvParameters,\n\t\t\t\t\t\t\t\t uint32_t uxPriority,\n\t\t\t\t\t\t\t\t task_stack_t *pxStackBuffer,\n\t\t\t\t\t\t\t\t static_task_s_t *pxTaskBuffer );</pre>\n *\n * Create a new task and add it to the list of tasks that are ready to run.\n *\n * Internally, within the FreeRTOS implementation, tasks use two blocks of\n * memory.  The first block is used to hold the task's data structures.  The\n * second block is used by the task as its stack.  If a task is created using\n * task_create() then both blocks of memory are automatically dynamically\n * allocated inside the task_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a task is created using\n * task_create_static() then the application writer must provide the required\n * memory.  task_create_static() therefore allows a task to be created without\n * using any dynamic memory allocation.\n *\n * @param pvTaskCode Pointer to the task entry function.  Tasks\n * must be implemented to never return (i.e. continuous loop).\n *\n * @param pcName A descriptive name for the task.  This is mainly used to\n * facilitate debugging.  The maximum length of the string is defined by\n * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.\n *\n * @param ulStackDepth The size of the task stack specified as the number of\n * variables the stack can hold - not the number of bytes.  For example, if\n * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes\n * will be allocated for stack storage.\n *\n * @param pvParameters Pointer that will be used as the parameter for the task\n * being created.\n *\n * @param uxPriority The priority at which the task will run.\n *\n * @param pxStackBuffer Must point to a task_stack_t array that has at least\n * ulStackDepth indexes - the array will then be used as the task's stack,\n * removing the need for the stack to be allocated dynamically.\n *\n * @param pxTaskBuffer Must point to a variable of type static_task_s_t, which will\n * then be used to hold the task's data structures, removing the need for the\n * memory to be allocated dynamically.\n *\n * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will\n * be created and pdPASS is returned.  If either pxStackBuffer or pxTaskBuffer\n * are NULL then the task will not be created and\n * errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY is returned.\n *\n * Example usage:\n   <pre>\n\n    // Dimensions the buffer that the task being created will use as its stack.\n    // NOTE:  This is the number of words the stack will hold, not the number of\n    // bytes.  For example, if each stack item is 32-bits, and this is set to 100,\n    // then 400 bytes (100 * 32-bits) will be allocated.\n    #define STACK_SIZE 200\n\n    // Structure that will hold the TCB of the task being created.\n    static_task_s_t xTaskBuffer;\n\n    // Buffer that the task being created will use as its stack.  Note this is\n    // an array of task_stack_t variables.  The size of task_stack_t is dependent on\n    // the RTOS port.\n    task_stack_t xStack[ STACK_SIZE ];\n\n    // Function that implements the task being created.\n    void vTaskCode( void * pvParameters )\n    {\n        // The parameter value is expected to be 1 as 1 is passed in the\n        // pvParameters value in the call to task_create_static().\n        configASSERT( ( uint32_t ) pvParameters == 1UL );\n\n        for( ;; )\n        {\n            // Task code goes here.\n        }\n    }\n\n    // Function that creates a task.\n    void vOtherFunction( void )\n    {\n        task_t xHandle = NULL;\n\n        // Create the task without using any dynamic memory allocation.\n        xHandle = task_create_static(\n                      vTaskCode,       // Function that implements the task.\n                      \"NAME\",          // Text name for the task.\n                      STACK_SIZE,      // Stack size in words, not bytes.\n                      ( void * ) 1,    // Parameter passed into the task.\n                      tskIDLE_PRIORITY,// Priority at which the task is created.\n                      xStack,          // Array to use as the task's stack.\n                      &xTaskBuffer );  // Variable to hold the task's data structure.\n\n        // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have\n        // been created, and xHandle will be the task's handle.  Use the handle\n        // to suspend the task.\n        task_suspend( xHandle );\n    }\n   </pre>\n * \\defgroup task_create_static task_create_static\n * \\ingroup Tasks\n */\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\ttask_t task_create_static(\ttask_fn_t task_code, void* const param,\n\t                            uint32_t priority, const size_t stack_size,\n\t                            const char* const name,\n\t                            task_stack_t * const stack_buffer,\n\t                            static_task_s_t * const task_buffer ) ;\n#endif /* configSUPPORT_STATIC_ALLOCATION */\n\n/**\n * task. h\n * <pre>void task_delete( task_t xTask );</pre>\n *\n * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.\n * See the configuration section for more information.\n *\n * Remove a task from the RTOS real time kernel's management.  The task being\n * deleted will be removed from all ready, blocked, suspended and event lists.\n *\n * NOTE:  The idle task is responsible for freeing the kernel allocated\n * memory from tasks that have been deleted.  It is therefore important that\n * the idle task is not starved of microcontroller processing time if your\n * application makes any calls to task_delete ().  Memory allocated by the\n * task code is not automatically freed, and should be freed before the task\n * is deleted.\n *\n * See the demo application file death.c for sample code that utilises\n * task_delete ().\n *\n * @param xTask The handle of the task to be deleted.  Passing NULL will\n * cause the calling task to be deleted.\n *\n * Example usage:\n   <pre>\n void vOtherFunction( void )\n {\n task_t xHandle;\n\n\t // Create the task, storing the handle.\n\t task_create( vTaskCode, \"NAME\", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\n\n\t // Use the handle to delete the task.\n\t task_delete( xHandle );\n }\n   </pre>\n * \\defgroup task_delete task_delete\n * \\ingroup Tasks\n */\nvoid task_delete( task_t xTaskToDelete ) ;\n\n/*-----------------------------------------------------------\n * TASK CONTROL API\n *----------------------------------------------------------*/\n\n/**\n * task. h\n * <pre>void task_delay( const uint32_t xTicksToDelay );</pre>\n *\n * Delay a task for a given number of ticks.  The actual time that the\n * task remains blocked depends on the tick rate.  The constant\n * portTICK_PERIOD_MS can be used to calculate real time from the tick\n * rate - with the resolution of one tick period.\n *\n * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.\n * See the configuration section for more information.\n *\n *\n * task_delay() specifies a time at which the task wishes to unblock relative to\n * the time at which task_delay() is called.  For example, specifying a block\n * period of 100 ticks will cause the task to unblock 100 ticks after\n * task_delay() is called.  task_delay() does not therefore provide a good method\n * of controlling the frequency of a periodic task as the path taken through the\n * code, as well as other task and interrupt activity, will effect the frequency\n * at which task_delay() gets called and therefore the time at which the task\n * next executes.  See task_delay_until() for an alternative API function designed\n * to facilitate fixed frequency execution.  It does this by specifying an\n * absolute time (rather than a relative time) at which the calling task should\n * unblock.\n *\n * @param xTicksToDelay The amount of time, in tick periods, that\n * the calling task should block.\n *\n * Example usage:\n\n void vTaskFunction( void * pvParameters )\n {\n // Block for 500ms.\n const uint32_t xDelay = 500 / portTICK_PERIOD_MS;\n\n\t for( ;; )\n\t {\n\t\t // Simply toggle the LED every 500ms, blocking between each toggle.\n\t\t vToggleLED();\n\t\t task_delay( xDelay );\n\t }\n }\n\n * \\defgroup task_delay task_delay\n * \\ingroup TaskCtrl\n */\nvoid task_delay( const uint32_t xTicksToDelay ) ;\n\n/**\n * task. h\n * <pre>void task_delay_until( uint32_t *pxPreviousWakeTime, const uint32_t xTimeIncrement );</pre>\n *\n * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.\n * See the configuration section for more information.\n *\n * Delay a task until a specified time.  This function can be used by periodic\n * tasks to ensure a constant execution frequency.\n *\n * This function differs from task_delay () in one important aspect:  task_delay () will\n * cause a task to block for the specified number of ticks from the time task_delay () is\n * called.  It is therefore difficult to use task_delay () by itself to generate a fixed\n * execution frequency as the time between a task starting to execute and that task\n * calling task_delay () may not be fixed [the task may take a different path though the\n * code between calls, or may get interrupted or preempted a different number of times\n * each time it executes].\n *\n * Whereas task_delay () specifies a wake time relative to the time at which the function\n * is called, task_delay_until () specifies the absolute (exact) time at which it wishes to\n * unblock.\n *\n * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick\n * rate - with the resolution of one tick period.\n *\n * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the\n * task was last unblocked.  The variable must be initialised with the current time\n * prior to its first use (see the example below).  Following this the variable is\n * automatically updated within task_delay_until ().\n *\n * @param xTimeIncrement The cycle time period.  The task will be unblocked at\n * time *pxPreviousWakeTime + xTimeIncrement.  Calling task_delay_until with the\n * same xTimeIncrement parameter value will cause the task to execute with\n * a fixed interface period.\n *\n * Example usage:\n   <pre>\n // Perform an action every 10 ticks.\n void vTaskFunction( void * pvParameters )\n {\n uint32_t xLastWakeTime;\n const uint32_t xFrequency = 10;\n\n\t // Initialise the xLastWakeTime variable with the current time.\n\t xLastWakeTime = millis ();\n\t for( ;; )\n\t {\n\t\t // Wait for the next cycle.\n\t\t task_delay_until( &xLastWakeTime, xFrequency );\n\n\t\t // Perform action here.\n\t }\n }\n   </pre>\n * \\defgroup task_delay_until task_delay_until\n * \\ingroup TaskCtrl\n */\nvoid task_delay_until( uint32_t * const pxPreviousWakeTime, const uint32_t xTimeIncrement ) ;\n\n/**\n * task. h\n * <pre>int32_t task_abort_delay( task_t xTask );</pre>\n *\n * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this\n * function to be available.\n *\n * A task will enter the Blocked state when it is waiting for an event.  The\n * event it is waiting for can be a temporal event (waiting for a time), such\n * as when task_delay() is called, or an event on an object, such as when\n * queue_recv() or task_notify_take() is called.  If the handle of a task\n * that is in the Blocked state is used in a call to task_abort_delay() then the\n * task will leave the Blocked state, and return from whichever function call\n * placed the task into the Blocked state.\n *\n * @param xTask The handle of the task to remove from the Blocked state.\n *\n * @return If the task referenced by xTask was not in the Blocked state then\n * pdFAIL is returned.  Otherwise pdPASS is returned.\n *\n * \\defgroup task_abort_delay task_abort_delay\n * \\ingroup TaskCtrl\n */\nint32_t task_abort_delay( task_t xTask ) ;\n\n/**\n * task. h\n * <pre>uint32_t task_get_priority( task_t xTask );</pre>\n *\n * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.\n * See the configuration section for more information.\n *\n * Obtain the priority of any task.\n *\n * @param xTask Handle of the task to be queried.  Passing a NULL\n * handle results in the priority of the calling task being returned.\n *\n * @return The priority of xTask.\n *\n * Example usage:\n   <pre>\n void vAFunction( void )\n {\n task_t xHandle;\n\n\t // Create a task, storing the handle.\n\t task_create( vTaskCode, \"NAME\", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\n\n\t // ...\n\n\t // Use the handle to obtain the priority of the created task.\n\t // It was created with tskIDLE_PRIORITY, but may have changed\n\t // it itself.\n\t if( task_get_priority( xHandle ) != tskIDLE_PRIORITY )\n\t {\n\t\t // The task has changed it's priority.\n\t }\n\n\t // ...\n\n\t // Is our priority higher than the created task?\n\t if( task_get_priority( xHandle ) < task_get_priority( NULL ) )\n\t {\n\t\t // Our priority (obtained using NULL handle) is higher.\n\t }\n }\n   </pre>\n * \\defgroup task_get_priority task_get_priority\n * \\ingroup TaskCtrl\n */\nuint32_t task_get_priority( task_t xTask ) ;\n\n/**\n * task. h\n * <pre>uint32_t uxTaskPriorityGetFromISR( task_t xTask );</pre>\n *\n * A version of task_get_priority() that can be used from an ISR.\n */\nuint32_t uxTaskPriorityGetFromISR( task_t xTask ) ;\n\n/**\n * task. h\n * <pre>task_state_e_t task_get_state( task_t xTask );</pre>\n *\n * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.\n * See the configuration section for more information.\n *\n * Obtain the state of any task.  States are encoded by the task_state_e_t\n * enumerated type.\n *\n * @param xTask Handle of the task to be queried.\n *\n * @return The state of xTask at the time the function was called.  Note the\n * state of the task might change between the function being called, and the\n * functions return value being tested by the calling task.\n */\ntask_state_e_t task_get_state( task_t xTask ) ;\n\n/**\n * task. h\n * <pre>void vTaskGetInfo( task_t xTask, TaskStatus_t *pxTaskStatus, int32_t xGetFreeStackSpace, task_state_e_t eState );</pre>\n *\n * configUSE_TRACE_FACILITY must be defined as 1 for this function to be\n * available.  See the configuration section for more information.\n *\n * Populates a TaskStatus_t structure with information about a task.\n *\n * @param xTask Handle of the task being queried.  If xTask is NULL then\n * information will be returned about the calling task.\n *\n * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be\n * filled with information about the task referenced by the handle passed using\n * the xTask parameter.\n *\n * @xGetFreeStackSpace The TaskStatus_t structure contains a member to report\n * the stack high water mark of the task being queried.  Calculating the stack\n * high water mark takes a relatively long time, and can make the system\n * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to\n * allow the high water mark checking to be skipped.  The high watermark value\n * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is\n * not set to pdFALSE;\n *\n * @param eState The TaskStatus_t structure contains a member to report the\n * state of the task being queried.  Obtaining the task state is not as fast as\n * a simple assignment - so the eState parameter is provided to allow the state\n * information to be omitted from the TaskStatus_t structure.  To obtain state\n * information then set eState to E_TASK_STATE_INVALID - otherwise the value passed in\n * eState will be reported as the task state in the TaskStatus_t structure.\n *\n * Example usage:\n   <pre>\n void vAFunction( void )\n {\n task_t xHandle;\n TaskStatus_t xTaskDetails;\n\n    // Obtain the handle of a task from its name.\n    xHandle = task_get_by_name( \"Task_Name\" );\n\n    // Check the handle is not NULL.\n    configASSERT( xHandle );\n\n    // Use the handle to obtain further information about the task.\n    vTaskGetInfo( xHandle,\n                  &xTaskDetails,\n                  pdTRUE, // Include the high water mark in xTaskDetails.\n                  E_TASK_STATE_INVALID ); // Include the task state in xTaskDetails.\n }\n   </pre>\n * \\defgroup vTaskGetInfo vTaskGetInfo\n * \\ingroup TaskCtrl\n */\nvoid vTaskGetInfo( task_t xTask, TaskStatus_t *pxTaskStatus, int32_t xGetFreeStackSpace, task_state_e_t eState ) ;\n\n/**\n * task. h\n * <pre>void task_set_priority( task_t xTask, uint32_t uxNewPriority );</pre>\n *\n * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.\n * See the configuration section for more information.\n *\n * Set the priority of any task.\n *\n * A context switch will occur before the function returns if the priority\n * being set is higher than the currently executing task.\n *\n * @param xTask Handle to the task for which the priority is being set.\n * Passing a NULL handle results in the priority of the calling task being set.\n *\n * @param uxNewPriority The priority to which the task will be set.\n *\n * Example usage:\n   <pre>\n void vAFunction( void )\n {\n task_t xHandle;\n\n\t // Create a task, storing the handle.\n\t task_create( vTaskCode, \"NAME\", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\n\n\t // ...\n\n\t // Use the handle to raise the priority of the created task.\n\t task_set_priority( xHandle, tskIDLE_PRIORITY + 1 );\n\n\t // ...\n\n\t // Use a NULL handle to raise our priority to the same value.\n\t task_set_priority( NULL, tskIDLE_PRIORITY + 1 );\n }\n   </pre>\n * \\defgroup task_set_priority task_set_priority\n * \\ingroup TaskCtrl\n */\nvoid task_set_priority( task_t xTask, uint32_t uxNewPriority ) ;\n\n/**\n * task. h\n * <pre>void task_suspend( task_t xTaskToSuspend );</pre>\n *\n * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.\n * See the configuration section for more information.\n *\n * Suspend any task.  When suspended a task will never get any microcontroller\n * processing time, no matter what its priority.\n *\n * Calls to task_suspend are not accumulative -\n * i.e. calling task_suspend () twice on the same task still only requires one\n * call to task_resume () to ready the suspended task.\n *\n * @param xTaskToSuspend Handle to the task being suspended.  Passing a NULL\n * handle will cause the calling task to be suspended.\n *\n * Example usage:\n   <pre>\n void vAFunction( void )\n {\n task_t xHandle;\n\n\t // Create a task, storing the handle.\n\t task_create( vTaskCode, \"NAME\", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\n\n\t // ...\n\n\t // Use the handle to suspend the created task.\n\t task_suspend( xHandle );\n\n\t // ...\n\n\t // The created task will not run during this period, unless\n\t // another task calls task_resume( xHandle ).\n\n\t //...\n\n\n\t // Suspend ourselves.\n\t task_suspend( NULL );\n\n\t // We cannot get here unless another task calls task_resume\n\t // with our handle as the parameter.\n }\n   </pre>\n * \\defgroup task_suspend task_suspend\n * \\ingroup TaskCtrl\n */\nvoid task_suspend( task_t xTaskToSuspend ) ;\n\n/**\n * task. h\n * <pre>void task_resume( task_t xTaskToResume );</pre>\n *\n * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.\n * See the configuration section for more information.\n *\n * Resumes a suspended task.\n *\n * A task that has been suspended by one or more calls to task_suspend ()\n * will be made available for running again by a single call to\n * task_resume ().\n *\n * @param xTaskToResume Handle to the task being readied.\n *\n * Example usage:\n   <pre>\n void vAFunction( void )\n {\n task_t xHandle;\n\n\t // Create a task, storing the handle.\n\t task_create( vTaskCode, \"NAME\", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\n\n\t // ...\n\n\t // Use the handle to suspend the created task.\n\t task_suspend( xHandle );\n\n\t // ...\n\n\t // The created task will not run during this period, unless\n\t // another task calls task_resume( xHandle ).\n\n\t //...\n\n\n\t // Resume the suspended task ourselves.\n\t task_resume( xHandle );\n\n\t // The created task will once again get microcontroller processing\n\t // time in accordance with its priority within the system.\n }\n   </pre>\n * \\defgroup task_resume task_resume\n * \\ingroup TaskCtrl\n */\nvoid task_resume( task_t xTaskToResume ) ;\n\n/**\n * task. h\n * <pre>void xTaskResumeFromISR( task_t xTaskToResume );</pre>\n *\n * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be\n * available.  See the configuration section for more information.\n *\n * An implementation of task_resume() that can be called from within an ISR.\n *\n * A task that has been suspended by one or more calls to task_suspend ()\n * will be made available for running again by a single call to\n * xTaskResumeFromISR ().\n *\n * xTaskResumeFromISR() should not be used to synchronise a task with an\n * interrupt if there is a chance that the interrupt could arrive prior to the\n * task being suspended - as this can lead to interrupts being missed. Use of a\n * semaphore as a synchronisation mechanism would avoid this eventuality.\n *\n * @param xTaskToResume Handle to the task being readied.\n *\n * @return pdTRUE if resuming the task should result in a context switch,\n * otherwise pdFALSE. This is used by the ISR to determine if a context switch\n * may be required following the ISR.\n *\n * \\defgroup vTaskResumeFromISR vTaskResumeFromISR\n * \\ingroup TaskCtrl\n */\nint32_t xTaskResumeFromISR( task_t xTaskToResume ) ;\n\n/*-----------------------------------------------------------\n * SCHEDULER CONTROL\n *----------------------------------------------------------*/\n\n/**\n * task. h\n * <pre>void rtos_sched_start( void );</pre>\n *\n * Starts the real time kernel tick processing.  After calling the kernel\n * has control over which tasks are executed and when.\n *\n * See the demo application file main.c for an example of creating\n * tasks and starting the kernel.\n *\n * Example usage:\n   <pre>\n void vAFunction( void )\n {\n\t // Create at least one task before starting the kernel.\n\t task_create( vTaskCode, \"NAME\", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\n\n\t // Start the real time kernel with preemption.\n\t rtos_sched_start ();\n\n\t // Will not get here unless a task calls rtos_sched_stop ()\n }\n   </pre>\n *\n * \\defgroup rtos_sched_start rtos_sched_start\n * \\ingroup SchedulerControl\n */\nvoid rtos_sched_start( void ) ;\n\n/**\n * task. h\n * <pre>void rtos_sched_stop( void );</pre>\n *\n * NOTE:  At the time of writing only the x86 real mode port, which runs on a PC\n * in place of DOS, implements this function.\n *\n * Stops the real time kernel tick.  All created tasks will be automatically\n * deleted and multitasking (either preemptive or cooperative) will\n * stop.  Execution then resumes from the point where rtos_sched_start ()\n * was called, as if rtos_sched_start () had just returned.\n *\n * See the demo application file main. c in the demo/PC directory for an\n * example that uses rtos_sched_stop ().\n *\n * rtos_sched_stop () requires an exit function to be defined within the\n * portable layer (see vPortEndScheduler () in port. c for the PC port).  This\n * performs hardware specific operations such as stopping the kernel tick.\n *\n * rtos_sched_stop () will cause all of the resources allocated by the\n * kernel to be freed - but will not free resources allocated by application\n * tasks.\n *\n * Example usage:\n   <pre>\n void vTaskCode( void * pvParameters )\n {\n\t for( ;; )\n\t {\n\t\t // Task code goes here.\n\n\t\t // At some point we want to end the real time kernel processing\n\t\t // so call ...\n\t\t rtos_sched_stop ();\n\t }\n }\n\n void vAFunction( void )\n {\n\t // Create at least one task before starting the kernel.\n\t task_create( vTaskCode, \"NAME\", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\n\n\t // Start the real time kernel with preemption.\n\t rtos_sched_start ();\n\n\t // Will only get here when the vTaskCode () task has called\n\t // rtos_sched_stop ().  When we get here we are back to single task\n\t // execution.\n }\n   </pre>\n *\n * \\defgroup rtos_sched_stop rtos_sched_stop\n * \\ingroup SchedulerControl\n */\nvoid rtos_sched_stop( void ) ;\n\n/**\n * task. h\n * <pre>void rtos_suspend_all( void );</pre>\n *\n * Suspends the scheduler without disabling interrupts.  Context switches will\n * not occur while the scheduler is suspended.\n *\n * After calling rtos_suspend_all () the calling task will continue to execute\n * without risk of being swapped out until a call to rtos_resume_all () has been\n * made.\n *\n * API functions that have the potential to cause a context switch (for example,\n * task_delay_until(), xQueueSend(), etc.) must not be called while the scheduler\n * is suspended.\n *\n * Example usage:\n   <pre>\n void vTask1( void * pvParameters )\n {\n\t for( ;; )\n\t {\n\t\t // Task code goes here.\n\n\t\t // ...\n\n\t\t // At some point the task wants to perform a long operation during\n\t\t // which it does not want to get swapped out.  It cannot use\n\t\t // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the\n\t\t // operation may cause interrupts to be missed - including the\n\t\t // ticks.\n\n\t\t // Prevent the real time kernel swapping out the task.\n\t\t rtos_suspend_all ();\n\n\t\t // Perform the operation here.  There is no need to use critical\n\t\t // sections as we have all the microcontroller processing time.\n\t\t // During this time interrupts will still operate and the kernel\n\t\t // tick count will be maintained.\n\n\t\t // ...\n\n\t\t // The operation is complete.  Restart the kernel.\n\t\t rtos_resume_all ();\n\t }\n }\n   </pre>\n * \\defgroup rtos_suspend_all rtos_suspend_all\n * \\ingroup SchedulerControl\n */\nvoid rtos_suspend_all( void ) ;\n\n/**\n * task. h\n * <pre>int32_t rtos_resume_all( void );</pre>\n *\n * Resumes scheduler activity after it was suspended by a call to\n * rtos_suspend_all().\n *\n * rtos_resume_all() only resumes the scheduler.  It does not unsuspend tasks\n * that were previously suspended by a call to task_suspend().\n *\n * @return If resuming the scheduler caused a context switch then pdTRUE is\n *\t\t  returned, otherwise pdFALSE is returned.\n *\n * Example usage:\n   <pre>\n void vTask1( void * pvParameters )\n {\n\t for( ;; )\n\t {\n\t\t // Task code goes here.\n\n\t\t // ...\n\n\t\t // At some point the task wants to perform a long operation during\n\t\t // which it does not want to get swapped out.  It cannot use\n\t\t // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the\n\t\t // operation may cause interrupts to be missed - including the\n\t\t // ticks.\n\n\t\t // Prevent the real time kernel swapping out the task.\n\t\t rtos_suspend_all ();\n\n\t\t // Perform the operation here.  There is no need to use critical\n\t\t // sections as we have all the microcontroller processing time.\n\t\t // During this time interrupts will still operate and the real\n\t\t // time kernel tick count will be maintained.\n\n\t\t // ...\n\n\t\t // The operation is complete.  Restart the kernel.  We want to force\n\t\t // a context switch - but there is no point if resuming the scheduler\n\t\t // caused a context switch already.\n\t\t if( !rtos_resume_all () )\n\t\t {\n\t\t\t  taskYIELD ();\n\t\t }\n\t }\n }\n   </pre>\n * \\defgroup rtos_resume_all rtos_resume_all\n * \\ingroup SchedulerControl\n */\nint32_t rtos_resume_all( void ) ;\n\n/*-----------------------------------------------------------\n * TASK UTILITIES\n *----------------------------------------------------------*/\n\n/**\n * task. h\n * <PRE>uint32_t millis( void );</PRE>\n *\n * @return The count of ticks since rtos_sched_start was called.\n *\n * \\defgroup millis millis\n * \\ingroup TaskUtils\n */\nuint32_t millis( void ) ;\n\n/**\n * task. h\n * <PRE>uint32_t xTaskGetTickCountFromISR( void );</PRE>\n *\n * @return The count of ticks since rtos_sched_start was called.\n *\n * This is a version of millis() that is safe to be called from an\n * ISR - provided that uint32_t is the natural word size of the\n * microcontroller being used or interrupt nesting is either not supported or\n * not being used.\n *\n * \\defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR\n * \\ingroup TaskUtils\n */\nuint32_t xTaskGetTickCountFromISR( void ) ;\n\n/**\n * task. h\n * <PRE>uint16_t task_get_count( void );</PRE>\n *\n * @return The number of tasks that the real time kernel is currently managing.\n * This includes all ready, blocked and suspended tasks.  A task that\n * has been deleted but not yet freed by the idle task will also be\n * included in the count.\n *\n * \\defgroup task_get_count task_get_count\n * \\ingroup TaskUtils\n */\nuint32_t task_get_count( void ) ;\n\n/**\n * task. h\n * <PRE>char *task_get_name( task_t xTaskToQuery );</PRE>\n *\n * @return The text (human readable) name of the task referenced by the handle\n * xTaskToQuery.  A task can query its own name by either passing in its own\n * handle, or by setting xTaskToQuery to NULL.\n *\n * \\defgroup task_get_name task_get_name\n * \\ingroup TaskUtils\n */\nchar *task_get_name( task_t xTaskToQuery ) ; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\n/**\n * task. h\n * <PRE>task_t task_get_by_name( const char *pcNameToQuery );</PRE>\n *\n * NOTE:  This function takes a relatively long time to complete and should be\n * used sparingly.\n *\n * @return The handle of the task that has the human readable name pcNameToQuery.\n * NULL is returned if no matching name is found.  INCLUDE_xTaskGetHandle\n * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.\n *\n * \\defgroup pcTaskGetHandle pcTaskGetHandle\n * \\ingroup TaskUtils\n */\ntask_t task_get_by_name( const char *pcNameToQuery ) ; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\n/**\n * task.h\n * <PRE>uint32_t uxTaskGetStackHighWaterMark( task_t xTask );</PRE>\n *\n * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for\n * this function to be available.\n *\n * Returns the high water mark of the stack associated with xTask.  That is,\n * the minimum free stack space there has been (in words, so on a 32 bit machine\n * a value of 1 means 4 bytes) since the task started.  The smaller the returned\n * number the closer the task has come to overflowing its stack.\n *\n * @param xTask Handle of the task associated with the stack to be checked.\n * Set xTask to NULL to check the stack of the calling task.\n *\n * @return The smallest amount of free stack space there has been (in words, so\n * actual spaces on the stack rather than bytes) since the task referenced by\n * xTask was created.\n */\nuint32_t uxTaskGetStackHighWaterMark( task_t xTask ) ;\n\n/* When using trace macros it is sometimes necessary to include task.h before\nFreeRTOS.h.  When this is done TaskHookFunction_t will not yet have been defined,\nso the following two prototypes will cause a compilation error.  This can be\nfixed by simply guarding against the inclusion of these two prototypes unless\nthey are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration\nconstant. */\n#ifdef configUSE_APPLICATION_TASK_TAG\n\t#if configUSE_APPLICATION_TASK_TAG == 1\n\t\t/**\n\t\t * task.h\n\t\t * <pre>void vTaskSetApplicationTaskTag( task_t xTask, TaskHookFunction_t pxHookFunction );</pre>\n\t\t *\n\t\t * Sets pxHookFunction to be the task hook function used by the task xTask.\n\t\t * Passing xTask as NULL has the effect of setting the calling tasks hook\n\t\t * function.\n\t\t */\n\t\tvoid vTaskSetApplicationTaskTag( task_t xTask, TaskHookFunction_t pxHookFunction ) ;\n\n\t\t/**\n\t\t * task.h\n\t\t * <pre>void xTaskGetApplicationTaskTag( task_t xTask );</pre>\n\t\t *\n\t\t * Returns the pxHookFunction value assigned to the task xTask.\n\t\t */\n\t\tTaskHookFunction_t xTaskGetApplicationTaskTag( task_t xTask ) ;\n\t#endif /* configUSE_APPLICATION_TASK_TAG ==1 */\n#endif /* ifdef configUSE_APPLICATION_TASK_TAG */\n\n#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )\n\n\t/* Each task contains an array of pointers that is dimensioned by the\n\tconfigNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h.  The\n\tkernel does not use the pointers itself, so the application writer can use\n\tthe pointers for any purpose they wish.  The following two functions are\n\tused to set and query a pointer respectively. */\n\tvoid vTaskSetThreadLocalStoragePointer( task_t xTaskToSet, int32_t xIndex, void *pvValue ) ;\n\tvoid *pvTaskGetThreadLocalStoragePointer( task_t xTaskToQuery, int32_t xIndex ) ;\n\n#endif\n\n/**\n * task.h\n * <pre>int32_t xTaskCallApplicationTaskHook( task_t xTask, void *pvParameter );</pre>\n *\n * Calls the hook function associated with xTask.  Passing xTask as NULL has\n * the effect of calling the Running tasks (the calling task) hook function.\n *\n * pvParameter is passed to the hook function for the task to interpret as it\n * wants.  The return value is the value returned by the task hook function\n * registered by the user.\n */\nint32_t xTaskCallApplicationTaskHook( task_t xTask, void *pvParameter ) ;\n\n/**\n * xTaskGetIdleTaskHandle() is only available if\n * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.\n *\n * Simply returns the handle of the idle task.  It is not valid to call\n * xTaskGetIdleTaskHandle() before the scheduler has been started.\n */\ntask_t xTaskGetIdleTaskHandle( void ) ;\n\n/**\n * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for\n * uxTaskGetSystemState() to be available.\n *\n * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in\n * the system.  TaskStatus_t structures contain, among other things, members\n * for the task handle, task name, task priority, task state, and total amount\n * of run time consumed by the task.  See the TaskStatus_t structure\n * definition in this file for the full member list.\n *\n * NOTE:  This function is intended for debugging use only as its use results in\n * the scheduler remaining suspended for an extended period.\n *\n * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.\n * The array must contain at least one TaskStatus_t structure for each task\n * that is under the control of the RTOS.  The number of tasks under the control\n * of the RTOS can be determined using the task_get_count() API function.\n *\n * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray\n * parameter.  The size is specified as the number of indexes in the array, or\n * the number of TaskStatus_t structures contained in the array, not by the\n * number of bytes in the array.\n *\n * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in\n * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the\n * total run time (as defined by the run time stats clock, see\n * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.\n * pulTotalRunTime can be set to NULL to omit the total run time information.\n *\n * @return The number of TaskStatus_t structures that were populated by\n * uxTaskGetSystemState().  This should equal the number returned by the\n * task_get_count() API function, but will be zero if the value passed\n * in the uxArraySize parameter was too small.\n *\n * Example usage:\n   <pre>\n    // This example demonstrates how a human readable table of run time stats\n\t// information is generated from raw data provided by uxTaskGetSystemState().\n\t// The human readable table is written to pcWriteBuffer\n\tvoid vTaskGetRunTimeStats( char *pcWriteBuffer )\n\t{\n\tTaskStatus_t *pxTaskStatusArray;\n\tvolatile uint32_t uxArraySize, x;\n\tuint32_t ulTotalRunTime, ulStatsAsPercentage;\n\n\t\t// Make sure the write buffer does not contain a string.\n\t\t*pcWriteBuffer = 0x00;\n\n\t\t// Take a snapshot of the number of tasks in case it changes while this\n\t\t// function is executing.\n\t\tuxArraySize = task_get_count();\n\n\t\t// Allocate a TaskStatus_t structure for each task.  An array could be\n\t\t// allocated statically at compile time.\n\t\tpxTaskStatusArray = kmalloc( uxArraySize * sizeof( TaskStatus_t ) );\n\n\t\tif( pxTaskStatusArray != NULL )\n\t\t{\n\t\t\t// Generate raw status information about each task.\n\t\t\tuxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );\n\n\t\t\t// For percentage calculations.\n\t\t\tulTotalRunTime /= 100UL;\n\n\t\t\t// Avoid divide by zero errors.\n\t\t\tif( ulTotalRunTime > 0 )\n\t\t\t{\n\t\t\t\t// For each populated position in the pxTaskStatusArray array,\n\t\t\t\t// format the raw data as human readable ASCII data\n\t\t\t\tfor( x = 0; x < uxArraySize; x++ )\n\t\t\t\t{\n\t\t\t\t\t// What percentage of the total run time has the task used?\n\t\t\t\t\t// This will always be rounded down to the nearest integer.\n\t\t\t\t\t// ulTotalRunTimeDiv100 has already been divided by 100.\n\t\t\t\t\tulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;\n\n\t\t\t\t\tif( ulStatsAsPercentage > 0UL )\n\t\t\t\t\t{\n\t\t\t\t\t\tsprintf( pcWriteBuffer, \"%s\\t\\t%lu\\t\\t%lu%%\\r\\n\", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t// If the percentage is zero here then the task has\n\t\t\t\t\t\t// consumed less than 1% of the total run time.\n\t\t\t\t\t\tsprintf( pcWriteBuffer, \"%s\\t\\t%lu\\t\\t<1%%\\r\\n\", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );\n\t\t\t\t\t}\n\n\t\t\t\t\tpcWriteBuffer += strlen( ( char * ) pcWriteBuffer );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// The array is no longer needed, free the memory it consumes.\n\t\t\tkfree( pxTaskStatusArray );\n\t\t}\n\t}\n\t</pre>\n */\nuint32_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const uint32_t uxArraySize, uint32_t * const pulTotalRunTime ) ;\n\n/**\n * task. h\n * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>\n *\n * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must\n * both be defined as 1 for this function to be available.  See the\n * configuration section of the FreeRTOS.org website for more information.\n *\n * NOTE 1: This function will disable interrupts for its duration.  It is\n * not intended for normal application runtime use but as a debug aid.\n *\n * Lists all the current tasks, along with their current state and stack\n * usage high water mark.\n *\n * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or\n * suspended ('S').\n *\n * PLEASE NOTE:\n *\n * This function is provided for convenience only, and is used by many of the\n * demo applications.  Do not consider it to be part of the scheduler.\n *\n * vTaskList() calls uxTaskGetSystemState(), then formats part of the\n * uxTaskGetSystemState() output into a human readable table that displays task\n * names, states and stack usage.\n *\n * vTaskList() has a dependency on the sprintf() C library function that might\n * bloat the code size, use a lot of stack, and provide different results on\n * different platforms.  An alternative, tiny, third party, and limited\n * functionality implementation of sprintf() is provided in many of the\n * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note\n * printf-stdarg.c does not provide a full snprintf() implementation!).\n *\n * It is recommended that production systems call uxTaskGetSystemState()\n * directly to get access to raw stats data, rather than indirectly through a\n * call to vTaskList().\n *\n * @param pcWriteBuffer A buffer into which the above mentioned details\n * will be written, in ASCII form.  This buffer is assumed to be large\n * enough to contain the generated report.  Approximately 40 bytes per\n * task should be sufficient.\n *\n * \\defgroup vTaskList vTaskList\n * \\ingroup TaskUtils\n */\nvoid vTaskList( char * pcWriteBuffer ) ; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\n/**\n * task. h\n * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>\n *\n * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS\n * must both be defined as 1 for this function to be available.  The application\n * must also then provide definitions for\n * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()\n * to configure a peripheral timer/counter and return the timers current count\n * value respectively.  The counter should be at least 10 times the frequency of\n * the tick count.\n *\n * NOTE 1: This function will disable interrupts for its duration.  It is\n * not intended for normal application runtime use but as a debug aid.\n *\n * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total\n * accumulated execution time being stored for each task.  The resolution\n * of the accumulated time value depends on the frequency of the timer\n * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.\n * Calling vTaskGetRunTimeStats() writes the total execution time of each\n * task into a buffer, both as an absolute count value and as a percentage\n * of the total system execution time.\n *\n * NOTE 2:\n *\n * This function is provided for convenience only, and is used by many of the\n * demo applications.  Do not consider it to be part of the scheduler.\n *\n * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the\n * uxTaskGetSystemState() output into a human readable table that displays the\n * amount of time each task has spent in the Running state in both absolute and\n * percentage terms.\n *\n * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function\n * that might bloat the code size, use a lot of stack, and provide different\n * results on different platforms.  An alternative, tiny, third party, and\n * limited functionality implementation of sprintf() is provided in many of the\n * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note\n * printf-stdarg.c does not provide a full snprintf() implementation!).\n *\n * It is recommended that production systems call uxTaskGetSystemState() directly\n * to get access to raw stats data, rather than indirectly through a call to\n * vTaskGetRunTimeStats().\n *\n * @param pcWriteBuffer A buffer into which the execution times will be\n * written, in ASCII form.  This buffer is assumed to be large enough to\n * contain the generated report.  Approximately 40 bytes per task should\n * be sufficient.\n *\n * \\defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats\n * \\ingroup TaskUtils\n */\nvoid vTaskGetRunTimeStats( char *pcWriteBuffer ) ; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\n/**\n * task. h\n * <PRE>int32_t xTaskNotify( task_t xTaskToNotify, uint32_t ulValue, notify_action_e_t eAction );</PRE>\n *\n * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this\n * function to be available.\n *\n * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private\n * \"notification value\", which is a 32-bit unsigned integer (uint32_t).\n *\n * Events can be sent to a task using an intermediary object.  Examples of such\n * objects are queues, semaphores, mutexes and event groups.  Task notifications\n * are a method of sending an event directly to a task without the need for such\n * an intermediary object.\n *\n * A notification sent to a task can optionally perform an action, such as\n * update, overwrite or increment the task's notification value.  In that way\n * task notifications can be used to send data to a task, or be used as light\n * weight and fast binary or counting semaphores.\n *\n * A notification sent to a task will remain pending until it is cleared by the\n * task calling task_notify_wait() or task_notify_take().  If the task was\n * already in the Blocked state to wait for a notification when the notification\n * arrives then the task will automatically be removed from the Blocked state\n * (unblocked) and the notification cleared.\n *\n * A task can use task_notify_wait() to [optionally] block to wait for a\n * notification to be pending, or task_notify_take() to [optionally] block\n * to wait for its notification value to have a non-zero value.  The task does\n * not consume any CPU time while it is in the Blocked state.\n *\n * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.\n *\n * @param xTaskToNotify The handle of the task being notified.  The handle to a\n * task can be returned from the task_create() API function used to create the\n * task, and the handle of the currently running task can be obtained by calling\n * task_get_current().\n *\n * @param ulValue Data that can be sent with the notification.  How the data is\n * used depends on the value of the eAction parameter.\n *\n * @param eAction Specifies how the notification updates the task's notification\n * value, if at all.  Valid values for eAction are as follows:\n *\n * E_NOTIFY_ACTION_BITS -\n * The task's notification value is bitwise ORed with ulValue.  xTaskNofify()\n * always returns pdPASS in this case.\n *\n * E_NOTIFY_ACTION_INCR -\n * The task's notification value is incremented.  ulValue is not used and\n * xTaskNotify() always returns pdPASS in this case.\n *\n * E_NOTIFY_ACTION_OWRITE -\n * The task's notification value is set to the value of ulValue, even if the\n * task being notified had not yet processed the previous notification (the\n * task already had a notification pending).  xTaskNotify() always returns\n * pdPASS in this case.\n *\n * E_NOTIFY_ACTION_NO_OWRITE -\n * If the task being notified did not already have a notification pending then\n * the task's notification value is set to ulValue and xTaskNotify() will\n * return pdPASS.  If the task being notified already had a notification\n * pending then no action is performed and pdFAIL is returned.\n *\n * E_NOTIFY_ACTION_NONE -\n * The task receives a notification without its notification value being\n * updated.  ulValue is not used and xTaskNotify() always returns pdPASS in\n * this case.\n *\n *  pulPreviousNotificationValue -\n *  Can be used to pass out the subject task's notification value before any\n *  bits are modified by the notify function.\n *\n * @return Dependent on the value of eAction.  See the description of the\n * eAction parameter.\n *\n * \\defgroup xTaskNotify xTaskNotify\n * \\ingroup TaskNotifications\n */\nint32_t task_notify_ext( task_t xTaskToNotify, uint32_t ulValue, notify_action_e_t eAction, uint32_t *pulPreviousNotificationValue ) ;\n#define xTaskNotify( xTaskToNotify, ulValue, eAction ) task_notify_ext( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL )\n#define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) task_notify_ext( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )\n\n/**\n * task. h\n * <PRE>int32_t xTaskNotifyFromISR( task_t xTaskToNotify, uint32_t ulValue, notify_action_e_t eAction, int32_t *pxHigherPriorityTaskWoken );</PRE>\n *\n * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this\n * function to be available.\n *\n * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private\n * \"notification value\", which is a 32-bit unsigned integer (uint32_t).\n *\n * A version of xTaskNotify() that can be used from an interrupt service routine\n * (ISR).\n *\n * Events can be sent to a task using an intermediary object.  Examples of such\n * objects are queues, semaphores, mutexes and event groups.  Task notifications\n * are a method of sending an event directly to a task without the need for such\n * an intermediary object.\n *\n * A notification sent to a task can optionally perform an action, such as\n * update, overwrite or increment the task's notification value.  In that way\n * task notifications can be used to send data to a task, or be used as light\n * weight and fast binary or counting semaphores.\n *\n * A notification sent to a task will remain pending until it is cleared by the\n * task calling task_notify_wait() or task_notify_take().  If the task was\n * already in the Blocked state to wait for a notification when the notification\n * arrives then the task will automatically be removed from the Blocked state\n * (unblocked) and the notification cleared.\n *\n * A task can use task_notify_wait() to [optionally] block to wait for a\n * notification to be pending, or task_notify_take() to [optionally] block\n * to wait for its notification value to have a non-zero value.  The task does\n * not consume any CPU time while it is in the Blocked state.\n *\n * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.\n *\n * @param xTaskToNotify The handle of the task being notified.  The handle to a\n * task can be returned from the task_create() API function used to create the\n * task, and the handle of the currently running task can be obtained by calling\n * task_get_current().\n *\n * @param ulValue Data that can be sent with the notification.  How the data is\n * used depends on the value of the eAction parameter.\n *\n * @param eAction Specifies how the notification updates the task's notification\n * value, if at all.  Valid values for eAction are as follows:\n *\n * E_NOTIFY_ACTION_BITS -\n * The task's notification value is bitwise ORed with ulValue.  xTaskNofify()\n * always returns pdPASS in this case.\n *\n * E_NOTIFY_ACTION_INCR -\n * The task's notification value is incremented.  ulValue is not used and\n * xTaskNotify() always returns pdPASS in this case.\n *\n * E_NOTIFY_ACTION_OWRITE -\n * The task's notification value is set to the value of ulValue, even if the\n * task being notified had not yet processed the previous notification (the\n * task already had a notification pending).  xTaskNotify() always returns\n * pdPASS in this case.\n *\n * E_NOTIFY_ACTION_NO_OWRITE -\n * If the task being notified did not already have a notification pending then\n * the task's notification value is set to ulValue and xTaskNotify() will\n * return pdPASS.  If the task being notified already had a notification\n * pending then no action is performed and pdFAIL is returned.\n *\n * E_NOTIFY_ACTION_NONE -\n * The task receives a notification without its notification value being\n * updated.  ulValue is not used and xTaskNotify() always returns pdPASS in\n * this case.\n *\n * @param pxHigherPriorityTaskWoken  xTaskNotifyFromISR() will set\n * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the\n * task to which the notification was sent to leave the Blocked state, and the\n * unblocked task has a priority higher than the currently running task.  If\n * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should\n * be requested before the interrupt is exited.  How a context switch is\n * requested from an ISR is dependent on the port - see the documentation page\n * for the port in use.\n *\n * @return Dependent on the value of eAction.  See the description of the\n * eAction parameter.\n *\n * \\defgroup xTaskNotify xTaskNotify\n * \\ingroup TaskNotifications\n */\nint32_t xTaskGenericNotifyFromISR( task_t xTaskToNotify, uint32_t ulValue, notify_action_e_t eAction, uint32_t *pulPreviousNotificationValue, int32_t *pxHigherPriorityTaskWoken ) ;\n#define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )\n#define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )\n\n/**\n * task. h\n * <PRE>int32_t task_notify_wait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, uint32_t xTicksToWait );</pre>\n *\n * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this\n * function to be available.\n *\n * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private\n * \"notification value\", which is a 32-bit unsigned integer (uint32_t).\n *\n * Events can be sent to a task using an intermediary object.  Examples of such\n * objects are queues, semaphores, mutexes and event groups.  Task notifications\n * are a method of sending an event directly to a task without the need for such\n * an intermediary object.\n *\n * A notification sent to a task can optionally perform an action, such as\n * update, overwrite or increment the task's notification value.  In that way\n * task notifications can be used to send data to a task, or be used as light\n * weight and fast binary or counting semaphores.\n *\n * A notification sent to a task will remain pending until it is cleared by the\n * task calling task_notify_wait() or task_notify_take().  If the task was\n * already in the Blocked state to wait for a notification when the notification\n * arrives then the task will automatically be removed from the Blocked state\n * (unblocked) and the notification cleared.\n *\n * A task can use task_notify_wait() to [optionally] block to wait for a\n * notification to be pending, or task_notify_take() to [optionally] block\n * to wait for its notification value to have a non-zero value.  The task does\n * not consume any CPU time while it is in the Blocked state.\n *\n * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.\n *\n * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value\n * will be cleared in the calling task's notification value before the task\n * checks to see if any notifications are pending, and optionally blocks if no\n * notifications are pending.  Setting ulBitsToClearOnEntry to ULONG_MAX (if\n * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have\n * the effect of resetting the task's notification value to 0.  Setting\n * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.\n *\n * @param ulBitsToClearOnExit If a notification is pending or received before\n * the calling task exits the task_notify_wait() function then the task's\n * notification value (see the xTaskNotify() API function) is passed out using\n * the pulNotificationValue parameter.  Then any bits that are set in\n * ulBitsToClearOnExit will be cleared in the task's notification value (note\n * *pulNotificationValue is set before any bits are cleared).  Setting\n * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL\n * (if limits.h is not included) will have the effect of resetting the task's\n * notification value to 0 before the function exits.  Setting\n * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged\n * when the function exits (in which case the value passed out in\n * pulNotificationValue will match the task's notification value).\n *\n * @param pulNotificationValue Used to pass the task's notification value out\n * of the function.  Note the value passed out will not be effected by the\n * clearing of any bits caused by ulBitsToClearOnExit being non-zero.\n *\n * @param xTicksToWait The maximum amount of time that the task should wait in\n * the Blocked state for a notification to be received, should a notification\n * not already be pending when task_notify_wait() was called.  The task\n * will not consume any processing time while it is in the Blocked state.  This\n * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be\n * used to convert a time specified in milliseconds to a time specified in\n * ticks.\n *\n * @return If a notification was received (including notifications that were\n * already pending when task_notify_wait was called) then pdPASS is\n * returned.  Otherwise pdFAIL is returned.\n *\n * \\defgroup task_notify_wait task_notify_wait\n * \\ingroup TaskNotifications\n */\nint32_t task_notify_wait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, uint32_t xTicksToWait ) ;\n\n/**\n * task. h\n * <PRE>int32_t task_notify( task_t xTaskToNotify );</PRE>\n *\n * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro\n * to be available.\n *\n * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private\n * \"notification value\", which is a 32-bit unsigned integer (uint32_t).\n *\n * Events can be sent to a task using an intermediary object.  Examples of such\n * objects are queues, semaphores, mutexes and event groups.  Task notifications\n * are a method of sending an event directly to a task without the need for such\n * an intermediary object.\n *\n * A notification sent to a task can optionally perform an action, such as\n * update, overwrite or increment the task's notification value.  In that way\n * task notifications can be used to send data to a task, or be used as light\n * weight and fast binary or counting semaphores.\n *\n * xTaskNotifyGive() is a helper macro intended for use when task notifications\n * are used as light weight and faster binary or counting semaphore equivalents.\n * Actual FreeRTOS semaphores are given using the sem_post() API function,\n * the equivalent action that instead uses a task notification is\n * xTaskNotifyGive().\n *\n * When task notifications are being used as a binary or counting semaphore\n * equivalent then the task being notified should wait for the notification\n * using the ulTaskNotificationTake() API function rather than the\n * task_notify_wait() API function.\n *\n * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.\n *\n * @param xTaskToNotify The handle of the task being notified.  The handle to a\n * task can be returned from the task_create() API function used to create the\n * task, and the handle of the currently running task can be obtained by calling\n * task_get_current().\n *\n * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the\n * eAction parameter set to E_NOTIFY_ACTION_INCR - so pdPASS is always returned.\n *\n * \\defgroup xTaskNotifyGive xTaskNotifyGive\n * \\ingroup TaskNotifications\n */\nint32_t task_notify(task_t xTaskToNotify);\n\n/**\n * task. h\n * <PRE>void vTaskNotifyGiveFromISR( task_t xTaskHandle, int32_t *pxHigherPriorityTaskWoken );\n *\n * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro\n * to be available.\n *\n * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private\n * \"notification value\", which is a 32-bit unsigned integer (uint32_t).\n *\n * A version of xTaskNotifyGive() that can be called from an interrupt service\n * routine (ISR).\n *\n * Events can be sent to a task using an intermediary object.  Examples of such\n * objects are queues, semaphores, mutexes and event groups.  Task notifications\n * are a method of sending an event directly to a task without the need for such\n * an intermediary object.\n *\n * A notification sent to a task can optionally perform an action, such as\n * update, overwrite or increment the task's notification value.  In that way\n * task notifications can be used to send data to a task, or be used as light\n * weight and fast binary or counting semaphores.\n *\n * vTaskNotifyGiveFromISR() is intended for use when task notifications are\n * used as light weight and faster binary or counting semaphore equivalents.\n * Actual FreeRTOS semaphores are given from an ISR using the\n * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses\n * a task notification is vTaskNotifyGiveFromISR().\n *\n * When task notifications are being used as a binary or counting semaphore\n * equivalent then the task being notified should wait for the notification\n * using the ulTaskNotificationTake() API function rather than the\n * task_notify_wait() API function.\n *\n * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.\n *\n * @param xTaskToNotify The handle of the task being notified.  The handle to a\n * task can be returned from the task_create() API function used to create the\n * task, and the handle of the currently running task can be obtained by calling\n * task_get_current().\n *\n * @param pxHigherPriorityTaskWoken  vTaskNotifyGiveFromISR() will set\n * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the\n * task to which the notification was sent to leave the Blocked state, and the\n * unblocked task has a priority higher than the currently running task.  If\n * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch\n * should be requested before the interrupt is exited.  How a context switch is\n * requested from an ISR is dependent on the port - see the documentation page\n * for the port in use.\n *\n * \\defgroup task_notify_wait task_notify_wait\n * \\ingroup TaskNotifications\n */\nvoid vTaskNotifyGiveFromISR( task_t xTaskToNotify, int32_t *pxHigherPriorityTaskWoken ) ;\n\n/**\n * task. h\n * <PRE>uint32_t task_notify_take( int32_t xClearCountOnExit, uint32_t xTicksToWait );</pre>\n *\n * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this\n * function to be available.\n *\n * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private\n * \"notification value\", which is a 32-bit unsigned integer (uint32_t).\n *\n * Events can be sent to a task using an intermediary object.  Examples of such\n * objects are queues, semaphores, mutexes and event groups.  Task notifications\n * are a method of sending an event directly to a task without the need for such\n * an intermediary object.\n *\n * A notification sent to a task can optionally perform an action, such as\n * update, overwrite or increment the task's notification value.  In that way\n * task notifications can be used to send data to a task, or be used as light\n * weight and fast binary or counting semaphores.\n *\n * task_notify_take() is intended for use when a task notification is used as a\n * faster and lighter weight binary or counting semaphore alternative.  Actual\n * FreeRTOS semaphores are taken using the sem_wait() API function, the\n * equivalent action that instead uses a task notification is\n * task_notify_take().\n *\n * When a task is using its notification value as a binary or counting semaphore\n * other tasks should send notifications to it using the xTaskNotifyGive()\n * macro, or xTaskNotify() function with the eAction parameter set to\n * E_NOTIFY_ACTION_INCR.\n *\n * task_notify_take() can either clear the task's notification value to\n * zero on exit, in which case the notification value acts like a binary\n * semaphore, or decrement the task's notification value on exit, in which case\n * the notification value acts like a counting semaphore.\n *\n * A task can use task_notify_take() to [optionally] block to wait for a\n * the task's notification value to be non-zero.  The task does not consume any\n * CPU time while it is in the Blocked state.\n *\n * Where as task_notify_wait() will return when a notification is pending,\n * task_notify_take() will return when the task's notification value is\n * not zero.\n *\n * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.\n *\n * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's\n * notification value is decremented when the function exits.  In this way the\n * notification value acts like a counting semaphore.  If xClearCountOnExit is\n * not pdFALSE then the task's notification value is cleared to zero when the\n * function exits.  In this way the notification value acts like a binary\n * semaphore.\n *\n * @param xTicksToWait The maximum amount of time that the task should wait in\n * the Blocked state for the task's notification value to be greater than zero,\n * should the count not already be greater than zero when\n * task_notify_take() was called.  The task will not consume any processing\n * time while it is in the Blocked state.  This is specified in kernel ticks,\n * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time\n * specified in milliseconds to a time specified in ticks.\n *\n * @return The task's notification count before it is either cleared to zero or\n * decremented (see the xClearCountOnExit parameter).\n *\n * \\defgroup task_notify_take task_notify_take\n * \\ingroup TaskNotifications\n */\nuint32_t task_notify_take( bool xClearCountOnExit, uint32_t xTicksToWait ) ;\n\n/**\n * task. h\n * <PRE>int32_t task_notify_clear( task_t xTask );</pre>\n *\n * If the notification state of the task referenced by the handle xTask is\n * eNotified, then set the task's notification state to eNotWaitingNotification.\n * The task's notification value is not altered.  Set xTask to NULL to clear the\n * notification state of the calling task.\n *\n * @return pdTRUE if the task's notification state was set to\n * eNotWaitingNotification, otherwise pdFALSE.\n * \\defgroup task_notify_clear task_notify_clear\n * \\ingroup TaskNotifications\n */\nint32_t task_notify_clear( task_t xTask );\n\n/*-----------------------------------------------------------\n * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES\n *----------------------------------------------------------*/\n\n/*\n * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY\n * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS\n * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\n *\n * Called from the real time kernel tick (either preemptive or cooperative),\n * this increments the tick count and checks if any tasks that are blocked\n * for a finite period required removing from a blocked list and placing on\n * a ready list.  If a non-zero value is returned then a context switch is\n * required because either:\n *   + A task was removed from a blocked list because its timeout had expired,\n *     or\n *   + Time slicing is in use and there is a task of equal priority to the\n *     currently running task.\n */\nint32_t xTaskIncrementTick( void ) ;\n\n/*\n * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\n * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\n *\n * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.\n *\n * Removes the calling task from the ready list and places it both\n * on the list of tasks waiting for a particular event, and the\n * list of delayed tasks.  The task will be removed from both lists\n * and replaced on the ready list should either the event occur (and\n * there be no higher priority tasks waiting on the same event) or\n * the delay period expires.\n *\n * The 'unordered' version replaces the event list item value with the\n * xItemValue value, and inserts the list item at the end of the list.\n *\n * The 'ordered' version uses the existing event list item value (which is the\n * owning tasks priority) to insert the list item into the event list is task\n * priority order.\n *\n * @param pxEventList The list containing tasks that are blocked waiting\n * for the event to occur.\n *\n * @param xItemValue The item value to use for the event list item when the\n * event list is not ordered by task priority.\n *\n * @param xTicksToWait The maximum amount of time that the task should wait\n * for the event to occur.  This is specified in kernel ticks,the constant\n * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time\n * period.\n */\nvoid vTaskPlaceOnEventList( List_t * const pxEventList, const uint32_t xTicksToWait ) ;\nvoid vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const uint32_t xItemValue, const uint32_t xTicksToWait ) ;\n\n/*\n * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\n * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\n *\n * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.\n *\n * This function performs nearly the same function as vTaskPlaceOnEventList().\n * The difference being that this function does not permit tasks to block\n * indefinitely, whereas vTaskPlaceOnEventList() does.\n *\n */\nvoid vTaskPlaceOnEventListRestricted( List_t * const pxEventList, uint32_t xTicksToWait, const int32_t xWaitIndefinitely ) ;\n\n/*\n * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\n * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\n *\n * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.\n *\n * Removes a task from both the specified event list and the list of blocked\n * tasks, and places it on a ready queue.\n *\n * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called\n * if either an event occurs to unblock a task, or the block timeout period\n * expires.\n *\n * xTaskRemoveFromEventList() is used when the event list is in task priority\n * order.  It removes the list item from the head of the event list as that will\n * have the highest priority owning task of all the tasks on the event list.\n * vTaskRemoveFromUnorderedEventList() is used when the event list is not\n * ordered and the event list items hold something other than the owning tasks\n * priority.  In this case the event list item value is updated to the value\n * passed in the xItemValue parameter.\n *\n * @return pdTRUE if the task being removed has a higher priority than the task\n * making the call, otherwise pdFALSE.\n */\nint32_t xTaskRemoveFromEventList( const List_t * const pxEventList ) ;\nvoid vTaskRemoveFromUnorderedEventList( list_item_t * pxEventListItem, const uint32_t xItemValue ) ;\n\n/*\n * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY\n * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS\n * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\n *\n * Sets the pointer to the current TCB to the TCB of the highest priority task\n * that is ready to run.\n */\nvoid vTaskSwitchContext( void ) ;\n\n/*\n * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE.  THEY ARE USED BY\n * THE EVENT BITS MODULE.\n */\nuint32_t uxTaskResetEventItemValue( void ) ;\n\n/*\n * Return the handle of the calling task.\n */\ntask_t task_get_current( void ) ;\n\n/*\n * Capture the current time status for future reference.\n */\nvoid vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) ;\n\n/*\n * Compare the time status now with that previously captured to see if the\n * timeout has expired.\n */\nint32_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, uint32_t * const pxTicksToWait ) ;\n\n/*\n * Shortcut used by the queue implementation to prevent unnecessary call to\n * taskYIELD();\n */\nvoid vTaskMissedYield( void ) ;\n\n/*\n * Returns the scheduler state as taskSCHEDULER_RUNNING,\n * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.\n */\nint32_t xTaskGetSchedulerState( void ) ;\n\n/*\n * Raises the priority of the mutex holder to that of the calling task should\n * the mutex holder have a priority less than the calling task.\n */\nint32_t xTaskPriorityInherit( task_t const pxMutexHolder ) ;\n\n/*\n * Set the priority of a task back to its proper priority in the case that it\n * inherited a higher priority while it was holding a semaphore.\n */\nint32_t xTaskPriorityDisinherit( task_t const pxMutexHolder ) ;\n\n/*\n * If a higher priority task attempting to obtain a mutex caused a lower\n * priority task to inherit the higher priority task's priority - but the higher\n * priority task then timed out without obtaining the mutex, then the lower\n * priority task will disinherit the priority again - but only down as far as\n * the highest priority task that is still waiting for the mutex (if there were\n * more than one task waiting for the mutex).\n */\nvoid vTaskPriorityDisinheritAfterTimeout( task_t const pxMutexHolder, uint32_t uxHighestPriorityWaitingTask ) ;\n\n/*\n * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.\n */\nuint32_t uxTaskGetTaskNumber( task_t xTask ) ;\n\n/*\n * Set the uxTaskNumber of the task referenced by the xTask parameter to\n * uxHandle.\n */\nvoid vTaskSetTaskNumber( task_t xTask, const uint32_t uxHandle ) ;\n\n/*\n * Only available when configUSE_TICKLESS_IDLE is set to 1.\n * If tickless mode is being used, or a low power mode is implemented, then\n * the tick interrupt will not execute during idle periods.  When this is the\n * case, the tick count value maintained by the scheduler needs to be kept up\n * to date with the actual execution time by being skipped forward by a time\n * equal to the idle period.\n */\nvoid vTaskStepTick( const uint32_t xTicksToJump ) ;\n\n/*\n * Only avilable when configUSE_TICKLESS_IDLE is set to 1.\n * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port\n * specific sleep function to determine if it is ok to proceed with the sleep,\n * and if it is ok to proceed, if it is ok to sleep indefinitely.\n *\n * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only\n * called with the scheduler suspended, not from within a critical section.  It\n * is therefore possible for an interrupt to request a context switch between\n * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being\n * entered.  eTaskConfirmSleepModeStatus() should be called from a short\n * critical section between the timer being stopped and the sleep mode being\n * entered to ensure it is ok to proceed into the sleep mode.\n */\neSleepModeStatus eTaskConfirmSleepModeStatus( void ) ;\n\n/*\n * For internal use only.  Increment the mutex held count when a mutex is\n * taken and return the handle of the task that has taken the mutex.\n */\nvoid *pvTaskIncrementMutexHeldCount( void ) ;\n\n/*\n * For internal use only.  Same as vTaskSetTimeOutState(), but without a critial\n * section.\n */\nvoid vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) ;\n\n\n#ifdef __cplusplus\n}\n#endif\n#endif /* INC_TASK_H */\n"
  },
  {
    "path": "include/rtos/tcb.h",
    "content": "#pragma once\n\n#include \"rtos/FreeRTOS.h\"\n#include \"rtos/list.h\"\n\n/*\n * Task control block.  A task control block (TCB) is allocated for each task,\n * and stores task state information, including a pointer to the task's context\n * (the task's run time environment, including register values)\n */\ntypedef struct tskTaskControlBlock\n{\n\tvolatile task_stack_t\t*pxTopOfStack;\t/*< Points to the location of the last item placed on the tasks stack.  THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */\n\n\n\tlist_item_t\t\t\txStateListItem;\t/*< The list that the state list item of a task is reference from denotes the state of that task (Ready, Blocked, Suspended ). */\n\tlist_item_t\t\t\txEventListItem;\t\t/*< Used to reference a task from an event list. */\n\tuint32_t\t\t\tuxPriority;\t\t\t/*< The priority of the task.  0 is the lowest priority. */\n\ttask_stack_t\t\t\t*pxStack;\t\t\t/*< Points to the start of the stack. */\n\tchar\t\t\t\tpcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created.  Facilitates debugging only. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\n\t#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )\n\t\ttask_stack_t\t\t*pxEndOfStack;\t\t/*< Points to the highest valid address for the stack. */\n\t#endif\n\n\t#if ( portCRITICAL_NESTING_IN_TCB == 1 )\n\t\tuint32_t\t\tuxCriticalNesting;\t/*< Holds the critical section nesting depth for ports that do not maintain their own count in the port layer. */\n\t#endif\n\n\t#if ( configUSE_TRACE_FACILITY == 1 )\n\t\tuint32_t\t\tuxTCBNumber;\t\t/*< Stores a number that increments each time a TCB is created.  It allows debuggers to determine when a task has been deleted and then recreated. */\n\t\tuint32_t\t\tuxTaskNumber;\t\t/*< Stores a number specifically for use by third party trace code. */\n\t#endif\n\n\t#if ( configUSE_MUTEXES == 1 )\n\t\tuint32_t\t\tuxBasePriority;\t\t/*< The priority last assigned to the task - used by the priority inheritance mechanism. */\n\t\tuint32_t\t\tuxMutexesHeld;\n\t#endif\n\n\t#if ( configUSE_APPLICATION_TASK_TAG == 1 )\n\t\tTaskHookFunction_t pxTaskTag;\n\t#endif\n\n\t#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )\n\t\tvoid\t\t\t*pvThreadLocalStoragePointers[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];\n\t#endif\n\n\t#if( configGENERATE_RUN_TIME_STATS == 1 )\n\t\tuint32_t\t\tulRunTimeCounter;\t/*< Stores the amount of time the task has spent in the Running state. */\n\t#endif\n\n\t#if ( configUSE_NEWLIB_REENTRANT == 1 )\n\t\t/* Allocate a Newlib reent structure that is specific to this task.\n\t\tNote Newlib support has been included by popular demand, but is not\n\t\tused by the FreeRTOS maintainers themselves.  FreeRTOS is not\n\t\tresponsible for resulting newlib operation.  User must be familiar with\n\t\tnewlib and must provide system-wide implementations of the necessary\n\t\tstubs. Be warned that (at the time of writing) the current newlib design\n\t\timplements a system-wide malloc() that must be provided with locks. */\n\t\tstruct\t_reent xNewLib_reent;\n\t#endif\n\n\t#if( configUSE_TASK_NOTIFICATIONS == 1 )\n\t\tvolatile uint32_t ulNotifiedValue;\n\t\tvolatile uint8_t ucNotifyState;\n\t#endif\n\n\t/* See the comments above the definition of\n\ttskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */\n\t#if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\n\t\tuint8_t\tucStaticallyAllocated; \t\t/*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */\n\t#endif\n\n\t#if( INCLUDE_xTaskAbortDelay == 1 )\n\t\tuint8_t ucDelayAborted;\n\t#endif\n\n} tskTCB;\n\n/* The old tskTCB name is maintained above then typedefed to the new TCB_t name\nbelow to enable the use of older kernel aware debuggers. */\ntypedef tskTCB TCB_t;\n\n/*lint -save -e956 A manual analysis and inspection has been used to determine\nwhich static variables must be declared volatile. */\n\nextern TCB_t * volatile pxCurrentTCB;"
  },
  {
    "path": "include/rtos/timers.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n\n#ifndef TIMERS_H\n#define TIMERS_H\n\n#ifndef INC_FREERTOS_H\n\t#error \"include FreeRTOS.h must appear in source files before include timers.h\"\n#endif\n\n/*lint -save -e537 This headers are only multiply included if the application code\nhappens to also be including task.h. */\n#include \"task.h\"\n/*lint -restore */\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/*-----------------------------------------------------------\n * MACROS AND DEFINITIONS\n *----------------------------------------------------------*/\n\n/* IDs for commands that can be sent/received on the timer queue.  These are to\nbe used solely through the macros that make up the public software timer API,\nas defined below.  The commands that are sent from interrupts must use the\nhighest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task\nor interrupt version of the queue send function should be used. */\n#define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR \t( ( int32_t ) -2 )\n#define tmrCOMMAND_EXECUTE_CALLBACK\t\t\t\t( ( int32_t ) -1 )\n#define tmrCOMMAND_START_DONT_TRACE\t\t\t\t( ( int32_t ) 0 )\n#define tmrCOMMAND_START\t\t\t\t\t    ( ( int32_t ) 1 )\n#define tmrCOMMAND_RESET\t\t\t\t\t\t( ( int32_t ) 2 )\n#define tmrCOMMAND_STOP\t\t\t\t\t\t\t( ( int32_t ) 3 )\n#define tmrCOMMAND_CHANGE_PERIOD\t\t\t\t( ( int32_t ) 4 )\n#define tmrCOMMAND_DELETE\t\t\t\t\t\t( ( int32_t ) 5 )\n\n#define tmrFIRST_FROM_ISR_COMMAND\t\t\t\t( ( int32_t ) 6 )\n#define tmrCOMMAND_START_FROM_ISR\t\t\t\t( ( int32_t ) 6 )\n#define tmrCOMMAND_RESET_FROM_ISR\t\t\t\t( ( int32_t ) 7 )\n#define tmrCOMMAND_STOP_FROM_ISR\t\t\t\t( ( int32_t ) 8 )\n#define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR\t\t( ( int32_t ) 9 )\n\n\n/**\n * Type by which software timers are referenced.  For example, a call to\n * xTimerCreate() returns an TimerHandle_t variable that can then be used to\n * reference the subject timer in calls to other software timer API functions\n * (for example, xTimerStart(), xTimerReset(), etc.).\n */\ntypedef void * TimerHandle_t;\n\n/*\n * Defines the prototype to which timer callback functions must conform.\n */\ntypedef void (*TimerCallbackFunction_t)( TimerHandle_t xTimer );\n\n/*\n * Defines the prototype to which functions used with the\n * xTimerPendFunctionCallFromISR() function must conform.\n */\ntypedef void (*PendedFunction_t)( void *, uint32_t );\n\n/**\n * TimerHandle_t xTimerCreate( \tconst char * const pcTimerName,\n * \t\t\t\t\t\t\t\tuint32_t xTimerPeriodInTicks,\n * \t\t\t\t\t\t\t\tuint32_t uxAutoReload,\n * \t\t\t\t\t\t\t\tvoid * pvTimerID,\n * \t\t\t\t\t\t\t\tTimerCallbackFunction_t pxCallbackFunction );\n *\n * Creates a new software timer instance, and returns a handle by which the\n * created software timer can be referenced.\n *\n * Internally, within the FreeRTOS implementation, software timers use a block\n * of memory, in which the timer data structure is stored.  If a software timer\n * is created using xTimerCreate() then the required memory is automatically\n * dynamically allocated inside the xTimerCreate() function.  (see\n * http://www.freertos.org/a00111.html).  If a software timer is created using\n * xTimerCreateStatic() then the application writer must provide the memory that\n * will get used by the software timer.  xTimerCreateStatic() therefore allows a\n * software timer to be created without using any dynamic memory allocation.\n *\n * Timers are created in the dormant state.  The xTimerStart(), xTimerReset(),\n * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and\n * xTimerChangePeriodFromISR() API functions can all be used to transition a\n * timer into the active state.\n *\n * @param pcTimerName A text name that is assigned to the timer.  This is done\n * purely to assist debugging.  The kernel itself only ever references a timer\n * by its handle, and never by its name.\n *\n * @param xTimerPeriodInTicks The timer period.  The time is defined in tick\n * periods so the constant portTICK_PERIOD_MS can be used to convert a time that\n * has been specified in milliseconds.  For example, if the timer must expire\n * after 100 ticks, then xTimerPeriodInTicks should be set to 100.\n * Alternatively, if the timer must expire after 500ms, then xPeriod can be set\n * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or\n * equal to 1000.\n *\n * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will\n * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.\n * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and\n * enter the dormant state after it expires.\n *\n * @param pvTimerID An identifier that is assigned to the timer being created.\n * Typically this would be used in the timer callback function to identify which\n * timer expired when the same callback function is assigned to more than one\n * timer.\n *\n * @param pxCallbackFunction The function to call when the timer expires.\n * Callback functions must have the prototype defined by TimerCallbackFunction_t,\n * which is\t\"void vCallbackFunction( TimerHandle_t xTimer );\".\n *\n * @return If the timer is successfully created then a handle to the newly\n * created timer is returned.  If the timer cannot be created (because either\n * there is insufficient FreeRTOS heap remaining to allocate the timer\n * structures, or the timer period was set to 0) then NULL is returned.\n *\n * Example usage:\n * @verbatim\n * #define NUM_TIMERS 5\n *\n * // An array to hold handles to the created timers.\n * TimerHandle_t xTimers[ NUM_TIMERS ];\n *\n * // An array to hold a count of the number of times each timer expires.\n * int32_t lExpireCounters[ NUM_TIMERS ] = { 0 };\n *\n * // Define a callback function that will be used by multiple timer instances.\n * // The callback function does nothing but count the number of times the\n * // associated timer expires, and stop the timer once the timer has expired\n * // 10 times.\n * void vTimerCallback( TimerHandle_t pxTimer )\n * {\n * int32_t lArrayIndex;\n * const int32_t xMaxExpiryCountBeforeStopping = 10;\n *\n * \t   // Optionally do something if the pxTimer parameter is NULL.\n * \t   configASSERT( pxTimer );\n *\n *     // Which timer expired?\n *     lArrayIndex = ( int32_t ) pvTimerGetTimerID( pxTimer );\n *\n *     // Increment the number of times that pxTimer has expired.\n *     lExpireCounters[ lArrayIndex ] += 1;\n *\n *     // If the timer has expired 10 times then stop it from running.\n *     if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping )\n *     {\n *         // Do not use a block time if calling a timer API function from a\n *         // timer callback function, as doing so could cause a deadlock!\n *         xTimerStop( pxTimer, 0 );\n *     }\n * }\n *\n * void main( void )\n * {\n * int32_t x;\n *\n *     // Create then start some timers.  Starting the timers before the scheduler\n *     // has been started means the timers will start running immediately that\n *     // the scheduler starts.\n *     for( x = 0; x < NUM_TIMERS; x++ )\n *     {\n *         xTimers[ x ] = xTimerCreate(    \"Timer\",       // Just a text name, not used by the kernel.\n *                                         ( 100 * x ),   // The timer period in ticks.\n *                                         pdTRUE,        // The timers will auto-reload themselves when they expire.\n *                                         ( void * ) x,  // Assign each timer a unique id equal to its array index.\n *                                         vTimerCallback // Each timer calls the same callback when it expires.\n *                                     );\n *\n *         if( xTimers[ x ] == NULL )\n *         {\n *             // The timer was not created.\n *         }\n *         else\n *         {\n *             // Start the timer.  No block time is specified, and even if one was\n *             // it would be ignored because the scheduler has not yet been\n *             // started.\n *             if( xTimerStart( xTimers[ x ], 0 ) != pdPASS )\n *             {\n *                 // The timer could not be set into the Active state.\n *             }\n *         }\n *     }\n *\n *     // ...\n *     // Create tasks here.\n *     // ...\n *\n *     // Starting the scheduler will start the timers running as they have already\n *     // been set into the active state.\n *     rtos_sched_start();\n *\n *     // Should not reach here.\n *     for( ;; );\n * }\n * @endverbatim\n */\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\tTimerHandle_t xTimerCreate(\tconst char * const pcTimerName,\t\t\t/*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t\t\t\t\t\t\t\tconst uint32_t xTimerPeriodInTicks,\n\t\t\t\t\t\t\t\tconst uint32_t uxAutoReload,\n\t\t\t\t\t\t\t\tvoid * const pvTimerID,\n\t\t\t\t\t\t\t\tTimerCallbackFunction_t pxCallbackFunction ) ;\n#endif\n\n/**\n * TimerHandle_t xTimerCreateStatic(const char * const pcTimerName,\n * \t\t\t\t\t\t\t\t\tuint32_t xTimerPeriodInTicks,\n * \t\t\t\t\t\t\t\t\tuint32_t uxAutoReload,\n * \t\t\t\t\t\t\t\t\tvoid * pvTimerID,\n * \t\t\t\t\t\t\t\t\tTimerCallbackFunction_t pxCallbackFunction,\n *\t\t\t\t\t\t\t\t\tStaticTimer_t *pxTimerBuffer );\n *\n * Creates a new software timer instance, and returns a handle by which the\n * created software timer can be referenced.\n *\n * Internally, within the FreeRTOS implementation, software timers use a block\n * of memory, in which the timer data structure is stored.  If a software timer\n * is created using xTimerCreate() then the required memory is automatically\n * dynamically allocated inside the xTimerCreate() function.  (see\n * http://www.freertos.org/a00111.html).  If a software timer is created using\n * xTimerCreateStatic() then the application writer must provide the memory that\n * will get used by the software timer.  xTimerCreateStatic() therefore allows a\n * software timer to be created without using any dynamic memory allocation.\n *\n * Timers are created in the dormant state.  The xTimerStart(), xTimerReset(),\n * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and\n * xTimerChangePeriodFromISR() API functions can all be used to transition a\n * timer into the active state.\n *\n * @param pcTimerName A text name that is assigned to the timer.  This is done\n * purely to assist debugging.  The kernel itself only ever references a timer\n * by its handle, and never by its name.\n *\n * @param xTimerPeriodInTicks The timer period.  The time is defined in tick\n * periods so the constant portTICK_PERIOD_MS can be used to convert a time that\n * has been specified in milliseconds.  For example, if the timer must expire\n * after 100 ticks, then xTimerPeriodInTicks should be set to 100.\n * Alternatively, if the timer must expire after 500ms, then xPeriod can be set\n * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or\n * equal to 1000.\n *\n * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will\n * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.\n * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and\n * enter the dormant state after it expires.\n *\n * @param pvTimerID An identifier that is assigned to the timer being created.\n * Typically this would be used in the timer callback function to identify which\n * timer expired when the same callback function is assigned to more than one\n * timer.\n *\n * @param pxCallbackFunction The function to call when the timer expires.\n * Callback functions must have the prototype defined by TimerCallbackFunction_t,\n * which is \"void vCallbackFunction( TimerHandle_t xTimer );\".\n *\n * @param pxTimerBuffer Must point to a variable of type StaticTimer_t, which\n * will be then be used to hold the software timer's data structures, removing\n * the need for the memory to be allocated dynamically.\n *\n * @return If the timer is created then a handle to the created timer is\n * returned.  If pxTimerBuffer was NULL then NULL is returned.\n *\n * Example usage:\n * @verbatim\n *\n * // The buffer used to hold the software timer's data structure.\n * static StaticTimer_t xTimerBuffer;\n *\n * // A variable that will be incremented by the software timer's callback\n * // function.\n * uint32_t uxVariableToIncrement = 0;\n *\n * // A software timer callback function that increments a variable passed to\n * // it when the software timer was created.  After the 5th increment the\n * // callback function stops the software timer.\n * static void prvTimerCallback( TimerHandle_t xExpiredTimer )\n * {\n * uint32_t *puxVariableToIncrement;\n * int32_t xReturned;\n *\n *     // Obtain the address of the variable to increment from the timer ID.\n *     puxVariableToIncrement = ( uint32_t * ) pvTimerGetTimerID( xExpiredTimer );\n *\n *     // Increment the variable to show the timer callback has executed.\n *     ( *puxVariableToIncrement )++;\n *\n *     // If this callback has executed the required number of times, stop the\n *     // timer.\n *     if( *puxVariableToIncrement == 5 )\n *     {\n *         // This is called from a timer callback so must not block.\n *         xTimerStop( xExpiredTimer, staticDONT_BLOCK );\n *     }\n * }\n *\n *\n * void main( void )\n * {\n *     // Create the software time.  xTimerCreateStatic() has an extra parameter\n *     // than the normal xTimerCreate() API function.  The parameter is a pointer\n *     // to the StaticTimer_t structure that will hold the software timer\n *     // structure.  If the parameter is passed as NULL then the structure will be\n *     // allocated dynamically, just as if xTimerCreate() had been called.\n *     xTimer = xTimerCreateStatic( \"T1\",             // Text name for the task.  Helps debugging only.  Not used by FreeRTOS.\n *                                  xTimerPeriod,     // The period of the timer in ticks.\n *                                  pdTRUE,           // This is an auto-reload timer.\n *                                  ( void * ) &uxVariableToIncrement,    // A variable incremented by the software timer's callback function\n *                                  prvTimerCallback, // The function to execute when the timer expires.\n *                                  &xTimerBuffer );  // The buffer that will hold the software timer structure.\n *\n *     // The scheduler has not started yet so a block time is not used.\n *     xReturned = xTimerStart( xTimer, 0 );\n *\n *     // ...\n *     // Create tasks here.\n *     // ...\n *\n *     // Starting the scheduler will start the timers running as they have already\n *     // been set into the active state.\n *     rtos_sched_start();\n *\n *     // Should not reach here.\n *     for( ;; );\n * }\n * @endverbatim\n */\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\tTimerHandle_t xTimerCreateStatic(\tconst char * const pcTimerName,\t\t\t/*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t\t\t\t\t\t\t\t\t\tconst uint32_t xTimerPeriodInTicks,\n\t\t\t\t\t\t\t\t\t\tconst uint32_t uxAutoReload,\n\t\t\t\t\t\t\t\t\t\tvoid * const pvTimerID,\n\t\t\t\t\t\t\t\t\t\tTimerCallbackFunction_t pxCallbackFunction,\n\t\t\t\t\t\t\t\t\t\tStaticTimer_t *pxTimerBuffer ) ;\n#endif /* configSUPPORT_STATIC_ALLOCATION */\n\n/**\n * void *pvTimerGetTimerID( TimerHandle_t xTimer );\n *\n * Returns the ID assigned to the timer.\n *\n * IDs are assigned to timers using the pvTimerID parameter of the call to\n * xTimerCreated() that was used to create the timer, and by calling the\n * vTimerSetTimerID() API function.\n *\n * If the same callback function is assigned to multiple timers then the timer\n * ID can be used as time specific (timer local) storage.\n *\n * @param xTimer The timer being queried.\n *\n * @return The ID assigned to the timer being queried.\n *\n * Example usage:\n *\n * See the xTimerCreate() API function example usage scenario.\n */\nvoid *pvTimerGetTimerID( const TimerHandle_t xTimer ) ;\n\n/**\n * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );\n *\n * Sets the ID assigned to the timer.\n *\n * IDs are assigned to timers using the pvTimerID parameter of the call to\n * xTimerCreated() that was used to create the timer.\n *\n * If the same callback function is assigned to multiple timers then the timer\n * ID can be used as time specific (timer local) storage.\n *\n * @param xTimer The timer being updated.\n *\n * @param pvNewID The ID to assign to the timer.\n *\n * Example usage:\n *\n * See the xTimerCreate() API function example usage scenario.\n */\nvoid vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ) ;\n\n/**\n * int32_t xTimerIsTimerActive( TimerHandle_t xTimer );\n *\n * Queries a timer to see if it is active or dormant.\n *\n * A timer will be dormant if:\n *     1) It has been created but not started, or\n *     2) It is an expired one-shot timer that has not been restarted.\n *\n * Timers are created in the dormant state.  The xTimerStart(), xTimerReset(),\n * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and\n * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the\n * active state.\n *\n * @param xTimer The timer being queried.\n *\n * @return pdFALSE will be returned if the timer is dormant.  A value other than\n * pdFALSE will be returned if the timer is active.\n *\n * Example usage:\n * @verbatim\n * // This function assumes xTimer has already been created.\n * void vAFunction( TimerHandle_t xTimer )\n * {\n *     if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently \"if( xTimerIsTimerActive( xTimer ) )\"\n *     {\n *         // xTimer is active, do something.\n *     }\n *     else\n *     {\n *         // xTimer is not active, do something else.\n *     }\n * }\n * @endverbatim\n */\nint32_t xTimerIsTimerActive( TimerHandle_t xTimer ) ;\n\n/**\n * task_t xTimerGetTimerDaemonTaskHandle( void );\n *\n * Simply returns the handle of the timer service/daemon task.  It it not valid\n * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.\n */\ntask_t xTimerGetTimerDaemonTaskHandle( void ) ;\n\n/**\n * int32_t xTimerStart( TimerHandle_t xTimer, uint32_t xTicksToWait );\n *\n * Timer functionality is provided by a timer service/daemon task.  Many of the\n * public FreeRTOS timer API functions send commands to the timer service task\n * through a queue called the timer command queue.  The timer command queue is\n * private to the kernel itself and is not directly accessible to application\n * code.  The length of the timer command queue is set by the\n * configTIMER_QUEUE_LENGTH configuration constant.\n *\n * xTimerStart() starts a timer that was previously created using the\n * xTimerCreate() API function.  If the timer had already been started and was\n * already in the active state, then xTimerStart() has equivalent functionality\n * to the xTimerReset() API function.\n *\n * Starting a timer ensures the timer is in the active state.  If the timer\n * is not stopped, deleted, or reset in the mean time, the callback function\n * associated with the timer will get called 'n' ticks after xTimerStart() was\n * called, where 'n' is the timers defined period.\n *\n * It is valid to call xTimerStart() before the scheduler has been started, but\n * when this is done the timer will not actually start until the scheduler is\n * started, and the timers expiry time will be relative to when the scheduler is\n * started, not relative to when xTimerStart() was called.\n *\n * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()\n * to be available.\n *\n * @param xTimer The handle of the timer being started/restarted.\n *\n * @param xTicksToWait Specifies the time, in ticks, that the calling task should\n * be held in the Blocked state to wait for the start command to be successfully\n * sent to the timer command queue, should the queue already be full when\n * xTimerStart() was called.  xTicksToWait is ignored if xTimerStart() is called\n * before the scheduler is started.\n *\n * @return pdFAIL will be returned if the start command could not be sent to\n * the timer command queue even after xTicksToWait ticks had passed.  pdPASS will\n * be returned if the command was successfully sent to the timer command queue.\n * When the command is actually processed will depend on the priority of the\n * timer service/daemon task relative to other tasks in the system, although the\n * timers expiry time is relative to when xTimerStart() is actually called.  The\n * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY\n * configuration constant.\n *\n * Example usage:\n *\n * See the xTimerCreate() API function example usage scenario.\n *\n */\n#define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( millis() ), NULL, ( xTicksToWait ) )\n\n/**\n * int32_t xTimerStop( TimerHandle_t xTimer, uint32_t xTicksToWait );\n *\n * Timer functionality is provided by a timer service/daemon task.  Many of the\n * public FreeRTOS timer API functions send commands to the timer service task\n * through a queue called the timer command queue.  The timer command queue is\n * private to the kernel itself and is not directly accessible to application\n * code.  The length of the timer command queue is set by the\n * configTIMER_QUEUE_LENGTH configuration constant.\n *\n * xTimerStop() stops a timer that was previously started using either of the\n * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),\n * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.\n *\n * Stopping a timer ensures the timer is not in the active state.\n *\n * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()\n * to be available.\n *\n * @param xTimer The handle of the timer being stopped.\n *\n * @param xTicksToWait Specifies the time, in ticks, that the calling task should\n * be held in the Blocked state to wait for the stop command to be successfully\n * sent to the timer command queue, should the queue already be full when\n * xTimerStop() was called.  xTicksToWait is ignored if xTimerStop() is called\n * before the scheduler is started.\n *\n * @return pdFAIL will be returned if the stop command could not be sent to\n * the timer command queue even after xTicksToWait ticks had passed.  pdPASS will\n * be returned if the command was successfully sent to the timer command queue.\n * When the command is actually processed will depend on the priority of the\n * timer service/daemon task relative to other tasks in the system.  The timer\n * service/daemon task priority is set by the configTIMER_TASK_PRIORITY\n * configuration constant.\n *\n * Example usage:\n *\n * See the xTimerCreate() API function example usage scenario.\n *\n */\n#define xTimerStop( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )\n\n/**\n * int32_t xTimerChangePeriod( \tTimerHandle_t xTimer,\n *\t\t\t\t\t\t\t\t\t\tuint32_t xNewPeriod,\n *\t\t\t\t\t\t\t\t\t\tuint32_t xTicksToWait );\n *\n * Timer functionality is provided by a timer service/daemon task.  Many of the\n * public FreeRTOS timer API functions send commands to the timer service task\n * through a queue called the timer command queue.  The timer command queue is\n * private to the kernel itself and is not directly accessible to application\n * code.  The length of the timer command queue is set by the\n * configTIMER_QUEUE_LENGTH configuration constant.\n *\n * xTimerChangePeriod() changes the period of a timer that was previously\n * created using the xTimerCreate() API function.\n *\n * xTimerChangePeriod() can be called to change the period of an active or\n * dormant state timer.\n *\n * The configUSE_TIMERS configuration constant must be set to 1 for\n * xTimerChangePeriod() to be available.\n *\n * @param xTimer The handle of the timer that is having its period changed.\n *\n * @param xNewPeriod The new period for xTimer. Timer periods are specified in\n * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time\n * that has been specified in milliseconds.  For example, if the timer must\n * expire after 100 ticks, then xNewPeriod should be set to 100.  Alternatively,\n * if the timer must expire after 500ms, then xNewPeriod can be set to\n * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than\n * or equal to 1000.\n *\n * @param xTicksToWait Specifies the time, in ticks, that the calling task should\n * be held in the Blocked state to wait for the change period command to be\n * successfully sent to the timer command queue, should the queue already be\n * full when xTimerChangePeriod() was called.  xTicksToWait is ignored if\n * xTimerChangePeriod() is called before the scheduler is started.\n *\n * @return pdFAIL will be returned if the change period command could not be\n * sent to the timer command queue even after xTicksToWait ticks had passed.\n * pdPASS will be returned if the command was successfully sent to the timer\n * command queue.  When the command is actually processed will depend on the\n * priority of the timer service/daemon task relative to other tasks in the\n * system.  The timer service/daemon task priority is set by the\n * configTIMER_TASK_PRIORITY configuration constant.\n *\n * Example usage:\n * @verbatim\n * // This function assumes xTimer has already been created.  If the timer\n * // referenced by xTimer is already active when it is called, then the timer\n * // is deleted.  If the timer referenced by xTimer is not active when it is\n * // called, then the period of the timer is set to 500ms and the timer is\n * // started.\n * void vAFunction( TimerHandle_t xTimer )\n * {\n *     if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently \"if( xTimerIsTimerActive( xTimer ) )\"\n *     {\n *         // xTimer is already active - delete it.\n *         xTimerDelete( xTimer );\n *     }\n *     else\n *     {\n *         // xTimer is not active, change its period to 500ms.  This will also\n *         // cause the timer to start.  Block for a maximum of 100 ticks if the\n *         // change period command cannot immediately be sent to the timer\n *         // command queue.\n *         if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS )\n *         {\n *             // The command was successfully sent.\n *         }\n *         else\n *         {\n *             // The command could not be sent, even after waiting for 100 ticks\n *             // to pass.  Take appropriate action here.\n *         }\n *     }\n * }\n * @endverbatim\n */\n #define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )\n\n/**\n * int32_t xTimerDelete( TimerHandle_t xTimer, uint32_t xTicksToWait );\n *\n * Timer functionality is provided by a timer service/daemon task.  Many of the\n * public FreeRTOS timer API functions send commands to the timer service task\n * through a queue called the timer command queue.  The timer command queue is\n * private to the kernel itself and is not directly accessible to application\n * code.  The length of the timer command queue is set by the\n * configTIMER_QUEUE_LENGTH configuration constant.\n *\n * xTimerDelete() deletes a timer that was previously created using the\n * xTimerCreate() API function.\n *\n * The configUSE_TIMERS configuration constant must be set to 1 for\n * xTimerDelete() to be available.\n *\n * @param xTimer The handle of the timer being deleted.\n *\n * @param xTicksToWait Specifies the time, in ticks, that the calling task should\n * be held in the Blocked state to wait for the delete command to be\n * successfully sent to the timer command queue, should the queue already be\n * full when xTimerDelete() was called.  xTicksToWait is ignored if xTimerDelete()\n * is called before the scheduler is started.\n *\n * @return pdFAIL will be returned if the delete command could not be sent to\n * the timer command queue even after xTicksToWait ticks had passed.  pdPASS will\n * be returned if the command was successfully sent to the timer command queue.\n * When the command is actually processed will depend on the priority of the\n * timer service/daemon task relative to other tasks in the system.  The timer\n * service/daemon task priority is set by the configTIMER_TASK_PRIORITY\n * configuration constant.\n *\n * Example usage:\n *\n * See the xTimerChangePeriod() API function example usage scenario.\n */\n#define xTimerDelete( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )\n\n/**\n * int32_t xTimerReset( TimerHandle_t xTimer, uint32_t xTicksToWait );\n *\n * Timer functionality is provided by a timer service/daemon task.  Many of the\n * public FreeRTOS timer API functions send commands to the timer service task\n * through a queue called the timer command queue.  The timer command queue is\n * private to the kernel itself and is not directly accessible to application\n * code.  The length of the timer command queue is set by the\n * configTIMER_QUEUE_LENGTH configuration constant.\n *\n * xTimerReset() re-starts a timer that was previously created using the\n * xTimerCreate() API function.  If the timer had already been started and was\n * already in the active state, then xTimerReset() will cause the timer to\n * re-evaluate its expiry time so that it is relative to when xTimerReset() was\n * called.  If the timer was in the dormant state then xTimerReset() has\n * equivalent functionality to the xTimerStart() API function.\n *\n * Resetting a timer ensures the timer is in the active state.  If the timer\n * is not stopped, deleted, or reset in the mean time, the callback function\n * associated with the timer will get called 'n' ticks after xTimerReset() was\n * called, where 'n' is the timers defined period.\n *\n * It is valid to call xTimerReset() before the scheduler has been started, but\n * when this is done the timer will not actually start until the scheduler is\n * started, and the timers expiry time will be relative to when the scheduler is\n * started, not relative to when xTimerReset() was called.\n *\n * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()\n * to be available.\n *\n * @param xTimer The handle of the timer being reset/started/restarted.\n *\n * @param xTicksToWait Specifies the time, in ticks, that the calling task should\n * be held in the Blocked state to wait for the reset command to be successfully\n * sent to the timer command queue, should the queue already be full when\n * xTimerReset() was called.  xTicksToWait is ignored if xTimerReset() is called\n * before the scheduler is started.\n *\n * @return pdFAIL will be returned if the reset command could not be sent to\n * the timer command queue even after xTicksToWait ticks had passed.  pdPASS will\n * be returned if the command was successfully sent to the timer command queue.\n * When the command is actually processed will depend on the priority of the\n * timer service/daemon task relative to other tasks in the system, although the\n * timers expiry time is relative to when xTimerStart() is actually called.  The\n * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY\n * configuration constant.\n *\n * Example usage:\n * @verbatim\n * // When a key is pressed, an LCD back-light is switched on.  If 5 seconds pass\n * // without a key being pressed, then the LCD back-light is switched off.  In\n * // this case, the timer is a one-shot timer.\n *\n * TimerHandle_t xBacklightTimer = NULL;\n *\n * // The callback function assigned to the one-shot timer.  In this case the\n * // parameter is not used.\n * void vBacklightTimerCallback( TimerHandle_t pxTimer )\n * {\n *     // The timer expired, therefore 5 seconds must have passed since a key\n *     // was pressed.  Switch off the LCD back-light.\n *     vSetBacklightState( BACKLIGHT_OFF );\n * }\n *\n * // The key press event handler.\n * void vKeyPressEventHandler( char cKey )\n * {\n *     // Ensure the LCD back-light is on, then reset the timer that is\n *     // responsible for turning the back-light off after 5 seconds of\n *     // key inactivity.  Wait 10 ticks for the command to be successfully sent\n *     // if it cannot be sent immediately.\n *     vSetBacklightState( BACKLIGHT_ON );\n *     if( xTimerReset( xBacklightTimer, 100 ) != pdPASS )\n *     {\n *         // The reset command was not executed successfully.  Take appropriate\n *         // action here.\n *     }\n *\n *     // Perform the rest of the key processing here.\n * }\n *\n * void main( void )\n * {\n * int32_t x;\n *\n *     // Create then start the one-shot timer that is responsible for turning\n *     // the back-light off if no keys are pressed within a 5 second period.\n *     xBacklightTimer = xTimerCreate( \"BacklightTimer\",           // Just a text name, not used by the kernel.\n *                                     ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks.\n *                                     pdFALSE,                    // The timer is a one-shot timer.\n *                                     0,                          // The id is not used by the callback so can take any value.\n *                                     vBacklightTimerCallback     // The callback function that switches the LCD back-light off.\n *                                   );\n *\n *     if( xBacklightTimer == NULL )\n *     {\n *         // The timer was not created.\n *     }\n *     else\n *     {\n *         // Start the timer.  No block time is specified, and even if one was\n *         // it would be ignored because the scheduler has not yet been\n *         // started.\n *         if( xTimerStart( xBacklightTimer, 0 ) != pdPASS )\n *         {\n *             // The timer could not be set into the Active state.\n *         }\n *     }\n *\n *     // ...\n *     // Create tasks here.\n *     // ...\n *\n *     // Starting the scheduler will start the timer running as it has already\n *     // been set into the active state.\n *     rtos_sched_start();\n *\n *     // Should not reach here.\n *     for( ;; );\n * }\n * @endverbatim\n */\n#define xTimerReset( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( millis() ), NULL, ( xTicksToWait ) )\n\n/**\n * int32_t xTimerStartFromISR( \tTimerHandle_t xTimer,\n *\t\t\t\t\t\t\t\t\tint32_t *pxHigherPriorityTaskWoken );\n *\n * A version of xTimerStart() that can be called from an interrupt service\n * routine.\n *\n * @param xTimer The handle of the timer being started/restarted.\n *\n * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most\n * of its time in the Blocked state, waiting for messages to arrive on the timer\n * command queue.  Calling xTimerStartFromISR() writes a message to the timer\n * command queue, so has the potential to transition the timer service/daemon\n * task out of the Blocked state.  If calling xTimerStartFromISR() causes the\n * timer service/daemon task to leave the Blocked state, and the timer service/\n * daemon task has a priority equal to or greater than the currently executing\n * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will\n * get set to pdTRUE internally within the xTimerStartFromISR() function.  If\n * xTimerStartFromISR() sets this value to pdTRUE then a context switch should\n * be performed before the interrupt exits.\n *\n * @return pdFAIL will be returned if the start command could not be sent to\n * the timer command queue.  pdPASS will be returned if the command was\n * successfully sent to the timer command queue.  When the command is actually\n * processed will depend on the priority of the timer service/daemon task\n * relative to other tasks in the system, although the timers expiry time is\n * relative to when xTimerStartFromISR() is actually called.  The timer\n * service/daemon task priority is set by the configTIMER_TASK_PRIORITY\n * configuration constant.\n *\n * Example usage:\n * @verbatim\n * // This scenario assumes xBacklightTimer has already been created.  When a\n * // key is pressed, an LCD back-light is switched on.  If 5 seconds pass\n * // without a key being pressed, then the LCD back-light is switched off.  In\n * // this case, the timer is a one-shot timer, and unlike the example given for\n * // the xTimerReset() function, the key press event handler is an interrupt\n * // service routine.\n *\n * // The callback function assigned to the one-shot timer.  In this case the\n * // parameter is not used.\n * void vBacklightTimerCallback( TimerHandle_t pxTimer )\n * {\n *     // The timer expired, therefore 5 seconds must have passed since a key\n *     // was pressed.  Switch off the LCD back-light.\n *     vSetBacklightState( BACKLIGHT_OFF );\n * }\n *\n * // The key press interrupt service routine.\n * void vKeyPressEventInterruptHandler( void )\n * {\n * int32_t xHigherPriorityTaskWoken = pdFALSE;\n *\n *     // Ensure the LCD back-light is on, then restart the timer that is\n *     // responsible for turning the back-light off after 5 seconds of\n *     // key inactivity.  This is an interrupt service routine so can only\n *     // call FreeRTOS API functions that end in \"FromISR\".\n *     vSetBacklightState( BACKLIGHT_ON );\n *\n *     // xTimerStartFromISR() or xTimerResetFromISR() could be called here\n *     // as both cause the timer to re-calculate its expiry time.\n *     // xHigherPriorityTaskWoken was initialised to pdFALSE when it was\n *     // declared (in this function).\n *     if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )\n *     {\n *         // The start command was not executed successfully.  Take appropriate\n *         // action here.\n *     }\n *\n *     // Perform the rest of the key processing here.\n *\n *     // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch\n *     // should be performed.  The syntax required to perform a context switch\n *     // from inside an ISR varies from port to port, and from compiler to\n *     // compiler.  Inspect the demos for the port you are using to find the\n *     // actual syntax required.\n *     if( xHigherPriorityTaskWoken != pdFALSE )\n *     {\n *         // Call the interrupt safe yield function here (actual function\n *         // depends on the FreeRTOS port being used).\n *     }\n * }\n * @endverbatim\n */\n#define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )\n\n/**\n * int32_t xTimerStopFromISR( \tTimerHandle_t xTimer,\n *\t\t\t\t\t\t\t\t\tint32_t *pxHigherPriorityTaskWoken );\n *\n * A version of xTimerStop() that can be called from an interrupt service\n * routine.\n *\n * @param xTimer The handle of the timer being stopped.\n *\n * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most\n * of its time in the Blocked state, waiting for messages to arrive on the timer\n * command queue.  Calling xTimerStopFromISR() writes a message to the timer\n * command queue, so has the potential to transition the timer service/daemon\n * task out of the Blocked state.  If calling xTimerStopFromISR() causes the\n * timer service/daemon task to leave the Blocked state, and the timer service/\n * daemon task has a priority equal to or greater than the currently executing\n * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will\n * get set to pdTRUE internally within the xTimerStopFromISR() function.  If\n * xTimerStopFromISR() sets this value to pdTRUE then a context switch should\n * be performed before the interrupt exits.\n *\n * @return pdFAIL will be returned if the stop command could not be sent to\n * the timer command queue.  pdPASS will be returned if the command was\n * successfully sent to the timer command queue.  When the command is actually\n * processed will depend on the priority of the timer service/daemon task\n * relative to other tasks in the system.  The timer service/daemon task\n * priority is set by the configTIMER_TASK_PRIORITY configuration constant.\n *\n * Example usage:\n * @verbatim\n * // This scenario assumes xTimer has already been created and started.  When\n * // an interrupt occurs, the timer should be simply stopped.\n *\n * // The interrupt service routine that stops the timer.\n * void vAnExampleInterruptServiceRoutine( void )\n * {\n * int32_t xHigherPriorityTaskWoken = pdFALSE;\n *\n *     // The interrupt has occurred - simply stop the timer.\n *     // xHigherPriorityTaskWoken was set to pdFALSE where it was defined\n *     // (within this function).  As this is an interrupt service routine, only\n *     // FreeRTOS API functions that end in \"FromISR\" can be used.\n *     if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )\n *     {\n *         // The stop command was not executed successfully.  Take appropriate\n *         // action here.\n *     }\n *\n *     // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch\n *     // should be performed.  The syntax required to perform a context switch\n *     // from inside an ISR varies from port to port, and from compiler to\n *     // compiler.  Inspect the demos for the port you are using to find the\n *     // actual syntax required.\n *     if( xHigherPriorityTaskWoken != pdFALSE )\n *     {\n *         // Call the interrupt safe yield function here (actual function\n *         // depends on the FreeRTOS port being used).\n *     }\n * }\n * @endverbatim\n */\n#define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )\n\n/**\n * int32_t xTimerChangePeriodFromISR( TimerHandle_t xTimer,\n *\t\t\t\t\t\t\t\t\t\t uint32_t xNewPeriod,\n *\t\t\t\t\t\t\t\t\t\t int32_t *pxHigherPriorityTaskWoken );\n *\n * A version of xTimerChangePeriod() that can be called from an interrupt\n * service routine.\n *\n * @param xTimer The handle of the timer that is having its period changed.\n *\n * @param xNewPeriod The new period for xTimer. Timer periods are specified in\n * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time\n * that has been specified in milliseconds.  For example, if the timer must\n * expire after 100 ticks, then xNewPeriod should be set to 100.  Alternatively,\n * if the timer must expire after 500ms, then xNewPeriod can be set to\n * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than\n * or equal to 1000.\n *\n * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most\n * of its time in the Blocked state, waiting for messages to arrive on the timer\n * command queue.  Calling xTimerChangePeriodFromISR() writes a message to the\n * timer command queue, so has the potential to transition the timer service/\n * daemon task out of the Blocked state.  If calling xTimerChangePeriodFromISR()\n * causes the timer service/daemon task to leave the Blocked state, and the\n * timer service/daemon task has a priority equal to or greater than the\n * currently executing task (the task that was interrupted), then\n * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the\n * xTimerChangePeriodFromISR() function.  If xTimerChangePeriodFromISR() sets\n * this value to pdTRUE then a context switch should be performed before the\n * interrupt exits.\n *\n * @return pdFAIL will be returned if the command to change the timers period\n * could not be sent to the timer command queue.  pdPASS will be returned if the\n * command was successfully sent to the timer command queue.  When the command\n * is actually processed will depend on the priority of the timer service/daemon\n * task relative to other tasks in the system.  The timer service/daemon task\n * priority is set by the configTIMER_TASK_PRIORITY configuration constant.\n *\n * Example usage:\n * @verbatim\n * // This scenario assumes xTimer has already been created and started.  When\n * // an interrupt occurs, the period of xTimer should be changed to 500ms.\n *\n * // The interrupt service routine that changes the period of xTimer.\n * void vAnExampleInterruptServiceRoutine( void )\n * {\n * int32_t xHigherPriorityTaskWoken = pdFALSE;\n *\n *     // The interrupt has occurred - change the period of xTimer to 500ms.\n *     // xHigherPriorityTaskWoken was set to pdFALSE where it was defined\n *     // (within this function).  As this is an interrupt service routine, only\n *     // FreeRTOS API functions that end in \"FromISR\" can be used.\n *     if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )\n *     {\n *         // The command to change the timers period was not executed\n *         // successfully.  Take appropriate action here.\n *     }\n *\n *     // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch\n *     // should be performed.  The syntax required to perform a context switch\n *     // from inside an ISR varies from port to port, and from compiler to\n *     // compiler.  Inspect the demos for the port you are using to find the\n *     // actual syntax required.\n *     if( xHigherPriorityTaskWoken != pdFALSE )\n *     {\n *         // Call the interrupt safe yield function here (actual function\n *         // depends on the FreeRTOS port being used).\n *     }\n * }\n * @endverbatim\n */\n#define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )\n\n/**\n * int32_t xTimerResetFromISR( \tTimerHandle_t xTimer,\n *\t\t\t\t\t\t\t\t\tint32_t *pxHigherPriorityTaskWoken );\n *\n * A version of xTimerReset() that can be called from an interrupt service\n * routine.\n *\n * @param xTimer The handle of the timer that is to be started, reset, or\n * restarted.\n *\n * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most\n * of its time in the Blocked state, waiting for messages to arrive on the timer\n * command queue.  Calling xTimerResetFromISR() writes a message to the timer\n * command queue, so has the potential to transition the timer service/daemon\n * task out of the Blocked state.  If calling xTimerResetFromISR() causes the\n * timer service/daemon task to leave the Blocked state, and the timer service/\n * daemon task has a priority equal to or greater than the currently executing\n * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will\n * get set to pdTRUE internally within the xTimerResetFromISR() function.  If\n * xTimerResetFromISR() sets this value to pdTRUE then a context switch should\n * be performed before the interrupt exits.\n *\n * @return pdFAIL will be returned if the reset command could not be sent to\n * the timer command queue.  pdPASS will be returned if the command was\n * successfully sent to the timer command queue.  When the command is actually\n * processed will depend on the priority of the timer service/daemon task\n * relative to other tasks in the system, although the timers expiry time is\n * relative to when xTimerResetFromISR() is actually called.  The timer service/daemon\n * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.\n *\n * Example usage:\n * @verbatim\n * // This scenario assumes xBacklightTimer has already been created.  When a\n * // key is pressed, an LCD back-light is switched on.  If 5 seconds pass\n * // without a key being pressed, then the LCD back-light is switched off.  In\n * // this case, the timer is a one-shot timer, and unlike the example given for\n * // the xTimerReset() function, the key press event handler is an interrupt\n * // service routine.\n *\n * // The callback function assigned to the one-shot timer.  In this case the\n * // parameter is not used.\n * void vBacklightTimerCallback( TimerHandle_t pxTimer )\n * {\n *     // The timer expired, therefore 5 seconds must have passed since a key\n *     // was pressed.  Switch off the LCD back-light.\n *     vSetBacklightState( BACKLIGHT_OFF );\n * }\n *\n * // The key press interrupt service routine.\n * void vKeyPressEventInterruptHandler( void )\n * {\n * int32_t xHigherPriorityTaskWoken = pdFALSE;\n *\n *     // Ensure the LCD back-light is on, then reset the timer that is\n *     // responsible for turning the back-light off after 5 seconds of\n *     // key inactivity.  This is an interrupt service routine so can only\n *     // call FreeRTOS API functions that end in \"FromISR\".\n *     vSetBacklightState( BACKLIGHT_ON );\n *\n *     // xTimerStartFromISR() or xTimerResetFromISR() could be called here\n *     // as both cause the timer to re-calculate its expiry time.\n *     // xHigherPriorityTaskWoken was initialised to pdFALSE when it was\n *     // declared (in this function).\n *     if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )\n *     {\n *         // The reset command was not executed successfully.  Take appropriate\n *         // action here.\n *     }\n *\n *     // Perform the rest of the key processing here.\n *\n *     // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch\n *     // should be performed.  The syntax required to perform a context switch\n *     // from inside an ISR varies from port to port, and from compiler to\n *     // compiler.  Inspect the demos for the port you are using to find the\n *     // actual syntax required.\n *     if( xHigherPriorityTaskWoken != pdFALSE )\n *     {\n *         // Call the interrupt safe yield function here (actual function\n *         // depends on the FreeRTOS port being used).\n *     }\n * }\n * @endverbatim\n */\n#define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )\n\n\n/**\n * int32_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,\n *                                          void *pvParameter1,\n *                                          uint32_t ulParameter2,\n *                                          int32_t *pxHigherPriorityTaskWoken );\n *\n *\n * Used from application interrupt service routines to defer the execution of a\n * function to the RTOS daemon task (the timer service task, hence this function\n * is implemented in timers.c and is prefixed with 'Timer').\n *\n * Ideally an interrupt service routine (ISR) is kept as short as possible, but\n * sometimes an ISR either has a lot of processing to do, or needs to perform\n * processing that is not deterministic.  In these cases\n * xTimerPendFunctionCallFromISR() can be used to defer processing of a function\n * to the RTOS daemon task.\n *\n * A mechanism is provided that allows the interrupt to return directly to the\n * task that will subsequently execute the pended callback function.  This\n * allows the callback function to execute contiguously in time with the\n * interrupt - just as if the callback had executed in the interrupt itself.\n *\n * @param xFunctionToPend The function to execute from the timer service/\n * daemon task.  The function must conform to the PendedFunction_t\n * prototype.\n *\n * @param pvParameter1 The value of the callback function's first parameter.\n * The parameter has a void * type to allow it to be used to pass any type.\n * For example, unsigned longs can be cast to a void *, or the void * can be\n * used to point to a structure.\n *\n * @param ulParameter2 The value of the callback function's second parameter.\n *\n * @param pxHigherPriorityTaskWoken As mentioned above, calling this function\n * will result in a message being sent to the timer daemon task.  If the\n * priority of the timer daemon task (which is set using\n * configTIMER_TASK_PRIORITY in FreeRTOSConfig.h) is higher than the priority of\n * the currently running task (the task the interrupt interrupted) then\n * *pxHigherPriorityTaskWoken will be set to pdTRUE within\n * xTimerPendFunctionCallFromISR(), indicating that a context switch should be\n * requested before the interrupt exits.  For that reason\n * *pxHigherPriorityTaskWoken must be initialised to pdFALSE.  See the\n * example code below.\n *\n * @return pdPASS is returned if the message was successfully sent to the\n * timer daemon task, otherwise pdFALSE is returned.\n *\n * Example usage:\n * @verbatim\n *\n *\t// The callback function that will execute in the context of the daemon task.\n *  // Note callback functions must all use this same prototype.\n *  void vProcessInterface( void *pvParameter1, uint32_t ulParameter2 )\n *\t{\n *\t\tint32_t xInterfaceToService;\n *\n *\t\t// The interface that requires servicing is passed in the second\n *      // parameter.  The first parameter is not used in this case.\n *\t\txInterfaceToService = ( int32_t ) ulParameter2;\n *\n *\t\t// ...Perform the processing here...\n *\t}\n *\n *\t// An ISR that receives data packets from multiple interfaces\n *  void vAnISR( void )\n *\t{\n *\t\tint32_t xInterfaceToService, xHigherPriorityTaskWoken;\n *\n *\t\t// Query the hardware to determine which interface needs processing.\n *\t\txInterfaceToService = prvCheckInterfaces();\n *\n *      // The actual processing is to be deferred to a task.  Request the\n *      // vProcessInterface() callback function is executed, passing in the\n *\t\t// number of the interface that needs processing.  The interface to\n *\t\t// service is passed in the second parameter.  The first parameter is\n *\t\t// not used in this case.\n *\t\txHigherPriorityTaskWoken = pdFALSE;\n *\t\txTimerPendFunctionCallFromISR( vProcessInterface, NULL, ( uint32_t ) xInterfaceToService, &xHigherPriorityTaskWoken );\n *\n *\t\t// If xHigherPriorityTaskWoken is now set to pdTRUE then a context\n *\t\t// switch should be requested.  The macro used is port specific and will\n *\t\t// be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to\n *\t\t// the documentation page for the port being used.\n *\t\tportYIELD_FROM_ISR( xHigherPriorityTaskWoken );\n *\n *\t}\n * @endverbatim\n */\nint32_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, int32_t *pxHigherPriorityTaskWoken ) ;\n\n /**\n  * int32_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,\n  *                                    void *pvParameter1,\n  *                                    uint32_t ulParameter2,\n  *                                    uint32_t xTicksToWait );\n  *\n  *\n  * Used to defer the execution of a function to the RTOS daemon task (the timer\n  * service task, hence this function is implemented in timers.c and is prefixed\n  * with 'Timer').\n  *\n  * @param xFunctionToPend The function to execute from the timer service/\n  * daemon task.  The function must conform to the PendedFunction_t\n  * prototype.\n  *\n  * @param pvParameter1 The value of the callback function's first parameter.\n  * The parameter has a void * type to allow it to be used to pass any type.\n  * For example, unsigned longs can be cast to a void *, or the void * can be\n  * used to point to a structure.\n  *\n  * @param ulParameter2 The value of the callback function's second parameter.\n  *\n  * @param xTicksToWait Calling this function will result in a message being\n  * sent to the timer daemon task on a queue.  xTicksToWait is the amount of\n  * time the calling task should remain in the Blocked state (so not using any\n  * processing time) for space to become available on the timer queue if the\n  * queue is found to be full.\n  *\n  * @return pdPASS is returned if the message was successfully sent to the\n  * timer daemon task, otherwise pdFALSE is returned.\n  *\n  */\nint32_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, uint32_t xTicksToWait ) ;\n\n/**\n * const char * const pcTimerGetName( TimerHandle_t xTimer );\n *\n * Returns the name that was assigned to a timer when the timer was created.\n *\n * @param xTimer The handle of the timer being queried.\n *\n * @return The name assigned to the timer specified by the xTimer parameter.\n */\nconst char * pcTimerGetName( TimerHandle_t xTimer ) ; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\n/**\n * uint32_t xTimerGetPeriod( TimerHandle_t xTimer );\n *\n * Returns the period of a timer.\n *\n * @param xTimer The handle of the timer being queried.\n *\n * @return The period of the timer in ticks.\n */\nuint32_t xTimerGetPeriod( TimerHandle_t xTimer ) ;\n\n/**\n* uint32_t xTimerGetExpiryTime( TimerHandle_t xTimer );\n*\n* Returns the time in ticks at which the timer will expire.  If this is less\n* than the current tick count then the expiry time has overflowed from the\n* current time.\n*\n* @param xTimer The handle of the timer being queried.\n*\n* @return If the timer is running then the time in ticks at which the timer\n* will next expire is returned.  If the timer is not running then the return\n* value is undefined.\n*/\nuint32_t xTimerGetExpiryTime( TimerHandle_t xTimer ) ;\n\n/*\n * Functions beyond this part are not part of the public API and are intended\n * for use by the kernel only.\n */\nint32_t xTimerCreateTimerTask( void ) ;\nint32_t xTimerGenericCommand( TimerHandle_t xTimer, const int32_t xCommandID, const uint32_t xOptionalValue, int32_t * const pxHigherPriorityTaskWoken, const uint32_t xTicksToWait ) ;\n\n#if( configUSE_TRACE_FACILITY == 1 )\n\tvoid vTimerSetTimerNumber( TimerHandle_t xTimer, uint32_t uxTimerNumber ) ;\n\tuint32_t uxTimerGetTimerNumber( TimerHandle_t xTimer ) ;\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n#endif /* TIMERS_H */\n\n\n\n"
  },
  {
    "path": "include/system/dev/banners.h",
    "content": "/**\n * \\file system/dev/banners.h\n *\n * PROS banners printed over serial line\n *\n * This file should only be included ONCE (in system/dev/serial_daemon.c)\n *\n * See system/dev/serial_daemon.c for discussion\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n// The banners look extra messed up due to the ANSI escape sequences and needing\n// to escape backslashes and quotes\nstatic char const* const short_banner =\n    \"\\n\\n\\n\"\n    \" \u001b[1;33m _____  _____   ____   _____ \u001b[0m\\n\"\n    \" \u001b[1;33m|  __ \\\\|  __ \\\\ / __ \\\\ / ____|\u001b[0m          \u001b[1;33mPowered by \"\n    \"PROS for VEX V5\u001b[0m\\n\"\n    \" \u001b[1;33m| |__) | |__) | |  | | (___  \u001b[0m    Version:  \u001b[1m%29s\u001b[0m\\n\"\n    \" \u001b[1;33m|  ___/|  _  /| |  | |\\\\___ \\\\ \u001b[0m    Uptime:   \u001b[1m%23lu.%03lu \"\n    \"s\u001b[0m\\n\"\n    \" \u001b[1;33m| |    | | \\\\ \\\\| |__| |____) |\u001b[0m    Compiled: \u001b[1m%29s\u001b[0m\\n\"\n    \" \u001b[1;33m|_|    |_|  \\\\_\\\\\\\\____/|_____/ \u001b[0m    Directory:\u001b[1m%29s\u001b[0m\\n\"\n    \"\\n\\n\";\n\nstatic char const* const large_banner =\n    \"\\n\\n\\n\"\n    \"         \u001b[1;33m_+=+_\u001b[0m\\n\"\n    \"     \u001b[1;33m .-`  .  `-. \u001b[0m         8888888b.  8888888b.   .d88888b.   \"\n    \".d8888b.\\n\"\n    \"  \u001b[1;33m _+`     \\\"     `+_ \u001b[0m      888   Y88b 888   Y88b d88P\\\" \"\n    \"\\\"Y88b d88P  Y88b\\n\"\n    \"  \u001b[1;33m\\\\\\\\\\\\sssssssssssss///\u001b[0m      888    888 888    888 888     \"\n    \"888 Y88b.\\n\"\n    \"     \u001b[1;33m.ss\\\\  \u001b[37m*\u001b[33m  /ss.\u001b[0m         888   d88P 888   d88P \"\n    \"888     888  \\\"Y888b.\\n\"\n    \" \u001b[1;33m.+bm\u001b[0m  \u001b[1;33m.s\u001b[37m  *  \u001b[33ms.\u001b[0m  \u001b[1;33mmd+.\u001b[0m     \"\n    \"8888888P\\\"  8888888P\\\"  888     888     \"\n    \"\\\"Y88b.\\n\"\n    \"\u001b[1;33m.hMMMMs\u001b[0m \u001b[1;33m.\u001b[37m  *  \u001b[33m.\u001b[0m \u001b[1;33msMMMMh.\u001b[0m    888 \"\n    \"       888 T88b   888     888       \"\n    \"\\\"888\\n\"\n    \" \u001b[1;33m`\\\\hMMMb\u001b[0m \u001b[1;33m\\\\\u001b[37m | \u001b[33m/\u001b[0m \u001b[1;33mdMMMh:\u001b[0m      \"\n    \"888        888  T88b  Y88b. .d88P Y88b  \"\n    \"d88P\\n\"\n    \"   \u001b[1;33m-SNMNo\u001b[0m  \u001b[1;33m-\u001b[0m  \u001b[1;33moNMNs-\u001b[0m       888        \"\n    \"888   T88b  \\\"Y88888P\\\"   \\\"Y8888P\\\"\\n\"\n    \"     \u001b[1;33m`+dMh\\\\./dMd/\u001b[0m\\n\"\n    \"        \u001b[1;33m`:yNy:`\u001b[0m                      \u001b[1;33mPowered by PROS \"\n    \"for VEX V5\u001b[0m\\n\"\n    \"           \u001b[1;33m\\\"\u001b[0m                Copyright (c) Purdue University \"\n    \"ACM SIGBots\\n\"\n    \"Version:\u001b[1m%13s\u001b[0m     Platform:  \u001b[1mV%d.%d.%d (b%d)\u001b[0m     \"\n    \"Uptime:\u001b[1m%5lu.%03lu s\u001b[0m\\n\"\n    \"Compiled:   \u001b[1m%20s\u001b[0m     Directory:  \u001b[1m%22s\u001b[0m\\n\"\n    \"\\n\\n\";\n"
  },
  {
    "path": "include/system/dev/dev.h",
    "content": "/**\n * \\file system/dev/dev.h\n *\n * Generic Serial Device driver header\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n#include \"vfs.h\"\n\nextern const struct fs_driver* const dev_driver;\nint dev_open_r(struct _reent* r, const char* path, int flags, int mode);\nvoid dev_initialize(void);\n"
  },
  {
    "path": "include/system/dev/ser.h",
    "content": "/**\n * \\file system/dev/ser.h\n *\n * Serial driver header\n *\n * See system/dev/ser_driver.c and system/dev/ser_daemon.c for discussion\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n#include \"vfs.h\"\n\nextern const struct fs_driver* const ser_driver;\nint ser_open_r(struct _reent* r, const char* path, int flags, int mode);\nvoid ser_initialize(void);\n"
  },
  {
    "path": "include/system/dev/usd.h",
    "content": "/**\n * \\file system/dev/usd.h\n *\n * microSD card driver header\n *\n * See system/dev/usd_driver.c for discussion\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n#include \"vfs.h\"\n\nextern const struct fs_driver* const usd_driver;\nint usd_open_r(struct _reent* r, const char* path, int flags, int mode);\nvoid usd_initialize(void);\n"
  },
  {
    "path": "include/system/dev/vfs.h",
    "content": "/**\n * \\file system/dev/vfs.h\n *\n * Virtual File System header\n *\n * See system/dev/vfs.c for discussion\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n#include <errno.h>\n#include <stdint.h>\n#include <sys/stat.h>\n#include <unistd.h>\n\nstruct fs_driver {\n\tssize_t (*read_r)(struct _reent*, void* const, uint8_t*, const size_t);\n\tint (*write_r)(struct _reent*, void* const, const uint8_t*, const size_t);\n\tint (*close_r)(struct _reent*, void* const);\n\tint (*fstat_r)(struct _reent*, void* const, struct stat*);\n\tint (*isatty_r)(struct _reent*, void* const);\n\toff_t (*lseek_r)(struct _reent*, void* const, off_t, int);\n\tint (*ctl)(void* const, const uint32_t, void* const);\n};\n\nstruct file_entry {\n\tstruct fs_driver const* driver;\n\tvoid* arg;\n};\n\n// adds an entry to the file table\nint vfs_add_entry_r(struct _reent* r, struct fs_driver const* const driver, void* arg);\n\n// update an entry to the file table. Returns -1 if there was an error.\n// If driver is NULL, then the driver isn't updated. If arg is (void*)-1, then\n// the arg isn't updated.\nint vfs_update_entry(int file, struct fs_driver const* const driver, void* arg);\n"
  },
  {
    "path": "include/system/hot.h",
    "content": "#pragma once\n\nstruct hot_table {\n\tchar const* compile_timestamp;\n\tchar const* compile_directory;\n\n\tvoid* __exidx_start;\n\tvoid* __exidx_end;\n\n\tstruct {\n#define FUNC(F) void (*F)();\n#include \"system/user_functions/list.h\"\n#undef FUNC\n\t} functions;\n};\n\nextern struct hot_table* const HOT_TABLE;\n"
  },
  {
    "path": "include/system/optimizers.h",
    "content": "/**\n * \\file system/optimizers.h\n *\n * Optimizers for the kernel\n *\n * Probably shouldn't use anything from this header\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n// See https://stackoverflow.com/q/109710 for discussion\n#define likely(cond) __builtin_expect(!!(cond), 1)\n#define unlikely(cond) __builtin_expect(!!(cond), 0)\n"
  },
  {
    "path": "include/system/user_functions/c_list.h",
    "content": "#ifndef FUNC\n#error \"FUNC must be defined\"\n#endif\n\nFUNC(autonomous)\nFUNC(initialize)\nFUNC(opcontrol)\nFUNC(disabled)\nFUNC(competition_initialize)\n"
  },
  {
    "path": "include/system/user_functions/cpp_list.h",
    "content": "#ifndef FUNC\n#error \"FUNC must be defined\"\n#endif\n\nFUNC(cpp_autonomous)\nFUNC(cpp_initialize)\nFUNC(cpp_opcontrol)\nFUNC(cpp_disabled)\nFUNC(cpp_competition_initialize)\n"
  },
  {
    "path": "include/system/user_functions/list.h",
    "content": "#ifndef FUNC\n#error \"FUNC must be defined\"\n#endif\n\n#include \"system/user_functions/c_list.h\"\n#include \"system/user_functions/cpp_list.h\"\n"
  },
  {
    "path": "include/system/user_functions.h",
    "content": "#pragma once\n\n#define FUNC(F) void user_ ##F();\n#include \"system/user_functions/list.h\"\n#undef FUNC\n"
  },
  {
    "path": "include/vdml/port.h",
    "content": "/**\n * \\file devices/port.h\n *\n * This file contains the standard header info for port macros and bit masks, \n * used mostly for the adi expander.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#define SMART_PORT_BITS 16\n#define SMART_PORT_MASK ((1 << SMART_PORT_BITS) - 1)\n\n/**\n * Macro Description: Given a merged ports variable, it sets the smart port and adi port to the values inside the\n * int32_t.\n */\n#define get_ports(ports, smart_port, adi_port) \\\n\t{                                            \\\n\t\tuint32_t uport = (uint32_t)ports;          \\\n\t\tsmart_port = uport & SMART_PORT_MASK;      \\\n\t\tadi_port = uport >> SMART_PORT_BITS;       \\\n\t}\n\nstatic inline uint32_t merge_adi_ports(uint8_t smart_port, uint8_t adi_port) {\n\treturn (adi_port << SMART_PORT_BITS) | smart_port;\n}\n"
  },
  {
    "path": "include/vdml/registry.h",
    "content": "/**\n * \\file vdml/registry.h\n *\n * This file contains the standard header info for the VDML (Vex Data Management\n * Layer) registry.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n#include \"pros/apix.h\"\n#include \"v5_api.h\"\n#include \"vdml/vdml.h\"\n\n#ifdef __cplusplus\n#define v5_device_e_t pros::c::v5_device_e_t\nextern \"C\" {\n#endif\n\ntypedef struct {\n\tv5_device_e_t device_type;\n\tV5_DeviceT device_info;\n\tuint8_t pad[128];  // 16 bytes in adi_data_s_t times 8 ADI Ports = 128\n} v5_smart_device_s_t;\n\n/*\n * Detects the devices that are plugged in.\n *\n * Pulls the type names of plugged-in devices and stores them in the buffer\n * registry_types.\n */\nvoid registry_update_types();\n\n/*\n * Returns the information on the device registered to the port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n *\n * \\param port\n *        The V5 port number from 1-21\n *\n * \\return A struct containing the device type and the info needed for api\n * functions\n */\nv5_smart_device_s_t* registry_get_device(uint8_t port);\n\n/*\n * Returns the information on the device registered to the port.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n *\n * \\param port\n *        The V5 port number from 0-32\n *\n * \\return A struct containing the device type and the info needed for api\n * functions\n */\nv5_smart_device_s_t* registry_get_device_internal(uint8_t port);\n\n/*\n * Checks whether there is a discrepancy between the binding of the port and\n * what is actually plugged in.\n *\n * If a device is plugged in but not registered, registers the port.\n * If a device is not plugged in and a device is registered, warns the user.\n * If one type of device is registered but another is plugged in, warns the user.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n *\n * \\param port\n *        The V5 port number from 1-21\n * \\param expected_t\n *        The expected type (i.e., the type of function being called. If\n *        E_DEVICE_NONE, indicates that background processing is calling this,\n *        and a mismatch will only occur if there is an actual discrepancy\n *        between what is registered and what is plugged in.\n *\n * \\return 0 if the device registered matches the device plugged and the\n * expected device matches both of those or is E_DEVICE_NONE, 1 if the\n * registered device is not plugged in, and 2 if there is a mismatch. PROS_ERR\n * on exception.\n */\nint32_t registry_validate_binding(uint8_t port, v5_device_e_t expected_t);\n\n#ifdef __cplusplus\n}\n#undef v5_device_e_t\n#endif\n"
  },
  {
    "path": "include/vdml/vdml.h",
    "content": "/**\n * \\file vdml/vdml.h\n *\n * This file contains all types and functions used throughout multiple VDML\n * (Vex Data Management Layer) files.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#pragma once\n\n#include <stdbool.h>\n#include <stdint.h>\n#include \"vdml/registry.h\"\n\n#ifdef __cplusplus\n#define v5_device_e_t pros::c::v5_device_e_t\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/**\n * Macro, returns true if the port is in range of user configurable ports,\n * false otherwise.\n */\n#define VALIDATE_PORT_NO(PORT) ((PORT) >= 0 && (PORT) < NUM_V5_PORTS)\n\n#define VALIDATE_PORT_NO_INTERNAL(PORT) ((PORT) >= 0 && (PORT) < V5_MAX_DEVICE_PORTS)\n\n/**\n * Macro that handles error checking, sanity checking, automatic registration,\n * and mutex taking for all of the motor wrapper functions.\n * If port is out of range, the calling function sets errno and returns.\n * If a port isn't yet registered, it registered as a motor automatically.\n * If a mutex cannot be taken, errno is set to EACCES (access denied) and\n * returns.\n *\n * \\param port\n *        The V5 port number from 0-20\n * \\param device_type\n *        The v5_device_e_t that the port is configured as\n * \\param error_code\n *        The error code that return if error checking failed\n */\n#define claim_port(port, device_type, error_code)          \\\n  if (registry_validate_binding(port, device_type) != 0) { \\\n    return error_code;                                     \\\n  }                                                        \\\n  v5_smart_device_s_t* device = registry_get_device(port); \\\n  if (!port_mutex_take(port)) {                            \\\n    errno = EACCES;                                        \\\n    return error_code;                                     \\\n  }\n\n/**\n * Function like claim_port. This macro should only be used in functions \n * that return int32_t or enums as PROS_ERR could be returned.\n *\n * \\param port\n *        The V5 port number from 0-20\n * \\param device_type\n *        The v5_device_e_t that the port is configured as\n */\n#define claim_port_i(port, device_type) claim_port(port, device_type, PROS_ERR)\n\n/**\n * Function like claim_port. This macro should only be used in functions \n * that return double or float as PROS_ERR_F could be returned.\n *\n * \\param port\n *        The V5 port number from 0-20\n * \\param device_type\n *        The v5_device_e_t that the port is configured as\n */\n#define claim_port_f(port, device_type) claim_port(port, device_type, PROS_ERR_F)\n\n/**\n * A function that executes claim_port and allows you to execute a block of \n * code if an error occurs.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (1-21).\n * EACCES - Another resource is currently trying to access the port.\n *\n * \\param port\n *        The V5 port number from 0-20\n * \\param device_type\n *        The v5_device_e_t that the port is configured as\n *\n * \\return 1 if the operation was successful or 0 if the operation\n * failed, setting errno.\n */\nint32_t claim_port_try(uint8_t port, v5_device_e_t type);\n\n/**\n * Macro that release the mutex for the given port and sets errno to 0 if the\n * function is an accessor wrapper whos return value is PROS_ERR or PROS_ERR_F.\n *\n * \\param port\n *        The V5 port number from 0-20\n * \\param rtn\n *        The desired return value\n *\n * \\return The rtn parameter\n */\n#define return_port(port, rtn) \\\n  port_mutex_give(port);       \\\n  return rtn;\n\n/**\n * Bitmap to indicate if a port has had an error printed or not.\n */\nextern int32_t port_errors;\n\n/**\n * Sets the port's bit to 1, indicating there has already been an error on this\n * port.\n *\n * \\param port\n *        The V5 port number to set from 0-20\n */\nvoid vdml_set_port_error(uint8_t port);\n\n/**\n * Sets the port's bit to 0, effectively resetting it.\n *\n * \\param port\n *        The V5 port number to unset from 0-20\n */\nvoid vdml_unset_port_error(uint8_t port);\n\n/**\n * Gets the error bit for the port, indicating whether or not there has been an\n * error on this port.\n *\n * \\param port\n *        The V5 port number to check from 0-20\n *\n * \\return True if the port's bit is set, false otherwise.\n */\nbool vdml_get_port_error(uint8_t port);\n\n/**\n * Claims the mutex for the given port.\n *\n * Reserves the mutex for this port. Any other tasks trying to access this port\n * will block until the mutex is returned. If a higher-priortiy task attempts\n * to claim this port, the task which has the port claimed will temporarily be\n * raised to an equal priority until the mutex is given, reducing the impact of\n * the delay. See FreeRTOS documentation for more details.\n *\n * This MUST be called before any call to the v5 api to maintain thread saftey.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (0-20).\n *\n * \\param port\n *        The V5 port number to claim from 0-20\n *\n * \\return 1 if the mutex was successfully taken, 0 if not, -1 if port is\n * invalid.\n */\nint port_mutex_take(uint8_t port);\n\n/**\n * Returns the mutex for the given port.\n *\n * Frees the mutex for this port, allowing other tasks to continue.\n *\n * WARNING: If a mutex was claimed by a task, this MUST be called immediately\n * after the port is no longer needed by that task in order to prevent delays in\n * other tasks.\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (0-20).\n *\n * \\param port\n *        The V5 port number to free from 0-20\n */\nint port_mutex_give(uint8_t port);\n\n/**\n * Executes port_mutex_take() for all of the V5 Smart Ports.\n */\nvoid port_mutex_take_all();\n\n/**\n * Executes port_mutex_give() for all of the V5 Smart Ports.\n */\nvoid port_mutex_give_all();\n\n/**\n * Obtains a port mutex with bounds checking for V5_MAX_PORTS (32) not user\n * exposed device ports (20). Intended for internal usage for protecting\n * thread-safety on devices such as the controller and battery\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (0-32).\n *\n * \\param port\n *        The V5 port number from 0-32\n *\n * \\return True if the mutex was successfully taken, false otherwise. If false\n * is returned, then errno is set with a hint about why the the mutex\n * couldn't be taken.\n */\nint internal_port_mutex_take(uint8_t port);\n\n/**\n * Returns a port mutex with bounds checking for V5_MAX_PORTS (32) not user\n * exposed device ports (20). Intended for internal usage for protecting\n * thread-safety on devices such as the controller and battery\n *\n * This function uses the following values of errno when an error state is\n * reached:\n * ENXIO - The given value is not within the range of V5 ports (0-32).\n *\n * \\param port\n *        The V5 port number from 0-32\n *\n * \\return True if the mutex was successfully returned, false otherwise. If\n * false is returned, then errno is set with a hint about why the mutex\n * couldn't be returned.\n */\nint internal_port_mutex_give(uint8_t port);\n\n#define V5_PORT_BATTERY 24\n#define V5_PORT_CONTROLLER_1 25\n#define V5_PORT_CONTROLLER_2 26\n\n#ifdef __cplusplus\n}\n#undef v5_device_e_t\n#endif\n"
  },
  {
    "path": "libv5rts-strip-options.txt",
    "content": "-N open\n-N _fstat\n-N fcntl\n-N lseek\n-N read\n-N write\n-N isatty\n-R .ARM.attributes\n"
  },
  {
    "path": "patch_headers.py",
    "content": "'''\nAdds __attribute__((pcs(\"aapcs\")) to all sdk function declarations to allow properly linking\nwith the sdk (which uses the soft float abi) when building pros with the hard float abi\n'''\n\nfrom os import listdir, makedirs\nfrom os.path import isfile, join, exists, dirname, realpath\n\ndef print_and_exit(message):\n    print(message)\n    print(\"Failed to patch libv5rts\")\n    exit(1)\n\n# get the current directory\ntry:\n    current_dir = dirname(realpath(__file__))\nexcept:\n    print_and_exit(\"Could not get working directory!\")\n# set the include path and the include path of the patched SDK\ninclude_path = current_dir + \"/firmware/libv5rts/sdk/vexv5/include/\"\npatched_include_path = current_dir + \"/firmware/libv5rts/sdk/vexv5/patched_include/\"\n# create the include path if it does not exist already\nif exists(patched_include_path):\n    print(\"libv5rts already patched\")\n    exit(0)\nelse:\n    try:\n        makedirs(patched_include_path)\n    except:\n        print_and_exit(\"Could not create directory for patched libv5rts\")\n\n# get a list of files in the include path\ntry:\n    all_files = listdir(include_path)\nexcept:\n    print_and_exit(\"Error getting directories and files in include path\")\nfiles = []\nfor f in all_files:\n    if isfile(join(include_path, f)) and str(f).endswith(\".h\"):\n        files.append(f)\n        \n# patch headers\nfor file_name in files:\n    header_file = \"\"\n    output = \"\"\n    skip_next_line = False\n    try:\n        with open(join(include_path, file_name), \"r\") as file:\n            header_file = file.read()\n    except:\n        print_and_exit(\"Failed to open file in v5rts\")\n    for line in header_file.splitlines():\n        if skip_next_line:\n            # This line is a macro continuation\n            if not line.endswith((\"\\\\\")):\n                # macro continuation ends here\n                skip_next_line = False\n            continue\n        if line.strip().startswith((\"/\", \"*\")):\n            # it's a comment\n            output += f\"{line}\\n\"\n            continue\n        if line.strip().startswith((\"#\")):\n            # it's a preprocessor directive\n            output += f\"{line}\\n\"\n            if line.endswith((\"\\\\\")):\n                skip_next_line = True\n            continue\n        if line.strip().startswith((\"}\", \"{\", \"extern\")):\n            # it's an extern c block or struct definition\n            output += f\"{line}\\n\"\n            continue\n        if line.strip().startswith((\"typedef\", \"struct\", \"enum\")):\n            # it's a struct/enum definition or typedef\n            output += f\"{line}\\n\"\n            continue\n        if not line or line.isspace():\n            # it's blank\n            output += f\"{line}\\n\"\n            continue\n        if \");\" not in line:\n            # just in case something that isn't a function slips past the previous checks\n            # \");\" should only occur in a function definition\n            output += f\"{line}\\n\"\n            continue\n        output += f\"__attribute__((pcs(\\\"aapcs\\\"))) {line}\\n\"\n    try:\n        with open(join(patched_include_path, file_name), \"w\") as file:\n            file.write(output)\n    except:\n        print_and_exit(\"Failed to write patched file\")\n\nprint(\"libv5rts patched successfully\")"
  },
  {
    "path": "project.pros",
    "content": "{\"py/object\": \"pros.conductor.project.Project\", \"py/state\": {\"project_name\": \"kernel-dev\", \"target\": \"v5\", \"templates\": {\"kernel\": {\"py/object\": \"pros.conductor.templates.local_template.LocalTemplate\", \"location\": \"./template\", \"metadata\": {\"origin\": \"local\", \"output\": \"bin/monolith.bin\", \"hot_output\": \"bin/hot.package.bin\", \"cold_output\": \"bin/cold.package.bin\", \"cold_addr\": 58720256, \"hot_addr\": 125829120}, \"name\": \"kernel\", \"supported_kernels\": null, \"system_files\": [], \"target\": \"v5\", \"user_files\": [], \"version\": \"3.0.0-beta1\"}}, \"upload_options\": {}}}\n"
  },
  {
    "path": "public_symbols.txt",
    "content": "millis\ntask_create\ntask_delete\ntask_delay\ntask_delay_until\ntask_get_priority\ntask_set_priority\ntask_get_state\ntask_suspend\ntask_resume\ntask_get_count\ntask_get_name\ntask_get_by_name\ntask_notify\ntask_notify_ext\ntask_notify_take\ntask_notify_clear\nmutex_create\nmutex_take\nmutex_give\nsem_create\nsem_wait\nsem_post\ntask_abort_delay\nsem_binary_create\nmutex_recursive_create\nmutex_recursive_take\nmutex_recursive_give\nmutex_get_owner\nsem_get_count\nqueue_create\nqueue_prepend\nqueue_append\nqueue_peek\nqueue_recv\nqueue_get_waiting\nqueue_get_available\nqueue_delete\nqueue_reset\n"
  },
  {
    "path": "src/common/README.md",
    "content": "# Common Facilities\n\nThis folder contains common facilities used throughout the PROS 3 kernel, such\nas JSON parsing.\n"
  },
  {
    "path": "src/common/cobs.c",
    "content": "/**\n * \\file common/cobs.c\n *\n * Consistent Overhead Byte Stuffing\n *\n * Contains an implementation of Consistent Overhead Byte Stuffing, adapted from\n * https://github.com/jacquesf/COBS-Consistent-Overhead-Byte-Stuffing\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <string.h>\n\n#include \"cobs.h\"\n\nsize_t cobs_encode_measure(const uint8_t* restrict src, const size_t src_len, const uint32_t prefix) {\n\tsize_t read_idx = 0;\n\tsize_t write_idx = 1;\n\tuint8_t code = 1;\n\n\tuint8_t* prefix_bytes = (uint8_t*)&(prefix);\n\tfor (read_idx = 0; read_idx < 4; read_idx++) {\n\t\tif (prefix_bytes[read_idx] == 0) {\n\t\t\tcode = 1;\n\t\t\twrite_idx++;\n\t\t} else {\n\t\t\twrite_idx++;\n\t\t\tcode++;\n\t\t\t// code will never be 0xff since the length will always be 4\n\t\t}\n\t}\n\tread_idx = 0;\n\n\twhile (read_idx < src_len) {\n\t\tif (src[read_idx] == 0) {\n\t\t\tcode = 1;\n\t\t\twrite_idx++;\n\t\t\tread_idx++;\n\t\t} else {\n\t\t\twrite_idx++;\n\t\t\tread_idx++;\n\t\t\tcode++;\n\t\t\tif (code == 0xff) {\n\t\t\t\tcode = 1;\n\t\t\t\twrite_idx++;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn write_idx;\n}\n\nint cobs_encode(uint8_t* restrict dest, const uint8_t* restrict src, const size_t src_len, const uint32_t prefix) {\n\tsize_t read_idx = 0;\n\tsize_t write_idx = 1;\n\tsize_t code_idx = 0;\n\tuint8_t code = 1;\n\n\tuint8_t* prefix_bytes = (uint8_t*)&prefix;\n\tfor (read_idx = 0; read_idx < 4;) {\n\t\tif (prefix_bytes[read_idx] == 0) {\n\t\t\tdest[code_idx] = code;\n\t\t\tcode = 1;\n\t\t\tcode_idx = write_idx++;\n\t\t\tread_idx++;\n\t\t} else {\n\t\t\tdest[write_idx++] = prefix_bytes[read_idx++];\n\t\t\tcode++;\n\t\t\t// code will never be 0xff since the length of the prefix is 4\n\t\t}\n\t}\n\tread_idx = 0;\n\n\twhile (read_idx < src_len) {\n\t\tif (src[read_idx] == 0) {\n\t\t\tdest[code_idx] = code;\n\t\t\tcode = 1;\n\t\t\tcode_idx = write_idx++;\n\t\t\tread_idx++;\n\t\t} else {\n\t\t\tdest[write_idx++] = src[read_idx++];\n\t\t\tcode++;\n\t\t\tif (code == 0xff) {\n\t\t\t\tdest[code_idx] = code;\n\t\t\t\tcode = 1;\n\t\t\t\tcode_idx = write_idx++;\n\t\t\t}\n\t\t}\n\t}\n\n\tdest[code_idx] = code;\n\n\treturn write_idx;\n}\n"
  },
  {
    "path": "src/common/gid.c",
    "content": "/**\n * \\file gid.c\n *\n * Globally Unique Identifiers Map\n *\n * Contains an implementation to efficiently assign globally unique IDs\n * e.g. to assign entries in a global table\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <limits.h>\n#include <stdint.h>\n\n#include \"common/gid.h\"\n#include \"kapi.h\"\n\n// Note: the V5 is a 32-bit architecture, so we'll use 32-bit integers\n\nvoid gid_init(struct gid_metadata* const metadata) {\n\t// metadata arguments aren't checked for correctness since this is an\n\t// internal data structure\n\tsize_t i;\n\tfor (i = 0; i < metadata->bitmap_size; i++) {\n\t\tmetadata->bitmap[i] = ~0;\n\t}\n\n\tmetadata->bitmap[0] = (~0 << (metadata->reserved));\n\n\tmetadata->_lock = mutex_create();\n\treturn;\n}\n\nuint32_t gid_alloc(struct gid_metadata* const metadata) {\n\tif (mutex_take(metadata->_lock, TIMEOUT_MAX)) {\n\t\tsize_t i;\n\t\tuint32_t gid = 0;\n\t\tuint32_t* gid_word = NULL;\n\t\tuint32_t gid_idx = 0;\n\t\t// check if the _cur_val + 1 is free\n\t\tif (!gid_check(metadata, (metadata->_cur_val + 1) % metadata->max)) {\n\t\t\t// that gid was free! so allocate it\n\t\t\tgid = metadata->_cur_val = (metadata->_cur_val + 1) % metadata->max;\n\t\t\tgid_word = metadata->bitmap + (gid / UINT32_WIDTH);\n\t\t\tgid_idx = gid % UINT32_WIDTH;\n\t\t\tgoto return_gid;\n\t\t} else {\n\t\t\tfor (i = 0; i < metadata->bitmap_size; i++) {\n\t\t\t\tgid_word = metadata->bitmap + i;\n\t\t\t\tif (*gid_word == 0) {  // all GIDs in this word are assigned\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// __builtin_ctz counts trailing zeros. This effectively returns the\n\t\t\t\t// position of the first unassigned gid withing the word\n\t\t\t\tgid_idx = __builtin_ctz(*gid_word);\n\t\t\t\tgid = gid_idx + (i * UINT32_WIDTH);\n\t\t\t\t// mark the id as allocated\n\t\t\t\tgoto return_gid;\n\t\t\t}\n\t\t}\n\treturn_gid:\n\t\tif (gid > metadata->max || gid == 0) {\n\t\t\tmutex_give(metadata->_lock);\n\t\t\treturn 0;\n\t\t}\n\t\t*gid_word &= ~(1 << gid_idx);\n\t\tmetadata->_cur_val = gid;\n\t\tmutex_give(metadata->_lock);\n\t\treturn gid;\n\t}\n\treturn 0;\n}\n\nvoid gid_free(struct gid_metadata* const metadata, uint32_t id) {\n\tif (id > metadata->max || id == 0) {\n\t\treturn;\n\t}\n\n\tsize_t word_idx = id / UINT32_WIDTH;\n\tmetadata->bitmap[word_idx] |= 1 << (id % UINT32_WIDTH);\n}\n\nbool gid_check(struct gid_metadata* metadata, uint32_t id) {\n\tif (id > metadata->max) {\n\t\treturn false;\n\t}\n\n\tsize_t word_idx = id / UINT32_WIDTH;\n\treturn (metadata->bitmap[word_idx] & (1 << (id % UINT32_WIDTH))) ? false : true;\n}\n"
  },
  {
    "path": "src/common/linkedlist.c",
    "content": "/*\n * \\file common/linkedlist.c\n *\n * Linked list implementation for internal use\n *\n * This file defines a linked list implementation that operates on the FreeRTOS\n * heap, and is able to generically store function pointers and data\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <stddef.h>  // NULL\n\n#include \"common/linkedlist.h\"\n#include \"kapi.h\"\n\n// NOTE: Do not intermix data and function payloads. This may cause data to be \n// re-evaluated as a pointer to an area in memory and a false free or add.\n\nll_node_s_t* linked_list_init_func_node(generic_fn_t func) {\n\tll_node_s_t* node = (ll_node_s_t*)kmalloc(sizeof *node);\n\tnode->payload.func = func;\n\tnode->next = NULL;\n\n\treturn node;\n}\n\nll_node_s_t* linked_list_init_data_node(void* data) {\n\tll_node_s_t* node = (ll_node_s_t*)kmalloc(sizeof *node);\n\tnode->payload.data = data;\n\tnode->next = NULL;\n\n\treturn node;\n}\n\nlinked_list_s_t* linked_list_init() {\n\tlinked_list_s_t* list = (linked_list_s_t*)kmalloc(sizeof *list);\n\tlist->head = NULL;\n\n\treturn list;\n}\n\nvoid linked_list_prepend_func(linked_list_s_t* list, generic_fn_t func) {\n\tif (list == NULL) list = linked_list_init();\n\n\tll_node_s_t* n = linked_list_init_func_node(func);\n\n\tn->next = list->head;\n\tlist->head = n;\n}\n\nvoid linked_list_prepend_data(linked_list_s_t* list, void* data) {\n\tif (list == NULL) list = linked_list_init();\n\n\tll_node_s_t* n = linked_list_init_data_node(data);\n\n\tn->next = list->head;\n\tlist->head = n;\n}\n\nvoid linked_list_append_func(linked_list_s_t* list, generic_fn_t func) {\n\tif (list == NULL) list = linked_list_init();\n\n\tll_node_s_t* n = linked_list_init_func_node(func);\n\n\tif (list->head == NULL) {\n\t\tlist->head = n;\n\t\treturn;\n\t}\n\n\tll_node_s_t* it = list->head;\n\twhile (it->next != NULL) it = it->next;\n\n\tit->next = n;\n}\n\nvoid linked_list_remove_func(linked_list_s_t* list, generic_fn_t func) {\n\tif (list == NULL || list->head == NULL) return;\n\n\tll_node_s_t* it = list->head;\n\tll_node_s_t* p = NULL;\n\twhile (it != NULL) {\n\t\tif (it->payload.func == func) {\n\t\t\tif (p == NULL)\n\t\t\t\tlist->head = it->next;\n\t\t\telse\n\t\t\t\tp->next = it->next;\n\t\t\tkfree(it);\n\t\t\tbreak;\n\t\t}\n\n\t\tp = it;\n\t\tit = it->next;\n\t}\n}\n\nvoid linked_list_append_data(linked_list_s_t* list, void* data) {\n\tif (list == NULL) list = linked_list_init();\n\n\tll_node_s_t* n = linked_list_init_data_node(data);\n\n\tif (list->head == NULL) {\n\t\tlist->head = n;\n\t\treturn;\n\t}\n\n\tll_node_s_t* it = list->head;\n\twhile (it->next != NULL) it = it->next;\n\n\tit->next = n;\n}\n\nvoid linked_list_remove_data(linked_list_s_t* list, void* data) {\n\tif (list == NULL || list->head == NULL) return;\n\n\tll_node_s_t* it = list->head;\n\tll_node_s_t* p = NULL;\n\twhile (it != NULL) {\n\t\tif (it->payload.data == data) {\n\t\t\tif (p == NULL)\n\t\t\t\tlist->head = it->next;\n\t\t\telse\n\t\t\t\tp->next = it->next;\n\t\t\tkfree(it);\n\t\t\tbreak;\n\t\t}\n\n\t\tp = it;\n\t\tit = it->next;\n\t}\n}\n\nvoid linked_list_foreach(linked_list_s_t* list, linked_list_foreach_fn_t cb, void* extra_data) {\n\tif (list == NULL || list->head == NULL) return;\n\n\tll_node_s_t* it = list->head;\n\twhile (it != NULL) {\n\t\tcb(it, extra_data);\n\t\tit = it->next;\n\t}\n}\n\nvoid linked_list_free(linked_list_s_t* list) {\n\tif (list == NULL || list->head == NULL) return;\n\n\twhile (list->head != NULL) {\n\t\tll_node_s_t* node = list->head;\n\t\tlist->head = node->next;\n\t\tkfree(node);\n\t}\n\tkfree(list);\n}\n"
  },
  {
    "path": "src/common/set.c",
    "content": "/**\n * \\file common/set.c\n *\n * Contains an implementation of a thread-safe basic set in the kernel heap.\n * It's used to check which streams are enabled in ser_driver for the moment,\n * but also has list_contains which may be useful in other contexts.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <string.h>\n\n#include \"common/set.h\"\n#include \"kapi.h\"\n#include \"system/optimizers.h\"\n\nvoid set_initialize(struct set* const set) {\n\tset->arr = kmalloc(8 * sizeof(*(set->arr)));\n\tset->used = 0;\n\tset->size = 8;\n\tset->mtx = mutex_create_static(&(set->mtx_buf));\n}\n\nbool set_add(struct set* const set, uint32_t item) {\n\tsize_t i = 0;\n\tif (!mutex_take(set->mtx, TIMEOUT_MAX)) {\n\t\treturn false;\n\t}\n\tfor (i = 0; i < set->used; i++) {\n\t\tif (set->arr[i] == item) {\n\t\t\tmutex_give(set->mtx);\n\t\t\treturn true;\n\t\t}\n\t}\n\tif (set->used == set->size) {\n\t\tuint32_t* temp = set->arr;\n\t\tset->arr = kmalloc((set->size + 8) * sizeof(*(set->arr)));\n\t\tif (unlikely(set->arr == NULL)) {\n\t\t\tset->arr = temp;\n\t\t\tmutex_give(set->mtx);\n\t\t\treturn false;\n\t\t}\n\t\tmemcpy(set->arr, temp, set->size * sizeof(*(set->arr)));\n\t\tset->size += 8;\n\t}\n\tset->arr[set->used] = item;\n\tset->used++;\n\tmutex_give(set->mtx);\n\treturn true;\n}\n\nbool set_rm(struct set* set, uint32_t item) {\n\tsize_t i = 0;\n\tif (!mutex_take(set->mtx, TIMEOUT_MAX)) {\n\t\treturn false;\n\t}\n\tfor (i = 0; i < set->used - 1; i++) {\n\t\tif (set->arr[i] == item) {\n\t\t\tmemcpy(set->arr + i, set->arr + i + 1, set->used - i - 1);\n\t\t\tset->used--;\n\t\t\tmutex_give(set->mtx);\n\t\t\treturn true;\n\t\t}\n\t}\n\tif (set->arr[set->used] == item) {\n\t\t// this is the last item, no need to do memcpy, just decrement the counter\n\t\tset->used--;\n\t}\n\tmutex_give(set->mtx);\n\treturn true;\n}\n\nbool set_contains(struct set* set, uint32_t item) {\n\tif (!mutex_take(set->mtx, TIMEOUT_MAX)) {\n\t\treturn false;\n\t}\n\tbool ret = list_contains(set->arr, set->used, item);\n\tmutex_give(set->mtx);\n\treturn ret;\n}\n\nbool list_contains(uint32_t const* list, const size_t size, const uint32_t item) {\n\tuint32_t const* const end = list + size;\n\twhile (list <= end) {\n\t\tif (*list == item) {\n\t\t\treturn true;\n\t\t}\n\t\tlist++;\n\t}\n\treturn false;\n}\n"
  },
  {
    "path": "src/common/string.c",
    "content": "/**\n * \\file common/string.c\n *\n * Contains extra string functions useful for PROS and kstrdup/kstrndup which\n * use the kernel heap instead of the user heap\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <string.h>\n\n#include \"kapi.h\"\n\nchar* kstrndup(const char* s, size_t n) {\n\tsize_t copy_len = strnlen(s, n);  // strlen max'd out at n\n\tchar* dupstr = kmalloc(n + 1);\n\tif (!dupstr) {\n\t\treturn NULL;\n\t}\n\tmemset(dupstr, 0, n + 1);\n\tmemcpy(dupstr, s, copy_len);\n\treturn dupstr;\n}\n\nchar* kstrdup(const char* s) {\n\treturn kstrndup(s, strlen(s));\n}\n\nvoid kprint_hex(uint8_t* s, size_t len) {\n\tfor (size_t i = 0; i < len; i++) {\n\t\tif (i % 16 == 0) {\n\t\t\tprintf(\"\\n%u:\\t\", i);\n\t\t}\n\t\tprintf(\"0x%02x \", s[i]);\n\t}\n\tprintf(\"\\n\");\n}\n"
  },
  {
    "path": "src/devices/README.md",
    "content": "# Devices\n\nThese source files implement VDML - the VEX Data Mesh Layer, which controls the\nV5 Smart Devices and other peripherals.\n"
  },
  {
    "path": "src/devices/battery.c",
    "content": "/**\n * \\file devices/battery.c\n *\n * Contains functions for interacting with the V5 Battery.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"kapi.h\"\n#include \"v5_api.h\"\n#include \"vdml/vdml.h\"\n\nint32_t battery_get_voltage(void) {\n\tif (!internal_port_mutex_take(V5_PORT_BATTERY)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tdouble rtn = vexBatteryVoltageGet();\n\tinternal_port_mutex_give(V5_PORT_BATTERY);\n\treturn rtn;\n}\n\nint32_t battery_get_current(void) {\n\tif (!internal_port_mutex_take(V5_PORT_BATTERY)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tdouble rtn = vexBatteryCurrentGet();\n\tinternal_port_mutex_give(V5_PORT_BATTERY);\n\treturn rtn;\n}\n\ndouble battery_get_temperature(void) {\n\tif (!internal_port_mutex_take(V5_PORT_BATTERY)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR_F;\n\t}\n\tdouble rtn = vexBatteryTemperatureGet();\n\tinternal_port_mutex_give(V5_PORT_BATTERY);\n\treturn rtn;\n}\n\ndouble battery_get_capacity(void) {\n\tif (!internal_port_mutex_take(V5_PORT_BATTERY)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR_F;\n\t}\n\tdouble rtn = vexBatteryCapacityGet();\n\tinternal_port_mutex_give(V5_PORT_BATTERY);\n\treturn rtn;\n}\n"
  },
  {
    "path": "src/devices/battery.cpp",
    "content": "/**\n * \\file devices/battery.cpp\n *\n * Contains functions for interacting with the V5 Battery.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"kapi.h\"\n\nnamespace pros {\nnamespace battery {\nusing namespace pros::c;\n\ndouble get_capacity(void) {\n\treturn battery_get_capacity();\n}\n\nstd::int32_t get_current(void) {\n\treturn battery_get_current();\n}\n\ndouble get_temperature(void) {\n\treturn battery_get_temperature();\n}\n\nstd::int32_t get_voltage(void) {\n\treturn battery_get_voltage();\n}\n}  // namespace battery\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/controller.c",
    "content": "/**\n * \\file devices/controller.c\n *\n * Contains functions for interacting with the V5 Controller.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <stdio.h>\n#include <string.h>\n\n#include \"kapi.h\"\n#include \"v5_api.h\"\n#include \"vdml/vdml.h\"\n\n#define CONTROLLER_MAX_COLS ( 20U )\n#define CONTROLLER_MAX_CHARS ( 31U )\n\n// From enum in misc.h\n#define NUM_BUTTONS 13\n\n// button_pressed is used for get_digital_new_press and button_released is used for get_digital_new_release\ntypedef struct __attribute__((__may_alias__)) controller_data {\n\tbool button_pressed[NUM_BUTTONS];\n\tbool button_released[NUM_BUTTONS];\n} controller_data_s_t;\n\nstatic controller_data_s_t data[2] = {\n        {\n                .button_pressed = {false},\n                .button_released = {true, true, true, true, true, true, true, true, true, true, true, true, true},\n        },\n        {\n                .button_pressed = {false},\n                .button_released = {true, true, true, true, true, true, true, true, true, true, true, true, true},\n        }\n};\n\nstatic bool get_button_pressed(int port, int button) {\n\treturn data[port - V5_PORT_CONTROLLER_1].button_pressed[button];\n}\n\nstatic void set_button_pressed(int port, int button, bool state) {\n\tdata[port - V5_PORT_CONTROLLER_1].button_pressed[button] = state;\n}\n\nstatic bool get_button_released(int port, int button) {\n\treturn data[port - V5_PORT_CONTROLLER_1].button_released[button];\n}\n\nstatic void set_button_released(int port, int button, bool state) {\n\tdata[port - V5_PORT_CONTROLLER_1].button_released[button] = state;\n}\n\nint32_t controller_is_connected(controller_id_e_t id) {\n\tuint8_t port;\n\tCONTROLLER_PORT_MUTEX_TAKE(id, port)\n\tint32_t rtn = vexControllerConnectionStatusGet(id);\n\tinternal_port_mutex_give(port);\n\treturn rtn;\n}\n\nint32_t controller_get_analog(controller_id_e_t id, controller_analog_e_t channel) {\n\tuint8_t port;\n\tCONTROLLER_PORT_MUTEX_TAKE(id, port)\n\tint32_t rtn = vexControllerGet(id, channel);\n\tinternal_port_mutex_give(port);\n\treturn rtn;\n}\n\nint32_t controller_get_battery_capacity(controller_id_e_t id) {\n\tuint8_t port;\n\tCONTROLLER_PORT_MUTEX_TAKE(id, port)\n\tint32_t rtn = vexControllerGet(id, BatteryCapacity);\n\tinternal_port_mutex_give(port);\n\treturn rtn;\n}\n\nint32_t controller_get_battery_level(controller_id_e_t id) {\n\tuint8_t port;\n\tCONTROLLER_PORT_MUTEX_TAKE(id, port)\n\tint32_t rtn = vexControllerGet(id, BatteryLevel);\n\tinternal_port_mutex_give(port);\n\treturn rtn;\n}\n\nint32_t controller_get_digital(controller_id_e_t id, controller_digital_e_t button) {\n\tuint8_t port;\n\tCONTROLLER_PORT_MUTEX_TAKE(id, port)\n\t// the buttons enum starts at 6, the correct place for the libv5rts\n\tint32_t rtn = vexControllerGet(id, button);\n\tinternal_port_mutex_give(port);\n\treturn rtn;\n}\n\nint32_t controller_get_digital_new_press(controller_id_e_t id, controller_digital_e_t button) {\n\tint32_t pressed = controller_get_digital(id, button);\n\tuint8_t port;\n\tCONTROLLER_PORT_MUTEX_TAKE(id, port)\n\tuint8_t button_num = button - E_CONTROLLER_DIGITAL_L1;\n\n\tif (!pressed) {\n\t\tset_button_pressed(port, button_num, false);\n\t}\n\tif (pressed && !get_button_pressed(port, button_num)) {\n\t\t// button is currently pressed and was not detected as being pressed during\n\t\t// last check\n\t\tset_button_pressed(port, button_num, true);\n\t\tinternal_port_mutex_give(port);\n\t\treturn true;\n\t} else {\n\t\tinternal_port_mutex_give(port);\n\t\treturn false;  // button is not pressed or was already detected\n\t}\n}\n\nint32_t controller_get_digital_new_release(controller_id_e_t id, controller_digital_e_t button) {\n\tint32_t pressed = controller_get_digital(id, button);\n\tuint8_t port;\n\tCONTROLLER_PORT_MUTEX_TAKE(id, port)\n\tuint8_t button_num = button - E_CONTROLLER_DIGITAL_L1;\n\n\tif (pressed) {\n\t\tset_button_released(port, button_num, false);\n\t}\n\tif (!pressed && !get_button_released(port, button_num)) {\n\t\t// button is currently not pressed and was detected as being pressed during\n\t\t// last check\n\t\tset_button_released(port, button_num, true);\n\t\tinternal_port_mutex_give(port);\n\t\treturn true;\n\t} else {\n\t\tinternal_port_mutex_give(port);\n\t\treturn false;  // button is pressed or was already detected\n\t}\n}\n\nint32_t controller_set_text(controller_id_e_t id, uint8_t line, uint8_t col, const char* str) {\n\tuint8_t port;\n\tCONTROLLER_PORT_MUTEX_TAKE(id, port)\n\tline++;\n\tif (col >= CONTROLLER_MAX_COLS)\n\t\tcol = CONTROLLER_MAX_COLS;\n\telse\n\t\tcol++;\n\n\tchar* buf = strndup(str, CONTROLLER_MAX_CHARS + 1);\n\n\tuint32_t rtn_val = vexControllerTextSet(id, line, col, buf);\n\tfree(buf);\n\tinternal_port_mutex_give(port);\n\n\tif (!rtn_val) {\n\t\terrno = EAGAIN;\n\t\treturn PROS_ERR;\n\t}\n\treturn 1;\n}\n\nint32_t controller_print(controller_id_e_t id, uint8_t line, uint8_t col, const char* fmt, ...) {\n\tuint8_t port;\n\tCONTROLLER_PORT_MUTEX_TAKE(id, port)\n\tline++;\n\tif (col >= CONTROLLER_MAX_COLS)\n\t\tcol = CONTROLLER_MAX_COLS;\n\telse\n\t\tcol++;\n\n\tva_list args;\n\tva_start(args, fmt);\n\tchar* buf = (char*)malloc(CONTROLLER_MAX_CHARS + 1);\n\tvsnprintf(buf, CONTROLLER_MAX_CHARS + 1, fmt, args);\n\n\tuint32_t rtn_val = vexControllerTextSet(id, line, col, buf);\n\tfree(buf);\n\tva_end(args);\n\n\tinternal_port_mutex_give(port);\n\n\tif (!rtn_val) {\n\t\terrno = EAGAIN;\n\t\treturn PROS_ERR;\n\t}\n\treturn 1;\n}\n\nint32_t controller_clear_line(controller_id_e_t id, uint8_t line) {\n\tuint8_t port;\n\tCONTROLLER_PORT_MUTEX_TAKE(id, port);\n\tint32_t rtn;\n\tif (vexSystemVersion() >= 0x1000C38) {\n\t\tstatic char* clear = \"\";\n\t\trtn = vexControllerTextSet(id, ++line, 1, clear);\n\t} else {\n\t\tstatic char* clear = \"                   \";\n\t\tkassert(strlen(clear) == CONTROLLER_MAX_COLS);\n\t\trtn = vexControllerTextSet(id, ++line, 1, clear);\n\t}\n\tinternal_port_mutex_give(port);\n\treturn rtn;\n}\n\nint32_t controller_clear(controller_id_e_t id) {\n\tif (vexSystemVersion() > 0x01000000) {\n\t\treturn controller_print(id, -1, 0, \"\");\n\t} else {\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\tint32_t rtn = controller_clear_line(id, i);\n\t\t\tif (rtn == PROS_ERR) return PROS_ERR;\n\t\t\tif (i != 2) delay(55);\n\t\t}\n\t\treturn 1;\n\t}\n}\n\nint32_t controller_rumble(controller_id_e_t id, const char* rumble_pattern) {\n\treturn controller_set_text(id, 3, 0, rumble_pattern);\n}\n\nuint8_t competition_get_status(void) {\n\treturn vexCompetitionStatus();\n}\n\nuint8_t competition_is_disabled(void) {\n\treturn (competition_get_status() & COMPETITION_DISABLED) != 0;\n}\n\nuint8_t competition_is_connected(void) {\n\treturn (competition_get_status() & COMPETITION_CONNECTED) != 0;\n}\n\nuint8_t competition_is_autonomous(void) {\n\treturn (competition_get_status() & COMPETITION_AUTONOMOUS) != 0;\n}\n\nuint8_t competition_is_field(void) {\n\treturn ((competition_get_status() & COMPETITION_SYSTEM) != 0) && competition_is_connected();\n}\n\nuint8_t competition_is_switch(void) {\n\treturn ((competition_get_status() & COMPETITION_SYSTEM) == 0) && competition_is_connected();\n}\n"
  },
  {
    "path": "src/devices/controller.cpp",
    "content": "/**\n * \\file devices/controller.cpp\n *\n * Contains functions for interacting with the V5 Controller, as well as the\n * competition control functions.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"kapi.h\"\n\nnamespace pros {\ninline namespace v5 {\nusing namespace pros::c;\n\nController::Controller(pros::controller_id_e_t id) : _id(id) {}\n\nstd::int32_t Controller::is_connected(void) {\n\treturn controller_is_connected(_id);\n}\n\nstd::int32_t Controller::get_analog(pros::controller_analog_e_t channel) {\n\treturn controller_get_analog(_id, channel);\n}\n\nstd::int32_t Controller::get_battery_capacity(void) {\n\treturn controller_get_battery_capacity(_id);\n}\n\nstd::int32_t Controller::get_battery_level(void) {\n\treturn controller_get_battery_level(_id);\n}\n\nstd::int32_t Controller::get_digital(pros::controller_digital_e_t button) {\n\treturn controller_get_digital(_id, button);\n}\n\nstd::int32_t Controller::get_digital_new_press(pros::controller_digital_e_t button) {\n\treturn controller_get_digital_new_press(_id, button);\n}\n\nstd::int32_t Controller::get_digital_new_release(pros::controller_digital_e_t button) {\n\treturn controller_get_digital_new_release(_id, button);\n}\n\nstd::int32_t Controller::set_text(std::uint8_t line, std::uint8_t col, const char* str) {\n\treturn controller_set_text(_id, line, col, str);\n}\n\nstd::int32_t Controller::set_text(std::uint8_t line, std::uint8_t col, const std::string& str) {\n\treturn controller_set_text(_id, line, col, str.c_str());\n}\n\nstd::int32_t Controller::clear_line(std::uint8_t line) {\n\treturn controller_clear_line(_id, line);\n}\n\nstd::int32_t Controller::clear(void) {\n\treturn controller_clear(_id);\n}\n\nstd::int32_t Controller::rumble(const char* rumble_pattern) {\n\treturn controller_rumble(_id, rumble_pattern);\n}\n\n}  // namespace v5\n\nnamespace competition {\nusing namespace pros::c;\nstd::uint8_t get_status(void) {\n\treturn competition_get_status();\n}\n\nstd::uint8_t is_autonomous(void) {\n\treturn competition_is_autonomous();\n}\n\nstd::uint8_t is_connected(void) {\n\treturn competition_is_connected();\n}\n\nstd::uint8_t is_disabled(void) {\n\treturn competition_is_disabled();\n}\n\nstd::uint8_t is_field_control(void) {\n\treturn competition_is_field();\n}\n\nstd::uint8_t is_competition_switch(void) {\n\treturn competition_is_switch();\n}\n\n}  // namespace competition\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/registry.c",
    "content": "/**\n * \\file devices/registry.c\n *\n * This file is the VDML (Vex Data Management Layer) Registry. It keeps track of\n * what devices are in use on the V5. Therefore, in order to use V5 devices with\n * PROS, they must be registered and deregistered using the registry.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n#include <stdio.h>\n\n#include \"api.h\"\n#include \"kapi.h\"\n#include \"pros/misc.h\"\n#include \"v5_api.h\"\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\nstatic v5_smart_device_s_t registry[V5_MAX_DEVICE_PORTS];\nstatic V5_DeviceType registry_types[V5_MAX_DEVICE_PORTS];\n\nvoid registry_init() {\n\tint i;\n\tkprint(\"[VDML][INFO]Initializing registry\\n\");\n\tregistry_update_types();\n\tfor (i = 0; i < NUM_V5_PORTS; i++) {\n\t\tregistry[i].device_type = (v5_device_e_t)registry_types[i];\n\t\tregistry[i].device_info = vexDeviceGetByIndex(i);\n\t\tif (registry[i].device_type != E_DEVICE_NONE) {\n\t\t\tkprintf(\"[VDML][INFO]Register device in port %d\", i + 1);\n\t\t}\n\t}\n\tkprint(\"[VDML][INFO]Done initializing registry\\n\");\n}\n\nvoid registry_update_types() {\n\tvexDeviceGetStatus(registry_types);\n}\n\nint registry_bind_port(uint8_t port, v5_device_e_t device_type) {\n\tif (!VALIDATE_PORT_NO(port)) {\n\t\tkprintf(\"[VDML][ERROR]Registration: Invalid port number %d\\n\", port + 1);\n\t\terrno = ENXIO;\n\t\treturn PROS_ERR;\n\t}\n\tif (registry[port].device_type != E_DEVICE_NONE) {\n\t\tkprintf(\"[VDML][ERROR]Registration: Port already in use %d\\n\", port + 1);\n\t\terrno = EADDRINUSE;\n\t\treturn PROS_ERR;\n\t}\n\tif ((v5_device_e_t)registry_types[port] != device_type && (v5_device_e_t)registry_types[port] != E_DEVICE_NONE) {\n\t\tkprintf(\"[VDML][ERROR]Registration: Device mismatch in port %d\\n\", port + 1);\n\t\terrno = EADDRINUSE;\n\t\treturn PROS_ERR;\n\t}\n\tkprintf(\"[VDML][INFO]Registering device in port %d\\n\", port + 1);\n\tv5_smart_device_s_t device;\n\tdevice.device_type = device_type;\n\tdevice.device_info = vexDeviceGetByIndex(port);\n\tregistry[port] = device;\n\treturn 1;\n}\n\nint registry_unbind_port(uint8_t port) {\n\tif (!VALIDATE_PORT_NO(port)) {\n\t\terrno = ENXIO;\n\t\treturn PROS_ERR;\n\t}\n\tregistry[port].device_type = E_DEVICE_NONE;\n\tregistry[port].device_info = NULL;\n\treturn 1;\n}\n\nv5_smart_device_s_t* registry_get_device(uint8_t port) {\n\tif (!VALIDATE_PORT_NO(port)) {\n\t\terrno = ENXIO;\n\t\treturn NULL;\n\t}\n\treturn &registry[port];\n}\n\nv5_smart_device_s_t* registry_get_device_internal(uint8_t port) {\n\tif (!VALIDATE_PORT_NO_INTERNAL(port)) {\n\t\terrno = ENXIO;\n\t\treturn NULL;\n\t}\n\treturn &registry[port];\n}\n\nv5_device_e_t registry_get_bound_type(uint8_t port) {\n\tif (!VALIDATE_PORT_NO(port)) {\n\t\terrno = ENXIO;\n\t\treturn E_DEVICE_UNDEFINED;\n\t}\n\treturn registry[port].device_type;\n}\n\nv5_device_e_t registry_get_plugged_type(uint8_t port) {\n\tif (!VALIDATE_PORT_NO(port)) {\n\t\terrno = ENXIO;\n\t\treturn -1;\n\t}\n\treturn registry_types[port];\n}\n\nint32_t registry_validate_binding(uint8_t port, v5_device_e_t expected_t) {\n\tif (!VALIDATE_PORT_NO(port)) {\n\t\terrno = ENXIO;\n\t\treturn PROS_ERR;\n\t}\n\n\t// Get the registered and plugged types\n\tv5_device_e_t registered_t = registry_get_bound_type(port);\n\tv5_device_e_t actual_t = registry_get_plugged_type(port);\n\n\t// Auto register the port if needed\n\tif (registered_t == E_DEVICE_NONE && actual_t != E_DEVICE_NONE) {\n\t\tregistry_bind_port(port, actual_t);\n\t\tregistered_t = registry_get_bound_type(port);\n\t}\n\n\tif ((expected_t == registered_t || expected_t == E_DEVICE_NONE) && registered_t == actual_t) {\n\t\t// All are same OR expected is none (bgp) AND reg = act.\n\t\t// All good\n\t\tvdml_unset_port_error(port);\n\t\treturn 0;\n\t} else if (actual_t == E_DEVICE_NONE) {\n\t\t// Warn about nothing plugged\n\t\tif (!vdml_get_port_error(port)) {\n\t\t\tkprintf(\"[VDML][WARNING] No device in port %d. Is it plugged in?\\n\", port + 1);\n\t\t\tvdml_set_port_error(port);\n\t\t}\n\t\terrno = ENODEV;\n\t\treturn 1;\n\t} else {\n\t\t// Warn about a mismatch\n\t\tif (!vdml_get_port_error(port)) {\n\t\t\tkprintf(\"[VDML][WARNING] Device mismatch in port %d.\\n\", port + 1);\n\t\t\tvdml_set_port_error(port);\n\t\t}\n\t\terrno = EADDRINUSE;\n\t\treturn 2;\n\t}\n}\n"
  },
  {
    "path": "src/devices/screen.c",
    "content": "/**\n * \\file screen.c\n *\n * \\brief Brain screen display and touch functions.\n *\n * Contains user calls to the v5 screen for touching and displaying graphics.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"pros/screen.h\"\n\n#include <stdint.h>\n#include <stdlib.h>\n#include <sys/_stdint.h>\n\n#include \"common/linkedlist.h\"\n#include \"kapi.h\"\n#include \"pros/apix.h\"\n#include \"v5_api.h\"  // vexDisplay* \n\n/******************************************************************************/\n/**                  Screen Graphical Display Functions                      **/\n/**                                                                          **/\n/**   These functions allow programmers to display shapes on the v5 screen   **/\n/******************************************************************************/\n\nstatic mutex_t _screen_mutex = NULL;\n\ntypedef struct touch_event_position_data_s {\n\tint16_t x;\n\tint16_t y;\n} touch_event_position_data_s_t;\n\nuint32_t screen_set_pen(uint32_t color){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayForegroundColor(color);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_set_eraser(uint32_t color){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayBackgroundColor(color);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_get_pen(void){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tuint32_t color = vexDisplayForegroundColorGet();\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t}\n\treturn color;\n}\n\nuint32_t screen_get_eraser(void){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tuint32_t color = vexDisplayBackgroundColorGet();\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t}\n\treturn color;\n}\n\nuint32_t screen_erase(void){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayErase();\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_scroll(int16_t start_line, int16_t lines){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayScroll(start_line, lines);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_scroll_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t lines){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayScrollRect(x0, y0, x1, y1, lines);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_copy_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32_t* buf, int32_t stride){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayCopyRect(x0, y0, x1, y1, buf, stride);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_draw_pixel(int16_t x, int16_t y){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayPixelSet(x, y);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_erase_pixel(int16_t x, int16_t y){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayPixelClear(x, y);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayLineDraw(x0, y0, x1, y1);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_erase_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayLineClear(x0, y0, x1, y1);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_draw_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayRectDraw(x0, y0, x1, y1);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_erase_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayRectClear(x0, y0, x1, y1);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_fill_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayRectFill(x0, y0, x1, y1);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_draw_circle(int16_t x, int16_t y, int16_t radius){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayCircleDraw(x, y, radius);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_erase_circle(int16_t x, int16_t y, int16_t radius){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayCircleClear(x, y, radius);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_fill_circle(int16_t x, int16_t y, int16_t radius){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDisplayCircleFill(x, y, radius);\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\n/******************************************************************************/\n/**                       Screen Text Display Functions                      **/\n/**                                                                          **/\n/**     These functions allow programmers to display text on the v5 screen   **/\n/******************************************************************************/\n\nuint32_t screen_print(text_format_e_t txt_fmt, const int16_t line, const char* text, ...){\n    va_list args;\n    va_start(args, text);\n    if (screen_vprintf((uint8_t)txt_fmt, line, text, args) == PROS_ERR) {\n\t\treturn PROS_ERR;\n\t}\n    va_end(args);\n\treturn 1;\n}\n\nuint32_t screen_print_at(text_format_e_t txt_fmt, int16_t x, int16_t y, const char* text, ...){\n    va_list args;\n    va_start(args, text);\n    if (screen_vprintf_at((uint8_t)txt_fmt, x, y, text, args) == PROS_ERR) {\n\t\treturn PROS_ERR;\n\t}\n    va_end(args);\n\treturn 1;\n}\n\nuint32_t screen_vprintf(text_format_e_t txt_fmt, const int16_t line, const char* text, va_list args){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tchar* out;\n\tvasprintf(&out, text, args);\n\tva_list empty;\n\tswitch(txt_fmt){\n\tcase E_TEXT_SMALL:\n\tcase E_TEXT_MEDIUM:\n\t\t{\n            vexDisplayVString(line, out, empty);\n            break;\n        }\n    case E_TEXT_LARGE:\n\t\t{\n            vexDisplayVBigString(line, out, empty);\n            break;\n        }\n    case E_TEXT_MEDIUM_CENTER:\n\t\t{\n            vexDisplayVCenteredString(line, out, empty);\n            break;\n        }\n    case E_TEXT_LARGE_CENTER:\n        {\n            vexDisplayVBigCenteredString(line, out, empty);\n            break;\n        }\n    default:\n        {\n            vexDisplayVString(line, out, empty);\n            break;\n        }\n    }\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nuint32_t screen_vprintf_at(text_format_e_t txt_fmt, const int16_t x, const int16_t y, const char* text, va_list args){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tchar* out;\n\tvasprintf(&out, text, args);\n\tva_list empty;\n\tswitch(txt_fmt){\n    case E_TEXT_SMALL:\n\t\t{\n            vexDisplayVSmallStringAt(x, y, out, empty);\n            break;\n        }\n    case E_TEXT_MEDIUM:\n    case E_TEXT_MEDIUM_CENTER:\n\t\t{\n            vexDisplayVStringAt(x, y, out, empty);\n            break;\n        }\n    case E_TEXT_LARGE:\n    case E_TEXT_LARGE_CENTER:\n\t\t{\n            vexDisplayVBigStringAt(x, y, out, empty);\n            break;\n        }\n    default:\n        {\n            vexDisplayVStringAt(x, y, out, empty);\n            break;\n        }\n    }\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n/******************************************************************************/\n/**                         Screen Touch Functions                           **/\n/**                                                                          **/\n/**               These functions allow programmers to access                **/\n/**                    information about screen touches                      **/\n/******************************************************************************/\n\nstatic const screen_touch_status_s_t PROS_SCREEN_ERR = {.touch_status = E_TOUCH_ERROR, .x = -1, .y = -1, .press_count = -1, .release_count = -1};\n\nscreen_touch_status_s_t screen_touch_status(void){\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_SCREEN_ERR;\n\t}\n\tV5_TouchStatus v5_touch_status;\n\tscreen_touch_status_s_t rtv;\n\tvexTouchDataGet(&v5_touch_status);\n\trtv.touch_status = (last_touch_e_t)v5_touch_status.lastEvent;\n\trtv.x = v5_touch_status.lastXpos;\n\trtv.y = v5_touch_status.lastYpos;\n\trtv.press_count = v5_touch_status.pressCount;\n\trtv.release_count = v5_touch_status.releaseCount;\n\tif (!mutex_give(_screen_mutex)) {\n\t\terrno = EACCES;\n\t\treturn PROS_SCREEN_ERR;\n\t} \n\treturn rtv;\n}\n\nstatic linked_list_s_t* _touch_event_release_handler_list = NULL;\nstatic linked_list_s_t* _touch_event_press_handler_list = NULL;\nstatic linked_list_s_t* _touch_event_press_auto_handler_list = NULL;\n\nstatic void _set_up_touch_callback_storage() {\n\t_touch_event_release_handler_list = linked_list_init();\n\t_touch_event_press_handler_list = linked_list_init();\n\t_touch_event_press_auto_handler_list = linked_list_init();\n}\n\nuint32_t screen_touch_callback(touch_event_cb_fn_t cb, last_touch_e_t event_type) {\n\tif (!mutex_take(_screen_mutex, TIMEOUT_MAX)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tswitch (event_type) {\n\tcase E_TOUCH_RELEASED:\n\t\tlinked_list_prepend_func(_touch_event_release_handler_list, (generic_fn_t)cb);\n\t\tbreak;\n\tcase E_TOUCH_PRESSED:\n\t\tlinked_list_prepend_func(_touch_event_press_handler_list, (generic_fn_t)cb);\n\t\tbreak;\n\tcase E_TOUCH_HELD:\n\t\tlinked_list_prepend_func(_touch_event_press_auto_handler_list, (generic_fn_t)cb);\n\t\tbreak;\n\tcase E_TOUCH_ERROR:\n\t\treturn PROS_ERR;\n\t\tbreak;\n\t}\n\tif (!mutex_give(_screen_mutex)) {\n\t\treturn PROS_ERR;\n\t} else {\n\t\treturn 1;\n\t}\n}\n\nstatic task_stack_t touch_handle_task_stack[TASK_STACK_DEPTH_DEFAULT];\nstatic static_task_s_t touch_handle_task_buffer;\nstatic task_t touch_handle_task;\n\n// volatile because some linters think this is going to be optimized out\nstatic volatile void _handle_cb(ll_node_s_t* current, void* extra_data) {\n\t(current->payload.func)();\n}\n\nstatic inline bool _touch_status_equivalent(V5_TouchStatus x, V5_TouchStatus y) {\n\treturn (x.lastEvent == y.lastEvent) && (x.lastXpos == y.lastXpos) && (x.lastYpos == y.lastYpos);\n}\n\nvoid _touch_handle_task(void* ignore) {\n\tV5_TouchStatus current = {0}, last = {0};\n\twhile (true) {\n\t\tmutex_take(_screen_mutex, TIMEOUT_MAX);\n        vexTouchDataGet(&current);\n\t\tmutex_give(_screen_mutex);\n\t\tif (!_touch_status_equivalent(current, last)) {\n\t\t\tswitch (current.lastEvent) {\n\t\t\tcase E_TOUCH_RELEASED:\n\t\t\t\tlinked_list_foreach(_touch_event_release_handler_list, _handle_cb, NULL);\n\t\t\t\tbreak;\n\t\t\tcase E_TOUCH_PRESSED:\n\t\t\t\tlinked_list_foreach(_touch_event_press_handler_list, _handle_cb, NULL);\n\t\t\t\tbreak;\n\t\t\tcase E_TOUCH_HELD:\n\t\t\t\tlinked_list_foreach(_touch_event_press_auto_handler_list, _handle_cb, NULL);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlast = current;\n\t\t}\n\t\tdelay(10);\n\t}\n}\n\n// internal functions for different mechanisms\n\nvoid display_fatal_error(const char* text) {\n\t// in fatal error state, cannot rely on integrity of the RTOS\n\tchar s[50];\n\tstrncpy(s, text, 50);\n\tvexDisplayForegroundColor(COLOR_RED);\n\tvexDisplayRectFill(0, 0, 480, 19);\n\tvexDisplayRectFill(0, 0, 27, 240);\n\tvexDisplayRectFill(453, 0, 480, 240);\n\tvexDisplayRectFill(0, 179, 480, 240);\n\tvexDisplayForegroundColor(0x1A1917);\n\tvexDisplayRectFill(50, 190, 130, 230);\n\tvexDisplayRectFill(200, 190, 280, 230);\n\tvexDisplayRectFill(350, 190, 430, 230);\n\tvexDisplayCenteredString(0, s);\n}\n\nvoid graphical_context_daemon_initialize(void) {\n\t_screen_mutex = mutex_create();\n\t_set_up_touch_callback_storage();\n\ttouch_handle_task =\n\t    task_create_static(_touch_handle_task, NULL, TASK_PRIORITY_MIN + 2, TASK_STACK_DEPTH_DEFAULT,\n\t                       \"PROS Graphics Touch Handler\", touch_handle_task_stack, &touch_handle_task_buffer);\n}"
  },
  {
    "path": "src/devices/screen.cpp",
    "content": "/**\n * \\file screen.cpp\n *\n * \\brief Brain screen display and touch functions.\n *\n * Contains user calls to the v5 screen for touching and displaying graphics.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"pros/screen.hpp\"\n#include <stdint.h>\n\nnamespace pros {\nnamespace screen {\n\n    std::uint32_t set_pen(pros::Color color){\n        return pros::c::screen_set_pen((uint32_t)color);\n    }\n\n    std::uint32_t set_eraser(pros::Color color){\n        return pros::c::screen_set_eraser((uint32_t)color);\n    }\n\n    std::uint32_t set_pen(std::uint32_t color){\n        return pros::c::screen_set_pen(color);\n    }\n\n    std::uint32_t set_eraser(std::uint32_t color) {\n        return pros::c::screen_set_eraser(color);\n    }\n\n    std::uint32_t get_pen(){\n        return pros::c::screen_get_pen();\n    }\n\n    std::uint32_t get_eraser(){\n        return pros::c::screen_get_eraser();\n    }\n\n    std::uint32_t erase(){\n        return pros::c::screen_erase();\n    }\n\n    std::uint32_t scroll(const std::int16_t start_line, const std::int16_t lines){\n        return pros::c::screen_scroll(start_line, lines);\n    }\n\n    std::uint32_t scroll_area(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1, std::int16_t lines){\n        return pros::c::screen_scroll_area(x0, y0, x1, y1, lines);\n    }\n\n    std::uint32_t copy_area(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1, uint32_t* buf, const std::int32_t stride){\n        return pros::c::screen_copy_area( x0, y0, x1, y1, buf, stride);\n    }\n\n    std::uint32_t draw_pixel(const std::int16_t x, const std::int16_t y){\n        return pros::c::screen_draw_pixel(x, y);\n    }\n\n    std::uint32_t erase_pixel(const std::int16_t x, const std::int16_t y){\n        return pros::c::screen_erase_pixel(x, y);\n    }\n\n    std::uint32_t draw_line(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1){\n        return pros::c::screen_draw_line(x0, y0, x1, y1);\n    }\n\n    std::uint32_t erase_line(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1){\n        return pros::c::screen_erase_line(x0, y0, x1, y1);\n    }\n\n    std::uint32_t draw_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1){\n        return pros::c::screen_draw_rect(x0, y0, x1, y1);\n    }\n\n    std::uint32_t erase_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1){\n        return pros::c::screen_erase_rect(x0, y0, x1, y1);\n    }\n\n    std::uint32_t fill_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1){\n        return pros::c::screen_fill_rect(x0, y0, x1, y1);\n    }\n\n    std::uint32_t draw_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius){\n        return pros::c::screen_draw_circle(x, y, radius);\n    }\n\n    std::uint32_t erase_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius){\n        return pros::c::screen_erase_circle(x, y, radius);\n    }\n\n    std::uint32_t fill_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius){\n        return pros::c::screen_fill_circle(x, y, radius);\n    }\n\n    screen_touch_status_s_t touch_status() {\n        return pros::c::screen_touch_status();\n    }\n\n    std::uint32_t touch_callback(touch_event_cb_fn_t cb, last_touch_e_t event_type){\n        return pros::c::screen_touch_callback(cb, event_type);\n    }\n\n    /******************************************************************************/\n    /**                                 LLEMU Weak Stubs                         **/\n    /**                                                                          **/\n    /**   These functions allow main.cpp to be compiled without LVGL present     **/\n    /******************************************************************************/\n    namespace lcd {\n#if !defined(_PROS_INCLUDE_LIBLVGL_LLEMU_HPP) && defined(_PROS_KERNEL_SUPPRESS_LLEMU_WARNING)\n#warning \"liblvgl is not installed. As this is a kernel build, this warning will only be shown once.\"\n#endif\n        using lcd_btn_cb_fn_t = void (*)(void);\n        extern __attribute__((weak)) bool is_initialized(void) {return false;}\n        extern __attribute__((weak)) bool initialize(void) {return false;}\n        extern __attribute__((weak)) bool shutdown(void) {return false;}\n        extern __attribute__((weak)) bool set_text(std::int16_t line, std::string text) {return false;}\n        extern __attribute__((weak)) bool clear(void) {return false;}\n        extern __attribute__((weak)) bool clear_line(std::int16_t line) {return false;}\n        // TODO: Text_Align is defined in liblvgl so this ain't going to compile for now.\n        // extern __attribute__((weak)) void set_text_align(Text_Align text_align) {}\n        extern __attribute__((weak)) void register_btn0_cb(lcd_btn_cb_fn_t cb) {}\n        extern __attribute__((weak)) void register_btn1_cb(lcd_btn_cb_fn_t cb) {}\n        extern __attribute__((weak)) void register_btn2_cb(lcd_btn_cb_fn_t cb) {}\n        extern __attribute__((weak)) std::uint8_t read_buttons(void) {return 0xf;}\n\n        template <typename... Params>\n        extern __attribute__((weak)) bool print(std::int16_t line, const char* fmt, Params... args) {return false;}\n    }  // namespace lcd\n\n}  // namespace screen\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/vdml.c",
    "content": "/**\n * \\file devices/vdml.c\n *\n * VDML - VEX Data Management Layer\n *\n * VDML ensures thread saftey for operations on smart devices by maintaining\n * an array of RTOS Mutexes and implementing functions to take and give them.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"vdml/vdml.h\"\n#include \"kapi.h\"\n#include \"v5_api.h\"\n#include \"vdml/registry.h\"\n\n#include <errno.h>\n#include <stdio.h>\n\n/**\n * Bitmap to indicate if a port has had an error printed or not.\n */\nint32_t port_errors;\n\nextern void registry_init();\nextern void port_mutex_init();\n\nint32_t claim_port_try(uint8_t port, v5_device_e_t type) {\n\tif (!VALIDATE_PORT_NO(port)) {\n\t\terrno = ENXIO;\n\t\treturn 0;\n\t}\n\tif (registry_validate_binding(port, type) != 0) {\n\t\treturn 0;\n\t}\n\tif (!port_mutex_take(port)) {\n\t\terrno = EACCES;\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n/**\n * We have V5_MAX_DEVICE_PORTS so that we can do thread safety on things like\n * controllers, batteries which are sort of like smart devices internally to the\n * V5\n */\nmutex_t port_mutexes[V5_MAX_DEVICE_PORTS];            // Mutexes for each port\nstatic_sem_s_t port_mutex_bufs[V5_MAX_DEVICE_PORTS];  // Stack mem for rtos\n\n/**\n * Shorcut to initialize all of VDML (mutexes and register)\n */\nvoid vdml_initialize() {\n\tport_mutex_init();\n\tregistry_init();\n}\n\n/**\n * Initializes the mutexes for the motor ports.\n *\n * Initializes a static array of FreeRTOS mutexes to protect against race\n * conditions. For example, we don't want the Background processing task to run\n * at the same time that we set a motor, because bad information may be\n * returned, or worse.\n */\nvoid port_mutex_init() {\n\tfor (int i = 0; i < V5_MAX_DEVICE_PORTS; i++) {\n\t\tport_mutexes[i] = mutex_create_static(&(port_mutex_bufs[i]));\n\t}\n}\n\nint port_mutex_take(uint8_t port) {\n\tif (port >= V5_MAX_DEVICE_PORTS) {\n\t\terrno = ENXIO;\n\t\treturn PROS_ERR;\n\t}\n\treturn xTaskGetSchedulerState() != taskSCHEDULER_RUNNING || mutex_take(port_mutexes[port], TIMEOUT_MAX);\n}\n\nint internal_port_mutex_take(uint8_t port) {\n\tif (port >= V5_MAX_DEVICE_PORTS) {\n\t\terrno = ENXIO;\n\t\treturn PROS_ERR;\n\t}\n\treturn mutex_take(port_mutexes[port], TIMEOUT_MAX);\n}\n\nstatic inline char* print_num(char* buff, int num) {\n\t*buff++ = (num / 10) + '0';\n\t*buff++ = (num % 10) + '0';\n\treturn buff;\n}\n\nint port_mutex_give(uint8_t port) {\n\tif (port >= V5_MAX_DEVICE_PORTS) {\n\t\terrno = ENXIO;\n\t\treturn PROS_ERR;\n\t}\n\treturn xTaskGetSchedulerState() != taskSCHEDULER_RUNNING || mutex_give(port_mutexes[port]);\n}\n\nint internal_port_mutex_give(uint8_t port) {\n\tif (port >= V5_MAX_DEVICE_PORTS) {\n\t\terrno = ENXIO;\n\t\treturn PROS_ERR;\n\t}\n\treturn mutex_give(port_mutexes[port]);\n}\n\nvoid port_mutex_take_all() {\n\tfor (int i = 0; i < V5_MAX_DEVICE_PORTS; i++) {\n\t\tport_mutex_take(i);\n\t}\n}\n\nvoid port_mutex_give_all() {\n\tfor (int i = 0; i < V5_MAX_DEVICE_PORTS; i++) {\n\t\tport_mutex_give(i);\n\t}\n}\n\nvoid vdml_set_port_error(uint8_t port) {\n\tif (VALIDATE_PORT_NO(port)) {\n\t\tport_errors |= (1 << port);\n\t}\n}\n\nvoid vdml_unset_port_error(uint8_t port) {\n\tif (VALIDATE_PORT_NO(port)) {\n\t\tport_errors &= ~(1 << port);\n\t}\n}\n\nbool vdml_get_port_error(uint8_t port) {\n\tif (VALIDATE_PORT_NO(port)) {\n\t\treturn (port_errors >> port) & 1;\n\t} else {\n\t\treturn false;\n\t}\n}\n\n#if 0\nvoid vdml_reset_port_error() {\n\tport_errors = 0;\n}\n#endif\n\n/**\n * Background processing function for the VDML system.\n *\n * This function should be called by the system daemon approximately every\n * 2 milliseconds.\n *\n * Updates the registry type array, detecting what devices are actually\n * plugged in according to the system, then compares that with the registry\n * records.\n *\n * On warnings, no operation is performed.\n */\nvoid vdml_background_processing() {\n\n// We're not removing this outright since we want to revisit the idea of logging\n// the errors with devices in the future\n#if 0\n\tstatic int32_t last_port_errors = 0;\n\tstatic int cycle = 0;\n\tcycle++;\n\tif (cycle % 5000 == 0) {\n\t\tvdml_reset_port_error();\n\t\tlast_port_errors = 0;\n\t}\n#endif\n\n\t// Refresh actual device types.\n\tregistry_update_types();\n\n#if 0\n\t// Validate the ports. Warn if mismatch.\n\tuint8_t error_arr[NUM_V5_PORTS];\n\tint num_errors = 0;\n\tint mismatch_errors = 0;\n\tfor (int i = 0; i < NUM_V5_PORTS; i++) {\n\t\terror_arr[i] = registry_validate_binding(i, E_DEVICE_NONE);\n\t\tif (error_arr[i] != 0) num_errors++;\n\t\tif (error_arr[i] == 2) mismatch_errors++;\n\t}\n\t// Every 50 ms\n\tif (cycle % 50 == 0) {\n\t\tif (last_port_errors == port_errors) {\n\t\t\tgoto end_render_errors;\n\t\t}\n\t\tchar line[50];\n\t\tchar* line_ptr = line;\n\t\tif (num_errors == 0)\n\t\t\tline[0] = (char)0;\n\t\telse if (num_errors <= 6) {\n\t\t\t// If we have 1-6 total errors (unplugged + mismatch), we can\n\t\t\t// display a line indicating the ports where these errors occur\n\t\t\tstrcpy(line_ptr, \"PORTS\");\n\t\t\tline_ptr += 5;  // 5 is length of \"PORTS\"\n\t\t\tif (mismatch_errors != 0) {\n\t\t\t\tstrcpy(line_ptr, \" MISMATCHED: \");\n\t\t\t\tline_ptr += 13;  // 13 is length of previous string\n\t\t\t\tfor (int i = 0; i < NUM_V5_PORTS; i++) {\n\t\t\t\t\tif (error_arr[i] == 2) {\n\t\t\t\t\t\tline_ptr = print_num(line_ptr, i + 1);\n\t\t\t\t\t\t*line_ptr++ = ',';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tline_ptr--;\n\t\t\t}\n\t\t\tif (num_errors != mismatch_errors) {\n\t\t\t\tstrcpy(line_ptr, \" UNPLUGGED: \");\n\t\t\t\tline_ptr += 12;  // 12 is length of previous string\n\t\t\t\tfor (int i = 0; i < NUM_V5_PORTS; i++) {\n\t\t\t\t\tif (error_arr[i] == 1) {\n\t\t\t\t\t\tline_ptr = print_num(line_ptr, i + 1);\n\t\t\t\t\t\t*line_ptr++ = ',';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tline_ptr--;\n\t\t\t}\n\t\t} else {\n\t\t\t/* If we have > 6 errors, we display the following:\n\t\t\t * PORT ERRORS: 1..... 6..... 11..... 16.....\n\t\t\t * where each . represents a port. A '.' indicates\n\t\t\t * there is no error on that port, a 'U' indicates\n\t\t\t * the registry expected a device there but there isn't\n\t\t\t * one, and a 'M' indicates the plugged in devices doesn't\n\t\t\t * match what we expect. The numbers are just a visual reference\n\t\t\t * to aid in determining what ports have errors.\n\t\t\t */\n\t\t\tstrcpy(line_ptr, \"PORT ERRORS:\");\n\t\t\tline_ptr += 12;  // 12 is length of previous string\n\t\t\tfor (int i = 0; i < NUM_V5_PORTS; i++) {\n\t\t\t\tif (i % 5 == 0) {\n\t\t\t\t\t*line_ptr++ = ' ';\n\t\t\t\t\tline_ptr = print_num(line_ptr, i + 1);\n\t\t\t\t}\n\t\t\t\tswitch (error_arr[i]) {\n\t\t\t\t\tcase 0:\n\t\t\t\t\t\t*line_ptr++ = '.';\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 1:\n\t\t\t\t\t\t*line_ptr++ = 'U';\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 2:\n\t\t\t\t\t\t*line_ptr++ = 'M';\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t// Should never happen\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t*line_ptr++ = '?';\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Null terminate the string\n\t\t*line_ptr = '\\0';\n\n\tend_render_errors:\n\t\tlast_port_errors = port_errors;\n\t}\n#endif\n}\n"
  },
  {
    "path": "src/devices/vdml_adi.c",
    "content": "/**\n * \\file devices/vdml_adi.c\n *\n * Contains functions for interacting with the V5 ADI.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\nadi_port_config_e_t adi_port_get_config(uint8_t port) {\n\treturn ext_adi_port_get_config(INTERNAL_ADI_PORT, port);\n}\n\nint32_t adi_port_get_value(uint8_t port) {\n\treturn ext_adi_port_get_value(INTERNAL_ADI_PORT, port);\n}\n\nint32_t adi_port_set_config(uint8_t port, adi_port_config_e_t type) {\n\treturn ext_adi_port_set_config(INTERNAL_ADI_PORT, port, type);\n}\n\nint32_t adi_port_set_value(uint8_t port, int32_t value) {\n\treturn ext_adi_port_set_value(INTERNAL_ADI_PORT, port, value);\n}\n\nint32_t adi_analog_calibrate(uint8_t port) {\n\treturn ext_adi_analog_calibrate(INTERNAL_ADI_PORT, port);\n}\n\nint32_t adi_analog_read(uint8_t port) {\n\treturn ext_adi_analog_read(INTERNAL_ADI_PORT, port);\n}\n\nint32_t adi_analog_read_calibrated(uint8_t port) {\n\treturn ext_adi_analog_read_calibrated(INTERNAL_ADI_PORT, port);\n}\n\nint32_t adi_analog_read_calibrated_HR(uint8_t port) {\n\treturn ext_adi_analog_read_calibrated_HR(INTERNAL_ADI_PORT, port);\n}\n\nint32_t adi_digital_read(uint8_t port) {\n\treturn ext_adi_digital_read(INTERNAL_ADI_PORT, port);\n}\n\nint32_t adi_digital_get_new_press(uint8_t port) {\n\treturn ext_adi_digital_get_new_press(INTERNAL_ADI_PORT, port);\n}\n\nint32_t adi_digital_write(uint8_t port, bool value) {\n\treturn ext_adi_digital_write(INTERNAL_ADI_PORT, port, value);\n}\n\nint32_t adi_pin_mode(uint8_t port, uint8_t mode) {\n\treturn ext_adi_pin_mode(INTERNAL_ADI_PORT, port, mode);\n}\n\nint32_t adi_motor_set(uint8_t port, int8_t speed) {\n\treturn ext_adi_motor_set(INTERNAL_ADI_PORT, port, speed);\n}\n\nint32_t adi_motor_get(uint8_t port) {\n\treturn ext_adi_motor_get(INTERNAL_ADI_PORT, port);\n}\n\nint32_t adi_motor_stop(uint8_t port) {\n\treturn ext_adi_motor_stop(INTERNAL_ADI_PORT, port);\n}\n\nadi_encoder_t adi_encoder_init(uint8_t port_top, uint8_t port_bottom, bool reverse) {\n\treturn (adi_encoder_t)ext_adi_encoder_init(INTERNAL_ADI_PORT, port_top, port_bottom, reverse);\n}\n\nint32_t adi_encoder_get(adi_encoder_t enc) {\n\treturn ext_adi_encoder_get((ext_adi_encoder_t)enc);\n}\n\nint32_t adi_encoder_reset(adi_encoder_t enc) {\n\treturn ext_adi_encoder_reset((ext_adi_encoder_t)enc);\n}\n\nint32_t adi_encoder_shutdown(adi_encoder_t enc) {\n\treturn ext_adi_encoder_shutdown((ext_adi_encoder_t)enc);\n}\n\nadi_ultrasonic_t adi_ultrasonic_init(uint8_t port_ping, uint8_t port_echo) {\n\treturn (adi_ultrasonic_t)ext_adi_ultrasonic_init(INTERNAL_ADI_PORT, port_ping, port_echo);\n}\n\nint32_t adi_ultrasonic_get(adi_ultrasonic_t ult) {\n\treturn ext_adi_ultrasonic_get((ext_adi_ultrasonic_t)ult);\n}\n\nint32_t adi_ultrasonic_shutdown(adi_ultrasonic_t ult) {\n\treturn ext_adi_ultrasonic_shutdown((ext_adi_ultrasonic_t)ult);\n}\n\nadi_gyro_t adi_gyro_init(uint8_t adi_port, double multiplier) {\n\treturn (adi_gyro_t)ext_adi_gyro_init(INTERNAL_ADI_PORT, adi_port, multiplier);\n}\n\ndouble adi_gyro_get(adi_gyro_t gyro) {\n\treturn ext_adi_gyro_get((ext_adi_gyro_t)gyro);\n}\n\nint32_t adi_gyro_reset(adi_gyro_t gyro) {\n\treturn ext_adi_gyro_reset((ext_adi_gyro_t)gyro);\n}\n\nint32_t adi_gyro_shutdown(adi_gyro_t gyro) {\n\treturn ext_adi_gyro_shutdown((ext_adi_gyro_t)gyro);\n}\n\nadi_potentiometer_t adi_potentiometer_init(uint8_t port) {\n\treturn (adi_potentiometer_t)ext_adi_potentiometer_init(INTERNAL_ADI_PORT, port, E_ADI_POT_EDR);\n}\n\nadi_potentiometer_t adi_potentiometer_type_init(uint8_t port, adi_potentiometer_type_e_t potentiometer_type) {\n\treturn (adi_potentiometer_t)ext_adi_potentiometer_init(INTERNAL_ADI_PORT, port, potentiometer_type);\n}\n\ndouble adi_potentiometer_get_angle(adi_potentiometer_t potentiometer) {\n\treturn ext_adi_potentiometer_get_angle((ext_adi_potentiometer_t)potentiometer);\n}\n\nadi_led_t adi_led_init(uint8_t port) {\n\treturn (adi_led_t)ext_adi_led_init(INTERNAL_ADI_PORT, port);\n}\n\nint32_t adi_led_set(adi_led_t led, uint32_t* buffer, uint32_t buffer_length) {\n\treturn ext_adi_led_set(led, buffer, buffer_length);\n}\n\nint32_t adi_led_set_pixel(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color, uint32_t pixel_position) {\n\treturn ext_adi_led_set_pixel((ext_adi_led_t)led, buffer, buffer_length, color, pixel_position);\n}\n\nint32_t adi_led_set_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color) {\n\treturn ext_adi_led_set_all((ext_adi_led_t)led, buffer, buffer_length, color);\n}\n\nint32_t adi_led_clear_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_length) {\n\treturn ext_adi_led_set_all((ext_adi_led_t)led, buffer, buffer_length, 0);\n}\n\nint32_t adi_led_clear_pixel(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t pixel_position) {\n\treturn ext_adi_led_set_pixel((ext_adi_led_t)led, buffer, buffer_length, 0, pixel_position);\n}\n"
  },
  {
    "path": "src/devices/vdml_adi.cpp",
    "content": "/**\n * \\file devices/vdml_adi.cpp\n *\n * Contains functions for interacting with the V5 ADI.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"kapi.h\"\n#include \"pros/adi.hpp\"\n#include \"vdml/port.h\"\n\n#define MAX_LED 64\n\nnamespace pros {\nnamespace adi {\nusing namespace pros::c;\n\nPort::Port(std::uint8_t adi_port, adi_port_config_e_t type)\n    : _smart_port(INTERNAL_ADI_PORT), _adi_port(adi_port) {\n\text_adi_port_set_config(_smart_port, _adi_port, type);\n}\n\nPort::Port(ext_adi_port_pair_t port_pair, adi_port_config_e_t type)\n    : _smart_port(port_pair.first), _adi_port(port_pair.second) {\n\text_adi_port_set_config(_smart_port, _adi_port, type);\n}\n\nstd::int32_t Port::set_config(adi_port_config_e_t type) const {\n\treturn ext_adi_port_set_config(_smart_port, _adi_port, type);\n}\n\nstd::int32_t Port::get_config() const {\n\treturn ext_adi_port_get_config(_smart_port, _adi_port);\n}\n\nstd::int32_t Port::set_value(std::int32_t value) const {\n\treturn ext_adi_port_set_value(_smart_port, _adi_port, value);\n}\n\nstd::int32_t Port::get_value() const {\n\treturn ext_adi_port_get_value(_smart_port, _adi_port);\n}\n\next_adi_port_tuple_t Port::get_port() const {\n\treturn std::make_tuple(_smart_port, _adi_port, PROS_ERR_BYTE);\n}\n\nAnalogIn::AnalogIn(std::uint8_t adi_port) : Port(adi_port, E_ADI_ANALOG_IN) {}\nAnalogIn::AnalogIn(ext_adi_port_pair_t port_pair) : Port(port_pair, E_ADI_ANALOG_IN) {}\n\nstd::int32_t AnalogIn::calibrate() const {\n\treturn ext_adi_analog_calibrate(_smart_port, _adi_port);\n}\n\nstd::int32_t AnalogIn::get_value_calibrated() const {\n\treturn ext_adi_analog_read_calibrated(_smart_port, _adi_port);\n}\n\nstd::int32_t AnalogIn::get_value_calibrated_HR() const {\n\treturn ext_adi_analog_read_calibrated_HR(_smart_port, _adi_port);\n}\n\nstd::ostream& operator<<(std::ostream& os, pros::adi::AnalogIn& analog_in) {\n\tos << \"AnalogIn [\";\n\tos << \"smart_port: \" << +analog_in._smart_port;\n\tos << \", adi_port: \" << ((analog_in._adi_port > 10) ? analog_in._adi_port : +analog_in._adi_port);\n\tos << \", value calibrated: \" << analog_in.get_value_calibrated();\n\tos << \", value calibrated HR: \" << analog_in.get_value_calibrated_HR();\n\tos << \", value: \" << analog_in.get_value();\n\tos << \"]\";\n\n\treturn os;\n}\n\nAnalogOut::AnalogOut(std::uint8_t adi_port) : Port(adi_port, E_ADI_ANALOG_OUT) {}\nAnalogOut::AnalogOut(ext_adi_port_pair_t port_pair) : Port(port_pair, E_ADI_ANALOG_OUT) {}\n\nstd::ostream& operator<<(std::ostream& os, pros::adi::AnalogOut& analog_out) {\n\tos << \"AnalogOut [\";\n\tos << \"smart_port: \" << +analog_out._smart_port;\n\tos << \", adi_port: \" << ((analog_out._adi_port > 10) ? analog_out._adi_port : +analog_out._adi_port);\n\tos << \", value: \" << analog_out.get_value();\n\tos << \"]\";\n\n\treturn os;\n}\n\nDigitalIn::DigitalIn(std::uint8_t adi_port) : Port(adi_port, E_ADI_DIGITAL_IN) {}\nDigitalIn::DigitalIn(ext_adi_port_pair_t port_pair) : Port(port_pair, E_ADI_DIGITAL_IN) {}\n\nstd::int32_t DigitalIn::get_new_press() const {\n\treturn ext_adi_digital_get_new_press(_smart_port, _adi_port);\n}\n\nstd::ostream& operator<<(std::ostream& os, pros::adi::DigitalIn& digital_in) {\n\tos << \"DigitalIn [\";\n\tos << \"smart_port: \" << +digital_in._smart_port;\n\tos << \", adi_port: \" << ((digital_in._adi_port > 10) ? digital_in._adi_port : +digital_in._adi_port);\n\tos << \", value: \" << digital_in.get_value();\n\tos << \"]\";\n\n\treturn os;\n}\n\nDigitalOut::DigitalOut(std::uint8_t adi_port, bool init_state) : Port(adi_port, E_ADI_DIGITAL_OUT) {\n\tset_value(init_state);\n}\n\nDigitalOut::DigitalOut(ext_adi_port_pair_t port_pair, bool init_state) : ADIPort(port_pair, E_ADI_DIGITAL_OUT) {\n\tset_value(init_state);\n}\n\nstd::ostream& operator<<(std::ostream& os, pros::adi::DigitalOut& digital_out) {\n\tos << \"DigitalOut [\";\n\tos << \"smart_port: \" << +digital_out._smart_port;\n\tos << \", adi_port: \" << ((digital_out._adi_port > 10) ? digital_out._adi_port : +digital_out._adi_port);\n\tos << \", value: \" << digital_out.get_value();\n\tos << \"]\";\n\n\treturn os;\n}\n\nMotor::Motor(std::uint8_t adi_port) : Port(adi_port, E_ADI_LEGACY_PWM) {\n\tstop();\n}\n\nMotor::Motor(ext_adi_port_pair_t port_pair) : Port(port_pair, E_ADI_LEGACY_PWM) {\n\tstop();\n}\n\nstd::int32_t Motor::stop() const {\n\treturn ext_adi_motor_stop(_smart_port, _adi_port);\n}\n\nEncoder::Encoder(std::uint8_t adi_port_top, std::uint8_t adi_port_bottom, bool reversed) : Port(adi_port_top),  _port_pair(adi_port_top, adi_port_bottom) {\n\tstd::int32_t _port = ext_adi_encoder_init(INTERNAL_ADI_PORT, adi_port_top, adi_port_bottom, reversed);\n\tget_ports(_port, _smart_port, _adi_port);\n}\n\nEncoder::Encoder(ext_adi_port_tuple_t port_tuple, bool reversed) : Port(std::get<1>(port_tuple)), _port_pair(std::get<1>(port_tuple), std::get<2>(port_tuple)) {\n\tstd::int32_t _port =\n\t    ext_adi_encoder_init(std::get<0>(port_tuple), std::get<1>(port_tuple), std::get<2>(port_tuple), reversed);\n\tget_ports(_port, _smart_port, _adi_port);\n}\n\nstd::int32_t Encoder::reset() const {\n\treturn ext_adi_encoder_reset(merge_adi_ports(_smart_port, _adi_port));\n}\n\nstd::int32_t Encoder::get_value() const {\n\treturn ext_adi_encoder_get(merge_adi_ports(_smart_port, _adi_port));\n}\n\next_adi_port_tuple_t ADIEncoder::get_port() const {\n\treturn std::make_tuple(_smart_port, std::get<0>(_port_pair), std::get<1>(_port_pair));\n}\n\nstd::ostream& operator<<(std::ostream& os, pros::adi::Encoder& encoder) {\n\tos << \"Encoder [\";\n\tos << \"smart_port: \" << +encoder._smart_port;\n\tos << \", adi_port: \" << ((encoder._adi_port > 10) ? encoder._adi_port : +encoder._adi_port);\n\tos << \", value: \" << encoder.get_value();\n\tos << \"]\";\n\n\treturn os;\n}\n\nUltrasonic::Ultrasonic(std::uint8_t adi_port_ping, std::uint8_t adi_port_echo) : Port(adi_port_ping) {\n\tstd::int32_t _port = ext_adi_ultrasonic_init(INTERNAL_ADI_PORT, adi_port_ping, adi_port_echo);\n\tget_ports(_port, _smart_port, _adi_port);\n}\n\nUltrasonic::Ultrasonic(ext_adi_port_tuple_t port_tuple) : Port(std::get<1>(port_tuple)) {\n\tstd::int32_t _port =\n\t    ext_adi_ultrasonic_init(std::get<0>(port_tuple), std::get<1>(port_tuple), std::get<2>(port_tuple));\n\tget_ports(_port, _smart_port, _adi_port);\n}\n\nstd::int32_t Ultrasonic::get_value() const {\n\treturn ext_adi_ultrasonic_get(merge_adi_ports(_smart_port, _adi_port));\n}\n\nGyro::Gyro(std::uint8_t adi_port, double multiplier) : Port(adi_port) {\n\tstd::int32_t _port = ext_adi_gyro_init(INTERNAL_ADI_PORT, adi_port, multiplier);\n\tget_ports(_port, _smart_port, _adi_port);\n}\n\nGyro::Gyro(ext_adi_port_pair_t port_pair, double multiplier) : ADIPort(std::get<1>(port_pair)) {\n\tstd::int32_t _port = ext_adi_gyro_init(port_pair.first, port_pair.second, multiplier);\n\tget_ports(_port, _smart_port, _adi_port);\n}\n\ndouble Gyro::get_value() const {\n\treturn ext_adi_gyro_get(merge_adi_ports(_smart_port, _adi_port));\n}\n\nstd::int32_t Gyro::reset() const {\n\treturn ext_adi_gyro_reset(merge_adi_ports(_smart_port, _adi_port));\n}\n\nPotentiometer::Potentiometer(std::uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type) : AnalogIn(adi_port) { \n\tstd::int32_t _port = ext_adi_potentiometer_init(INTERNAL_ADI_PORT, adi_port, potentiometer_type);\n\tget_ports(_port, _smart_port, _adi_port);\n}\n\nPotentiometer::Potentiometer(ext_adi_port_pair_t port_pair, adi_potentiometer_type_e_t potentiometer_type) : AnalogIn(std::get<1>(port_pair)) { \n \tstd::int32_t _port = ext_adi_potentiometer_init(port_pair.first, port_pair.second, potentiometer_type);\n\tget_ports(_port, _smart_port, _adi_port);\n}\n\ndouble Potentiometer::get_angle() const {\n\tuint8_t temp_smart = _smart_port - 1;\n\treturn ext_adi_potentiometer_get_angle(merge_adi_ports(temp_smart, _adi_port));\n}\n\nLed::Led(std::uint8_t adi_port, std::uint32_t length) : Port(adi_port) {\n\tstd::int32_t _port = ext_adi_led_init(INTERNAL_ADI_PORT, adi_port);\n\tget_ports(_port, _smart_port, _adi_port);\n\tif (length < 1) {\n\t\tlength = 0;\n\t}\n\tif (length > MAX_LED) {\n\t\tlength = MAX_LED;\n\t}\n\t_buffer.resize(length, 0);\n}\n\nLed::Led(ext_adi_port_pair_t port_pair, std::uint32_t length) : Port(std::get<1>(port_pair)) {\n\tstd::int32_t _port = ext_adi_led_init(port_pair.first, port_pair.second);\n\tget_ports(_port, _smart_port, _adi_port);\n\tif (length < 1) {\n\t\tlength = 0;\n\t}\n\tif (length > MAX_LED) {\n\t\tlength = MAX_LED;\n\t}\n\t_buffer.resize(length, 0);\n}\n\nuint32_t& Led::operator[] (size_t index) {\n\treturn _buffer[index];\n}\n\nstd::int32_t Led::update() const {\n\treturn ext_adi_led_set(merge_adi_ports(_smart_port, _adi_port), (uint32_t*)_buffer.data(), _buffer.size());\n}\n\nstd::int32_t Led::length() {\n\treturn _buffer.size();\n}\n\nstd::int32_t Led::set_all(uint32_t color) {\n\treturn ext_adi_led_set_all((adi_led_t)merge_adi_ports(_smart_port, _adi_port), (uint32_t*)_buffer.data(), _buffer.size(), color);\n}\n\nstd::int32_t Led::set_pixel(uint32_t color, uint32_t pixel_position) {\n\treturn ext_adi_led_set_pixel((adi_led_t)merge_adi_ports(_smart_port, _adi_port), (uint32_t*)_buffer.data(), _buffer.size(), color, pixel_position);\n}\n\nstd::int32_t Led::clear_all() {\n\treturn ext_adi_led_clear_all((adi_led_t)merge_adi_ports(_smart_port, _adi_port), (uint32_t*)_buffer.data(), _buffer.size());\n}\n\nstd::int32_t Led::clear() {\n\treturn ext_adi_led_clear_all((adi_led_t)merge_adi_ports(_smart_port, _adi_port), (uint32_t*)_buffer.data(), _buffer.size());\n}\n\nstd::int32_t Led::clear_pixel(uint32_t pixel_position) {\n\treturn ext_adi_led_clear_pixel((adi_led_t)merge_adi_ports(_smart_port, _adi_port), (uint32_t*)_buffer.data(), _buffer.size(), pixel_position);\n}\n\nPneumatics::Pneumatics(std::uint8_t adi_port, bool start_extended, bool extended_is_low)\n\t: DigitalOut(adi_port), state(start_extended ^ extended_is_low), extended_is_low(extended_is_low) {\n\tset_value(state);\n}\n\nPneumatics::Pneumatics(ext_adi_port_pair_t port_pair, bool start_extended, bool extended_is_low) \n\t: DigitalOut(port_pair), state(start_extended ^ extended_is_low), extended_is_low(extended_is_low) {\n\tset_value(state);\n}\n\nstd::int32_t Pneumatics::extend() {\n\tbool old_state = state;\n\n\tstate = !extended_is_low;\n\tif(set_value(state) == PROS_ERR) {\n\t\treturn PROS_ERR;\n\t}\n\n\treturn state != old_state;\n}\n\nstd::int32_t Pneumatics::retract() {\n\tbool old_state = state;\n\n\tstate = extended_is_low;\n\tif(set_value(state) == PROS_ERR) {\n\t\treturn PROS_ERR;\n\t}\n\n\treturn state != old_state;\n}\n\nstd::int32_t Pneumatics::toggle() {\n\tstate = !state;\n\treturn set_value(state);\n}\n\nbool Pneumatics::is_extended() const {\n\treturn state ^ extended_is_low;\n}\n\nstd::ostream& operator<<(std::ostream& os, pros::adi::Potentiometer& potentiometer) {\n\tos << \"Potentiometer [\";\n\tos << \"smart_port: \" << +potentiometer._smart_port;\n\tos << \", adi_port: \" << ((potentiometer._adi_port > 10) ? potentiometer._adi_port : +potentiometer._adi_port);\n\tos << \", value: \" << potentiometer.get_value();\n\tos << \", value calibrated: \" << potentiometer.get_value_calibrated();\n\tos << \", angle: \" << potentiometer.get_angle();\n\tos << \"]\";\n\n\treturn os;\n}\n}  // namespace adi\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/vdml_ai_vision.c",
    "content": "/**\n * \\file devices/vdml_aivision.c\n *\n * Contains functions for interacting with the V5 Vision Sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n#include \"pros/ai_vision.h\"\n#include \"v5_api.h\"\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\n#define AIVISION_COLOR_ERR_INIT                                                                                        \\\n\t{   .id = PROS_ERR_BYTE, .red = PROS_ERR_BYTE, .green = PROS_ERR_BYTE, .blue = PROS_ERR_BYTE,                      \\\n        .hue_range = PROS_ERR_F, .saturation_range = PROS_ERR_F                                                        \\\n\t}\n\n#define AIVISION_CODE_ERR_INIT                                                                                         \\\n\t{   .id = PROS_ERR_BYTE, .length = PROS_ERR_BYTE, .c1 = PROS_ERR_2_BYTE, .c2 = PROS_ERR_2_BYTE,                    \\\n\t\t.c3 = PROS_ERR_2_BYTE, .c4 = PROS_ERR_2_BYTE, .c5 = PROS_ERR_2_BYTE                                            \\\n\t}\n\n#define AIVISION_OBJECT_ERR_INIT \\\n\t{ .id = PROS_ERR_BYTE, .type = PROS_ERR_BYTE }\n\nint32_t aivision_reset(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tvexDeviceAiVisionReset(device->device_info);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t aivision_set_enabled_detection_types(uint8_t port, uint8_t bits, uint8_t bitmask) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tvexDeviceAiVisionEnableSet(device->device_info, bits, bitmask);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t aivision_get_enabled_detection_types(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tuint8_t enabled_detection_types = vexDeviceAiVisionEnableGet(device->device_info);\n\treturn_port(port - 1, enabled_detection_types);\n}\n\nint32_t aivision_enable_detection_types(uint8_t port, uint8_t types_mask) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tvexDeviceAiVisionEnableSet(device->device_info, types_mask, types_mask);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t aivision_disable_detection_types(uint8_t port, uint8_t types_mask) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tvexDeviceAiVisionEnableSet(device->device_info, 0, types_mask);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t aivision_get_class_name(uint8_t port, int32_t id, uint8_t* class_name) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tvexDeviceAiVisionClassNameGet(device->device_info, id, class_name);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t aivision_set_color(uint8_t port, const aivision_color_s_t* color) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tV5_DeviceAiVisionColor _color;\n\t_color.id = color->id;\n\t_color.red = color->red;\n\t_color.grn = color->green;\n\t_color.blu = color->blue;\n\t_color.hangle = color->hue_range;\n\t_color.hdsat = color->saturation_range;\n\tvexDeviceAiVisionColorSet(device->device_info, &_color);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\naivision_color_s_t aivision_get_color(uint8_t port, uint32_t id) {\n\taivision_color_s_t color = AIVISION_COLOR_ERR_INIT;\n\tif (!claim_port_try(port - 1, E_DEVICE_AIVISION)) {\n\t\treturn color;\n\t}\n\tV5_DeviceAiVisionColor _color;\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tvexDeviceAiVisionColorGet(device->device_info, id, &_color);\n\tcolor.id = _color.id;\n\tcolor.red = _color.red;\n\tcolor.green = _color.grn;\n\tcolor.blue = _color.blu;\n\tcolor.hue_range = _color.hangle;\n\tcolor.saturation_range = _color.hdsat;\n\treturn_port(port - 1, color);\n}\n\nint32_t aivision_get_object_count(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tint32_t result = vexDeviceAiVisionObjectCountGet(device->device_info);\n\treturn_port(port - 1, result);\n}\n\ndouble aivision_get_temperature(uint8_t port) {\n\tclaim_port_f(port - 1, E_DEVICE_AIVISION);\n\tdouble result = vexDeviceAiVisionTemperatureGet(device->device_info);\n\treturn_port(port - 1, result);\n}\n\nint32_t aivision_set_tag_family(uint8_t port, aivision_tag_family_e_t family) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tuint32_t tag_family_flag = vexDeviceAiVisionStatusGet(device->device_info);\n\ttag_family_flag &= !(0xff << 16);\n\ttag_family_flag |= (uint32_t)family << 16;\n\tvexDeviceAiVisionModeSet(device->device_info, tag_family_flag | AIVISION_MODE_TAG_SET_BIT);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t aivision_set_tag_family_override(uint8_t port, aivision_tag_family_e_t family) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tuint32_t tag_family_flag = (uint32_t)family << 16;\n\tvexDeviceAiVisionModeSet(device->device_info, tag_family_flag | AIVISION_MODE_TAG_SET_BIT);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t aivision_set_usb_bounding_box_overlay(uint8_t port, bool enabled) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tuint32_t mode = vexDeviceAiVisionStatusGet(device->device_info);\n\tif (enabled) {\n\t\tmode &= 0x7F;\n\t} else {\n\t\tmode = (mode != 0) | 0x80;\n\t}\n\tmode = (mode << 8) | (1 << 25);\n\n\tvexDeviceAiVisionModeSet(device->device_info, mode);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t aivision_start_awb(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tuint32_t mode = (1 << 18) | (1 << 27);\n\tvexDeviceAiVisionModeSet(device->device_info, mode);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\naivision_object_s_t aivision_get_object(uint8_t port, uint32_t object_index) {\n\taivision_object_s_t result = AIVISION_OBJECT_ERR_INIT;\n\n    if (!claim_port_try(port - 1, E_DEVICE_AIVISION)) {\n        return result;\n    }\n    v5_smart_device_s_t* device = registry_get_device(port - 1);\n    vexDeviceAiVisionObjectGet(device->device_info, object_index, (V5_DeviceAiVisionObject*)&result);\n    return_port(port - 1, result);\n}\n\naivision_code_s_t aivision_get_code(uint8_t port, uint32_t id) {\n\taivision_code_s_t code = AIVISION_CODE_ERR_INIT;\n\tif (!claim_port_try(port - 1, E_DEVICE_AIVISION)) {\n\t\treturn code;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tV5_DeviceAiVisionCode _code;\n\tvexDeviceAiVisionCodeGet(device->device_info, id, &_code);\n\tcode.id = _code.id;\n\tcode.length = _code.len;\n\tcode.c1 = _code.c1;\n\tcode.c2 = _code.c2;\n\tcode.c3 = _code.c3;\n\tcode.c4 = _code.c4;\n\tcode.c5 = _code.c5;\n\treturn_port(port - 1, code);\n}\n\nint32_t aivision_set_code(uint8_t port, const aivision_code_s_t* code) {\n\tclaim_port_i(port - 1, E_DEVICE_AIVISION);\n\tV5_DeviceAiVisionCode _code;\n\t_code.id = code->id;\n\t_code.len = code->length;\n\t_code.c1 = code->c1;\n\t_code.c2 = code->c2;\n\t_code.c3 = code->c3;\n\t_code.c4 = code->c4;\n\t_code.c5 = code->c5;\n\tvexDeviceAiVisionCodeSet(device->device_info, &_code);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n"
  },
  {
    "path": "src/devices/vdml_ai_vision.cpp",
    "content": "/**\n * \\file devices/vdml_vision.cpp\n *\n * Contains functions for interacting with the V5 Vision Sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"pros/ai_vision.hpp\"\n#include \"pros/device.h\"\n#include \"vdml/vdml.h\"\n\nnamespace pros {\ninline namespace v5 {\nusing namespace pros::c;\n\nAivisionModeType operator|(AivisionModeType lhs, AivisionModeType rhs) {\n\treturn static_cast<AivisionModeType>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));\n}\n\nAIVision::AIVision(const uint8_t port) : Device(port, DeviceType::aivision) {\n\t// empty constructor\n}\n\nstd::vector<AIVision> AIVision::get_all_devices() {\n\tstd::vector<Device> matching_devices{Device::get_all_devices(DeviceType::aivision)};\n\n\tstd::vector<AIVision> return_vector;\n\tfor (const auto& device : matching_devices) {\n\t\treturn_vector.push_back(device);\n\t}\n\treturn return_vector;\n}\n\nbool AIVision::is_type(const Object& object, AivisionDetectType type) {\n\treturn static_cast<uint8_t>(type) == object.type;\n}\n\nint32_t AIVision::reset() {\n\treturn c::aivision_reset(this->_port);\n}\n\nint32_t AIVision::get_enabled_detection_types() {\n\treturn c::aivision_get_enabled_detection_types(this->_port);\n}\n\nint32_t AIVision::enable_detection_types(AivisionModeType types_mask) {\n\treturn c::aivision_enable_detection_types(this->_port, static_cast<uint8_t>(types_mask));\n}\n\nint32_t AIVision::disable_detection_types(AivisionModeType types_mask) {\n\treturn c::aivision_disable_detection_types(this->_port, static_cast<uint8_t>(types_mask));\n}\n\nint32_t AIVision::set_tag_family(AivisionTagFamily family, bool override) {\n\tif (override) {\n\t\treturn c::aivision_set_tag_family_override(this->_port, static_cast<aivision_tag_family_e_t>(family));\n\t}\n\treturn c::aivision_set_tag_family(this->_port, static_cast<aivision_tag_family_e_t>(family));\n}\n\nint32_t AIVision::set_color(const pros::AIVision::Color& color) {\n\tauto _color = static_cast<aivision_color_s_t>(color);\n\treturn c::aivision_set_color(this->_port, &_color);\n}\n\nAIVision::Color AIVision::get_color(uint32_t id) {\n\treturn c::aivision_get_color(this->_port, id);\n}\n\nint32_t AIVision::get_object_count() {\n\treturn c::aivision_get_object_count(this->_port);\n}\n\nAIVision::Object AIVision::get_object(uint32_t object_index) {\n\treturn c::aivision_get_object(this->_port, object_index);\n}\n\nint32_t AIVision::get_class_name(int32_t id, char* class_name) {\n\treturn c::aivision_get_class_name(this->_port, id, (uint8_t*)class_name);\n}\n\nstd::optional<std::string> AIVision::get_class_name(int32_t id) {\n\tchar class_name[21];\n\tuint32_t result = c::aivision_get_class_name(this->_port, id, (uint8_t*)class_name);\n\tif (result == PROS_SUCCESS) {\n\t\treturn std::string(class_name);\n\t}\n\treturn std::nullopt;\n}\n\nint32_t AIVision::start_awb() {\n\treturn c::aivision_start_awb(this->_port);\n}\n\nAIVision::Code AIVision::get_code(uint32_t id) {\n\treturn c::aivision_get_code(this->_port, id);\n}\n\nuint32_t AIVision::set_code(const pros::AIVision::Code& code) {\n\tauto _code = static_cast<aivision_code_s_t>(code);\n\treturn c::aivision_set_code(this->_port, &_code);\n}\n\nstd::vector<AIVision::Object> AIVision::get_all_objects() {\n\tint32_t count = this->get_object_count();\n\tif (count < 0 || count == PROS_ERR) {\n\t\treturn {};\n\t}\n\tstd::vector<AIVision::Object> objects = std::vector<AIVision::Object>();\n\tobjects.reserve(count);\n\tfor (int idx = 0; idx < count; idx++) {\n\t\tobjects.emplace_back(this->get_object(idx));\n\t}\n\treturn objects;\n}\n\n}  // namespace v5\n}  // namespace pros"
  },
  {
    "path": "src/devices/vdml_device.c",
    "content": "/**\n * \\file devices/vdml_device.c\n *\n * Contains functions for interacting with VEX devices.\n *\n *\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"pros/device.h\"\n#include \"vdml/vdml.h\"\n\nv5_device_e_t get_plugged_type(uint8_t port) {\n    if (!port_mutex_take(port - 1)) {                            \n\t\terrno = EACCES; \n\t\treturn E_DEVICE_UNDEFINED;                                                                           \n\t}\n\tv5_device_e_t type = registry_get_plugged_type(port - 1);\n\t\n\treturn_port(port - 1, type);\n}\n"
  },
  {
    "path": "src/devices/vdml_device.cpp",
    "content": "/**\n * \\file devices/vdml_device.cpp\n *\n * Base class for all smart devices.\n *\n *\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"pros/device.hpp\"\n#include \"vdml/vdml.h\"\n\nnamespace pros {\ninline namespace v5 {\n\nbool Device::is_installed() {\n    std::uint8_t zero_indexed_port = _port - 1;\n    port_mutex_take(zero_indexed_port);\n    pros::DeviceType plugged_device_type = (pros::DeviceType)pros::c::registry_get_plugged_type(zero_indexed_port);\n\treturn_port(zero_indexed_port, _deviceType == plugged_device_type);\n}\n\nstd::uint8_t Device::get_port(void) const {\n\treturn _port;\n}\n\npros::DeviceType Device::get_plugged_type() const {\n\treturn(get_plugged_type(_port));\n}\n\npros::DeviceType Device::get_plugged_type(std::uint8_t port) {\n\tif (!port_mutex_take(port - 1)) {                            \n\t\terrno = EACCES; \n\t\treturn DeviceType::undefined;                                                                           \n\t}\n\tDeviceType type = (DeviceType) pros::c::registry_get_plugged_type(port - 1);\n\t\n\treturn_port(port - 1, type);\n}\n\nstd::vector<Device> Device::get_all_devices(pros::DeviceType device_type) {\n\tstd::vector<Device> device_list {};\n\n\tfor (std::uint8_t curr_port = 0; curr_port < 21; ++curr_port) {\n\t\tif (!port_mutex_take(curr_port)) {                            \n\t\t\terrno = EACCES;\n\t\t\tcontinue;\n\t\t}\n\n\t\tpros::DeviceType type = (DeviceType) pros::c::registry_get_plugged_type(curr_port);\n\t\tif (device_type == type) {;\n\t\t\tdevice_list.push_back(Device {static_cast<std::uint8_t>(curr_port + 1)});\n\t\t}\n\t\tport_mutex_give(curr_port);\n\t}\n\treturn device_list;\n}\n\nDevice::Device(const std::uint8_t port) : _port(port) {}\n\n\n}  // namespace v5\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/vdml_distance.c",
    "content": "/**\n * \\file devices/vdml_distance.c\n *\n * Contains functions for interacting with the VEX Distance sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n\n#include \"pros/distance.h\"\n#include \"v5_api.h\"\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\n#define ERROR_DISTANCE_BAD_PORT(device, err_return)                 \\\n\tif (!(vexDeviceDistanceStatusGet(device->device_info) == 0x82 ||  \\\n\t      vexDeviceDistanceStatusGet(device->device_info) == 0x86)) { \\\n\t\terrno = EAGAIN;                                                 \\\n\t\treturn_port(port - 1, err_return);                              \\\n\t}\n\nint32_t distance_get(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_DISTANCE);\n\tERROR_DISTANCE_BAD_PORT(device, PROS_ERR);\n\tint32_t rtn = vexDeviceDistanceDistanceGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t distance_get_confidence(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_DISTANCE);\n\tERROR_DISTANCE_BAD_PORT(device, PROS_ERR);\n\tint32_t rtn = vexDeviceDistanceConfidenceGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t distance_get_object_size(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_DISTANCE);\n\tERROR_DISTANCE_BAD_PORT(device, PROS_ERR);\n\tint32_t rtn = vexDeviceDistanceObjectSizeGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\ndouble distance_get_object_velocity(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_DISTANCE);\n\tERROR_DISTANCE_BAD_PORT(device, PROS_ERR);\n\tdouble rtn = vexDeviceDistanceObjectVelocityGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n"
  },
  {
    "path": "src/devices/vdml_distance.cpp",
    "content": "/**\n * \\file devices/vdml_distance.cpp\n *\n * Contains functions for interacting with the VEX Distance sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"pros/distance.hpp\"\n#include \"vdml/vdml.h\"\n\nnamespace pros {\ninline namespace v5 {\n\nDistance::Distance(const std::uint8_t port) : Device(port, DeviceType::distance) {}\n\nstd::int32_t Distance::get() {\n\treturn pros::c::distance_get(_port);\n}\n\nstd::int32_t Distance::get_distance() {\n\treturn get();\n}\n\nstd::vector<Distance> Distance::get_all_devices() {\n\tstd::vector<Device> matching_devices {Device::get_all_devices(DeviceType::distance)};\n\tstd::vector<Distance> return_vector;\n\tfor (auto device : matching_devices) {\n\t\treturn_vector.push_back(device);\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t Distance::get_confidence() {\n\treturn pros::c::distance_get_confidence(_port);\n}\n\nstd::int32_t Distance::get_object_size() {\n\treturn pros::c::distance_get_object_size(_port);\n}\n\ndouble Distance::get_object_velocity() {\n\treturn pros::c::distance_get_object_velocity(_port);\n}\n\n\nstd::ostream& operator<<(std::ostream& os, pros::Distance& distance) {\n\tos << \"Distance [\";\n\tos << \"port: \" << distance.get_port();\n\tos << \", distance: \" << distance.get();\n\tos << \", confidence: \" << distance.get_confidence();\n\tos << \", object size: \" << distance.get_object_size();\n\tos << \", object velocity: \" << distance.get_object_velocity();\n\tos << \"]\";\n\treturn os;\n}\n\nnamespace literals {\nconst pros::Distance operator\"\"_dist(const unsigned long long int d) {\n    return pros::Distance(d);\n}\n} // namespace literals\n} // namespace v5\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/vdml_ext_adi.c",
    "content": "/**\n * \\file devices/vdml_ext_adi.c\n *\n * Contains functions for interacting with the V5 3-Wire Expander.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n#include <math.h>\n#include <stdio.h>\n\n#include \"kapi.h\"\n#include \"pros/adi.h\"\n#include \"pros/ext_adi.h\"\n#include \"v5_api.h\"\n#include \"vdml/port.h\"\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\n#define ADI_MOTOR_MAX_SPEED 127\n#define ADI_MOTOR_MIN_SPEED -128\n#define NUM_MAX_TWOWIRE 4\n#define MAX_LED 64\n\n// Theoretical calibration time is 1024ms, but in practice this seemed to be the\n// actual time that it takes.\n#define GYRO_CALIBRATION_TIME 1300\n\ntypedef union adi_data {\n\tstruct {\n\t\tint32_t calib;\n\t} analog_data;\n\tstruct {\n\t\tbool was_pressed;\n\t} digital_data;\n\tstruct {\n\t\tbool reversed;\n\t} encoder_data;\n\tstruct {\n\t\tadi_potentiometer_type_e_t potentiometer_type;\n\t} potentiometer_data;\n\tstruct __attribute__((packed)) {\n\t\tdouble multiplier;\n\t\tdouble tare_value;\n\t} gyro_data;\n} adi_data_s_t;\n\n// These 2 functions aren't in v5_api.h but should be... so we're going to directly expose them with an extern \"C\".\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n// private addressable LED API\nint32_t vexDeviceAdiAddrLedSet(V5_DeviceT device, uint32_t port, uint32_t* pData, uint32_t nOffset, uint32_t nLength,\n                               uint32_t options);\nint32_t vexAdiAddrLedSet(uint32_t index, uint32_t port, uint32_t* pData, uint32_t nOffset, uint32_t nLength,\n                         uint32_t options);\n#ifdef __cplusplus\n}\n#endif\n\n#define transform_adi_port(port)       \\\n\tif (port >= 'a' && port <= 'h')      \\\n\t\tport -= 'a';                       \\\n\telse if (port >= 'A' && port <= 'H') \\\n\t\tport -= 'A';                       \\\n\telse                                 \\\n\t\tport--;                            \\\n\tif (port > 7 || port < 0) {          \\\n\t\terrno = ENXIO;                     \\\n\t\treturn PROS_ERR;                   \\\n\t}\n\n#define validate_type(device, adi_port, smart_port, type)                                                     \\\n\tadi_port_config_e_t config = (adi_port_config_e_t)vexDeviceAdiPortConfigGet(device->device_info, adi_port); \\\n\tif (config != type) {                                                                                       \\\n\t\terrno = EADDRINUSE;                                                                                       \\\n\t\tprintf(\"Error: validate_type\\n\");                                                                         \\\n\t\treturn_port(smart_port, PROS_ERR);                                                                        \\\n\t}\n\n#define validate_type_f(device, adi_port, smart_port, type)                                                   \\\n\tadi_port_config_e_t config = (adi_port_config_e_t)vexDeviceAdiPortConfigGet(device->device_info, adi_port); \\\n\tif (config != type) {                                                                                       \\\n\t\terrno = EADDRINUSE;                                                                                       \\\n\t\treturn_port(smart_port, PROS_ERR_F);                                                                      \\\n\t}\n\n#define validate_motor(device, adi_port, smart_port)                                                          \\\n\tadi_port_config_e_t config = (adi_port_config_e_t)vexDeviceAdiPortConfigGet(device->device_info, adi_port); \\\n\tif (config != E_ADI_LEGACY_PWM && config != E_ADI_LEGACY_SERVO) {                                           \\\n\t\terrno = EADDRINUSE;                                                                                       \\\n\t\treturn_port(smart_port, PROS_ERR);                                                                        \\\n\t}\n\n/*\n * Validates 3 things:\n * - Ports next to each other\n * - Both ports are initialized and valid (individually)\n *\n * Returns PROS_ERR if one of these is false.\n */\n#define validate_twowire(port_top, port_bottom) \\\n\tif (abs(port_top - port_bottom) > 1) {        \\\n\t\terrno = ENXIO;                              \\\n\t\treturn PROS_ERR;                            \\\n\t}                                             \\\n\tint port;                                     \\\n\tif (port_top < port_bottom)                   \\\n\t\tport = port_top;                            \\\n\telse if (port_bottom < port_top)              \\\n\t\tport = port_bottom;                         \\\n\telse {                                        \\\n\t\terrno = EINVAL;                             \\\n\t\treturn PROS_ERR;                            \\\n\t}                                             \\\n\tif (port % 2 == 1) {                          \\\n\t\terrno = EINVAL;                             \\\n\t\treturn PROS_ERR;                            \\\n\t}\n\nadi_port_config_e_t ext_adi_port_get_config(uint8_t smart_port, uint8_t adi_port) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tadi_port_config_e_t rtn = (adi_port_config_e_t)vexDeviceAdiPortConfigGet(device->device_info, adi_port);\n\treturn_port(smart_port - 1, rtn);\n}\n\nint32_t ext_adi_port_get_value(uint8_t smart_port, uint8_t adi_port) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tint32_t rtn = vexDeviceAdiValueGet(device->device_info, adi_port);\n\treturn_port(smart_port - 1, rtn);\n}\n\nint32_t ext_adi_port_set_config(uint8_t smart_port, uint8_t adi_port, adi_port_config_e_t type) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvexDeviceAdiPortConfigSet(device->device_info, adi_port, (V5_AdiPortConfiguration)type);\n\treturn_port(smart_port - 1, 1);\n}\n\nint32_t ext_adi_port_set_value(uint8_t smart_port, uint8_t adi_port, int32_t value) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvexDeviceAdiValueSet(device->device_info, adi_port, value);\n\treturn_port(smart_port - 1, 1);\n}\n\nint32_t ext_adi_analog_calibrate(uint8_t smart_port, uint8_t adi_port) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_ANALOG_IN);\n\tuint32_t total = 0;\n\tfor (uint32_t i = 0; i < 512; i++) {\n\t\ttotal += vexDeviceAdiValueGet(device->device_info, adi_port);\n\t\ttask_delay(1);  // TODO: If smart ports (and the ADI) only update every 10ms, this really only reads 56 samples,\n\t\t                // maybe change to a 10ms\n\t}\n\tadi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port];\n\tadi_data->analog_data.calib = (int32_t)((total + 16) >> 5);\n\treturn_port(smart_port - 1, (int32_t)((total + 256) >> 9));\n}\n\nint32_t ext_adi_analog_read(uint8_t smart_port, uint8_t adi_port) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_ANALOG_IN);\n\tint32_t rtn = vexDeviceAdiValueGet(device->device_info, adi_port);\n\treturn_port(smart_port - 1, rtn);\n}\n\nint32_t ext_adi_analog_read_calibrated(uint8_t smart_port, uint8_t adi_port) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_ANALOG_IN);\n\tadi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port];\n\tint32_t rtn = vexDeviceAdiValueGet(device->device_info, adi_port) - (adi_data->analog_data.calib >> 4);\n\treturn_port(smart_port - 1, rtn);\n}\n\nint32_t ext_adi_analog_read_calibrated_HR(uint8_t smart_port, uint8_t adi_port) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_ANALOG_IN);\n\tadi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port];\n\tint32_t rtn = (vexDeviceAdiValueGet(device->device_info, adi_port) << 4) - adi_data->analog_data.calib;\n\treturn_port(smart_port - 1, rtn);\n}\n\nint32_t ext_adi_digital_read(uint8_t smart_port, uint8_t adi_port) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_DIGITAL_IN);\n\tint32_t rtn = vexDeviceAdiValueGet(device->device_info, adi_port);\n\treturn_port(smart_port - 1, rtn);\n}\n\nint32_t ext_adi_digital_get_new_press(uint8_t smart_port, uint8_t adi_port) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_DIGITAL_IN);\n\n\tadi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port];\n\n\tint32_t pressed = vexDeviceAdiValueGet(device->device_info, adi_port);\n\n\tif (!pressed)\n\t\tadi_data->digital_data.was_pressed = false;\n\telse if (!adi_data->digital_data.was_pressed) {\n\t\t// Button is currently pressed and was not detected as being pressed during last check\n\t\tadi_data->digital_data.was_pressed = true;\n\t\treturn_port(smart_port - 1, true);\n\t}\n\n\treturn_port(smart_port - 1, false);\n}\n\nint32_t ext_adi_digital_write(uint8_t smart_port, uint8_t adi_port, bool value) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_DIGITAL_OUT);\n\tvexDeviceAdiValueSet(device->device_info, adi_port, (int32_t)value);\n\treturn_port(smart_port - 1, 1);\n}\n\nint32_t ext_adi_pin_mode(uint8_t smart_port, uint8_t adi_port, uint8_t mode) {\n\tswitch (mode) {\n\t\tcase INPUT:\n\t\t\text_adi_port_set_config(smart_port, adi_port, E_ADI_DIGITAL_IN);\n\t\t\tbreak;\n\t\tcase OUTPUT:\n\t\t\text_adi_port_set_config(smart_port, adi_port, E_ADI_DIGITAL_OUT);\n\t\t\tbreak;\n\t\tcase INPUT_ANALOG:\n\t\t\text_adi_port_set_config(smart_port, adi_port, E_ADI_ANALOG_IN);\n\t\t\tbreak;\n\t\tcase OUTPUT_ANALOG:\n\t\t\text_adi_port_set_config(smart_port, adi_port, E_ADI_ANALOG_OUT);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\terrno = EINVAL;\n\t\t\treturn PROS_ERR;\n\t};\n\treturn 1;\n}\n\nint32_t ext_adi_motor_set(uint8_t smart_port, uint8_t adi_port, int8_t speed) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_motor(device, adi_port, smart_port - 1);\n\tif (speed > ADI_MOTOR_MAX_SPEED)\n\t\tspeed = ADI_MOTOR_MAX_SPEED;\n\telse if (speed < ADI_MOTOR_MIN_SPEED)\n\t\tspeed = ADI_MOTOR_MIN_SPEED;\n\tvexDeviceAdiValueSet(device->device_info, adi_port, speed);\n\treturn_port(smart_port - 1, 1);\n}\n\nint32_t ext_adi_motor_get(uint8_t smart_port, uint8_t adi_port) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_motor(device, adi_port, smart_port - 1);\n\tint32_t rtn = vexDeviceAdiValueGet(device->device_info, adi_port) - ADI_MOTOR_MAX_SPEED;\n\treturn_port(smart_port - 1, rtn);\n}\n\nint32_t ext_adi_motor_stop(uint8_t smart_port, uint8_t adi_port) {\n\treturn ext_adi_motor_set(smart_port, adi_port, 0);\n}\n\next_adi_encoder_t ext_adi_encoder_init(uint8_t smart_port, uint8_t adi_port_top, uint8_t adi_port_bottom,\n                                       bool reverse) {\n\ttransform_adi_port(adi_port_top);\n\ttransform_adi_port(adi_port_bottom);\n\tvalidate_twowire(adi_port_top, adi_port_bottom);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\n\tadi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[port];\n\tadi_data->encoder_data.reversed = reverse;\n\tvexDeviceAdiPortConfigSet(device->device_info, port, E_ADI_LEGACY_ENCODER);\n\treturn_port(smart_port - 1, merge_adi_ports(smart_port, port + 1));\n}\n\nint32_t ext_adi_encoder_get(ext_adi_encoder_t enc) {\n\tuint8_t smart_port, adi_port;\n\tget_ports(enc, smart_port, adi_port);\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_ENCODER);\n\n\tint32_t rtn;\n\tadi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port];\n\tif (adi_data->encoder_data.reversed)\n\t\trtn = -vexDeviceAdiValueGet(device->device_info, adi_port);\n\telse\n\t\trtn = vexDeviceAdiValueGet(device->device_info, adi_port);\n\treturn_port(smart_port - 1, rtn);\n}\n\nint32_t ext_adi_encoder_reset(ext_adi_encoder_t enc) {\n\tuint8_t smart_port, adi_port;\n\tget_ports(enc, smart_port, adi_port);\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_ENCODER);\n\n\tvexDeviceAdiValueSet(device->device_info, adi_port, 0);\n\treturn_port(smart_port - 1, 1);\n}\n\nint32_t ext_adi_encoder_shutdown(ext_adi_encoder_t enc) {\n\tuint8_t smart_port, adi_port;\n\tget_ports(enc, smart_port, adi_port);\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_ENCODER);\n\n\tvexDeviceAdiPortConfigSet(device->device_info, adi_port, E_ADI_TYPE_UNDEFINED);\n\treturn_port(smart_port - 1, 1);\n}\n\next_adi_ultrasonic_t ext_adi_ultrasonic_init(uint8_t smart_port, uint8_t adi_port_ping, uint8_t adi_port_echo) {\n\ttransform_adi_port(adi_port_ping);\n\ttransform_adi_port(adi_port_echo);\n\tvalidate_twowire(adi_port_ping, adi_port_echo);\n\tif (port != adi_port_ping) {\n\t\terrno = EINVAL;\n\t\treturn PROS_ERR;\n\t}\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvexDeviceAdiPortConfigSet(device->device_info, port, E_ADI_LEGACY_ULTRASONIC);\n\treturn_port(smart_port - 1, merge_adi_ports(smart_port, port + 1));\n}\n\nint32_t ext_adi_ultrasonic_get(ext_adi_ultrasonic_t ult) {\n\tuint8_t smart_port, adi_port;\n\tget_ports(ult, smart_port, adi_port);\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_ULTRASONIC);\n\n\tint32_t rtn = vexDeviceAdiValueGet(device->device_info, adi_port);\n\treturn_port(smart_port - 1, rtn);\n}\n\nint32_t ext_adi_ultrasonic_shutdown(ext_adi_ultrasonic_t ult) {\n\tuint8_t smart_port, adi_port;\n\tget_ports(ult, smart_port, adi_port);\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_ULTRASONIC);\n\n\tvexDeviceAdiPortConfigSet(device->device_info, adi_port, E_ADI_TYPE_UNDEFINED);\n\treturn_port(smart_port - 1, 1);\n}\n\next_adi_gyro_t ext_adi_gyro_init(uint8_t smart_port, uint8_t adi_port, double multiplier) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\n\tif (multiplier == 0) multiplier = 1;\n\tadi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port];\n\tadi_data->gyro_data.multiplier = multiplier;\n\tadi_data->gyro_data.tare_value = 0;\n\n\tadi_port_config_e_t config = vexDeviceAdiPortConfigGet(device->device_info, adi_port);\n\tif (config == E_ADI_LEGACY_GYRO) {\n\t\t// Port has already been calibrated, no need to do that again\n\t\treturn_port(smart_port - 1, merge_adi_ports(smart_port, adi_port + 1));\n\t}\n\n\tvexDeviceAdiPortConfigSet(device->device_info, adi_port, E_ADI_LEGACY_GYRO);\n\tif (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {\n\t\t// If the scheduler is currently running (meaning that this is not called\n\t\t// from a global constructor, for example) then delay for the duration of\n\t\t// the calibration time in VexOS.\n\t\tdelay(GYRO_CALIBRATION_TIME);\n\t}\n\treturn_port(smart_port - 1, merge_adi_ports(smart_port, adi_port + 1));\n}\n\ndouble ext_adi_gyro_get(ext_adi_gyro_t gyro) {\n\tuint8_t smart_port, adi_port;\n\tget_ports(gyro, smart_port, adi_port);\n\ttransform_adi_port(adi_port);\n\tclaim_port_f(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type_f(device, adi_port, smart_port - 1, E_ADI_LEGACY_GYRO);\n\n\tdouble rtv = (double)vexDeviceAdiValueGet(device->device_info, adi_port);\n\tadi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port];\n\trtv -= adi_data->gyro_data.tare_value;\n\trtv *= adi_data->gyro_data.multiplier;\n\treturn_port(smart_port - 1, rtv);\n}\n\nint32_t ext_adi_gyro_reset(ext_adi_gyro_t gyro) {\n\tuint8_t smart_port, adi_port;\n\tget_ports(gyro, smart_port, adi_port);\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_GYRO);\n\n\tadi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port];\n\tadi_data->gyro_data.tare_value = vexDeviceAdiValueGet(device->device_info, adi_port);\n\treturn_port(smart_port - 1, 1);\n}\n\nint32_t ext_adi_gyro_shutdown(ext_adi_gyro_t gyro) {\n\tuint8_t smart_port, adi_port;\n\tget_ports(gyro, smart_port, adi_port);\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_LEGACY_GYRO);\n\n\tvexDeviceAdiPortConfigSet(device->device_info, adi_port, E_ADI_TYPE_UNDEFINED);\n\treturn_port(smart_port - 1, 1);\n}\n\next_adi_potentiometer_t ext_adi_potentiometer_init(uint8_t smart_port, uint8_t adi_port,\n                                                   adi_potentiometer_type_e_t potentiometer_type) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tadi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port];\n\tadi_data->potentiometer_data.potentiometer_type = potentiometer_type;\n\tvexDeviceAdiPortConfigSet(device->device_info, adi_port, E_ADI_ANALOG_IN);\n\treturn_port(smart_port - 1, merge_adi_ports(smart_port, adi_port + 1));\n}\n\ndouble ext_adi_potentiometer_get_angle(ext_adi_potentiometer_t potentiometer) {\n\tdouble rtn;\n\tuint8_t smart_port, adi_port;\n\tget_ports(potentiometer, smart_port, adi_port);\n\ttransform_adi_port(adi_port);\n\tclaim_port_f(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_ANALOG_IN);\n\n\tadi_data_s_t* const adi_data = &((adi_data_s_t*)(device->pad))[adi_port];\n\n\tswitch (adi_data->potentiometer_data.potentiometer_type) {\n\t\tcase E_ADI_POT_EDR:\n\t\t\trtn = vexDeviceAdiValueGet(device->device_info, adi_port) * 250 / 4095.0;\n\t\t\tbreak;\n\t\tcase E_ADI_POT_V2:\n\t\t\trtn = vexDeviceAdiValueGet(device->device_info, adi_port) * 330 / 4095.0;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\terrno = ENXIO;\n\t\t\trtn = PROS_ERR_F;\n\t}\n\treturn_port(smart_port - 1, rtn);\n}\n\next_adi_led_t ext_adi_led_init(uint8_t smart_port, uint8_t adi_port) {\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvexDeviceAdiPortConfigSet(device->device_info, adi_port, (V5_AdiPortConfiguration)E_ADI_DIGITAL_OUT);\n\treturn_port(smart_port - 1, merge_adi_ports(smart_port, adi_port + 1));\n}\n\nint32_t ext_adi_led_set(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length) {\n\tuint8_t smart_port, adi_port;\n\tget_ports(led, smart_port, adi_port);\n\ttransform_adi_port(adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_DIGITAL_OUT);\n\tif (buffer_length > MAX_LED) {\n\t\tbuffer_length = MAX_LED;\n\t} else if (buffer == NULL || buffer_length < 1) {\n\t\terrno = EINVAL;\n\t\treturn_port(smart_port - 1, PROS_ERR);\n\t}\n\tuint32_t rtv = (uint32_t)vexDeviceAdiAddrLedSet(device->device_info, adi_port, buffer, 0, buffer_length, 0);\n\treturn_port(smart_port - 1, rtv);\n}\n\nint32_t ext_adi_led_set_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color,\n                              uint32_t pixel_position) {\n\tuint8_t smart_port, adi_port;\n\tget_ports(led, smart_port, adi_port);\n\tclaim_port_i(smart_port - 1, E_DEVICE_ADI);\n\ttransform_adi_port(adi_port);\n\tvalidate_type(device, adi_port, smart_port - 1, E_ADI_DIGITAL_OUT);\n\tif (buffer == NULL || pixel_position < 0 || buffer_length >= MAX_LED || buffer_length < 1 ||\n\t    pixel_position > buffer_length - 1) {\n\t\terrno = EINVAL;\n\t\treturn_port(smart_port - 1, PROS_ERR);\n\t}\n\tbuffer[pixel_position] = color;\n\tuint32_t rtv = (uint32_t)vexDeviceAdiAddrLedSet(device->device_info, adi_port, buffer, 0, buffer_length, 0);\n\treturn_port(smart_port - 1, rtv);\n}\n\nint32_t ext_adi_led_set_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color) {\n\tfor (int i = 0; i < buffer_length; i++) {\n\t\tbuffer[i] = color;\n\t}\n\treturn ext_adi_led_set(led, buffer, buffer_length);\n}\n\nint32_t ext_adi_led_clear_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length) {\n\treturn ext_adi_led_set_all(led, buffer, buffer_length, 0);\n}\n\nint32_t ext_adi_led_clear_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t pixel_position) {\n\treturn ext_adi_led_set_pixel(led, buffer, buffer_length, 0, pixel_position);\n}\n"
  },
  {
    "path": "src/devices/vdml_gps.c",
    "content": "/**\n * \\file devices/vdml_gps.c\n *\n * Contains functions for interacting with the VEX GPS.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n\n#include \"pros/gps.h\"\n#include \"v5_api.h\"\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\n#define GPS_MINIMUM_DATA_RATE 5\n\n#define GPS_STATUS_ERR_INIT \\\n\t{ .x = PROS_ERR_F, .y = PROS_ERR_F, .roll = PROS_ERR_F, .pitch = PROS_ERR_F, .yaw = PROS_ERR_F }\n\n#define GPS_RAW_ERR_INIT \\\n\t{ .x = PROS_ERR_F, .y = PROS_ERR_F, .z = PROS_ERR_F }\n\nint32_t gps_initialize_full(uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset,\n                            double yOffset) {\n\tclaim_port_i(port - 1, E_DEVICE_GPS);\n\tvexDeviceGpsOriginSet(device->device_info, xOffset, yOffset);\n\tvexDeviceGpsInitialPositionSet(device->device_info, xInitial, yInitial, headingInitial);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t gps_set_offset(uint8_t port, double xOffset, double yOffset) {\n\tclaim_port_i(port - 1, E_DEVICE_GPS);\n\tvexDeviceGpsOriginSet(device->device_info, xOffset, yOffset);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\ngps_position_s_t gps_get_offset(uint8_t port) {\n\tgps_position_s_t rtv = {PROS_ERR_F, PROS_ERR_F};\n\tif (!claim_port_try(port - 1, E_DEVICE_GPS)) {\n\t\treturn rtv;\n\t}\n\t// This is necessary for warning suppression as a packed struct's address\n\t// may be misaligned. \n\tdouble x = PROS_ERR_F;\n\tdouble y = PROS_ERR_F;\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tvexDeviceGpsOriginGet(device->device_info, &x, &y);\n\trtv.x = x;\n\trtv.y = y;\n\treturn_port(port - 1, rtv);\n}\n\nint32_t gps_set_position(uint8_t port, double xInitial, double yInitial, double headingInitial) {\n\tclaim_port_i(port - 1, E_DEVICE_GPS);\n\tvexDeviceGpsInitialPositionSet(device->device_info, xInitial, yInitial, headingInitial);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t gps_set_data_rate(uint8_t port, uint32_t rate) {\n\tclaim_port_i(port - 1, E_DEVICE_GPS);\n\n\t// rate is not less than 5ms, and rounded down to nearest increment of 5\n\tif (rate < GPS_MINIMUM_DATA_RATE) {\n\t\trate = GPS_MINIMUM_DATA_RATE;\n\t} else {\n\t\trate -= rate % GPS_MINIMUM_DATA_RATE;\n\t}\n\n\tvexDeviceGpsDataRateSet(device->device_info, rate);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\ndouble gps_get_error(uint8_t port) {\n\tclaim_port_f(port - 1, E_DEVICE_GPS);\n\tdouble rtv = vexDeviceGpsErrorGet(device->device_info);\n\treturn_port(port - 1, rtv);\n}\n\ngps_status_s_t gps_get_position_and_orientation(uint8_t port) {\n\tgps_status_s_t rtv = GPS_STATUS_ERR_INIT;\n\tif (!claim_port_try(port - 1, E_DEVICE_GPS)) {\n\t\treturn rtv;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tV5_DeviceGpsAttitude data;\n\tvexDeviceGpsAttitudeGet(device->device_info, &data, false);\n\trtv.x = data.position_x;\n\trtv.y = data.position_y;\n\trtv.pitch = data.pitch;\n\trtv.roll = data.roll;\n\trtv.yaw = data.yaw;\n\treturn_port(port - 1, rtv);\n}\n\ngps_position_s_t gps_get_position(uint8_t port) {\n\tgps_position_s_t rtv = {PROS_ERR_F, PROS_ERR_F};\n\tif (!claim_port_try(port - 1, E_DEVICE_GPS)) {\n\t\treturn rtv;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tV5_DeviceGpsAttitude data;\n\tvexDeviceGpsAttitudeGet(device->device_info, &data, false);\n\trtv.x = data.position_x;\n\trtv.y = data.position_y;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_position_x(uint8_t port) {\n    claim_port_f(port - 1, E_DEVICE_GPS);\n\tV5_DeviceGpsAttitude data;\n\tvexDeviceGpsAttitudeGet(device->device_info, &data, false);\n\tdouble rtv = data.position_x;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_position_y(uint8_t port) {\n    claim_port_f(port - 1, E_DEVICE_GPS);\n\tV5_DeviceGpsAttitude data;\n\tvexDeviceGpsAttitudeGet(device->device_info, &data, false);\n\tdouble rtv = data.position_y;\n\treturn_port(port - 1, rtv);\n}\n\ngps_orientation_s_t gps_get_orientation(uint8_t port) {\n    gps_orientation_s_t rtv = {PROS_ERR_F, PROS_ERR_F, PROS_ERR_F};\n\tif (!claim_port_try(port - 1, E_DEVICE_GPS)) {\n\t\treturn rtv;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tV5_DeviceGpsAttitude data;\n\tvexDeviceGpsAttitudeGet(device->device_info, &data, false);\n\trtv.pitch = data.pitch;\n\trtv.roll = data.roll;\n\trtv.yaw = data.yaw;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_pitch(uint8_t port) {\n    claim_port_f(port - 1, E_DEVICE_GPS);\n\tV5_DeviceGpsAttitude data;\n\tvexDeviceGpsAttitudeGet(device->device_info, &data, false);\n\tdouble rtv = data.pitch;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_roll(uint8_t port) {\n    claim_port_f(port - 1, E_DEVICE_GPS);\n\tV5_DeviceGpsAttitude data;\n\tvexDeviceGpsAttitudeGet(device->device_info, &data, false);\n\tdouble rtv = data.roll;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_yaw(uint8_t port) {\n    claim_port_f(port - 1, E_DEVICE_GPS);\n\tV5_DeviceGpsAttitude data;\n\tvexDeviceGpsAttitudeGet(device->device_info, &data, false);\n\tdouble rtv = data.yaw;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_heading(uint8_t port) {\n\tclaim_port_f(port - 1, E_DEVICE_GPS);\n\tdouble rtv = vexDeviceGpsDegreesGet(device->device_info);\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_heading_raw(uint8_t port) {\n\tclaim_port_f(port - 1, E_DEVICE_GPS);\n\tdouble rtv = vexDeviceGpsHeadingGet(device->device_info);\n\treturn_port(port - 1, rtv);\n}\n\ngps_gyro_s_t gps_get_gyro_rate(uint8_t port) {\n\tgps_gyro_s_t rtv = GPS_RAW_ERR_INIT;\n\tif (!claim_port_try(port - 1, E_DEVICE_GPS)) {\n\t\treturn rtv;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tV5_DeviceGpsRaw data;\n\tvexDeviceGpsRawGyroGet(device->device_info, &data);\n\trtv.x = data.x;\n\trtv.y = data.y;\n\trtv.z = data.z;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_gyro_rate_x(uint8_t port) {\n    claim_port_f(port - 1, E_DEVICE_GPS);\n\tV5_DeviceGpsRaw data;\n\tvexDeviceGpsRawGyroGet(device->device_info, &data);\n\tdouble rtv = data.x;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_gyro_rate_y(uint8_t port) {\n    claim_port_f(port - 1, E_DEVICE_GPS);\n\tV5_DeviceGpsRaw data;\n\tvexDeviceGpsRawGyroGet(device->device_info, &data);\n\tdouble rtv = data.y;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_gyro_rate_z(uint8_t port) {\n    claim_port_f(port - 1, E_DEVICE_GPS);\n\tV5_DeviceGpsRaw data;\n\tvexDeviceGpsRawGyroGet(device->device_info, &data);\n\tdouble rtv = data.z;\n\treturn_port(port - 1, rtv);\n}\n\ngps_accel_s_t gps_get_accel(uint8_t port) {\n\tgps_accel_s_t rtv = GPS_RAW_ERR_INIT;\n\tif (!claim_port_try(port - 1, E_DEVICE_GPS)) {\n\t\treturn rtv;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tV5_DeviceGpsRaw data;\n\tvexDeviceGpsRawAccelGet(device->device_info, &data);\n\trtv.x = data.x;\n\trtv.y = data.y;\n\trtv.z = data.z;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_accel_x(uint8_t port) {\n    claim_port_f(port - 1, E_DEVICE_GPS);\n\tV5_DeviceGpsRaw data;\n\tvexDeviceGpsRawAccelGet(device->device_info, &data);\n\tdouble rtv = data.x;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_accel_y(uint8_t port) {\n    claim_port_f(port - 1, E_DEVICE_GPS);\n\tV5_DeviceGpsRaw data;\n\tvexDeviceGpsRawAccelGet(device->device_info, &data);\n\tdouble rtv = data.y;\n\treturn_port(port - 1, rtv);\n}\n\ndouble gps_get_accel_z(uint8_t port) {\n    claim_port_f(port - 1, E_DEVICE_GPS);\n\tV5_DeviceGpsRaw data;\n\tvexDeviceGpsRawAccelGet(device->device_info, &data);\n\tdouble rtv = data.z;\n\treturn_port(port - 1, rtv);\n}\n"
  },
  {
    "path": "src/devices/vdml_gps.cpp",
    "content": "/**\n * \\file devices/vdml_gps.cpp\n *\n * Contains functions for interacting with the VEX GPS.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"pros/device.h\"\n#include \"pros/gps.hpp\"\n#include \"vdml/vdml.h\"\n\nnamespace pros {\ninline namespace v5 {\n\nstd::int32_t Gps::initialize_full(double xInitial, double yInitial, double headingInitial, double xOffset,\n                                  double yOffset) const {\n\treturn pros::c::gps_initialize_full(_port, xInitial, yInitial, headingInitial, xOffset, yOffset);\n}\n\nstd::int32_t Gps::set_offset(double xOffset, double yOffset) const {\n\treturn pros::c::gps_set_offset(_port, xOffset, yOffset);\n}\n\npros::gps_position_s_t Gps::get_offset() const {\n\treturn pros::c::gps_get_offset(_port);\n}\n\nstd::int32_t Gps::set_position(double xInitial, double yInitial, double headingInitial) const {\n\treturn pros::c::gps_set_position(_port, xInitial, yInitial, headingInitial);\n}\n\nstd::int32_t Gps::set_data_rate(std::uint32_t rate) const {\n\treturn pros::c::gps_set_data_rate(_port, rate);\n}\n\nstd::vector<Gps> Gps::get_all_devices() {\n\tstd::vector<Device> matching_devices {Device::get_all_devices(DeviceType::gps)};\n\tstd::vector<Gps> return_vector;\n\tfor (auto device : matching_devices) {\n\t\treturn_vector.push_back(device);\n\t}\n\treturn return_vector;\n}\n\n\ndouble Gps::get_error() const {\n\treturn pros::c::gps_get_error(_port);\n}\n\npros::gps_status_s_t Gps::get_position_and_orientation() const {\n\treturn pros::c::gps_get_position_and_orientation(_port);\n}\n\npros::gps_position_s_t Gps::get_position() const {\n\treturn pros::c::gps_get_position(_port);\n}\n\ndouble Gps::get_position_x() const {\n    return pros::c::gps_get_position_x(_port);\n}\n\ndouble Gps::get_position_y() const {\n    return pros::c::gps_get_position_y(_port);\n}\n\npros::gps_orientation_s_t Gps::get_orientation() const {\n    return pros::c::gps_get_orientation(_port);\n}\n\ndouble Gps::get_pitch() const {\n    return pros::c::gps_get_pitch(_port);\n}\n\ndouble Gps::get_roll() const {\n    return pros::c::gps_get_roll(_port);\n}\n\ndouble Gps::get_yaw() const {\n    return pros::c::gps_get_yaw(_port);\n}\n\ndouble Gps::get_heading() const {\n\treturn pros::c::gps_get_heading(_port);\n}\n\ndouble Gps::get_heading_raw() const {\n\treturn pros::c::gps_get_heading_raw(_port);\n}\n\npros::gps_gyro_s_t Gps::get_gyro_rate() const {\n\treturn pros::c::gps_get_gyro_rate(_port);\n}\n\ndouble Gps::get_gyro_rate_x() const {\n    return pros::c::gps_get_gyro_rate_x(_port);\n}\n\ndouble Gps::get_gyro_rate_y() const {\n\treturn pros::c::gps_get_gyro_rate_y(_port);\n}\n\ndouble Gps::get_gyro_rate_z() const {\n\treturn pros::c::gps_get_gyro_rate_z(_port);\n}\n\npros::gps_accel_s_t Gps::get_accel() const {\n\treturn pros::c::gps_get_accel(_port);\n}\n\ndouble Gps::get_accel_x() const {\n    return pros::c::gps_get_accel_x(_port);\n}\n\ndouble Gps::get_accel_y() const {\n\treturn pros::c::gps_get_accel_y(_port);\n}\n\ndouble Gps::get_accel_z() const {\n\treturn pros::c::gps_get_accel_z(_port);\n}\n\nstd::ostream& operator<<(std::ostream& os, const pros::Gps& gps) {\n\tpros::gps_status_s_t data = gps.get_position_and_orientation();\n\tos << \"Gps [\";\n\tos << \"port: \" << gps._port;\n\tos << \", x: \" << data.x;\n\tos << \", y: \" << data.y;\n\tos << \", heading: \" << gps.get_heading();\n\tos << \"]\";\n\treturn os;\n}\n\npros::Gps pros::Gps::get_gps() {\n\tstatic int curr_gps_port = 0;\n\tcurr_gps_port = curr_gps_port % 21;\n\tfor (int i = 0; i < 21; i++) {\n\t\tif (registry_get_device(curr_gps_port)->device_type == pros::c::E_DEVICE_GPS) {\n\t\t\tcurr_gps_port++;\n\t\t\treturn Gps(curr_gps_port);\n\t\t}\n\t\tcurr_gps_port++;\n\t\tcurr_gps_port = curr_gps_port % 21;\n\t}\n\terrno = ENODEV;\n\treturn Gps(PROS_ERR_BYTE);\n}\n\nnamespace literals {\nconst pros::Gps operator\"\"_gps(const unsigned long long int g) {\n\treturn pros::Gps(g);\n}\n}  // namespace literals\n}  // namespace v5\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/vdml_imu.c",
    "content": "/**\n * \\file devices/vdml_imu.c\n *\n * Contains functions for interacting with the VEX Inertial sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n\n#include \"pros/imu.h\"\n#include \"v5_api.h\"\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\n#define IMU_EULER_LIMIT 180\n#define IMU_HEADING_MAX 360\n\n#define DEGTORAD (M_PI / 180)\n\n#define ERROR_IMU_STILL_CALIBRATING(port, device, err_return)                  \\\n\tif (vexDeviceImuStatusGet(device->device_info) & E_IMU_STATUS_CALIBRATING) { \\\n\t\terrno = EAGAIN;                                                            \\\n\t\treturn_port(port - 1, err_return);                                         \\\n\t}\n\n#define IMU_RESET_FLAG_SET_TIMEOUT 1000\n#define IMU_RESET_TIMEOUT 3000  // Canonically this should be 2s, but 3s for good margin\n\ntypedef struct __attribute__((packed, __may_alias__)) imu_reset_data {\n\tdouble heading_offset;\n\tdouble rotation_offset;\n\tdouble pitch_offset;\n\tdouble yaw_offset;\n\tdouble roll_offset;\n} imu_data_s_t;\n\nint32_t imu_reset(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_IMU);\n\tERROR_IMU_STILL_CALIBRATING(port, device, PROS_ERR);\n\tvexDeviceImuReset(device->device_info);\n\t// delay for vexos to set calibration flag, background processing must be called for flag\n\t// to be set.\n\tuint16_t timeoutCount = 0;\n\t// releasing mutex so vexBackgrounProcessing can run without being blocked.\n\tdo {\n\t\tport_mutex_give(port - 1);\n\t\ttask_delay(5);\n\t\ttimeoutCount += 5;\n\t\tclaim_port_i(port - 1, E_DEVICE_IMU);\n\t\tif (timeoutCount >= IMU_RESET_FLAG_SET_TIMEOUT) {\n\t\t\tport_mutex_give(port - 1);\n\t\t\terrno = EAGAIN;\n\t\t\treturn PROS_ERR;\n\t\t}\n\t\tdevice = device;  // suppressing compiler warning\n\t} while (!(vexDeviceImuStatusGet(device->device_info) & E_IMU_STATUS_CALIBRATING));\n\tport_mutex_give(port - 1);\n\treturn 1;\n}\n\nint32_t imu_reset_blocking(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_IMU);\n\tERROR_IMU_STILL_CALIBRATING(port, device, PROS_ERR);\n\tvexDeviceImuReset(device->device_info);\n\t// delay for vexos to set calibration flag, background processing must be called for flag\n\t// to be set.\n\tuint16_t timeoutCount = 0;\n\t// releasing mutex so vexBackgroundProcessing can run without being blocked.\n\tdo {\n\t\tport_mutex_give(port - 1);\n\t\ttask_delay(5);\n\t\ttimeoutCount += 5;\n\t\tclaim_port_i(port - 1, E_DEVICE_IMU);\n\t\tif (timeoutCount >= IMU_RESET_FLAG_SET_TIMEOUT) {\n\t\t\tport_mutex_give(port - 1);\n\t\t\terrno = EAGAIN;\n\t\t\treturn PROS_ERR;\n\t\t}\n\t\tdevice = device;  // suppressing compiler warning\n\t} while (!(vexDeviceImuStatusGet(device->device_info) & E_IMU_STATUS_CALIBRATING));\n\t// same concept here, we add a blocking delay for the blocking version to wait\n\t// until the IMU calibrating flag is cleared\n\tdo {\n\t\tport_mutex_give(port - 1);\n\t\ttask_delay(5);\n\t\ttimeoutCount += 5;\n\t\tclaim_port_i(port - 1, E_DEVICE_IMU);\n\t\tif (timeoutCount >= IMU_RESET_TIMEOUT) {\n\t\t\tport_mutex_give(port - 1);\n\t\t\terrno = EAGAIN;\n\t\t\treturn PROS_ERR;\n\t\t}\n\t\tdevice = device;  // suppressing compiler warning\n\t} while (vexDeviceImuStatusGet(device->device_info) & E_IMU_STATUS_CALIBRATING);\n\tport_mutex_give(port - 1);\n\treturn 1;\n}\n\nint32_t imu_set_data_rate(uint8_t port, uint32_t rate) {\n\tclaim_port_i(port - 1, E_DEVICE_IMU);\n\tERROR_IMU_STILL_CALIBRATING(port, device, PROS_ERR);\n\n\t// rate is not less than 5ms, and rounded down to nearest increment of 5\n\tif (rate < IMU_MINIMUM_DATA_RATE) {\n\t\trate = IMU_MINIMUM_DATA_RATE;\n\t} else {\n\t\trate -= rate % IMU_MINIMUM_DATA_RATE;\n\t}\n\n\tvexDeviceImuDataRateSet(device->device_info, rate);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\ndouble imu_get_rotation(uint8_t port) {\n\tclaim_port_f(port - 1, E_DEVICE_IMU);\n\tERROR_IMU_STILL_CALIBRATING(port, device, PROS_ERR_F);\n\tdouble rtn = vexDeviceImuHeadingGet(device->device_info) +\n\t             ((imu_data_s_t*)registry_get_device(port - 1)->pad)->rotation_offset;\n\treturn_port(port - 1, rtn);\n}\n\ndouble imu_get_heading(uint8_t port) {\n\tclaim_port_f(port - 1, E_DEVICE_IMU);\n\tERROR_IMU_STILL_CALIBRATING(port, device, PROS_ERR_F);\n\tdouble rtn =\n\t    vexDeviceImuDegreesGet(device->device_info) + ((imu_data_s_t*)registry_get_device(port - 1)->pad)->heading_offset;\n\t// Restricting value to raw boundaries\n\treturn_port(port - 1, fmod((rtn + IMU_HEADING_MAX), (double)IMU_HEADING_MAX));\n}\n\n#define QUATERNION_ERR_INIT \\\n\t{ .x = PROS_ERR_F, .y = PROS_ERR_F, .z = PROS_ERR_F, .w = PROS_ERR_F }\n\nquaternion_s_t imu_get_quaternion(uint8_t port) {\n\tquaternion_s_t rtn = QUATERNION_ERR_INIT;\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn rtn;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tERROR_IMU_STILL_CALIBRATING(port, device, rtn);\n\teuler_s_t euler;\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&euler);\n\timu_data_s_t* data = (imu_data_s_t*)device->pad;\n\t// To calculate the quaternion values, we first get the euler values, add the offsets,\n\t// and then do the calculations.\n\tdouble roll = fmod(euler.roll + data->roll_offset, 2.0 * IMU_EULER_LIMIT);\n\tdouble yaw = fmod(euler.yaw + data->yaw_offset, 2.0 * IMU_EULER_LIMIT);\n\tdouble pitch = fmod(euler.pitch + data->pitch_offset, 2.0 * IMU_EULER_LIMIT);\n\n\tdouble cy = cos(DEGTORAD * yaw * 0.5);\n\tdouble sy = sin(DEGTORAD * yaw * 0.5);\n\tdouble cp = cos(DEGTORAD * pitch * 0.5);\n\tdouble sp = sin(DEGTORAD * pitch * 0.5);\n\tdouble cr = cos(DEGTORAD * roll * 0.5);\n\tdouble sr = sin(DEGTORAD * roll * 0.5);\n\n\trtn.w = cr * cp * cy + sr * sp * sy;\n\trtn.x = sr * cp * cy - cr * sp * sy;\n\trtn.y = cr * sp * cy + sr * cp * sy;\n\trtn.z = cr * cp * sy - sr * sp * cy;\n\n\treturn_port(port - 1, rtn);\n}\n\n#define ATTITUDE_ERR_INIT \\\n\t{ .pitch = PROS_ERR_F, .roll = PROS_ERR_F, .yaw = PROS_ERR_F }\n\neuler_s_t imu_get_euler(uint8_t port) {\n\teuler_s_t rtn = ATTITUDE_ERR_INIT;\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn rtn;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\timu_data_s_t* data = (imu_data_s_t*)device->pad;\n\tERROR_IMU_STILL_CALIBRATING(port, device, rtn);\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&rtn);\n\trtn.pitch += data->pitch_offset;\n\trtn.yaw += data->yaw_offset;\n\trtn.roll += data->roll_offset;\n\trtn.roll = fmod(rtn.roll, 2.0 * IMU_EULER_LIMIT);\n\trtn.yaw = fmod(rtn.yaw, 2.0 * IMU_EULER_LIMIT);\n\trtn.pitch = fmod(rtn.pitch, 2.0 * IMU_EULER_LIMIT);\n\treturn_port(port - 1, rtn);\n}\n\ndouble imu_get_pitch(uint8_t port) {\n\tdouble rtn = PROS_ERR_F;\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn rtn;\n\t}\n\teuler_s_t euler_values;\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&euler_values);\n\trtn = euler_values.pitch + ((imu_data_s_t*)registry_get_device(port - 1)->pad)->pitch_offset;\n\t// Restricting value to raw boundaries\n\treturn_port(port - 1, fmod(rtn, 2.0 * IMU_EULER_LIMIT));\n}\n\ndouble imu_get_roll(uint8_t port) {\n\tdouble rtn = PROS_ERR_F;\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn rtn;\n\t}\n\teuler_s_t euler_values;\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&euler_values);\n\trtn = euler_values.roll + ((imu_data_s_t*)registry_get_device(port - 1)->pad)->roll_offset;\n\t// Restricting value to raw boundaries\n\treturn_port(port - 1, fmod(rtn, 2.0 * IMU_EULER_LIMIT));\n}\n\ndouble imu_get_yaw(uint8_t port) {\n\tdouble rtn = PROS_ERR_F;\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn rtn;\n\t}\n\teuler_s_t euler_values;\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&euler_values);\n\trtn = euler_values.yaw + ((imu_data_s_t*)registry_get_device(port - 1)->pad)->yaw_offset;\n\t// Restricting value to raw boundaries\n\treturn_port(port - 1, fmod(rtn, 2.0 * IMU_EULER_LIMIT));\n}\n\n#define RAW_IMU_ERR_INIT {.x = PROS_ERR_F, .y = PROS_ERR_F, .z = PROS_ERR_F};\n\nimu_gyro_s_t imu_get_gyro_rate(uint8_t port) {\n\timu_gyro_s_t rtn = RAW_IMU_ERR_INIT;\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn rtn;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tERROR_IMU_STILL_CALIBRATING(port, device, rtn);\n\t// NOTE: `V5_DeviceImuRaw` has the same form as a quaternion, but this call\n\t// never fills the `w` field, so we make a dummy quaternion container and copy\n\t// the (x,y,z) part into the return struct\n\tquaternion_s_t dummy;\n\tvexDeviceImuRawGyroGet(device->device_info, (V5_DeviceImuRaw*)&dummy);\n\trtn.x = dummy.x;\n\trtn.y = dummy.y;\n\trtn.z = dummy.z;\n\treturn_port(port - 1, rtn);\n}\n\nimu_accel_s_t imu_get_accel(uint8_t port) {\n\timu_accel_s_t rtn = RAW_IMU_ERR_INIT;\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn rtn;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tERROR_IMU_STILL_CALIBRATING(port, device, rtn);\n\t// NOTE: this is the same as `imu_get_raw_gyro`\n\tquaternion_s_t dummy;\n\tvexDeviceImuRawAccelGet(device->device_info, (V5_DeviceImuRaw*)&dummy);\n\trtn.x = dummy.x;\n\trtn.y = dummy.y;\n\trtn.z = dummy.z;\n\treturn_port(port - 1, rtn);\n}\n\nimu_status_e_t imu_get_status(uint8_t port) {\n\timu_status_e_t rtn = E_IMU_STATUS_ERROR;\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn rtn;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\trtn = vexDeviceImuStatusGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\n// Reset Functions:\nint32_t imu_tare(uint8_t port) {\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn PROS_ERR;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\teuler_s_t euler_values;\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&euler_values);\n\timu_data_s_t* data = (imu_data_s_t*)device->pad;\n\tdata->rotation_offset = -vexDeviceImuHeadingGet(device->device_info);\n\tdata->heading_offset = -vexDeviceImuDegreesGet(device->device_info);\n\tdata->pitch_offset = -euler_values.pitch;\n\tdata->roll_offset = -euler_values.roll;\n\tdata->yaw_offset = -euler_values.yaw;\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t imu_tare_euler(uint8_t port) {\n\treturn imu_set_euler(port, (euler_s_t){0, 0, 0});\n}\n\nint32_t imu_tare_heading(uint8_t port) {\n\treturn imu_set_heading(port, 0);\n}\n\nint32_t imu_tare_rotation(uint8_t port) {\n\treturn imu_set_rotation(port, 0);\n}\n\nint32_t imu_tare_pitch(uint8_t port) {\n\treturn imu_set_pitch(port, 0);\n}\n\nint32_t imu_tare_roll(uint8_t port) {\n\treturn imu_set_roll(port, 0);\n}\n\nint32_t imu_tare_yaw(uint8_t port) {\n\treturn imu_set_yaw(port, 0);\n}\n\n// Setter Functions:\nint32_t imu_set_rotation(uint8_t port, double target) {\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn PROS_ERR;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tERROR_IMU_STILL_CALIBRATING(port, device, PROS_ERR);\n\teuler_s_t euler_values;\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&euler_values);\n\timu_data_s_t* data = (imu_data_s_t*)device->pad;\n\tdata->rotation_offset = target - vexDeviceImuHeadingGet(device->device_info);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t imu_set_heading(uint8_t port, double target) {\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn PROS_ERR;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tERROR_IMU_STILL_CALIBRATING(port, device, PROS_ERR);\n\teuler_s_t euler_values;\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&euler_values);\n\timu_data_s_t* data = (imu_data_s_t*)device->pad;\n\tif (target > IMU_HEADING_MAX) target = IMU_HEADING_MAX;\n\tif (target < 0) target = 0;\n\tdata->heading_offset = target - vexDeviceImuDegreesGet(device->device_info);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t imu_set_pitch(uint8_t port, double target) {\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn PROS_ERR;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tERROR_IMU_STILL_CALIBRATING(port, device, PROS_ERR);\n\teuler_s_t euler_values;\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&euler_values);\n\timu_data_s_t* data = (imu_data_s_t*)device->pad;\n\tif (target > IMU_EULER_LIMIT) target = IMU_EULER_LIMIT;\n\tif (target < -IMU_EULER_LIMIT) target = -IMU_EULER_LIMIT;\n\tdata->pitch_offset = target - euler_values.pitch;\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t imu_set_roll(uint8_t port, double target) {\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn PROS_ERR;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tERROR_IMU_STILL_CALIBRATING(port, device, PROS_ERR);\n\teuler_s_t euler_values;\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&euler_values);\n\timu_data_s_t* data = (imu_data_s_t*)device->pad;\n\tif (target > IMU_EULER_LIMIT) target = IMU_EULER_LIMIT;\n\tif (target < -IMU_EULER_LIMIT) target = -IMU_EULER_LIMIT;\n\tdata->roll_offset = target - euler_values.roll;\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t imu_set_yaw(uint8_t port, double target) {\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn PROS_ERR;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tERROR_IMU_STILL_CALIBRATING(port, device, PROS_ERR);\n\teuler_s_t euler_values;\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&euler_values);\n\timu_data_s_t* data = (imu_data_s_t*)device->pad;\n\tdata->yaw_offset = target - euler_values.yaw;\n\tif (target > IMU_EULER_LIMIT) target = IMU_EULER_LIMIT;\n\tif (target < -IMU_EULER_LIMIT) target = -IMU_EULER_LIMIT;\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t imu_set_euler(uint8_t port, euler_s_t target) {\n\tif (!claim_port_try(port - 1, E_DEVICE_IMU)) {\n\t\treturn PROS_ERR;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\teuler_s_t euler_values;\n\tvexDeviceImuAttitudeGet(device->device_info, (V5_DeviceImuAttitude*)&euler_values);\n\timu_data_s_t* data = (imu_data_s_t*)device->pad;\n\tif (target.pitch > IMU_EULER_LIMIT) target.pitch = IMU_EULER_LIMIT;\n\tif (target.pitch < -IMU_EULER_LIMIT) target.pitch = -IMU_EULER_LIMIT;\n\tif (target.yaw > IMU_EULER_LIMIT) target.yaw = IMU_EULER_LIMIT;\n\tif (target.yaw < -IMU_EULER_LIMIT) target.yaw = -IMU_EULER_LIMIT;\n\tif (target.roll > IMU_EULER_LIMIT) target.roll = IMU_EULER_LIMIT;\n\tif (target.roll < -IMU_EULER_LIMIT) target.roll = -IMU_EULER_LIMIT;\n\tdata->pitch_offset = target.pitch - euler_values.pitch;\n\tdata->roll_offset = target.roll - euler_values.roll;\n\tdata->yaw_offset = target.yaw - euler_values.yaw;\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nimu_orientation_e_t imu_get_physical_orientation(uint8_t port) {\n\timu_status_e_t status = imu_get_status(port);\n\tif (status == E_IMU_STATUS_ERROR) {\n\t\treturn E_IMU_ORIENTATION_ERROR;\n\t}\n\treturn (status >> 1) & 7;\n}\n"
  },
  {
    "path": "src/devices/vdml_imu.cpp",
    "content": "/**\n * \\file devices/vdml_imu.cpp\n *\n * Contains functions for interacting with the VEX Inertial sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <cerrno>\n\n#include \"pros/imu.hpp\"\n#include \"vdml/vdml.h\"\n\nnamespace pros {\ninline namespace v5 {\n\nstd::int32_t Imu::reset(bool blocking /*= false*/) const {\n\treturn blocking ? pros::c::imu_reset_blocking(_port) : pros::c::imu_reset(_port);\n}\n\nstd::int32_t Imu::set_data_rate(std::uint32_t rate) const {\n\treturn pros::c::imu_set_data_rate(_port, rate);\n}\n\nstd::vector<Imu> Imu::get_all_devices() {\n\n\n\tstd::vector<Device> matching_devices {Device::get_all_devices(DeviceType::imu)};\n  \n\tstd::vector<Imu> return_vector;\n\tfor (auto device : matching_devices) {\n\t\treturn_vector.push_back(device);\n\t}\n\treturn return_vector;\n}\n\ndouble Imu::get_rotation() const {\n\treturn pros::c::imu_get_rotation(_port);\n}\n\ndouble Imu::get_heading() const {\n\treturn pros::c::imu_get_heading(_port);\n}\n\npros::quaternion_s_t Imu::get_quaternion() const {\n\treturn pros::c::imu_get_quaternion(_port);\n}\n\npros::euler_s_t Imu::get_euler() const {\n\treturn pros::c::imu_get_euler(_port);\n}\n\ndouble Imu::get_pitch() const {\n\treturn get_euler().pitch;\n}\n\ndouble Imu::get_roll() const {\n\treturn get_euler().roll;\n}\n\ndouble Imu::get_yaw() const {\n\treturn get_euler().yaw;\n}\n\npros::imu_gyro_s_t Imu::get_gyro_rate() const {\n\treturn pros::c::imu_get_gyro_rate(_port);\n}\n\npros::imu_accel_s_t Imu::get_accel() const {\n\treturn pros::c::imu_get_accel(_port);\n}\n\npros::ImuStatus Imu::get_status() const {\n\treturn static_cast<pros::ImuStatus>(pros::c::imu_get_status(_port));\n}\n\nbool Imu::is_calibrating() const {\n\timu_status_e_t status = pros::c::imu_get_status(_port);\n\tif (status == E_IMU_STATUS_ERROR) {\n\t\treturn false;\n\t}\n\treturn status & E_IMU_STATUS_CALIBRATING;\n}\n\nstd::int32_t Imu::tare_heading() const {\n\treturn pros::c::imu_tare_heading(_port);\n}\n\nstd::int32_t Imu::tare_rotation() const {\n\treturn pros::c::imu_tare_rotation(_port);\n}\n\nstd::int32_t Imu::tare_pitch() const {\n\treturn pros::c::imu_tare_pitch(_port);\n}\n\nstd::int32_t Imu::tare_yaw() const {\n\treturn pros::c::imu_tare_yaw(_port);\n}\n\nstd::int32_t Imu::tare_roll() const {\n\treturn pros::c::imu_tare_roll(_port);\n}\n\nstd::int32_t Imu::tare_euler() const {\n\treturn pros::c::imu_tare_euler(_port);\n}\n\nstd::int32_t Imu::set_heading(double target) const {\n\treturn pros::c::imu_set_heading(_port, target);\n}\n\nstd::int32_t Imu::set_rotation(double target) const {\n\treturn pros::c::imu_set_rotation(_port, target);\n}\n\nstd::int32_t Imu::set_pitch(double target) const {\n\treturn pros::c::imu_set_pitch(_port, target);\n}\n\nstd::int32_t Imu::set_yaw(double target) const {\n\treturn pros::c::imu_set_yaw(_port, target);\n}\n\nstd::int32_t Imu::set_roll(double target) const {\n\treturn pros::c::imu_set_roll(_port, target);\n}\n\nstd::int32_t Imu::set_euler(pros::euler_s_t target) const {\n\treturn pros::c::imu_set_euler(_port, target);\n}\n\nstd::int32_t Imu::tare() const {\n\treturn pros::c::imu_tare(_port);\n}\n\nimu_orientation_e_t Imu::get_physical_orientation() const {\n\treturn pros::c::imu_get_physical_orientation(_port);\n}\n\nImu Imu::get_imu() {\n\tstatic int curr_imu_port = 0;\n\tcurr_imu_port = curr_imu_port % 21;\n\tfor (int i = 0; i < 21; i++) {\n\t\tif (registry_get_device(curr_imu_port)->device_type == pros::c::E_DEVICE_IMU) {\n\t\t\tcurr_imu_port++;\n\t\t\treturn Imu(curr_imu_port);\n\t\t}\n\t\tcurr_imu_port++;\n\t\tcurr_imu_port = curr_imu_port % 21;\n\t}\n\terrno = ENODEV;\n\treturn Imu(PROS_ERR_BYTE);\n}\n\nstd::ostream& operator<<(std::ostream& os, const pros::Imu& imu) {\n\tpros::imu_gyro_s_t gyro = imu.get_gyro_rate();\n\tpros::imu_accel_s_t accel = imu.get_accel();\n\tos << \"Imu [\";\n\tos << \"port: \" << imu._port;\n\tos << \", rotation: \" << imu.get_rotation();\n\tos << \", heading: \" << imu.get_heading();\n\tos << \", pitch: \" << imu.get_pitch();\n\tos << \", roll: \" << imu.get_roll();\n\tos << \", yaw: \" << imu.get_yaw();\n\tos << \", gyro rate: \"\n\t   << \"{\" << gyro.x << \",\" << gyro.y << \",\" << gyro.z << \"}\";\n\tos << \", get accel: \"\n\t   << \"{\" << accel.x << \",\" << accel.y << \",\" << accel.z << \"}\";\n\tos << \", calibrating: \" << imu.is_calibrating();\n\tos << \"]\";\n\treturn os;\n}\n\nnamespace literals {\nconst pros::Imu operator\"\"_imu(const unsigned long long int i) {\n\treturn pros::Imu(i);\n}\n}  // namespace literals\n}  // namespace v5\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/vdml_link.c",
    "content": "/**\n * \\file vdml_link.c\n *\n * \\brief Contains source code for functions related to the robot to robot communications.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n #include \"pros/link.h\"\n #include \"kapi.h\"\n #include \"pros/apix.h\"\n #include \"vdml/vdml.h\"\n #include <string.h>\n\n#define PROTOCOL_SIZE         4 // Protocol Size \n\nstatic const uint8_t START_BYTE = 0x33;\n\n// internal function for clearing the rx buffer \nstatic uint32_t _clear_rx_buf(v5_smart_device_s_t* device) {\n    uint8_t buf[LINK_BUFFER_SIZE];\n    return vexDeviceGenericRadioReceive(device->device_info, \n    (uint8_t*)buf, \n    vexDeviceGenericRadioReceiveAvail(device->device_info));\n}\n\n//custom claim_port style wrapper for link_init due to type mismatching otherwise, limit of one radio per brain\nstatic uint32_t _link_init(uint8_t port, const char* link_id, link_type_e_t type, bool ov)\n{\n    if (!port_mutex_take(port)) {\n            errno = EACCES;                                       \n            return PROS_ERR;\n    }\n    v5_device_e_t plugged_type = registry_get_plugged_type(port);\n    if (plugged_type == E_DEVICE_RADIO || plugged_type == E_DEVICE_NONE) {\n        if (!VALIDATE_PORT_NO(port)) {\n\t\t    errno = ENXIO;\n\t\t    return PROS_ERR;\n\t    }\n        v5_smart_device_s_t* device = registry_get_device(port);\n        vexDeviceGenericRadioConnection(device->device_info, (char* )link_id, type, ov);\n        // Hack: Force v5 to recognize the plugged type as a serial device the next time we touch the device\n        registry_unbind_port(port);\n        return_port(port, PROS_SUCCESS);\n    }\n    errno = ENODEV;\n    return_port(port, PROS_ERR);\n}\n\nuint32_t link_init(uint8_t port, const char* link_id, link_type_e_t type) {\n    return _link_init(port - 1, link_id, type, false);\n}\n\nuint32_t link_init_override(uint8_t port, const char* link_id, link_type_e_t type) {\n    return _link_init(port - 1, link_id, type, true);\n}\n\nbool link_connected(uint8_t port) {\n    claim_port(port - 1, E_DEVICE_SERIAL, false);\n    bool rtv = vexDeviceGenericRadioLinkStatus(device->device_info); \n    return_port(port - 1, rtv);\n}\n\nuint32_t link_raw_receivable_size(uint8_t port) {\n    claim_port_i(port - 1, E_DEVICE_SERIAL);\n    uint32_t rtv = vexDeviceGenericRadioReceiveAvail(device->device_info); \n    return_port(port - 1, rtv);\n}\n\nuint32_t link_raw_transmittable_size(uint8_t port) {\n    claim_port_i(port - 1, E_DEVICE_SERIAL);\n    uint32_t rtv = vexDeviceGenericRadioWriteFree(device->device_info);\n    return_port(port - 1, rtv);\n}\n\nuint32_t link_transmit_raw(uint8_t port, void* data, uint16_t data_size) {\n    if(data == NULL) {\n        errno = EINVAL;\n        return PROS_ERR;\n    }\n    claim_port_i(port - 1, E_DEVICE_SERIAL);\n    if(!vexDeviceGenericRadioLinkStatus(device->device_info)) {\n        errno = ENXIO;\n        return_port(port - 1, PROS_ERR);\n    }\n    if(data_size > vexDeviceGenericRadioWriteFree(device->device_info)) {\n        errno = EBUSY;\n        return_port(port - 1, PROS_ERR);\n    }\n    uint32_t rtv = vexDeviceGenericRadioTransmit(device->device_info, (uint8_t*)data, data_size);\n    return_port(port - 1, rtv);\n}\n\nuint32_t link_receive_raw(uint8_t port, void* dest, uint16_t data_size) {\n    if(dest == NULL) {\n        errno = EINVAL;\n        return PROS_ERR;\n    }\n    claim_port_i(port - 1, E_DEVICE_SERIAL); \n    if(!vexDeviceGenericRadioLinkStatus(device->device_info)) {\n        errno = ENXIO;\n        return_port(port - 1, PROS_ERR);\n    }\n    if(data_size > vexDeviceGenericRadioReceiveAvail(device->device_info)) {\n        errno = EBUSY;\n        return_port(port - 1, PROS_ERR);\n    }\n    uint32_t rtv = vexDeviceGenericRadioReceive(device->device_info, (uint8_t*)dest, data_size);\n    return_port(port - 1, rtv);\n}\n\nuint32_t link_transmit(uint8_t port, void* data, uint16_t data_size) {\n    if(data == NULL) {\n        errno = EINVAL;\n        return PROS_ERR;\n    }\n    claim_port_i(port - 1, E_DEVICE_SERIAL);\n    if(!vexDeviceGenericRadioLinkStatus(device->device_info)) {\n        errno = ENXIO;\n        return_port(port - 1, PROS_ERR);\n    }\n    if(data_size + PROTOCOL_SIZE > vexDeviceGenericRadioWriteFree(device->device_info)) {\n        errno = EBUSY;\n        return_port(port - 1, PROS_ERR);\n    }\n    // calculated checksum\n    uint8_t checksum = START_BYTE;\n    uint8_t size_tx_buf[2];\n    size_tx_buf[1] = (data_size >> 8) & 0xff;\n    size_tx_buf[0] = (data_size) & 0xff;\n    checksum ^= size_tx_buf[1];\n    checksum ^= size_tx_buf[0];\n    \n    for(int i = 0; i < data_size; i++) {\n        checksum ^= ((uint8_t*)data)[i];\n    }\n    uint32_t rtv = 0;\n    // send protocol\n    rtv += vexDeviceGenericRadioTransmit(device->device_info, (uint8_t*)&START_BYTE, 1);\n    rtv += vexDeviceGenericRadioTransmit(device->device_info, size_tx_buf, 2);\n    rtv += vexDeviceGenericRadioTransmit(device->device_info, (uint8_t*)data, data_size);\n    rtv += vexDeviceGenericRadioTransmit(device->device_info, &checksum, 1);\n    return_port(port - 1, rtv);\n}\n\nuint32_t link_receive(uint8_t port, void* dest, uint16_t data_size) {\n    if(dest == NULL) {\n        errno = EINVAL;\n        return PROS_ERR;\n    }\n    claim_port_i(port - 1, E_DEVICE_SERIAL);\n    if(!vexDeviceGenericRadioLinkStatus(device->device_info)) {\n        errno = ENXIO;\n        return_port(port - 1, PROS_ERR);\n    }\n    if(data_size + PROTOCOL_SIZE > vexDeviceGenericRadioReceiveAvail(device->device_info)) {\n        errno = EBUSY;\n        return_port(port - 1, PROS_ERR);\n    }\n    uint8_t header_byte;\n    uint8_t received_size;\n    // process protocol\n    received_size = vexDeviceGenericRadioReceive(device->device_info, &header_byte, 1); // 0x33\n    if(START_BYTE != header_byte || received_size != 1) {\n        kprintf(\"[VEXLINK] Invalid Header Byte Received Port %d, header byte: %x\", port, header_byte);\n        errno = EBADMSG;\n        return_port(port - 1, PROS_ERR);\n    }\n    // datasize\n    uint16_t received_data_size;\n    received_size = vexDeviceGenericRadioReceive(device->device_info, (uint8_t*)&received_data_size, 2);\n    if(received_size != 2 || received_data_size != data_size) {\n        _clear_rx_buf(device);\n        kprintf(\"[VEXLINK] Invalid Data Size (Size: %d ) Received Port %d, flushing RX buffer!\\n\", received_data_size, port);\n        errno = EBADMSG;\n        return_port(port - 1, PROS_ERR);\n    }\n    // receive data\n    uint32_t rtv = vexDeviceGenericRadioReceive(device->device_info, (uint8_t*)dest, data_size);\n    if(rtv != data_size || received_data_size != data_size) {\n        kprintf(\"[VEXLINK] Invalid Data Received Port %d, flushing RX buffer!\\n\", port);\n        errno = EBADMSG;\n        _clear_rx_buf(device);\n        return_port(port - 1, PROS_ERR);\n    }\n    uint8_t received_checksum;\n    received_size = vexDeviceGenericRadioReceive(device->device_info, &received_checksum, 1);\n    // check checksum\n    uint8_t calculated_checksum = START_BYTE;\n    calculated_checksum ^= (data_size >> 8) & 0xff;\n    calculated_checksum ^= (data_size) & 0xff;\n    for(int i = 0; i < data_size; i++) {\n        calculated_checksum ^= ((uint8_t*)dest)[i];\n    }\n    if(calculated_checksum != received_checksum || received_size != 1) {\n        kprintf(\"[VEXLINK] Checksum Mismatch Port %d!, Checksum: %x\\n\", port, received_checksum);\n        errno = EBADMSG;\n        return_port(port - 1, PROS_ERR);\n    }\n    return_port(port - 1, rtv);\n}\n\nuint32_t link_clear_receive_buf(uint8_t port) {\n    claim_port_i(port - 1, E_DEVICE_SERIAL);\n    uint32_t rtv = _clear_rx_buf(device);\n    return_port(port - 1, rtv);\n}\n\n"
  },
  {
    "path": "src/devices/vdml_link.cpp",
    "content": "/**\n * \\file vdml_link.cpp\n *\n * \\brief Contains source code for functions related to the robot to robot communications.\n *\n * This file should not be modified by users, since it gets replaced whenever\n * a kernel upgrade occurs.\n * \n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"pros/link.hpp\"\n#include \"vdml/vdml.h\"\n\nnamespace pros {\nLink::Link(const std::uint8_t port, const std::string link_id, link_type_e_t type, bool ov) : Device(port, DeviceType::radio) {\n\t(ov) ? pros::c::link_init_override(_port, link_id.c_str(), type) : pros::c::link_init(_port, link_id.c_str(), type);\n}\n\nbool Link::connected() {\n\treturn pros::c::link_connected(_port);\n}\n\nstd::uint32_t Link::raw_receivable_size() {\n\treturn pros::c::link_raw_receivable_size(_port);\n}\n\nstd::uint32_t Link::raw_transmittable_size() {\n\treturn pros::c::link_raw_transmittable_size(_port);\n}\n\nstd::uint32_t Link::transmit_raw(void* data, std::uint16_t data_size) {\n\treturn pros::c::link_transmit_raw(_port, data, data_size);\n}\n\nstd::uint32_t Link::receive_raw(void* dest, std::uint16_t data_size) {\n\treturn pros::c::link_receive_raw(_port, dest, data_size);\n}\n\nstd::uint32_t Link::transmit(void* data, std::uint16_t data_size) {\n\treturn pros::c::link_transmit(_port, data, data_size);\n}\n\nstd::uint32_t Link::receive(void* dest, std::uint16_t data_size) {\n\treturn pros::c::link_receive(_port, dest, data_size);\n}\n\nstd::uint32_t Link::clear_receive_buf() {\n\treturn pros::c::link_clear_receive_buf(_port);\n}\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/vdml_motorgroup.cpp",
    "content": "/**\n * \\file devices/vdml_motors.cpp\n *\n * Contains functions for interacting with the V5 Motors.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <cstdint>\n#include \"kapi.h\"\n#include \"pros/abstract_motor.hpp\"\n#include \"pros/motor_group.hpp\"\n#include \"pros/motors.hpp\"\n\nnamespace pros {\ninline namespace v5 {\nusing namespace pros::c;\n#define empty_MotorGroup_check(error) \\\n\tif (_ports.size() <= 0) {           \\\n\t\terrno = EDOM;                     \\\n\t\treturn error;                     \\\n\t}\n#define MotorGroup_index_check(error, index) \\\n\tif (_ports.size() <= index || index < 0) { \\\n\t\terrno = EOVERFLOW;                       \\\n\t\treturn error;                            \\\n\t}\n\n#define empty_MotorGroup_check_vector(error, vector) \\\n\tif (_ports.size() <= 0) {                          \\\n\t\terrno = EDOM;                                    \\\n\t\tvector.push_back(error);                         \\\n\t\treturn vector;                                   \\\n\t}\n\n\nMotorGroup::MotorGroup(AbstractMotor& motor_group) : MotorGroup(motor_group.get_port_all()) {}\n\nMotorGroup::MotorGroup(const std::initializer_list<std::int8_t> ports, const pros::v5::MotorGears gearset,\n                       const pros::v5::MotorUnits encoder_units)\n    : _ports(ports) {\n\tif (gearset != pros::v5::MotorGears::invalid) {\n\t\tset_gearing_all(gearset);\n\t}\n\tif (encoder_units != pros::v5::MotorUnits::invalid) {\n\t\tset_encoder_units_all(encoder_units);\n\t}\n}\n\nMotorGroup::MotorGroup(const std::vector<std::int8_t>& ports, const pros::v5::MotorGears gearset,\n                       const pros::v5::MotorUnits encoder_units)\n    : _ports(ports) {\n\tif (gearset != pros::v5::MotorGears::invalid) {\n\t\tset_gearing_all(gearset);\n\t}\n\tif (encoder_units != pros::v5::MotorUnits::invalid) {\n\t\tset_encoder_units_all(encoder_units);\n\t}\n}\n\nstd::int32_t MotorGroup::move(std::int32_t voltage) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_move(*it, voltage);\n\t}\n\treturn motor_move(_ports[0], voltage);\n}\n\nstd::int32_t MotorGroup::move_absolute(const double position, const std::int32_t velocity) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_move_absolute(*it, position, velocity);\n\t}\n\treturn motor_move_absolute(_ports[0], position, velocity);\n}\n\nstd::int32_t MotorGroup::move_relative(const double position, const std::int32_t velocity) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_move_relative(*it, position, velocity);\n\t}\n\treturn motor_move_relative(_ports[0], position, velocity);\n}\n\nstd::int32_t MotorGroup::move_velocity(const std::int32_t velocity) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_move_velocity(*it, velocity);\n\t}\n\treturn motor_move_velocity(_ports[0], velocity);\n}\n\nstd::int32_t MotorGroup::move_voltage(const std::int32_t voltage) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_move_voltage(*it, voltage);\n\t}\n\treturn motor_move_voltage(_ports[0], voltage);\n}\n\nstd::int32_t MotorGroup::brake(void) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_brake(*it);\n\t}\n\treturn motor_brake(_ports[0]);\n}\n\nstd::int32_t MotorGroup::modify_profiled_velocity(const std::int32_t velocity) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_modify_profiled_velocity(*it, velocity);\n\t}\n\treturn motor_modify_profiled_velocity(_ports[0], velocity);\n}\n\ndouble MotorGroup::get_actual_velocity(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR_F);\n\tMotorGroup_index_check(PROS_ERR_F, index);\n\n\treturn motor_get_actual_velocity(_ports[index]);\n}\nstd::vector<double> MotorGroup::get_actual_velocity_all(void) const {\n\tstd::vector<double> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR_F, return_vector);\n\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_actual_velocity(*it));\n\t}\n\treturn return_vector;\n}\n\npros::v5::MotorBrake MotorGroup::get_brake_mode(const std::uint8_t index) const {\n\tempty_MotorGroup_check(pros::v5::MotorBrake::invalid);\n\tMotorGroup_index_check(pros::v5::MotorBrake::invalid, index);\n\n\treturn static_cast<pros::v5::MotorBrake>(motor_get_brake_mode(_ports[index]));\n}\n\nstd::vector<pros::v5::MotorBrake> MotorGroup::get_brake_mode_all(void) const {\n\tstd::vector<pros::v5::MotorBrake> return_vector;\n\tempty_MotorGroup_check_vector(pros::v5::MotorBrake::invalid, return_vector);\n\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(static_cast<pros::v5::MotorBrake>(motor_get_brake_mode(*it)));\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t MotorGroup::get_current_draw(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\n\treturn motor_get_current_draw(_ports[index]);\n}\nstd::vector<std::int32_t> MotorGroup::get_current_draw_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_current_draw(*it));\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t MotorGroup::get_current_limit(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\n\treturn motor_get_current_limit(_ports[index]);\n}\n\nstd::vector<std::int32_t> MotorGroup::get_current_limit_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_current_limit(*it));\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t MotorGroup::is_over_current(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_is_over_current(_ports[index]);\n}\n\nstd::vector<std::int32_t> MotorGroup::is_over_current_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_is_over_current(*it));\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t MotorGroup::get_direction(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\tint ret = motor_get_direction(_ports[index]);\n\tret = _ports[index] >= 0 ? ret : ret * -1;\n\treturn ret;\n}\n\nstd::vector<std::int32_t> MotorGroup::get_direction_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\tint ret = motor_get_direction(*it);\n\t\tret = *it >= 0 ? ret : ret * -1;\n\t\treturn_vector.push_back(ret);\n\t}\n\treturn return_vector;\n}\n\ndouble MotorGroup::get_efficiency(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR_F);\n\tMotorGroup_index_check(PROS_ERR_F, index);\n\treturn motor_get_efficiency(_ports[index]);\n}\n\nstd::vector<double> MotorGroup::get_efficiency_all(void) const {\n\tstd::vector<double> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR_F, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_efficiency(*it));\n\t}\n\treturn return_vector;\n}\n\npros::v5::MotorUnits MotorGroup::get_encoder_units(const std::uint8_t index) const {\n\tempty_MotorGroup_check(pros::v5::MotorUnits::invalid);\n\tMotorGroup_index_check(pros::v5::MotorUnits::invalid, index);\n\treturn static_cast<pros::v5::MotorUnits>(motor_get_encoder_units(_ports[index]));\n}\n\nstd::vector<pros::v5::MotorUnits> MotorGroup::get_encoder_units_all(void) const {\n\tstd::vector<pros::v5::MotorUnits> return_vector;\n\tempty_MotorGroup_check_vector(pros::v5::MotorUnits::invalid, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(static_cast<pros::v5::MotorUnits>(motor_get_encoder_units(*it)));\n\t}\n\treturn return_vector;\n}\n\nstd::uint32_t MotorGroup::get_faults(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_get_faults(_ports[index]);\n}\n\nstd::vector<std::uint32_t> MotorGroup::get_faults_all(void) const {\n\tstd::vector<std::uint32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_faults(*it));\n\t}\n\treturn return_vector;\n}\n\nstd::uint32_t MotorGroup::get_flags(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_get_flags(_ports[index]);\n}\n\nstd::vector<std::uint32_t> MotorGroup::get_flags_all(void) const {\n\tstd::vector<std::uint32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_flags(*it));\n\t}\n\treturn return_vector;\n}\n\npros::v5::MotorGears MotorGroup::get_gearing(const std::uint8_t index) const {\n\tempty_MotorGroup_check(pros::v5::MotorGears::invalid);\n\tMotorGroup_index_check(pros::v5::MotorGears::invalid, index);\n\treturn static_cast<pros::v5::MotorGears>(motor_get_gearing(_ports[index]));\n}\n\nstd::vector<pros::v5::MotorGears> MotorGroup::get_gearing_all(void) const {\n\tstd::vector<pros::v5::MotorGears> return_vector;\n\tempty_MotorGroup_check_vector(pros::v5::MotorGears::invalid, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(static_cast<pros::v5::MotorGears>(motor_get_gearing(*it)));\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t MotorGroup::get_raw_position(std::uint32_t* const timestamp, std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_get_raw_position(_ports[index], timestamp);\n}\n\nstd::vector<std::int32_t> MotorGroup::get_raw_position_all(std::uint32_t* const timestamp) const {\n\tstd::vector<std::int32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_raw_position(*it, timestamp));\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t MotorGroup::is_over_temp(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_is_over_temp(_ports[index]);\n}\n\nstd::vector<std::int32_t> MotorGroup::is_over_temp_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_is_over_temp(*it));\n\t}\n\treturn return_vector;\n}\n\ndouble MotorGroup::get_position(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR_F);\n\tMotorGroup_index_check(PROS_ERR_F, index);\n\treturn motor_get_position(_ports[index]);\n}\n\nstd::vector<double> MotorGroup::get_position_all(void) const {\n\tstd::vector<double> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR_F, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_position(*it));\n\t}\n\treturn return_vector;\n}\n\ndouble MotorGroup::get_power(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR_F);\n\tMotorGroup_index_check(PROS_ERR_F, index);\n\treturn motor_get_power(_ports[index]);\n}\n\nstd::vector<double> MotorGroup::get_power_all(void) const {\n\tstd::vector<double> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR_F, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_power(*it));\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t MotorGroup::is_reversed(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_is_reversed(index);\n}\n\nstd::vector<std::int32_t> MotorGroup::is_reversed_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_is_reversed(*it));\n\t}\n\treturn return_vector;\n}\n\npros::v5::MotorType MotorGroup::get_type(const std::uint8_t index) const {\n\tempty_MotorGroup_check(pros::v5::MotorType::invalid);\n\tMotorGroup_index_check(pros::v5::MotorType::invalid, index);\n\treturn static_cast<pros::v5::MotorType>(motor_get_type(_ports[index]));\n}\n\nstd::vector<pros::v5::MotorType> MotorGroup::get_type_all(void) const {\n\tstd::vector<pros::v5::MotorType> return_vector;\n\tempty_MotorGroup_check_vector(pros::v5::MotorType::invalid, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(static_cast<pros::v5::MotorType>(motor_get_type(*it)));\n\t}\n\treturn return_vector;\n}\n\ndouble MotorGroup::get_temperature(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR_F);\n\tMotorGroup_index_check(PROS_ERR_F, index);\n\treturn motor_get_temperature(_ports[index]);\n}\n\nstd::vector<double> MotorGroup::get_temperature_all(void) const {\n\tstd::vector<double> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR_F, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_temperature(*it));\n\t}\n\treturn return_vector;\n}\n\ndouble MotorGroup::get_target_position(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR_F);\n\tMotorGroup_index_check(PROS_ERR_F, index);\n\treturn motor_get_target_position(_ports[index]);\n}\n\nstd::vector<double> MotorGroup::get_target_position_all(void) const {\n\tstd::vector<double> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR_F, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_target_position(*it));\n\t}\n\treturn return_vector;\n}\n\ndouble MotorGroup::get_torque(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR_F);\n\tMotorGroup_index_check(PROS_ERR_F, index);\n\treturn motor_get_torque(_ports[index]);\n}\n\nstd::vector<double> MotorGroup::get_torque_all(void) const {\n\tstd::vector<double> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR_F, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_torque(*it));\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t MotorGroup::get_target_velocity(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_get_target_velocity(_ports[index]);\n}\n\nstd::vector<std::int32_t> MotorGroup::get_target_velocity_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_target_velocity(*it));\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t MotorGroup::get_voltage(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_get_voltage(_ports[index]);\n}\nstd::vector<std::int32_t> MotorGroup::get_voltage_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_voltage(*it));\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t MotorGroup::get_voltage_limit(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_get_voltage_limit(_ports[index]);\n}\n\nstd::vector<std::int32_t> MotorGroup::get_voltage_limit_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\tempty_MotorGroup_check_vector(PROS_ERR, return_vector);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\treturn_vector.push_back(motor_get_voltage_limit(*it));\n\t}\n\treturn return_vector;\n}\n\nstd::int8_t MotorGroup::get_port(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR_BYTE);\n\tMotorGroup_index_check(PROS_ERR_BYTE, index);\n\treturn _ports[index];\n}\n\nstd::vector<std::int8_t> MotorGroup::get_port_all(void) const {\n\treturn _ports;\n}\n\nstd::int32_t MotorGroup::tare_position(const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_tare_position(_ports[index]);\n}\n\nstd::int32_t MotorGroup::tare_position_all(void) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_tare_position(*it);\n\t}\n\treturn motor_tare_position(_ports[0]);\n}\n\nstd::int32_t MotorGroup::set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_set_brake_mode(_ports[index], mode);\n}\n\nstd::int32_t MotorGroup::set_brake_mode(const pros::v5::MotorBrake mode, const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\n\treturn motor_set_brake_mode(_ports[index], static_cast<pros::motor_brake_mode_e_t>(mode));\n}\n\nstd::int32_t MotorGroup::set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_set_brake_mode(*it, mode);\n\t}\n\treturn motor_set_brake_mode(_ports[0], mode);\n}\n\nstd::int32_t MotorGroup::set_brake_mode_all(const pros::v5::MotorBrake mode) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_set_brake_mode(*it, static_cast<pros::motor_brake_mode_e_t>(mode));\n\t}\n\treturn motor_set_brake_mode(_ports[0], static_cast<pros::motor_brake_mode_e_t>(mode));\n}\nstd::int32_t MotorGroup::set_current_limit(const std::int32_t limit, const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_set_current_limit(_ports[index], limit);\n}\nstd::int32_t MotorGroup::set_current_limit_all(const std::int32_t limit) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_set_current_limit(*it, limit);\n\t}\n\treturn motor_set_current_limit(_ports[0], limit);\n}\nstd::int32_t MotorGroup::set_encoder_units_all(const pros::motor_encoder_units_e_t units) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_set_encoder_units(*it, units);\n\t}\n\treturn motor_set_encoder_units(_ports[0], units);\n}\n\nstd::int32_t MotorGroup::set_encoder_units_all(const pros::v5::MotorUnits units) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_set_encoder_units(*it, static_cast<motor_encoder_units_e_t>(units));\n\t}\n\treturn motor_set_encoder_units(_ports[0], static_cast<motor_encoder_units_e_t>(units));\n}\nstd::int32_t MotorGroup::set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_set_encoder_units(_ports[index], units);\n}\n\nstd::int32_t MotorGroup::set_encoder_units(const pros::v5::MotorUnits units, const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_set_encoder_units(_ports[index], static_cast<motor_encoder_units_e_t>(units));\n}\n\nstd::int32_t MotorGroup::set_gearing(const motor_gearset_e_t gearset, const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_set_gearing(_ports[index], gearset);\n}\nstd::int32_t MotorGroup::set_gearing(std::vector<motor_gearset_e_t> gearsets) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (std::size_t i = 0; i < gearsets.size(); i++) {\n\t\tthis->set_gearing(gearsets[i], _ports[i]);\n\t}\n\tif (gearsets.size() != _ports.size()) {\n\t\terrno = E2BIG;\n\t}\n\treturn PROS_SUCCESS;\n}\n\nstd::int32_t MotorGroup::set_gearing(std::vector<MotorGears> gearsets) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (std::size_t i = 0; i < gearsets.size(); i++) {\n\t\tthis->set_gearing(gearsets[i], _ports[i]);\n\t}\n\tif (gearsets.size() != _ports.size()) {\n\t\terrno = E2BIG;\n\t}\n\treturn PROS_SUCCESS;\n}\nstd::int32_t MotorGroup::set_gearing(const pros::v5::MotorGear gearset, const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_set_gearing(_ports[index], (motor_gearset_e_t)gearset);\n}\n\nstd::int32_t MotorGroup::set_gearing_all(const motor_gearset_e_t gearset) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_set_gearing(*it, gearset);\n\t}\n\treturn motor_set_gearing(_ports[0], gearset);\n}\n\nstd::int32_t MotorGroup::set_gearing_all(const pros::v5::MotorGear gearset) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_set_gearing(*it, (motor_gearset_e_t)gearset);\n\t}\n\treturn motor_set_gearing(_ports[0], (motor_gearset_e_t)gearset);\n}\n\nstd::int32_t MotorGroup::set_zero_position(const double position, const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_set_zero_position(_ports[index], position);\n}\nstd::int32_t MotorGroup::set_zero_position_all(const double position) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_set_zero_position(*it, position);\n\t}\n\treturn motor_set_zero_position(_ports[0], position);\n}\nstd::int32_t MotorGroup::set_reversed(const bool reverse, const std::uint8_t index) {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\tstd::int8_t abs_port = std::abs(_ports[index]);\n\tif (reverse) {\n\t\t_ports[index] = -abs_port;\n\t} else {\n\t\t_ports[index] = abs_port;\n\t}\n\treturn PROS_SUCCESS;\n}\nstd::int32_t MotorGroup::set_reversed_all(const bool reverse) {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (auto it = _ports.begin(); it < _ports.end(); it++) {\n\t\tstd::int8_t abs_port = std::abs(_ports[*it]);\n\t\tif (reverse) {\n\t\t\t_ports[*it] = -abs_port;\n\t\t} else {\n\t\t\t_ports[*it] = abs_port;\n\t\t}\n\t}\n\treturn PROS_SUCCESS;\n}\nstd::int32_t MotorGroup::set_voltage_limit(const std::int32_t limit, const std::uint8_t index) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tMotorGroup_index_check(PROS_ERR, index);\n\treturn motor_set_voltage_limit(_ports[index], limit);\n}\nstd::int32_t MotorGroup::set_voltage_limit_all(const std::int32_t limit) const {\n\tempty_MotorGroup_check(PROS_ERR);\n\tfor (auto it = _ports.begin() + 1; it < _ports.end(); it++) {\n\t\tmotor_set_voltage_limit(*it, limit);\n\t}\n\treturn motor_set_voltage_limit(_ports[0], limit);\n}\n\nstd::int8_t MotorGroup::size() const {\n\treturn _ports.size();\n}\n\nvoid MotorGroup::operator+=(AbstractMotor& other) {\n\tauto ports = other.get_port_all();\n\tfor (auto it = ports.begin(); it < ports.end(); it++) {\n\t\tauto port = *it;\n\t\t_ports.push_back(port);\n\t}\n}\n\nvoid MotorGroup::append(AbstractMotor& other) {\n\t(*this) += other;\n}\n\nvoid MotorGroup::erase_port(std::int8_t port) {\n\tauto it = _ports.begin();\n\twhile (it < _ports.end()) {\n\t\tif (std::abs(*it) == std::abs(port)) {\n\t\t\t_ports.erase(it);\n\t\t} else {\n\t\t\tit++;\n\t\t}\n\t}\n}\n}  // namespace v5\n}  // namespace pros"
  },
  {
    "path": "src/devices/vdml_motors.c",
    "content": "/**\n * \\file devices/vdml_motors.c\n *\n * Contains functions for interacting with the V5 Motors.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n#include <math.h>\n#include <stdio.h>\n\n#include \"kapi.h\"\n#include \"pros/colors.h\"\n#include \"pros/motors.h\"\n#include \"pros/apix.h\"\n#include \"v5_api.h\"\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\n#define MOTOR_MOVE_RANGE 127\n#define MOTOR_VOLTAGE_RANGE 12000\n\n// Movement functions\n\nint32_t motor_move(int8_t port, int32_t voltage) {\n\tif (voltage > 127) {\n\t\tvoltage = 127;\n\t} else if (voltage < -127) {\n\t\tvoltage = -127;\n\t}\n\n\tif (port < 0) {\n\t\tvoltage = -voltage;\n\t}\n\n\tport = abs(port);\n\t// Remap the input voltage range to the motor voltage\n\t// scale to [-127, 127] -> [-12000, 12000]\n\tint32_t command = (((voltage + MOTOR_MOVE_RANGE) * (MOTOR_VOLTAGE_RANGE)) / (MOTOR_MOVE_RANGE));\n\tcommand -= MOTOR_VOLTAGE_RANGE;\n\treturn motor_move_voltage(port, command);\n}\n\nint32_t motor_brake(int8_t port) {\n\treturn motor_move_velocity(port, 0);\n}\n\nint32_t motor_move_absolute(int8_t port, double position, int32_t velocity) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_i(abs_port - 1, E_DEVICE_MOTOR);\n\tif (port < 0) position = -position;\n\tvexDeviceMotorAbsoluteTargetSet(device->device_info, position, velocity);\n\treturn_port(abs_port - 1, PROS_SUCCESS);\n}\n\nint32_t motor_move_relative(int8_t port, double position, int32_t velocity) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_i(abs_port - 1, E_DEVICE_MOTOR);\n\tif (port < 0) position = -position;\n\tvexDeviceMotorRelativeTargetSet(device->device_info, position, velocity);\n\treturn_port(abs_port - 1, PROS_SUCCESS);\n}\n\nint32_t motor_move_velocity(int8_t port, int32_t velocity) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_i(abs_port - 1, E_DEVICE_MOTOR);\n\tif (port < 0) velocity = -velocity;\n\tvexDeviceMotorVelocitySet(device->device_info, velocity);\n\treturn_port(abs_port - 1, PROS_SUCCESS);\n}\n\nint32_t motor_move_voltage(int8_t port, int32_t voltage) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_i(abs_port - 1, E_DEVICE_MOTOR);\n\tif (port < 0) voltage = -voltage;\n\tvexDeviceMotorVoltageSet(device->device_info, voltage);\n\treturn_port(abs_port - 1, PROS_SUCCESS);\n}\n\nint32_t motor_modify_profiled_velocity(int8_t port, int32_t velocity) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_i(abs_port - 1, E_DEVICE_MOTOR);\n\tif (port < 0) velocity = -velocity;\n\tvexDeviceMotorVelocityUpdate(device->device_info, velocity);\n\treturn_port(abs_port - 1, PROS_SUCCESS);\n}\n\ndouble motor_get_target_position(int8_t port) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_f(abs_port - 1, E_DEVICE_MOTOR);\n\tdouble rtn = vexDeviceMotorTargetGet(device->device_info);\n\tif (port < 0) rtn = -rtn;\n\treturn_port(abs_port - 1, rtn);\n}\n\nint32_t motor_get_target_velocity(int8_t port) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_i(abs_port - 1, E_DEVICE_MOTOR);\n\tint32_t rtn = vexDeviceMotorVelocityGet(device->device_info);\n\tif (port < 0) rtn = -rtn;\n\treturn_port(abs_port - 1, rtn);\n}\n\n// Telemetry functions\n\ndouble motor_get_actual_velocity(int8_t port) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_f(abs_port - 1, E_DEVICE_MOTOR);\n\tdouble rtn = vexDeviceMotorActualVelocityGet(device->device_info);\n\tif (port < 0) rtn = -rtn;\n\treturn_port(abs_port - 1, rtn);\n}\n\nint32_t motor_get_current_draw(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tint32_t rtn = vexDeviceMotorCurrentGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t motor_get_direction(int8_t port) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_i(abs_port - 1, E_DEVICE_MOTOR);\n\tint32_t rtn = vexDeviceMotorDirectionGet(device->device_info);\n\tif (port < 0) rtn = -rtn;\n\treturn_port(abs_port - 1, rtn);\n}\n\ndouble motor_get_efficiency(int8_t port) {\n\tport = abs(port);\n\tclaim_port_f(port - 1, E_DEVICE_MOTOR);\n\tdouble rtn = vexDeviceMotorEfficiencyGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t motor_is_over_current(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tint rtn = vexDeviceMotorCurrentLimitFlagGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t motor_is_over_temp(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tint rtn = vexDeviceMotorOverTempFlagGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nuint32_t motor_get_faults(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tuint32_t rtn = vexDeviceMotorFaultsGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nuint32_t motor_get_flags(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tuint32_t rtn = vexDeviceMotorFlagsGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t motor_get_raw_position(int8_t port, uint32_t* const timestamp) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_i(abs_port - 1, E_DEVICE_MOTOR);\n\tint32_t rtn = vexDeviceMotorPositionRawGet(device->device_info, timestamp);\n\tif (port < 0) rtn = -rtn;\n\treturn_port(abs_port - 1, rtn);\n}\n\ndouble motor_get_position(int8_t port) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_f(abs_port - 1, E_DEVICE_MOTOR);\n\tdouble rtn = vexDeviceMotorPositionGet(device->device_info);\n\tif (port < 0) rtn = -rtn;\n\treturn_port(abs_port - 1, rtn);\n}\n\ndouble motor_get_power(int8_t port) {\n\tport = abs(port);\n\tclaim_port_f(port - 1, E_DEVICE_MOTOR);\n\tdouble rtn = vexDeviceMotorPowerGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\ndouble motor_get_temperature(int8_t port) {\n\tport = abs(port);\n\tclaim_port_f(port - 1, E_DEVICE_MOTOR);\n\tdouble rtn = vexDeviceMotorTemperatureGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\ndouble motor_get_torque(int8_t port) {\n\tport = abs(port);\n\tclaim_port_f(port - 1, E_DEVICE_MOTOR);\n\tdouble rtn = vexDeviceMotorTorqueGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t motor_get_voltage(int8_t port) {\n\tuint8_t abs_port = abs(port);\n\tclaim_port_i(abs_port - 1, E_DEVICE_MOTOR);\n\tint32_t rtn = vexDeviceMotorVoltageGet(device->device_info);\n\tif (port < 0) rtn = -rtn;\n\treturn_port(abs_port - 1, rtn);\n}\n\n// Config functions\n\nint32_t motor_set_zero_position(int8_t port, const double position) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tvexDeviceMotorPositionSet(device->device_info, position);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t motor_tare_position(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tvexDeviceMotorPositionReset(device->device_info);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t motor_set_brake_mode(int8_t port, const motor_brake_mode_e_t mode) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tvexDeviceMotorBrakeModeSet(device->device_info, (V5MotorBrakeMode)mode);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t motor_set_current_limit(int8_t port, const int32_t limit) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tvexDeviceMotorCurrentLimitSet(device->device_info, limit);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t motor_set_encoder_units(int8_t port, const motor_encoder_units_e_t units) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tvexDeviceMotorEncoderUnitsSet(device->device_info, (V5MotorEncoderUnits)units);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t motor_set_gearing(int8_t port, const motor_gearset_e_t gearset) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tvexDeviceMotorGearingSet(device->device_info, (V5MotorGearset)gearset);\n  return_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t motor_set_reversed(int8_t port, const bool reverse) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tvexDeviceMotorReverseFlagSet(device->device_info, reverse);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t motor_set_voltage_limit(int8_t port, const int32_t limit) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tvexDeviceMotorVoltageLimitSet(device->device_info, limit);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nmotor_brake_mode_e_t motor_get_brake_mode(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tV5MotorBrakeMode rtn = vexDeviceMotorBrakeModeGet(device->device_info);\n\treturn_port(port - 1, (motor_brake_mode_e_t)rtn);\n}\n\nint32_t motor_get_current_limit(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tint32_t rtn = vexDeviceMotorCurrentLimitGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nmotor_encoder_units_e_t motor_get_encoder_units(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tV5MotorEncoderUnits rtn = vexDeviceMotorEncoderUnitsGet(device->device_info);\n\treturn_port(port - 1, (motor_encoder_units_e_t)rtn);\n}\n\nmotor_gearset_e_t motor_get_gearing(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tV5MotorGearset rtn = vexDeviceMotorGearingGet(device->device_info);\n\treturn_port(port - 1, (motor_gearset_e_t)rtn);\n}\n\nint32_t motor_is_reversed(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tint rtn = vexDeviceMotorReverseFlagGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t motor_get_voltage_limit(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tint32_t rtn = vexDeviceMotorVoltageLimitGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nmotor_type_e_t motor_get_type(int8_t port) {\n\tport = abs(port);\n\tclaim_port_i(port - 1, E_DEVICE_MOTOR);\n\tint32_t rtn = vexDeviceMotorTypeGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n"
  },
  {
    "path": "src/devices/vdml_motors.cpp",
    "content": "/**\n * \\file devices/vdml_motors.cpp\n *\n * Contains functions for interacting with the V5 Motors.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"kapi.h\"\n#include \"pros/motors.hpp\"\n#include \"vdml/vdml.h\"\n#include <cmath>\n\nnamespace pros {\ninline namespace v5 {\nusing namespace pros::c;\n\n\nMotor::Motor(const std::int8_t port, const pros::v5::MotorGears gearset, const pros::v5::MotorUnits encoder_units)\n    : Device(std::abs(port), DeviceType::motor), _port(port) {\n\tif (gearset != pros::v5::MotorGears::invalid) {\n\t\tset_gearing(gearset);\n\t}\n\tif (encoder_units != pros::v5::MotorEncoderUnits::invalid) {\n\t\tset_encoder_units(encoder_units);\n\t}\n}\n\nstd::int32_t Motor::move(std::int32_t voltage) const {\n\treturn motor_move(_port, voltage);\n\n}\n\nstd::int32_t Motor::move_absolute(const double position, const std::int32_t velocity) const {\n\treturn motor_move_absolute(_port, position, velocity);\n}\n\nstd::int32_t Motor::move_relative(const double position, const std::int32_t velocity) const {\n\treturn motor_move_relative(_port, position, velocity);\n}\n\nstd::int32_t Motor::move_velocity(const std::int32_t velocity) const {\n\treturn motor_move_velocity(_port, velocity);\n}\n\nstd::int32_t Motor::move_voltage(const std::int32_t voltage) const {\n\treturn motor_move_voltage(_port, voltage);\n}\n\nstd::int32_t Motor::brake(void) const {\n\treturn motor_brake(_port);\n}\n\nstd::int32_t Motor::modify_profiled_velocity(const std::int32_t velocity) const {\n\treturn motor_modify_profiled_velocity(_port, velocity);\n}\n\ndouble Motor::get_actual_velocity(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR_F;\n\t}\n\treturn motor_get_actual_velocity(_port);\n}\nstd::vector<double> Motor::get_actual_velocity_all(void) const {\n\tstd::vector<double> return_vector;\n\treturn_vector.push_back(motor_get_actual_velocity(_port));\n\treturn return_vector;\n}\n\npros::v5::MotorBrake Motor::get_brake_mode(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn pros::v5::MotorBrake::invalid;\n\t}\n\treturn static_cast<pros::v5::MotorBrake>(motor_get_brake_mode(_port));\n}\n\nstd::vector<pros::v5::MotorBrake> Motor::get_brake_mode_all() const {\n\tstd::vector<pros::v5::MotorBrake> return_vector;\n\treturn_vector.push_back(static_cast<pros::v5::MotorBrake>(motor_get_brake_mode(_port)));\n\treturn return_vector;\n}\n\nstd::int32_t Motor::get_current_draw(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_get_current_draw(_port);\n}\nstd::vector<std::int32_t> Motor::get_current_draw_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\treturn_vector.push_back(motor_get_current_draw(_port));\n\treturn return_vector;\n}\nstd::int32_t Motor::get_current_limit(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_get_current_limit(_port);\n}\nstd::vector<std::int32_t> Motor::get_current_limit_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\treturn_vector.push_back(motor_get_current_limit(_port));\n\treturn return_vector;\n}\n\nstd::int32_t Motor::is_over_current(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_is_over_current(_port);\n}\n\nstd::vector<std::int32_t> Motor::is_over_current_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\treturn_vector.push_back(motor_is_over_current(_port));\n\n\treturn return_vector;\n}\n\nstd::int32_t Motor::get_direction(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\tint ret = motor_get_direction(_port);\n\tret = _port >= 0 ? ret : ret * -1;\n\treturn ret;\n}\nstd::vector<std::int32_t> Motor::get_direction_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\tint ret = motor_get_direction(_port);\n\tret = _port >= 0 ? ret : ret * -1;\n\treturn_vector.push_back(ret);\n\treturn return_vector;\n}\n\ndouble Motor::get_efficiency(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR_F;\n\t}\n\treturn motor_get_efficiency(_port);\n}\nstd::vector<double> Motor::get_efficiency_all(void) const {\n\tstd::vector<double> return_vector;\n\treturn_vector.push_back(motor_get_efficiency(_port));\n\treturn return_vector;\n}\n\npros::v5::MotorUnits Motor::get_encoder_units(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn pros::v5::MotorUnits::invalid;\n\t}\n\treturn static_cast<pros::v5::MotorUnits>(motor_get_encoder_units(_port));\n}\n\nstd::vector<pros::v5::MotorUnits> Motor::get_encoder_units_all(void) const {\n\tstd::vector<pros::v5::MotorUnits> return_vector;\n\treturn_vector.push_back(static_cast<pros::v5::MotorUnits>(motor_get_encoder_units(_port)));\n\treturn return_vector;\n}\n\nstd::uint32_t Motor::get_faults(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_get_faults(_port);\n}\n\nstd::vector<std::uint32_t> Motor::get_faults_all(void) const {\n\tstd::vector<std::uint32_t> return_vector;\n\treturn_vector.push_back(motor_get_faults(_port));\n\treturn return_vector;\n}\n\nstd::uint32_t Motor::get_flags(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_get_flags(_port);\n}\n\nstd::vector<std::uint32_t> Motor::get_flags_all(void) const {\n\tstd::vector<std::uint32_t> return_vector;\n\treturn_vector.push_back(motor_get_flags(_port));\n\treturn return_vector;\n}\n\npros::v5::MotorGears Motor::get_gearing(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn pros::v5::MotorGears::invalid;\n\t}\n\treturn static_cast<pros::v5::MotorGears>(motor_get_gearing(_port));\n}\nstd::vector<pros::v5::MotorGears> Motor::get_gearing_all(void) const {\n\tstd::vector<pros::v5::MotorGears> return_vector;\n\treturn_vector.push_back(static_cast<pros::v5::MotorGears>(motor_get_gearing(_port)));\n\treturn return_vector;\n}\n\nstd::int32_t Motor::get_raw_position(std::uint32_t* const timestamp, std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_get_raw_position(_port, timestamp);\n}\n\nstd::vector<std::int32_t> Motor::get_raw_position_all(std::uint32_t* const timestamp) const {\n\tstd::vector<std::int32_t> return_vector;\n\treturn_vector.push_back(motor_get_raw_position(_port, timestamp));\n\treturn return_vector;\n}\n\nstd::int32_t Motor::is_over_temp(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_is_over_temp(_port);\n}\n\nstd::vector<std::int32_t> Motor::is_over_temp_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\treturn_vector.push_back(motor_is_over_temp(_port));\n\treturn return_vector;\n}\n\ndouble Motor::get_position(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR_F;\n\t}\n\treturn motor_get_position(_port);\n}\nstd::vector<double> Motor::get_position_all(void) const {\n\tstd::vector<double> return_vector;\n\treturn_vector.push_back(motor_get_position(_port));\n\treturn return_vector;\n}\n\ndouble Motor::get_power(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_get_power(_port);\n}\n\nstd::vector<double> Motor::get_power_all(void) const {\n\tstd::vector<double> return_vector;\n\treturn_vector.push_back(motor_get_power(_port));\n\treturn return_vector;\n}\n\nstd::int32_t Motor::is_reversed(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn _port < 0;\n}\nstd::vector<std::int32_t> Motor::is_reversed_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\treturn_vector.push_back(_port < 0);\n\treturn return_vector;\n}\n\npros::v5::MotorType Motor::get_type(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn pros::v5::MotorType::invalid;\n\t}\n\treturn static_cast<pros::v5::MotorType>(motor_get_type(_port));\n}\nstd::vector<pros::v5::MotorType> Motor::get_type_all(void) const {\n\tstd::vector<pros::v5::MotorType> return_vector;\n\treturn_vector.push_back(static_cast<pros::v5::MotorType>(motor_get_type(_port)));\n\treturn return_vector;\n}\n\ndouble Motor::get_temperature(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR_F;\n\t}\n\treturn motor_get_temperature(_port);\n}\n\nstd::vector<double> Motor::get_temperature_all(void) const {\n\tstd::vector<double> return_vector;\n\treturn_vector.push_back(motor_get_temperature(_port));\n\treturn return_vector;\n}\n\ndouble Motor::get_target_position(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_get_target_position(_port);\n}\n\nstd::vector<double> Motor::get_target_position_all(void) const {\n\tstd::vector<double> return_vector;\n\treturn_vector.push_back(motor_get_target_position(_port));\n\treturn return_vector;\n}\n\ndouble Motor::get_torque(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_get_torque(_port);\n}\nstd::vector<double> Motor::get_torque_all(void) const {\n\tstd::vector<double> return_vector;\n\treturn_vector.push_back(motor_get_torque(_port));\n\treturn return_vector;\n}\nstd::int32_t Motor::get_target_velocity(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_get_target_velocity(_port);\n}\nstd::vector<std::int32_t> Motor::get_target_velocity_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\treturn_vector.push_back(motor_get_target_velocity(_port));\n\treturn return_vector;\n}\n\nstd::int32_t Motor::get_voltage(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_get_voltage(_port);\n}\nstd::vector<std::int32_t> Motor::get_voltage_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\treturn_vector.push_back(motor_get_voltage(_port));\n\treturn return_vector;\n}\n\nstd::int32_t Motor::get_voltage_limit(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_get_voltage_limit(_port);\n}\n\nstd::vector<std::int32_t> Motor::get_voltage_limit_all(void) const {\n\tstd::vector<std::int32_t> return_vector;\n\treturn_vector.push_back(motor_get_voltage_limit(_port));\n\treturn return_vector;\n}\n\nstd::vector<Motor> Motor::get_all_devices() {\n\tstd::vector<Device> matching_devices {Device::get_all_devices(DeviceType::motor)};\n\tstd::vector<Motor> return_vector;\n\tfor (auto device : matching_devices) {\n\t\treturn_vector.push_back(device);\n\t}\n\treturn return_vector;\n}\n\nstd::int8_t Motor::get_port(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR_BYTE;\n\t}\n\treturn _port;\n}\n\nstd::vector<std::int8_t> Motor::get_port_all(void) const {\n\tstd::vector<std::int8_t> return_vector;\n\treturn_vector.push_back(_port);\n\treturn return_vector;\n}\n\nstd::int32_t Motor::tare_position(const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_tare_position(_port);\n}\n\nstd::int32_t Motor::set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_set_brake_mode(_port, mode);\n}\n\nstd::int32_t Motor::set_brake_mode(const pros::v5::MotorBrake mode, const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_set_brake_mode(_port, static_cast<pros::motor_brake_mode_e_t>(mode));\n}\n\nstd::int32_t Motor::set_current_limit(const std::int32_t limit, const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_set_current_limit(_port, limit);\n}\n\nstd::int32_t Motor::set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_set_encoder_units(_port, units);\n}\n\nstd::int32_t Motor::set_encoder_units(const pros::v5::MotorUnits units, const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_set_encoder_units(_port, static_cast<motor_encoder_units_e_t>(units));\n}\n\nstd::int32_t Motor::set_gearing(const motor_gearset_e_t gearset, const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_set_gearing(_port, gearset);\n}\n\nstd::int32_t Motor::set_gearing(const pros::v5::MotorGear gearset, const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_set_gearing(_port, static_cast<motor_gearset_e_t>(gearset));\n}\n\nstd::int32_t Motor::set_zero_position(const double position, const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_set_zero_position(_port, position);\n}\n\nstd::int32_t Motor::set_reversed(const bool reverse, const std::uint8_t index) {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\tstd::int8_t abs_port = std::abs(_port);\n\tif (reverse) {\n\t\t_port = -abs_port;\n\t} else {\n\t\t_port = abs_port;\n\n\t}\n\treturn PROS_SUCCESS;\n}\n\nstd::int32_t Motor::set_voltage_limit(const std::int32_t limit, const std::uint8_t index) const {\n\tif (index != 0) {\n\t\terrno = EOVERFLOW;\n\t\treturn PROS_ERR;\n\t}\n\treturn motor_set_voltage_limit(_port, limit);\n}\n\nstd::int32_t Motor::tare_position_all(void) const {\n\treturn motor_tare_position(_port);\n}\n\nstd::int32_t Motor::set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const {\n\treturn motor_set_brake_mode(_port, mode);\n}\n\nstd::int32_t Motor::set_brake_mode_all(const pros::v5::MotorBrake mode) const {\n\treturn motor_set_brake_mode(_port, static_cast<pros::motor_brake_mode_e_t>(mode));\n}\n\nstd::int32_t Motor::set_current_limit_all(const std::int32_t limit) const {\n\treturn motor_set_current_limit(_port, limit);\n}\n\nstd::int32_t Motor::set_encoder_units_all(const pros::motor_encoder_units_e_t units) const {\n\treturn motor_set_encoder_units(_port, units);\n}\n\nstd::int32_t Motor::set_encoder_units_all(const pros::v5::MotorUnits units) const {\n\treturn motor_set_encoder_units(_port, static_cast<motor_encoder_units_e_t>(units));\n}\n\nstd::int32_t Motor::set_gearing_all(const motor_gearset_e_t gearset) const {\n\treturn motor_set_gearing(_port, gearset);\n}\n\nstd::int32_t Motor::set_gearing_all(const pros::v5::MotorGear gearset) const {\n\treturn motor_set_gearing(_port, static_cast<motor_gearset_e_t>(gearset));\n}\n\nstd::int32_t Motor::set_zero_position_all(const double position) const {\n\treturn motor_set_zero_position(_port, position);\n}\n\nstd::int32_t Motor::set_reversed_all(const bool reverse) {\n\tstd::int8_t abs_port = std::abs(_port);\n\tif (reverse) {\n\t\t_port = -abs_port;\n\t} else {\n\t\t_port = abs_port;\n\t}\n\treturn PROS_SUCCESS;\n}\n\nstd::int32_t Motor::set_voltage_limit_all(const std::int32_t limit) const {\n\treturn motor_set_voltage_limit(_port, limit);\n}\n\nstd::int8_t Motor::size() const {\n\treturn 1;\n}\n\nstd::ostream& operator<<(std::ostream& os, pros::Motor& motor) {\n\tos << \"Motor [\";\n\tos << \"port: \" << motor.get_port();\n\tos << \", brake mode: \" << (int)motor.get_brake_mode();\n\tos << \", current draw: \" << motor.get_current_draw();\n\tos << \", current limit: \" << motor.get_current_limit();\n\tos << \", direction: \" << motor.get_direction();\n\tos << \", efficiency: \" << motor.get_efficiency();\n\tos << \", encoder units: \" << (int)motor.get_encoder_units();\n\tos << \", gearing: \" << (int)motor.get_gearing();\n\tos << \", over temp: \" << motor.is_over_temp();\n\tos << \", position: \" << motor.get_position();\n\tos << \", reversed: \" << motor.is_reversed();\n\tos << \", temperature: \" << motor.get_temperature();\n\tos << \", torque: \" << motor.get_torque();\n\tos << \", voltage: \" << motor.get_voltage();\n\tos << \"]\";\n\treturn os;\n}\n\n}  // namespace v5\nnamespace literals {\nconst pros::Motor operator\"\"_mtr(const unsigned long long int m) {\n\treturn pros::Motor(m);\n}\nconst pros::Motor operator\"\"_rmtr(const unsigned long long int m) {\n\treturn pros::Motor(-m);\n}\n}  // namespace literals\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/vdml_optical.c",
    "content": "/**\n * \\file devices/vdml_optical.c\n *\n * Contains functions for interacting with the VEX Optical sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n\n#include \"pros/optical.h\"\n#include \"v5_api.h\"\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\n// Source for these figures: \n// https://www.vexforum.com/t/v5-optical-sensor-refresh-rate/109632/9\n#define MIN_INTEGRATION_TIME 3 // ms\n#define MAX_INTEGRATION_TIME 712 // ms\n\ndouble optical_get_hue(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_OPTICAL);\n\tdouble rtn = vexDeviceOpticalHueGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\ndouble optical_get_saturation(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_OPTICAL);\n\tdouble rtn = vexDeviceOpticalSatGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\ndouble optical_get_brightness(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_OPTICAL);\n\tdouble rtn = vexDeviceOpticalBrightnessGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t optical_get_proximity(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_OPTICAL);\n\tdouble rtn = vexDeviceOpticalProximityGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t optical_set_led_pwm(uint8_t port, uint8_t value) {\n\tclaim_port_i(port - 1, E_DEVICE_OPTICAL);\n\tvexDeviceOpticalLedPwmSet(device->device_info, value);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t optical_get_led_pwm(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_OPTICAL);\n\tint32_t rtn = vexDeviceOpticalLedPwmGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\n#define RGB_ERR_INIT \\\n\t{ .red = PROS_ERR_F, .green = PROS_ERR_F, .blue = PROS_ERR_F, .brightness = PROS_ERR_F }\n\noptical_rgb_s_t optical_get_rgb(uint8_t port) {\n\toptical_rgb_s_t rtn = RGB_ERR_INIT;\n\tv5_smart_device_s_t* device;\n\tif (!claim_port_try(port - 1, E_DEVICE_OPTICAL)) {\n\t\treturn rtn;\n\t}\n\tdevice = registry_get_device(port - 1);\n\tV5_DeviceOpticalRgb rgb;\n\tvexDeviceOpticalRgbGet(device->device_info, &rgb);\n\trtn.red = rgb.red;\n\trtn.green = rgb.green;\n\trtn.blue = rgb.blue;\n\trtn.brightness = rgb.brightness;\n\treturn_port(port - 1, rtn);\n}\n\n#define RAW_ERR_INIT \\\n\t{ .clear = PROS_ERR, .red = PROS_ERR, .green = PROS_ERR, .blue = PROS_ERR }\n\noptical_raw_s_t optical_get_raw(uint8_t port) {\n\toptical_raw_s_t rtn = RAW_ERR_INIT;\n\tv5_smart_device_s_t* device;\n\tif (!claim_port_try(port - 1, E_DEVICE_OPTICAL)) {\n\t\treturn rtn;\n\t}\n\tdevice = registry_get_device(port - 1);\n\tV5_DeviceOpticalRaw rgb;\n\tvexDeviceOpticalRawGet(device->device_info, &rgb);\n\trtn.clear = rgb.clear;\n\trtn.red = rgb.red;\n\trtn.green = rgb.green;\n\trtn.blue = rgb.blue;\n\treturn_port(port - 1, rtn);\n}\n\noptical_direction_e_t optical_get_gesture(uint8_t port) {\n\tclaim_port(port - 1, E_DEVICE_OPTICAL, OPT_GESTURE_ERR);\n\toptical_direction_e_t rtn = vexDeviceOpticalGestureGet(device->device_info, NULL);\n\treturn_port(port - 1, rtn);\n}\n\n#define GESTURE_ERR_INIT                                                                                    \\\n\t{                                                                                                         \\\n\t\t.udata = OPT_GESTURE_ERR, .ddata = OPT_GESTURE_ERR, .ldata = OPT_GESTURE_ERR, .rdata = OPT_GESTURE_ERR, \\\n\t\t.type = OPT_GESTURE_ERR, .pad = OPT_GESTURE_ERR, .count = OPT_COUNT_ERR, .time = OPT_TIME_ERR           \\\n\t}\n\noptical_gesture_s_t optical_get_gesture_raw(uint8_t port) {\n\toptical_gesture_s_t rtn = GESTURE_ERR_INIT;\n\tv5_smart_device_s_t* device;\n\tif (!claim_port_try(port - 1, E_DEVICE_OPTICAL)) {\n\t\treturn rtn;\n\t}\n\tdevice = registry_get_device(port - 1);\n\tV5_DeviceOpticalGesture gesture;\n\tvexDeviceOpticalGestureGet(device->device_info, &gesture);\n\trtn.udata = gesture.udata;\n\trtn.ddata = gesture.ddata;\n\trtn.ldata = gesture.ldata;\n\trtn.rdata = gesture.rdata;\n\trtn.type = gesture.type;\n\trtn.pad = gesture.pad;\n\trtn.count = gesture.count;\n\trtn.time = gesture.time;\n\treturn_port(port - 1, rtn);\n}\n\nint32_t optical_enable_gesture(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_OPTICAL);\n\tvexDeviceOpticalGestureEnable(device->device_info);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t optical_disable_gesture(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_OPTICAL);\n\tvexDeviceOpticalGestureDisable(device->device_info);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\ndouble optical_get_integration_time(uint8_t port) {\n\tclaim_port_f(port - 1, E_DEVICE_OPTICAL);\n\tdouble rtv = vexDeviceOpticalIntegrationTimeGet(device->device_info);\n\treturn_port(port - 1, rtv);\n}\n\nint32_t optical_set_integration_time(uint8_t port, double time) {\n\tclaim_port_i(port - 1, E_DEVICE_OPTICAL);\n\t// going to set the time to minimum of 3 ms, 3 ms is possible but impractical.\n\ttime = time < MIN_INTEGRATION_TIME ? MIN_INTEGRATION_TIME : time;\n\t// also boundary limit max integration time too\n\ttime = time > MAX_INTEGRATION_TIME ? MAX_INTEGRATION_TIME : time;\n\n\tvexDeviceOpticalIntegrationTimeSet(device->device_info, time);\n\treturn_port(port - 1, PROS_SUCCESS);\n}"
  },
  {
    "path": "src/devices/vdml_optical.cpp",
    "content": "/**\n * \\file devices/vdml_optical.cpp\n *\n * Contains functions for interacting with the VEX Optical sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"pros/optical.h\"\n#include \"pros/optical.hpp\"\n#include \"vdml/vdml.h\"\n\nnamespace pros {\ninline namespace v5 {\nusing namespace pros::c;\n\nOptical::Optical(std::uint8_t port) : Device(port, DeviceType::optical) {}\n\nstd::vector<Optical> Optical::get_all_devices() {\n\tstd::vector<Device> matching_devices {Device::get_all_devices(DeviceType::optical)};\n\tstd::vector<Optical> return_vector;\n\tfor (auto device : matching_devices) {\n\t\treturn_vector.push_back(device);\n\t}\n\treturn return_vector;\n}\n\ndouble Optical::get_hue(){\n  return optical_get_hue(_port);\n}\n\ndouble Optical::get_saturation(){\n  return optical_get_saturation(_port);\n}\n\ndouble Optical::get_brightness(){\n  return optical_get_brightness(_port);\n}\n\nstd::int32_t Optical::get_proximity(){\n  return optical_get_proximity(_port);\n}\n\nstd::int32_t Optical::set_led_pwm(std::uint8_t value){\n  return optical_set_led_pwm(_port, value);\n}\n\nstd::int32_t Optical::get_led_pwm(){\n  return optical_get_led_pwm(_port);\n}\n\noptical_rgb_s_t Optical::get_rgb(){\n  return optical_get_rgb(_port);\n}\n\noptical_raw_s_t Optical::get_raw(){\n  return optical_get_raw(_port);\n}\n\noptical_direction_e_t Optical::get_gesture(){\n  return optical_get_gesture(_port);\n}\n\noptical_gesture_s_t Optical::get_gesture_raw(){\n  return optical_get_gesture_raw(_port);\n}\n\nstd::int32_t Optical::enable_gesture(){\n  return optical_enable_gesture(_port);\n}\n\nstd::int32_t Optical::disable_gesture(){\n  return optical_disable_gesture(_port);\n}\n\ndouble Optical::get_integration_time() {\n  return optical_get_integration_time(_port);\n}\n\nstd::int32_t Optical::set_integration_time(double time) {\n  return optical_set_integration_time(_port, time);\n}\n\nstd::ostream& operator<<(std::ostream& os, pros::Optical& optical) {\n  pros::c::optical_rgb_s_t rgb = optical.get_rgb(); \n  os << \"Optical [\";\n  os << \"port: \" << optical.get_port();\n  os << \", hue: \" << optical.get_hue();\n  os << \", saturation: \" << optical.get_saturation();\n  os << \", brightness: \" << optical.get_brightness();\n  os << \", proximity: \" << optical.get_proximity();\n  os << \", rgb: \" << \"{\" << rgb.red << \",\"<< rgb.green << \",\" << rgb.blue << \"}\"; \n  os << \"]\";\n  return os;\n}\n\nnamespace literals {\nconst pros::Optical operator\"\"_opt(const unsigned long long int o) {\n  return pros::Optical(o);\n}\n} //\n\n} // namespace v5\n} // namespace pros\n"
  },
  {
    "path": "src/devices/vdml_rotation.c",
    "content": "/**\n * \\file devices/vdml_rotation.c\n *\n * Contains functions for interacting with the VEX Rotation sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n\n#include \"pros/rotation.h\"\n#include \"v5_api.h\"\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\n#define ROTATION_RESET_TIMEOUT 1000\n\nint32_t rotation_reset(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_ROTATION);\n\tvexDeviceAbsEncReset(device->device_info);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t rotation_set_data_rate(uint8_t port, uint32_t rate) {\n\tclaim_port_i(port - 1, E_DEVICE_ROTATION);\n\n\t// rate is not less than 5ms, and rounded down to nearest increment of 5\n\tif (rate < ROTATION_MINIMUM_DATA_RATE) {\n\t\trate = ROTATION_MINIMUM_DATA_RATE;\n\t} else {\n\t\trate -= rate % ROTATION_MINIMUM_DATA_RATE;\n\t}\n\n\tvexDeviceAbsEncDataRateSet(device->device_info, rate);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t rotation_reset_position(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_ROTATION);\n\tvexDeviceAbsEncPositionSet(device->device_info, 0);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t rotation_set_position(uint8_t port, int32_t position) {\n\tclaim_port_i(port - 1, E_DEVICE_ROTATION);\n\tvexDeviceAbsEncPositionSet(device->device_info, position);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t rotation_get_position(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_ROTATION);\n\tint32_t rtn = vexDeviceAbsEncPositionGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t rotation_get_velocity(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_ROTATION);\n\tint32_t rtn = vexDeviceAbsEncVelocityGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t rotation_get_angle(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_ROTATION);\n\tint32_t rtn = vexDeviceAbsEncAngleGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t rotation_set_reversed(uint8_t port, bool value) {\n\tclaim_port_i(port - 1, E_DEVICE_ROTATION);\n\tvexDeviceAbsEncReverseFlagSet(device->device_info, value);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t rotation_init_reverse(uint8_t port, bool reverse_flag) {\n\tclaim_port_i(port - 1, E_DEVICE_ROTATION);\n    uint16_t timeoutCount = 0;\n    // releasing mutex so vexBackgrounProcessing can run without being blocked.\n    do {\n        port_mutex_give(port - 1);\n        task_delay(5);\n        timeoutCount += 5;\n        claim_port_i(port - 1, E_DEVICE_ROTATION);\n        if (timeoutCount >= ROTATION_RESET_TIMEOUT) {\n            port_mutex_give(port - 1);\n            errno = EAGAIN;\n            return PROS_ERR;\n        }\n        device = device; // suppressing compiler warning\n    } while(vexDeviceAbsEncStatusGet(device->device_info) == 0);\n    vexAbsEncReverseFlagSet(port - 1, reverse_flag);\n    return_port(port - 1, 1)\n}\n\nint32_t rotation_reverse(uint8_t port){\n\tclaim_port_i(port - 1, E_DEVICE_ROTATION);\n\tvexDeviceAbsEncReverseFlagSet(device->device_info, !vexDeviceAbsEncReverseFlagGet(device->device_info));\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t rotation_get_reversed(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_ROTATION);\n\tint32_t rtn = vexDeviceAbsEncReverseFlagGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}"
  },
  {
    "path": "src/devices/vdml_rotation.cpp",
    "content": "/**\n * \\file devices/vdml_rotation.cpp\n *\n * Contains functions for interacting with the VEX Rotation sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"pros/rotation.hpp\"\n#include \"vdml/vdml.h\"\n\nnamespace pros {\ninline namespace v5 {\n\nRotation::Rotation(const std::int8_t port) : Device(abs(port), DeviceType::rotation) {\n\tif (port < 0) {\n\t\tpros::c::rotation_set_reversed(abs(port), true);\n\t} else {\n\t\tpros::c::rotation_set_reversed(port, false);\n\t}\n}\n\nstd::int32_t Rotation::reset() {\n\treturn pros::c::rotation_reset(_port);\n}\n\nstd::int32_t Rotation::set_data_rate(std::uint32_t rate) const {\n\treturn pros::c::rotation_set_data_rate(_port, rate);\n}\n\nstd::int32_t Rotation::set_position(std::int32_t position) const {\n\treturn pros::c::rotation_set_position(_port, position);\n}\n\nstd::int32_t Rotation::reset_position(void) const {\n\treturn pros::c::rotation_reset_position(_port);\n}\n\nstd::vector<Rotation> Rotation::get_all_devices() {\n\tstd::vector<Device> matching_devices {Device::get_all_devices(DeviceType::rotation)};\n\tstd::vector<Rotation> return_vector;\n\tfor (auto device : matching_devices) {\n\t\treturn_vector.push_back(device);\n\t}\n\treturn return_vector;\n}\n\nstd::int32_t Rotation::get_position(void) const {\n\treturn pros::c::rotation_get_position(_port);\n}\n\nstd::int32_t Rotation::get_velocity(void) const {\n\treturn pros::c::rotation_get_velocity(_port);\n}\n\nstd::int32_t Rotation::get_angle(void) const {\n\treturn pros::c::rotation_get_angle(_port);\n}\n\nstd::int32_t Rotation::set_reversed(bool value) const {\n\treturn pros::c::rotation_set_reversed(_port, value);\n}\n\nstd::int32_t Rotation::reverse(void) const {\n\treturn pros::c::rotation_reverse(_port);\n}\n\nstd::int32_t Rotation::get_reversed(void) const {\n\treturn pros::c::rotation_get_reversed(_port);\n}\n\nstd::ostream& operator<<(std::ostream& os, const pros::Rotation& rotation) {\n\tos << \"Rotation [\";\n\tos << \"port: \" << rotation._port;\n\tos << \", position: \" << rotation.get_position();\n\tos << \", velocity: \" << rotation.get_velocity();\n\tos << \", angle: \" << rotation.get_angle();\n\tos << \", reversed: \" << rotation.get_reversed();\n\tos << \"]\";\n\treturn os;\n}\n\nnamespace literals {\nconst pros::Rotation operator\"\"_rot(const unsigned long long int r) {\n\treturn pros::Rotation(r);\n}\n}  // namespace literals\n\n}  // namespace v5\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/vdml_serial.c",
    "content": "/**\n * \\file devices/vdml_serial.c\n *\n * Contains functions for interacting with V5 Generic Serial devices.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n#include <math.h>\n#include <stdio.h>\n\n#include \"kapi.h\"\n#include \"pros/serial.h\"\n#include \"v5_api.h\"\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\n// Control function\n\nint32_t serial_enable(uint8_t port) {\n\t/**\n\t * claim_port_i(port - 1, E_DEVICE_SERIAL) is not used because it requires\n\t * the port to already be of the requested type in VEXos, which will not yet\n\t * be the case for generic serial as vexDeviceGenericSerialEnable is what\n\t * switches the port into the correct mode\n\t */\n\tif (!VALIDATE_PORT_NO(port - 1)) {\n\t\terrno = EINVAL;\n\t\treturn PROS_ERR;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\tif (!port_mutex_take(port - 1)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tvexDeviceGenericSerialEnable(device->device_info, 0);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t serial_set_baudrate(uint8_t port, int32_t baudrate) {\n\tclaim_port_i(port - 1, E_DEVICE_SERIAL);\n\tvexDeviceGenericSerialBaudrate(device->device_info, baudrate);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t serial_flush(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_SERIAL);\n\tvexDeviceGenericSerialFlush(device->device_info);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\n// Telemetry functions\n\nint32_t serial_get_read_avail(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_SERIAL);\n\tint32_t rtn = vexDeviceGenericSerialReceiveAvail(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t serial_get_write_free(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_SERIAL);\n\tint32_t rtn = vexDeviceGenericSerialWriteFree(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\n// Read functions\n\nint32_t serial_peek_byte(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_SERIAL);\n\tint32_t rtn = vexDeviceGenericSerialPeekChar(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t serial_read_byte(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_SERIAL);\n\tint32_t rtn = vexDeviceGenericSerialReadChar(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nint32_t serial_read(uint8_t port, uint8_t* buffer, int32_t length) {\n\tclaim_port_i(port - 1, E_DEVICE_SERIAL);\n\tint32_t rtn = vexDeviceGenericSerialReceive(device->device_info, buffer, length);\n\treturn_port(port - 1, rtn);\n}\n\n// Write functions\n\nint32_t serial_write_byte(uint8_t port, uint8_t buffer) {\n\tclaim_port_i(port - 1, E_DEVICE_SERIAL);\n\tint32_t rtn = vexDeviceGenericSerialWriteChar(device->device_info, buffer);\n\tif (rtn == -1) {\n\t\terrno = EIO;\n\t\treturn_port(port - 1, PROS_ERR);\n\t}\n\treturn_port(port - 1, rtn);\n}\n\nint32_t serial_write(uint8_t port, uint8_t* buffer, int32_t length) {\n\tclaim_port_i(port - 1, E_DEVICE_SERIAL);\n\tint32_t rtn = vexDeviceGenericSerialTransmit(device->device_info, buffer, length);\n\tif (rtn == -1) {\n\t\terrno = EIO;\n\t\treturn_port(port - 1, PROS_ERR);\n\t}\n\treturn_port(port - 1, rtn);\n}\n"
  },
  {
    "path": "src/devices/vdml_serial.cpp",
    "content": "/**\n * \\file devices/vdml_serial.cpp\n *\n * Contains functions for interacting with V5 Generic Serial devices.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"kapi.h\"\n#include \"pros/serial.hpp\"\n#include \"vdml/vdml.h\"\n\nnamespace pros {\nusing namespace pros::c;\n\nSerial::Serial(std::uint8_t port, std::int32_t baudrate) : Device(port, DeviceType::serial) {\n\tserial_enable(port);\n\tset_baudrate(baudrate);\n}\n\nSerial::Serial(std::uint8_t port) : Device(port, DeviceType::serial) {\n\tserial_enable(port);\n}\n\nstd::int32_t Serial::set_baudrate(std::int32_t baudrate) const {\n\treturn serial_set_baudrate(_port, baudrate);\n}\n\nstd::int32_t Serial::flush() const {\n\treturn serial_flush(_port);\n}\n\nstd::int32_t Serial::get_read_avail() const {\n\treturn serial_get_read_avail(_port);\n}\n\nstd::int32_t Serial::get_write_free() const {\n\treturn serial_get_write_free(_port);\n}\n\nstd::int32_t Serial::peek_byte() const {\n\treturn serial_peek_byte(_port);\n}\n\nstd::int32_t Serial::read_byte() const {\n\treturn serial_read_byte(_port);\n}\n\nstd::int32_t Serial::read(std::uint8_t* buffer, std::int32_t length) const {\n\treturn serial_read(_port, buffer, length);\n}\n\nstd::int32_t Serial::write_byte(std::uint8_t buffer) const {\n\treturn serial_write_byte(_port, buffer);\n}\n\nstd::int32_t Serial::write(std::uint8_t* buffer, std::int32_t length) const {\n\treturn serial_write(_port, buffer, length);\n}\n\nnamespace literals {\nconst pros::Serial operator\"\"_ser(const unsigned long long int m) {\n\treturn pros::Serial(m);\n}\n}  // namespace literals\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/vdml_usd.c",
    "content": "/**\n * \\file devices/usd.c\n *\n * Contains functions for interacting with the SD card.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"kapi.h\"\n#include \"v5_api.h\"\n\nint32_t usd_is_installed(void) {\n\treturn vexFileDriveStatus(0);\n}\nstatic const int FRESULTMAP[] = {0,       EIO,    EINVAL, EBUSY, ENOENT,  ENOENT, EINVAL, EACCES,  // FR_DENIED\n                                 EEXIST,  EINVAL, EROFS,  ENXIO, ENOBUFS, ENXIO,  EIO,    EACCES,  // FR_LOCKED\n                                 ENOBUFS, ENFILE, EINVAL};\n\nint32_t usd_list_files(const char* path, char* buffer, int32_t len) {\n\tFRESULT result =  vexFileDirectoryGet(path, buffer, len);\n\tif (result != F_OK) {\n\t\terrno = FRESULTMAP[result];\n\t\treturn PROS_ERR;\n\t}\n\treturn PROS_SUCCESS;\n}\n"
  },
  {
    "path": "src/devices/vdml_usd.cpp",
    "content": "/**\n * \\file devices/usd.cpp\n *\n * Contains functions for interacting with the SD card.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"kapi.h\"\n\nnamespace pros {\nnamespace usd {\nusing namespace pros::c;\n\nstd::int32_t is_installed(void) {\n\treturn usd_is_installed();\n}\n\nint32_t list_files(const char* path, char* buffer, int32_t len) {\n\treturn usd_list_files(path, buffer, len);\n}\n\n}  // namespace usd\n}  // namespace pros\n"
  },
  {
    "path": "src/devices/vdml_vision.c",
    "content": "/**\n * \\file devices/vdml_vision.c\n *\n * Contains functions for interacting with the V5 Vision Sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"kapi.h\"\n#include \"v5_api.h\"\n#include \"v5_apitypes.h\"\n#include \"vdml/registry.h\"\n#include \"vdml/vdml.h\"\n\ntypedef struct vision_data {\n\tvision_zero_e_t zero_point;\n} vision_data_s_t;\n\nstatic vision_zero_e_t get_zero_point(uint8_t port) {\n\treturn ((vision_data_s_t*)registry_get_device(port)->pad)->zero_point;\n}\n\nstatic void set_zero_point(uint8_t port, vision_zero_e_t zero_point) {\n\tvision_data_s_t* data = (vision_data_s_t*)registry_get_device(port)->pad;\n\tdata->zero_point = zero_point;\n}\n\nstatic void _vision_transform_coords(uint8_t port, vision_object_s_t* object_ptr) {\n\tswitch (get_zero_point(port)) {\n\t\tcase E_VISION_ZERO_CENTER:\n\t\t\tobject_ptr->left_coord -= VISION_FOV_WIDTH / 2;\n\t\t\tobject_ptr->top_coord = (VISION_FOV_HEIGHT / 2) - object_ptr->top_coord;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\tobject_ptr->x_middle_coord = object_ptr->left_coord + (object_ptr->width / 2);\n\tobject_ptr->y_middle_coord = object_ptr->top_coord - (object_ptr->height / 2);\n}\n\nint32_t vision_get_object_count(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\tint32_t rtn = vexDeviceVisionObjectCountGet(device->device_info);\n\treturn_port(port - 1, rtn);\n}\n\nvision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id) {\n\tvision_object_s_t rtn;\n\tv5_smart_device_s_t* device;\n\tif (!claim_port_try(port - 1, E_DEVICE_VISION)) {\n\t\trtn.signature = VISION_OBJECT_ERR_SIG;\n\t\treturn rtn;\n\t}\n\tdevice = registry_get_device(port - 1);\n\tif ((uint32_t)vexDeviceVisionObjectCountGet(device->device_info) <= size_id) {\n\t\terrno = EDOM;\n\t\trtn.signature = VISION_OBJECT_ERR_SIG;\n\t\tgoto leave;\n\t}\n\tif (vexDeviceVisionObjectGet(device->device_info, size_id, (V5_DeviceVisionObject*)&rtn) == 0) {\n\t\terrno = EAGAIN;\n\t\trtn.signature = VISION_OBJECT_ERR_SIG;\n\t\tgoto leave;\n\t}\n\t_vision_transform_coords(port - 1, &rtn);\n\nleave:\n\tport_mutex_give(port - 1);\n\treturn rtn;\n}\n\nvision_object_s_t _vision_get_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id) {\n\tvision_object_s_t rtn;\n\trtn.signature = VISION_OBJECT_ERR_SIG;\n\tv5_smart_device_s_t* device;\n\tuint8_t count = 0;\n\tint32_t object_count = 0;\n\n\tif (!claim_port_try(port - 1, E_DEVICE_VISION)) {\n\t\tgoto err_return_no_mutex;\n\t}\n\n\tdevice = registry_get_device(port - 1);\n\tobject_count = vexDeviceVisionObjectCountGet(device->device_info);\n\tif ((uint32_t)object_count <= size_id) {\n\t\terrno = EDOM;\n\t\tgoto err_return;\n\t}\n\n\tfor (uint8_t i = 0; i <= object_count; i++) {\n\t\tvision_object_s_t check;\n\t\tif (vexDeviceVisionObjectGet(device->device_info, i, (V5_DeviceVisionObject*)&check) == PROS_ERR) {\n\t\t\terrno = EAGAIN;\n\t\t\trtn = check;\n\t\t\tgoto err_return;\n\t\t}\n\t\tif (check.signature == sig_id) {\n\t\t\tif (count == size_id) {\n\t\t\t\trtn = check;\n\t\t\t\t_vision_transform_coords(port - 1, &rtn);\n\t\t\t\tport_mutex_give(port - 1);\n\t\t\t\treturn rtn;\n\t\t\t}\n\t\t\tcount++;\n\t\t}\n\t}\n\terrno = EDOM;  // we read through all the objects and none matched sig_id and size_id\n\nerr_return:\n\tport_mutex_give(port - 1);\nerr_return_no_mutex:\n\trtn.signature = VISION_OBJECT_ERR_SIG;\n\treturn rtn;\n}\n\nvision_object_s_t vision_get_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id) {\n\tif (sig_id > 7 || sig_id == 0) {\n\t\terrno = EINVAL;\n\t\tvision_object_s_t rtn;\n\t\trtn.signature = VISION_OBJECT_ERR_SIG;\n\t\treturn rtn;\n\t}\n\treturn _vision_get_by_sig(port, size_id, sig_id);\n}\n\nvision_object_s_t vision_get_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code) {\n\treturn _vision_get_by_sig(port, size_id, color_code);\n}\n\nint32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t object_count,\n                            vision_object_s_t* const object_arr) {\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\tfor (uint8_t i = 0; i < object_count; i++) {\n\t\tobject_arr[i].signature = VISION_OBJECT_ERR_SIG;\n\t}\n\tuint32_t c = vexDeviceVisionObjectCountGet(device->device_info);\n\tif (c <= size_id) {\n\t\tport_mutex_give(port - 1);\n\t\terrno = EDOM;\n\t\treturn PROS_ERR;\n\t} else if (c > object_count + size_id) {\n\t\tc = object_count + size_id;\n\t}\n\n\tfor (uint32_t i = size_id; i < c; i++) {\n\t\tif (!vexDeviceVisionObjectGet(device->device_info, i, (V5_DeviceVisionObject*)(object_arr + i))) {\n\t\t\terrno = EAGAIN;\n\t\t\tobject_arr[i].signature = VISION_OBJECT_ERR_SIG;\n\t\t\tbreak;\n\t\t}\n\t\t_vision_transform_coords(port - 1, &object_arr[i]);\n\t}\n\treturn_port(port - 1, c);\n}\n\nint32_t _vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id, const uint32_t object_count,\n                            vision_object_s_t* const object_arr) {\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\tfor (uint8_t i = 0; i < object_count; i++) {\n\t\tobject_arr[i].signature = VISION_OBJECT_ERR_SIG;\n\t}\n\tuint32_t c = vexDeviceVisionObjectCountGet(device->device_info);\n\tif (c <= size_id) {\n\t\terrno = EDOM;\n\t\tport_mutex_give(port - 1);\n\t\treturn PROS_ERR;\n\t}\n\tif (c > object_count) {\n\t\tc = object_count;\n\t}\n\n\tuint32_t j = 0;                    // track how many objects we've placed into object_arr\n\tuint32_t seen = 0;                 // track how many objects we've seen matching sig_id\n\tfor (uint8_t i = 0; i < c; i++) {  // loop through all objects on sensor\n\t\t// place i-th object on vision sensor on j-th position in object_arr\n\t\tif (!vexDeviceVisionObjectGet(device->device_info, i, (V5_DeviceVisionObject*)(object_arr + j))) {\n\t\t\terrno = EAGAIN;\n\t\t\tobject_arr[i].signature = VISION_OBJECT_ERR_SIG;\n\t\t\tgoto rtn;\n\t\t}\n\t\t// check if this (j-th) object matches sig_id\n\t\tif (object_arr[j].signature == sig_id) {\n\t\t\tseen++;\n\t\t\tif (seen >= size_id) {  // have we seen enough objects to start adding to object_arr?\n\t\t\t\t// if so, transform the coords and \"commit\" it by incrementing j\n\t\t\t\t_vision_transform_coords(port - 1, &object_arr[j]);\n\t\t\t\tj++;\n\t\t\t\tif (j == object_count) goto rtn;\n\t\t\t}\n\t\t}\n\t}\n\terrno = EDOM;  // read through all objects and couldn't find enough objects matching filter parameters\nrtn:\n\treturn_port(port - 1, j);\n}\n\nint32_t vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id, const uint32_t object_count,\n                           vision_object_s_t* const object_arr) {\n\tif (sig_id > 7 || sig_id == 0) {\n\t\terrno = EINVAL;\n\t\tfor (uint8_t i = 0; i < object_count; i++) {\n\t\t\tobject_arr[i].signature = VISION_OBJECT_ERR_SIG;\n\t\t}\n\t\treturn PROS_ERR;\n\t}\n\treturn _vision_read_by_sig(port, size_id, sig_id, object_count, object_arr);\n}\n\nint32_t vision_read_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code,\n                            const uint32_t object_count, vision_object_s_t* const object_arr) {\n\treturn _vision_read_by_sig(port, size_id, color_code, object_count, object_arr);\n}\n\nvision_signature_s_t vision_get_signature(uint8_t port, const uint8_t signature_id) {\n\tvision_signature_s_t sig;\n\tsig.id = VISION_OBJECT_ERR_SIG;\n\tif (signature_id > 7 || signature_id == 0) {\n\t\terrno = EINVAL;\n\t\treturn sig;\n\t}\n\tint32_t rtn = claim_port_try(port - 1, E_DEVICE_VISION);\n\tif (!rtn) {\n\t\treturn sig;\n\t}\n\tv5_smart_device_s_t* device = registry_get_device(port - 1);\n\trtn = vexDeviceVisionSignatureGet(device->device_info, signature_id, (V5_DeviceVisionSignature*)&sig);\n\tif (!rtn || !sig._pad[0]) {  // sig._pad[0] is flags, will be set to 1 if data is valid and signatures are sent\n\t\terrno = EAGAIN;\n\t\tsig.id = VISION_OBJECT_ERR_SIG;\n\t}\n\tport_mutex_give(port - 1);\n\treturn sig;\n}\n\nint32_t vision_set_signature(uint8_t port, const uint8_t signature_id, vision_signature_s_t* const signature_ptr) {\n\tif (signature_id > 7 || signature_id == 0) {\n\t\terrno = EINVAL;\n\t\treturn PROS_ERR;\n\t}\n\tsignature_ptr->id = signature_id;\n\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\tvexDeviceVisionSignatureSet(device->device_info, (V5_DeviceVisionSignature*)signature_ptr);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nvision_signature_s_t vision_signature_from_utility(const int32_t id, const int32_t u_min, const int32_t u_max,\n                                                   const int32_t u_mean, const int32_t v_min, const int32_t v_max,\n                                                   const int32_t v_mean, const float range, const int32_t type) {\n\tvision_signature_s_t sig = {0};\n\tsig.id = id;\n\tsig.range = range;\n\tsig.u_min = u_min;\n\tsig.u_max = u_max;\n\tsig.u_mean = u_mean;\n\tsig.v_min = v_min;\n\tsig.v_max = v_max;\n\tsig.v_mean = v_mean;\n\tsig.type = type;\n\treturn sig;\n}\n\nvision_color_code_t vision_create_color_code(uint8_t port, const uint32_t sig_id1, const uint32_t sig_id2,\n                                             const uint32_t sig_id3, const uint32_t sig_id4, const uint32_t sig_id5) {\n\tuint16_t id = 0;\n\tif (!sig_id1 || !sig_id2 || sig_id1 > 7 || sig_id2 > 7 || sig_id3 > 7 || sig_id4 > 7 || sig_id5 > 7) {\n\t\t// Need to at least have two signatures to make a color code, and they all\n\t\t// must be in the range [0-7]\n\t\terrno = EINVAL;\n\t\tid = VISION_OBJECT_ERR_SIG;\n\t\treturn id;\n\t}\n\n\tconst uint32_t sigs[5] = {sig_id1, sig_id2, sig_id3, sig_id4, sig_id5};\n\tfor (size_t i = 0; i < 5 && sigs[i]; i++) {\n\t\tregister const uint32_t sig_id = sigs[i];\n\t\tid = (id << 3) | sig_id;\n\n\t\tvision_signature_s_t stored_sig = vision_get_signature(port, sig_id);\n\t\tif (stored_sig.type != E_VISION_OBJECT_COLOR_CODE) {\n\t\t\tstored_sig.type = E_VISION_OBJECT_COLOR_CODE;\n\t\t\tvision_set_signature(port, sig_id, &stored_sig);\n\t\t}\n\t}\n\n\treturn id;\n}\n\nint32_t vision_set_led(uint8_t port, const int32_t rgb) {\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\tvexDeviceVisionLedModeSet(device->device_info, 1);\n\tV5_DeviceVisionRgb _rgb = {.red = COLOR2R(rgb), .blue = COLOR2B(rgb), .green = COLOR2G(rgb), .brightness = 255};\n\tvexDeviceVisionLedColorSet(device->device_info, _rgb);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t vision_clear_led(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\tvexDeviceVisionLedModeSet(device->device_info, 0);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t vision_set_exposure(uint8_t port, const uint8_t percent) {\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\t// This translation comes from VEX to match the brightness represented in vision utility\n\tvexDeviceVisionBrightnessSet(device->device_info, (((int)((percent * 100) + 50)) / 255));\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t vision_get_exposure(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\t// This translation comes from VEX to match the brightness represented in vision utility\n\tint32_t rtn = ((vexDeviceVisionBrightnessGet(device->device_info) * 255) + 50) / 100;\n\treturn_port(port - 1, rtn);\n}\n\nint32_t vision_set_auto_white_balance(uint8_t port, const uint8_t enable) {\n\tif (enable != 0 && enable != 1) {\n\t\terrno = EINVAL;\n\t\treturn PROS_ERR;\n\t}\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\tvexDeviceVisionWhiteBalanceModeSet(device->device_info, enable + 1);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t vision_set_white_balance(uint8_t port, const int32_t rgb) {\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\tvexDeviceVisionWhiteBalanceModeSet(device->device_info, 2);\n\tV5_DeviceVisionRgb _rgb = {.red = COLOR2R(rgb), .blue = COLOR2B(rgb), .green = COLOR2G(rgb), .brightness = 255};\n\tvexDeviceVisionWhiteBalanceSet(device->device_info, _rgb);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t vision_get_white_balance(uint8_t port) {\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\tV5_DeviceVisionRgb rgb = vexDeviceVisionWhiteBalanceGet(device->device_info);\n\treturn_port(port - 1, RGB2COLOR(rgb.red, rgb.green, rgb.blue));\n}\n\nint32_t vision_set_zero_point(uint8_t port, vision_zero_e_t zero_point) {\n\tif (!VALIDATE_PORT_NO(port - 1)) {\n\t\terrno = ENXIO;\n\t\treturn PROS_ERR;\n\t}\n\tif (registry_validate_binding(port - 1, E_DEVICE_VISION) != 0) {\n\t\terrno = ENODEV;\n\t\treturn PROS_ERR;\n\t}\n\tif (!port_mutex_take(port - 1)) {\n\t\terrno = EACCES;\n\t\treturn PROS_ERR;\n\t}\n\tset_zero_point(port - 1, zero_point);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t vision_set_wifi_mode(uint8_t port, const uint8_t enable) {\n\tclaim_port_i(port - 1, E_DEVICE_VISION);\n\tvexDeviceVisionWifiModeSet(device->device_info, !!enable);\n\treturn_port(port - 1, PROS_SUCCESS);\n}\n\nint32_t vision_print_signature(const vision_signature_s_t sig) {\n\tprintf(\"\\n\\npros::vision_signature_s_t SIG_%d = {\", sig.id);\n\tprintf(\"%d, {%d, %d, %d}, %f, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld};\\n\\n\", sig.id, sig._pad[0], sig._pad[1],\n\t       sig._pad[2], sig.range, sig.u_min, sig.u_max, sig.u_mean, sig.v_min, sig.v_max, sig.v_mean, sig.rgb, sig.type);\n\treturn 1;\n}\n"
  },
  {
    "path": "src/devices/vdml_vision.cpp",
    "content": "/**\n * \\file devices/vdml_vision.cpp\n *\n * Contains functions for interacting with the V5 Vision Sensor.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"kapi.h\"\n#include \"vdml/vdml.h\"\n\nnamespace pros {\ninline namespace v5 {\nusing namespace pros::c;\n\nVision::Vision(std::uint8_t port, vision_zero_e_t zero_point) : Device(port, DeviceType::vision) {\n\tvision_set_zero_point(port, zero_point);\n}\n\nstd::int32_t Vision::clear_led(void) const {\n\treturn vision_clear_led(_port);\n}\n\nvision_signature_s_t Vision::signature_from_utility(const std::int32_t id, const std::int32_t u_min,\n                                                    const std::int32_t u_max, const std::int32_t u_mean,\n                                                    const std::int32_t v_min, const std::int32_t v_max,\n                                                    const std::int32_t v_mean, const float range,\n                                                    const std::int32_t type) {\n\treturn c::vision_signature_from_utility(id, u_min, u_max, u_mean, v_min, v_max, v_mean, range, type);\n}\n\nvision_color_code_t Vision::create_color_code(const std::uint32_t sig_id1, const std::uint32_t sig_id2,\n                                              const std::uint32_t sig_id3, const std::uint32_t sig_id4,\n                                              const std::uint32_t sig_id5) const {\n\treturn vision_create_color_code(_port, sig_id1, sig_id2, sig_id3, sig_id4, sig_id5);\n}\n\nstd::vector<Vision> Vision::get_all_devices() {\n\n\tstd::vector<Device> matching_devices{Device::get_all_devices(DeviceType::vision)};\n\n\tstd::vector<Vision> return_vector;\n\tfor (auto device : matching_devices) {\n\t\treturn_vector.push_back(device);\n\t}\n\treturn return_vector;\n}\n\nvision_object_s_t Vision::get_by_size(const std::uint32_t size_id) const {\n\treturn vision_get_by_size(_port, size_id);\n}\n\nvision_object_s_t Vision::get_by_sig(const std::uint32_t size_id, const std::uint32_t sig_id) const {\n\treturn vision_get_by_sig(_port, size_id, sig_id);\n}\n\nvision_object_s_t Vision::get_by_code(const std::uint32_t size_id, const vision_color_code_t color_code) const {\n\treturn vision_get_by_code(_port, size_id, color_code);\n}\n\nint32_t Vision::get_exposure(void) const {\n\treturn vision_get_exposure(_port);\n}\n\nint32_t Vision::get_object_count(void) const {\n\treturn vision_get_object_count(_port);\n}\n\nstd::int32_t Vision::get_white_balance(void) const {\n\treturn vision_get_white_balance(_port);\n}\n\nint32_t Vision::read_by_size(const std::uint32_t size_id, const std::uint32_t object_count,\n                             vision_object_s_t* const object_arr) const {\n\treturn vision_read_by_size(_port, size_id, object_count, object_arr);\n}\n\nint32_t Vision::read_by_sig(const std::uint32_t size_id, const std::uint32_t sig_id, const std::uint32_t object_count,\n                            vision_object_s_t* const object_arr) const {\n\treturn vision_read_by_sig(_port, size_id, sig_id, object_count, object_arr);\n}\n\nint32_t Vision::read_by_code(const std::uint32_t size_id, const vision_color_code_t color_code,\n                             const std::uint32_t object_count, vision_object_s_t* const object_arr) const {\n\treturn vision_read_by_code(_port, size_id, color_code, object_count, object_arr);\n}\n\nvision_signature_s_t Vision::get_signature(const std::uint8_t signature_id) const {\n\treturn vision_get_signature(_port, signature_id);\n}\n\nstd::int32_t Vision::print_signature(const vision_signature_s_t sig) {\n\treturn vision_print_signature(sig);\n}\n\nstd::int32_t Vision::set_signature(const std::uint8_t signature_id, vision_signature_s_t* const signature_ptr) const {\n\treturn vision_set_signature(_port, signature_id, signature_ptr);\n}\n\nstd::int32_t Vision::set_auto_white_balance(const std::uint8_t enable) const {\n\treturn vision_set_auto_white_balance(_port, enable);\n}\n\nstd::int32_t Vision::set_exposure(const std::uint8_t exposure) const {\n\treturn vision_set_exposure(_port, exposure);\n}\n\nstd::int32_t Vision::set_led(const std::int32_t rgb) const {\n\treturn vision_set_led(_port, rgb);\n}\n\nstd::int32_t Vision::set_white_balance(const std::int32_t rgb) const {\n\treturn vision_set_white_balance(_port, rgb);\n}\n\nstd::int32_t Vision::set_zero_point(vision_zero_e_t zero_point) const {\n\treturn vision_set_zero_point(_port, zero_point);\n}\n\nstd::int32_t Vision::set_wifi_mode(const std::uint8_t enable) const {\n\treturn vision_set_wifi_mode(_port, enable);\n}\nVision Vision::get_vision() {\n\tstatic int curr_vision_port = 0;\n\tcurr_vision_port = curr_vision_port % 21;\n\tfor (int i = 0; i < 21; i++) {\n\t\tif (registry_get_device(curr_vision_port)->device_type == pros::c::E_DEVICE_VISION) {\n\t\t\tcurr_vision_port++;\n\t\t\treturn Vision(curr_vision_port);\n\t\t}\n\t\tcurr_vision_port++;\n\t\tcurr_vision_port = curr_vision_port % 21;\n\t}\n\terrno = ENODEV;\n\treturn Vision(PROS_ERR_BYTE);\n}\n\n}  // namespace v5\nnamespace literals {\nconst pros::Vision operator\"\"_vis(const unsigned long long int m) {\n\treturn Vision(m);\n}\n\n}  // namespace literals\n}  // namespace pros\n"
  },
  {
    "path": "src/main.cpp",
    "content": "#include \"main.h\"\n\n/**\n * A callback function for LLEMU's center button.\n *\n * When this callback is fired, it will toggle line 2 of the LCD text between\n * \"I was pressed!\" and nothing.\n */\nvoid on_center_button() {\n\tstatic bool pressed = false;\n\tpressed = !pressed;\n\tif (pressed) {\n\t\tpros::lcd::set_text(2, \"I was pressed!\");\n\t} else {\n\t\tpros::lcd::clear_line(2);\n\t}\n}\n\n/**\n * Runs initialization code. This occurs as soon as the program is started.\n *\n * All other competition modes are blocked by initialize; it is recommended\n * to keep execution time for this mode under a few seconds.\n */\nvoid initialize() {\n\tpros::lcd::initialize();\n\tpros::lcd::set_text(1, \"Hello PROS User!\");\n\n\tpros::lcd::register_btn1_cb(on_center_button);\n}\n\n/**\n * Runs while the robot is in the disabled state of Field Management System or\n * the VEX Competition Switch, following either autonomous or opcontrol. When\n * the robot is enabled, this task will exit.\n */\nvoid disabled() {}\n\n/**\n * Runs after initialize(), and before autonomous when connected to the Field\n * Management System or the VEX Competition Switch. This is intended for\n * competition-specific initialization routines, such as an autonomous selector\n * on the LCD.\n *\n * This task will exit when the robot is enabled and autonomous or opcontrol\n * starts.\n */\nvoid competition_initialize() {}\n\n/**\n * Runs the user autonomous code. This function will be started in its own task\n * with the default priority and stack size whenever the robot is enabled via\n * the Field Management System or the VEX Competition Switch in the autonomous\n * mode. Alternatively, this function may be called in initialize or opcontrol\n * for non-competition testing purposes.\n *\n * If the robot is disabled or communications is lost, the autonomous task\n * will be stopped. Re-enabling the robot will restart the task, not re-start it\n * from where it left off.\n */\nvoid autonomous() {}\n\n/**\n * Runs the operator control code. This function will be started in its own task\n * with the default priority and stack size whenever the robot is enabled via\n * the Field Management System or the VEX Competition Switch in the operator\n * control mode.\n *\n * If no competition control is connected, this function will run immediately\n * following initialize().\n *\n * If the robot is disabled or communications is lost, the\n * operator control task will be stopped. Re-enabling the robot will restart the\n * task, not resume it from where it left off.\n */\nvoid opcontrol() {\n\tpros::Controller master(pros::E_CONTROLLER_MASTER);\n\tpros::MotorGroup left_mg({1, -2, 3});    // Creates a motor group with forwards ports 1 & 3 and reversed port 2\n\tpros::MotorGroup right_mg({-4, 5, -6});  // Creates a motor group with forwards port 5 and reversed ports 4 & 6\n\n\n\twhile (true) {\n\t\tpros::lcd::print(0, \"%d %d %d\", (pros::lcd::read_buttons() & LCD_BTN_LEFT) >> 2,\n\t\t                 (pros::lcd::read_buttons() & LCD_BTN_CENTER) >> 1,\n\t\t                 (pros::lcd::read_buttons() & LCD_BTN_RIGHT) >> 0);  // Prints status of the emulated screen LCDs\n\n\t\t// Arcade control scheme\n\t\tint dir = master.get_analog(ANALOG_LEFT_Y);    // Gets amount forward/backward from left joystick\n\t\tint turn = master.get_analog(ANALOG_RIGHT_X);  // Gets the turn left/right from right joystick\n\t\tleft_mg.move(dir - turn);                      // Sets left motor voltage\n\t\tright_mg.move(dir + turn);                     // Sets right motor voltage\n\t\tpros::delay(20);                               // Run for 20 ms then update\n\t}\n}"
  },
  {
    "path": "src/rtos/LICENSE",
    "content": "The FreeRTOS kernel is released under the MIT open source license, the text of\nwhich is provided below.\n\nThis license covers the FreeRTOS kernel source files, which are located in the\n/FreeRTOS/Source directory of the official FreeRTOS kernel download.  It also\ncovers most of the source files in the demo application projects, which are\nlocated in the /FreeRTOS/Demo directory of the official FreeRTOS download.  The\ndemo projects may also include third party software that is not part of FreeRTOS\nand is licensed separately to FreeRTOS.  Examples of third party software\nincludes header files provided by chip or tools vendors, linker scripts,\nperipheral drivers, etc.  All the software in subdirectories of the /FreeRTOS\ndirectory is either open source or distributed with permission, and is free for\nuse.  For the avoidance of doubt, refer to the comments at the top of each\nsource file.\n\n\nLicense text:\n-------------\n\nCopyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n"
  },
  {
    "path": "src/rtos/README.md",
    "content": "## The FreeRTOS Kernel Library\n\n__Note: modifiying these files may break PROS or make PROS unstable__\n\n_This file serves as an introduction to how PROS uses FreeRTOS if you're just_\n_getting started with development of the PROS kernel. It also contains some_\n_notes from configuring FreeRTOS to work with the V5._\n\nPROS 3 uses FreeRTOS 9.0.0 to implement scheduling, queues, and lists - the \nbarebones of an operating system. In some respects, FreeRTOS could be thought of\nas a C library that we have ported to the V5. It of course does more significant\nwork that a typical application library.\nSince computer architectures are different and FreeRTOS aims to work with many\nembedded architectures, some work must be done to let FreeRTOS work with the \nhardware.\n\nFreeRTOS provides many demo projects and the developers recommend modifying one \nof the projects to suit the needs of the project. Since the V5 is Zynq-7000 board,\nwe're modifying the Cortex\\_A9\\_Zynq\\_ZC702 demo.\n\nYou should read some of FreeRTOS's documentation and/or take an equivalent of \nPurdue's CS250 (Computer Architecture) and CS354 (Operating Systems) for \nrequisite background knowledge. For more info about the Zynq/A9 port, see \nFreeRTOS's documentation on [Zynq](http://www.freertos.org/RTOS-Xilinx-Zynq.html) \nand the [A9](http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html).\n\n## Modifications to FreeRTOS\nWe've somewhat significantly refactored the FreeRTOS kernel so that any FreeRTOS\nfunctions used within PROS align with the PROS coding style. See refactor.tsv in\nthis directory.\n\nWe've removed the use of `int32_t` and `uint32_t` from any public facing\nAPI since we felt it unnecessary. Additionally, all variables pertaining to ticks\non the PROS internal or public facing APIs have become millisecond precision, and \nthe conversion done immediately upon entering the functiion.\n\n"
  },
  {
    "path": "src/rtos/heap_4.c",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n/*\n * A sample implementation of kmalloc() and kfree() that combines\n * (coalescences) adjacent memory blocks as they are freed, and in so doing\n * limits memory fragmentation.\n *\n * See heap_1.c, heap_2.c and heap_3.c for alternative implementations, and the\n * memory management pages of http://www.FreeRTOS.org for more information.\n */\n#include <stdlib.h>\n\n#include \"FreeRTOS.h\"\n#include \"task.h\"\n\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 )\n\t#error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0\n#endif\n\n/* Block sizes must not get too small. */\n#define heapMINIMUM_BLOCK_SIZE\t( ( size_t ) ( xHeapStructSize << 1 ) )\n\n/* Assumes 8bit bytes! */\n#define heapBITS_PER_BYTE\t\t( ( size_t ) 8 )\n\n/* Allocate the memory for the heap. */\n#if( configAPPLICATION_ALLOCATED_HEAP == 1 )\n\t/* The application writer has already defined the array used for the RTOS\n\theap - probably so it can be placed in a special segment or address. */\n\textern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];\n#else\n\tstatic uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];\n#endif /* configAPPLICATION_ALLOCATED_HEAP */\n\n/* Define the linked list structure.  This is used to link free blocks in order\nof their memory address. */\ntypedef struct A_BLOCK_LINK\n{\n\tstruct A_BLOCK_LINK *pxNextFreeBlock;\t/*<< The next free block in the list. */\n\tsize_t xBlockSize;\t\t\t\t\t\t/*<< The size of the free block. */\n} BlockLink_t;\n\n/*-----------------------------------------------------------*/\n\n/*\n * Inserts a block of memory that is being freed into the correct position in\n * the list of free memory blocks.  The block being freed will be merged with\n * the block in front it and/or the block behind it if the memory blocks are\n * adjacent to each other.\n */\nstatic void prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert );\n\n/*\n * Called automatically to setup the required heap structures the first time\n * kmalloc() is called.\n */\nstatic void prvHeapInit( void );\n\n/*-----------------------------------------------------------*/\n\n/* The size of the structure placed at the beginning of each allocated memory\nblock must by correctly byte aligned. */\nstatic const size_t xHeapStructSize\t= ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK );\n\n/* Create a couple of list links to mark the start and end of the list. */\nstatic BlockLink_t xStart, *pxEnd = NULL;\n\n/* Keeps track of the number of free bytes remaining, but says nothing about\nfragmentation. */\nstatic size_t xFreeBytesRemaining = 0U;\nstatic size_t xMinimumEverFreeBytesRemaining = 0U;\n\n/* Gets set to the top bit of an size_t type.  When this bit in the xBlockSize\nmember of an BlockLink_t structure is set then the block belongs to the\napplication.  When the bit is free the block is still part of the free heap\nspace. */\nstatic size_t xBlockAllocatedBit = 0;\n\n/*-----------------------------------------------------------*/\n\nvoid *kmalloc( size_t xWantedSize )\n{\nBlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink;\nvoid *pvReturn = NULL;\n\n\trtos_suspend_all();\n\t{\n\t\t/* If this is the first call to malloc then the heap will require\n\t\tinitialisation to setup the list of free blocks. */\n\t\tif( pxEnd == NULL )\n\t\t{\n\t\t\tprvHeapInit();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\t/* Check the requested block size is not so large that the top bit is\n\t\tset.  The top bit of the block size member of the BlockLink_t structure\n\t\tis used to determine who owns the block - the application or the\n\t\tkernel, so it must be free. */\n\t\tif( ( xWantedSize & xBlockAllocatedBit ) == 0 )\n\t\t{\n\t\t\t/* The wanted size is increased so it can contain a BlockLink_t\n\t\t\tstructure in addition to the requested amount of bytes. */\n\t\t\tif( xWantedSize > 0 )\n\t\t\t{\n\t\t\t\txWantedSize += xHeapStructSize;\n\n\t\t\t\t/* Ensure that blocks are always aligned to the required number\n\t\t\t\tof bytes. */\n\t\t\t\tif( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 )\n\t\t\t\t{\n\t\t\t\t\t/* Byte alignment required. */\n\t\t\t\t\txWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );\n\t\t\t\t\tconfigASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\n\t\t\tif( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )\n\t\t\t{\n\t\t\t\t/* Traverse the list from the start\t(lowest address) block until\n\t\t\t\tone\tof adequate size is found. */\n\t\t\t\tpxPreviousBlock = &xStart;\n\t\t\t\tpxBlock = xStart.pxNextFreeBlock;\n\t\t\t\twhile( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )\n\t\t\t\t{\n\t\t\t\t\tpxPreviousBlock = pxBlock;\n\t\t\t\t\tpxBlock = pxBlock->pxNextFreeBlock;\n\t\t\t\t}\n\n\t\t\t\t/* If the end marker was reached then a block of adequate size\n\t\t\t\twas\tnot found. */\n\t\t\t\tif( pxBlock != pxEnd )\n\t\t\t\t{\n\t\t\t\t\t/* Return the memory space pointed to - jumping over the\n\t\t\t\t\tBlockLink_t structure at its start. */\n\t\t\t\t\tpvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize );\n\n\t\t\t\t\t/* This block is being returned for use so must be taken out\n\t\t\t\t\tof the list of free blocks. */\n\t\t\t\t\tpxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;\n\n\t\t\t\t\t/* If the block is larger than required it can be split into\n\t\t\t\t\ttwo. */\n\t\t\t\t\tif( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* This block is to be split into two.  Create a new\n\t\t\t\t\t\tblock following the number of bytes requested. The void\n\t\t\t\t\t\tcast is used to prevent byte alignment warnings from the\n\t\t\t\t\t\tcompiler. */\n\t\t\t\t\t\tpxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );\n\t\t\t\t\t\tconfigASSERT( ( ( ( size_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 );\n\n\t\t\t\t\t\t/* Calculate the sizes of two blocks split from the\n\t\t\t\t\t\tsingle block. */\n\t\t\t\t\t\tpxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;\n\t\t\t\t\t\tpxBlock->xBlockSize = xWantedSize;\n\n\t\t\t\t\t\t/* Insert the new block into the list of free blocks. */\n\t\t\t\t\t\tprvInsertBlockIntoFreeList( pxNewBlockLink );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\n\t\t\t\t\txFreeBytesRemaining -= pxBlock->xBlockSize;\n\n\t\t\t\t\tif( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining )\n\t\t\t\t\t{\n\t\t\t\t\t\txMinimumEverFreeBytesRemaining = xFreeBytesRemaining;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\n\t\t\t\t\t/* The block is being returned - it is allocated and owned\n\t\t\t\t\tby the application and has no \"next\" block. */\n\t\t\t\t\tpxBlock->xBlockSize |= xBlockAllocatedBit;\n\t\t\t\t\tpxBlock->pxNextFreeBlock = NULL;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\ttraceMALLOC( pvReturn, xWantedSize );\n\t}\n\t( void ) rtos_resume_all();\n\n\t#if( configUSE_MALLOC_FAILED_HOOK == 1 )\n\t{\n\t\tif( pvReturn == NULL )\n\t\t{\n\t\t\textern void vApplicationMallocFailedHook( void );\n\t\t\tvApplicationMallocFailedHook();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\t#endif\n\n\tconfigASSERT( ( ( ( size_t ) pvReturn ) & ( size_t ) portBYTE_ALIGNMENT_MASK ) == 0 );\n\treturn pvReturn;\n}\n/*-----------------------------------------------------------*/\n\nvoid kfree( void *pv )\n{\nuint8_t *puc = ( uint8_t * ) pv;\nBlockLink_t *pxLink;\n\n\tif( pv != NULL )\n\t{\n\t\t/* The memory being freed will have an BlockLink_t structure immediately\n\t\tbefore it. */\n\t\tpuc -= xHeapStructSize;\n\n\t\t/* This casting is to keep the compiler from issuing warnings. */\n\t\tpxLink = ( void * ) puc;\n\n\t\t/* Check the block is actually allocated. */\n\t\tconfigASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 );\n\t\tconfigASSERT( pxLink->pxNextFreeBlock == NULL );\n\n\t\tif( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 )\n\t\t{\n\t\t\tif( pxLink->pxNextFreeBlock == NULL )\n\t\t\t{\n\t\t\t\t/* The block is being returned to the heap - it is no longer\n\t\t\t\tallocated. */\n\t\t\t\tpxLink->xBlockSize &= ~xBlockAllocatedBit;\n\n\t\t\t\trtos_suspend_all();\n\t\t\t\t{\n\t\t\t\t\t/* Add this block to the list of free blocks. */\n\t\t\t\t\txFreeBytesRemaining += pxLink->xBlockSize;\n\t\t\t\t\ttraceFREE( pv, pxLink->xBlockSize );\n\t\t\t\t\tprvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );\n\t\t\t\t}\n\t\t\t\t( void ) rtos_resume_all();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n}\n/*-----------------------------------------------------------*/\n\nsize_t xPortGetFreeHeapSize( void )\n{\n\treturn xFreeBytesRemaining;\n}\n/*-----------------------------------------------------------*/\n\nsize_t xPortGetMinimumEverFreeHeapSize( void )\n{\n\treturn xMinimumEverFreeBytesRemaining;\n}\n/*-----------------------------------------------------------*/\n\nvoid vPortInitialiseBlocks( void )\n{\n\t/* This just exists to keep the linker quiet. */\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvHeapInit( void )\n{\nBlockLink_t *pxFirstFreeBlock;\nuint8_t *pucAlignedHeap;\nsize_t uxAddress;\nsize_t xTotalHeapSize = configTOTAL_HEAP_SIZE;\n\n\t/* Ensure the heap starts on a correctly aligned boundary. */\n\tuxAddress = ( size_t ) ucHeap;\n\n\tif( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 )\n\t{\n\t\tuxAddress += ( portBYTE_ALIGNMENT - 1 );\n\t\tuxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK );\n\t\txTotalHeapSize -= uxAddress - ( size_t ) ucHeap;\n\t}\n\n\tpucAlignedHeap = ( uint8_t * ) uxAddress;\n\n\t/* xStart is used to hold a pointer to the first item in the list of free\n\tblocks.  The void cast is used to prevent compiler warnings. */\n\txStart.pxNextFreeBlock = ( void * ) pucAlignedHeap;\n\txStart.xBlockSize = ( size_t ) 0;\n\n\t/* pxEnd is used to mark the end of the list of free blocks and is inserted\n\tat the end of the heap space. */\n\tuxAddress = ( ( size_t ) pucAlignedHeap ) + xTotalHeapSize;\n\tuxAddress -= xHeapStructSize;\n\tuxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK );\n\tpxEnd = ( void * ) uxAddress;\n\tpxEnd->xBlockSize = 0;\n\tpxEnd->pxNextFreeBlock = NULL;\n\n\t/* To start with there is a single free block that is sized to take up the\n\tentire heap space, minus the space taken by pxEnd. */\n\tpxFirstFreeBlock = ( void * ) pucAlignedHeap;\n\tpxFirstFreeBlock->xBlockSize = uxAddress - ( size_t ) pxFirstFreeBlock;\n\tpxFirstFreeBlock->pxNextFreeBlock = pxEnd;\n\n\t/* Only one block exists - and it covers the entire usable heap space. */\n\txMinimumEverFreeBytesRemaining = pxFirstFreeBlock->xBlockSize;\n\txFreeBytesRemaining = pxFirstFreeBlock->xBlockSize;\n\n\t/* Work out the position of the top bit in a size_t variable. */\n\txBlockAllocatedBit = ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 );\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert )\n{\nBlockLink_t *pxIterator;\nuint8_t *puc;\n\n\t/* Iterate through the list until a block is found that has a higher address\n\tthan the block being inserted. */\n\tfor( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock )\n\t{\n\t\t/* Nothing to do here, just iterate to the right position. */\n\t}\n\n\t/* Do the block being inserted, and the block it is being inserted after\n\tmake a contiguous block of memory? */\n\tpuc = ( uint8_t * ) pxIterator;\n\tif( ( puc + pxIterator->xBlockSize ) == ( uint8_t * ) pxBlockToInsert )\n\t{\n\t\tpxIterator->xBlockSize += pxBlockToInsert->xBlockSize;\n\t\tpxBlockToInsert = pxIterator;\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\t/* Do the block being inserted, and the block it is being inserted before\n\tmake a contiguous block of memory? */\n\tpuc = ( uint8_t * ) pxBlockToInsert;\n\tif( ( puc + pxBlockToInsert->xBlockSize ) == ( uint8_t * ) pxIterator->pxNextFreeBlock )\n\t{\n\t\tif( pxIterator->pxNextFreeBlock != pxEnd )\n\t\t{\n\t\t\t/* Form one big block from the two blocks. */\n\t\t\tpxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize;\n\t\t\tpxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpxBlockToInsert->pxNextFreeBlock = pxEnd;\n\t\t}\n\t}\n\telse\n\t{\n\t\tpxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock;\n\t}\n\n\t/* If the block being inserted plugged a gab, so was merged with the block\n\tbefore and the block after, then it's pxNextFreeBlock pointer will have\n\talready been set, and should not be set here as that would make it point\n\tto itself. */\n\tif( pxIterator != pxBlockToInsert )\n\t{\n\t\tpxIterator->pxNextFreeBlock = pxBlockToInsert;\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n}\n"
  },
  {
    "path": "src/rtos/list.c",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n\n#include <stdlib.h>\n#include \"FreeRTOS.h\"\n#include \"list.h\"\n\n/*-----------------------------------------------------------\n * PUBLIC LIST API documented in list.h\n *----------------------------------------------------------*/\n\nvoid vListInitialise( List_t * const pxList )\n{\n\t/* The list structure contains a list item which is used to mark the\n\tend of the list.  To initialise the list the list end is inserted\n\tas the only list entry. */\n\tpxList->pxIndex = ( list_item_t * ) &( pxList->xListEnd );\t\t\t/*lint !e826 !e740 The mini list structure is used as the list end to save RAM.  This is checked and valid. */\n\n\t/* The list end value is the highest possible value in the list to\n\tensure it remains at the end of the list. */\n\tpxList->xListEnd.xItemValue = portMAX_DELAY;\n\n\t/* The list end next and previous pointers point to itself so we know\n\twhen the list is empty. */\n\tpxList->xListEnd.pxNext = ( list_item_t * ) &( pxList->xListEnd );\t/*lint !e826 !e740 The mini list structure is used as the list end to save RAM.  This is checked and valid. */\n\tpxList->xListEnd.pxPrevious = ( list_item_t * ) &( pxList->xListEnd );/*lint !e826 !e740 The mini list structure is used as the list end to save RAM.  This is checked and valid. */\n\n\tpxList->uxNumberOfItems = ( uint32_t ) 0U;\n\n\t/* Write known values into the list if\n\tconfigUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */\n\tlistSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );\n\tlistSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );\n}\n/*-----------------------------------------------------------*/\n\nvoid vListInitialiseItem( list_item_t * const pxItem )\n{\n\t/* Make sure the list item is not recorded as being on a list. */\n\tpxItem->pvContainer = NULL;\n\n\t/* Write known values into the list item if\n\tconfigUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */\n\tlistSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );\n\tlistSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );\n}\n/*-----------------------------------------------------------*/\n\nvoid vListInsertEnd( List_t * const pxList, list_item_t * const pxNewListItem )\n{\nlist_item_t * const pxIndex = pxList->pxIndex;\n\n\t/* Only effective when configASSERT() is also defined, these tests may catch\n\tthe list data structures being overwritten in memory.  They will not catch\n\tdata errors caused by incorrect configuration or use of FreeRTOS. */\n\tlistTEST_LIST_INTEGRITY( pxList );\n\tlistTEST_LIST_ITEM_INTEGRITY( pxNewListItem );\n\n\t/* Insert a new list item into pxList, but rather than sort the list,\n\tmakes the new list item the last item to be removed by a call to\n\tlistGET_OWNER_OF_NEXT_ENTRY(). */\n\tpxNewListItem->pxNext = pxIndex;\n\tpxNewListItem->pxPrevious = pxIndex->pxPrevious;\n\n\t/* Only used during decision coverage testing. */\n\tmtCOVERAGE_TEST_DELAY();\n\n\tpxIndex->pxPrevious->pxNext = pxNewListItem;\n\tpxIndex->pxPrevious = pxNewListItem;\n\n\t/* Remember which list the item is in. */\n\tpxNewListItem->pvContainer = ( void * ) pxList;\n\n\t( pxList->uxNumberOfItems )++;\n}\n/*-----------------------------------------------------------*/\n\nvoid vListInsert( List_t * const pxList, list_item_t * const pxNewListItem )\n{\nlist_item_t *pxIterator;\nconst uint32_t xValueOfInsertion = pxNewListItem->xItemValue;\n\n\t/* Only effective when configASSERT() is also defined, these tests may catch\n\tthe list data structures being overwritten in memory.  They will not catch\n\tdata errors caused by incorrect configuration or use of FreeRTOS. */\n\tlistTEST_LIST_INTEGRITY( pxList );\n\tlistTEST_LIST_ITEM_INTEGRITY( pxNewListItem );\n\n\t/* Insert the new list item into the list, sorted in xItemValue order.\n\n\tIf the list already contains a list item with the same item value then the\n\tnew list item should be placed after it.  This ensures that TCB's which are\n\tstored in ready lists (all of which have the same xItemValue value) get a\n\tshare of the CPU.  However, if the xItemValue is the same as the back marker\n\tthe iteration loop below will not end.  Therefore the value is checked\n\tfirst, and the algorithm slightly modified if necessary. */\n\tif( xValueOfInsertion == portMAX_DELAY )\n\t{\n\t\tpxIterator = pxList->xListEnd.pxPrevious;\n\t}\n\telse\n\t{\n\t\t/* *** NOTE ***********************************************************\n\t\tIf you find your application is crashing here then likely causes are\n\t\tlisted below.  In addition see http://www.freertos.org/FAQHelp.html for\n\t\tmore tips, and ensure configASSERT() is defined!\n\t\thttp://www.freertos.org/a00110.html#configASSERT\n\n\t\t\t1) Stack overflow -\n\t\t\t   see http://www.freertos.org/Stacks-and-stack-overflow-checking.html\n\t\t\t2) Incorrect interrupt priority assignment, especially on Cortex-M\n\t\t\t   parts where numerically high priority values denote low actual\n\t\t\t   interrupt priorities, which can seem counter intuitive.  See\n\t\t\t   http://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition\n\t\t\t   of configMAX_SYSCALL_INTERRUPT_PRIORITY on\n\t\t\t   http://www.freertos.org/a00110.html\n\t\t\t3) Calling an API function from within a critical section or when\n\t\t\t   the scheduler is suspended, or calling an API function that does\n\t\t\t   not end in \"FromISR\" from an interrupt.\n\t\t\t4) Using a queue or semaphore before it has been initialised or\n\t\t\t   before the scheduler has been started (are interrupts firing\n\t\t\t   before rtos_sched_start() has been called?).\n\t\t**********************************************************************/\n\n\t\tfor( pxIterator = ( list_item_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 The mini list structure is used as the list end to save RAM.  This is checked and valid. */\n\t\t{\n\t\t\t/* There is nothing to do here, just iterating to the wanted\n\t\t\tinsertion position. */\n\t\t}\n\t}\n\n\tpxNewListItem->pxNext = pxIterator->pxNext;\n\tpxNewListItem->pxNext->pxPrevious = pxNewListItem;\n\tpxNewListItem->pxPrevious = pxIterator;\n\tpxIterator->pxNext = pxNewListItem;\n\n\t/* Remember which list the item is in.  This allows fast removal of the\n\titem later. */\n\tpxNewListItem->pvContainer = ( void * ) pxList;\n\n\t( pxList->uxNumberOfItems )++;\n}\n/*-----------------------------------------------------------*/\n\nuint32_t uxListRemove( list_item_t * const pxItemToRemove )\n{\n/* The list item knows which list it is in.  Obtain the list from the list\nitem. */\nList_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer;\n\n\tpxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;\n\tpxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;\n\n\t/* Only used during decision coverage testing. */\n\tmtCOVERAGE_TEST_DELAY();\n\n\t/* Make sure the index is left pointing to a valid item. */\n\tif( pxList->pxIndex == pxItemToRemove )\n\t{\n\t\tpxList->pxIndex = pxItemToRemove->pxPrevious;\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\tpxItemToRemove->pvContainer = NULL;\n\t( pxList->uxNumberOfItems )--;\n\n\treturn pxList->uxNumberOfItems;\n}\n/*-----------------------------------------------------------*/\n\n"
  },
  {
    "path": "src/rtos/port.c",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n/* Standard includes. */\n#include <stdlib.h>\n\n/* Scheduler includes. */\n#include \"FreeRTOS.h\"\n#include \"task.h\"\n\n#ifndef configINTERRUPT_CONTROLLER_BASE_ADDRESS\n\t#error configINTERRUPT_CONTROLLER_BASE_ADDRESS must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\n#endif\n\n#ifndef configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET\n\t#error configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\n#endif\n\n#ifndef configUNIQUE_INTERRUPT_PRIORITIES\n\t#error configUNIQUE_INTERRUPT_PRIORITIES must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\n#endif\n\n#ifndef configSETUP_TICK_INTERRUPT\n\t#error configSETUP_TICK_INTERRUPT() must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\n#endif /* configSETUP_TICK_INTERRUPT */\n\n#ifndef configMAX_API_CALL_INTERRUPT_PRIORITY\n\t#error configMAX_API_CALL_INTERRUPT_PRIORITY must be defined.  See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html\n#endif\n\n#if configMAX_API_CALL_INTERRUPT_PRIORITY == 0\n\t#error configMAX_API_CALL_INTERRUPT_PRIORITY must not be set to 0\n#endif\n\n#if configMAX_API_CALL_INTERRUPT_PRIORITY > configUNIQUE_INTERRUPT_PRIORITIES\n\t#error configMAX_API_CALL_INTERRUPT_PRIORITY must be less than or equal to configUNIQUE_INTERRUPT_PRIORITIES as the lower the numeric priority value the higher the logical interrupt priority\n#endif\n\n#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\n\t/* Check the configuration. */\n\t#if( configMAX_PRIORITIES > 32 )\n\t\t#error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32.  It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.\n\t#endif\n#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\n\n/* In case security extensions are implemented. */\n#if configMAX_API_CALL_INTERRUPT_PRIORITY <= ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )\n\t#error configMAX_API_CALL_INTERRUPT_PRIORITY must be greater than ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )\n#endif\n\n/* Some vendor specific files default configCLEAR_TICK_INTERRUPT() in\nportmacro.h. */\n#ifndef configCLEAR_TICK_INTERRUPT\n\t#define configCLEAR_TICK_INTERRUPT()\n#endif\n\n/* A critical section is exited when the critical section nesting count reaches\nthis value. */\n#define portNO_CRITICAL_NESTING\t\t\t( ( uint32_t ) 0 )\n\n/* In all GICs 255 can be written to the priority mask register to unmask all\n(but the lowest) interrupt priority. */\n#define portUNMASK_VALUE\t\t\t\t( 0xFFUL )\n\n/* Tasks are not created with a floating point context, but can be given a\nfloating point context after they have been created.  A variable is stored as\npart of the tasks context that holds portNO_FLOATING_POINT_CONTEXT if the task\ndoes not have an FPU context, or any other value if the task does have an FPU\ncontext. */\n#define portNO_FLOATING_POINT_CONTEXT\t( ( task_stack_t ) 0 )\n\n/* Constants required to setup the initial task context. */\n#define portINITIAL_SPSR\t\t\t\t( ( task_stack_t ) 0x1f ) /* System mode, ARM mode, IRQ enabled FIQ enabled. */\n#define portTHUMB_MODE_BIT\t\t\t\t( ( task_stack_t ) 0x20 )\n#define portINTERRUPT_ENABLE_BIT\t\t( 0x80UL )\n#define portTHUMB_MODE_ADDRESS\t\t\t( 0x01UL )\n\n/* Used by portASSERT_IF_INTERRUPT_PRIORITY_INVALID() when ensuring the binary\npoint is zero. */\n#define portBINARY_POINT_BITS\t\t\t( ( uint8_t ) 0x03 )\n\n/* Masks all bits in the APSR other than the mode bits. */\n#define portAPSR_MODE_BITS_MASK\t\t\t( 0x1F )\n\n/* The value of the mode bits in the APSR when the CPU is executing in user\nmode. */\n#define portAPSR_USER_MODE\t\t\t\t( 0x10 )\n\n/* The critical section macros only mask interrupts up to an application\ndetermined priority level.  Sometimes it is necessary to turn interrupt off in\nthe CPU itself before modifying certain hardware registers. */\n#define portCPU_IRQ_DISABLE()\t\t\t\t\t\t\t\t\t\t\\\n\t__asm volatile ( \"CPSID i\" ::: \"memory\" );\t\t\t\t\t\t\\\n\t__asm volatile ( \"DSB\" );\t\t\t\t\t\t\t\t\t\t\\\n\t__asm volatile ( \"ISB\" );\n\n#define portCPU_IRQ_ENABLE()\t\t\t\t\t\t\t\t\t\t\\\n\t__asm volatile ( \"CPSIE i\" ::: \"memory\" );\t\t\t\t\t\t\\\n\t__asm volatile ( \"DSB\" );\t\t\t\t\t\t\t\t\t\t\\\n\t__asm volatile ( \"ISB\" );\n\n\n/* Macro to unmask all interrupt priorities. */\n#define portCLEAR_INTERRUPT_MASK()\t\t\t\t\t\t\t\t\t\\\n{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tportCPU_IRQ_DISABLE();\t\t\t\t\t\t\t\t\t\t\t\\\n\tportICCPMR_PRIORITY_MASK_REGISTER = portUNMASK_VALUE;\t\t\t\\\n\t__asm volatile (\t\"DSB\t\t\\n\"\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\"ISB\t\t\\n\" );\t\t\t\t\t\t\t\\\n\tportCPU_IRQ_ENABLE();\t\t\t\t\t\t\t\t\t\t\t\\\n}\n\n#define portINTERRUPT_PRIORITY_REGISTER_OFFSET\t\t0x400UL\n#define portMAX_8_BIT_VALUE\t\t\t\t\t\t\t( ( uint8_t ) 0xff )\n#define portBIT_0_SET\t\t\t\t\t\t\t\t( ( uint8_t ) 0x01 )\n\n/* Let the user override the pre-loading of the initial LR with the address of\nprvTaskExitError() in case it messes up unwinding of the stack in the\ndebugger. */\n#ifdef configTASK_RETURN_ADDRESS\n\t#define portTASK_RETURN_ADDRESS\tconfigTASK_RETURN_ADDRESS\n#else\n\t#define portTASK_RETURN_ADDRESS\tprvTaskExitError\n#endif\n\n/* The space on the stack required to hold the FPU registers.  This is 32 64-bit\nregisters, plus a 32-bit status register. */\n#define portFPU_REGISTER_WORDS\t( ( 32 * 2 ) + 1 )\n\n/*-----------------------------------------------------------*/\n\n/*\n * Starts the first task executing.  This function is necessarily written in\n * assembly code so is implemented in portASM.s.\n */\nextern void vPortRestoreTaskContext( void );\n\n/*\n * Used to catch tasks that attempt to return from their implementing function.\n */\nstatic void prvTaskExitError( void );\n\n/*\n * If the application provides an implementation of vApplicationIRQHandler(),\n * then it will get called directly without saving the FPU registers on\n * interrupt entry, and this weak implementation of\n * vApplicationFPUSafeIRQHandler() is just provided to remove linkage errors -\n * it should never actually get called so its implementation contains a\n * call to configASSERT() that will always fail.\n *\n * If the application provides its own implementation of\n * vApplicationFPUSafeIRQHandler() then the implementation of\n * vApplicationIRQHandler() provided in portASM.S will save the FPU registers\n * before calling it.\n *\n * Therefore, if the application writer wants FPU registers to be saved on\n * interrupt entry their IRQ handler must be called\n * vApplicationFPUSafeIRQHandler(), and if the application writer does not want\n * FPU registers to be saved on interrupt entry their IRQ handler must be\n * called vApplicationIRQHandler().\n */\nvoid vApplicationFPUSafeIRQHandler( uint32_t ulICCIAR ) __attribute__((weak) );\n\n/*-----------------------------------------------------------*/\n\n/* A variable is used to keep track of the critical section nesting.  This\nvariable has to be stored as part of the task context and must be initialised to\na non zero value to ensure interrupts don't inadvertently become unmasked before\nthe scheduler starts.  As it is stored as part of the task context it will\nautomatically be set to 0 when the first task is started. */\nvolatile uint32_t ulCriticalNesting = 9999UL;\n\n/* Saved as part of the task context.  If ulPortTaskHasFPUContext is non-zero then\na floating point context must be saved and restored for the task. */\nvolatile uint32_t ulPortTaskHasFPUContext = pdFALSE;\n\n/* Set to 1 to pend a context switch from an ISR. */\nvolatile uint32_t ulPortYieldRequired = pdFALSE;\n\n/* Counts the interrupt nesting depth.  A context switch is only performed if\nif the nesting depth is 0. */\nvolatile uint32_t ulPortInterruptNesting = 0UL;\n\n/* Used in the asm file. */\n__attribute__(( used )) const uint32_t ulICCIAR = portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS;\n__attribute__(( used )) const uint32_t ulICCEOIR = portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS;\n__attribute__(( used )) const uint32_t ulICCPMR\t= portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS;\n__attribute__(( used )) const uint32_t ulMaxAPIPriorityMask = ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\n\n/*-----------------------------------------------------------*/\n\nvoid task_clean_up() {\n\t// TODO: Make this a kernel debugging statement\n\t// vexDisplayString(1, \"Reaping dying task: %s\", task_get_name(NULL));\n\ttask_delete(NULL);\n}\n\n/*\n * See header file for description.\n */\ntask_stack_t *pxPortInitialiseStack( task_stack_t *pxTopOfStack, task_fn_t pxCode, void *pvParameters )\n{\n\t/* Setup the initial stack of the task.  The stack is set exactly as\n\texpected by the portRESTORE_CONTEXT() macro.\n\n\tThe fist real value on the stack is the status register, which is set for\n\tsystem mode, with interrupts enabled.  A few NULLs are added first to ensure\n\tGDB does not try decoding a non-existent return address. */\n\t*pxTopOfStack = ( task_stack_t ) NULL;\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) NULL;\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) NULL;\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) portINITIAL_SPSR;\n\n\tif( ( ( uint32_t ) pxCode & portTHUMB_MODE_ADDRESS ) != 0x00UL )\n\t{\n\t\t/* The task will start in THUMB mode. */\n\t\t*pxTopOfStack |= portTHUMB_MODE_BIT;\n\t}\n\n\tpxTopOfStack--;\n\n\t/* Next the return address, which in this case is the start of the task. */\n\textern void task_fn_wrapper(task_fn_t fn, void* args);\n\t*pxTopOfStack = ( task_stack_t ) task_fn_wrapper;\n\tpxTopOfStack--;\n\n\t/* Next all the registers other than the stack pointer. */\n\t*pxTopOfStack = ( task_stack_t ) task_clean_up;\t/* R14 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) 0x12121212;\t/* R12 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) 0x11111111;\t/* R11 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) 0x10101010;\t/* R10 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) 0x09090909;\t/* R9 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) 0x08080808;\t/* R8 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) 0x07070707;\t/* R7 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) 0x06060606;\t/* R6 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) 0x05050505;\t/* R5 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) 0x04040404;\t/* R4 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) 0x03030303;\t/* R3 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) 0x02020202;\t/* R2 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) pvParameters;\t/* R1 */\n\tpxTopOfStack--;\n\t*pxTopOfStack = ( task_stack_t ) pxCode; /* R0 */\n\tpxTopOfStack--;\n\n\t/* The task will start with a critical nesting count of 0 as interrupts are\n\tenabled. */\n\t*pxTopOfStack = portNO_CRITICAL_NESTING;\n\n\t#if( configUSE_TASK_FPU_SUPPORT == 1 )\n\t{\n\t\t/* The task will start without a floating point context.  A task that\n\t\tuses the floating point hardware must call vPortTaskUsesFPU() before\n\t\texecuting any floating point instructions. */\n\t\tpxTopOfStack--;\n\t\t*pxTopOfStack = portNO_FLOATING_POINT_CONTEXT;\n\t}\n\t#elif( configUSE_TASK_FPU_SUPPORT == 2 )\n\t{\n\t\t/* The task will start with a floating point context.  Leave enough\n\t\tspace for the registers - and ensure they are initialised to 0. */\n\t\tpxTopOfStack -= portFPU_REGISTER_WORDS;\n\t\tmemset( pxTopOfStack, 0x00, portFPU_REGISTER_WORDS * sizeof( task_stack_t ) );\n\n\t\tpxTopOfStack--;\n\t\t*pxTopOfStack = pdTRUE;\n\t\tulPortTaskHasFPUContext = pdTRUE;\n\t}\n\t#else\n\t{\n\t\t#error Invalid configUSE_TASK_FPU_SUPPORT setting - configUSE_TASK_FPU_SUPPORT must be set to 1, 2, or left undefined.\n\t}\n\t#endif\n\n\treturn pxTopOfStack;\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvTaskExitError( void )\n{\n\t/* A function that implements a task must not exit or attempt to return to\n\tits caller as there is nothing to return to.  If a task wants to exit it\n\tshould instead call task_delete( NULL ).\n\n\tArtificially force an assert() to be triggered if configASSERT() is\n\tdefined, then stop here so application writers can catch the error. */\n\tconfigASSERT( ulPortInterruptNesting == ~0UL );\n\tportDISABLE_INTERRUPTS();\n\tfor( ;; );\n}\n/*-----------------------------------------------------------*/\n\nint32_t xPortStartScheduler( void )\n{\nuint32_t ulAPSR;\n\n\t#if( configASSERT_DEFINED == 1 )\n\t{\n\t\tvolatile uint32_t ulOriginalPriority;\n\t\tvolatile uint8_t * const pucFirstUserPriorityRegister = ( volatile uint8_t * const ) ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + portINTERRUPT_PRIORITY_REGISTER_OFFSET );\n\t\tvolatile uint8_t ucMaxPriorityValue;\n\n\t\t/* Determine how many priority bits are implemented in the GIC.\n\n\t\tSave the interrupt priority value that is about to be clobbered. */\n\t\tulOriginalPriority = *pucFirstUserPriorityRegister;\n\n\t\t/* Determine the number of priority bits available.  First write to\n\t\tall possible bits. */\n\t\t*pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE;\n\n\t\t/* Read the value back to see how many bits stuck. */\n\t\tucMaxPriorityValue = *pucFirstUserPriorityRegister;\n\n\t\t/* Shift to the least significant bits. */\n\t\twhile( ( ucMaxPriorityValue & portBIT_0_SET ) != portBIT_0_SET )\n\t\t{\n\t\t\tucMaxPriorityValue >>= ( uint8_t ) 0x01;\n\t\t}\n\n\t\t/* Sanity check configUNIQUE_INTERRUPT_PRIORITIES matches the read\n\t\tvalue. */\n\t\tconfigASSERT( ucMaxPriorityValue == portLOWEST_INTERRUPT_PRIORITY );\n\n\t\t/* Restore the clobbered interrupt priority register to its original\n\t\tvalue. */\n\t\t*pucFirstUserPriorityRegister = ulOriginalPriority;\n\t}\n\t#endif /* conifgASSERT_DEFINED */\n\n\n\t/* Only continue if the CPU is not in User mode.  The CPU must be in a\n\tPrivileged mode for the scheduler to start. */\n\t__asm volatile ( \"MRS %0, APSR\" : \"=r\" ( ulAPSR ) :: \"memory\" );\n\tulAPSR &= portAPSR_MODE_BITS_MASK;\n\tconfigASSERT( ulAPSR != portAPSR_USER_MODE );\n\n\tif( ulAPSR != portAPSR_USER_MODE )\n\t{\n\t\t/* Only continue if the binary point value is set to its lowest possible\n\t\tsetting.  See the comments in vPortValidateInterruptPriority() below for\n\t\tmore information. */\n\t\tconfigASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );\n\n\t\tif( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE )\n\t\t{\n\t\t\t/* Interrupts are turned off in the CPU itself to ensure tick does\n\t\t\tnot execute\twhile the scheduler is being started.  Interrupts are\n\t\t\tautomatically turned back on in the CPU when the first task starts\n\t\t\texecuting. */\n\t\t\tportCPU_IRQ_DISABLE();\n\n\t\t\t/* Start the timer that generates the tick ISR. */\n\t\t\tconfigSETUP_TICK_INTERRUPT();\n\n\t\t\t/* Start the first task executing. */\n\t\t\tvPortRestoreTaskContext();\n\t\t}\n\t}\n\n\t/* Will only get here if rtos_sched_start() was called with the CPU in\n\ta non-privileged mode or the binary point register was not set to its lowest\n\tpossible value.  prvTaskExitError() is referenced to prevent a compiler\n\twarning about it being defined but not referenced in the case that the user\n\tdefines their own exit address. */\n\t( void ) prvTaskExitError;\n\treturn 0;\n}\n/*-----------------------------------------------------------*/\n\nvoid vPortEndScheduler( void )\n{\n\t/* Not implemented in ports where there is nothing to return to.\n\tArtificially force an assert. */\n\tconfigASSERT( ulCriticalNesting == 1000UL );\n}\n/*-----------------------------------------------------------*/\n\nvoid vPortEnterCritical( void )\n{\n\t/* Mask interrupts up to the max syscall interrupt priority. */\n\tulPortSetInterruptMask();\n\n\t/* Now interrupts are disabled ulCriticalNesting can be accessed\n\tdirectly.  Increment ulCriticalNesting to keep a count of how many times\n\tportENTER_CRITICAL() has been called. */\n\tulCriticalNesting++;\n\n\t/* This is not the interrupt safe version of the enter critical function so\n\tassert() if it is being called from an interrupt context.  Only API\n\tfunctions that end in \"FromISR\" can be used in an interrupt.  Only assert if\n\tthe critical nesting count is 1 to protect against recursive calls if the\n\tassert function also uses a critical section. */\n\tif( ulCriticalNesting == 1 )\n\t{\n\t\tconfigASSERT( ulPortInterruptNesting == 0 );\n\t}\n}\n/*-----------------------------------------------------------*/\n\nvoid vPortExitCritical( void )\n{\n\tif( ulCriticalNesting > portNO_CRITICAL_NESTING )\n\t{\n\t\t/* Decrement the nesting count as the critical section is being\n\t\texited. */\n\t\tulCriticalNesting--;\n\n\t\t/* If the nesting level has reached zero then all interrupt\n\t\tpriorities must be re-enabled. */\n\t\tif( ulCriticalNesting == portNO_CRITICAL_NESTING )\n\t\t{\n\t\t\t/* Critical nesting has reached zero so all interrupt priorities\n\t\t\tshould be unmasked. */\n\t\t\tportCLEAR_INTERRUPT_MASK();\n\t\t}\n\t}\n}\n/*-----------------------------------------------------------*/\n\nvoid FreeRTOS_Tick_Handler( void )\n{\n\t/* Set interrupt mask before altering scheduler structures.   The tick\n\thandler runs at the lowest priority, so interrupts cannot already be masked,\n\tso there is no need to save and restore the current mask value.  It is\n\tnecessary to turn off interrupts in the CPU itself while the ICCPMR is being\n\tupdated. */\n\tportCPU_IRQ_DISABLE();\n\tportICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\n\t__asm volatile (\t\"dsb\t\t\\n\"\n\t\t\t\t\t\t\"isb\t\t\\n\" ::: \"memory\" );\n\tportCPU_IRQ_ENABLE();\n\n\t/* Increment the RTOS tick. */\n\tif( xTaskIncrementTick() != pdFALSE )\n\t{\n\t\tulPortYieldRequired = pdTRUE;\n\t}\n\n\t/* Ensure all interrupt priorities are active again. */\n\tportCLEAR_INTERRUPT_MASK();\n\tconfigCLEAR_TICK_INTERRUPT();\n}\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TASK_FPU_SUPPORT != 2 )\n\n\tvoid vPortTaskUsesFPU( void )\n\t{\n\tuint32_t ulInitialFPSCR = 0;\n\n\t\t/* A task is registering the fact that it needs an FPU context.  Set the\n\t\tFPU flag (which is saved as part of the task context). */\n\t\tulPortTaskHasFPUContext = pdTRUE;\n\n\t\t/* Initialise the floating point status register. */\n\t\t__asm volatile ( \"FMXR \tFPSCR, %0\" :: \"r\" (ulInitialFPSCR) : \"memory\" );\n\t}\n\n#endif /* configUSE_TASK_FPU_SUPPORT */\n/*-----------------------------------------------------------*/\n\nvoid vPortClearInterruptMask( uint32_t ulNewMaskValue )\n{\n\tif( ulNewMaskValue == pdFALSE )\n\t{\n\t\tportCLEAR_INTERRUPT_MASK();\n\t}\n}\n/*-----------------------------------------------------------*/\n\nuint32_t ulPortSetInterruptMask( void )\n{\nuint32_t ulReturn;\n\n\t/* Interrupt in the CPU must be turned off while the ICCPMR is being\n\tupdated. */\n\tportCPU_IRQ_DISABLE();\n\tif( portICCPMR_PRIORITY_MASK_REGISTER == ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) )\n\t{\n\t\t/* Interrupts were already masked. */\n\t\tulReturn = pdTRUE;\n\t}\n\telse\n\t{\n\t\tulReturn = pdFALSE;\n\t\tportICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\n\t\t__asm volatile (\t\"dsb\t\t\\n\"\n\t\t\t\t\t\t\t\"isb\t\t\\n\" ::: \"memory\" );\n\t}\n\tportCPU_IRQ_ENABLE();\n\n\treturn ulReturn;\n}\n/*-----------------------------------------------------------*/\n\n#if( configASSERT_DEFINED == 1 )\n\n\tvoid vPortValidateInterruptPriority( void )\n\t{\n\t\t/* The following assertion will fail if a service routine (ISR) for\n\t\tan interrupt that has been assigned a priority above\n\t\tconfigMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API\n\t\tfunction.  ISR safe FreeRTOS API functions must *only* be called\n\t\tfrom interrupts that have been assigned a priority at or below\n\t\tconfigMAX_SYSCALL_INTERRUPT_PRIORITY.\n\n\t\tNumerically low interrupt priority numbers represent logically high\n\t\tinterrupt priorities, therefore the priority of the interrupt must\n\t\tbe set to a value equal to or numerically *higher* than\n\t\tconfigMAX_SYSCALL_INTERRUPT_PRIORITY.\n\n\t\tFreeRTOS maintains separate thread and ISR API functions to ensure\n\t\tinterrupt entry is as fast and simple as possible. */\n\t\tconfigASSERT( portICCRPR_RUNNING_PRIORITY_REGISTER >= ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) );\n\n\t\t/* Priority grouping:  The interrupt controller (GIC) allows the bits\n\t\tthat define each interrupt's priority to be split between bits that\n\t\tdefine the interrupt's pre-emption priority bits and bits that define\n\t\tthe interrupt's sub-priority.  For simplicity all bits must be defined\n\t\tto be pre-emption priority bits.  The following assertion will fail if\n\t\tthis is not the case (if some bits represent a sub-priority).\n\n\t\tThe priority grouping is configured by the GIC's binary point register\n\t\t(ICCBPR).  Writing 0 to ICCBPR will ensure it is set to its lowest\n\t\tpossible value (which may be above 0). */\n\t\tconfigASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );\n\t}\n\n#endif /* configASSERT_DEFINED */\n/*-----------------------------------------------------------*/\n\nvoid vApplicationFPUSafeIRQHandler( uint32_t ulICCIAR )\n{\n\t( void ) ulICCIAR;\n\tconfigASSERT( ( volatile void * ) NULL );\n}\n"
  },
  {
    "path": "src/rtos/portASM.S",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n\t.text\n\t.arm\n\n\t.set SYS_MODE,\t0x1f\n\t.set SVC_MODE,\t0x13\n\t.set IRQ_MODE,\t0x12\n\n\t/* Hardware registers. */\n\t.extern ulICCIAR\n\t.extern ulICCEOIR\n\t.extern ulICCPMR\n\n\t/* Variables and functions. */\n\t.extern ulMaxAPIPriorityMask\n\t.extern _freertos_vector_table\n\t.extern pxCurrentTCB\n\t.extern vTaskSwitchContext\n\t.extern vApplicationIRQHandler\n\t.extern ulPortInterruptNesting\n\t.extern ulPortTaskHasFPUContext\n\n\t.global FreeRTOS_IRQ_Handler\n\t.global FreeRTOS_SWI_Handler\n\t.global vPortRestoreTaskContext\n\n\n\n\n.macro portSAVE_CONTEXT\n\n\t/* Save the LR and SPSR onto the system mode stack before switching to\n\tsystem mode to save the remaining system mode registers. */\n\tSRSDB\tsp!, #SYS_MODE\n\tCPS\t\t#SYS_MODE\n\tPUSH\t{R0-R12, R14}\n\n\t/* Push the critical nesting count. */\n\tLDR\t\tR2, ulCriticalNestingConst\n\tLDR\t\tR1, [R2]\n\tPUSH\t{R1}\n\n\t/* Does the task have a floating point context that needs saving?  If\n\tulPortTaskHasFPUContext is 0 then no. */\n\tLDR\t\tR2, ulPortTaskHasFPUContextConst\n\tLDR\t\tR3, [R2]\n\tCMP\t\tR3, #0\n\n\t/* Save the floating point context, if any. */\n\tFMRXNE  R1,  FPSCR\n\tVPUSHNE {D0-D15}\n\tVPUSHNE\t{D16-D31}\n\tPUSHNE\t{R1}\n\n\t/* Save ulPortTaskHasFPUContext itself. */\n\tPUSH\t{R3}\n\n\t/* Save the stack pointer in the TCB. */\n\tLDR\t\tR0, pxCurrentTCBConst\n\tLDR\t\tR1, [R0]\n\tSTR\t\tSP, [R1]\n\n\t.endm\n\n; /**********************************************************************/\n\n.macro portRESTORE_CONTEXT\n\n\t/* Set the SP to point to the stack of the task being restored. */\n\tLDR\t\tR0, pxCurrentTCBConst\n\tLDR\t\tR1, [R0]\n\tLDR\t\tSP, [R1]\n\n\t/* Is there a floating point context to restore?  If the restored\n\tulPortTaskHasFPUContext is zero then no. */\n\tLDR\t\tR0, ulPortTaskHasFPUContextConst\n\tPOP\t\t{R1}\n\tSTR\t\tR1, [R0]\n\tCMP\t\tR1, #0\n\n\t/* Restore the floating point context, if any. */\n\tPOPNE \t{R0}\n\tVPOPNE\t{D16-D31}\n\tVPOPNE\t{D0-D15}\n\tVMSRNE  FPSCR, R0\n\n\t/* Restore the critical section nesting depth. */\n\tLDR\t\tR0, ulCriticalNestingConst\n\tPOP\t\t{R1}\n\tSTR\t\tR1, [R0]\n\n\t/* Ensure the priority mask is correct for the critical nesting depth. */\n\tLDR\t\tR2, ulICCPMRConst\n\tLDR\t\tR2, [R2]\n\tCMP\t\tR1, #0\n\tMOVEQ\tR4, #255\n\tLDRNE\tR4, ulMaxAPIPriorityMaskConst\n\tLDRNE\tR4, [R4]\n\tSTR\t\tR4, [R2]\n\n\t/* Restore all system mode registers other than the SP (which is already\n\tbeing used). */\n\tPOP\t\t{R0-R12, R14}\n\n\t/* Return to the task code, loading CPSR on the way. */\n\tRFEIA\tsp!\n\n\t.endm\n\n\n\n\n/******************************************************************************\n * SVC handler is used to start the scheduler.\n *****************************************************************************/\n.align 4\n.type FreeRTOS_SWI_Handler, %function\nFreeRTOS_SWI_Handler:\n\t/* Save the context of the current task and select a new task to run. */\n\tportSAVE_CONTEXT\n\tLDR R0, vTaskSwitchContextConst\n\tBLX\tR0\n\tportRESTORE_CONTEXT\n\n\n/******************************************************************************\n * vPortRestoreTaskContext is used to start the scheduler.\n *****************************************************************************/\n.type vPortRestoreTaskContext, %function\nvPortRestoreTaskContext:\n\t/* Switch to system mode. */\n\tCPS\t\t#SYS_MODE\n\tportRESTORE_CONTEXT\n\n.align 4\n.type FreeRTOS_IRQ_Handler, %function\nFreeRTOS_IRQ_Handler:\n\t/* Return to the interrupted instruction. */\n\tSUB\t\tlr, lr, #4\n\n\t/* Push the return address and SPSR. */\n\tPUSH\t{lr}\n\tMRS\t\tlr, SPSR\n\tPUSH\t{lr}\n\n\t/* Change to supervisor mode to allow reentry. */\n\tCPS\t\t#SVC_MODE\n\n\t/* Push used registers. */\n\tPUSH\t{r0-r4, r12}\n\n\t/* Increment nesting count.  r3 holds the address of ulPortInterruptNesting\n\tfor future use.  r1 holds the original ulPortInterruptNesting value for\n\tfuture use. */\n\tLDR\t\tr3, ulPortInterruptNestingConst\n\tLDR\t\tr1, [r3]\n\tADD\t\tr4, r1, #1\n\tSTR\t\tr4, [r3]\n\n\t/* Read value from the interrupt acknowledge register, which is stored in r0\n\tfor future parameter and interrupt clearing use. */\n\tLDR \tr2, ulICCIARConst\n\tLDR\t\tr2, [r2]\n\tLDR\t\tr0, [r2]\n\n\t/* Ensure bit 2 of the stack pointer is clear.  r2 holds the bit 2 value for\n\tfuture use.  _RB_ Does this ever actually need to be done provided the start\n\tof the stack is 8-byte aligned? */\n\tMOV\t\tr2, sp\n\tAND\t\tr2, r2, #4\n\tSUB\t\tsp, sp, r2\n\n\t/* Call the interrupt handler.  r4 pushed to maintain alignment. */\n\tPUSH\t{r0-r4, lr}\n\tLDR\t\tr1, vApplicationIRQHandlerConst\n\tBLX\t\tr1\n\tPOP\t\t{r0-r4, lr}\n\tADD\t\tsp, sp, r2\n\n\tCPSID\ti\n\tDSB\n\tISB\n\n\t/* Write the value read from ICCIAR to ICCEOIR. */\n\tLDR \tr4, ulICCEOIRConst\n\tLDR\t\tr4, [r4]\n\tSTR\t\tr0, [r4]\n\n\t/* Restore the old nesting count. */\n\tSTR\t\tr1, [r3]\n\n\t/* A context switch is never performed if the nesting count is not 0. */\n\tCMP\t\tr1, #0\n\tBNE\t\texit_without_switch\n\n\t/* Did the interrupt request a context switch?  r1 holds the address of\n\tulPortYieldRequired and r0 the value of ulPortYieldRequired for future\n\tuse. */\n\tLDR\t\tr1, =ulPortYieldRequired\n\tLDR\t\tr0, [r1]\n\tCMP\t\tr0, #0\n\tBNE\t\tswitch_before_exit\n\nexit_without_switch:\n\t/* No context switch.  Restore used registers, LR_irq and SPSR before\n\treturning. */\n\tPOP\t\t{r0-r4, r12}\n\tCPS\t\t#IRQ_MODE\n\tPOP\t\t{LR}\n\tMSR\t\tSPSR_cxsf, LR\n\tPOP\t\t{LR}\n\tMOVS\tPC, LR\n\nswitch_before_exit:\n\t/* A context swtich is to be performed.  Clear the context switch pending\n\tflag. */\n\tMOV\t\tr0, #0\n\tSTR\t\tr0, [r1]\n\n\t/* Restore used registers, LR-irq and SPSR before saving the context\n\tto the task stack. */\n\tPOP\t\t{r0-r4, r12}\n\tCPS\t\t#IRQ_MODE\n\tPOP\t\t{LR}\n\tMSR\t\tSPSR_cxsf, LR\n\tPOP\t\t{LR}\n\tportSAVE_CONTEXT\n\n\t/* Call the function that selects the new task to execute.\n\tvTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD\n\tinstructions, or 8 byte aligned stack allocated data.  LR does not need\n\tsaving as a new LR will be loaded by portRESTORE_CONTEXT anyway. */\n\tLDR\t\tR0, vTaskSwitchContextConst\n\tBLX\t\tR0\n\n\t/* Restore the context of, and branch to, the task selected to execute\n\tnext. */\n\tportRESTORE_CONTEXT\n\n\n/******************************************************************************\n * If the application provides an implementation of vApplicationIRQHandler(),\n * then it will get called directly without saving the FPU registers on\n * interrupt entry, and this weak implementation of\n * vApplicationIRQHandler() will not get called.\n *\n * If the application provides its own implementation of\n * vApplicationFPUSafeIRQHandler() then this implementation of\n * vApplicationIRQHandler() will be called, save the FPU registers, and then\n * call vApplicationFPUSafeIRQHandler().\n *\n * Therefore, if the application writer wants FPU registers to be saved on\n * interrupt entry their IRQ handler must be called\n * vApplicationFPUSafeIRQHandler(), and if the application writer does not want\n * FPU registers to be saved on interrupt entry their IRQ handler must be\n * called vApplicationIRQHandler().\n *****************************************************************************/\n\n.align 4\n.weak vApplicationIRQHandler\n.type vApplicationIRQHandler, %function\nvApplicationIRQHandler:\n\tPUSH\t{LR}\n\tFMRX\tR1,  FPSCR\n\tVPUSH\t{D0-D15}\n\tVPUSH\t{D16-D31}\n\tPUSH\t{R1}\n\n\tLDR\t\tr1, vApplicationFPUSafeIRQHandlerConst\n\tBLX\t\tr1\n\n\tPOP\t\t{R0}\n\tVPOP\t{D16-D31}\n\tVPOP\t{D0-D15}\n\tVMSR\tFPSCR, R0\n\n\tPOP {PC}\n\n\nulICCIARConst:\t.word ulICCIAR\nulICCEOIRConst:\t.word ulICCEOIR\nulICCPMRConst: .word ulICCPMR\npxCurrentTCBConst: .word pxCurrentTCB\nulCriticalNestingConst: .word ulCriticalNesting\nulPortTaskHasFPUContextConst: .word ulPortTaskHasFPUContext\nulMaxAPIPriorityMaskConst: .word ulMaxAPIPriorityMask\nvTaskSwitchContextConst: .word vTaskSwitchContext\nvApplicationIRQHandlerConst: .word vApplicationIRQHandler\nulPortInterruptNestingConst: .word ulPortInterruptNesting\nvApplicationFPUSafeIRQHandlerConst: .word vApplicationFPUSafeIRQHandler\n\n.end\n\n\n\n\n\n"
  },
  {
    "path": "src/rtos/portmacro.h",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n#ifndef PORTMACRO_H\n#define PORTMACRO_H\n\n#ifdef __cplusplus\n\textern \"C\" {\n#endif\n\n/*-----------------------------------------------------------\n * Port specific definitions.\n *\n * The settings in this file configure FreeRTOS correctly for the given hardware\n * and compiler.\n *\n * These settings should not be altered.\n *-----------------------------------------------------------\n */\n\n/* Type definitions. */\n#define portCHAR\t\tchar\n#define portFLOAT\t\tfloat\n#define portDOUBLE\t\tdouble\n#define portLONG\t\tlong\n#define portSHORT\t\tshort\n#define portSTACK_TYPE\tuint32_t\n#define portBASE_TYPE\tlong\n\ntypedef portSTACK_TYPE task_stack_t;\ntypedef long int32_t;\ntypedef unsigned long uint32_t;\n\ntypedef uint32_t uint32_t;\n#define portMAX_DELAY ( uint32_t ) 0xffffffffUL\n\n/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do\nnot need to be guarded with a critical section. */\n#define portTICK_TYPE_IS_ATOMIC 1\n\n/*-----------------------------------------------------------*/\n\n/* Hardware specifics. */\n#define portSTACK_GROWTH\t\t\t( -1 )\n#define portTICK_PERIOD_MS\t\t\t( ( uint32_t ) 1000 / configTICK_RATE_HZ )\n#define portBYTE_ALIGNMENT\t\t\t8\n\n/*-----------------------------------------------------------*/\n\n/* Task utilities. */\n\n/* Called at the end of an ISR that can cause a context switch. */\n#define portEND_SWITCHING_ISR( xSwitchRequired )\\\n{\t\t\t\t\t\t\t\t\t\t\t\t\\\nextern uint32_t ulPortYieldRequired;\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tif( xSwitchRequired != pdFALSE )\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tulPortYieldRequired = pdTRUE;\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\\\n}\n\n#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )\n#define portYIELD() __asm volatile ( \"SWI 0\" ::: \"memory\" );\n\n\n/*-----------------------------------------------------------\n * Critical section control\n *----------------------------------------------------------*/\n\nextern void vPortEnterCritical( void );\nextern void vPortExitCritical( void );\nextern uint32_t ulPortSetInterruptMask( void );\nextern void vPortClearInterruptMask( uint32_t ulNewMaskValue );\nextern void vPortInstallFreeRTOSVectorTable( void );\n\n/* These macros do not globally disable/enable interrupts.  They do mask off\ninterrupts that have a priority below configMAX_API_CALL_INTERRUPT_PRIORITY. */\n#define portENTER_CRITICAL()\t\tvPortEnterCritical();\n#define portEXIT_CRITICAL()\t\t\tvPortExitCritical();\n#define portDISABLE_INTERRUPTS()\tulPortSetInterruptMask()\n#define portENABLE_INTERRUPTS()\t\tvPortClearInterruptMask( 0 )\n#define portSET_INTERRUPT_MASK_FROM_ISR()\t\tulPortSetInterruptMask()\n#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x)\tvPortClearInterruptMask(x)\n\n/*-----------------------------------------------------------*/\n\n/* Task function macros as described on the FreeRTOS.org WEB site.  These are\nnot required for this port but included in case common demo code that uses these\nmacros is used. */\n#define portTASK_FUNCTION_PROTO( vFunction, pvParameters )\tvoid vFunction( void *pvParameters )\n#define portTASK_FUNCTION( vFunction, pvParameters )\tvoid vFunction( void *pvParameters )\n\n/* Prototype of the FreeRTOS tick handler.  This must be installed as the\nhandler for whichever peripheral is used to generate the RTOS tick. */\nvoid FreeRTOS_Tick_Handler( void );\n\n/* If configUSE_TASK_FPU_SUPPORT is set to 1 (or left undefined) then tasks are\ncreated without an FPU context and must call vPortTaskUsesFPU() to give\nthemselves an FPU context before using any FPU instructions.  If\nconfigUSE_TASK_FPU_SUPPORT is set to 2 then all tasks will have an FPU context\nby default. */\n#if( configUSE_TASK_FPU_SUPPORT != 2 )\n\tvoid vPortTaskUsesFPU( void );\n#else\n\t/* Each task has an FPU context already, so define this function away to\n\tnothing to prevent it being called accidentally. */\n\t#define vPortTaskUsesFPU()\n#endif\n#define portTASK_USES_FLOATING_POINT() vPortTaskUsesFPU()\n\n#define portLOWEST_INTERRUPT_PRIORITY ( ( ( uint32_t ) configUNIQUE_INTERRUPT_PRIORITIES ) - 1UL )\n#define portLOWEST_USABLE_INTERRUPT_PRIORITY ( portLOWEST_INTERRUPT_PRIORITY - 1UL )\n\n/* Architecture specific optimisations. */\n#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION\n\t#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1\n#endif\n\n#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\n\n\t/* Store/clear the ready priorities in a bit map. */\n\t#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\n\t#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\n\n\t/*-----------------------------------------------------------*/\n\n\t#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __builtin_clz( uxReadyPriorities ) )\n\n#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\n\n#ifdef configASSERT\n\tvoid vPortValidateInterruptPriority( void );\n\t#define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() \tvPortValidateInterruptPriority()\n#endif /* configASSERT */\n\n#define portNOP() __asm volatile( \"NOP\" )\n#define portINLINE __inline\n\n#ifdef __cplusplus\n\t} /* extern C */\n#endif\n\n\n/* The number of bits to shift for an interrupt priority is dependent on the\nnumber of bits implemented by the interrupt controller. */\n#if configUNIQUE_INTERRUPT_PRIORITIES == 16\n\t#define portPRIORITY_SHIFT 4\n\t#define portMAX_BINARY_POINT_VALUE\t3\n#elif configUNIQUE_INTERRUPT_PRIORITIES == 32\n\t#define portPRIORITY_SHIFT 3\n\t#define portMAX_BINARY_POINT_VALUE\t2\n#elif configUNIQUE_INTERRUPT_PRIORITIES == 64\n\t#define portPRIORITY_SHIFT 2\n\t#define portMAX_BINARY_POINT_VALUE\t1\n#elif configUNIQUE_INTERRUPT_PRIORITIES == 128\n\t#define portPRIORITY_SHIFT 1\n\t#define portMAX_BINARY_POINT_VALUE\t0\n#elif configUNIQUE_INTERRUPT_PRIORITIES == 256\n\t#define portPRIORITY_SHIFT 0\n\t#define portMAX_BINARY_POINT_VALUE\t0\n#else\n\t#error Invalid configUNIQUE_INTERRUPT_PRIORITIES setting.  configUNIQUE_INTERRUPT_PRIORITIES must be set to the number of unique priorities implemented by the target hardware\n#endif\n\n/* Interrupt controller access addresses. */\n#define portICCPMR_PRIORITY_MASK_OFFSET  \t\t\t\t\t\t( 0x04 )\n#define portICCIAR_INTERRUPT_ACKNOWLEDGE_OFFSET \t\t\t\t( 0x0C )\n#define portICCEOIR_END_OF_INTERRUPT_OFFSET \t\t\t\t\t( 0x10 )\n#define portICCBPR_BINARY_POINT_OFFSET\t\t\t\t\t\t\t( 0x08 )\n#define portICCRPR_RUNNING_PRIORITY_OFFSET\t\t\t\t\t\t( 0x14 )\n\n#define portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS \t\t( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET )\n#define portICCPMR_PRIORITY_MASK_REGISTER \t\t\t\t\t( *( ( volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCPMR_PRIORITY_MASK_OFFSET ) ) )\n#define portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS \t( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCIAR_INTERRUPT_ACKNOWLEDGE_OFFSET )\n#define portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS \t\t( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCEOIR_END_OF_INTERRUPT_OFFSET )\n#define portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS \t\t\t( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCPMR_PRIORITY_MASK_OFFSET )\n#define portICCBPR_BINARY_POINT_REGISTER \t\t\t\t\t( *( ( const volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCBPR_BINARY_POINT_OFFSET ) ) )\n#define portICCRPR_RUNNING_PRIORITY_REGISTER \t\t\t\t( *( ( const volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCRPR_RUNNING_PRIORITY_OFFSET ) ) )\n\n#endif /* PORTMACRO_H */\n\n"
  },
  {
    "path": "src/rtos/queue.c",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n#include <stdlib.h>\n#include <string.h>\n\n#include \"FreeRTOS.h\"\n#include \"task.h\"\n#include \"queue.h\"\n\n\n/* Constants used with the cRxLock and cTxLock structure members. */\n#define queueUNLOCKED\t\t\t\t\t( ( int8_t ) -1 )\n#define queueLOCKED_UNMODIFIED\t\t\t( ( int8_t ) 0 )\n\n/* When the Queue_t structure is used to represent a base queue its pcHead and\npcTail members are used as pointers into the queue storage area.  When the\nQueue_t structure is used to represent a mutex pcHead and pcTail pointers are\nnot necessary, and the pcHead pointer is set to NULL to indicate that the\npcTail pointer actually points to the mutex holder (if any).  Map alternative\nnames to the pcHead and pcTail structure members to ensure the readability of\nthe code is maintained despite this dual use of two structure members.  An\nalternative implementation would be to use a union, but use of a union is\nagainst the coding standard (although an exception to the standard has been\npermitted where the dual use also significantly changes the type of the\nstructure member). */\n#define pxMutexHolder\t\t\t\t\tpcTail\n#define uxQueueType\t\t\t\t\t\tpcHead\n#define queueQUEUE_IS_MUTEX\t\t\t\tNULL\n\n/* Semaphores do not actually store or copy data, so have an item size of\nzero. */\n#define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( uint32_t ) 0 )\n#define queueMUTEX_GIVE_BLOCK_TIME\t\t ( ( uint32_t ) 0U )\n\n#if( configUSE_PREEMPTION == 0 )\n\t/* If the cooperative scheduler is being used then a yield should not be\n\tperformed just because a higher priority task has been woken. */\n\t#define queueYIELD_IF_USING_PREEMPTION()\n#else\n\t#define queueYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API()\n#endif\n\n/*\n * Definition of the queue used by the scheduler.\n * Items are queued by copy, not reference.  See the following link for the\n * rationale: http://www.freertos.org/Embedded-RTOS-Queues.html\n */\ntypedef struct QueueDefinition\n{\n\tint8_t *pcHead;\t\t\t\t\t/*< Points to the beginning of the queue storage area. */\n\tint8_t *pcTail;\t\t\t\t\t/*< Points to the byte at the end of the queue storage area.  Once more byte is allocated than necessary to store the queue items, this is used as a marker. */\n\tint8_t *pcWriteTo;\t\t\t\t/*< Points to the free next place in the storage area. */\n\n\tunion\t\t\t\t\t\t\t/* Use of a union is an exception to the coding standard to ensure two mutually exclusive structure members don't appear simultaneously (wasting RAM). */\n\t{\n\t\tint8_t *pcReadFrom;\t\t\t/*< Points to the last place that a queued item was read from when the structure is used as a queue. */\n\t\tuint32_t uxRecursiveCallCount;/*< Maintains a count of the number of times a recursive mutex has been recursively 'taken' when the structure is used as a mutex. */\n\t} u;\n\n\tList_t xTasksWaitingToSend;\t\t/*< List of tasks that are blocked waiting to post onto this queue.  Stored in priority order. */\n\tList_t xTasksWaitingToReceive;\t/*< List of tasks that are blocked waiting to read from this queue.  Stored in priority order. */\n\n\tvolatile uint32_t uxMessagesWaiting;/*< The number of items currently in the queue. */\n\tuint32_t uxLength;\t\t\t/*< The length of the queue defined as the number of items it will hold, not the number of bytes. */\n\tuint32_t uxItemSize;\t\t\t/*< The size of each items that the queue will hold. */\n\n\tvolatile int8_t cRxLock;\t\t/*< Stores the number of items received from the queue (removed from the queue) while the queue was locked.  Set to queueUNLOCKED when the queue is not locked. */\n\tvolatile int8_t cTxLock;\t\t/*< Stores the number of items transmitted to the queue (added to the queue) while the queue was locked.  Set to queueUNLOCKED when the queue is not locked. */\n\n\t#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\n\t\tuint8_t ucStaticallyAllocated;\t/*< Set to pdTRUE if the memory used by the queue was statically allocated to ensure no attempt is made to free the memory. */\n\t#endif\n\n\t#if ( configUSE_QUEUE_SETS == 1 )\n\t\tstruct QueueDefinition *pxQueueSetContainer;\n\t#endif\n\n\t#if ( configUSE_TRACE_FACILITY == 1 )\n\t\tuint32_t uxQueueNumber;\n\t\tuint8_t ucQueueType;\n\t#endif\n\n} xQUEUE;\n\n/* The old xQUEUE name is maintained above then typedefed to the new Queue_t\nname below to enable the use of older kernel aware debuggers. */\ntypedef xQUEUE Queue_t;\n\n/*-----------------------------------------------------------*/\n\n/*\n * The queue registry is just a means for kernel aware debuggers to locate\n * queue structures.  It has no other purpose so is an optional component.\n */\n#if ( configQUEUE_REGISTRY_SIZE > 0 )\n\n\t/* The type stored within the queue registry array.  This allows a name\n\tto be assigned to each queue making kernel aware debugging a little\n\tmore user friendly. */\n\ttypedef struct QUEUE_REGISTRY_ITEM\n\t{\n\t\tconst char *pcQueueName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t\tqueue_t xHandle;\n\t} xQueueRegistryItem;\n\n\t/* The old xQueueRegistryItem name is maintained above then typedefed to the\n\tnew xQueueRegistryItem name below to enable the use of older kernel aware\n\tdebuggers. */\n\ttypedef xQueueRegistryItem QueueRegistryItem_t;\n\n\t/* The queue registry is simply an array of QueueRegistryItem_t structures.\n\tThe pcQueueName member of a structure being NULL is indicative of the\n\tarray position being vacant. */\n\tQueueRegistryItem_t xQueueRegistry[ configQUEUE_REGISTRY_SIZE ];\n\n#endif /* configQUEUE_REGISTRY_SIZE */\n\n/*\n * Unlocks a queue locked by a call to prvLockQueue.  Locking a queue does not\n * prevent an ISR from adding or removing items to the queue, but does prevent\n * an ISR from removing tasks from the queue event lists.  If an ISR finds a\n * queue is locked it will instead increment the appropriate queue lock count\n * to indicate that a task may require unblocking.  When the queue in unlocked\n * these lock counts are inspected, and the appropriate action taken.\n */\nstatic void prvUnlockQueue( Queue_t * const pxQueue ) ;\n\n/*\n * Uses a critical section to determine if there is any data in a queue.\n *\n * @return pdTRUE if the queue contains no items, otherwise pdFALSE.\n */\nstatic int32_t prvIsQueueEmpty( const Queue_t *pxQueue ) ;\n\n/*\n * Uses a critical section to determine if there is any space in a queue.\n *\n * @return pdTRUE if there is no space, otherwise pdFALSE;\n */\nstatic int32_t prvIsQueueFull( const Queue_t *pxQueue ) ;\n\n/*\n * Copies an item into the queue, either at the front of the queue or the\n * back of the queue.\n */\nstatic int32_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const int32_t xPosition ) ;\n\n/*\n * Copies an item out of a queue.\n */\nstatic void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const buffer ) ;\n\n#if ( configUSE_QUEUE_SETS == 1 )\n\t/*\n\t * Checks to see if a queue is a member of a queue set, and if so, notifies\n\t * the queue set that the queue contains data.\n\t */\n\tstatic int32_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue, const int32_t xCopyPosition ) ;\n#endif\n\n/*\n * Called after a Queue_t structure has been allocated either statically or\n * dynamically to fill in the structure's members.\n */\nstatic void prvInitialiseNewQueue( const uint32_t uxQueueLength, const uint32_t uxItemSize, uint8_t *pucQueueStorage, const uint8_t ucQueueType, Queue_t *pxNewQueue ) ;\n\n/*\n * Mutexes are a special type of queue.  When a mutex is created, first the\n * queue is created, then prvInitialiseMutex() is called to configure the queue\n * as a mutex.\n */\n#if( configUSE_MUTEXES == 1 )\n\tstatic void prvInitialiseMutex( Queue_t *pxNewQueue ) ;\n#endif\n\n#if( configUSE_MUTEXES == 1 )\n\t/*\n\t * If a task waiting for a mutex causes the mutex holder to inherit a\n\t * priority, but the waiting task times out, then the holder should\n\t * disinherit the priority - but only down to the highest priority of any\n\t * other tasks that are waiting for the same mutex.  This function returns\n\t * that priority.\n\t */\n\tstatic uint32_t prvGetDisinheritPriorityAfterTimeout( const Queue_t * const pxQueue ) ;\n#endif\n/*-----------------------------------------------------------*/\n\n/*\n * Macro to mark a queue as locked.  Locking a queue prevents an ISR from\n * accessing the queue event lists.\n */\n#define prvLockQueue( pxQueue )\t\t\t\t\t\t\t\t\\\n\ttaskENTER_CRITICAL();\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tif( ( pxQueue )->cRxLock == queueUNLOCKED )\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t( pxQueue )->cRxLock = queueLOCKED_UNMODIFIED;\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tif( ( pxQueue )->cTxLock == queueUNLOCKED )\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t( pxQueue )->cTxLock = queueLOCKED_UNMODIFIED;\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\ttaskEXIT_CRITICAL()\n/*-----------------------------------------------------------*/\n\nint32_t xQueueGenericReset( queue_t xQueue, int32_t xNewQueue )\n{\nQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n\tconfigASSERT( pxQueue );\n\n\ttaskENTER_CRITICAL();\n\t{\n\t\tpxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize );\n\t\tpxQueue->uxMessagesWaiting = ( uint32_t ) 0U;\n\t\tpxQueue->pcWriteTo = pxQueue->pcHead;\n\t\tpxQueue->u.pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( uint32_t ) 1U ) * pxQueue->uxItemSize );\n\t\tpxQueue->cRxLock = queueUNLOCKED;\n\t\tpxQueue->cTxLock = queueUNLOCKED;\n\n\t\tif( xNewQueue == pdFALSE )\n\t\t{\n\t\t\t/* If there are tasks blocked waiting to read from the queue, then\n\t\t\tthe tasks will remain blocked as after this function exits the queue\n\t\t\twill still be empty.  If there are tasks blocked waiting to write to\n\t\t\tthe queue, then one should be unblocked as after this function exits\n\t\t\tit will be possible to write to it. */\n\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\n\t\t\t{\n\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tqueueYIELD_IF_USING_PREEMPTION();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* Ensure the event queues start in the correct state. */\n\t\t\tvListInitialise( &( pxQueue->xTasksWaitingToSend ) );\n\t\t\tvListInitialise( &( pxQueue->xTasksWaitingToReceive ) );\n\t\t}\n\t}\n\ttaskEXIT_CRITICAL();\n\n\t/* A value is returned for calling semantic consistency with previous\n\tversions. */\n\treturn pdPASS;\n}\n/*-----------------------------------------------------------*/\n/** Generic Reset \"Macros\" **/\nvoid queue_reset(queue_t queue) {\n\txQueueGenericReset(queue, pdFALSE);\n}\n\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\n\tqueue_t xQueueGenericCreateStatic( const uint32_t uxQueueLength, const uint32_t uxItemSize, uint8_t *pucQueueStorage, static_queue_s_t *pxStaticQueue, const uint8_t ucQueueType )\n\t{\n\tQueue_t *pxNewQueue;\n\n\t\tconfigASSERT( uxQueueLength > ( uint32_t ) 0 );\n\n\t\t/* The static_queue_s_t structure and the queue storage area must be\n\t\tsupplied. */\n\t\tconfigASSERT( pxStaticQueue != NULL );\n\n\t\t/* A queue storage area should be provided if the item size is not 0, and\n\t\tshould not be provided if the item size is 0. */\n\t\tconfigASSERT( !( ( pucQueueStorage != NULL ) && ( uxItemSize == 0 ) ) );\n\t\tconfigASSERT( !( ( pucQueueStorage == NULL ) && ( uxItemSize != 0 ) ) );\n\n\t\t#if( configASSERT_DEFINED == 1 )\n\t\t{\n\t\t\t/* Sanity check that the size of the structure used to declare a\n\t\t\tvariable of type static_queue_s_t or static_sem_s_t equals the size of\n\t\t\tthe real queue and semaphore structures. */\n\t\t\tvolatile size_t xSize = sizeof( static_queue_s_t );\n\t\t\tconfigASSERT( xSize == sizeof( Queue_t ) );\n\t\t}\n\t\t#endif /* configASSERT_DEFINED */\n\n\t\t/* The address of a statically allocated queue was passed in, use it.\n\t\tThe address of a statically allocated storage area was also passed in\n\t\tbut is already set. */\n\t\tpxNewQueue = ( Queue_t * ) pxStaticQueue; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */\n\n\t\tif( pxNewQueue != NULL )\n\t\t{\n\t\t\t#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\t\t\t{\n\t\t\t\t/* Queues can be allocated wither statically or dynamically, so\n\t\t\t\tnote this queue was allocated statically in case the queue is\n\t\t\t\tlater deleted. */\n\t\t\t\tpxNewQueue->ucStaticallyAllocated = pdTRUE;\n\t\t\t}\n\t\t\t#endif /* configSUPPORT_DYNAMIC_ALLOCATION */\n\n\t\t\tprvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue );\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttraceQUEUE_CREATE_FAILED( ucQueueType );\n\t\t}\n\n\t\treturn pxNewQueue;\n\t}\n\n\tqueue_t queue_create_static(uint32_t uxQueueLength, uint32_t uxItemSize, uint8_t* pucQueueStorage, \n\t                            static_queue_s_t* pxQueueBuffer) {\n\t\treturn xQueueGenericCreateStatic(uxQueueLength, uxItemSize, pucQueueStorage, \n\t\t                                 pxQueueBuffer, queueQUEUE_TYPE_BASE);\n\t}\n\n#endif /* configSUPPORT_STATIC_ALLOCATION */\n/*-----------------------------------------------------------*/\n\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\n\tqueue_t xQueueGenericCreate( const uint32_t uxQueueLength, const uint32_t uxItemSize, const uint8_t ucQueueType )\n\t{\n\tQueue_t *pxNewQueue;\n\tsize_t xQueueSizeInBytes;\n\tuint8_t *pucQueueStorage;\n\n\t\tconfigASSERT( uxQueueLength > ( uint32_t ) 0 );\n\n\t\tif( uxItemSize == ( uint32_t ) 0 )\n\t\t{\n\t\t\t/* There is not going to be a queue storage area. */\n\t\t\txQueueSizeInBytes = ( size_t ) 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* Allocate enough space to hold the maximum number of items that\n\t\t\tcan be in the queue at any time. */\n\t\t\txQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\t\t}\n\n\t\tpxNewQueue = ( Queue_t * ) kmalloc( sizeof( Queue_t ) + xQueueSizeInBytes );\n\n\t\tif( pxNewQueue != NULL )\n\t\t{\n\t\t\t/* Jump past the queue structure to find the location of the queue\n\t\t\tstorage area. */\n\t\t\tpucQueueStorage = ( ( uint8_t * ) pxNewQueue ) + sizeof( Queue_t );\n\n\t\t\t#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\t\t\t{\n\t\t\t\t/* Queues can be created either statically or dynamically, so\n\t\t\t\tnote this task was created dynamically in case it is later\n\t\t\t\tdeleted. */\n\t\t\t\tpxNewQueue->ucStaticallyAllocated = pdFALSE;\n\t\t\t}\n\t\t\t#endif /* configSUPPORT_STATIC_ALLOCATION */\n\n\t\t\tprvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue );\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttraceQUEUE_CREATE_FAILED( ucQueueType );\n\t\t\terrno = ENOMEM;\n\t\t}\n\n\t\treturn pxNewQueue;\n\t}\n\n\tqueue_t queue_create(uint32_t length, uint32_t item_size) {\n\t        return xQueueGenericCreate((length), (item_size), (queueQUEUE_TYPE_BASE));\n\t}\n\n#endif /* configSUPPORT_STATIC_ALLOCATION */\n/*-----------------------------------------------------------*/\n\nstatic void prvInitialiseNewQueue( const uint32_t uxQueueLength, const uint32_t uxItemSize, uint8_t *pucQueueStorage, const uint8_t ucQueueType, Queue_t *pxNewQueue )\n{\n\t/* Remove compiler warnings about unused parameters should\n\tconfigUSE_TRACE_FACILITY not be set to 1. */\n\t( void ) ucQueueType;\n\n\tif( uxItemSize == ( uint32_t ) 0 )\n\t{\n\t\t/* No RAM was allocated for the queue storage area, but PC head cannot\n\t\tbe set to NULL because NULL is used as a key to say the queue is used as\n\t\ta mutex.  Therefore just set pcHead to point to the queue as a benign\n\t\tvalue that is known to be within the memory map. */\n\t\tpxNewQueue->pcHead = ( int8_t * ) pxNewQueue;\n\t}\n\telse\n\t{\n\t\t/* Set the head to the start of the queue storage area. */\n\t\tpxNewQueue->pcHead = ( int8_t * ) pucQueueStorage;\n\t}\n\n\t/* Initialise the queue members as described where the queue type is\n\tdefined. */\n\tpxNewQueue->uxLength = uxQueueLength;\n\tpxNewQueue->uxItemSize = uxItemSize;\n\t( void ) xQueueGenericReset( pxNewQueue, pdTRUE );\n\n\t#if ( configUSE_TRACE_FACILITY == 1 )\n\t{\n\t\tpxNewQueue->ucQueueType = ucQueueType;\n\t}\n\t#endif /* configUSE_TRACE_FACILITY */\n\n\t#if( configUSE_QUEUE_SETS == 1 )\n\t{\n\t\tpxNewQueue->pxQueueSetContainer = NULL;\n\t}\n\t#endif /* configUSE_QUEUE_SETS */\n\n\ttraceQUEUE_CREATE( pxNewQueue );\n}\n/*-----------------------------------------------------------*/\n\n#if( configUSE_MUTEXES == 1 )\n\n\tstatic void prvInitialiseMutex( Queue_t *pxNewQueue )\n\t{\n\t\tif( pxNewQueue != NULL )\n\t\t{\n\t\t\t/* The queue create function will set all the queue structure members\n\t\t\tcorrectly for a generic queue, but this function is creating a\n\t\t\tmutex.  Overwrite those members that need to be set differently -\n\t\t\tin particular the information required for priority inheritance. */\n\t\t\tpxNewQueue->pxMutexHolder = NULL;\n\t\t\tpxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;\n\n\t\t\t/* In case this is a recursive mutex. */\n\t\t\tpxNewQueue->u.uxRecursiveCallCount = 0;\n\n\t\t\ttraceCREATE_MUTEX( pxNewQueue );\n\n\t\t\t/* Start with the semaphore in the expected state. */\n\t\t\t( void ) xQueueGenericSend( pxNewQueue, NULL, ( uint32_t ) 0U, queueSEND_TO_BACK );\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttraceCREATE_MUTEX_FAILED();\n\t\t}\n\t}\n\n#endif /* configUSE_MUTEXES */\n/*-----------------------------------------------------------*/\n\n#if( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\n\n\tqueue_t xQueueCreateMutex( const uint8_t ucQueueType )\n\t{\n\tQueue_t *pxNewQueue;\n\tconst uint32_t uxMutexLength = ( uint32_t ) 1, uxMutexSize = ( uint32_t ) 0;\n\n\t\tpxNewQueue = ( Queue_t * ) xQueueGenericCreate( uxMutexLength, uxMutexSize, ucQueueType );\n\t\tprvInitialiseMutex( pxNewQueue );\n\n\t\treturn pxNewQueue;\n\t}\n\n#endif /* configUSE_MUTEXES */\n/*-----------------------------------------------------------*/\n\n#if( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\n\n\tqueue_t xQueueCreateMutexStatic( const uint8_t ucQueueType, static_queue_s_t *pxStaticQueue )\n\t{\n\tQueue_t *pxNewQueue;\n\tconst uint32_t uxMutexLength = ( uint32_t ) 1, uxMutexSize = ( uint32_t ) 0;\n\n\t\t/* Prevent compiler warnings about unused parameters if\n\t\tconfigUSE_TRACE_FACILITY does not equal 1. */\n\t\t( void ) ucQueueType;\n\n\t\tpxNewQueue = ( Queue_t * ) xQueueGenericCreateStatic( uxMutexLength, uxMutexSize, NULL, pxStaticQueue, ucQueueType );\n\t\tprvInitialiseMutex( pxNewQueue );\n\n\t\treturn pxNewQueue;\n\t}\n\n#endif /* configUSE_MUTEXES */\n/*-----------------------------------------------------------*/\n\n#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )\n\n\tvoid* xQueueGetMutexHolder( queue_t xSemaphore )\n\t{\n\tvoid *pxReturn;\n\n\t\t/* This function is called by mutex_get_owner(), and should not\n\t\tbe called directly.  Note:  This is a good way of determining if the\n\t\tcalling task is the mutex holder, but not a good way of determining the\n\t\tidentity of the mutex holder, as the holder may change between the\n\t\tfollowing critical section exiting and the function returning. */\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\tif( ( ( Queue_t * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )\n\t\t\t{\n\t\t\t\tpxReturn = ( void * ) ( ( Queue_t * ) xSemaphore )->pxMutexHolder;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpxReturn = NULL;\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\treturn pxReturn;\n\t} /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */\n\n#endif\n/*-----------------------------------------------------------*/\n\n#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )\n\n\tvoid* xQueueGetMutexHolderFromISR( queue_t xSemaphore )\n\t{\n\tvoid *pxReturn;\n\n\t\tconfigASSERT( xSemaphore );\n\n\t\t/* Mutexes cannot be used in interrupt service routines, so the mutex\n\t\tholder should not change in an ISR, and therefore a critical section is\n\t\tnot required here. */\n\t\tif( ( ( Queue_t * ) xSemaphore )->uxQueueType == queueQUEUE_IS_MUTEX )\n\t\t{\n\t\t\tpxReturn = ( void * ) ( ( Queue_t * ) xSemaphore )->pxMutexHolder;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpxReturn = NULL;\n\t\t}\n\n\t\treturn pxReturn;\n\t} /*lint !e818 xSemaphore cannot be a pointer to const because it is a typedef. */\n\n#endif\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_RECURSIVE_MUTEXES == 1 )\n\n\tint32_t xQueueGiveMutexRecursive( queue_t xMutex )\n\t{\n\tint32_t xReturn;\n\tQueue_t * const pxMutex = ( Queue_t * ) xMutex;\n\n\t\tconfigASSERT( pxMutex );\n\n\t\t/* If this is the task that holds the mutex then pxMutexHolder will not\n\t\tchange outside of this task.  If this task does not hold the mutex then\n\t\tpxMutexHolder can never coincidentally equal the tasks handle, and as\n\t\tthis is the only condition we are interested in it does not matter if\n\t\tpxMutexHolder is accessed simultaneously by another task.  Therefore no\n\t\tmutual exclusion is required to test the pxMutexHolder variable. */\n\t\tif( pxMutex->pxMutexHolder == ( void * ) task_get_current() ) /*lint !e961 Not a redundant cast as task_t is a typedef. */\n\t\t{\n\t\t\ttraceGIVE_MUTEX_RECURSIVE( pxMutex );\n\n\t\t\t/* uxRecursiveCallCount cannot be zero if pxMutexHolder is equal to\n\t\t\tthe task handle, therefore no underflow check is required.  Also,\n\t\t\tuxRecursiveCallCount is only modified by the mutex holder, and as\n\t\t\tthere can only be one, no mutual exclusion is required to modify the\n\t\t\tuxRecursiveCallCount member. */\n\t\t\t( pxMutex->u.uxRecursiveCallCount )--;\n\n\t\t\t/* Has the recursive call count unwound to 0? */\n\t\t\tif( pxMutex->u.uxRecursiveCallCount == ( uint32_t ) 0 )\n\t\t\t{\n\t\t\t\t/* Return the mutex.  This will automatically unblock any other\n\t\t\t\ttask that might be waiting to access the mutex. */\n\t\t\t\t( void ) xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\n\t\t\txReturn = pdPASS;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* The mutex cannot be given because the calling task is not the\n\t\t\tholder. */\n\t\t\txReturn = pdFAIL;\n\n\t\t\ttraceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex );\n\t\t}\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_RECURSIVE_MUTEXES */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_RECURSIVE_MUTEXES == 1 )\n\n\tint32_t xQueueTakeMutexRecursive( queue_t xMutex, uint32_t timeout )\n\t{\n\tint32_t xReturn;\n\tQueue_t * const pxMutex = ( Queue_t * ) xMutex;\n\n\t\tconfigASSERT( pxMutex );\n\n\t\t/* Comments regarding mutual exclusion as per those within\n\t\txQueueGiveMutexRecursive(). */\n\n\t\ttraceTAKE_MUTEX_RECURSIVE( pxMutex );\n\n\t\tif( pxMutex->pxMutexHolder == ( void * ) task_get_current() ) /*lint !e961 Cast is not redundant as task_t is a typedef. */\n\t\t{\n\t\t\t( pxMutex->u.uxRecursiveCallCount )++;\n\t\t\txReturn = pdPASS;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = xQueueSemaphoreTake( pxMutex, timeout );\n\n\t\t\t/* pdPASS will only be returned if the mutex was successfully\n\t\t\tobtained.  The calling task may have entered the Blocked state\n\t\t\tbefore reaching here. */\n\t\t\tif( xReturn != pdFAIL )\n\t\t\t{\n\t\t\t\t( pxMutex->u.uxRecursiveCallCount )++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ttraceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex );\n\t\t\t}\n\t\t}\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_RECURSIVE_MUTEXES */\n/*-----------------------------------------------------------*/\n\n#if( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\n\n\tqueue_t xQueueCreateCountingSemaphoreStatic( const uint32_t uxMaxCount, const uint32_t uxInitialCount, static_queue_s_t *pxStaticQueue )\n\t{\n\tqueue_t xHandle;\n\n\t\tconfigASSERT( uxMaxCount != 0 );\n\t\tconfigASSERT( uxInitialCount <= uxMaxCount );\n\n\t\txHandle = xQueueGenericCreateStatic( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticQueue, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\n\n\t\tif( xHandle != NULL )\n\t\t{\n\t\t\t( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount;\n\n\t\t\ttraceCREATE_COUNTING_SEMAPHORE();\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttraceCREATE_COUNTING_SEMAPHORE_FAILED();\n\t\t}\n\n\t\treturn xHandle;\n\t}\n\n#endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */\n/*-----------------------------------------------------------*/\n\n#if( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\n\n\tqueue_t xQueueCreateCountingSemaphore( const uint32_t uxMaxCount, const uint32_t uxInitialCount )\n\t{\n\tqueue_t xHandle;\n\n\t\tconfigASSERT( uxMaxCount != 0 );\n\t\tconfigASSERT( uxInitialCount <= uxMaxCount );\n\n\t\txHandle = xQueueGenericCreate( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );\n\n\t\tif( xHandle != NULL )\n\t\t{\n\t\t\t( ( Queue_t * ) xHandle )->uxMessagesWaiting = uxInitialCount;\n\n\t\t\ttraceCREATE_COUNTING_SEMAPHORE();\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttraceCREATE_COUNTING_SEMAPHORE_FAILED();\n\t\t}\n\n\t\treturn xHandle;\n\t}\n\n#endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */\n/*-----------------------------------------------------------*/\n\nint32_t xQueueGenericSend( queue_t xQueue, const void * const pvItemToQueue, uint32_t timeout, const int32_t xCopyPosition )\n{\nint32_t xEntryTimeSet = pdFALSE, xYieldRequired;\nTimeOut_t xTimeOut;\nQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n\tconfigASSERT( pxQueue );\n\tconfigASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( uint32_t ) 0U ) ) );\n\tconfigASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\n\t#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\n\t{\n\t\tconfigASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( timeout != 0 ) ) );\n\t}\n\t#endif\n\n\n\t/* This function relaxes the coding standard somewhat to allow return\n\tstatements within the function itself.  This is done in the interest\n\tof execution time efficiency. */\n\tfor( ;; )\n\t{\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\t/* Is there room on the queue now?  The running task must be the\n\t\t\thighest priority task wanting to access the queue.  If the head item\n\t\t\tin the queue is to be overwritten then it does not matter if the\n\t\t\tqueue is full. */\n\t\t\tif( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\n\t\t\t{\n\t\t\t\ttraceQUEUE_SEND( pxQueue );\n\t\t\t\txYieldRequired = prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\n\n\t\t\t\t#if ( configUSE_QUEUE_SETS == 1 )\n\t\t\t\t{\n\t\t\t\t\tif( pxQueue->pxQueueSetContainer != NULL )\n\t\t\t\t\t{\n\t\t\t\t\t\tif( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) != pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* The queue is a member of a queue set, and posting\n\t\t\t\t\t\t\tto the queue set caused a higher priority task to\n\t\t\t\t\t\t\tunblock. A context switch is required. */\n\t\t\t\t\t\t\tqueueYIELD_IF_USING_PREEMPTION();\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t/* If there was a task waiting for data to arrive on the\n\t\t\t\t\t\tqueue then unblock it now. */\n\t\t\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t/* The unblocked task has a priority higher than\n\t\t\t\t\t\t\t\tour own so yield immediately.  Yes it is ok to\n\t\t\t\t\t\t\t\tdo this from within the critical section - the\n\t\t\t\t\t\t\t\tkernel takes care of that. */\n\t\t\t\t\t\t\t\tqueueYIELD_IF_USING_PREEMPTION();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if( xYieldRequired != pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* This path is a special case that will only get\n\t\t\t\t\t\t\texecuted if the task was holding multiple mutexes\n\t\t\t\t\t\t\tand the mutexes were given back in an order that is\n\t\t\t\t\t\t\tdifferent to that in which they were taken. */\n\t\t\t\t\t\t\tqueueYIELD_IF_USING_PREEMPTION();\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#else /* configUSE_QUEUE_SETS */\n\t\t\t\t{\n\t\t\t\t\t/* If there was a task waiting for data to arrive on the\n\t\t\t\t\tqueue then unblock it now. */\n\t\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* The unblocked task has a priority higher than\n\t\t\t\t\t\t\tour own so yield immediately.  Yes it is ok to do\n\t\t\t\t\t\t\tthis from within the critical section - the kernel\n\t\t\t\t\t\t\ttakes care of that. */\n\t\t\t\t\t\t\tqueueYIELD_IF_USING_PREEMPTION();\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse if( xYieldRequired != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* This path is a special case that will only get\n\t\t\t\t\t\texecuted if the task was holding multiple mutexes and\n\t\t\t\t\t\tthe mutexes were given back in an order that is\n\t\t\t\t\t\tdifferent to that in which they were taken. */\n\t\t\t\t\t\tqueueYIELD_IF_USING_PREEMPTION();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#endif /* configUSE_QUEUE_SETS */\n\n\t\t\t\ttaskEXIT_CRITICAL();\n\t\t\t\treturn pdPASS;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif( timeout == ( uint32_t ) 0 )\n\t\t\t\t{\n\t\t\t\t\t/* The queue was full and no block time is specified (or\n\t\t\t\t\tthe block time has expired) so leave now. */\n\t\t\t\t\ttaskEXIT_CRITICAL();\n\n\t\t\t\t\t/* Return to the original privilege level before exiting\n\t\t\t\t\tthe function. */\n\t\t\t\t\ttraceQUEUE_SEND_FAILED( pxQueue );\n\t\t\t\t\terrno = ENOSPC;\n\t\t\t\t\treturn errQUEUE_FULL;\n\t\t\t\t}\n\t\t\t\telse if( xEntryTimeSet == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t/* The queue was full and a block time was specified so\n\t\t\t\t\tconfigure the timeout structure. */\n\t\t\t\t\tvTaskInternalSetTimeOutState( &xTimeOut );\n\t\t\t\t\txEntryTimeSet = pdTRUE;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* Entry time was already set. */\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\t/* Interrupts and other tasks can send to and receive from the queue\n\t\tnow the critical section has been exited. */\n\n\t\trtos_suspend_all();\n\t\tprvLockQueue( pxQueue );\n\n\t\t/* Update the timeout state to see if it has expired yet. */\n\t\tif( xTaskCheckForTimeOut( &xTimeOut, &timeout ) == pdFALSE )\n\t\t{\n\t\t\tif( prvIsQueueFull( pxQueue ) != pdFALSE )\n\t\t\t{\n\t\t\t\ttraceBLOCKING_ON_QUEUE_SEND( pxQueue );\n\t\t\t\tvTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToSend ), timeout );\n\n\t\t\t\t/* Unlocking the queue means queue events can effect the\n\t\t\t\tevent list.  It is possible that interrupts occurring now\n\t\t\t\tremove this task from the event list again - but as the\n\t\t\t\tscheduler is suspended the task will go onto the pending\n\t\t\t\tready last instead of the actual ready list. */\n\t\t\t\tprvUnlockQueue( pxQueue );\n\n\t\t\t\t/* Resuming the scheduler will move tasks from the pending\n\t\t\t\tready list into the ready list - so it is feasible that this\n\t\t\t\ttask is already in a ready list before it yields - in which\n\t\t\t\tcase the yield will not cause a context switch unless there\n\t\t\t\tis also a higher priority task in the pending ready list. */\n\t\t\t\tif( rtos_resume_all() == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tportYIELD_WITHIN_API();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* Try again. */\n\t\t\t\tprvUnlockQueue( pxQueue );\n\t\t\t\t( void ) rtos_resume_all();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* The timeout has expired. */\n\t\t\tprvUnlockQueue( pxQueue );\n\t\t\t( void ) rtos_resume_all();\n\n\t\t\ttraceQUEUE_SEND_FAILED( pxQueue );\n\t\t\treturn errQUEUE_FULL;\n\t\t}\n\t}\n}\n/*-----------------------------------------------------------*/\n/** Queue Generic Send \"Macros\" **/\nbool queue_prepend(queue_t queue, const void* item, uint32_t timeout) {\n\treturn xQueueGenericSend(queue, item, timeout, queueSEND_TO_FRONT);\n}\nbool queue_append(queue_t queue, const void* item, uint32_t timeout) {\n\treturn xQueueGenericSend(queue, item, timeout, queueSEND_TO_BACK);\n}\n\nint32_t xQueueGenericSendFromISR( queue_t xQueue, const void * const pvItemToQueue, int32_t * const pxHigherPriorityTaskWoken, const int32_t xCopyPosition )\n{\nint32_t xReturn;\nuint32_t uxSavedInterruptStatus;\nQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n\tconfigASSERT( pxQueue );\n\tconfigASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( uint32_t ) 0U ) ) );\n\tconfigASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );\n\n\t/* RTOS ports that support interrupt nesting have the concept of a maximum\n\tsystem call (or maximum API call) interrupt priority.  Interrupts that are\n\tabove the maximum system call priority are kept permanently enabled, even\n\twhen the RTOS kernel is in a critical section, but cannot make any calls to\n\tFreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\n\tthen portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\n\tfailure if a FreeRTOS API function is called from an interrupt that has been\n\tassigned a priority above the configured maximum system call priority.\n\tOnly FreeRTOS functions that end in FromISR can be called from interrupts\n\tthat have been assigned a priority at or (logically) below the maximum\n\tsystem call\tinterrupt priority.  FreeRTOS maintains a separate interrupt\n\tsafe API to ensure interrupt entry is as fast and as simple as possible.\n\tMore information (albeit Cortex-M specific) is provided on the following\n\tlink: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\n\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID();\n\n\t/* Similar to xQueueGenericSend, except without blocking if there is no room\n\tin the queue.  Also don't directly wake a task that was blocked on a queue\n\tread, instead return a flag to say whether a context switch is required or\n\tnot (i.e. has a task with a higher priority than us been woken by this\n\tpost). */\n\tuxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\n\t{\n\t\tif( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) )\n\t\t{\n\t\t\tconst int8_t cTxLock = pxQueue->cTxLock;\n\n\t\t\ttraceQUEUE_SEND_FROM_ISR( pxQueue );\n\n\t\t\t/* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a\n\t\t\tsemaphore or mutex.  That means prvCopyDataToQueue() cannot result\n\t\t\tin a task disinheriting a priority and prvCopyDataToQueue() can be\n\t\t\tcalled here even though the disinherit function does not check if\n\t\t\tthe scheduler is suspended before accessing the ready lists. */\n\t\t\t( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\n\n\t\t\t/* The event list is not altered if the queue is locked.  This will\n\t\t\tbe done when the queue is unlocked later. */\n\t\t\tif( cTxLock == queueUNLOCKED )\n\t\t\t{\n\t\t\t\t#if ( configUSE_QUEUE_SETS == 1 )\n\t\t\t\t{\n\t\t\t\t\tif( pxQueue->pxQueueSetContainer != NULL )\n\t\t\t\t\t{\n\t\t\t\t\t\tif( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) != pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* The queue is a member of a queue set, and posting\n\t\t\t\t\t\t\tto the queue set caused a higher priority task to\n\t\t\t\t\t\t\tunblock.  A context switch is required. */\n\t\t\t\t\t\t\tif( pxHigherPriorityTaskWoken != NULL )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t*pxHigherPriorityTaskWoken = pdTRUE;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t/* The task waiting has a higher priority so\n\t\t\t\t\t\t\t\trecord that a context switch is required. */\n\t\t\t\t\t\t\t\tif( pxHigherPriorityTaskWoken != NULL )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t*pxHigherPriorityTaskWoken = pdTRUE;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#else /* configUSE_QUEUE_SETS */\n\t\t\t\t{\n\t\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* The task waiting has a higher priority so record that a\n\t\t\t\t\t\t\tcontext\tswitch is required. */\n\t\t\t\t\t\t\tif( pxHigherPriorityTaskWoken != NULL )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t*pxHigherPriorityTaskWoken = pdTRUE;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#endif /* configUSE_QUEUE_SETS */\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* Increment the lock count so the task that unlocks the queue\n\t\t\t\tknows that data was posted while it was locked. */\n\t\t\t\tpxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 );\n\t\t\t}\n\n\t\t\txReturn = pdPASS;\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttraceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );\n\t\t\txReturn = errQUEUE_FULL;\n\t\t}\n\t}\n\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nint32_t xQueueGiveFromISR( queue_t xQueue, int32_t * const pxHigherPriorityTaskWoken )\n{\nint32_t xReturn;\nuint32_t uxSavedInterruptStatus;\nQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n\t/* Similar to xQueueGenericSendFromISR() but used with semaphores where the\n\titem size is 0.  Don't directly wake a task that was blocked on a queue\n\tread, instead return a flag to say whether a context switch is required or\n\tnot (i.e. has a task with a higher priority than us been woken by this\n\tpost). */\n\n\tconfigASSERT( pxQueue );\n\n\t/* xQueueGenericSendFromISR() should be used instead of xQueueGiveFromISR()\n\tif the item size is not 0. */\n\tconfigASSERT( pxQueue->uxItemSize == 0 );\n\n\t/* Normally a mutex would not be given from an interrupt, especially if\n\tthere is a mutex holder, as priority inheritance makes no sense for an\n\tinterrupts, only tasks. */\n\tconfigASSERT( !( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && ( pxQueue->pxMutexHolder != NULL ) ) );\n\n\t/* RTOS ports that support interrupt nesting have the concept of a maximum\n\tsystem call (or maximum API call) interrupt priority.  Interrupts that are\n\tabove the maximum system call priority are kept permanently enabled, even\n\twhen the RTOS kernel is in a critical section, but cannot make any calls to\n\tFreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\n\tthen portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\n\tfailure if a FreeRTOS API function is called from an interrupt that has been\n\tassigned a priority above the configured maximum system call priority.\n\tOnly FreeRTOS functions that end in FromISR can be called from interrupts\n\tthat have been assigned a priority at or (logically) below the maximum\n\tsystem call\tinterrupt priority.  FreeRTOS maintains a separate interrupt\n\tsafe API to ensure interrupt entry is as fast and as simple as possible.\n\tMore information (albeit Cortex-M specific) is provided on the following\n\tlink: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\n\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID();\n\n\tuxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\n\t{\n\t\tconst uint32_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;\n\n\t\t/* When the queue is used to implement a semaphore no data is ever\n\t\tmoved through the queue but it is still valid to see if the queue 'has\n\t\tspace'. */\n\t\tif( uxMessagesWaiting < pxQueue->uxLength )\n\t\t{\n\t\t\tconst int8_t cTxLock = pxQueue->cTxLock;\n\n\t\t\ttraceQUEUE_SEND_FROM_ISR( pxQueue );\n\n\t\t\t/* A task can only have an inherited priority if it is a mutex\n\t\t\tholder - and if there is a mutex holder then the mutex cannot be\n\t\t\tgiven from an ISR.  As this is the ISR version of the function it\n\t\t\tcan be assumed there is no mutex holder and no need to determine if\n\t\t\tpriority disinheritance is needed.  Simply increase the count of\n\t\t\tmessages (semaphores) available. */\n\t\t\tpxQueue->uxMessagesWaiting = uxMessagesWaiting + ( uint32_t ) 1;\n\n\t\t\t/* The event list is not altered if the queue is locked.  This will\n\t\t\tbe done when the queue is unlocked later. */\n\t\t\tif( cTxLock == queueUNLOCKED )\n\t\t\t{\n\t\t\t\t#if ( configUSE_QUEUE_SETS == 1 )\n\t\t\t\t{\n\t\t\t\t\tif( pxQueue->pxQueueSetContainer != NULL )\n\t\t\t\t\t{\n\t\t\t\t\t\tif( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) != pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* The semaphore is a member of a queue set, and\n\t\t\t\t\t\t\tposting\tto the queue set caused a higher priority\n\t\t\t\t\t\t\ttask to\tunblock.  A context switch is required. */\n\t\t\t\t\t\t\tif( pxHigherPriorityTaskWoken != NULL )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t*pxHigherPriorityTaskWoken = pdTRUE;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t/* The task waiting has a higher priority so\n\t\t\t\t\t\t\t\trecord that a context switch is required. */\n\t\t\t\t\t\t\t\tif( pxHigherPriorityTaskWoken != NULL )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t*pxHigherPriorityTaskWoken = pdTRUE;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#else /* configUSE_QUEUE_SETS */\n\t\t\t\t{\n\t\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* The task waiting has a higher priority so record that a\n\t\t\t\t\t\t\tcontext\tswitch is required. */\n\t\t\t\t\t\t\tif( pxHigherPriorityTaskWoken != NULL )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t*pxHigherPriorityTaskWoken = pdTRUE;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#endif /* configUSE_QUEUE_SETS */\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* Increment the lock count so the task that unlocks the queue\n\t\t\t\tknows that data was posted while it was locked. */\n\t\t\t\tpxQueue->cTxLock = ( int8_t ) ( cTxLock + 1 );\n\t\t\t}\n\n\t\t\txReturn = pdPASS;\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttraceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );\n\t\t\txReturn = errQUEUE_FULL;\n\t\t}\n\t}\n\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nint32_t queue_recv(queue_t queue, void* const buffer, uint32_t timeout)\n{\nint32_t xEntryTimeSet = pdFALSE;\nTimeOut_t xTimeOut;\nQueue_t * const pxQueue = ( Queue_t * ) queue;\n\n\t/* Check the pointer is not NULL. */\n\tconfigASSERT( ( pxQueue ) );\n\n\t/* The buffer into which data is received can only be NULL if the data size\n\tis zero (so no data is copied into the buffer. */\n\tconfigASSERT( !( ( ( buffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( uint32_t ) 0U ) ) );\n\n\t/* Cannot block if the scheduler is suspended. */\n\t#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\n\t{\n\t\tconfigASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( timeout != 0 ) ) );\n\t}\n\t#endif\n\n\n\t/* This function relaxes the coding standard somewhat to allow return\n\tstatements within the function itself.  This is done in the interest\n\tof execution time efficiency. */\n\n\tfor( ;; )\n\t{\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\tconst uint32_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;\n\n\t\t\t/* Is there data in the queue now?  To be running the calling task\n\t\t\tmust be the highest priority task wanting to access the queue. */\n\t\t\tif( uxMessagesWaiting > ( uint32_t ) 0 )\n\t\t\t{\n\t\t\t\t/* Data available, remove one item. */\n\t\t\t\tprvCopyDataFromQueue( pxQueue, buffer );\n\t\t\t\ttraceQUEUE_RECEIVE( pxQueue );\n\t\t\t\tpxQueue->uxMessagesWaiting = uxMessagesWaiting - ( uint32_t ) 1;\n\n\t\t\t\t/* There is now space in the queue, were any tasks waiting to\n\t\t\t\tpost to the queue?  If so, unblock the highest priority waiting\n\t\t\t\ttask. */\n\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\tqueueYIELD_IF_USING_PREEMPTION();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\n\t\t\t\ttaskEXIT_CRITICAL();\n\t\t\t\treturn pdPASS;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif( timeout == ( uint32_t ) 0 )\n\t\t\t\t{\n\t\t\t\t\t/* The queue was empty and no block time is specified (or\n\t\t\t\t\tthe block time has expired) so leave now. */\n\t\t\t\t\ttaskEXIT_CRITICAL();\n\t\t\t\t\ttraceQUEUE_RECEIVE_FAILED( pxQueue );\n\t\t\t\t\treturn errQUEUE_EMPTY;\n\t\t\t\t}\n\t\t\t\telse if( xEntryTimeSet == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t/* The queue was empty and a block time was specified so\n\t\t\t\t\tconfigure the timeout structure. */\n\t\t\t\t\tvTaskInternalSetTimeOutState( &xTimeOut );\n\t\t\t\t\txEntryTimeSet = pdTRUE;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* Entry time was already set. */\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\t/* Interrupts and other tasks can send to and receive from the queue\n\t\tnow the critical section has been exited. */\n\n\t\trtos_suspend_all();\n\t\tprvLockQueue( pxQueue );\n\n\t\t/* Update the timeout state to see if it has expired yet. */\n\t\tif( xTaskCheckForTimeOut( &xTimeOut, &timeout ) == pdFALSE )\n\t\t{\n\t\t\t/* The timeout has not expired.  If the queue is still empty place\n\t\t\tthe task on the list of tasks waiting to receive from the queue. */\n\t\t\tif( prvIsQueueEmpty( pxQueue ) != pdFALSE )\n\t\t\t{\n\t\t\t\ttraceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\n\t\t\t\tvTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), timeout );\n\t\t\t\tprvUnlockQueue( pxQueue );\n\t\t\t\tif( rtos_resume_all() == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tportYIELD_WITHIN_API();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* The queue contains data again.  Loop back to try and read the\n\t\t\t\tdata. */\n\t\t\t\tprvUnlockQueue( pxQueue );\n\t\t\t\t( void ) rtos_resume_all();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* Timed out.  If there is no data in the queue exit, otherwise loop\n\t\t\tback and attempt to read the data. */\n\t\t\tprvUnlockQueue( pxQueue );\n\t\t\t( void ) rtos_resume_all();\n\n\t\t\tif( prvIsQueueEmpty( pxQueue ) != pdFALSE )\n\t\t\t{\n\t\t\t\ttraceQUEUE_RECEIVE_FAILED( pxQueue );\n\t\t\t\treturn errQUEUE_EMPTY;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t}\n}\n/*-----------------------------------------------------------*/\n\nint32_t xQueueSemaphoreTake( queue_t xQueue, uint32_t timeout )\n{\nint32_t xEntryTimeSet = pdFALSE;\nTimeOut_t xTimeOut;\nQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n#if( configUSE_MUTEXES == 1 )\n\tint32_t xInheritanceOccurred = pdFALSE;\n#endif\n\n\t/* Check the queue pointer is not NULL. */\n\tconfigASSERT( ( pxQueue ) );\n\n\t/* Check this really is a semaphore, in which case the item size will be\n\t0. */\n\tconfigASSERT( pxQueue->uxItemSize == 0 );\n\n\t/* Cannot block if the scheduler is suspended. */\n\t#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\n\t{\n\t\tconfigASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( timeout != 0 ) ) );\n\t}\n\t#endif\n\n\n\t/* This function relaxes the coding standard somewhat to allow return\n\tstatements within the function itself.  This is done in the interest\n\tof execution time efficiency. */\n\n\tfor( ;; )\n\t{\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\t/* Semaphores are queues with an item size of 0, and where the\n\t\t\tnumber of messages in the queue is the semaphore's count value. */\n\t\t\tconst uint32_t uxSemaphoreCount = pxQueue->uxMessagesWaiting;\n\n\t\t\t/* Is there data in the queue now?  To be running the calling task\n\t\t\tmust be the highest priority task wanting to access the queue. */\n\t\t\tif( uxSemaphoreCount > ( uint32_t ) 0 )\n\t\t\t{\n\t\t\t\ttraceQUEUE_RECEIVE( pxQueue );\n\n\t\t\t\t/* Semaphores are queues with a data size of zero and where the\n\t\t\t\tmessages waiting is the semaphore's count.  Reduce the count. */\n\t\t\t\tpxQueue->uxMessagesWaiting = uxSemaphoreCount - ( uint32_t ) 1;\n\n\t\t\t\t#if ( configUSE_MUTEXES == 1 )\n\t\t\t\t{\n\t\t\t\t\tif( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* Record the information required to implement\n\t\t\t\t\t\tpriority inheritance should it become necessary. */\n\t\t\t\t\t\tpxQueue->pxMutexHolder = ( int8_t * ) pvTaskIncrementMutexHeldCount(); /*lint !e961 Cast is not redundant as task_t is a typedef. */\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#endif /* configUSE_MUTEXES */\n\n\t\t\t\t/* Check to see if other tasks are blocked waiting to give the\n\t\t\t\tsemaphore, and if so, unblock the highest priority such task. */\n\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\tqueueYIELD_IF_USING_PREEMPTION();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\n\t\t\t\ttaskEXIT_CRITICAL();\n\t\t\t\treturn pdPASS;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif( timeout == ( uint32_t ) 0 )\n\t\t\t\t{\n\t\t\t\t\t/* For inheritance to have occurred there must have been an\n\t\t\t\t\tinitial timeout, and an adjusted timeout cannot become 0, as\n\t\t\t\t\tif it were 0 the function would have exited. */\n\t\t\t\t\t#if( configUSE_MUTEXES == 1 )\n\t\t\t\t\t{\n\t\t\t\t\t\tconfigASSERT( xInheritanceOccurred == pdFALSE );\n\t\t\t\t\t}\n\t\t\t\t\t#endif /* configUSE_MUTEXES */\n\n\t\t\t\t\t/* The semaphore count was 0 and no block time is specified\n\t\t\t\t\t(or the block time has expired) so exit now. */\n\t\t\t\t\ttaskEXIT_CRITICAL();\n\t\t\t\t\ttraceQUEUE_RECEIVE_FAILED( pxQueue );\n\t\t\t\t\treturn errQUEUE_EMPTY;\n\t\t\t\t}\n\t\t\t\telse if( xEntryTimeSet == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t/* The semaphore count was 0 and a block time was specified\n\t\t\t\t\tso configure the timeout structure ready to block. */\n\t\t\t\t\tvTaskInternalSetTimeOutState( &xTimeOut );\n\t\t\t\t\txEntryTimeSet = pdTRUE;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* Entry time was already set. */\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\t/* Interrupts and other tasks can give to and take from the semaphore\n\t\tnow the critical section has been exited. */\n\n\t\trtos_suspend_all();\n\t\tprvLockQueue( pxQueue );\n\n\t\t/* Update the timeout state to see if it has expired yet. */\n\t\tif( xTaskCheckForTimeOut( &xTimeOut, &timeout ) == pdFALSE )\n\t\t{\n\t\t\t/* A block time is specified and not expired.  If the semaphore\n\t\t\tcount is 0 then enter the Blocked state to wait for a semaphore to\n\t\t\tbecome available.  As semaphores are implemented with queues the\n\t\t\tqueue being empty is equivalent to the semaphore count being 0. */\n\t\t\tif( prvIsQueueEmpty( pxQueue ) != pdFALSE )\n\t\t\t{\n\t\t\t\ttraceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\n\n\t\t\t\t#if ( configUSE_MUTEXES == 1 )\n\t\t\t\t{\n\t\t\t\t\tif( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\n\t\t\t\t\t{\n\t\t\t\t\t\ttaskENTER_CRITICAL();\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\txInheritanceOccurred = xTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttaskEXIT_CRITICAL();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#endif\n\n\t\t\t\tvTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), timeout );\n\t\t\t\tprvUnlockQueue( pxQueue );\n\t\t\t\tif( rtos_resume_all() == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tportYIELD_WITHIN_API();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* There was no timeout and the semaphore count was not 0, so\n\t\t\t\tattempt to take the semaphore again. */\n\t\t\t\tprvUnlockQueue( pxQueue );\n\t\t\t\t( void ) rtos_resume_all();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* Timed out. */\n\t\t\tprvUnlockQueue( pxQueue );\n\t\t\t( void ) rtos_resume_all();\n\n\t\t\t/* If the semaphore count is 0 exit now as the timeout has\n\t\t\texpired.  Otherwise return to attempt to take the semaphore that is\n\t\t\tknown to be available.  As semaphores are implemented by queues the\n\t\t\tqueue being empty is equivalent to the semaphore count being 0. */\n\t\t\tif( prvIsQueueEmpty( pxQueue ) != pdFALSE )\n\t\t\t{\n\t\t\t\t#if ( configUSE_MUTEXES == 1 )\n\t\t\t\t{\n\t\t\t\t\t/* xInheritanceOccurred could only have be set if\n\t\t\t\t\tpxQueue->uxQueueType == queueQUEUE_IS_MUTEX so no need to\n\t\t\t\t\ttest the mutex type again to check it is actually a mutex. */\n\t\t\t\t\tif( xInheritanceOccurred != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\ttaskENTER_CRITICAL();\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tuint32_t uxHighestWaitingPriority;\n\n\t\t\t\t\t\t\t/* This task blocking on the mutex caused another\n\t\t\t\t\t\t\ttask to inherit this task's priority.  Now this task\n\t\t\t\t\t\t\thas timed out the priority should be disinherited\n\t\t\t\t\t\t\tagain, but only as low as the next highest priority\n\t\t\t\t\t\t\ttask that is waiting for the same mutex. */\n\t\t\t\t\t\t\tuxHighestWaitingPriority = prvGetDisinheritPriorityAfterTimeout( pxQueue );\n\t\t\t\t\t\t\tvTaskPriorityDisinheritAfterTimeout( ( void * ) pxQueue->pxMutexHolder, uxHighestWaitingPriority );\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttaskEXIT_CRITICAL();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#endif /* configUSE_MUTEXES */\n\n\t\t\t\ttraceQUEUE_RECEIVE_FAILED( pxQueue );\n\t\t\t\treturn errQUEUE_EMPTY;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t}\n}\n/*-----------------------------------------------------------*/\n\nint32_t queue_peek(queue_t queue, void* const buffer, uint32_t timeout)\n{\nint32_t xEntryTimeSet = pdFALSE;\nTimeOut_t xTimeOut;\nint8_t *pcOriginalReadPosition;\nQueue_t * const pxQueue = ( Queue_t * ) queue;\n\n\t/* Check the pointer is not NULL. */\n\tconfigASSERT( ( pxQueue ) );\n\n\t/* The buffer into which data is received can only be NULL if the data size\n\tis zero (so no data is copied into the buffer. */\n\tconfigASSERT( !( ( ( buffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( uint32_t ) 0U ) ) );\n\n\t/* Cannot block if the scheduler is suspended. */\n\t#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\n\t{\n\t\tconfigASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( timeout != 0 ) ) );\n\t}\n\t#endif\n\n\n\t/* This function relaxes the coding standard somewhat to allow return\n\tstatements within the function itself.  This is done in the interest\n\tof execution time efficiency. */\n\n\tfor( ;; )\n\t{\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\tconst uint32_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;\n\n\t\t\t/* Is there data in the queue now?  To be running the calling task\n\t\t\tmust be the highest priority task wanting to access the queue. */\n\t\t\tif( uxMessagesWaiting > ( uint32_t ) 0 )\n\t\t\t{\n\t\t\t\t/* Remember the read position so it can be reset after the data\n\t\t\t\tis read from the queue as this function is only peeking the\n\t\t\t\tdata, not removing it. */\n\t\t\t\tpcOriginalReadPosition = pxQueue->u.pcReadFrom;\n\n\t\t\t\tprvCopyDataFromQueue( pxQueue, buffer );\n\t\t\t\ttraceQUEUE_PEEK( pxQueue );\n\n\t\t\t\t/* The data is not being removed, so reset the read pointer. */\n\t\t\t\tpxQueue->u.pcReadFrom = pcOriginalReadPosition;\n\n\t\t\t\t/* The data is being left in the queue, so see if there are\n\t\t\t\tany other tasks waiting for the data. */\n\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The task waiting has a higher priority than this task. */\n\t\t\t\t\t\tqueueYIELD_IF_USING_PREEMPTION();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\n\t\t\t\ttaskEXIT_CRITICAL();\n\t\t\t\treturn pdPASS;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif( timeout == ( uint32_t ) 0 )\n\t\t\t\t{\n\t\t\t\t\t/* The queue was empty and no block time is specified (or\n\t\t\t\t\tthe block time has expired) so leave now. */\n\t\t\t\t\ttaskEXIT_CRITICAL();\n\t\t\t\t\ttraceQUEUE_PEEK_FAILED( pxQueue );\n\t\t\t\t\treturn errQUEUE_EMPTY;\n\t\t\t\t}\n\t\t\t\telse if( xEntryTimeSet == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t/* The queue was empty and a block time was specified so\n\t\t\t\t\tconfigure the timeout structure ready to enter the blocked\n\t\t\t\t\tstate. */\n\t\t\t\t\tvTaskInternalSetTimeOutState( &xTimeOut );\n\t\t\t\t\txEntryTimeSet = pdTRUE;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* Entry time was already set. */\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\t/* Interrupts and other tasks can send to and receive from the queue\n\t\tnow the critical section has been exited. */\n\n\t\trtos_suspend_all();\n\t\tprvLockQueue( pxQueue );\n\n\t\t/* Update the timeout state to see if it has expired yet. */\n\t\tif( xTaskCheckForTimeOut( &xTimeOut, &timeout ) == pdFALSE )\n\t\t{\n\t\t\t/* Timeout has not expired yet, check to see if there is data in the\n\t\t\tqueue now, and if not enter the Blocked state to wait for data. */\n\t\t\tif( prvIsQueueEmpty( pxQueue ) != pdFALSE )\n\t\t\t{\n\t\t\t\ttraceBLOCKING_ON_QUEUE_PEEK( pxQueue );\n\t\t\t\tvTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), timeout );\n\t\t\t\tprvUnlockQueue( pxQueue );\n\t\t\t\tif( rtos_resume_all() == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tportYIELD_WITHIN_API();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* There is data in the queue now, so don't enter the blocked\n\t\t\t\tstate, instead return to try and obtain the data. */\n\t\t\t\tprvUnlockQueue( pxQueue );\n\t\t\t\t( void ) rtos_resume_all();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* The timeout has expired.  If there is still no data in the queue\n\t\t\texit, otherwise go back and try to read the data again. */\n\t\t\tprvUnlockQueue( pxQueue );\n\t\t\t( void ) rtos_resume_all();\n\n\t\t\tif( prvIsQueueEmpty( pxQueue ) != pdFALSE )\n\t\t\t{\n\t\t\t\ttraceQUEUE_PEEK_FAILED( pxQueue );\n\t\t\t\treturn errQUEUE_EMPTY;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t}\n}\n/*-----------------------------------------------------------*/\n\nint32_t xQueueReceiveFromISR( queue_t xQueue, void * const buffer, int32_t * const pxHigherPriorityTaskWoken )\n{\nint32_t xReturn;\nuint32_t uxSavedInterruptStatus;\nQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n\tconfigASSERT( pxQueue );\n\tconfigASSERT( !( ( buffer == NULL ) && ( pxQueue->uxItemSize != ( uint32_t ) 0U ) ) );\n\n\t/* RTOS ports that support interrupt nesting have the concept of a maximum\n\tsystem call (or maximum API call) interrupt priority.  Interrupts that are\n\tabove the maximum system call priority are kept permanently enabled, even\n\twhen the RTOS kernel is in a critical section, but cannot make any calls to\n\tFreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\n\tthen portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\n\tfailure if a FreeRTOS API function is called from an interrupt that has been\n\tassigned a priority above the configured maximum system call priority.\n\tOnly FreeRTOS functions that end in FromISR can be called from interrupts\n\tthat have been assigned a priority at or (logically) below the maximum\n\tsystem call\tinterrupt priority.  FreeRTOS maintains a separate interrupt\n\tsafe API to ensure interrupt entry is as fast and as simple as possible.\n\tMore information (albeit Cortex-M specific) is provided on the following\n\tlink: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\n\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID();\n\n\tuxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\n\t{\n\t\tconst uint32_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;\n\n\t\t/* Cannot block in an ISR, so check there is data available. */\n\t\tif( uxMessagesWaiting > ( uint32_t ) 0 )\n\t\t{\n\t\t\tconst int8_t cRxLock = pxQueue->cRxLock;\n\n\t\t\ttraceQUEUE_RECEIVE_FROM_ISR( pxQueue );\n\n\t\t\tprvCopyDataFromQueue( pxQueue, buffer );\n\t\t\tpxQueue->uxMessagesWaiting = uxMessagesWaiting - ( uint32_t ) 1;\n\n\t\t\t/* If the queue is locked the event list will not be modified.\n\t\t\tInstead update the lock count so the task that unlocks the queue\n\t\t\twill know that an ISR has removed data while the queue was\n\t\t\tlocked. */\n\t\t\tif( cRxLock == queueUNLOCKED )\n\t\t\t{\n\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The task waiting has a higher priority than us so\n\t\t\t\t\t\tforce a context switch. */\n\t\t\t\t\t\tif( pxHigherPriorityTaskWoken != NULL )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t*pxHigherPriorityTaskWoken = pdTRUE;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* Increment the lock count so the task that unlocks the queue\n\t\t\t\tknows that data was removed while it was locked. */\n\t\t\t\tpxQueue->cRxLock = ( int8_t ) ( cRxLock + 1 );\n\t\t\t}\n\n\t\t\txReturn = pdPASS;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = pdFAIL;\n\t\t\ttraceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue );\n\t\t}\n\t}\n\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nint32_t xQueuePeekFromISR( queue_t xQueue,  void * const buffer )\n{\nint32_t xReturn;\nuint32_t uxSavedInterruptStatus;\nint8_t *pcOriginalReadPosition;\nQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n\tconfigASSERT( pxQueue );\n\tconfigASSERT( !( ( buffer == NULL ) && ( pxQueue->uxItemSize != ( uint32_t ) 0U ) ) );\n\tconfigASSERT( pxQueue->uxItemSize != 0 ); /* Can't peek a semaphore. */\n\n\t/* RTOS ports that support interrupt nesting have the concept of a maximum\n\tsystem call (or maximum API call) interrupt priority.  Interrupts that are\n\tabove the maximum system call priority are kept permanently enabled, even\n\twhen the RTOS kernel is in a critical section, but cannot make any calls to\n\tFreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\n\tthen portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\n\tfailure if a FreeRTOS API function is called from an interrupt that has been\n\tassigned a priority above the configured maximum system call priority.\n\tOnly FreeRTOS functions that end in FromISR can be called from interrupts\n\tthat have been assigned a priority at or (logically) below the maximum\n\tsystem call\tinterrupt priority.  FreeRTOS maintains a separate interrupt\n\tsafe API to ensure interrupt entry is as fast and as simple as possible.\n\tMore information (albeit Cortex-M specific) is provided on the following\n\tlink: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\n\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID();\n\n\tuxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\n\t{\n\t\t/* Cannot block in an ISR, so check there is data available. */\n\t\tif( pxQueue->uxMessagesWaiting > ( uint32_t ) 0 )\n\t\t{\n\t\t\ttraceQUEUE_PEEK_FROM_ISR( pxQueue );\n\n\t\t\t/* Remember the read position so it can be reset as nothing is\n\t\t\tactually being removed from the queue. */\n\t\t\tpcOriginalReadPosition = pxQueue->u.pcReadFrom;\n\t\t\tprvCopyDataFromQueue( pxQueue, buffer );\n\t\t\tpxQueue->u.pcReadFrom = pcOriginalReadPosition;\n\n\t\t\txReturn = pdPASS;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = pdFAIL;\n\t\t\ttraceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue );\n\t\t}\n\t}\n\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nuint32_t queue_get_waiting(const queue_t queue)\n{\nuint32_t uxReturn;\n\n\tconfigASSERT( queue );\n\n\ttaskENTER_CRITICAL();\n\t{\n\t\tuxReturn = ( ( Queue_t * ) queue )->uxMessagesWaiting;\n\t}\n\ttaskEXIT_CRITICAL();\n\n\treturn uxReturn;\n} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */\n/*-----------------------------------------------------------*/\n\nuint32_t queue_get_available(const queue_t queue)\n{\nuint32_t uxReturn;\nQueue_t *pxQueue;\n\n\tpxQueue = ( Queue_t * ) queue;\n\tconfigASSERT( pxQueue );\n\n\ttaskENTER_CRITICAL();\n\t{\n\t\tuxReturn = pxQueue->uxLength - pxQueue->uxMessagesWaiting;\n\t}\n\ttaskEXIT_CRITICAL();\n\n\treturn uxReturn;\n} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */\n/*-----------------------------------------------------------*/\n\nuint32_t uxQueueMessagesWaitingFromISR( const queue_t xQueue )\n{\nuint32_t uxReturn;\n\n\tconfigASSERT( xQueue );\n\n\tuxReturn = ( ( Queue_t * ) xQueue )->uxMessagesWaiting;\n\n\treturn uxReturn;\n} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */\n/*-----------------------------------------------------------*/\n\nvoid queue_delete(queue_t queue)\n{\nQueue_t * const pxQueue = ( Queue_t * ) queue;\n\n\tconfigASSERT( pxQueue );\n\ttraceQUEUE_DELETE( pxQueue );\n\n\t#if ( configQUEUE_REGISTRY_SIZE > 0 )\n\t{\n\t\tvQueueUnregisterQueue( pxQueue );\n\t}\n\t#endif\n\n\t#if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )\n\t{\n\t\t/* The queue can only have been allocated dynamically - free it\n\t\tagain. */\n\t\tkfree( pxQueue );\n\t}\n\t#elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\n\t{\n\t\t/* The queue could have been allocated statically or dynamically, so\n\t\tcheck before attempting to free the memory. */\n\t\tif( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdFALSE )\n\t\t{\n\t\t\tkfree( pxQueue );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\t#else\n\t{\n\t\t/* The queue must have been statically allocated, so is not going to be\n\t\tdeleted.  Avoid compiler warnings about the unused parameter. */\n\t\t( void ) pxQueue;\n\t}\n\t#endif /* configSUPPORT_DYNAMIC_ALLOCATION */\n}\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tuint32_t uxQueueGetQueueNumber( queue_t xQueue )\n\t{\n\t\treturn ( ( Queue_t * ) xQueue )->uxQueueNumber;\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tvoid vQueueSetQueueNumber( queue_t xQueue, uint32_t uxQueueNumber )\n\t{\n\t\t( ( Queue_t * ) xQueue )->uxQueueNumber = uxQueueNumber;\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tuint8_t ucQueueGetQueueType( queue_t xQueue )\n\t{\n\t\treturn ( ( Queue_t * ) xQueue )->ucQueueType;\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*-----------------------------------------------------------*/\n\n#if( configUSE_MUTEXES == 1 )\n\n\tstatic uint32_t prvGetDisinheritPriorityAfterTimeout( const Queue_t * const pxQueue )\n\t{\n\tuint32_t uxHighestPriorityOfWaitingTasks;\n\n\t\t/* If a task waiting for a mutex causes the mutex holder to inherit a\n\t\tpriority, but the waiting task times out, then the holder should\n\t\tdisinherit the priority - but only down to the highest priority of any\n\t\tother tasks that are waiting for the same mutex.  For this purpose,\n\t\treturn the priority of the highest priority task that is waiting for the\n\t\tmutex. */\n\t\tif( listCURRENT_LIST_LENGTH( &( pxQueue->xTasksWaitingToReceive ) ) > 0 )\n\t\t{\n\t\t\tuxHighestPriorityOfWaitingTasks = configMAX_PRIORITIES - listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( pxQueue->xTasksWaitingToReceive ) );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tuxHighestPriorityOfWaitingTasks = tskIDLE_PRIORITY;\n\t\t}\n\n\t\treturn uxHighestPriorityOfWaitingTasks;\n\t}\n\n#endif /* configUSE_MUTEXES */\n/*-----------------------------------------------------------*/\n\nstatic int32_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const int32_t xPosition )\n{\nint32_t xReturn = pdFALSE;\nuint32_t uxMessagesWaiting;\n\n\t/* This function is called from a critical section. */\n\n\tuxMessagesWaiting = pxQueue->uxMessagesWaiting;\n\n\tif( pxQueue->uxItemSize == ( uint32_t ) 0 )\n\t{\n\t\t#if ( configUSE_MUTEXES == 1 )\n\t\t{\n\t\t\tif( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\n\t\t\t{\n\t\t\t\t/* The mutex is no longer being held. */\n\t\t\t\txReturn = xTaskPriorityDisinherit( ( void * ) pxQueue->pxMutexHolder );\n\t\t\t\tpxQueue->pxMutexHolder = NULL;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\t#endif /* configUSE_MUTEXES */\n\t}\n\telse if( xPosition == queueSEND_TO_BACK )\n\t{\n\t\t( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0. */\n\t\tpxQueue->pcWriteTo += pxQueue->uxItemSize;\n\t\tif( pxQueue->pcWriteTo >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */\n\t\t{\n\t\t\tpxQueue->pcWriteTo = pxQueue->pcHead;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\telse\n\t{\n\t\t( void ) memcpy( ( void * ) pxQueue->u.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\t\tpxQueue->u.pcReadFrom -= pxQueue->uxItemSize;\n\t\tif( pxQueue->u.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */\n\t\t{\n\t\t\tpxQueue->u.pcReadFrom = ( pxQueue->pcTail - pxQueue->uxItemSize );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\tif( xPosition == queueOVERWRITE )\n\t\t{\n\t\t\tif( uxMessagesWaiting > ( uint32_t ) 0 )\n\t\t\t{\n\t\t\t\t/* An item is not being added but overwritten, so subtract\n\t\t\t\tone from the recorded number of items in the queue so when\n\t\t\t\tone is added again below the number of recorded items remains\n\t\t\t\tcorrect. */\n\t\t\t\t--uxMessagesWaiting;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\n\tpxQueue->uxMessagesWaiting = uxMessagesWaiting + ( uint32_t ) 1;\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const buffer )\n{\n\tif( pxQueue->uxItemSize != ( uint32_t ) 0 )\n\t{\n\t\tpxQueue->u.pcReadFrom += pxQueue->uxItemSize;\n\t\tif( pxQueue->u.pcReadFrom >= pxQueue->pcTail ) /*lint !e946 MISRA exception justified as use of the relational operator is the cleanest solutions. */\n\t\t{\n\t\t\tpxQueue->u.pcReadFrom = pxQueue->pcHead;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t\t( void ) memcpy( ( void * ) buffer, ( void * ) pxQueue->u.pcReadFrom, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 MISRA exception as the casts are only redundant for some ports.  Also previous logic ensures a null pointer can only be passed to memcpy() when the count is 0. */\n\t}\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvUnlockQueue( Queue_t * const pxQueue )\n{\n\t/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */\n\n\t/* The lock counts contains the number of extra data items placed or\n\tremoved from the queue while the queue was locked.  When a queue is\n\tlocked items can be added or removed, but the event lists cannot be\n\tupdated. */\n\ttaskENTER_CRITICAL();\n\t{\n\t\tint8_t cTxLock = pxQueue->cTxLock;\n\n\t\t/* See if data was added to the queue while it was locked. */\n\t\twhile( cTxLock > queueLOCKED_UNMODIFIED )\n\t\t{\n\t\t\t/* Data was posted while the queue was locked.  Are any tasks\n\t\t\tblocked waiting for data to become available? */\n\t\t\t#if ( configUSE_QUEUE_SETS == 1 )\n\t\t\t{\n\t\t\t\tif( pxQueue->pxQueueSetContainer != NULL )\n\t\t\t\t{\n\t\t\t\t\tif( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The queue is a member of a queue set, and posting to\n\t\t\t\t\t\tthe queue set caused a higher priority task to unblock.\n\t\t\t\t\t\tA context switch is required. */\n\t\t\t\t\t\tvTaskMissedYield();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* Tasks that are removed from the event list will get\n\t\t\t\t\tadded to the pending ready list as the scheduler is still\n\t\t\t\t\tsuspended. */\n\t\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* The task waiting has a higher priority so record that a\n\t\t\t\t\t\t\tcontext\tswitch is required. */\n\t\t\t\t\t\t\tvTaskMissedYield();\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t#else /* configUSE_QUEUE_SETS */\n\t\t\t{\n\t\t\t\t/* Tasks that are removed from the event list will get added to\n\t\t\t\tthe pending ready list as the scheduler is still suspended. */\n\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The task waiting has a higher priority so record that\n\t\t\t\t\t\ta context switch is required. */\n\t\t\t\t\t\tvTaskMissedYield();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t#endif /* configUSE_QUEUE_SETS */\n\n\t\t\t--cTxLock;\n\t\t}\n\n\t\tpxQueue->cTxLock = queueUNLOCKED;\n\t}\n\ttaskEXIT_CRITICAL();\n\n\t/* Do the same for the Rx lock. */\n\ttaskENTER_CRITICAL();\n\t{\n\t\tint8_t cRxLock = pxQueue->cRxLock;\n\n\t\twhile( cRxLock > queueLOCKED_UNMODIFIED )\n\t\t{\n\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\n\t\t\t{\n\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tvTaskMissedYield();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\n\t\t\t\t--cRxLock;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tpxQueue->cRxLock = queueUNLOCKED;\n\t}\n\ttaskEXIT_CRITICAL();\n}\n/*-----------------------------------------------------------*/\n\nstatic int32_t prvIsQueueEmpty( const Queue_t *pxQueue )\n{\nint32_t xReturn;\n\n\ttaskENTER_CRITICAL();\n\t{\n\t\tif( pxQueue->uxMessagesWaiting == ( uint32_t )  0 )\n\t\t{\n\t\t\txReturn = pdTRUE;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = pdFALSE;\n\t\t}\n\t}\n\ttaskEXIT_CRITICAL();\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nint32_t xQueueIsQueueEmptyFromISR( const queue_t xQueue )\n{\nint32_t xReturn;\n\n\tconfigASSERT( xQueue );\n\tif( ( ( Queue_t * ) xQueue )->uxMessagesWaiting == ( uint32_t ) 0 )\n\t{\n\t\txReturn = pdTRUE;\n\t}\n\telse\n\t{\n\t\txReturn = pdFALSE;\n\t}\n\n\treturn xReturn;\n} /*lint !e818 xQueue could not be pointer to const because it is a typedef. */\n/*-----------------------------------------------------------*/\n\nstatic int32_t prvIsQueueFull( const Queue_t *pxQueue )\n{\nint32_t xReturn;\n\n\ttaskENTER_CRITICAL();\n\t{\n\t\tif( pxQueue->uxMessagesWaiting == pxQueue->uxLength )\n\t\t{\n\t\t\txReturn = pdTRUE;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = pdFALSE;\n\t\t}\n\t}\n\ttaskEXIT_CRITICAL();\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nint32_t xQueueIsQueueFullFromISR( const queue_t xQueue )\n{\nint32_t xReturn;\n\n\tconfigASSERT( xQueue );\n\tif( ( ( Queue_t * ) xQueue )->uxMessagesWaiting == ( ( Queue_t * ) xQueue )->uxLength )\n\t{\n\t\txReturn = pdTRUE;\n\t}\n\telse\n\t{\n\t\txReturn = pdFALSE;\n\t}\n\n\treturn xReturn;\n} /*lint !e818 xQueue could not be pointer to const because it is a typedef. */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_CO_ROUTINES == 1 )\n\n\tint32_t xQueueCRSend( queue_t xQueue, const void *pvItemToQueue, uint32_t timeout )\n\t{\n\tint32_t xReturn;\n\tQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n\t\t/* If the queue is already full we may have to block.  A critical section\n\t\tis required to prevent an interrupt removing something from the queue\n\t\tbetween the check to see if the queue is full and blocking on the queue. */\n\t\tportDISABLE_INTERRUPTS();\n\t\t{\n\t\t\tif( prvIsQueueFull( pxQueue ) != pdFALSE )\n\t\t\t{\n\t\t\t\t/* The queue is full - do we want to block or just leave without\n\t\t\t\tposting? */\n\t\t\t\tif( timeout > ( uint32_t ) 0 )\n\t\t\t\t{\n\t\t\t\t\t/* As this is called from a coroutine we cannot block directly, but\n\t\t\t\t\treturn indicating that we need to block. */\n\t\t\t\t\tvCoRoutineAddToDelayedList( timeout, &( pxQueue->xTasksWaitingToSend ) );\n\t\t\t\t\tportENABLE_INTERRUPTS();\n\t\t\t\t\treturn errQUEUE_BLOCKED;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tportENABLE_INTERRUPTS();\n\t\t\t\t\treturn errQUEUE_FULL;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tportENABLE_INTERRUPTS();\n\n\t\tportDISABLE_INTERRUPTS();\n\t\t{\n\t\t\tif( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\n\t\t\t{\n\t\t\t\t/* There is room in the queue, copy the data into the queue. */\n\t\t\t\tprvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );\n\t\t\t\txReturn = pdPASS;\n\n\t\t\t\t/* Were any co-routines waiting for data to become available? */\n\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t/* In this instance the co-routine could be placed directly\n\t\t\t\t\tinto the ready list as we are within a critical section.\n\t\t\t\t\tInstead the same pending ready list mechanism is used as if\n\t\t\t\t\tthe event were caused from within an interrupt. */\n\t\t\t\t\tif( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The co-routine waiting has a higher priority so record\n\t\t\t\t\t\tthat a yield might be appropriate. */\n\t\t\t\t\t\txReturn = errQUEUE_YIELD;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\txReturn = errQUEUE_FULL;\n\t\t\t}\n\t\t}\n\t\tportENABLE_INTERRUPTS();\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_CO_ROUTINES */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_CO_ROUTINES == 1 )\n\n\tint32_t xQueueCRReceive( queue_t xQueue, void *buffer, uint32_t timeout )\n\t{\n\tint32_t xReturn;\n\tQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n\t\t/* If the queue is already empty we may have to block.  A critical section\n\t\tis required to prevent an interrupt adding something to the queue\n\t\tbetween the check to see if the queue is empty and blocking on the queue. */\n\t\tportDISABLE_INTERRUPTS();\n\t\t{\n\t\t\tif( pxQueue->uxMessagesWaiting == ( uint32_t ) 0 )\n\t\t\t{\n\t\t\t\t/* There are no messages in the queue, do we want to block or just\n\t\t\t\tleave with nothing? */\n\t\t\t\tif( timeout > ( uint32_t ) 0 )\n\t\t\t\t{\n\t\t\t\t\t/* As this is a co-routine we cannot block directly, but return\n\t\t\t\t\tindicating that we need to block. */\n\t\t\t\t\tvCoRoutineAddToDelayedList( timeout, &( pxQueue->xTasksWaitingToReceive ) );\n\t\t\t\t\tportENABLE_INTERRUPTS();\n\t\t\t\t\treturn errQUEUE_BLOCKED;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tportENABLE_INTERRUPTS();\n\t\t\t\t\treturn errQUEUE_FULL;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\tportENABLE_INTERRUPTS();\n\n\t\tportDISABLE_INTERRUPTS();\n\t\t{\n\t\t\tif( pxQueue->uxMessagesWaiting > ( uint32_t ) 0 )\n\t\t\t{\n\t\t\t\t/* Data is available from the queue. */\n\t\t\t\tpxQueue->u.pcReadFrom += pxQueue->uxItemSize;\n\t\t\t\tif( pxQueue->u.pcReadFrom >= pxQueue->pcTail )\n\t\t\t\t{\n\t\t\t\t\tpxQueue->u.pcReadFrom = pxQueue->pcHead;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t\t--( pxQueue->uxMessagesWaiting );\n\t\t\t\t( void ) memcpy( ( void * ) buffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\n\n\t\t\t\txReturn = pdPASS;\n\n\t\t\t\t/* Were any co-routines waiting for space to become available? */\n\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t/* In this instance the co-routine could be placed directly\n\t\t\t\t\tinto the ready list as we are within a critical section.\n\t\t\t\t\tInstead the same pending ready list mechanism is used as if\n\t\t\t\t\tthe event were caused from within an interrupt. */\n\t\t\t\t\tif( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\txReturn = errQUEUE_YIELD;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\txReturn = pdFAIL;\n\t\t\t}\n\t\t}\n\t\tportENABLE_INTERRUPTS();\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_CO_ROUTINES */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_CO_ROUTINES == 1 )\n\n\tint32_t xQueueCRSendFromISR( queue_t xQueue, const void *pvItemToQueue, int32_t xCoRoutinePreviouslyWoken )\n\t{\n\tQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n\t\t/* Cannot block within an ISR so if there is no space on the queue then\n\t\texit without doing anything. */\n\t\tif( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\n\t\t{\n\t\t\tprvCopyDataToQueue( pxQueue, pvItemToQueue, queueSEND_TO_BACK );\n\n\t\t\t/* We only want to wake one co-routine per ISR, so check that a\n\t\t\tco-routine has not already been woken. */\n\t\t\tif( xCoRoutinePreviouslyWoken == pdFALSE )\n\t\t\t{\n\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tif( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\treturn pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\treturn xCoRoutinePreviouslyWoken;\n\t}\n\n#endif /* configUSE_CO_ROUTINES */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_CO_ROUTINES == 1 )\n\n\tint32_t xQueueCRReceiveFromISR( queue_t xQueue, void *buffer, int32_t *pxCoRoutineWoken )\n\t{\n\tint32_t xReturn;\n\tQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n\t\t/* We cannot block from an ISR, so check there is data available. If\n\t\tnot then just leave without doing anything. */\n\t\tif( pxQueue->uxMessagesWaiting > ( uint32_t ) 0 )\n\t\t{\n\t\t\t/* Copy the data from the queue. */\n\t\t\tpxQueue->u.pcReadFrom += pxQueue->uxItemSize;\n\t\t\tif( pxQueue->u.pcReadFrom >= pxQueue->pcTail )\n\t\t\t{\n\t\t\t\tpxQueue->u.pcReadFrom = pxQueue->pcHead;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t\t--( pxQueue->uxMessagesWaiting );\n\t\t\t( void ) memcpy( ( void * ) buffer, ( void * ) pxQueue->u.pcReadFrom, ( unsigned ) pxQueue->uxItemSize );\n\n\t\t\tif( ( *pxCoRoutineWoken ) == pdFALSE )\n\t\t\t{\n\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tif( xCoRoutineRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\t*pxCoRoutineWoken = pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\n\t\t\txReturn = pdPASS;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = pdFAIL;\n\t\t}\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_CO_ROUTINES */\n/*-----------------------------------------------------------*/\n\n#if ( configQUEUE_REGISTRY_SIZE > 0 )\n\n\tvoid vQueueAddToRegistry( queue_t xQueue, const char *pcQueueName ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t{\n\tuint32_t ux;\n\n\t\t/* See if there is an empty space in the registry.  A NULL name denotes\n\t\ta free slot. */\n\t\tfor( ux = ( uint32_t ) 0U; ux < ( uint32_t ) configQUEUE_REGISTRY_SIZE; ux++ )\n\t\t{\n\t\t\tif( xQueueRegistry[ ux ].pcQueueName == NULL )\n\t\t\t{\n\t\t\t\t/* Store the information on this queue. */\n\t\t\t\txQueueRegistry[ ux ].pcQueueName = pcQueueName;\n\t\t\t\txQueueRegistry[ ux ].xHandle = xQueue;\n\n\t\t\t\ttraceQUEUE_REGISTRY_ADD( xQueue, pcQueueName );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t}\n\n#endif /* configQUEUE_REGISTRY_SIZE */\n/*-----------------------------------------------------------*/\n\n#if ( configQUEUE_REGISTRY_SIZE > 0 )\n\n\tconst char *pcQueueGetName( queue_t xQueue ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t{\n\tuint32_t ux;\n\tconst char *pcReturn = NULL; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\n\t\t/* Note there is nothing here to protect against another task adding or\n\t\tremoving entries from the registry while it is being searched. */\n\t\tfor( ux = ( uint32_t ) 0U; ux < ( uint32_t ) configQUEUE_REGISTRY_SIZE; ux++ )\n\t\t{\n\t\t\tif( xQueueRegistry[ ux ].xHandle == xQueue )\n\t\t\t{\n\t\t\t\tpcReturn = xQueueRegistry[ ux ].pcQueueName;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\n\t\treturn pcReturn;\n\t} /*lint !e818 xQueue cannot be a pointer to const because it is a typedef. */\n\n#endif /* configQUEUE_REGISTRY_SIZE */\n/*-----------------------------------------------------------*/\n\n#if ( configQUEUE_REGISTRY_SIZE > 0 )\n\n\tvoid vQueueUnregisterQueue( queue_t xQueue )\n\t{\n\tuint32_t ux;\n\n\t\t/* See if the handle of the queue being unregistered in actually in the\n\t\tregistry. */\n\t\tfor( ux = ( uint32_t ) 0U; ux < ( uint32_t ) configQUEUE_REGISTRY_SIZE; ux++ )\n\t\t{\n\t\t\tif( xQueueRegistry[ ux ].xHandle == xQueue )\n\t\t\t{\n\t\t\t\t/* Set the name to NULL to show that this slot if free again. */\n\t\t\t\txQueueRegistry[ ux ].pcQueueName = NULL;\n\n\t\t\t\t/* Set the handle to NULL to ensure the same queue handle cannot\n\t\t\t\tappear in the registry twice if it is added, removed, then\n\t\t\t\tadded again. */\n\t\t\t\txQueueRegistry[ ux ].xHandle = ( queue_t ) 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\n\t} /*lint !e818 xQueue could not be pointer to const because it is a typedef. */\n\n#endif /* configQUEUE_REGISTRY_SIZE */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TIMERS == 1 )\n\n\tvoid vQueueWaitForMessageRestricted( queue_t xQueue, uint32_t timeout, const int32_t xWaitIndefinitely )\n\t{\n\tQueue_t * const pxQueue = ( Queue_t * ) xQueue;\n\n\t\t/* This function should not be called by application code hence the\n\t\t'Restricted' in its name.  It is not part of the public API.  It is\n\t\tdesigned for use by kernel code, and has special calling requirements.\n\t\tIt can result in vListInsert() being called on a list that can only\n\t\tpossibly ever have one item in it, so the list will be fast, but even\n\t\tso it should be called with the scheduler locked and not from a critical\n\t\tsection. */\n\n\t\t/* Only do anything if there are no messages in the queue.  This function\n\t\twill not actually cause the task to block, just place it on a blocked\n\t\tlist.  It will not block until the scheduler is unlocked - at which\n\t\ttime a yield will be performed.  If an item is added to the queue while\n\t\tthe queue is locked, and the calling task blocks on the queue, then the\n\t\tcalling task will be immediately unblocked when the queue is unlocked. */\n\t\tprvLockQueue( pxQueue );\n\t\tif( pxQueue->uxMessagesWaiting == ( uint32_t ) 0U )\n\t\t{\n\t\t\t/* There is nothing in the queue, block for the specified period. */\n\t\t\tvTaskPlaceOnEventListRestricted( &( pxQueue->xTasksWaitingToReceive ), timeout, xWaitIndefinitely );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t\tprvUnlockQueue( pxQueue );\n\t}\n\n#endif /* configUSE_TIMERS */\n/*-----------------------------------------------------------*/\n\n#if( ( configUSE_QUEUE_SETS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\n\n\tQueueSetHandle_t xQueueCreateSet( const uint32_t uxEventQueueLength )\n\t{\n\tQueueSetHandle_t pxQueue;\n\n\t\tpxQueue = xQueueGenericCreate( uxEventQueueLength, ( uint32_t ) sizeof( Queue_t * ), queueQUEUE_TYPE_SET );\n\n\t\treturn pxQueue;\n\t}\n\n#endif /* configUSE_QUEUE_SETS */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_QUEUE_SETS == 1 )\n\n\tint32_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet )\n\t{\n\tint32_t xReturn;\n\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\tif( ( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer != NULL )\n\t\t\t{\n\t\t\t\t/* Cannot add a queue/semaphore to more than one queue set. */\n\t\t\t\txReturn = pdFAIL;\n\t\t\t}\n\t\t\telse if( ( ( Queue_t * ) xQueueOrSemaphore )->uxMessagesWaiting != ( uint32_t ) 0 )\n\t\t\t{\n\t\t\t\t/* Cannot add a queue/semaphore to a queue set if there are already\n\t\t\t\titems in the queue/semaphore. */\n\t\t\t\txReturn = pdFAIL;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t( ( Queue_t * ) xQueueOrSemaphore )->pxQueueSetContainer = xQueueSet;\n\t\t\t\txReturn = pdPASS;\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_QUEUE_SETS */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_QUEUE_SETS == 1 )\n\n\tint32_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet )\n\t{\n\tint32_t xReturn;\n\tQueue_t * const pxQueueOrSemaphore = ( Queue_t * ) xQueueOrSemaphore;\n\n\t\tif( pxQueueOrSemaphore->pxQueueSetContainer != xQueueSet )\n\t\t{\n\t\t\t/* The queue was not a member of the set. */\n\t\t\txReturn = pdFAIL;\n\t\t}\n\t\telse if( pxQueueOrSemaphore->uxMessagesWaiting != ( uint32_t ) 0 )\n\t\t{\n\t\t\t/* It is dangerous to remove a queue from a set when the queue is\n\t\t\tnot empty because the queue set will still hold pending events for\n\t\t\tthe queue. */\n\t\t\txReturn = pdFAIL;\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttaskENTER_CRITICAL();\n\t\t\t{\n\t\t\t\t/* The queue is no longer contained in the set. */\n\t\t\t\tpxQueueOrSemaphore->pxQueueSetContainer = NULL;\n\t\t\t}\n\t\t\ttaskEXIT_CRITICAL();\n\t\t\txReturn = pdPASS;\n\t\t}\n\n\t\treturn xReturn;\n\t} /*lint !e818 xQueueSet could not be declared as pointing to const as it is a typedef. */\n\n#endif /* configUSE_QUEUE_SETS */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_QUEUE_SETS == 1 )\n\n\tQueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet, uint32_t const timeout )\n\t{\n\tQueueSetMemberHandle_t xReturn = NULL;\n\n\t\t( void ) queue_recv( ( queue_t ) xQueueSet, &xReturn, timeout ); /*lint !e961 Casting from one typedef to another is not redundant. */\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_QUEUE_SETS */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_QUEUE_SETS == 1 )\n\n\tQueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet )\n\t{\n\tQueueSetMemberHandle_t xReturn = NULL;\n\n\t\t( void ) xQueueReceiveFromISR( ( queue_t ) xQueueSet, &xReturn, NULL ); /*lint !e961 Casting from one typedef to another is not redundant. */\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_QUEUE_SETS */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_QUEUE_SETS == 1 )\n\n\tstatic int32_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue, const int32_t xCopyPosition )\n\t{\n\tQueue_t *pxQueueSetContainer = pxQueue->pxQueueSetContainer;\n\tint32_t xReturn = pdFALSE;\n\n\t\t/* This function must be called form a critical section. */\n\n\t\tconfigASSERT( pxQueueSetContainer );\n\t\tconfigASSERT( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength );\n\n\t\tif( pxQueueSetContainer->uxMessagesWaiting < pxQueueSetContainer->uxLength )\n\t\t{\n\t\t\tconst int8_t cTxLock = pxQueueSetContainer->cTxLock;\n\n\t\t\ttraceQUEUE_SEND( pxQueueSetContainer );\n\n\t\t\t/* The data copied is the handle of the queue that contains data. */\n\t\t\txReturn = prvCopyDataToQueue( pxQueueSetContainer, &pxQueue, xCopyPosition );\n\n\t\t\tif( cTxLock == queueUNLOCKED )\n\t\t\t{\n\t\t\t\tif( listLIST_IS_EMPTY( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tif( xTaskRemoveFromEventList( &( pxQueueSetContainer->xTasksWaitingToReceive ) ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The task waiting has a higher priority. */\n\t\t\t\t\t\txReturn = pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpxQueueSetContainer->cTxLock = ( int8_t ) ( cTxLock + 1 );\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_QUEUE_SETS */\n"
  },
  {
    "path": "src/rtos/refactor.sh",
    "content": "# Change the current order of the awk print is to convert FreeRTOS style to PROS \n# style. Change from `$1, $2` to `$2, $1` to go the other way.\ncat src/rtos/refactor.tsv | dos2unix | awk '/^\\s*$/ {next;} {if(NR>1) { printf \"s/\\\\\\\\<%s\\\\\\\\>/%s/g\\n\", $1, $2 } }' | xargs -I '{}' zsh -c 'echo \"{}\"; sed -i \"{}\" **/*.(h|c|md|s|S|cpp|c++|cc)'\n"
  },
  {
    "path": "src/rtos/refactor.tsv",
    "content": "Original\t\t\tRefactored\nTaskHandle_t\t\ttask_t\nTaskFunction_t\t\ttask_fn_t\neTaskState\t\t\ttask_state_e_t\neRunning\t\t\tE_TASK_STATE_RUNNING\neReady\t\t\t\tE_TASK_STATE_READY\neBlocked\t\t\tE_TASK_STATE_BLOCKED\neSuspended\t\t\tE_TASK_STATE_SUSPENDED\neDeleted\t\t\tE_TASK_STATE_DELETED\neInvalid\t\t\tE_TASK_STATE_INVALID\neNotifyAction               notify_action_e_t\neNoAction                   E_NOTIFY_ACTION_NONE\neSetBits                    E_NOTIFY_ACTION_BITS\neIncrement                  E_NOTIFY_ACTION_INCR\neSetValueWithOverwrite      E_NOTIFY_ACTION_OWRITE\neSetValueWithoutOverwrite   E_NOTIFY_ACTION_NO_OWRITE\nQueueHandle_t\t\t        queue_t\nSemaphoreHandle_t\t        sem_t\nMutexHandle_t               mutex_t\nStackType_t                 task_stack_t\nStaticTask_t                static_task_s_t\nBaseType_t                  int32_t\nUBaseType_t                 uint32_t\nTickType_t\t\t\t\t\tuint32_t\nListItem_t\t\t\t\t\tlist_item_t\nStaticSemaphore_t   static_sem_s_t\nStaticQueue_t       static_queue_s_t\nStreamBufferHandle_t        stream_buf_t\nStaticStreamBuffer_t        static_stream_buf_s_t\nMessageBufferHandle_t       msg_buf_t\nStaticMessageBuffer_t       static_msg_buf_s_t\n\n\n\nxTaskCreate\t\t\ttask_create\nxTaskCreateStatic   task_create_static\nvTaskDelete\t\t\ttask_delete\nvTaskDelay\t\t\ttask_delay\nvTaskDelayUntil\t\ttask_delay_until\nuxTaskPriorityGet\ttask_get_priority\nvTaskPrioritySet\ttask_set_priority\neTaskGetState\t\ttask_get_state\nvTaskSuspend\t\ttask_suspend\nvTaskResume\t\t\ttask_resume\nxTaskAbortDelay      task_abort_delay\nvTaskStartScheduler\t\trtos_sched_start\nvTaskEndScheduler\t\trtos_sched_stop\nvTaskSuspendAll\t\t\trtos_suspend_all\nxTaskResumeAll\t\t\trtos_resume_all\nxTaskGetTickCount\t\tmillis\nuxTaskGetNumberOfTasks \ttask_get_count\npcTaskGetName\t\t\ttask_get_name\nxTaskGetHandle\t\t\ttask_get_by_name\nxTaskGenericNotify\t\ttask_notify_ext\nulTaskNotifyTake\t\ttask_notify_take\nxTaskNotifyWait\t\t\ttask_notify_wait\nxTaskNotifyStateClear\ttask_notify_clear\nxTaskGetCurrentTaskHandle\t\t\ttask_get_current\nxQueueCreate\t\t\tqueue_create\nxQueueSendToFront\t\tqueue_prepend\nxQueueSendToBack\t\tqueue_append\nxQueueOverwrite\t\t\tqueue_overwrite\nxQueuePeek\t\t\t\tqueue_peek\nxQueueReceive\t\t\tqueue_recv\nuxQueueMessagesWaiting\tqueue_get_waiting\nuxQueueSpacesAvailable\tqueue_get_available\nvQueueDelete\t\t\tqueue_delete\nxSemaphoreCreateBinary\tsem_binary_create\nxSemaphoreTake\t\t\tsem_wait\nxSemaphoreTakeRecursive\t\t\tmutex_recursive_take\nxSemaphoreGive\t\t\t\t\tsem_post\nxSemaphoreGiveRecursive\t\t\tmutex_recursive_give\nxSemaphoreCreateMutex\t\t\tmutex_create\nxSemaphoreCreateRecursiveMutex\tmutex_recursive_create\nxSemaphoreCreateCounting\t\tsem_create\nvSemaphoreDelete\t\t\tsem_delete\nxSemaphoreGetMutexHolder\tmutex_get_owner\nuxSemaphoreGetCount\t\t\tsem_get_count\npvPortMalloc                kmalloc\nvPortFree                   kfree\nxSemaphoreCreateMutexStatic     mutex_create_static\nxSemaphoreCreateCountingStatic  sem_create_static\nxQueueCreateStatic              queue_create_static\nxStreamBufferCreateStatic       stream_buf_create_static\nxStreamBufferCreate             stream_buf_create\nxStreamBufferSend               stream_buf_send\nxStreamBufferReceive            stream_buf_recv\nxStreamBufferDelete             stream_buf_delete\nxStreamBufferBytesAvailable     stream_buf_get_used\nxStreamBufferSpacesAvailable    stream_buf_get_unused\nxStreamBufferSetTriggerLevel    stream_buf_set_trigger\nxStreamBufferReset              stream_buf_reset\nxStreamBufferIsEmpty            stream_buf_is_empty\nxStreamBufferIsFull             stream_buf_is_full\nxMessageBufferSend              msg_buf_send\nxMessageBufferReceive           msg_buf_recv\nxMessageBufferDelete            msg_buf_delete\nxMessageBufferSpacesAvailable   msg_buf_get_unused\nxMessageBufferReset             msg_buf_reset\nxMessageBufferIsEmpty           msg_buf_is_empty\nxMessageBufferIsFull            msg_buf_is_full\n"
  },
  {
    "path": "src/rtos/rtos.cpp",
    "content": "/**\n * \\file rtos/rtos.cpp\n *\n * Contains functions for the PROS RTOS kernel for use by typical\n * VEX programmers.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"pros/rtos.hpp\"\n\n#include <atomic>\n#include <system_error>\n\n#include \"kapi.h\"\n#include \"system/optimizers.h\"\n\n/* definitions needed from task.h, since directly including it conflicts with definitions in pros/rtos.h */\n\n#define taskENTER_CRITICAL()\t\tportENTER_CRITICAL()\n#define taskEXIT_CRITICAL()\t\t\tportEXIT_CRITICAL()\n\nnamespace pros {\nusing namespace pros::c;\n\nTask::Task(task_fn_t function, void* parameters, std::uint32_t prio, std::uint16_t stack_depth, const char* name) {\n\ttask = task_create(function, parameters, prio, stack_depth, name);\n}\n\nTask::Task(task_fn_t function, void* parameters, const char* name)\n    : Task(function, parameters, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, name) {}\n\nTask::Task(task_t task) : task(task) {}\nTask& Task::operator=(const task_t in) {\n\ttask = in;\n\treturn *this;\n}\n\nTask Task::current() {\n\treturn Task{task_get_current()};\n}\n\nvoid Task::remove() {\n\treturn task_delete(task);\n}\n\nstd::uint32_t Task::get_priority() {\n\treturn task_get_priority(task);\n}\n\nvoid Task::set_priority(std::uint32_t prio) {\n\ttask_set_priority(task, prio);\n}\n\nstd::uint32_t Task::get_state() {\n\treturn task_get_state(task);\n}\n\nvoid Task::suspend() {\n\ttask_suspend(task);\n}\n\nvoid Task::resume() {\n\ttask_resume(task);\n}\n\nconst char* Task::get_name() {\n\treturn task_get_name(task);\n}\n\nstd::uint32_t Task::notify() {\n\treturn task_notify(task);\n}\n\nvoid Task::join() {\n\treturn task_join(task);\n}\n\nstd::uint32_t Task::notify_ext(std::uint32_t value, notify_action_e_t action, std::uint32_t* prev_value) {\n\treturn task_notify_ext(task, value, action, prev_value);\n}\n\nstd::uint32_t Task::notify_take(bool clear_on_exit, std::uint32_t timeout) {\n\treturn task_notify_take(clear_on_exit, timeout);\n}\n\nbool Task::notify_clear() {\n\treturn task_notify_clear(task);\n}\n\nvoid Task::delay(const std::uint32_t milliseconds) {\n\ttask_delay(milliseconds);\n}\n\nvoid Task::delay_until(std::uint32_t* const prev_time, const std::uint32_t delta) {\n\ttask_delay_until(prev_time, delta);\n}\n\nstd::uint32_t Task::get_count() {\n\treturn task_get_count();\n}\n\nClock::time_point Clock::now() {\n\treturn Clock::time_point{Clock::duration{millis()}};\n}\n\nmutex_t Mutex::lazy_init() {\n\t\tmutex_t _mutex;\n\t\tif(unlikely((_mutex = mutex.load(std::memory_order::relaxed)) == nullptr)) {\n\t\t\ttaskENTER_CRITICAL();\n\t\t\tif(likely((_mutex = mutex.load()) == nullptr)) {\t\n\t\t\t\tmutex.store((_mutex = pros::c::mutex_create()));\n\t\t\t}\n\t\t\ttaskEXIT_CRITICAL();\n\t\t}\n\t\treturn _mutex;\n}\n\nbool Mutex::take() {\n\treturn mutex_take(lazy_init(), TIMEOUT_MAX);\n}\n\nbool Mutex::take(std::uint32_t timeout) {\n\treturn mutex_take(lazy_init(), timeout);\n}\n\nbool Mutex::give() {\n\treturn mutex_give(lazy_init());\n}\n\nvoid Mutex::lock() {\n\tif (!take(TIMEOUT_MAX)) {\n\t\tthrow std::system_error(errno, std::system_category(), \"Cannot obtain lock!\");\n\t}\n}\n\nvoid Mutex::unlock() {\n\tgive();\n}\n\nbool Mutex::try_lock() {\n\treturn take(0);\n}\n\nMutex::~Mutex() {\n\tmutex_t _mutex = mutex.exchange(reinterpret_cast<mutex_t>(~0));\n\tpros::c::mutex_delete(_mutex);\n}\n\nmutex_t RecursiveMutex::lazy_init() {\n\t\tmutex_t _mutex;\n\t\tif(unlikely((_mutex = mutex.load(std::memory_order::relaxed)) == nullptr)) {\n\t\t\ttaskENTER_CRITICAL();\n\t\t\tif(likely((_mutex = mutex.load()) == nullptr)) {\t\n\t\t\t\tmutex.store((_mutex = pros::c::mutex_recursive_create()));\n\t\t\t}\n\t\t\ttaskEXIT_CRITICAL();\n\t\t}\n\t\treturn _mutex;\n}\n\nbool RecursiveMutex::take() {\n\treturn mutex_recursive_take(lazy_init(), TIMEOUT_MAX);\n}\n\nbool RecursiveMutex::take(std::uint32_t timeout) {\n\treturn mutex_recursive_take(lazy_init(), timeout);\n}\n\nbool RecursiveMutex::give() {\n\treturn mutex_recursive_give(lazy_init());\n}\n\nvoid RecursiveMutex::lock() {\n\tif (!take(TIMEOUT_MAX)) {\n\t\tthrow std::system_error(errno, std::system_category(), \"Cannot obtain lock!\");\n\t}\n}\n\nvoid RecursiveMutex::unlock() {\n\tgive();\n}\n\nbool RecursiveMutex::try_lock() {\n\treturn take(0);\n}\n\nRecursiveMutex::~RecursiveMutex() {\n\tmutex_t _mutex = mutex.exchange(reinterpret_cast<mutex_t>(~0));\n\tpros::c::mutex_delete(_mutex);\n}\n}  // namespace pros\n"
  },
  {
    "path": "src/rtos/semphr.c",
    "content": "#include \"FreeRTOS.h\"\n#include \"semphr.h\"\n\n/**\n * semphr. h\n * <pre>sem_wait(\n *                   sem_t sem,\n *                   uint32_t xBlockTime\n *               )</pre>\n *\n * <i>Macro</i> to obtain a semaphore.  The semaphore must have previously been\n * created with a call to sem_binary_create(), mutex_create() or\n * sem_create().\n *\n * @param sem A handle to the semaphore being taken - obtained when\n * the semaphore was created.\n *\n * @param xBlockTime The time in ticks to wait for the semaphore to become\n * available.  The macro portTICK_PERIOD_MS can be used to convert this to a\n * real time.  A block time of zero can be used to poll the semaphore.  A block\n * time of portMAX_DELAY can be used to block indefinitely (provided\n * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h).\n *\n * @return pdTRUE if the semaphore was obtained.  pdFALSE\n * if xBlockTime expired without the semaphore becoming available.\n *\n * Example usage:\n <pre>\n sem_t sem = NULL;\n\n // A task that creates a semaphore.\n void vATask( void * pvParameters )\n {\n    // Create the semaphore to guard a shared resource.\n    sem = sem_binary_create();\n }\n\n // A task that uses the semaphore.\n void vAnotherTask( void * pvParameters )\n {\n    // ... Do other things.\n\n    if( sem != NULL )\n    {\n        // See if we can obtain the semaphore.  If the semaphore is not available\n        // wait 10 ticks to see if it becomes free.\n        if( sem_wait( sem, ( uint32_t ) 10 ) == pdTRUE )\n        {\n            // We were able to obtain the semaphore and can now access the\n            // shared resource.\n\n            // ...\n\n            // We have finished accessing the shared resource.  Release the\n            // semaphore.\n            sem_post( sem );\n        }\n        else\n        {\n            // We could not obtain the semaphore and can therefore not access\n            // the shared resource safely.\n        }\n    }\n }\n </pre>\n * \\defgroup sem_wait sem_wait\n * \\ingroup Semaphores\n */\nuint8_t sem_wait(sem_t sem, uint32_t timeout) {\n\treturn xQueueSemaphoreTake( ( sem ), ( timeout ) );\n}\n\n/**\n * semphr. h\n * <pre>sem_post( sem_t sem )</pre>\n *\n * <i>Macro</i> to release a semaphore.  The semaphore must have previously been\n * created with a call to sem_binary_create(), mutex_create() or\n * sem_create(). and obtained using sSemaphoreTake().\n *\n * This macro must not be used from an ISR.  See semGiveFromISR () for\n * an alternative which can be used from an ISR.\n *\n * This macro must also not be used on semaphores created using\n * mutex_recursive_create().\n *\n * @param sem A handle to the semaphore being released.  This is the\n * handle returned when the semaphore was created.\n *\n * @return pdTRUE if the semaphore was released.  pdFALSE if an error occurred.\n * Semaphores are implemented using queues.  An error can occur if there is\n * no space on the queue to post a message - indicating that the\n * semaphore was not first obtained correctly.\n *\n * Example usage:\n <pre>\n sem_t sem = NULL;\n\n void vATask( void * pvParameters )\n {\n    // Create the semaphore to guard a shared resource.\n    sem = vSemaphoreCreateBinary();\n\n    if( sem != NULL )\n    {\n        if( sem_post( sem ) != pdTRUE )\n        {\n            // We would expect this call to fail because we cannot give\n            // a semaphore without first \"taking\" it!\n        }\n\n        // Obtain the semaphore - don't block if the semaphore is not\n        // immediately available.\n        if( sem_wait( sem, ( uint32_t ) 0 ) )\n        {\n            // We now have the semaphore and can access the shared resource.\n\n            // ...\n\n            // We have finished accessing the shared resource so can free the\n            // semaphore.\n            if( sem_post( sem ) != pdTRUE )\n            {\n                // We would not expect this call to fail because we must have\n                // obtained the semaphore to get here.\n            }\n        }\n    }\n }\n </pre>\n * \\defgroup sem_post sem_post\n * \\ingroup Semaphores\n */\nuint8_t sem_post(sem_t sem) {\n\treturn xQueueGenericSend((queue_t)(sem), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK);\n}\n\n/**\n * semphr. h\n * <pre>sem_t mutex_create( void )</pre>\n *\n * Creates a new mutex type semaphore instance, and returns a handle by which\n * the new mutex can be referenced.\n *\n * Internally, within the FreeRTOS implementation, mutex semaphores use a block\n * of memory, in which the mutex structure is stored.  If a mutex is created\n * using mutex_create() then the required memory is automatically\n * dynamically allocated inside the mutex_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a mutex is created using\n * mutex_create_static() then the application writer must provided the\n * memory.  mutex_create_static() therefore allows a mutex to be created\n * without using any dynamic memory allocation.\n *\n * Mutexes created using this function can be accessed using the sem_wait()\n * and sem_post() macros.  The mutex_recursive_take() and\n * mutex_recursive_give() macros must not be used.\n *\n * This type of semaphore uses a priority inheritance mechanism so a task\n * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the\n * semaphore it is no longer required.\n *\n * Mutex type semaphores cannot be used from within interrupt service routines.\n *\n * See sem_binary_create() for an alternative implementation that can be\n * used for pure synchronisation (where one task or interrupt always 'gives' the\n * semaphore and another always 'takes' the semaphore) and from within interrupt\n * service routines.\n *\n * @return If the mutex was successfully created then a handle to the created\n * semaphore is returned.  If there was not enough heap to allocate the mutex\n * data structures then NULL is returned.\n *\n * Example usage:\n <pre>\n sem_t sem;\n\n void vATask( void * pvParameters )\n {\n    // Semaphore cannot be used before a call to mutex_create().\n    // This is a macro so pass the variable in directly.\n    sem = mutex_create();\n\n    if( sem != NULL )\n    {\n        // The semaphore was created successfully.\n        // The semaphore can now be used.\n    }\n }\n </pre>\n * \\defgroup mutex_create mutex_create\n * \\ingroup Semaphores\n */\nmutex_t mutex_create(void) {\n\treturn (mutex_t)xQueueCreateMutex(queueQUEUE_TYPE_MUTEX);\n}\n\nuint8_t mutex_give(mutex_t mutex) {\n\treturn xQueueGenericSend((queue_t)(mutex), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK);\n}\n\nuint8_t mutex_take(mutex_t mutex, uint32_t timeout) {\n\treturn xQueueSemaphoreTake( ( mutex ), ( timeout ) );\n}\n\nvoid mutex_delete(mutex_t mutex){\n  sem_delete((sem_t)(mutex));\n}\n\n/**\n * semphr. h\n * <pre>sem_t sem_binary_create( void )</pre>\n *\n * Creates a new binary semaphore instance, and returns a handle by which the\n * new semaphore can be referenced.\n *\n * In many usage scenarios it is faster and more memory efficient to use a\n * direct to task notification in place of a binary semaphore!\n * http://www.freertos.org/RTOS-task-notifications.html\n *\n * Internally, within the FreeRTOS implementation, binary semaphores use a block\n * of memory, in which the semaphore structure is stored.  If a binary semaphore\n * is created using sem_binary_create() then the required memory is\n * automatically dynamically allocated inside the sem_binary_create()\n * function.  (see http://www.freertos.org/a00111.html).  If a binary semaphore\n * is created using semCreateBinaryStatic() then the application writer\n * must provide the memory.  semCreateBinaryStatic() therefore allows a\n * binary semaphore to be created without using any dynamic memory allocation.\n *\n * The old vSemaphoreCreateBinary() macro is now deprecated in favour of this\n * sem_binary_create() function.  Note that binary semaphores created using\n * the vSemaphoreCreateBinary() macro are created in a state such that the\n * first call to 'take' the semaphore would pass, whereas binary semaphores\n * created using sem_binary_create() are created in a state such that the\n * the semaphore must first be 'given' before it can be 'taken'.\n *\n * This type of semaphore can be used for pure synchronisation between tasks or\n * between an interrupt and a task.  The semaphore need not be given back once\n * obtained, so one task/interrupt can continuously 'give' the semaphore while\n * another continuously 'takes' the semaphore.  For this reason this type of\n * semaphore does not use a priority inheritance mechanism.  For an alternative\n * that does use priority inheritance see mutex_create().\n *\n * @return Handle to the created semaphore, or NULL if the memory required to\n * hold the semaphore's data structures could not be allocated.\n *\n * Example usage:\n <pre>\n sem_t sem = NULL;\n\n void vATask( void * pvParameters )\n {\n    // Semaphore cannot be used before a call to sem_binary_create().\n    // This is a macro so pass the variable in directly.\n    sem = sem_binary_create();\n\n    if( sem != NULL )\n    {\n        // The semaphore was created successfully.\n        // The semaphore can now be used.\n    }\n }\n </pre>\n * \\defgroup sem_binary_create sem_binary_create\n * \\ingroup Semaphores\n */\nsem_t sem_binary_create(void) {\n\treturn xQueueGenericCreate((uint32_t)1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE);\n}\n\n/**\n * semphr. h\n * <pre>sem_t mutex_recursive_create( void )</pre>\n *\n * Creates a new recursive mutex type semaphore instance, and returns a handle\n * by which the new recursive mutex can be referenced.\n *\n * Internally, within the FreeRTOS implementation, recursive mutexs use a block\n * of memory, in which the mutex structure is stored.  If a recursive mutex is\n * created using mutex_recursive_create() then the required memory is\n * automatically dynamically allocated inside the\n * mutex_recursive_create() function.  (see\n * http://www.freertos.org/a00111.html).  If a recursive mutex is created using\n * semCreateRecursiveMutexStatic() then the application writer must\n * provide the memory that will get used by the mutex.\n * semCreateRecursiveMutexStatic() therefore allows a recursive mutex to\n * be created without using any dynamic memory allocation.\n *\n * Mutexes created using this macro can be accessed using the\n * mutex_recursive_take() and mutex_recursive_give() macros.  The\n * sem_wait() and sem_post() macros must not be used.\n *\n * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex\n * doesn't become available again until the owner has called\n * mutex_recursive_give() for each successful 'take' request.  For example,\n * if a task successfully 'takes' the same mutex 5 times then the mutex will\n * not be available to any other task until it has also  'given' the mutex back\n * exactly five times.\n *\n * This type of semaphore uses a priority inheritance mechanism so a task\n * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the\n * semaphore it is no longer required.\n *\n * Mutex type semaphores cannot be used from within interrupt service routines.\n *\n * See sem_binary_create() for an alternative implementation that can be\n * used for pure synchronisation (where one task or interrupt always 'gives' the\n * semaphore and another always 'takes' the semaphore) and from within interrupt\n * service routines.\n *\n * @return sem Handle to the created mutex semaphore.  Should be of type\n * sem_t.\n *\n * Example usage:\n <pre>\n sem_t sem;\n\n void vATask( void * pvParameters )\n {\n    // Semaphore cannot be used before a call to mutex_create().\n    // This is a macro so pass the variable in directly.\n    sem = mutex_recursive_create();\n\n    if( sem != NULL )\n    {\n        // The semaphore was created successfully.\n        // The semaphore can now be used.\n    }\n }\n </pre>\n * \\defgroup mutex_recursive_create mutex_recursive_create\n * \\ingroup Semaphores\n */\nmutex_t mutex_recursive_create(void) {\n\treturn xQueueCreateMutex(queueQUEUE_TYPE_RECURSIVE_MUTEX);\n}\n\n/**\n * semphr. h\n * <pre>mutex_recursive_give( sem_t xMutex )</pre>\n *\n * <i>Macro</i> to recursively release, or 'give', a mutex type semaphore.\n * The mutex must have previously been created using a call to\n * mutex_recursive_create();\n *\n * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this\n * macro to be available.\n *\n * This macro must not be used on mutexes created using mutex_create().\n *\n * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex\n * doesn't become available again until the owner has called\n * mutex_recursive_give() for each successful 'take' request.  For example,\n * if a task successfully 'takes' the same mutex 5 times then the mutex will\n * not be available to any other task until it has also  'given' the mutex back\n * exactly five times.\n *\n * @param xMutex A handle to the mutex being released, or 'given'.  This is the\n * handle returned by mutex_create();\n *\n * @return pdTRUE if the semaphore was given.\n *\n * Example usage:\n <pre>\n sem_t xMutex = NULL;\n\n // A task that creates a mutex.\n void vATask( void * pvParameters )\n {\n    // Create the mutex to guard a shared resource.\n    xMutex = mutex_recursive_create();\n }\n\n // A task that uses the mutex.\n void vAnotherTask( void * pvParameters )\n {\n    // ... Do other things.\n\n    if( xMutex != NULL )\n    {\n        // See if we can obtain the mutex.  If the mutex is not available\n        // wait 10 ticks to see if it becomes free.\n        if( mutex_recursive_take( xMutex, ( uint32_t ) 10 ) == pdTRUE )\n        {\n            // We were able to obtain the mutex and can now access the\n            // shared resource.\n\n            // ...\n            // For some reason due to the nature of the code further calls to\n                        // mutex_recursive_take() are made on the same mutex.  In real\n                        // code these would not be just sequential calls as this would make\n                        // no sense.  Instead the calls are likely to be buried inside\n                        // a more complex call structure.\n            mutex_recursive_take( xMutex, ( uint32_t ) 10 );\n            mutex_recursive_take( xMutex, ( uint32_t ) 10 );\n\n            // The mutex has now been 'taken' three times, so will not be\n                        // available to another task until it has also been given back\n                        // three times.  Again it is unlikely that real code would have\n                        // these calls sequentially, it would be more likely that the calls\n                        // to mutex_recursive_give() would be called as a call stack\n                        // unwound.  This is just for demonstrative purposes.\n            mutex_recursive_give( xMutex );\n                        mutex_recursive_give( xMutex );\n                        mutex_recursive_give( xMutex );\n\n                        // Now the mutex can be taken by other tasks.\n        }\n        else\n        {\n            // We could not obtain the mutex and can therefore not access\n            // the shared resource safely.\n        }\n    }\n }\n </pre>\n * \\defgroup mutex_recursive_give mutex_recursive_give\n * \\ingroup Semaphores\n */\nuint8_t mutex_recursive_give(mutex_t mutex) {\n\treturn xQueueGiveMutexRecursive((mutex));\n}\n\n/**\n * semphr. h\n * mutex_recursive_take(\n *                          sem_t xMutex,\n *                          uint32_t xBlockTime\n *                        )\n *\n * <i>Macro</i> to recursively obtain, or 'take', a mutex type semaphore.\n * The mutex must have previously been created using a call to\n * mutex_recursive_create();\n *\n * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this\n * macro to be available.\n *\n * This macro must not be used on mutexes created using mutex_create().\n *\n * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex\n * doesn't become available again until the owner has called\n * mutex_recursive_give() for each successful 'take' request.  For example,\n * if a task successfully 'takes' the same mutex 5 times then the mutex will\n * not be available to any other task until it has also  'given' the mutex back\n * exactly five times.\n *\n * @param xMutex A handle to the mutex being obtained.  This is the\n * handle returned by mutex_recursive_create();\n *\n * @param xBlockTime The time in ticks to wait for the semaphore to become\n * available.  The macro portTICK_PERIOD_MS can be used to convert this to a\n * real time.  A block time of zero can be used to poll the semaphore.  If\n * the task already owns the semaphore then mutex_recursive_take() will\n * return immediately no matter what the value of xBlockTime.\n *\n * @return pdTRUE if the semaphore was obtained.  pdFALSE if xBlockTime\n * expired without the semaphore becoming available.\n *\n * Example usage:\n <pre>\n sem_t xMutex = NULL;\n\n // A task that creates a mutex.\n void vATask( void * pvParameters )\n {\n    // Create the mutex to guard a shared resource.\n    xMutex = mutex_recursive_create();\n }\n\n // A task that uses the mutex.\n void vAnotherTask( void * pvParameters )\n {\n    // ... Do other things.\n\n    if( xMutex != NULL )\n    {\n        // See if we can obtain the mutex.  If the mutex is not available\n        // wait 10 ticks to see if it becomes free.\n        if( mutex_recursive_take( sem, ( uint32_t ) 10 ) == pdTRUE )\n        {\n            // We were able to obtain the mutex and can now access the\n            // shared resource.\n\n            // ...\n            // For some reason due to the nature of the code further calls to\n                        // mutex_recursive_take() are made on the same mutex.  In real\n                        // code these would not be just sequential calls as this would make\n                        // no sense.  Instead the calls are likely to be buried inside\n                        // a more complex call structure.\n            mutex_recursive_take( xMutex, ( uint32_t ) 10 );\n            mutex_recursive_take( xMutex, ( uint32_t ) 10 );\n\n            // The mutex has now been 'taken' three times, so will not be\n                        // available to another task until it has also been given back\n                        // three times.  Again it is unlikely that real code would have\n                        // these calls sequentially, but instead buried in a more complex\n                        // call structure.  This is just for illustrative purposes.\n            mutex_recursive_give( xMutex );\n                        mutex_recursive_give( xMutex );\n                        mutex_recursive_give( xMutex );\n\n                        // Now the mutex can be taken by other tasks.\n        }\n        else\n        {\n            // We could not obtain the mutex and can therefore not access\n            // the shared resource safely.\n        }\n    }\n }\n </pre>\n * \\defgroup mutex_recursive_take mutex_recursive_take\n * \\ingroup Semaphores\n */\nuint8_t mutex_recursive_take(mutex_t mutex, uint32_t timeout) {\n\treturn xQueueTakeMutexRecursive((mutex), (timeout));\n}\n\nsem_t sem_create(uint32_t max_count, uint32_t init_count) {\n\treturn xQueueCreateCountingSemaphore((max_count), (init_count));\n}\n\nvoid sem_delete(sem_t sem) {\n\tqueue_delete((queue_t)(sem));\n}\n\ntask_t mutex_get_owner(mutex_t mutex) {\n\treturn xQueueGetMutexHolder((mutex));\n}\n\nuint32_t sem_get_count(sem_t sem) {\n\treturn queue_get_waiting((queue_t)(sem));\n}\n\nmutex_t mutex_create_static(static_sem_s_t* pxMutexBuffer) {\n\treturn xQueueCreateMutexStatic(queueQUEUE_TYPE_MUTEX, (pxMutexBuffer));\n}\n\nsem_t sem_create_static(uint32_t max_count, uint32_t init_count, static_sem_s_t* psemBuffer) {\n\treturn xQueueCreateCountingSemaphoreStatic((max_count), (init_count), (psemBuffer));\n}\n"
  },
  {
    "path": "src/rtos/stream_buffer.c",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n/* Standard includes. */\n#include <stdint.h>\n#include <string.h>\n\n/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining\nall the API functions to use the MPU wrappers.  That should only be done when\ntask.h is included from an application file. */\n#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE\n\n/* FreeRTOS includes. */\n#include \"FreeRTOS.h\"\n#include \"task.h\"\n#include \"stream_buffer.h\"\n\n#if( configUSE_TASK_NOTIFICATIONS != 1 )\n\t#error configUSE_TASK_NOTIFICATIONS must be set to 1 to build stream_buffer.c\n#endif\n\n/* Lint e961 and e750 are suppressed as a MISRA exception justified because the\nMPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the\nheader files above, but not in this file, in order to generate the correct\nprivileged Vs unprivileged linkage and placement. */\n#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\n\n/* If the user has not provided application specific Rx notification macros,\nor #defined the notification macros away, them provide default implementations\nthat uses task notifications. */\n/*lint -save -e9026 Function like macros allowed and needed here so they can be overidden. */\n#ifndef sbRECEIVE_COMPLETED\n\t#define sbRECEIVE_COMPLETED( pxStreamBuffer )\t\t\t\t\t\t\t\t\t\t\\\n\t\trtos_suspend_all();\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tif( ( pxStreamBuffer )->xTaskWaitingToSend != NULL )\t\t\t\t\t\t\\\n\t\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t( void ) xTaskNotify( ( pxStreamBuffer )->xTaskWaitingToSend,\t\t\t\\\n\t\t\t\t\t\t\t\t\t  ( uint32_t ) 0,\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t  E_NOTIFY_ACTION_NONE );\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t( pxStreamBuffer )->xTaskWaitingToSend = NULL;\t\t\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t( void ) rtos_resume_all();\n#endif /* sbRECEIVE_COMPLETED */\n\n#ifndef sbRECEIVE_COMPLETED_FROM_ISR\n\t#define sbRECEIVE_COMPLETED_FROM_ISR( pxStreamBuffer,\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t  pxHigherPriorityTaskWoken )\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tuint32_t uxSavedInterruptStatus;\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tuxSavedInterruptStatus = ( uint32_t ) portSET_INTERRUPT_MASK_FROM_ISR();\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tif( ( pxStreamBuffer )->xTaskWaitingToSend != NULL )\t\t\t\t\t\t\\\n\t\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToSend,\t\\\n\t\t\t\t\t\t\t\t\t\t\t ( uint32_t ) 0,\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t E_NOTIFY_ACTION_NONE,\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t pxHigherPriorityTaskWoken );\t\t\t\t\\\n\t\t\t\t( pxStreamBuffer )->xTaskWaitingToSend = NULL;\t\t\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\t\t\t\t\t\\\n\t}\n#endif /* sbRECEIVE_COMPLETED_FROM_ISR */\n\n/* If the user has not provided an application specific Tx notification macro,\nor #defined the notification macro away, them provide a default implementation\nthat uses task notifications. */\n#ifndef sbSEND_COMPLETED\n\t#define sbSEND_COMPLETED( pxStreamBuffer )\t\t\t\t\t\t\t\t\t\t\t\\\n\t\trtos_suspend_all();\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tif( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL )\t\t\t\t\t\t\\\n\t\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t( void ) xTaskNotify( ( pxStreamBuffer )->xTaskWaitingToReceive,\t\t\\\n\t\t\t\t\t\t\t\t\t  ( uint32_t ) 0,\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t  E_NOTIFY_ACTION_NONE );\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t( pxStreamBuffer )->xTaskWaitingToReceive = NULL;\t\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t( void ) rtos_resume_all();\n#endif /* sbSEND_COMPLETED */\n\n#ifndef sbSEND_COMPLETE_FROM_ISR\n\t#define sbSEND_COMPLETE_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken )\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tuint32_t uxSavedInterruptStatus;\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tuxSavedInterruptStatus = ( uint32_t ) portSET_INTERRUPT_MASK_FROM_ISR();\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tif( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL )\t\t\t\t\t\t\\\n\t\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToReceive,\t\\\n\t\t\t\t\t\t\t\t\t\t\t ( uint32_t ) 0,\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t E_NOTIFY_ACTION_NONE,\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t pxHigherPriorityTaskWoken );\t\t\t\t\\\n\t\t\t\t( pxStreamBuffer )->xTaskWaitingToReceive = NULL;\t\t\t\t\t\t\\\n\t\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\t\t\t\t\t\\\n\t}\n#endif /* sbSEND_COMPLETE_FROM_ISR */\n/*lint -restore (9026) */\n\n/* The number of bytes used to hold the length of a message in the buffer. */\n#define sbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( size_t ) )\n\n/* Bits stored in the ucFlags field of the stream buffer. */\n#define sbFLAGS_IS_MESSAGE_BUFFER\t\t( ( uint8_t ) 1 ) /* Set if the stream buffer was created as a message buffer, in which case it holds discrete messages rather than a stream. */\n#define sbFLAGS_IS_STATICALLY_ALLOCATED ( ( uint8_t ) 2 ) /* Set if the stream buffer was created using statically allocated memory. */\n\n/*-----------------------------------------------------------*/\n\n/* Structure that hold state information on the buffer. */\ntypedef struct xSTREAM_BUFFER /*lint !e9058 Style convention uses tag. */\n{\n\tvolatile size_t xTail;\t\t\t\t/* Index to the next item to read within the buffer. */\n\tvolatile size_t xHead;\t\t\t\t/* Index to the next item to write within the buffer. */\n\tsize_t xLength;\t\t\t\t\t\t/* The length of the buffer pointed to by pucBuffer. */\n\tsize_t xTriggerLevelBytes;\t\t\t/* The number of bytes that must be in the stream buffer before a task that is waiting for data is unblocked. */\n\tvolatile task_t xTaskWaitingToReceive; /* Holds the handle of a task waiting for data, or NULL if no tasks are waiting. */\n\tvolatile task_t xTaskWaitingToSend;\t/* Holds the handle of a task waiting to send data to a message buffer that is full. */\n\tuint8_t *pucBuffer;\t\t\t\t\t/* Points to the buffer itself - that is - the RAM that stores the data passed through the buffer. */\n\tuint8_t ucFlags;\n\n\t#if ( configUSE_TRACE_FACILITY == 1 )\n\t\tuint32_t uxStreamBufferNumber;\t\t/* Used for tracing purposes. */\n\t#endif\n} StreamBuffer_t;\n\n/*\n * The number of bytes available to be read from the buffer.\n */\nstatic size_t prvBytesInBuffer( const StreamBuffer_t * const pxStreamBuffer ) ;\n\n/*\n * Add xCount bytes from pucData into the pxStreamBuffer message buffer.\n * Returns the number of bytes written, which will either equal xCount in the\n * success case, or 0 if there was not enough space in the buffer (in which case\n * no data is written into the buffer).\n */\nstatic size_t prvWriteBytesToBuffer( StreamBuffer_t * const pxStreamBuffer, const uint8_t *pucData, size_t xCount ) ;\n\n/*\n * If the stream buffer is being used as a message buffer, then reads an entire\n * message out of the buffer.  If the stream buffer is being used as a stream\n * buffer then read as many bytes as possible from the buffer.\n * prvReadBytesFromBuffer() is called to actually extract the bytes from the\n * buffer's data storage area.\n */\nstatic size_t prvReadMessageFromBuffer( StreamBuffer_t *pxStreamBuffer,\n\t\t\t\t\t\t\t\t\t\tvoid *pvRxData,\n\t\t\t\t\t\t\t\t\t\tsize_t xBufferLengthBytes,\n\t\t\t\t\t\t\t\t\t\tsize_t xBytesAvailable,\n\t\t\t\t\t\t\t\t\t\tsize_t xBytesToStoreMessageLength ) ;\n\n/*\n * If the stream buffer is being used as a message buffer, then writes an entire\n * message to the buffer.  If the stream buffer is being used as a stream\n * buffer then write as many bytes as possible to the buffer.\n * prvWriteBytestoBuffer() is called to actually send the bytes to the buffer's\n * data storage area.\n */\nstatic size_t prvWriteMessageToBuffer(  StreamBuffer_t * const pxStreamBuffer,\n\t\t\t\t\t\t\t\t\t\tconst void * pvTxData,\n\t\t\t\t\t\t\t\t\t\tsize_t xDataLengthBytes,\n\t\t\t\t\t\t\t\t\t\tsize_t xSpace,\n\t\t\t\t\t\t\t\t\t\tsize_t xRequiredSpace ) ;\n\n/*\n * Read xMaxCount bytes from the pxStreamBuffer message buffer and write them\n * to pucData.\n */\nstatic size_t prvReadBytesFromBuffer( StreamBuffer_t *pxStreamBuffer,\n\t\t\t\t\t\t\t\t\t  uint8_t *pucData,\n\t\t\t\t\t\t\t\t\t  size_t xMaxCount,\n\t\t\t\t\t\t\t\t\t  size_t xBytesAvailable ); \n\n/*\n * Called by both pxStreamBufferCreate() and pxStreamBufferCreateStatic() to\n * initialise the members of the newly created stream buffer structure.\n */\nstatic void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,\n\t\t\t\t\t\t\t\t\t\t  uint8_t * const pucBuffer,\n\t\t\t\t\t\t\t\t\t\t  size_t xBufferSizeBytes,\n\t\t\t\t\t\t\t\t\t\t  size_t xTriggerLevelBytes,\n\t\t\t\t\t\t\t\t\t\t  int32_t xIsMessageBuffer ) ;\n\n/*-----------------------------------------------------------*/\n\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\n\tstream_buf_t xStreamBufferGenericCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, int32_t xIsMessageBuffer )\n\t{\n\tuint8_t *pucAllocatedMemory;\n\n\t\t/* In case the stream buffer is going to be used as a message buffer\n\t\t(that is, it will hold discrete messages with a little meta data that\n\t\tsays how big the next message is) check the buffer will be large enough\n\t\tto hold at least one message. */\n\t\tconfigASSERT( xBufferSizeBytes > sbBYTES_TO_STORE_MESSAGE_LENGTH );\n\t\tconfigASSERT( xTriggerLevelBytes <= xBufferSizeBytes );\n\n\t\t/* A trigger level of 0 would cause a waiting task to unblock even when\n\t\tthe buffer was empty. */\n\t\tif( xTriggerLevelBytes == ( size_t ) 0 )\n\t\t{\n\t\t\txTriggerLevelBytes = ( size_t ) 1; /*lint !e9044 Parameter modified to ensure it doesn't have a dangerous value. */\n\t\t}\n\n\t\t/* A stream buffer requires a StreamBuffer_t structure and a buffer.\n\t\tBoth are allocated in a single call to kmalloc().  The\n\t\tStreamBuffer_t structure is placed at the start of the allocated memory\n\t\tand the buffer follows immediately after.  The requested size is\n\t\tincremented so the free space is returned as the user would expect -\n\t\tthis is a quirk of the implementation that means otherwise the free\n\t\tspace would be reported as one byte smaller than would be logically\n\t\texpected. */\n\t\txBufferSizeBytes++;\n\t\tpucAllocatedMemory = ( uint8_t * ) kmalloc( xBufferSizeBytes + sizeof( StreamBuffer_t ) ); /*lint !e9079 malloc() only returns void*. */\n\n\t\tif( pucAllocatedMemory != NULL )\n\t\t{\n\t\t\tprvInitialiseNewStreamBuffer( ( StreamBuffer_t * ) pucAllocatedMemory, /* Structure at the start of the allocated memory. */ /*lint !e9087 Safe cast as allocated memory is aligned. */ /*lint !e826 Area is not too small and alignment is guaranteed provided malloc() behaves as expected and returns aligned buffer. */\n\t\t\t\t\t\t\t\t\t\t   pucAllocatedMemory + sizeof( StreamBuffer_t ),  /* Storage area follows. */ /*lint !e9016 Indexing past structure valid for uint8_t pointer, also storage area has no alignment requirement. */\n\t\t\t\t\t\t\t\t\t\t   xBufferSizeBytes,\n\t\t\t\t\t\t\t\t\t\t   xTriggerLevelBytes,\n\t\t\t\t\t\t\t\t\t\t   xIsMessageBuffer );\n\n\t\t\ttraceSTREAM_BUFFER_CREATE( ( ( StreamBuffer_t * ) pucAllocatedMemory ), xIsMessageBuffer );\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttraceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer );\n\t\t}\n\n\t\treturn ( stream_buf_t * ) pucAllocatedMemory; /*lint !e9087 !e826 Safe cast as allocated memory is aligned. */\n\t}\n\n#endif /* configSUPPORT_DYNAMIC_ALLOCATION */\n/*-----------------------------------------------------------*/\n\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\n\tstream_buf_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t   size_t xTriggerLevelBytes,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t   int32_t xIsMessageBuffer,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t   uint8_t * const pucStreamBufferStorageArea,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t   static_stream_buf_s_t * const pxStaticStreamBuffer )\n\t{\n\tStreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) pxStaticStreamBuffer; /*lint !e740 !e9087 Safe cast as static_stream_buf_s_t is opaque Streambuffer_t. */\n\tstream_buf_t xReturn;\n\n\t\tconfigASSERT( pucStreamBufferStorageArea );\n\t\tconfigASSERT( pxStaticStreamBuffer );\n\t\tconfigASSERT( xTriggerLevelBytes <= xBufferSizeBytes );\n\n\t\t/* A trigger level of 0 would cause a waiting task to unblock even when\n\t\tthe buffer was empty. */\n\t\tif( xTriggerLevelBytes == ( size_t ) 0 )\n\t\t{\n\t\t\txTriggerLevelBytes = ( size_t ) 1; /*lint !e9044 Function parameter deliberately modified to ensure it is in range. */\n\t\t}\n\n\t\t/* In case the stream buffer is going to be used as a message buffer\n\t\t(that is, it will hold discrete messages with a little meta data that\n\t\tsays how big the next message is) check the buffer will be large enough\n\t\tto hold at least one message. */\n\t\tconfigASSERT( xBufferSizeBytes > sbBYTES_TO_STORE_MESSAGE_LENGTH );\n\n\t\t#if( configASSERT_DEFINED == 1 )\n\t\t{\n\t\t\t/* Sanity check that the size of the structure used to declare a\n\t\t\tvariable of type static_stream_buf_s_t equals the size of the real\n\t\t\tmessage buffer structure. */\n\t\t\tvolatile size_t xSize = sizeof( static_stream_buf_s_t );\n\t\t\tconfigASSERT( xSize == sizeof( StreamBuffer_t ) );\n\t\t}\n\t\t#endif /* configASSERT_DEFINED */\n\n\t\tif( ( pucStreamBufferStorageArea != NULL ) && ( pxStaticStreamBuffer != NULL ) )\n\t\t{\n\t\t\tprvInitialiseNewStreamBuffer( pxStreamBuffer,\n\t\t\t\t\t\t\t\t\t\t  pucStreamBufferStorageArea,\n\t\t\t\t\t\t\t\t\t\t  xBufferSizeBytes,\n\t\t\t\t\t\t\t\t\t\t  xTriggerLevelBytes,\n\t\t\t\t\t\t\t\t\t\t  xIsMessageBuffer );\n\n\t\t\t/* Remember this was statically allocated in case it is ever deleted\n\t\t\tagain. */\n\t\t\tpxStreamBuffer->ucFlags |= sbFLAGS_IS_STATICALLY_ALLOCATED;\n\n\t\t\ttraceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer );\n\n\t\t\txReturn = ( stream_buf_t ) pxStaticStreamBuffer; /*lint !e9087 Data hiding requires cast to opaque type. */\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = NULL;\n\t\t\ttraceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer );\n\t\t}\n\n\t\treturn xReturn;\n\t}\n\n#endif /* ( configSUPPORT_STATIC_ALLOCATION == 1 ) */\n/*-----------------------------------------------------------*/\n\nvoid vStreamBufferDelete( stream_buf_t xStreamBuffer )\n{\nStreamBuffer_t * pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\n\n\tconfigASSERT( pxStreamBuffer );\n\n\ttraceSTREAM_BUFFER_DELETE( xStreamBuffer );\n\n\tif( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) pdFALSE )\n\t{\n\t\t#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\t\t{\n\t\t\t/* Both the structure and the buffer were allocated using a single call\n\t\t\tto kmalloc(), hence only one call to kfree() is required. */\n\t\t\tkfree( ( void * ) pxStreamBuffer ); /*lint !e9087 Standard free() semantics require void *, plus pxStreamBuffer was allocated by kmalloc(). */\n\t\t}\n\t\t#else\n\t\t{\n\t\t\t/* Should not be possible to get here, ucFlags must be corrupt.\n\t\t\tForce an assert. */\n\t\t\tconfigASSERT( xStreamBuffer == ( stream_buf_t ) ~0 );\n\t\t}\n\t\t#endif\n\t}\n\telse\n\t{\n\t\t/* The structure and buffer were not allocated dynamically and cannot be\n\t\tfreed - just scrub the structure so future use will assert. */\n\t\tmemset( pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) );\n\t}\n}\n/*-----------------------------------------------------------*/\n\nint32_t stream_buf_reset( stream_buf_t xStreamBuffer )\n{\nStreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\nint32_t xReturn = pdFAIL, xIsMessageBuffer;\n\n#if( configUSE_TRACE_FACILITY == 1 )\n\tuint32_t uxStreamBufferNumber;\n#endif\n\n\tconfigASSERT( pxStreamBuffer );\n\n\t#if( configUSE_TRACE_FACILITY == 1 )\n\t{\n\t\t/* Store the stream buffer number so it can be restored after the\n\t\treset. */\n\t\tuxStreamBufferNumber = pxStreamBuffer->uxStreamBufferNumber;\n\t}\n\t#endif\n\n\t/* Can only reset a message buffer if there are no tasks blocked on it. */\n\tif( pxStreamBuffer->xTaskWaitingToReceive == NULL )\n\t{\n\t\tif( pxStreamBuffer->xTaskWaitingToSend == NULL )\n\t\t{\n\t\t\tif( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )\n\t\t\t{\n\t\t\t\txIsMessageBuffer = pdTRUE;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\txIsMessageBuffer = pdFALSE;\n\t\t\t}\n\n\t\t\tprvInitialiseNewStreamBuffer( pxStreamBuffer,\n\t\t\t\t\t\t\t\t\t\t  pxStreamBuffer->pucBuffer,\n\t\t\t\t\t\t\t\t\t\t  pxStreamBuffer->xLength,\n\t\t\t\t\t\t\t\t\t\t  pxStreamBuffer->xTriggerLevelBytes,\n\t\t\t\t\t\t\t\t\t\t  xIsMessageBuffer );\n\t\t\txReturn = pdPASS;\n\n\t\t\t#if( configUSE_TRACE_FACILITY == 1 )\n\t\t\t{\n\t\t\t\tpxStreamBuffer->uxStreamBufferNumber = uxStreamBufferNumber;\n\t\t\t}\n\t\t\t#endif\n\n\t\t\ttraceSTREAM_BUFFER_RESET( xStreamBuffer );\n\t\t}\n\t}\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nint32_t stream_buf_set_trigger( stream_buf_t xStreamBuffer, size_t xTriggerLevel )\n{\nStreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\nint32_t xReturn;\n\n\tconfigASSERT( pxStreamBuffer );\n\n\t/* It is not valid for the trigger level to be 0. */\n\tif( xTriggerLevel == ( size_t ) 0 )\n\t{\n\t\txTriggerLevel = ( size_t ) 1; /*lint !e9044 Parameter modified to ensure it doesn't have a dangerous value. */\n\t}\n\n\t/* The trigger level is the number of bytes that must be in the stream\n\tbuffer before a task that is waiting for data is unblocked. */\n\tif( xTriggerLevel <= pxStreamBuffer->xLength )\n\t{\n\t\tpxStreamBuffer->xTriggerLevelBytes = xTriggerLevel;\n\t\txReturn = pdPASS;\n\t}\n\telse\n\t{\n\t\txReturn = pdFALSE;\n\t}\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nsize_t stream_buf_get_unused( stream_buf_t xStreamBuffer )\n{\nconst StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\nsize_t xSpace;\n\n\tconfigASSERT( pxStreamBuffer );\n\n\txSpace = pxStreamBuffer->xLength + pxStreamBuffer->xTail;\n\txSpace -= pxStreamBuffer->xHead;\n\txSpace -= ( size_t ) 1;\n\n\tif( xSpace >= pxStreamBuffer->xLength )\n\t{\n\t\txSpace -= pxStreamBuffer->xLength;\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\treturn xSpace;\n}\n/*-----------------------------------------------------------*/\n\nsize_t stream_buf_get_used( stream_buf_t xStreamBuffer )\n{\nconst StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\nsize_t xReturn;\n\n\tconfigASSERT( pxStreamBuffer );\n\n\txReturn = prvBytesInBuffer( pxStreamBuffer );\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nsize_t stream_buf_send( stream_buf_t xStreamBuffer,\n\t\t\t\t\t\t  const void *pvTxData,\n\t\t\t\t\t\t  size_t xDataLengthBytes,\n\t\t\t\t\t\t  uint32_t xTicksToWait )\n{\nStreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\nsize_t xReturn, xSpace = 0;\nsize_t xRequiredSpace = xDataLengthBytes;\nTimeOut_t xTimeOut;\n\n\tconfigASSERT( pvTxData );\n\tconfigASSERT( pxStreamBuffer );\n\n\t/* This send function is used to write to both message buffers and stream\n\tbuffers.  If this is a message buffer then the space needed must be\n\tincreased by the amount of bytes needed to store the length of the\n\tmessage. */\n\tif( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )\n\t{\n\t\txRequiredSpace += sbBYTES_TO_STORE_MESSAGE_LENGTH;\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\tif( xTicksToWait != ( uint32_t ) 0 )\n\t{\n\t\tvTaskSetTimeOutState( &xTimeOut );\n\n\t\tdo\n\t\t{\n\t\t\t/* Wait until the required number of bytes are free in the message\n\t\t\tbuffer. */\n\t\t\ttaskENTER_CRITICAL();\n\t\t\t{\n\t\t\t\txSpace = stream_buf_get_unused( pxStreamBuffer );\n\n\t\t\t\tif( xSpace < xRequiredSpace )\n\t\t\t\t{\n\t\t\t\t\t/* Clear notification state as going to wait for space. */\n\t\t\t\t\t( void ) task_notify_clear( NULL );\n\n\t\t\t\t\t/* Should only be one writer. */\n\t\t\t\t\tconfigASSERT( pxStreamBuffer->xTaskWaitingToSend == NULL );\n\t\t\t\t\tpxStreamBuffer->xTaskWaitingToSend = task_get_current();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ttaskEXIT_CRITICAL();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttaskEXIT_CRITICAL();\n\n\t\t\ttraceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer );\n\t\t\t( void ) task_notify_wait( ( uint32_t ) 0, UINT32_MAX, NULL, xTicksToWait );\n\t\t\tpxStreamBuffer->xTaskWaitingToSend = NULL;\n\n\t\t} while( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE );\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\tif( xSpace == ( size_t ) 0 )\n\t{\n\t\txSpace = stream_buf_get_unused( pxStreamBuffer );\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\ttaskENTER_CRITICAL();\n\txReturn = prvWriteMessageToBuffer( pxStreamBuffer, pvTxData, xDataLengthBytes, xSpace, xRequiredSpace );\n\ttaskEXIT_CRITICAL();\n\n\tif( xReturn > ( size_t ) 0 )\n\t{\n\t\ttraceSTREAM_BUFFER_SEND( xStreamBuffer, xReturn );\n\n\t\t/* Was a task waiting for the data? */\n\t\tif( prvBytesInBuffer( pxStreamBuffer ) >= pxStreamBuffer->xTriggerLevelBytes )\n\t\t{\n\t\t\tsbSEND_COMPLETED( pxStreamBuffer );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t\ttraceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer );\n\t}\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nsize_t xStreamBufferSendFromISR( stream_buf_t xStreamBuffer,\n\t\t\t\t\t\t\t\t const void *pvTxData,\n\t\t\t\t\t\t\t\t size_t xDataLengthBytes,\n\t\t\t\t\t\t\t\t int32_t * const pxHigherPriorityTaskWoken )\n{\nStreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\nsize_t xReturn, xSpace;\nsize_t xRequiredSpace = xDataLengthBytes;\n\n\tconfigASSERT( pvTxData );\n\tconfigASSERT( pxStreamBuffer );\n\n\t/* This send function is used to write to both message buffers and stream\n\tbuffers.  If this is a message buffer then the space needed must be\n\tincreased by the amount of bytes needed to store the length of the\n\tmessage. */\n\tif( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )\n\t{\n\t\txRequiredSpace += sbBYTES_TO_STORE_MESSAGE_LENGTH;\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\txSpace = stream_buf_get_unused( pxStreamBuffer );\n\txReturn = prvWriteMessageToBuffer( pxStreamBuffer, pvTxData, xDataLengthBytes, xSpace, xRequiredSpace );\n\n\tif( xReturn > ( size_t ) 0 )\n\t{\n\t\t/* Was a task waiting for the data? */\n\t\tif( prvBytesInBuffer( pxStreamBuffer ) >= pxStreamBuffer->xTriggerLevelBytes )\n\t\t{\n\t\t\tsbSEND_COMPLETE_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\ttraceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xReturn );\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nstatic size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer,\n\t\t\t\t\t\t\t\t\t   const void * pvTxData,\n\t\t\t\t\t\t\t\t\t   size_t xDataLengthBytes,\n\t\t\t\t\t\t\t\t\t   size_t xSpace,\n\t\t\t\t\t\t\t\t\t   size_t xRequiredSpace )\n{\n\tint32_t xShouldWrite;\n\tsize_t xReturn;\n\n\tif( xSpace == ( size_t ) 0 )\n\t{\n\t\t/* Doesn't matter if this is a stream buffer or a message buffer, there\n\t\tis no space to write. */\n\t\txShouldWrite = pdFALSE;\n\t}\n\telse if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) == ( uint8_t ) 0 )\n\t{\n\t\t/* This is a stream buffer, as opposed to a message buffer, so writing a\n\t\tstream of bytes rather than discrete messages.  Write as many bytes as\n\t\tpossible. */\n\t\txShouldWrite = pdTRUE;\n\t\txDataLengthBytes = configMIN( xDataLengthBytes, xSpace ); /*lint !e9044 Function parameter modified to ensure it is capped to available space. */\n\t}\n\telse if( xSpace >= xRequiredSpace )\n\t{\n\t\t/* This is a message buffer, as opposed to a stream buffer, and there\n\t\tis enough space to write both the message length and the message itself\n\t\tinto the buffer.  Start by writing the length of the data, the data\n\t\titself will be written later in this function. */\n\t\txShouldWrite = pdTRUE;\n\t\ttaskENTER_CRITICAL();\n\t\t( void ) prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) &( xDataLengthBytes ), sbBYTES_TO_STORE_MESSAGE_LENGTH );\n\t\ttaskEXIT_CRITICAL();\n\t}\n\telse\n\t{\n\t\t/* There is space available, but not enough space. */\n\t\txShouldWrite = pdFALSE;\n\t}\n\n\tif( xShouldWrite != pdFALSE )\n\t{\n\t\t/* Writes the data itself. */\n\t\ttaskENTER_CRITICAL();\n\t\txReturn = prvWriteBytesToBuffer( pxStreamBuffer, ( const uint8_t * ) pvTxData, xDataLengthBytes ); /*lint !e9079 Storage buffer is implemented as uint8_t for ease of sizing, alighment and access. */\n\t\ttaskEXIT_CRITICAL();\n\t}\n\telse\n\t{\n\t\txReturn = 0;\n\t}\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nsize_t stream_buf_recv( stream_buf_t xStreamBuffer,\n\t\t\t\t\t\t\t void *pvRxData,\n\t\t\t\t\t\t\t size_t xBufferLengthBytes,\n\t\t\t\t\t\t\t uint32_t xTicksToWait )\n{\nStreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\nsize_t xReceivedLength = 0, xBytesAvailable, xBytesToStoreMessageLength;\n\n\tconfigASSERT( pvRxData );\n\tconfigASSERT( pxStreamBuffer );\n\n\t/* This receive function is used by both message buffers, which store\n\tdiscrete messages, and stream buffers, which store a continuous stream of\n\tbytes.  Discrete messages include an additional\n\tsbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the\n\tmessage. */\n\tif( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )\n\t{\n\t\txBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH;\n\t}\n\telse\n\t{\n\t\txBytesToStoreMessageLength = 0;\n\t}\n\n\tif( xTicksToWait != ( uint32_t ) 0 )\n\t{\n\t\t/* Checking if there is data and clearing the notification state must be\n\t\tperformed atomically. */\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\txBytesAvailable = prvBytesInBuffer( pxStreamBuffer );\n\n\t\t\t/* If this function was invoked by a message buffer read then\n\t\t\txBytesToStoreMessageLength holds the number of bytes used to hold\n\t\t\tthe length of the next discrete message.  If this function was\n\t\t\tinvoked by a stream buffer read then xBytesToStoreMessageLength will\n\t\t\tbe 0. */\n\t\t\tif( xBytesAvailable <= xBytesToStoreMessageLength )\n\t\t\t{\n\t\t\t\t/* Clear notification state as going to wait for data. */\n\t\t\t\t( void ) task_notify_clear( NULL );\n\n\t\t\t\t/* Should only be one reader. */\n\t\t\t\tconfigASSERT( pxStreamBuffer->xTaskWaitingToReceive == NULL );\n\t\t\t\tpxStreamBuffer->xTaskWaitingToReceive = task_get_current();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\tif( xBytesAvailable <= xBytesToStoreMessageLength )\n\t\t{\n\t\t\t/* Wait for data to be available. */\n\t\t\ttraceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer );\n\t\t\t( void ) task_notify_wait( ( uint32_t ) 0, UINT32_MAX, NULL, xTicksToWait );\n\t\t\tpxStreamBuffer->xTaskWaitingToReceive = NULL;\n\n\t\t\t/* Recheck the data available after blocking. */\n\t\t\txBytesAvailable = prvBytesInBuffer( pxStreamBuffer );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\telse\n\t{\n\t\txBytesAvailable = prvBytesInBuffer( pxStreamBuffer );\n\t}\n\n\t/* Whether receiving a discrete message (where xBytesToStoreMessageLength\n\tholds the number of bytes used to store the message length) or a stream of\n\tbytes (where xBytesToStoreMessageLength is zero), the number of bytes\n\tavailable must be greater than xBytesToStoreMessageLength to be able to\n\tread bytes from the buffer. */\n\tif( xBytesAvailable > xBytesToStoreMessageLength )\n\t{\n\t\txReceivedLength = prvReadMessageFromBuffer( pxStreamBuffer, pvRxData, xBufferLengthBytes, xBytesAvailable, xBytesToStoreMessageLength );\n\n\t\t/* Was a task waiting for space in the buffer? */\n\t\tif( xReceivedLength != ( size_t ) 0 )\n\t\t{\n\t\t\ttraceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength );\n\t\t\tsbRECEIVE_COMPLETED( pxStreamBuffer );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\telse\n\t{\n\t\ttraceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer );\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\treturn xReceivedLength;\n}\n/*-----------------------------------------------------------*/\n\nsize_t xStreamBufferReceiveFromISR( stream_buf_t xStreamBuffer,\n\t\t\t\t\t\t\t\t\tvoid *pvRxData,\n\t\t\t\t\t\t\t\t\tsize_t xBufferLengthBytes,\n\t\t\t\t\t\t\t\t\tint32_t * const pxHigherPriorityTaskWoken )\n{\nStreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\nsize_t xReceivedLength = 0, xBytesAvailable, xBytesToStoreMessageLength;\n\n\tconfigASSERT( pvRxData );\n\tconfigASSERT( pxStreamBuffer );\n\n\t/* This receive function is used by both message buffers, which store\n\tdiscrete messages, and stream buffers, which store a continuous stream of\n\tbytes.  Discrete messages include an additional\n\tsbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the\n\tmessage. */\n\tif( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )\n\t{\n\t\txBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH;\n\t}\n\telse\n\t{\n\t\txBytesToStoreMessageLength = 0;\n\t}\n\n\txBytesAvailable = prvBytesInBuffer( pxStreamBuffer );\n\n\t/* Whether receiving a discrete message (where xBytesToStoreMessageLength\n\tholds the number of bytes used to store the message length) or a stream of\n\tbytes (where xBytesToStoreMessageLength is zero), the number of bytes\n\tavailable must be greater than xBytesToStoreMessageLength to be able to\n\tread bytes from the buffer. */\n\tif( xBytesAvailable > xBytesToStoreMessageLength )\n\t{\n\t\txReceivedLength = prvReadMessageFromBuffer( pxStreamBuffer, pvRxData, xBufferLengthBytes, xBytesAvailable, xBytesToStoreMessageLength );\n\n\t\t/* Was a task waiting for space in the buffer? */\n\t\tif( xReceivedLength != ( size_t ) 0 )\n\t\t{\n\t\t\tsbRECEIVE_COMPLETED_FROM_ISR( pxStreamBuffer, pxHigherPriorityTaskWoken );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\ttraceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength );\n\n\treturn xReceivedLength;\n}\n/*-----------------------------------------------------------*/\n\nstatic size_t prvReadMessageFromBuffer( StreamBuffer_t *pxStreamBuffer,\n\t\t\t\t\t\t\t\t\t\tvoid *pvRxData,\n\t\t\t\t\t\t\t\t\t\tsize_t xBufferLengthBytes,\n\t\t\t\t\t\t\t\t\t\tsize_t xBytesAvailable,\n\t\t\t\t\t\t\t\t\t\tsize_t xBytesToStoreMessageLength )\n{\nsize_t xOriginalTail, xReceivedLength, xNextMessageLength;\n\n\tif( xBytesToStoreMessageLength != ( size_t ) 0 )\n\t{\n\t\t/* A discrete message is being received.  First receive the length\n\t\tof the message.  A copy of the tail is stored so the buffer can be\n\t\treturned to its prior state if the length of the message is too\n\t\tlarge for the provided buffer. */\n\t\txOriginalTail = pxStreamBuffer->xTail;\n\t\ttaskENTER_CRITICAL();\n\t\t( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable );\n\t\ttaskEXIT_CRITICAL();\n\n\t\t/* Reduce the number of bytes available by the number of bytes just\n\t\tread out. */\n\t\txBytesAvailable -= xBytesToStoreMessageLength;\n\n\t\t/* Check there is enough space in the buffer provided by the\n\t\tuser. */\n\t\tif( xNextMessageLength > xBufferLengthBytes )\n\t\t{\n\t\t\t/* The user has provided insufficient space to read the message\n\t\t\tso return the buffer to its previous state (so the length of\n\t\t\tthe message is in the buffer again). */\n\t\t\tpxStreamBuffer->xTail = xOriginalTail;\n\t\t\txNextMessageLength = 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\telse\n\t{\n\t\t/* A stream of bytes is being received (as opposed to a discrete\n\t\tmessage), so read as many bytes as possible. */\n\t\txNextMessageLength = xBufferLengthBytes;\n\t}\n\n\t/* Read the actual data. */\n\ttaskENTER_CRITICAL();\n\txReceivedLength = prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) pvRxData, xNextMessageLength, xBytesAvailable ); /*lint !e9079 Data storage area is implemented as uint8_t array for ease of sizing, indexing and alignment. */\n\ttaskEXIT_CRITICAL();\n\n\treturn xReceivedLength;\n}\n/*-----------------------------------------------------------*/\n\nint32_t stream_buf_is_empty( stream_buf_t xStreamBuffer )\n{\nconst StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\nint32_t xReturn;\nsize_t xTail;\n\n\tconfigASSERT( pxStreamBuffer );\n\n\t/* True if no bytes are available. */\n\txTail = pxStreamBuffer->xTail;\n\tif( pxStreamBuffer->xHead == xTail )\n\t{\n\t\txReturn = pdTRUE;\n\t}\n\telse\n\t{\n\t\txReturn = pdFALSE;\n\t}\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nint32_t stream_buf_is_full( stream_buf_t xStreamBuffer )\n{\nint32_t xReturn;\nsize_t xBytesToStoreMessageLength;\nconst StreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\n\n\tconfigASSERT( pxStreamBuffer );\n\n\t/* This generic version of the receive function is used by both message\n\tbuffers, which store discrete messages, and stream buffers, which store a\n\tcontinuous stream of bytes.  Discrete messages include an additional\n\tsbBYTES_TO_STORE_MESSAGE_LENGTH bytes that hold the length of the message. */\n\tif( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )\n\t{\n\t\txBytesToStoreMessageLength = sbBYTES_TO_STORE_MESSAGE_LENGTH;\n\t}\n\telse\n\t{\n\t\txBytesToStoreMessageLength = 0;\n\t}\n\n\t/* True if the available space equals zero. */\n\tif( stream_buf_get_unused( xStreamBuffer ) <= xBytesToStoreMessageLength )\n\t{\n\t\txReturn = pdTRUE;\n\t}\n\telse\n\t{\n\t\txReturn = pdFALSE;\n\t}\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nint32_t xStreamBufferSendCompletedFromISR( stream_buf_t xStreamBuffer, int32_t *pxHigherPriorityTaskWoken )\n{\nStreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\nint32_t xReturn;\nuint32_t uxSavedInterruptStatus;\n\n\tconfigASSERT( pxStreamBuffer );\n\n\tuxSavedInterruptStatus = ( uint32_t ) portSET_INTERRUPT_MASK_FROM_ISR();\n\t{\n\t\tif( ( pxStreamBuffer )->xTaskWaitingToReceive != NULL )\n\t\t{\n\t\t\t( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToReceive,\n\t\t\t\t\t\t\t\t\t\t ( uint32_t ) 0,\n\t\t\t\t\t\t\t\t\t\t E_NOTIFY_ACTION_NONE,\n\t\t\t\t\t\t\t\t\t\t pxHigherPriorityTaskWoken );\n\t\t\t( pxStreamBuffer )->xTaskWaitingToReceive = NULL;\n\t\t\txReturn = pdTRUE;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = pdFALSE;\n\t\t}\n\t}\n\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nint32_t xStreamBufferReceiveCompletedFromISR( stream_buf_t xStreamBuffer, int32_t *pxHigherPriorityTaskWoken )\n{\nStreamBuffer_t * const pxStreamBuffer = ( StreamBuffer_t * ) xStreamBuffer; /*lint !e9087 !e9079 Safe cast as stream_buf_t is opaque Streambuffer_t. */\nint32_t xReturn;\nuint32_t uxSavedInterruptStatus;\n\n\tconfigASSERT( pxStreamBuffer );\n\n\tuxSavedInterruptStatus = ( uint32_t ) portSET_INTERRUPT_MASK_FROM_ISR();\n\t{\n\t\tif( ( pxStreamBuffer )->xTaskWaitingToSend != NULL )\n\t\t{\n\t\t\t( void ) xTaskNotifyFromISR( ( pxStreamBuffer )->xTaskWaitingToSend,\n\t\t\t\t\t\t\t\t\t\t ( uint32_t ) 0,\n\t\t\t\t\t\t\t\t\t\t E_NOTIFY_ACTION_NONE,\n\t\t\t\t\t\t\t\t\t\t pxHigherPriorityTaskWoken );\n\t\t\t( pxStreamBuffer )->xTaskWaitingToSend = NULL;\n\t\t\txReturn = pdTRUE;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = pdFALSE;\n\t\t}\n\t}\n\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nstatic size_t prvWriteBytesToBuffer( StreamBuffer_t * const pxStreamBuffer, const uint8_t *pucData, size_t xCount )\n{\nsize_t xNextHead, xFirstLength;\n\n\tconfigASSERT( xCount > ( size_t ) 0 );\n\n\txNextHead = pxStreamBuffer->xHead;\n\n\t/* Calculate the number of bytes that can be added in the first write -\n\twhich may be less than the total number of bytes that need to be added if\n\tthe buffer will wrap back to the beginning. */\n\txFirstLength = configMIN( pxStreamBuffer->xLength - xNextHead, xCount );\n\n\t/* Write as many bytes as can be written in the first write. */\n\tconfigASSERT( ( xNextHead + xFirstLength ) <= pxStreamBuffer->xLength );\n\tmemcpy( ( void* ) ( &( pxStreamBuffer->pucBuffer[ xNextHead ] ) ), ( const void * ) pucData, xFirstLength ); /*lint !e9087 memcpy() requires void *. */\n\n\t/* If the number of bytes written was less than the number that could be\n\twritten in the first write... */\n\tif( xCount > xFirstLength )\n\t{\n\t\t/* ...then write the remaining bytes to the start of the buffer. */\n\t\tconfigASSERT( ( xCount - xFirstLength ) <= pxStreamBuffer->xLength );\n\t\tmemcpy( ( void * ) pxStreamBuffer->pucBuffer, ( const void * ) &( pucData[ xFirstLength ] ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\txNextHead += xCount;\n\tif( xNextHead >= pxStreamBuffer->xLength )\n\t{\n\t\txNextHead -= pxStreamBuffer->xLength;\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\tpxStreamBuffer->xHead = xNextHead;\n\n\treturn xCount;\n}\n/*-----------------------------------------------------------*/\n\nstatic size_t prvReadBytesFromBuffer( StreamBuffer_t *pxStreamBuffer, uint8_t *pucData, size_t xMaxCount, size_t xBytesAvailable )\n{\nsize_t xCount, xFirstLength, xNextTail;\n\n\t/* Use the minimum of the wanted bytes and the available bytes. */\n\txCount = configMIN( xBytesAvailable, xMaxCount );\n\n\tif( xCount > ( size_t ) 0 )\n\t{\n\t\txNextTail = pxStreamBuffer->xTail;\n\n\t\t/* Calculate the number of bytes that can be read - which may be\n\t\tless than the number wanted if the data wraps around to the start of\n\t\tthe buffer. */\n\t\txFirstLength = configMIN( pxStreamBuffer->xLength - xNextTail, xCount );\n\n\t\t/* Obtain the number of bytes it is possible to obtain in the first\n\t\tread.  Asserts check bounds of read and write. */\n\t\tconfigASSERT( xFirstLength <= xMaxCount );\n\t\tconfigASSERT( ( xNextTail + xFirstLength ) <= pxStreamBuffer->xLength );\n\t\tmemcpy( ( void * ) pucData, ( const void * ) &( pxStreamBuffer->pucBuffer[ xNextTail ] ), xFirstLength ); /*lint !e9087 memcpy() requires void *. */\n\n\t\t/* If the total number of wanted bytes is greater than the number\n\t\tthat could be read in the first read... */\n\t\tif( xCount > xFirstLength )\n\t\t{\n\t\t\t/*...then read the remaining bytes from the start of the buffer. */\n\t\t\tconfigASSERT( xCount <= xMaxCount );\n\t\t\tmemcpy( ( void * ) &( pucData[ xFirstLength ] ), ( void * ) ( pxStreamBuffer->pucBuffer ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\t/* Move the tail pointer to effectively remove the data read from\n\t\tthe buffer. */\n\t\txNextTail += xCount;\n\n\t\tif( xNextTail >= pxStreamBuffer->xLength )\n\t\t{\n\t\t\txNextTail -= pxStreamBuffer->xLength;\n\t\t}\n\n\t\tpxStreamBuffer->xTail = xNextTail;\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\treturn xCount;\n}\n/*-----------------------------------------------------------*/\n\nstatic size_t prvBytesInBuffer( const StreamBuffer_t * const pxStreamBuffer )\n{\n/* Returns the distance between xTail and xHead. */\nsize_t xCount;\n\n\txCount = pxStreamBuffer->xLength + pxStreamBuffer->xHead;\n\txCount -= pxStreamBuffer->xTail;\n\tif ( xCount >= pxStreamBuffer->xLength )\n\t{\n\t\txCount -= pxStreamBuffer->xLength;\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\treturn xCount;\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,\n\t\t\t\t\t\t\t\t\t\t  uint8_t * const pucBuffer,\n\t\t\t\t\t\t\t\t\t\t  size_t xBufferSizeBytes,\n\t\t\t\t\t\t\t\t\t\t  size_t xTriggerLevelBytes,\n\t\t\t\t\t\t\t\t\t\t  int32_t xIsMessageBuffer )\n{\n\t/* Assert here is deliberately writing to the entire buffer to ensure it can\n\tbe written to without generating exceptions, and is setting the buffer to a\n\tknown value to assist in development/debugging. */\n\t#if( configASSERT_DEFINED == 1 )\n\t{\n\t\t/* The value written just has to be identifiable when looking at the\n\t\tmemory.  Don't use 0xA5 as that is the stack fill value and could\n\t\tresult in confusion as to what is actually being observed. */\n\t\tconst int32_t xWriteValue = 0x55;\n\t\tconfigASSERT( memset( pucBuffer, ( int ) xWriteValue, xBufferSizeBytes ) == pucBuffer );\n\t}\n\t#endif\n\n\tmemset( ( void * ) pxStreamBuffer, 0x00, sizeof( StreamBuffer_t ) ); /*lint !e9087 memset() requires void *. */\n\tpxStreamBuffer->pucBuffer = pucBuffer;\n\tpxStreamBuffer->xLength = xBufferSizeBytes;\n\tpxStreamBuffer->xTriggerLevelBytes = xTriggerLevelBytes;\n\n\tif( xIsMessageBuffer != pdFALSE )\n\t{\n\t\tpxStreamBuffer->ucFlags |= sbFLAGS_IS_MESSAGE_BUFFER;\n\t}\n}\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tuint32_t uxStreamBufferGetStreamBufferNumber( stream_buf_t xStreamBuffer )\n\t{\n\t\treturn ( ( StreamBuffer_t * ) xStreamBuffer )->uxStreamBufferNumber;\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tvoid vStreamBufferSetStreamBufferNumber( stream_buf_t xStreamBuffer, uint32_t uxStreamBufferNumber )\n\t{\n\t\t( ( StreamBuffer_t * ) xStreamBuffer )->uxStreamBufferNumber = uxStreamBufferNumber;\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tuint8_t ucStreamBufferGetStreamBufferType( stream_buf_t xStreamBuffer )\n\t{\n\t\treturn ( ( StreamBuffer_t * )xStreamBuffer )->ucFlags | sbFLAGS_IS_MESSAGE_BUFFER;\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*-----------------------------------------------------------*/\n"
  },
  {
    "path": "src/rtos/task_notify_when_deleting.c",
    "content": "#include \"kapi.h\"\r\n#include \"common/linkedlist.h\"\r\n\r\n// NOTE: can't just include task.h because of redefinition that goes on in kapi\r\n//       include chain, so we just prototype what we need here\r\nvoid *pvTaskGetThreadLocalStoragePointer( task_t xTaskToQuery, int32_t xIndex );\r\nvoid vTaskSetThreadLocalStoragePointer( task_t xTaskToSet, int32_t xIndex, void *pvValue );\r\n\r\n#include \"rtos/tcb.h\"\r\n\r\n// This increments configNUM_THREAD_LOCAL_STORAGE_POINTERS by 2\r\n\r\n#define SUBSCRIBERS_TLSP_IDX 0\r\n#define SUBSCRIPTIONS_TLSP_IDX 1\r\n\r\nstatic static_sem_s_t task_notify_when_deleting_mutex_buf;\r\nstatic mutex_t task_notify_when_deleting_mutex;\r\n\r\nstruct notify_delete_action {\r\n  task_t task_to_notify;\r\n  uint32_t value;\r\n  notify_action_e_t notify_action;\r\n};\r\n\r\nstruct _find_task_args {\r\n  task_t task;\r\n  struct notify_delete_action* found_action;\r\n};\r\n\r\nstatic void _find_task_cb(ll_node_s_t* node, void* extra) {\r\n  struct notify_delete_action* action = node->payload.data;\r\n  struct _find_task_args* args = extra;\r\n\r\n  if(action->task_to_notify == args->task) {\r\n    args->found_action = action;\r\n  }\r\n}\r\n\r\nstatic struct notify_delete_action* _find_task(linked_list_s_t* ll, task_t task) {\r\n  struct _find_task_args args = {\r\n    .task = task,\r\n    .found_action = NULL\r\n  };\r\n  linked_list_foreach(ll, _find_task_cb, &args);\r\n\r\n  return args.found_action;\r\n}\r\n\r\nvoid task_notify_when_deleting_init() {\r\n  task_notify_when_deleting_mutex = mutex_create_static(&task_notify_when_deleting_mutex_buf);\r\n}\r\n\r\nvoid task_notify_when_deleting(task_t target_task, task_t task_to_notify,\r\n                               uint32_t value, notify_action_e_t notify_action) {\r\n  task_to_notify = (task_to_notify == NULL) ? pxCurrentTCB : task_to_notify;\r\n  target_task = (target_task == NULL) ? pxCurrentTCB : target_task;\r\n\r\n  // It doesn't make sense for a task to notify itself, and make sure that\r\n  // neither task is NULL (implying that scheduler hasn't started yet)\r\n  if (task_to_notify == target_task || !task_to_notify || !target_task) {\r\n    return;\r\n  }\r\n  \r\n  // Return immediately if the target task is already deleted\r\n  if (eTaskStateGet(target_task) == E_TASK_STATE_DELETED) {\r\n    return;\r\n  }\r\n\r\n  mutex_take(task_notify_when_deleting_mutex, TIMEOUT_MAX);\r\n\r\n  // task_to_notify maintains a list of the tasks whose deletion it cares about.\r\n  // This will allow us to unsubscribe from notification if/when task_to_notify\r\n  // is deleted\r\n  linked_list_s_t* subscriptions_ll = pvTaskGetThreadLocalStoragePointer(task_to_notify, SUBSCRIPTIONS_TLSP_IDX);\r\n  if (subscriptions_ll == NULL) {\r\n    subscriptions_ll = linked_list_init();\r\n    vTaskSetThreadLocalStoragePointer(task_to_notify, SUBSCRIPTIONS_TLSP_IDX, subscriptions_ll);\r\n  }\r\n  if (subscriptions_ll != NULL) {\r\n    // check whether task_to_notify is already subscribed to target_task. if so,\r\n    // do nothing\r\n    ll_node_s_t* it = subscriptions_ll->head;\r\n    bool found = false;\r\n    while (it != NULL && !found) {\r\n      found = it->payload.data == target_task;\r\n      it = it->next;\r\n    }\r\n    if (!found) {\r\n      linked_list_prepend_data(subscriptions_ll, target_task);\r\n    }\r\n  }\r\n\r\n  // similarly, target_task maintains a list of the tasks it needs to notify\r\n  // when being deleted\r\n  linked_list_s_t* target_ll = pvTaskGetThreadLocalStoragePointer(target_task, SUBSCRIBERS_TLSP_IDX);\r\n  if (target_ll == NULL) {\r\n    target_ll = linked_list_init();\r\n    vTaskSetThreadLocalStoragePointer(target_task, SUBSCRIBERS_TLSP_IDX, target_ll);\r\n  }\r\n\r\n  if (target_ll != NULL) {\r\n    // Try to find the task_to_notify in the target linked list\r\n    // i.e., target_task was already configured to notify task_to_notify\r\n    struct notify_delete_action* action = _find_task(target_ll, task_to_notify);\r\n\r\n    // action wasn't found, so add it to the linked list\r\n    if (action == NULL) {\r\n      action = (struct notify_delete_action*)kmalloc(sizeof(struct notify_delete_action));\r\n      if (action != NULL) {\r\n        linked_list_prepend_data(target_ll, action);\r\n      }\r\n    }\r\n\r\n    // update the action (whether it was found or newly allocated)\r\n    if (action != NULL) {\r\n      action->task_to_notify = task_to_notify;\r\n      action->notify_action = notify_action;\r\n      action->value = value;\r\n    }\r\n  }\r\n  mutex_give(task_notify_when_deleting_mutex);\r\n}\r\n\r\n// NOTE: this code is untested, probably works, but also has a terrible name (task_notify_when_deleting_unsubscribe)\r\n// void task_notify_when_deleting_unsubscribe(task_t target_task, task_t task_to_notify) {\r\n//   task_to_notify = (task_to_notify == NULL) ? pxCurrentTCB : task_to_notify;\r\n//   target_task = (target_task == NULL) ? pxCurrentTCB : target_task;\r\n//\r\n//   if (task_to_notify == target_task || !task_to_notify || !target_task) {\r\n//     return;\r\n//   }\r\n//\r\n//   linked_list_s_t* ll = pvTaskGetThreadLocalStoragePointer(target_task, TLSP_IDX);\r\n//   if (ll != NULL) {\r\n//     struct notify_delete_action* action = _find_task(ll, task_to_notify);\r\n//     if (action != NULL) {\r\n//       linked_list_remove_data(ll, action);\r\n//       kfree(action);\r\n//     }\r\n//   }\r\n// }\r\n\r\nstatic void unsubscribe_hook_cb(ll_node_s_t* node, void* task_to_remove) {\r\n  task_t subscription = node->payload.data;\r\n\r\n  linked_list_s_t* subscriptions_list = pvTaskGetThreadLocalStoragePointer(subscription, SUBSCRIBERS_TLSP_IDX);\r\n  if (subscriptions_list != NULL) {\r\n    linked_list_remove_data(subscriptions_list, task_to_remove);\r\n  }\r\n}\r\n\r\nstatic void delete_hook_cb(ll_node_s_t* node, void* ignore) {\r\n  struct notify_delete_action* action = node->payload.data;\r\n  if (action != NULL) {\r\n    task_notify_ext(action->task_to_notify, action->value, action->notify_action, NULL);\r\n    kfree(action);\r\n    node->payload.data = NULL;\r\n  }\r\n}\r\n\r\nvoid task_notify_when_deleting_hook(task_t task) {\r\n  mutex_take(task_notify_when_deleting_mutex, TIMEOUT_MAX);\r\n  // if this task was subscribed to any other task deletion events, unsubscribe\r\n  linked_list_s_t* ll = pvTaskGetThreadLocalStoragePointer(task, SUBSCRIPTIONS_TLSP_IDX);\r\n  if (ll != NULL) {\r\n    linked_list_foreach(ll, unsubscribe_hook_cb, task);\r\n    linked_list_free(ll);\r\n    vTaskSetThreadLocalStoragePointer(task, SUBSCRIPTIONS_TLSP_IDX, NULL);\r\n  }\r\n  // notify subscribed tasks of this task's deletion\r\n  ll = pvTaskGetThreadLocalStoragePointer(task, SUBSCRIBERS_TLSP_IDX);\r\n  if (ll != NULL) {\r\n    linked_list_foreach(ll, delete_hook_cb, NULL);\r\n    linked_list_free(ll);\r\n    vTaskSetThreadLocalStoragePointer(task, SUBSCRIBERS_TLSP_IDX, NULL); // for good measure\r\n  }\r\n  mutex_give(task_notify_when_deleting_mutex);\r\n}\r\n"
  },
  {
    "path": "src/rtos/tasks.c",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n/* Standard includes. */\n#include <stdlib.h>\n#include <string.h>\n\n#include \"v5_api.h\"\n\n/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining\nall the API functions to use the MPU wrappers.  That should only be done when\ntask.h is included from an application file. */\n#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE\n\n/* FreeRTOS includes. */\n#include \"FreeRTOS.h\"\n#include \"task.h\"\n#include \"timers.h\"\n#include \"stack_macros.h\"\n\n/* Lint e961 and e750 are suppressed as a MISRA exception justified because the\nMPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the\nheader files above, but not in this file, in order to generate the correct\nprivileged Vs unprivileged linkage and placement. */\n#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\n\n/* Set configUSE_STATS_FORMATTING_FUNCTIONS to 2 to include the stats formatting\nfunctions but without including stdio.h here. */\n#if ( configUSE_STATS_FORMATTING_FUNCTIONS == 1 )\n\t/* At the bottom of this file are two optional functions that can be used\n\tto generate human readable text from the raw data generated by the\n\tuxTaskGetSystemState() function.  Note the formatting functions are provided\n\tfor convenience only, and are NOT considered part of the kernel. */\n\t#include <stdio.h>\n#endif /* configUSE_STATS_FORMATTING_FUNCTIONS == 1 ) */\n\n#if( configUSE_PREEMPTION == 0 )\n\t/* If the cooperative scheduler is being used then a yield should not be\n\tperformed just because a higher priority task has been woken. */\n\t#define taskYIELD_IF_USING_PREEMPTION()\n#else\n\t#define taskYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API()\n#endif\n\n/* Values that can be assigned to the ucNotifyState member of the TCB. */\n#define taskNOT_WAITING_NOTIFICATION\t( ( uint8_t ) 0 )\n#define taskWAITING_NOTIFICATION\t\t( ( uint8_t ) 1 )\n#define taskNOTIFICATION_RECEIVED\t\t( ( uint8_t ) 2 )\n\n/*\n * The value used to fill the stack of a task when the task is created.  This\n * is used purely for checking the high water mark for tasks.\n */\n#define tskSTACK_FILL_BYTE\t( 0xa5U )\n\n/* Sometimes the FreeRTOSConfig.h settings only allow a task to be created using\ndynamically allocated RAM, in which case when any task is deleted it is known\nthat both the task's stack and TCB need to be freed.  Sometimes the\nFreeRTOSConfig.h settings only allow a task to be created using statically\nallocated RAM, in which case when any task is deleted it is known that neither\nthe task's stack or TCB should be freed.  Sometimes the FreeRTOSConfig.h\nsettings allow a task to be created using either statically or dynamically\nallocated RAM, in which case a member of the TCB is used to record whether the\nstack and/or TCB were allocated statically or dynamically, so when a task is\ndeleted the RAM that was allocated dynamically is freed again and no attempt is\nmade to free the RAM that was allocated statically.\ntskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is only true if it is possible for a\ntask to be created using either statically or dynamically allocated RAM.  Note\nthat if portUSING_MPU_WRAPPERS is 1 then a protected task can be created with\na statically allocated stack and a dynamically allocated TCB.\n!!!NOTE!!! If the definition of tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is\nchanged then the definition of static_task_s_t must also be updated. */\n#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE\t( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\n#define tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB \t\t( ( uint8_t ) 0 )\n#define tskSTATICALLY_ALLOCATED_STACK_ONLY \t\t\t( ( uint8_t ) 1 )\n#define tskSTATICALLY_ALLOCATED_STACK_AND_TCB\t\t( ( uint8_t ) 2 )\n\n/* If any of the following are set then task stacks are filled with a known\nvalue so the high water mark can be determined.  If none of the following are\nset then don't fill the stack so there is no unnecessary dependency on memset. */\n#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\n\t#define tskSET_NEW_STACKS_TO_KNOWN_VALUE\t1\n#else\n\t#define tskSET_NEW_STACKS_TO_KNOWN_VALUE\t0\n#endif\n\n/*\n * Macros used by vListTask to indicate which state a task is in.\n */\n#define tskRUNNING_CHAR\t\t( 'X' )\n#define tskBLOCKED_CHAR\t\t( 'B' )\n#define tskREADY_CHAR\t\t( 'R' )\n#define tskDELETED_CHAR\t\t( 'D' )\n#define tskSUSPENDED_CHAR\t( 'S' )\n\n/*\n * Some kernel aware debuggers require the data the debugger needs access to be\n * global, rather than file scope.\n */\n#ifdef portREMOVE_STATIC_QUALIFIER\n\t#define static\n#endif\n\n/* The name allocated to the Idle task.  This can be overridden by defining\nconfigIDLE_TASK_NAME in FreeRTOSConfig.h. */\n#ifndef configIDLE_TASK_NAME\n\t#define configIDLE_TASK_NAME \"IDLE\"\n#endif\n\n#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 )\n\n\t/* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 0 then task selection is\n\tperformed in a generic way that is not optimised to any particular\n\tmicrocontroller architecture. */\n\n\t/* uxTopReadyPriority holds the priority of the highest priority ready\n\tstate task. */\n\t#define taskRECORD_READY_PRIORITY( uxPriority )\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tif( ( uxPriority ) > uxTopReadyPriority )\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tuxTopReadyPriority = ( uxPriority );\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t} /* taskRECORD_READY_PRIORITY */\n\n\t/*-----------------------------------------------------------*/\n\n\t#define taskSELECT_HIGHEST_PRIORITY_TASK()\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tuint32_t uxTopPriority = uxTopReadyPriority;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t/* Find the highest priority queue that contains ready tasks. */\t\t\t\t\t\t\t\t\\\n\t\twhile( listLIST_IS_EMPTY( &( pxReadyTasksLists[ uxTopPriority ] ) ) )\t\t\t\t\t\t\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tconfigASSERT( uxTopPriority );\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t--uxTopPriority;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t/* listGET_OWNER_OF_NEXT_ENTRY indexes through the list, so the tasks of\t\t\t\t\t\t\\\n\t\tthe\tsame priority get an equal share of the processor time. */\t\t\t\t\t\t\t\t\t\\\n\t\tlistGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) );\t\t\t\\\n\t\tuxTopReadyPriority = uxTopPriority;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t} /* taskSELECT_HIGHEST_PRIORITY_TASK */\n\n\t/*-----------------------------------------------------------*/\n\n\t/* Define away taskRESET_READY_PRIORITY() and portRESET_READY_PRIORITY() as\n\tthey are only required when a port optimised method of task selection is\n\tbeing used. */\n\t#define taskRESET_READY_PRIORITY( uxPriority )\n\t#define portRESET_READY_PRIORITY( uxPriority, uxTopReadyPriority )\n\n#else /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\n\n\t/* If configUSE_PORT_OPTIMISED_TASK_SELECTION is 1 then task selection is\n\tperformed in a way that is tailored to the particular microcontroller\n\tarchitecture being used. */\n\n\t/* A port optimised version is provided.  Call the port defined macros. */\n\t#define taskRECORD_READY_PRIORITY( uxPriority )\tportRECORD_READY_PRIORITY( uxPriority, uxTopReadyPriority )\n\n\t/*-----------------------------------------------------------*/\n\n\t#define taskSELECT_HIGHEST_PRIORITY_TASK()\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tuint32_t uxTopPriority;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t/* Find the highest priority list that contains ready tasks. */\t\t\t\t\t\t\t\t\\\n\t\tportGET_HIGHEST_PRIORITY( uxTopPriority, uxTopReadyPriority );\t\t\t\t\t\t\t\t\\\n\t\tconfigASSERT( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ uxTopPriority ] ) ) > 0 );\t\t\\\n\t\tlistGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopPriority ] ) );\t\t\\\n\t} /* taskSELECT_HIGHEST_PRIORITY_TASK() */\n\n\t/*-----------------------------------------------------------*/\n\n\t/* A port optimised version is provided, call it only if the TCB being reset\n\tis being referenced from a ready list.  If it is referenced from a delayed\n\tor suspended list then it won't be in a ready list. */\n\t#define taskRESET_READY_PRIORITY( uxPriority )\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\tif( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ ( uxPriority ) ] ) ) == ( uint32_t ) 0 )\t\\\n\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tportRESET_READY_PRIORITY( ( uxPriority ), ( uxTopReadyPriority ) );\t\t\t\t\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t}\n\n#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\n\n/*-----------------------------------------------------------*/\n\n/* pxDelayedTaskList and pxOverflowDelayedTaskList are switched when the tick\ncount overflows. */\n#define taskSWITCH_DELAYED_LISTS()\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n{\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tList_t *pxTemp;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t/* The delayed tasks list should be empty when the lists are switched. */\t\t\t\t\t\t\\\n\tconfigASSERT( ( listLIST_IS_EMPTY( pxDelayedTaskList ) ) );\t\t\t\t\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tpxTemp = pxDelayedTaskList;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tpxDelayedTaskList = pxOverflowDelayedTaskList;\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tpxOverflowDelayedTaskList = pxTemp;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\txNumOfOverflows++;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tprvResetNextTaskUnblockTime();\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n}\n\n/*-----------------------------------------------------------*/\n\n/*\n * Place the task represented by pxTCB into the appropriate ready list for\n * the task.  It is inserted at the end of the list.\n */\n#define prvAddTaskToReadyList( pxTCB )\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\ttraceMOVED_TASK_TO_READY_STATE( pxTCB );\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\ttaskRECORD_READY_PRIORITY( ( pxTCB )->uxPriority );\t\t\t\t\t\t\t\t\t\t\t\t\\\n\tvListInsertEnd( &( pxReadyTasksLists[ ( pxTCB )->uxPriority ] ), &( ( pxTCB )->xStateListItem ) ); \\\n\ttracePOST_MOVED_TASK_TO_READY_STATE( pxTCB )\n/*-----------------------------------------------------------*/\n\n/*\n * Several functions take an task_t parameter that can optionally be NULL,\n * where NULL is used to indicate that the handle of the currently executing\n * task should be used in place of the parameter.  This macro simply checks to\n * see if the parameter is NULL and returns a pointer to the appropriate TCB.\n */\n#define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( TCB_t * ) pxCurrentTCB : ( TCB_t * ) ( pxHandle ) )\n\n/* The item value of the event list item is normally used to hold the priority\nof the task to which it belongs (coded to allow it to be held in reverse\npriority order).  However, it is occasionally borrowed for other purposes.  It\nis important its value is not updated due to a task priority change while it is\nbeing used for another purpose.  The following bit definition is used to inform\nthe scheduler that the value should not be changed - in which case it is the\nresponsibility of whichever module is using the value to ensure it gets set back\nto its original value when it is released. */\n#if( configUSE_16_BIT_TICKS == 1 )\n\t#define taskEVENT_LIST_ITEM_VALUE_IN_USE\t0x8000U\n#else\n\t#define taskEVENT_LIST_ITEM_VALUE_IN_USE\t0x80000000UL\n#endif\n\n#include \"tcb.h\"\n\n/*lint -save -e956 A manual analysis and inspection has been used to determine\nwhich static variables must be declared volatile. */\n\nTCB_t * volatile pxCurrentTCB = NULL;\n\n/* Lists for ready and blocked tasks. --------------------*/\nstatic List_t pxReadyTasksLists[ configMAX_PRIORITIES ];/*< Prioritised ready tasks. */\nstatic List_t xDelayedTaskList1;\t\t\t\t\t\t/*< Delayed tasks. */\nstatic List_t xDelayedTaskList2;\t\t\t\t\t\t/*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */\nstatic List_t * volatile pxDelayedTaskList;\t\t\t\t/*< Points to the delayed task list currently being used. */\nstatic List_t * volatile pxOverflowDelayedTaskList;\t\t/*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */\nstatic List_t xPendingReadyList;\t\t\t\t\t\t/*< Tasks that have been readied while the scheduler was suspended.  They will be moved to the ready list when the scheduler is resumed. */\n\n#if( INCLUDE_vTaskDelete == 1 )\n\n\tstatic List_t xTasksWaitingTermination;\t\t\t\t/*< Tasks that have been deleted - but their memory not yet freed. */\n\tstatic volatile uint32_t uxDeletedTasksWaitingCleanUp = ( uint32_t ) 0U;\n\n#endif\n\n#if ( INCLUDE_vTaskSuspend == 1 )\n\n\tstatic List_t xSuspendedTaskList;\t\t\t\t\t/*< Tasks that are currently suspended. */\n\n#endif\n\n/* Other file private variables. --------------------------------*/\nstatic volatile uint32_t uxCurrentNumberOfTasks \t= ( uint32_t ) 0U;\nstatic volatile uint32_t xTickCount \t\t\t\t= ( uint32_t ) configINITIAL_TICK_COUNT;\nstatic volatile uint32_t uxTopReadyPriority \t\t= tskIDLE_PRIORITY;\nstatic volatile int32_t xSchedulerRunning \t\t= pdFALSE;\nstatic volatile uint32_t uxPendedTicks \t\t\t= ( uint32_t ) 0U;\nstatic volatile int32_t xYieldPending \t\t\t= pdFALSE;\nstatic volatile int32_t xNumOfOverflows \t\t\t= ( int32_t ) 0;\nstatic uint32_t uxTaskNumber \t\t\t\t\t= ( uint32_t ) 0U;\nstatic volatile uint32_t xNextTaskUnblockTime\t\t= ( uint32_t ) 0U; /* Initialised to portMAX_DELAY before the scheduler starts. */\nstatic task_t xIdleTaskHandle\t\t\t\t\t= NULL;\t\t\t/*< Holds the handle of the idle task.  The idle task is created automatically when the scheduler is started. */\n\n/* Context switches are held pending while the scheduler is suspended.  Also,\ninterrupts must not manipulate the xStateListItem of a TCB, or any of the\nlists the xStateListItem can be referenced from, if the scheduler is suspended.\nIf an interrupt needs to unblock a task while the scheduler is suspended then it\nmoves the task's event list item into the xPendingReadyList, ready for the\nkernel to move the task from the pending ready list into the real ready list\nwhen the scheduler is unsuspended.  The pending ready list itself can only be\naccessed from a critical section. */\nstatic volatile uint32_t uxSchedulerSuspended\t= ( uint32_t ) pdFALSE;\n\n#if ( configGENERATE_RUN_TIME_STATS == 1 )\n\n\tstatic uint32_t ulTaskSwitchedInTime = 0UL;\t/*< Holds the value of a timer/counter the last time a task was switched in. */\n\tstatic uint32_t ulTotalRunTime = 0UL;\t\t/*< Holds the total amount of execution time as defined by the run time counter clock. */\n\n#endif\n\n/*lint -restore */\n\n/*-----------------------------------------------------------*/\n\n/* Callback function prototypes. --------------------------*/\n#if(  configCHECK_FOR_STACK_OVERFLOW > 0 )\n\n\textern void vApplicationStackOverflowHook( task_t task, char *pcTaskName );\n\n#endif\n\n#if( configUSE_TICK_HOOK > 0 )\n\n\textern void vApplicationTickHook( void );\n\n#endif\n\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\n\textern void vApplicationGetIdleTaskMemory( static_task_s_t **ppxIdleTaskTCBBuffer, task_stack_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );\n\n#endif\n\n/* File private functions. --------------------------------*/\n\n/**\n * Utility task that simply returns pdTRUE if the task referenced by task is\n * currently in the Suspended state, or pdFALSE if the task referenced by task\n * is in any other state.\n */\n#if ( INCLUDE_vTaskSuspend == 1 )\n\n\tstatic int32_t prvTaskIsTaskSuspended( const task_t task ) ;\n\n#endif /* INCLUDE_vTaskSuspend */\n\n/*\n * Utility to ready all the lists used by the scheduler.  This is called\n * automatically upon the creation of the first task.\n */\nstatic void prvInitialiseTaskLists( void ) ;\n\n/*\n * The idle task, which as all tasks is implemented as a never ending loop.\n * The idle task is automatically created and added to the ready lists upon\n * creation of the first user task.\n *\n * The portTASK_FUNCTION_PROTO() macro is used to allow port/compiler specific\n * language extensions.  The equivalent prototype for this function is:\n *\n * void prvIdleTask( void *pvParameters );\n *\n */\nstatic portTASK_FUNCTION_PROTO( prvIdleTask, pvParameters );\n\n/*\n * Utility to free all memory allocated by the scheduler to hold a TCB,\n * including the stack pointed to by the TCB.\n *\n * This does not free memory allocated by the task itself (i.e. memory\n * allocated by calls to kmalloc from within the tasks application code).\n */\n#if ( INCLUDE_vTaskDelete == 1 )\n\n\tstatic void prvDeleteTCB( TCB_t *pxTCB ) ;\n\n#endif\n\n/*\n * Used only by the idle task.  This checks to see if anything has been placed\n * in the list of tasks waiting to be deleted.  If so the task is cleaned up\n * and its TCB deleted.\n */\nstatic void prvCheckTasksWaitingTermination( void ) ;\n\n/*\n * The currently executing task is entering the Blocked state.  Add the task to\n * either the current or the overflow delayed task list.\n */\nstatic void prvAddCurrentTaskToDelayedList( uint32_t timeout, const int32_t xCanBlockIndefinitely ) ;\n\n/*\n * Fills an TaskStatus_t structure with information on each task that is\n * referenced from the pxList list (which may be a ready list, a delayed list,\n * a suspended list, etc.).\n *\n * THIS FUNCTION IS INTENDED FOR DEBUGGING ONLY, AND SHOULD NOT BE CALLED FROM\n * NORMAL APPLICATION CODE.\n */\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tstatic uint32_t prvListTasksWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, task_state_e_t eState ) ;\n\n#endif\n\n/*\n * Searches pxList for a task with name name - returning a handle to\n * the task if it is found, or NULL if the task is not found.\n */\n#if ( INCLUDE_xTaskGetHandle == 1 )\n\n\tstatic TCB_t *prvSearchForNameWithinSingleList( List_t *pxList, const char name[] ) ;\n\n#endif\n\n/*\n * When a task is created, the stack of the task is filled with a known value.\n * This function determines the 'high water mark' of the task stack by\n * determining how much of the stack remains at the original preset value.\n */\n#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\n\n\tstatic uint16_t prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte ) ;\n\n#endif\n\n/*\n * Return the amount of time, in ticks, that will pass before the kernel will\n * next move a task from the Blocked state to the Running state.\n *\n * This conditional compilation should use inequality to 0, not equality to 1.\n * This is to ensure portSUPPRESS_TICKS_AND_SLEEP() can be called when user\n * defined low power mode implementations require configUSE_TICKLESS_IDLE to be\n * set to a value other than 1.\n */\n#if ( configUSE_TICKLESS_IDLE != 0 )\n\n\tstatic uint32_t prvGetExpectedIdleTime( void ) ;\n\n#endif\n\n/*\n * Set xNextTaskUnblockTime to the time at which the next Blocked state task\n * will exit the Blocked state.\n */\nstatic void prvResetNextTaskUnblockTime( void );\n\n#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\n\n\t/*\n\t * Helper function used to pad task names with spaces when printing out\n\t * human readable tables of task information.\n\t */\n\tstatic char *prvWriteNameToBuffer( char *pcBuffer, const char *pcTaskName ) ;\n\n#endif\n\n/*\n * Called after a Task_t structure has been allocated either statically or\n * dynamically to fill in the structure's members.\n */\nstatic void prvInitialiseNewTask( \ttask_fn_t pxTaskCode,\n\t\t\t\t\t\t\t\t\tconst char * const pcName, \t\t/*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t\t\t\t\t\t\t\t\tconst uint32_t ulStackDepth,\n\t\t\t\t\t\t\t\t\tvoid * const pvParameters,\n\t\t\t\t\t\t\t\t\tuint32_t uxPriority,\n\t\t\t\t\t\t\t\t\ttask_t * const pxCreatedTask,\n\t\t\t\t\t\t\t\t\tTCB_t *pxNewTCB\n\t\t\t\t\t\t\t\t\t) ;\n\n/*\n * Called after a new task has been created and initialised to place the task\n * under the control of the scheduler.\n */\nstatic void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) ;\n\n/*\n * freertos_tasks_c_additions_init() should only be called if the user definable\n * macro FREERTOS_TASKS_C_ADDITIONS_INIT() is defined, as that is the only macro\n * called by the function.\n */\n#ifdef FREERTOS_TASKS_C_ADDITIONS_INIT\n\n\tstatic void freertos_tasks_c_additions_init( void ) ;\n\n#endif\n\n/*-----------------------------------------------------------*/\n\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\n\ttask_t task_create_static(\ttask_fn_t task_code, void* const param,\n\t\t\t\t\t\t\t\tuint32_t priority, const size_t stack_size,\n\t\t\t\t\t\t\t\tconst char* const name,\n\t\t\t\t\t\t\t\ttask_stack_t * const stack_buffer,\n\t\t\t\t\t\t\t\tstatic_task_s_t * const task_buffer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t{\n\tTCB_t *pxNewTCB;\n\ttask_t xReturn;\n\n\t\tconfigASSERT( stack_buffer != NULL );\n\t\tconfigASSERT( task_buffer != NULL );\n\n\t\t#if( configASSERT_DEFINED == 1 )\n\t\t{\n\t\t\t/* Sanity check that the size of the structure used to declare a\n\t\t\tvariable of type static_task_s_t equals the size of the real task\n\t\t\tstructure. */\n\t\t\tvolatile size_t xSize = sizeof( static_task_s_t );\n\t\t\tconfigASSERT( xSize == sizeof( TCB_t ) );\n\t\t}\n\t\t#endif /* configASSERT_DEFINED */\n\n\n\t\tif ((task_buffer != NULL) && (stack_buffer != NULL))\n\t\t{\n      /* Finish task termination if the TCB is awaiting termination by the IDLE\n      task. xTasksWaitingTermination list would then have a pointer to (this)\n      task in an active task list, which would end up destroying that list in\n      unexpected ways */\n\t\t\tvoid task_finish_termination(TCB_t*);\n\t\t\ttask_finish_termination((TCB_t*)task_buffer);\n\t\t\t/* The memory used for the task's TCB and stack are passed into this\n\t\t\tfunction - use them. */\n\t\t\tpxNewTCB = (TCB_t*)task_buffer; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */\n\t\t\tpxNewTCB->pxStack = (task_stack_t*)stack_buffer;\n\n\t\t\t#if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\n\t\t\t{\n\t\t\t\t/* Tasks can be created statically or dynamically, so note this\n\t\t\t\ttask was created statically in case the task is later deleted. */\n\t\t\t\tpxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB;\n\t\t\t}\n\t\t\t#endif /* configSUPPORT_DYNAMIC_ALLOCATION */\n\n\t\t\tprvInitialiseNewTask( task_code, name, stack_size, param, priority, &xReturn, pxNewTCB );\n\t\t\tprvAddNewTaskToReadyList( pxNewTCB );\n\t\t}\n\t\telse\n\t\t{\n\t\t\terrno = EINVAL;\n\t\t\txReturn = NULL;\n\t\t}\n\n\t\treturn xReturn;\n\t}\n\n#endif /* SUPPORT_STATIC_ALLOCATION */\n/*-----------------------------------------------------------*/\n/*-----------------------------------------------------------*/\n\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\n\ttask_t task_create(task_fn_t function,\n\t\t\t\t\t\t\tvoid* const parameters,\n\t\t\t\t\t\t\tuint32_t prio,\n\t\t\t\t\t\t\tconst uint16_t stack_depth,\n\t\t\t\t\t\t\tconst char* const name)\t\t/*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t{\n\tTCB_t* new_tcb;\n\ttask_t return_val = NULL;\n\n\t\t/* If the stack grows down then allocate the stack then the TCB so the stack\n\t\tdoes not grow into the TCB.  Likewise if the stack grows up then allocate\n\t\tthe TCB then the stack. */\n\t\t#if( portSTACK_GROWTH > 0 )\n\t\t{\n\t\t\t/* Allocate space for the TCB.  Where the memory comes from depends on\n\t\t\tthe implementation of the port malloc function and whether or not static\n\t\t\tallocation is being used. */\n\t\t\tnew_tcb = ( TCB_t * ) kmalloc( sizeof( TCB_t ) );\n\n\t\t\tif( new_tcb != NULL )\n\t\t\t{\n\t\t\t\t/* Allocate space for the stack used by the task being created.\n\t\t\t\tThe base of the stack memory stored in the TCB so the task can\n\t\t\t\tbe deleted later if required. */\n\t\t\t\tnew_tcb->pxStack = ( task_stack_t * ) kmalloc( ( ( ( size_t ) usStackDepth ) * sizeof( task_stack_t ) ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\n\t\t\t\tif( new_tcb->pxStack == NULL )\n\t\t\t\t{\n\t\t\t\t\t/* Could not allocate the stack.  Delete the allocated TCB. */\n\t\t\t\t\tkfree( new_tcb );\n\t\t\t\t\tnew_tcb = NULL;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t#else /* portSTACK_GROWTH */\n\t\t{\n\t\ttask_stack_t* stack;\n\n\t\t\t/* Allocate space for the stack used by the task being created. */\n\t\t\tstack = ( task_stack_t * ) kmalloc( ( ( ( size_t ) stack_depth ) * sizeof( task_stack_t ) ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\n\t\t\tif( stack != NULL )\n\t\t\t{\n\t\t\t\t/* Allocate space for the TCB. */\n\t\t\t\tnew_tcb = ( TCB_t * ) kmalloc( sizeof( TCB_t ) ); /*lint !e961 MISRA exception as the casts are only redundant for some paths. */\n\n\t\t\t\tif( new_tcb != NULL )\n\t\t\t\t{\n\t\t\t\t\t/* Store the stack location in the TCB. */\n\t\t\t\t\tnew_tcb->pxStack = stack;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* The stack cannot be used as the TCB was not created.  Free\n\t\t\t\t\tit again. */\n\t\t\t\t\terrno = ENOMEM;\n\t\t\t\t\tkfree(stack);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\terrno = ENOMEM;\n\t\t\t\tnew_tcb = NULL;\n\t\t\t}\n\t\t}\n\t\t#endif /* portSTACK_GROWTH */\n\n\t\tif (new_tcb != NULL )\n\t\t{\n\t\t\t#if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\n\t\t\t{\n\t\t\t\t/* Tasks can be created statically or dynamically, so note this\n\t\t\t\ttask was created dynamically in case it is later deleted. */\n\t\t\t\tnew_tcb->ucStaticallyAllocated = tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB;\n\t\t\t}\n\t\t\t#endif /* configSUPPORT_STATIC_ALLOCATION */\n\n\t\t\tprvInitialiseNewTask(function, name, ( uint32_t ) stack_depth, parameters, prio,\n\t\t\t\t&return_val, new_tcb);\n\t\t\tprvAddNewTaskToReadyList(new_tcb);\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn_val = NULL;\n\t\t\terrno = ENOMEM;\n\t\t}\n\n\t\treturn return_val;\n\t}\n\n#endif /* configSUPPORT_DYNAMIC_ALLOCATION */\n/*-----------------------------------------------------------*/\n\nstatic void prvInitialiseNewTask( \ttask_fn_t pxTaskCode,\n\t\t\t\t\t\t\t\t\tconst char * const pcName,\t\t/*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t\t\t\t\t\t\t\t\tconst uint32_t ulStackDepth,\n\t\t\t\t\t\t\t\t\tvoid * const pvParameters,\n\t\t\t\t\t\t\t\t\tuint32_t uxPriority,\n\t\t\t\t\t\t\t\t\ttask_t * const pxCreatedTask,\n\t\t\t\t\t\t\t\t\tTCB_t *pxNewTCB\n\t\t\t\t\t\t\t\t)\n{\ntask_stack_t *pxTopOfStack;\nuint32_t x;\n\n\t/* Avoid dependency on memset() if it is not required. */\n\t#if( tskSET_NEW_STACKS_TO_KNOWN_VALUE == 1 )\n\t{\n\t\t/* Fill the stack with a known value to assist debugging. */\n\t\t( void ) memset( pxNewTCB->pxStack, ( int ) tskSTACK_FILL_BYTE, ( size_t ) ulStackDepth * sizeof( task_stack_t ) );\n\t}\n\t#endif /* tskSET_NEW_STACKS_TO_KNOWN_VALUE */\n\n\t/* Calculate the top of stack address.  This depends on whether the stack\n\tgrows from high memory to low (as per the 80x86) or vice versa.\n\tportSTACK_GROWTH is used to make the result positive or negative as required\n\tby the port. */\n\t#if( portSTACK_GROWTH < 0 )\n\t{\n\t\tpxTopOfStack = pxNewTCB->pxStack + ( ulStackDepth - ( uint32_t ) 1 );\n\t\tpxTopOfStack = ( task_stack_t * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) ); /*lint !e923 MISRA exception.  Avoiding casts between pointers and integers is not practical.  Size differences accounted for using portPOINTER_SIZE_TYPE type. */\n\n\t\t/* Check the alignment of the calculated top of stack is correct. */\n\t\tconfigASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\n\n\t\t#if( configRECORD_STACK_HIGH_ADDRESS == 1 )\n\t\t{\n\t\t\t/* Also record the stack's high address, which may assist\n\t\t\tdebugging. */\n\t\t\tpxNewTCB->pxEndOfStack = pxTopOfStack;\n\t\t}\n\t\t#endif /* configRECORD_STACK_HIGH_ADDRESS */\n\t}\n\t#else /* portSTACK_GROWTH */\n\t{\n\t\tpxTopOfStack = pxNewTCB->pxStack;\n\n\t\t/* Check the alignment of the stack buffer is correct. */\n\t\tconfigASSERT( ( ( ( portPOINTER_SIZE_TYPE ) pxNewTCB->pxStack & ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\n\n\t\t/* The other extreme of the stack space is required if stack checking is\n\t\tperformed. */\n\t\tpxNewTCB->pxEndOfStack = pxNewTCB->pxStack + ( ulStackDepth - ( uint32_t ) 1 );\n\t}\n\t#endif /* portSTACK_GROWTH */\n\n\t/* Store the task name in the TCB. */\n\tfor( x = ( uint32_t ) 0; x < ( uint32_t ) configMAX_TASK_NAME_LEN; x++ )\n\t{\n\t\tpxNewTCB->pcTaskName[ x ] = pcName[ x ];\n\n\t\t/* Don't copy all configMAX_TASK_NAME_LEN if the string is shorter than\n\t\tconfigMAX_TASK_NAME_LEN characters just in case the memory after the\n\t\tstring is not accessible (extremely unlikely). */\n\t\tif( pcName[ x ] == 0x00 )\n\t\t{\n\t\t\tbreak;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\n\t/* Ensure the name string is terminated in the case that the string length\n\twas greater or equal to configMAX_TASK_NAME_LEN. */\n\tpxNewTCB->pcTaskName[ configMAX_TASK_NAME_LEN - 1 ] = '\\0';\n\n\t/* This is used as an array index so must ensure it's not too large.  First\n\tremove the privilege bit if one is present. */\n\tif( uxPriority >= ( uint32_t ) configMAX_PRIORITIES )\n\t{\n\t\tuxPriority = ( uint32_t ) configMAX_PRIORITIES - ( uint32_t ) 1U;\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\tpxNewTCB->uxPriority = uxPriority;\n\t#if ( configUSE_MUTEXES == 1 )\n\t{\n\t\tpxNewTCB->uxBasePriority = uxPriority;\n\t\tpxNewTCB->uxMutexesHeld = 0;\n\t}\n\t#endif /* configUSE_MUTEXES */\n\n\tvListInitialiseItem( &( pxNewTCB->xStateListItem ) );\n\tvListInitialiseItem( &( pxNewTCB->xEventListItem ) );\n\n\t/* Set the pxNewTCB as a link back from the list_item_t.  This is so we can get\n\tback to\tthe containing TCB from a generic item in a list. */\n\tlistSET_LIST_ITEM_OWNER( &( pxNewTCB->xStateListItem ), pxNewTCB );\n\n\t/* Event lists are always in priority order. */\n\tlistSET_LIST_ITEM_VALUE( &( pxNewTCB->xEventListItem ), ( uint32_t ) configMAX_PRIORITIES - ( uint32_t ) uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\tlistSET_LIST_ITEM_OWNER( &( pxNewTCB->xEventListItem ), pxNewTCB );\n\n\t#if ( portCRITICAL_NESTING_IN_TCB == 1 )\n\t{\n\t\tpxNewTCB->uxCriticalNesting = ( uint32_t ) 0U;\n\t}\n\t#endif /* portCRITICAL_NESTING_IN_TCB */\n\n\t#if ( configUSE_APPLICATION_TASK_TAG == 1 )\n\t{\n\t\tpxNewTCB->pxTaskTag = NULL;\n\t}\n\t#endif /* configUSE_APPLICATION_TASK_TAG */\n\n\t#if ( configGENERATE_RUN_TIME_STATS == 1 )\n\t{\n\t\tpxNewTCB->ulRunTimeCounter = 0UL;\n\t}\n\t#endif /* configGENERATE_RUN_TIME_STATS */\n\n\t#if( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )\n\t{\n\t\tfor( x = 0; x < ( uint32_t ) configNUM_THREAD_LOCAL_STORAGE_POINTERS; x++ )\n\t\t{\n\t\t\tpxNewTCB->pvThreadLocalStoragePointers[ x ] = NULL;\n\t\t}\n\t}\n\t#endif\n\n\t#if ( configUSE_TASK_NOTIFICATIONS == 1 )\n\t{\n\t\tpxNewTCB->ulNotifiedValue = 0;\n\t\tpxNewTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\n\t}\n\t#endif\n\n\t#if ( configUSE_NEWLIB_REENTRANT == 1 )\n\t{\n\t\t/* Initialise this task's Newlib reent structure. */\n\t\t_REENT_INIT_PTR( ( &( pxNewTCB->xNewLib_reent ) ) );\n\t}\n\t#endif\n\n\t#if( INCLUDE_xTaskAbortDelay == 1 )\n\t{\n\t\tpxNewTCB->ucDelayAborted = pdFALSE;\n\t}\n\t#endif\n\n\t/* Initialize the TCB stack to look as if the task was already running,\n\tbut had been interrupted by the scheduler.  The return address is set\n\tto the start of the task function. Once the stack has been initialised\n\tthe top of stack variable is updated. */\n\t\tpxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pxTaskCode, pvParameters );\n\n\tif( ( void * ) pxCreatedTask != NULL )\n\t{\n\t\t/* Pass the handle out in an anonymous way.  The handle can be used to\n\t\tchange the created task's priority, delete the created task, etc.*/\n\t\t*pxCreatedTask = ( task_t ) pxNewTCB;\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )\n{\n\t/* Ensure interrupts don't access the task lists while the lists are being\n\tupdated. */\n\ttaskENTER_CRITICAL();\n\t{\n\t\tuxCurrentNumberOfTasks++;\n\t\tif( pxCurrentTCB == NULL )\n\t\t{\n\t\t\t/* There are no other tasks, or all the other tasks are in\n\t\t\tthe suspended state - make this the current task. */\n\t\t\tpxCurrentTCB = pxNewTCB;\n\n\t\t\tif( uxCurrentNumberOfTasks == ( uint32_t ) 1 )\n\t\t\t{\n\t\t\t\t/* This is the first task to be created so do the preliminary\n\t\t\t\tinitialisation required.  We will not recover if this call\n\t\t\t\tfails, but we will report the failure. */\n\t\t\t\tprvInitialiseTaskLists();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* If the scheduler is not already running, make this task the\n\t\t\tcurrent task if it is the highest priority task to be created\n\t\t\tso far. */\n\t\t\tif( xSchedulerRunning == pdFALSE )\n\t\t\t{\n\t\t\t\tif( pxCurrentTCB->uxPriority <= pxNewTCB->uxPriority )\n\t\t\t\t{\n\t\t\t\t\tpxCurrentTCB = pxNewTCB;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\n\t\tuxTaskNumber++;\n\n\t\t#if ( configUSE_TRACE_FACILITY == 1 )\n\t\t{\n\t\t\t/* Add a counter into the TCB for tracing only. */\n\t\t\tpxNewTCB->uxTCBNumber = uxTaskNumber;\n\t\t}\n\t\t#endif /* configUSE_TRACE_FACILITY */\n\t\ttraceTASK_CREATE( pxNewTCB );\n\n\t\tprvAddTaskToReadyList( pxNewTCB );\n\n\t\tportSETUP_TCB( pxNewTCB );\n\t}\n\ttaskEXIT_CRITICAL();\n\n\tif( xSchedulerRunning != pdFALSE )\n\t{\n\t\t/* If the created task is of a higher priority than the current task\n\t\tthen it should run now. */\n\t\tif( pxCurrentTCB->uxPriority < pxNewTCB->uxPriority )\n\t\t{\n\t\t\ttaskYIELD_IF_USING_PREEMPTION();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n}\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_vTaskDelete == 1 )\n\n\tvoid task_delete(task_t task)\n\t{\n\tTCB_t *pxTCB;\n\n\t\tvoid task_notify_when_deleting_hook(task_t);\n\t\ttask_notify_when_deleting_hook(task);\n\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\t/* If null is passed in here then it is the calling task that is\n\t\t\tbeing deleted. */\n\t\t\tpxTCB = prvGetTCBFromHandle( task );\n\n\t\t\t/* Remove task from the ready list. */\n\t\t\tif( uxListRemove( &( pxTCB->xStateListItem ) ) == ( uint32_t ) 0 )\n\t\t\t{\n\t\t\t\ttaskRESET_READY_PRIORITY( pxTCB->uxPriority );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\n\t\t\t/* Is the task waiting on an event also? */\n\t\t\tif( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\n\t\t\t{\n\t\t\t\t( void ) uxListRemove( &( pxTCB->xEventListItem ) );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\n\t\t\t/* Increment the uxTaskNumber also so kernel aware debuggers can\n\t\t\tdetect that the task lists need re-generating.  This is done before\n\t\t\tportPRE_TASK_DELETE_HOOK() as in the Windows port that macro will\n\t\t\tnot return. */\n\t\t\tuxTaskNumber++;\n\n\t\t\tif( pxTCB == pxCurrentTCB )\n\t\t\t{\n\t\t\t\t/* A task is deleting itself.  This cannot complete within the\n\t\t\t\ttask itself, as a context switch to another task is required.\n\t\t\t\tPlace the task in the termination list.  The idle task will\n\t\t\t\tcheck the termination list and free up any memory allocated by\n\t\t\t\tthe scheduler for the TCB and stack of the deleted task. */\n\t\t\t\tvListInsertEnd( &xTasksWaitingTermination, &( pxTCB->xStateListItem ) );\n\n\t\t\t\t/* Increment the ucTasksDeleted variable so the idle task knows\n\t\t\t\tthere is a task that has been deleted and that it should therefore\n\t\t\t\tcheck the xTasksWaitingTermination list. */\n\t\t\t\t++uxDeletedTasksWaitingCleanUp;\n\n\t\t\t\t/* The pre-delete hook is primarily for the Windows simulator,\n\t\t\t\tin which Windows specific clean up operations are performed,\n\t\t\t\tafter which it is not possible to yield away from this task -\n\t\t\t\thence xYieldPending is used to latch that a context switch is\n\t\t\t\trequired. */\n\t\t\t\tportPRE_TASK_DELETE_HOOK( pxTCB, &xYieldPending );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t--uxCurrentNumberOfTasks;\n\t\t\t\tprvDeleteTCB( pxTCB );\n\n\t\t\t\t/* Reset the next expected unblock time in case it referred to\n\t\t\t\tthe task that has just been deleted. */\n\t\t\t\tprvResetNextTaskUnblockTime();\n\t\t\t}\n\n\t\t\ttraceTASK_DELETE( pxTCB );\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\t/* Force a reschedule if it is the currently running task that has just\n\t\tbeen deleted. */\n\t\tif( xSchedulerRunning != pdFALSE )\n\t\t{\n\t\t\tif( pxTCB == pxCurrentTCB )\n\t\t\t{\n\t\t\t\tconfigASSERT( uxSchedulerSuspended == 0 );\n\t\t\t\tportYIELD_WITHIN_API();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t}\n\n  // Check if a task is awaiting termination and finish termination if it is\n\tvoid task_finish_termination(TCB_t* pxTCB)\n\t{\n\t\t\tuint8_t doCleanup = 0;\n\n\t\t\ttaskENTER_CRITICAL();\n\t\t\t{\n\t\t\tlist_item_t* pxStateListItem = &( pxTCB->xStateListItem );\n\t\t\tif (pxStateListItem != NULL)\n\t\t\t{\n\t\t\t\tList_t* pxStateList = ( List_t * ) listLIST_ITEM_CONTAINER( pxStateListItem );\n\t\t\t\tif (pxStateList == &xTasksWaitingTermination && listGET_NEXT( pxStateListItem )->pxPrevious == pxStateListItem)\n\t\t\t\t{\n\t\t\t\t\t( void ) uxListRemove( &( pxTCB->xStateListItem ) );\n\t\t\t\t\t--uxCurrentNumberOfTasks;\n\t\t\t\t\t--uxDeletedTasksWaitingCleanUp;\n\t\t\t\t\tdoCleanup = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t}\n\t\t\ttaskEXIT_CRITICAL();\n\n\t\t\tif (doCleanup == 1)\n\t\t\t{\n\t\t\t\tprvDeleteTCB(pxTCB);\n\t\t\t}\n\t}\n#endif /* INCLUDE_vTaskDelete */\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_vTaskDelayUntil == 1 )\n\n\tvoid task_delay_until(uint32_t* const prev_time, const uint32_t delta)\n\t{\n\tuint32_t xTimeToWake;\n\tint32_t xAlreadyYielded, xShouldDelay = pdFALSE;\n\n\t\tconfigASSERT( prev_time );\n\t\tconfigASSERT( ( delta > 0U ) );\n\t\tconfigASSERT( uxSchedulerSuspended == 0 );\n\n\t\tconst uint32_t xTicksIncrement = pdMS_TO_TICKS(delta);\n\n\t\trtos_suspend_all();\n\t\t{\n\t\t\t/* Minor optimisation.  The tick count cannot change in this\n\t\t\tblock. */\n\t\t\tconst uint32_t xConstTickCount = xTickCount;\n\n\t\t\t/* Generate the tick time at which the task wants to wake. */\n\t\t\txTimeToWake = *prev_time + xTicksIncrement;\n\n\t\t\tif( xConstTickCount < *prev_time )\n\t\t\t{\n\t\t\t\t/* The tick count has overflowed since this function was\n\t\t\t\tlasted called.  In this case the only time we should ever\n\t\t\t\tactually delay is if the wake time has also\toverflowed,\n\t\t\t\tand the wake time is greater than the tick time.  When this\n\t\t\t\tis the case it is as if neither time had overflowed. */\n\t\t\t\tif( ( xTimeToWake < *prev_time ) && ( xTimeToWake > xConstTickCount ) )\n\t\t\t\t{\n\t\t\t\t\txShouldDelay = pdTRUE;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* The tick time has not overflowed.  In this case we will\n\t\t\t\tdelay if either the wake time has overflowed, and/or the\n\t\t\t\ttick time is less than the wake time. */\n\t\t\t\tif( ( xTimeToWake < *prev_time ) || ( xTimeToWake > xConstTickCount ) )\n\t\t\t\t{\n\t\t\t\t\txShouldDelay = pdTRUE;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/* Update the wake time ready for the next call. */\n\t\t\t*prev_time = xTimeToWake;\n\n\t\t\tif( xShouldDelay != pdFALSE )\n\t\t\t{\n\t\t\t\ttraceTASK_DELAY_UNTIL( xTimeToWake );\n\n\t\t\t\t/* prvAddCurrentTaskToDelayedList() needs the block time, not\n\t\t\t\tthe time to wake, so subtract the current tick count. */\n\t\t\t\tprvAddCurrentTaskToDelayedList( xTimeToWake - xConstTickCount, pdFALSE );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\txAlreadyYielded = rtos_resume_all();\n\n\t\t/* Force a reschedule if rtos_resume_all has not already done so, we may\n\t\thave put ourselves to sleep. */\n\t\tif( xAlreadyYielded == pdFALSE )\n\t\t{\n\t\t\tportYIELD_WITHIN_API();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\n#endif /* INCLUDE_vTaskDelayUntil */\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_vTaskDelay == 1 )\n\n\tvoid task_delay(const uint32_t milliseconds)\n\t{\n\tint32_t xAlreadyYielded = pdFALSE;\n\n\t\t/* A delay time of zero just forces a reschedule. */\n\t\tif( milliseconds > ( uint32_t ) 0U )\n\t\t{\n\t\t\tconfigASSERT( uxSchedulerSuspended == 0 );\n\t\t\trtos_suspend_all();\n\t\t\t{\n\t\t\t\ttraceTASK_DELAY();\n\n\t\t\t\t/* A task that is removed from the event list while the\n\t\t\t\tscheduler is suspended will not get placed in the ready\n\t\t\t\tlist or removed from the blocked list until the scheduler\n\t\t\t\tis resumed.\n\n\t\t\t\tThis task cannot be in an event list as it is the currently\n\t\t\t\texecuting task. */\n\t\t\t\tprvAddCurrentTaskToDelayedList( milliseconds, pdFALSE );\n\t\t\t}\n\t\t\txAlreadyYielded = rtos_resume_all();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\t/* Force a reschedule if rtos_resume_all has not already done so, we may\n\t\thave put ourselves to sleep. */\n\t\tif( xAlreadyYielded == pdFALSE )\n\t\t{\n\t\t\tportYIELD_WITHIN_API();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\nvoid delay(const uint32_t milliseconds)\n{\n  task_delay(milliseconds);\n}\n\n#endif /* INCLUDE_vTaskDelay */\n/*-----------------------------------------------------------*/\n\n#if( ( INCLUDE_eTaskGetState == 1 ) || ( configUSE_TRACE_FACILITY == 1 ) )\n\n\ttask_state_e_t task_get_state(task_t task)\n\t{\n\ttask_state_e_t eReturn;\n\tList_t *pxStateList;\n\tconst TCB_t * const pxTCB = ( TCB_t * ) task;\n\n\t\tconfigASSERT( pxTCB );\n\n\t\tif( pxTCB == pxCurrentTCB )\n\t\t{\n\t\t\t/* The task calling this function is querying its own state. */\n\t\t\teReturn = E_TASK_STATE_RUNNING;\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttaskENTER_CRITICAL();\n\t\t\t{\n\t\t\t\tpxStateList = ( List_t * ) listLIST_ITEM_CONTAINER( &( pxTCB->xStateListItem ) );\n\t\t\t}\n\t\t\ttaskEXIT_CRITICAL();\n\n\t\t\tif( ( pxStateList == pxDelayedTaskList ) || ( pxStateList == pxOverflowDelayedTaskList ) )\n\t\t\t{\n\t\t\t\t/* The task being queried is referenced from one of the Blocked\n\t\t\t\tlists. */\n\t\t\t\teReturn = E_TASK_STATE_BLOCKED;\n\t\t\t}\n\n\t\t\t#if ( INCLUDE_vTaskSuspend == 1 )\n\t\t\t\telse if( pxStateList == &xSuspendedTaskList )\n\t\t\t\t{\n\t\t\t\t\t/* The task being queried is referenced from the suspended\n\t\t\t\t\tlist.  Is it genuinely suspended or is it block\n\t\t\t\t\tindefinitely? */\n\t\t\t\t\tif( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL )\n\t\t\t\t\t{\n\t\t\t\t\t\teReturn = E_TASK_STATE_SUSPENDED;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\teReturn = E_TASK_STATE_BLOCKED;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t#endif\n\n\t\t\t#if ( INCLUDE_vTaskDelete == 1 )\n\t\t\t\telse if( ( pxStateList == &xTasksWaitingTermination ) || ( pxStateList == NULL ) )\n\t\t\t\t{\n\t\t\t\t\t/* The task being queried is referenced from the deleted\n\t\t\t\t\ttasks list, or it is not referenced from any lists at\n\t\t\t\t\tall. */\n\t\t\t\t\teReturn = E_TASK_STATE_DELETED;\n\t\t\t\t}\n\t\t\t#endif\n\n\t\t\telse /*lint !e525 Negative indentation is intended to make use of pre-processor clearer. */\n\t\t\t{\n\t\t\t\t/* If the task is not in any other state, it must be in the\n\t\t\t\tReady (including pending ready) state. */\n\t\t\t\teReturn = E_TASK_STATE_READY;\n\t\t\t}\n\t\t}\n\n\t\treturn eReturn;\n\t} /*lint !e818 task cannot be a pointer to const because it is a typedef. */\n\n#endif /* INCLUDE_eTaskGetState */\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_uxTaskPriorityGet == 1 )\n\n\tuint32_t task_get_priority(task_t task)\n\t{\n\tTCB_t *pxTCB;\n\tuint32_t uxReturn;\n\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\t/* If null is passed in here then it is the priority of the that\n\t\t\tcalled task_get_priority() that is being queried. */\n\t\t\tpxTCB = prvGetTCBFromHandle( task );\n\t\t\tuxReturn = pxTCB->uxPriority;\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\treturn uxReturn;\n\t}\n\n#endif /* INCLUDE_uxTaskPriorityGet */\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_uxTaskPriorityGet == 1 )\n\n\tuint32_t uxTaskPriorityGetFromISR( task_t task )\n\t{\n\tTCB_t *pxTCB;\n\tuint32_t uxReturn, uxSavedInterruptState;\n\n\t\t/* RTOS ports that support interrupt nesting have the concept of a\n\t\tmaximum\tsystem call (or maximum API call) interrupt priority.\n\t\tInterrupts that are\tabove the maximum system call priority are keep\n\t\tpermanently enabled, even when the RTOS kernel is in a critical section,\n\t\tbut cannot make any calls to FreeRTOS API functions.  If configASSERT()\n\t\tis defined in FreeRTOSConfig.h then\n\t\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\n\t\tfailure if a FreeRTOS API function is called from an interrupt that has\n\t\tbeen assigned a priority above the configured maximum system call\n\t\tpriority.  Only FreeRTOS functions that end in FromISR can be called\n\t\tfrom interrupts\tthat have been assigned a priority at or (logically)\n\t\tbelow the maximum system call interrupt priority.  FreeRTOS maintains a\n\t\tseparate interrupt safe API to ensure interrupt entry is as fast and as\n\t\tsimple as possible.  More information (albeit Cortex-M specific) is\n\t\tprovided on the following link:\n\t\thttp://www.freertos.org/RTOS-Cortex-M3-M4.html */\n\t\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID();\n\n\t\tuxSavedInterruptState = portSET_INTERRUPT_MASK_FROM_ISR();\n\t\t{\n\t\t\t/* If null is passed in here then it is the priority of the calling\n\t\t\ttask that is being queried. */\n\t\t\tpxTCB = prvGetTCBFromHandle( task );\n\t\t\tuxReturn = pxTCB->uxPriority;\n\t\t}\n\t\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptState );\n\n\t\treturn uxReturn;\n\t}\n\n#endif /* INCLUDE_uxTaskPriorityGet */\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_vTaskPrioritySet == 1 )\n\n\tvoid task_set_priority(task_t task, uint32_t prio)\n\t{\n\tTCB_t *pxTCB;\n\tuint32_t uxCurrentBasePriority, uxPriorityUsedOnEntry;\n\tint32_t xYieldRequired = pdFALSE;\n\n\t\tconfigASSERT( ( prio < configMAX_PRIORITIES ) );\n\n\t\t/* Ensure the new priority is valid. */\n\t\tif( prio >= ( uint32_t ) configMAX_PRIORITIES )\n\t\t{\n\t\t\tprio = ( uint32_t ) configMAX_PRIORITIES - ( uint32_t ) 1U;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\t/* If null is passed in here then it is the priority of the calling\n\t\t\ttask that is being changed. */\n\t\t\tpxTCB = prvGetTCBFromHandle( task );\n\n\t\t\ttraceTASK_PRIORITY_SET( pxTCB, prio );\n\n\t\t\t#if ( configUSE_MUTEXES == 1 )\n\t\t\t{\n\t\t\t\tuxCurrentBasePriority = pxTCB->uxBasePriority;\n\t\t\t}\n\t\t\t#else\n\t\t\t{\n\t\t\t\tuxCurrentBasePriority = pxTCB->uxPriority;\n\t\t\t}\n\t\t\t#endif\n\n\t\t\tif( uxCurrentBasePriority != prio )\n\t\t\t{\n\t\t\t\t/* The priority change may have readied a task of higher\n\t\t\t\tpriority than the calling task. */\n\t\t\t\tif( prio > uxCurrentBasePriority )\n\t\t\t\t{\n\t\t\t\t\tif( pxTCB != pxCurrentTCB )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The priority of a task other than the currently\n\t\t\t\t\t\trunning task is being raised.  Is the priority being\n\t\t\t\t\t\traised above that of the running task? */\n\t\t\t\t\t\tif( prio >= pxCurrentTCB->uxPriority )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\txYieldRequired = pdTRUE;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The priority of the running task is being raised,\n\t\t\t\t\t\tbut the running task must already be the highest\n\t\t\t\t\t\tpriority task able to run so no yield is required. */\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if( pxTCB == pxCurrentTCB )\n\t\t\t\t{\n\t\t\t\t\t/* Setting the priority of the running task down means\n\t\t\t\t\tthere may now be another task of higher priority that\n\t\t\t\t\tis ready to execute. */\n\t\t\t\t\txYieldRequired = pdTRUE;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* Setting the priority of any other task down does not\n\t\t\t\t\trequire a yield as the running task must be above the\n\t\t\t\t\tnew priority of the task being modified. */\n\t\t\t\t}\n\n\t\t\t\t/* Remember the ready list the task might be referenced from\n\t\t\t\tbefore its uxPriority member is changed so the\n\t\t\t\ttaskRESET_READY_PRIORITY() macro can function correctly. */\n\t\t\t\tuxPriorityUsedOnEntry = pxTCB->uxPriority;\n\n\t\t\t\t#if ( configUSE_MUTEXES == 1 )\n\t\t\t\t{\n\t\t\t\t\t/* Only change the priority being used if the task is not\n\t\t\t\t\tcurrently using an inherited priority. */\n\t\t\t\t\tif( pxTCB->uxBasePriority == pxTCB->uxPriority )\n\t\t\t\t\t{\n\t\t\t\t\t\tpxTCB->uxPriority = prio;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\n\t\t\t\t\t/* The base priority gets set whatever. */\n\t\t\t\t\tpxTCB->uxBasePriority = prio;\n\t\t\t\t}\n\t\t\t\t#else\n\t\t\t\t{\n\t\t\t\t\tpxTCB->uxPriority = prio;\n\t\t\t\t}\n\t\t\t\t#endif\n\n\t\t\t\t/* Only reset the event list item value if the value is not\n\t\t\t\tbeing used for anything else. */\n\t\t\t\tif( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\n\t\t\t\t{\n\t\t\t\t\tlistSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( ( uint32_t ) configMAX_PRIORITIES - ( uint32_t ) prio ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\n\t\t\t\t/* If the task is in the blocked or suspended list we need do\n\t\t\t\tnothing more than change its priority variable. However, if\n\t\t\t\tthe task is in a ready list it needs to be removed and placed\n\t\t\t\tin the list appropriate to its new priority. */\n\t\t\t\tif( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxPriorityUsedOnEntry ] ), &( pxTCB->xStateListItem ) ) != pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t/* The task is currently in its ready list - remove before\n\t\t\t\t\tadding it to it's new ready list.  As we are in a critical\n\t\t\t\t\tsection we can do this even if the scheduler is suspended. */\n\t\t\t\t\tif( uxListRemove( &( pxTCB->xStateListItem ) ) == ( uint32_t ) 0 )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* It is known that the task is in its ready list so\n\t\t\t\t\t\tthere is no need to check again and the port level\n\t\t\t\t\t\treset macro can be called directly. */\n\t\t\t\t\t\tportRESET_READY_PRIORITY( uxPriorityUsedOnEntry, uxTopReadyPriority );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t\tprvAddTaskToReadyList( pxTCB );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\n\t\t\t\tif( xYieldRequired != pdFALSE )\n\t\t\t\t{\n\t\t\t\t\ttaskYIELD_IF_USING_PREEMPTION();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\n\t\t\t\t/* Remove compiler warning about unused variables when the port\n\t\t\t\toptimised task selection is not being used. */\n\t\t\t\t( void ) uxPriorityUsedOnEntry;\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\t}\n\n#endif /* INCLUDE_vTaskPrioritySet */\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_vTaskSuspend == 1 )\n\n\tvoid task_suspend(task_t task)\n\t{\n\tTCB_t *pxTCB;\n\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\t/* If null is passed in here then it is the running task that is\n\t\t\tbeing suspended. */\n\t\t\tpxTCB = prvGetTCBFromHandle( task );\n\n\t\t\ttraceTASK_SUSPEND( pxTCB );\n\n\t\t\t/* Remove task from the ready/delayed list and place in the\n\t\t\tsuspended list. */\n\t\t\tif( uxListRemove( &( pxTCB->xStateListItem ) ) == ( uint32_t ) 0 )\n\t\t\t{\n\t\t\t\ttaskRESET_READY_PRIORITY( pxTCB->uxPriority );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\n\t\t\t/* Is the task waiting on an event also? */\n\t\t\tif( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\n\t\t\t{\n\t\t\t\t( void ) uxListRemove( &( pxTCB->xEventListItem ) );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\n\t\t\tvListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) );\n\n\t\t\t#if( configUSE_TASK_NOTIFICATIONS == 1 )\n\t\t\t{\n\t\t\t\tif( pxTCB->ucNotifyState == taskWAITING_NOTIFICATION )\n\t\t\t\t{\n\t\t\t\t\t/* The task was blocked to wait for a notification, but is\n\t\t\t\t\tnow suspended, so no notification was received. */\n\t\t\t\t\tpxTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\n\t\t\t\t}\n\t\t\t}\n\t\t\t#endif\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\tif( xSchedulerRunning != pdFALSE )\n\t\t{\n\t\t\t/* Reset the next expected unblock time in case it referred to the\n\t\t\ttask that is now in the Suspended state. */\n\t\t\ttaskENTER_CRITICAL();\n\t\t\t{\n\t\t\t\tprvResetNextTaskUnblockTime();\n\t\t\t}\n\t\t\ttaskEXIT_CRITICAL();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\tif( pxTCB == pxCurrentTCB )\n\t\t{\n\t\t\tif( xSchedulerRunning != pdFALSE )\n\t\t\t{\n\t\t\t\t/* The current task has just been suspended. */\n\t\t\t\tconfigASSERT( uxSchedulerSuspended == 0 );\n\t\t\t\tportYIELD_WITHIN_API();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* The scheduler is not running, but the task that was pointed\n\t\t\t\tto by pxCurrentTCB has just been suspended and pxCurrentTCB\n\t\t\t\tmust be adjusted to point to a different task. */\n\t\t\t\tif( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == uxCurrentNumberOfTasks )\n\t\t\t\t{\n\t\t\t\t\t/* No other tasks are ready, so set pxCurrentTCB back to\n\t\t\t\t\tNULL so when the next task is created pxCurrentTCB will\n\t\t\t\t\tbe set to point to it no matter what its relative priority\n\t\t\t\t\tis. */\n\t\t\t\t\tpxCurrentTCB = NULL;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tvTaskSwitchContext();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\n#endif /* INCLUDE_vTaskSuspend */\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_vTaskSuspend == 1 )\n\n\tstatic int32_t prvTaskIsTaskSuspended( const task_t task )\n\t{\n\tint32_t xReturn = pdFALSE;\n\tconst TCB_t * const pxTCB = ( TCB_t * ) task;\n\n\t\t/* Accesses xPendingReadyList so must be called from a critical\n\t\tsection. */\n\n\t\t/* It does not make sense to check if the calling task is suspended. */\n\t\tconfigASSERT( task );\n\n\t\t/* Is the task being resumed actually in the suspended list? */\n\t\tif( listIS_CONTAINED_WITHIN( &xSuspendedTaskList, &( pxTCB->xStateListItem ) ) != pdFALSE )\n\t\t{\n\t\t\t/* Has the task already been resumed from within an ISR? */\n\t\t\tif( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) == pdFALSE )\n\t\t\t{\n\t\t\t\t/* Is it in the suspended list because it is in the\tSuspended\n\t\t\t\tstate, or because is is blocked with no timeout? */\n\t\t\t\tif( listIS_CONTAINED_WITHIN( NULL, &( pxTCB->xEventListItem ) ) != pdFALSE ) /*lint !e961.  The cast is only redundant when NULL is used. */\n\t\t\t\t{\n\t\t\t\t\txReturn = pdTRUE;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\treturn xReturn;\n\t} /*lint !e818 task cannot be a pointer to const because it is a typedef. */\n\n#endif /* INCLUDE_vTaskSuspend */\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_vTaskSuspend == 1 )\n\n\tvoid task_resume(task_t task)\n\t{\n\tTCB_t * const pxTCB = ( TCB_t * ) task;\n\n\t\t/* It does not make sense to resume the calling task. */\n\t\tconfigASSERT( task );\n\n\t\t/* The parameter cannot be NULL as it is impossible to resume the\n\t\tcurrently executing task. */\n\t\tif( ( pxTCB != NULL ) && ( pxTCB != pxCurrentTCB ) )\n\t\t{\n\t\t\ttaskENTER_CRITICAL();\n\t\t\t{\n\t\t\t\tif( prvTaskIsTaskSuspended( pxTCB ) != pdFALSE )\n\t\t\t\t{\n\t\t\t\t\ttraceTASK_RESUME( pxTCB );\n\n\t\t\t\t\t/* The ready list can be accessed even if the scheduler is\n\t\t\t\t\tsuspended because this is inside a critical section. */\n\t\t\t\t\t( void ) uxListRemove(  &( pxTCB->xStateListItem ) );\n\t\t\t\t\tprvAddTaskToReadyList( pxTCB );\n\n\t\t\t\t\t/* A higher priority task may have just been resumed. */\n\t\t\t\t\tif( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* This yield may not cause the task just resumed to run,\n\t\t\t\t\t\tbut will leave the lists in the correct state for the\n\t\t\t\t\t\tnext yield. */\n\t\t\t\t\t\ttaskYIELD_IF_USING_PREEMPTION();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\ttaskEXIT_CRITICAL();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\n#endif /* INCLUDE_vTaskSuspend */\n\n/*-----------------------------------------------------------*/\n\n#if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )\n\n\tint32_t xTaskResumeFromISR( task_t task )\n\t{\n\tint32_t xYieldRequired = pdFALSE;\n\tTCB_t * const pxTCB = ( TCB_t * ) task;\n\tuint32_t uxSavedInterruptStatus;\n\n\t\tconfigASSERT( task );\n\n\t\t/* RTOS ports that support interrupt nesting have the concept of a\n\t\tmaximum\tsystem call (or maximum API call) interrupt priority.\n\t\tInterrupts that are\tabove the maximum system call priority are keep\n\t\tpermanently enabled, even when the RTOS kernel is in a critical section,\n\t\tbut cannot make any calls to FreeRTOS API functions.  If configASSERT()\n\t\tis defined in FreeRTOSConfig.h then\n\t\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\n\t\tfailure if a FreeRTOS API function is called from an interrupt that has\n\t\tbeen assigned a priority above the configured maximum system call\n\t\tpriority.  Only FreeRTOS functions that end in FromISR can be called\n\t\tfrom interrupts\tthat have been assigned a priority at or (logically)\n\t\tbelow the maximum system call interrupt priority.  FreeRTOS maintains a\n\t\tseparate interrupt safe API to ensure interrupt entry is as fast and as\n\t\tsimple as possible.  More information (albeit Cortex-M specific) is\n\t\tprovided on the following link:\n\t\thttp://www.freertos.org/RTOS-Cortex-M3-M4.html */\n\t\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID();\n\n\t\tuxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\n\t\t{\n\t\t\tif( prvTaskIsTaskSuspended( pxTCB ) != pdFALSE )\n\t\t\t{\n\t\t\t\ttraceTASK_RESUME_FROM_ISR( pxTCB );\n\n\t\t\t\t/* Check the ready lists can be accessed. */\n\t\t\t\tif( uxSchedulerSuspended == ( uint32_t ) pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t/* Ready lists can be accessed so move the task from the\n\t\t\t\t\tsuspended list to the ready list directly. */\n\t\t\t\t\tif( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\n\t\t\t\t\t{\n\t\t\t\t\t\txYieldRequired = pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\n\t\t\t\t\t( void ) uxListRemove( &( pxTCB->xStateListItem ) );\n\t\t\t\t\tprvAddTaskToReadyList( pxTCB );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* The delayed or ready lists cannot be accessed so the task\n\t\t\t\t\tis held in the pending ready list until the scheduler is\n\t\t\t\t\tunsuspended. */\n\t\t\t\t\tvListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\n\n\t\treturn xYieldRequired;\n\t}\n\n#endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */\n/*-----------------------------------------------------------*/\n\nvoid rtos_sched_start( void )\n{\nint32_t xReturn;\n\n\t/* Add the idle task at the lowest priority. */\n\t#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\t{\n\t\tstatic_task_s_t *pxIdleTaskTCBBuffer = NULL;\n\t\ttask_stack_t *pxIdleTaskStackBuffer = NULL;\n\t\tuint32_t ulIdleTaskStackSize;\n\n\t\t/* The Idle task is created using user provided RAM - obtain the\n\t\taddress of the RAM then create the idle task. */\n\t\tvApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &ulIdleTaskStackSize );\n\t\txIdleTaskHandle = task_create_static(\tprvIdleTask,\n\t\t\t\t\t\t\t\t\t\t\t\t( void * ) NULL, /*lint !e961.  The cast is not redundant for all compilers. */\n\t\t\t\t\t\t\t\t\t\t\t\t( tskIDLE_PRIORITY | portPRIVILEGE_BIT ),\n\t\t\t\t\t\t\t\t\t\t\t\tulIdleTaskStackSize,\n\t\t\t\t\t\t\t\t\t\t\t\tconfigIDLE_TASK_NAME,\n\t\t\t\t\t\t\t\t\t\t\t\tpxIdleTaskStackBuffer,\n\t\t\t\t\t\t\t\t\t\t\t\tpxIdleTaskTCBBuffer); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\n\n\t\tif( xIdleTaskHandle != NULL )\n\t\t{\n\t\t\txReturn = pdPASS;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = pdFAIL;\n\t\t}\n\t}\n\t#else\n\t{\n\t\t/* The Idle task is being created using dynamically allocated RAM. */\n\t\txIdleTaskHandle = task_create(\tprvIdleTask,\n\t\t\t\t\t\t\t\t( void * ) NULL,\n\t\t\t\t\t\t\t\t( tskIDLE_PRIORITY | portPRIVILEGE_BIT ),\n\t\t\t\t\t\t\t\tconfigMINIMAL_STACK_SIZE,\n\t\t\t\t\t\t\t\tconfigIDLE_TASK_NAME); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */\n\t}\n\t#endif /* configSUPPORT_STATIC_ALLOCATION */\n\n\t#if ( configUSE_TIMERS == 1 )\n\t{\n\t\tif( xReturn == pdPASS )\n\t\t{\n\t\t\txReturn = xTimerCreateTimerTask();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\t#endif /* configUSE_TIMERS */\n\n\tif( xReturn == pdPASS )\n\t{\n\t\t/* freertos_tasks_c_additions_init() should only be called if the user\n\t\tdefinable macro FREERTOS_TASKS_C_ADDITIONS_INIT() is defined, as that is\n\t\tthe only macro called by the function. */\n\t\t#ifdef FREERTOS_TASKS_C_ADDITIONS_INIT\n\t\t{\n\t\t\tfreertos_tasks_c_additions_init();\n\t\t}\n\t\t#endif\n\n\t\t/* Interrupts are turned off here, to ensure a tick does not occur\n\t\tbefore or during the call to xPortStartScheduler().  The stacks of\n\t\tthe created tasks contain a status word with interrupts switched on\n\t\tso interrupts will automatically get re-enabled when the first task\n\t\tstarts to run. */\n\t\tportDISABLE_INTERRUPTS();\n\n\t\t#if ( configUSE_NEWLIB_REENTRANT == 1 )\n\t\t{\n\t\t\t/* Switch Newlib's _impure_ptr variable to point to the _reent\n\t\t\tstructure specific to the task that will run first. */\n\t\t\t_impure_ptr = &( pxCurrentTCB->xNewLib_reent );\n\t\t}\n\t\t#endif /* configUSE_NEWLIB_REENTRANT */\n\n\t\txNextTaskUnblockTime = portMAX_DELAY;\n\t\txSchedulerRunning = pdTRUE;\n\t\txTickCount = ( uint32_t ) 0U;\n\n\t\t/* If configGENERATE_RUN_TIME_STATS is defined then the following\n\t\tmacro must be defined to configure the timer/counter used to generate\n\t\tthe run time counter time base.   NOTE:  If configGENERATE_RUN_TIME_STATS\n\t\tis set to 0 and the following line fails to build then ensure you do not\n\t\thave portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() defined in your\n\t\tFreeRTOSConfig.h file. */\n\t\tportCONFIGURE_TIMER_FOR_RUN_TIME_STATS();\n\n\t\t/* Setting up the timer tick is hardware specific and thus in the\n\t\tportable interface. */\n\t\tif( xPortStartScheduler() != pdFALSE )\n\t\t{\n\t\t\t/* Should not reach here as if the scheduler is running the\n\t\t\tfunction will not return. */\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* Should only reach here if a task calls xTaskEndScheduler(). */\n\t\t}\n\t}\n\telse\n\t{\n\t\t/* This line will only be reached if the kernel could not be started,\n\t\tbecause there was not enough FreeRTOS heap to create the idle task\n\t\tor the timer task. */\n\t\tconfigASSERT( xReturn != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY );\n\t}\n\n\t/* Prevent compiler warnings if INCLUDE_xTaskGetIdleTaskHandle is set to 0,\n\tmeaning xIdleTaskHandle is not used anywhere else. */\n\t( void ) xIdleTaskHandle;\n}\n/*-----------------------------------------------------------*/\n\nvoid rtos_sched_stop( void )\n{\n\t/* Stop the scheduler interrupts and call the portable scheduler end\n\troutine so the original ISRs can be restored if necessary.  The port\n\tlayer must ensure interrupts enable\tbit is left in the correct state. */\n\tportDISABLE_INTERRUPTS();\n\txSchedulerRunning = pdFALSE;\n\tvPortEndScheduler();\n}\n/*----------------------------------------------------------*/\n\nvoid rtos_suspend_all( void )\n{\n\t/* A critical section is not required as the variable is of type\n\tint32_t.  Please read Richard Barry's reply in the following link to a\n\tpost in the FreeRTOS support forum before reporting this as a bug! -\n\thttp://goo.gl/wu4acr */\n\t++uxSchedulerSuspended;\n}\n/*----------------------------------------------------------*/\n\n#if ( configUSE_TICKLESS_IDLE != 0 )\n\n\tstatic uint32_t prvGetExpectedIdleTime( void )\n\t{\n\tuint32_t xReturn;\n\tuint32_t uxHigherPriorityReadyTasks = pdFALSE;\n\n\t\t/* uxHigherPriorityReadyTasks takes care of the case where\n\t\tconfigUSE_PREEMPTION is 0, so there may be tasks above the idle priority\n\t\ttask that are in the Ready state, even though the idle task is\n\t\trunning. */\n\t\t#if( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 )\n\t\t{\n\t\t\tif( uxTopReadyPriority > tskIDLE_PRIORITY )\n\t\t\t{\n\t\t\t\tuxHigherPriorityReadyTasks = pdTRUE;\n\t\t\t}\n\t\t}\n\t\t#else\n\t\t{\n\t\t\tconst uint32_t uxLeastSignificantBit = ( uint32_t ) 0x01;\n\n\t\t\t/* When port optimised task selection is used the uxTopReadyPriority\n\t\t\tvariable is used as a bit map.  If bits other than the least\n\t\t\tsignificant bit are set then there are tasks that have a priority\n\t\t\tabove the idle priority that are in the Ready state.  This takes\n\t\t\tcare of the case where the co-operative scheduler is in use. */\n\t\t\tif( uxTopReadyPriority > uxLeastSignificantBit )\n\t\t\t{\n\t\t\t\tuxHigherPriorityReadyTasks = pdTRUE;\n\t\t\t}\n\t\t}\n\t\t#endif\n\n\t\tif( pxCurrentTCB->uxPriority > tskIDLE_PRIORITY )\n\t\t{\n\t\t\txReturn = 0;\n\t\t}\n\t\telse if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > 1 )\n\t\t{\n\t\t\t/* There are other idle priority tasks in the ready state.  If\n\t\t\ttime slicing is used then the very next tick interrupt must be\n\t\t\tprocessed. */\n\t\t\txReturn = 0;\n\t\t}\n\t\telse if( uxHigherPriorityReadyTasks != pdFALSE )\n\t\t{\n\t\t\t/* There are tasks in the Ready state that have a priority above the\n\t\t\tidle priority.  This path can only be reached if\n\t\t\tconfigUSE_PREEMPTION is 0. */\n\t\t\txReturn = 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = xNextTaskUnblockTime - xTickCount;\n\t\t}\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_TICKLESS_IDLE */\n/*----------------------------------------------------------*/\n\nint32_t rtos_resume_all( void )\n{\nTCB_t *pxTCB = NULL;\nint32_t xAlreadyYielded = pdFALSE;\n\n\t/* If uxSchedulerSuspended is zero then this function does not match a\n\tprevious call to rtos_suspend_all(). */\n\tconfigASSERT( uxSchedulerSuspended );\n\n\t/* It is possible that an ISR caused a task to be removed from an event\n\tlist while the scheduler was suspended.  If this was the case then the\n\tremoved task will have been added to the xPendingReadyList.  Once the\n\tscheduler has been resumed it is safe to move all the pending ready\n\ttasks from this list into their appropriate ready list. */\n\ttaskENTER_CRITICAL();\n\t{\n\t\t--uxSchedulerSuspended;\n\n\t\tif( uxSchedulerSuspended == ( uint32_t ) pdFALSE )\n\t\t{\n\t\t\tif( uxCurrentNumberOfTasks > ( uint32_t ) 0U )\n\t\t\t{\n\t\t\t\t/* Move any readied tasks from the pending list into the\n\t\t\t\tappropriate ready list. */\n\t\t\t\twhile( listLIST_IS_EMPTY( &xPendingReadyList ) == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tpxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xPendingReadyList ) );\n\t\t\t\t\t( void ) uxListRemove( &( pxTCB->xEventListItem ) );\n\t\t\t\t\t( void ) uxListRemove( &( pxTCB->xStateListItem ) );\n\t\t\t\t\tprvAddTaskToReadyList( pxTCB );\n\n\t\t\t\t\t/* If the moved task has a priority higher than the current\n\t\t\t\t\ttask then a yield must be performed. */\n\t\t\t\t\tif( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\n\t\t\t\t\t{\n\t\t\t\t\t\txYieldPending = pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif( pxTCB != NULL )\n\t\t\t\t{\n\t\t\t\t\t/* A task was unblocked while the scheduler was suspended,\n\t\t\t\t\twhich may have prevented the next unblock time from being\n\t\t\t\t\tre-calculated, in which case re-calculate it now.  Mainly\n\t\t\t\t\timportant for low power tickless implementations, where\n\t\t\t\t\tthis can prevent an unnecessary exit from low power\n\t\t\t\t\tstate. */\n\t\t\t\t\tprvResetNextTaskUnblockTime();\n\t\t\t\t}\n\n\t\t\t\t/* If any ticks occurred while the scheduler was suspended then\n\t\t\t\tthey should be processed now.  This ensures the tick count does\n\t\t\t\tnot\tslip, and that any delayed tasks are resumed at the correct\n\t\t\t\ttime. */\n\t\t\t\t{\n\t\t\t\t\tuint32_t uxPendedCounts = uxPendedTicks; /* Non-volatile copy. */\n\n\t\t\t\t\tif( uxPendedCounts > ( uint32_t ) 0U )\n\t\t\t\t\t{\n\t\t\t\t\t\tdo\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif( xTaskIncrementTick() != pdFALSE )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\txYieldPending = pdTRUE;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t--uxPendedCounts;\n\t\t\t\t\t\t} while( uxPendedCounts > ( uint32_t ) 0U );\n\n\t\t\t\t\t\tuxPendedTicks = 0;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif( xYieldPending != pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t#if( configUSE_PREEMPTION != 0 )\n\t\t\t\t\t{\n\t\t\t\t\t\txAlreadyYielded = pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t\t#endif\n\t\t\t\t\ttaskYIELD_IF_USING_PREEMPTION();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\ttaskEXIT_CRITICAL();\n\n\treturn xAlreadyYielded;\n}\n/*-----------------------------------------------------------*/\n\nuint32_t millis(void)\n{\nuint32_t xTicks;\n\n\t/* Critical section required if running on a 16 bit processor. */\n\tportTICK_TYPE_ENTER_CRITICAL();\n\t{\n\t\txTicks = xTickCount;\n\t}\n\tportTICK_TYPE_EXIT_CRITICAL();\n\n\treturn xTicks * (configTICK_RATE_HZ / 1000);\n}\n\nuint64_t micros(void)\n{\n\treturn vexSystemHighResTimeGet();\n}\n/*-----------------------------------------------------------*/\n\nuint32_t xTaskGetTickCountFromISR( void )\n{\nuint32_t xReturn;\nuint32_t uxSavedInterruptStatus;\n\n\t/* RTOS ports that support interrupt nesting have the concept of a maximum\n\tsystem call (or maximum API call) interrupt priority.  Interrupts that are\n\tabove the maximum system call priority are kept permanently enabled, even\n\twhen the RTOS kernel is in a critical section, but cannot make any calls to\n\tFreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\n\tthen portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\n\tfailure if a FreeRTOS API function is called from an interrupt that has been\n\tassigned a priority above the configured maximum system call priority.\n\tOnly FreeRTOS functions that end in FromISR can be called from interrupts\n\tthat have been assigned a priority at or (logically) below the maximum\n\tsystem call\tinterrupt priority.  FreeRTOS maintains a separate interrupt\n\tsafe API to ensure interrupt entry is as fast and as simple as possible.\n\tMore information (albeit Cortex-M specific) is provided on the following\n\tlink: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\n\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID();\n\n\tuxSavedInterruptStatus = portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR();\n\t{\n\t\txReturn = xTickCount;\n\t}\n\tportTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nuint32_t task_get_count(void)\n{\n\t/* A critical section is not required because the variables are of type\n\tint32_t. */\n\treturn uxCurrentNumberOfTasks;\n}\n/*-----------------------------------------------------------*/\n\nchar *task_get_name(task_t task) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n{\nTCB_t *pxTCB;\n\n\t/* If null is passed in here then the name of the calling task is being\n\tqueried. */\n\tpxTCB = prvGetTCBFromHandle( task );\n\tconfigASSERT( pxTCB );\n\treturn &( pxTCB->pcTaskName[ 0 ] );\n}\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_xTaskGetHandle == 1 )\n\n\tstatic TCB_t *prvSearchForNameWithinSingleList( List_t *pxList, const char name[] )\n\t{\n\tTCB_t *pxNextTCB, *pxFirstTCB, *pxReturn = NULL;\n\tuint32_t x;\n\tchar cNextChar;\n\n\t\t/* This function is called with the scheduler suspended. */\n\n\t\tif( listCURRENT_LIST_LENGTH( pxList ) > ( uint32_t ) 0 )\n\t\t{\n\t\t\tlistGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\n\n\t\t\tdo\n\t\t\t{\n\t\t\t\tlistGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );\n\n\t\t\t\t/* Check each character in the name looking for a match or\n\t\t\t\tmismatch. */\n\t\t\t\tfor( x = ( uint32_t ) 0; x < ( uint32_t ) configMAX_TASK_NAME_LEN; x++ )\n\t\t\t\t{\n\t\t\t\t\tcNextChar = pxNextTCB->pcTaskName[ x ];\n\n\t\t\t\t\tif( cNextChar != name[ x ] )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* Characters didn't match. */\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\telse if( cNextChar == 0x00 )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* Both strings terminated, a match must have been\n\t\t\t\t\t\tfound. */\n\t\t\t\t\t\tpxReturn = pxNextTCB;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif( pxReturn != NULL )\n\t\t\t\t{\n\t\t\t\t\t/* The handle has been found. */\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t} while( pxNextTCB != pxFirstTCB );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\treturn pxReturn;\n\t}\n\n#endif /* INCLUDE_xTaskGetHandle */\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_xTaskGetHandle == 1 )\n\n\ttask_t task_get_by_name(const char* name) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t{\n\tuint32_t uxQueue = configMAX_PRIORITIES;\n\tTCB_t* pxTCB;\n\n\t\t/* Task names will be truncated to configMAX_TASK_NAME_LEN - 1 bytes. */\n\t\tconfigASSERT( strlen( name ) < configMAX_TASK_NAME_LEN );\n\n\t\trtos_suspend_all();\n\t\t{\n\t\t\t/* Search the ready lists. */\n\t\t\tdo\n\t\t\t{\n\t\t\t\tuxQueue--;\n\t\t\t\tpxTCB = prvSearchForNameWithinSingleList( ( List_t * ) &( pxReadyTasksLists[ uxQueue ] ), name );\n\n\t\t\t\tif( pxTCB != NULL )\n\t\t\t\t{\n\t\t\t\t\t/* Found the handle. */\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t} while( uxQueue > ( uint32_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\n\t\t\t/* Search the delayed lists. */\n\t\t\tif( pxTCB == NULL )\n\t\t\t{\n\t\t\t\tpxTCB = prvSearchForNameWithinSingleList( ( List_t * ) pxDelayedTaskList, name );\n\t\t\t}\n\n\t\t\tif( pxTCB == NULL )\n\t\t\t{\n\t\t\t\tpxTCB = prvSearchForNameWithinSingleList( ( List_t * ) pxOverflowDelayedTaskList, name );\n\t\t\t}\n\n\t\t\t#if ( INCLUDE_vTaskSuspend == 1 )\n\t\t\t{\n\t\t\t\tif( pxTCB == NULL )\n\t\t\t\t{\n\t\t\t\t\t/* Search the suspended list. */\n\t\t\t\t\tpxTCB = prvSearchForNameWithinSingleList( &xSuspendedTaskList, name );\n\t\t\t\t}\n\t\t\t}\n\t\t\t#endif\n\n\t\t\t#if( INCLUDE_vTaskDelete == 1 )\n\t\t\t{\n\t\t\t\tif( pxTCB == NULL )\n\t\t\t\t{\n\t\t\t\t\t/* Search the deleted list. */\n\t\t\t\t\tpxTCB = prvSearchForNameWithinSingleList( &xTasksWaitingTermination, name );\n\t\t\t\t}\n\t\t\t}\n\t\t\t#endif\n\t\t}\n\t\t( void ) rtos_resume_all();\n\n\t\treturn ( task_t ) pxTCB;\n\t}\n\n#endif /* INCLUDE_xTaskGetHandle */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tuint32_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const uint32_t uxArraySize, uint32_t * const pulTotalRunTime )\n\t{\n\tuint32_t uxTask = 0, uxQueue = configMAX_PRIORITIES;\n\n\t\trtos_suspend_all();\n\t\t{\n\t\t\t/* Is there a space in the array for each task in the system? */\n\t\t\tif( uxArraySize >= uxCurrentNumberOfTasks )\n\t\t\t{\n\t\t\t\t/* Fill in an TaskStatus_t structure with information on each\n\t\t\t\ttask in the Ready state. */\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tuxQueue--;\n\t\t\t\t\tuxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), E_TASK_STATE_READY );\n\n\t\t\t\t} while( uxQueue > ( uint32_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\n\t\t\t\t/* Fill in an TaskStatus_t structure with information on each\n\t\t\t\ttask in the Blocked state. */\n\t\t\t\tuxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxDelayedTaskList, E_TASK_STATE_BLOCKED );\n\t\t\t\tuxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxOverflowDelayedTaskList, E_TASK_STATE_BLOCKED );\n\n\t\t\t\t#if( INCLUDE_vTaskDelete == 1 )\n\t\t\t\t{\n\t\t\t\t\t/* Fill in an TaskStatus_t structure with information on\n\t\t\t\t\teach task that has been deleted but not yet cleaned up. */\n\t\t\t\t\tuxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xTasksWaitingTermination, E_TASK_STATE_DELETED );\n\t\t\t\t}\n\t\t\t\t#endif\n\n\t\t\t\t#if ( INCLUDE_vTaskSuspend == 1 )\n\t\t\t\t{\n\t\t\t\t\t/* Fill in an TaskStatus_t structure with information on\n\t\t\t\t\teach task in the Suspended state. */\n\t\t\t\t\tuxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xSuspendedTaskList, E_TASK_STATE_SUSPENDED );\n\t\t\t\t}\n\t\t\t\t#endif\n\n\t\t\t\t#if ( configGENERATE_RUN_TIME_STATS == 1)\n\t\t\t\t{\n\t\t\t\t\tif( pulTotalRunTime != NULL )\n\t\t\t\t\t{\n\t\t\t\t\t\t#ifdef portALT_GET_RUN_TIME_COUNTER_VALUE\n\t\t\t\t\t\t\tportALT_GET_RUN_TIME_COUNTER_VALUE( ( *pulTotalRunTime ) );\n\t\t\t\t\t\t#else\n\t\t\t\t\t\t\t*pulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\n\t\t\t\t\t\t#endif\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#else\n\t\t\t\t{\n\t\t\t\t\tif( pulTotalRunTime != NULL )\n\t\t\t\t\t{\n\t\t\t\t\t\t*pulTotalRunTime = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#endif\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\t( void ) rtos_resume_all();\n\n\t\treturn uxTask;\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*----------------------------------------------------------*/\n\n#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\n\n\ttask_t xTaskGetIdleTaskHandle( void )\n\t{\n\t\t/* If xTaskGetIdleTaskHandle() is called before the scheduler has been\n\t\tstarted, then xIdleTaskHandle will be NULL. */\n\t\tconfigASSERT( ( xIdleTaskHandle != NULL ) );\n\t\treturn xIdleTaskHandle;\n\t}\n\n#endif /* INCLUDE_xTaskGetIdleTaskHandle */\n/*----------------------------------------------------------*/\n\n/* This conditional compilation should use inequality to 0, not equality to 1.\nThis is to ensure vTaskStepTick() is available when user defined low power mode\nimplementations require configUSE_TICKLESS_IDLE to be set to a value other than\n1. */\n#if ( configUSE_TICKLESS_IDLE != 0 )\n\n\tvoid vTaskStepTick( const uint32_t xTicksToJump )\n\t{\n\t\t/* Correct the tick count value after a period during which the tick\n\t\twas suppressed.  Note this does *not* call the tick hook function for\n\t\teach stepped tick. */\n\t\tconfigASSERT( ( xTickCount + xTicksToJump ) <= xNextTaskUnblockTime );\n\t\txTickCount += xTicksToJump;\n\t\ttraceINCREASE_TICK_COUNT( xTicksToJump );\n\t}\n\n#endif /* configUSE_TICKLESS_IDLE */\n/*----------------------------------------------------------*/\n\n#if ( INCLUDE_xTaskAbortDelay == 1 )\n\n\tint32_t task_abort_delay(task_t task)\n\t{\n\tTCB_t *pxTCB = ( TCB_t * ) task;\n\tint32_t xReturn;\n\n\t\tconfigASSERT( pxTCB );\n\n\t\trtos_suspend_all();\n\t\t{\n\t\t\t/* A task can only be prematurely removed from the Blocked state if\n\t\t\tit is actually in the Blocked state. */\n\t\t\tif( task_get_state( task ) == E_TASK_STATE_BLOCKED )\n\t\t\t{\n\t\t\t\txReturn = pdPASS;\n\n\t\t\t\t/* Remove the reference to the task from the blocked list.  An\n\t\t\t\tinterrupt won't touch the xStateListItem because the\n\t\t\t\tscheduler is suspended. */\n\t\t\t\t( void ) uxListRemove( &( pxTCB->xStateListItem ) );\n\n\t\t\t\t/* Is the task waiting on an event also?  If so remove it from\n\t\t\t\tthe event list too.  Interrupts can touch the event list item,\n\t\t\t\teven though the scheduler is suspended, so a critical section\n\t\t\t\tis used. */\n\t\t\t\ttaskENTER_CRITICAL();\n\t\t\t\t{\n\t\t\t\t\tif( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\n\t\t\t\t\t{\n\t\t\t\t\t\t( void ) uxListRemove( &( pxTCB->xEventListItem ) );\n\t\t\t\t\t\tpxTCB->ucDelayAborted = pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttaskEXIT_CRITICAL();\n\n\t\t\t\t/* Place the unblocked task into the appropriate ready list. */\n\t\t\t\tprvAddTaskToReadyList( pxTCB );\n\n\t\t\t\t/* A task being unblocked cannot cause an immediate context\n\t\t\t\tswitch if preemption is turned off. */\n\t\t\t\t#if (  configUSE_PREEMPTION == 1 )\n\t\t\t\t{\n\t\t\t\t\t/* Preemption is on, but a context switch should only be\n\t\t\t\t\tperformed if the unblocked task has a priority that is\n\t\t\t\t\tequal to or higher than the currently executing task. */\n\t\t\t\t\tif( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* Pend the yield to be performed when the scheduler\n\t\t\t\t\t\tis unsuspended. */\n\t\t\t\t\t\txYieldPending = pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#endif /* configUSE_PREEMPTION */\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\txReturn = pdFAIL;\n\t\t\t}\n\t\t}\n\t\t( void ) rtos_resume_all();\n\n\t\treturn xReturn;\n\t}\n\n#endif /* INCLUDE_xTaskAbortDelay */\n/*----------------------------------------------------------*/\n\nint32_t xTaskIncrementTick( void )\n{\nTCB_t * pxTCB;\nuint32_t xItemValue;\nint32_t xSwitchRequired = pdFALSE;\n\n\t/* Called by the portable layer each time a tick interrupt occurs.\n\tIncrements the tick then checks to see if the new tick value will cause any\n\ttasks to be unblocked. */\n\ttraceTASK_INCREMENT_TICK( xTickCount );\n\tif( uxSchedulerSuspended == ( uint32_t ) pdFALSE )\n\t{\n\t\t/* Minor optimisation.  The tick count cannot change in this\n\t\tblock. */\n\t\tconst uint32_t xConstTickCount = xTickCount + ( uint32_t ) 1;\n\n\t\t/* Increment the RTOS tick, switching the delayed and overflowed\n\t\tdelayed lists if it wraps to 0. */\n\t\txTickCount = xConstTickCount;\n\n\t\tif( xConstTickCount == ( uint32_t ) 0U ) /*lint !e774 'if' does not always evaluate to false as it is looking for an overflow. */\n\t\t{\n\t\t\ttaskSWITCH_DELAYED_LISTS();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\t/* See if this tick has made a timeout expire.  Tasks are stored in\n\t\tthe\tqueue in the order of their wake time - meaning once one task\n\t\thas been found whose block time has not expired there is no need to\n\t\tlook any further down the list. */\n\t\tif( xConstTickCount >= xNextTaskUnblockTime )\n\t\t{\n\t\t\tfor( ;; )\n\t\t\t{\n\t\t\t\tif( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t/* The delayed list is empty.  Set xNextTaskUnblockTime\n\t\t\t\t\tto the maximum possible value so it is extremely\n\t\t\t\t\tunlikely that the\n\t\t\t\t\tif( xTickCount >= xNextTaskUnblockTime ) test will pass\n\t\t\t\t\tnext time through. */\n\t\t\t\t\txNextTaskUnblockTime = portMAX_DELAY; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* The delayed list is not empty, get the value of the\n\t\t\t\t\titem at the head of the delayed list.  This is the time\n\t\t\t\t\tat which the task at the head of the delayed list must\n\t\t\t\t\tbe removed from the Blocked state. */\n\t\t\t\t\tpxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\n\t\t\t\t\txItemValue = listGET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ) );\n\n\t\t\t\t\tif( xConstTickCount < xItemValue )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* It is not time to unblock this item yet, but the\n\t\t\t\t\t\titem value is the time at which the task at the head\n\t\t\t\t\t\tof the blocked list must be removed from the Blocked\n\t\t\t\t\t\tstate -\tso record the item value in\n\t\t\t\t\t\txNextTaskUnblockTime. */\n\t\t\t\t\t\txNextTaskUnblockTime = xItemValue;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\n\t\t\t\t\t/* It is time to remove the item from the Blocked state. */\n\t\t\t\t\t( void ) uxListRemove( &( pxTCB->xStateListItem ) );\n\n\t\t\t\t\t/* Is the task waiting on an event also?  If so remove\n\t\t\t\t\tit from the event list. */\n\t\t\t\t\tif( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\n\t\t\t\t\t{\n\t\t\t\t\t\t( void ) uxListRemove( &( pxTCB->xEventListItem ) );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\n\t\t\t\t\t/* Place the unblocked task into the appropriate ready\n\t\t\t\t\tlist. */\n\t\t\t\t\tprvAddTaskToReadyList( pxTCB );\n\n\t\t\t\t\t/* A task being unblocked cannot cause an immediate\n\t\t\t\t\tcontext switch if preemption is turned off. */\n\t\t\t\t\t#if (  configUSE_PREEMPTION == 1 )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* Preemption is on, but a context switch should\n\t\t\t\t\t\tonly be performed if the unblocked task has a\n\t\t\t\t\t\tpriority that is equal to or higher than the\n\t\t\t\t\t\tcurrently executing task. */\n\t\t\t\t\t\tif( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\txSwitchRequired = pdTRUE;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t#endif /* configUSE_PREEMPTION */\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t/* Tasks of equal priority to the currently running task will share\n\t\tprocessing time (time slice) if preemption is on, and the application\n\t\twriter has not explicitly turned time slicing off. */\n\t\t#if ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) )\n\t\t{\n\t\t\tif( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ pxCurrentTCB->uxPriority ] ) ) > ( uint32_t ) 1 )\n\t\t\t{\n\t\t\t\txSwitchRequired = pdTRUE;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\t#endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) */\n\n\t\t#if ( configUSE_TICK_HOOK == 1 )\n\t\t{\n\t\t\t/* Guard against the tick hook being called when the pended tick\n\t\t\tcount is being unwound (when the scheduler is being unlocked). */\n\t\t\tif( uxPendedTicks == ( uint32_t ) 0U )\n\t\t\t{\n\t\t\t\tvApplicationTickHook();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\t#endif /* configUSE_TICK_HOOK */\n\t}\n\telse\n\t{\n\t\t++uxPendedTicks;\n\n\t\t/* The tick hook gets called at regular intervals, even if the\n\t\tscheduler is locked. */\n\t\t#if ( configUSE_TICK_HOOK == 1 )\n\t\t{\n\t\t\tvApplicationTickHook();\n\t\t}\n\t\t#endif\n\t}\n\n\t#if ( configUSE_PREEMPTION == 1 )\n\t{\n\t\tif( xYieldPending != pdFALSE )\n\t\t{\n\t\t\txSwitchRequired = pdTRUE;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\t#endif /* configUSE_PREEMPTION */\n\n\treturn xSwitchRequired;\n}\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_APPLICATION_TASK_TAG == 1 )\n\n\tvoid vTaskSetApplicationTaskTag( task_t task, TaskHookFunction_t pxHookFunction )\n\t{\n\tTCB_t *xTCB;\n\n\t\t/* If task is NULL then it is the task hook of the calling task that is\n\t\tgetting set. */\n\t\tif( task == NULL )\n\t\t{\n\t\t\txTCB = ( TCB_t * ) pxCurrentTCB;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txTCB = ( TCB_t * ) task;\n\t\t}\n\n\t\t/* Save the hook function in the TCB.  A critical section is required as\n\t\tthe value can be accessed from an interrupt. */\n\t\ttaskENTER_CRITICAL();\n\t\t\txTCB->pxTaskTag = pxHookFunction;\n\t\ttaskEXIT_CRITICAL();\n\t}\n\n#endif /* configUSE_APPLICATION_TASK_TAG */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_APPLICATION_TASK_TAG == 1 )\n\n\tTaskHookFunction_t xTaskGetApplicationTaskTag( task_t task )\n\t{\n\tTCB_t *xTCB;\n\tTaskHookFunction_t xReturn;\n\n\t\t/* If task is NULL then we are setting our own task hook. */\n\t\tif( task == NULL )\n\t\t{\n\t\t\txTCB = ( TCB_t * ) pxCurrentTCB;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txTCB = ( TCB_t * ) task;\n\t\t}\n\n\t\t/* Save the hook function in the TCB.  A critical section is required as\n\t\tthe value can be accessed from an interrupt. */\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\txReturn = xTCB->pxTaskTag;\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_APPLICATION_TASK_TAG */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_APPLICATION_TASK_TAG == 1 )\n\n\tint32_t xTaskCallApplicationTaskHook( task_t task, void *pvParameter )\n\t{\n\tTCB_t *xTCB;\n\tint32_t xReturn;\n\n\t\t/* If task is NULL then we are calling our own task hook. */\n\t\tif( task == NULL )\n\t\t{\n\t\t\txTCB = ( TCB_t * ) pxCurrentTCB;\n\t\t}\n\t\telse\n\t\t{\n\t\t\txTCB = ( TCB_t * ) task;\n\t\t}\n\n\t\tif( xTCB->pxTaskTag != NULL )\n\t\t{\n\t\t\txReturn = xTCB->pxTaskTag( pvParameter );\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = pdFAIL;\n\t\t}\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_APPLICATION_TASK_TAG */\n/*-----------------------------------------------------------*/\n\nvoid vTaskSwitchContext( void )\n{\n\tif( uxSchedulerSuspended != ( uint32_t ) pdFALSE )\n\t{\n\t\t/* The scheduler is currently suspended - do not allow a context\n\t\tswitch. */\n\t\txYieldPending = pdTRUE;\n\t}\n\telse\n\t{\n\t\txYieldPending = pdFALSE;\n\t\ttraceTASK_SWITCHED_OUT();\n\n\t\t#if ( configGENERATE_RUN_TIME_STATS == 1 )\n\t\t{\n\t\t\t\t#ifdef portALT_GET_RUN_TIME_COUNTER_VALUE\n\t\t\t\t\tportALT_GET_RUN_TIME_COUNTER_VALUE( ulTotalRunTime );\n\t\t\t\t#else\n\t\t\t\t\tulTotalRunTime = portGET_RUN_TIME_COUNTER_VALUE();\n\t\t\t\t#endif\n\n\t\t\t\t/* Add the amount of time the task has been running to the\n\t\t\t\taccumulated time so far.  The time the task started running was\n\t\t\t\tstored in ulTaskSwitchedInTime.  Note that there is no overflow\n\t\t\t\tprotection here so count values are only valid until the timer\n\t\t\t\toverflows.  The guard against negative values is to protect\n\t\t\t\tagainst suspect run time stat counter implementations - which\n\t\t\t\tare provided by the application, not the kernel. */\n\t\t\t\tif( ulTotalRunTime > ulTaskSwitchedInTime )\n\t\t\t\t{\n\t\t\t\t\tpxCurrentTCB->ulRunTimeCounter += ( ulTotalRunTime - ulTaskSwitchedInTime );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t\tulTaskSwitchedInTime = ulTotalRunTime;\n\t\t}\n\t\t#endif /* configGENERATE_RUN_TIME_STATS */\n\n\t\t/* Check for stack overflow, if configured. */\n\t\ttaskCHECK_FOR_STACK_OVERFLOW();\n\n\t\t/* Select a new task to run using either the generic C or port\n\t\toptimised asm code. */\n\t\ttaskSELECT_HIGHEST_PRIORITY_TASK();\n\t\ttraceTASK_SWITCHED_IN();\n\n\t\t#if ( configUSE_NEWLIB_REENTRANT == 1 )\n\t\t{\n\t\t\t/* Switch Newlib's _impure_ptr variable to point to the _reent\n\t\t\tstructure specific to this task. */\n\t\t\t_impure_ptr = &( pxCurrentTCB->xNewLib_reent );\n\t\t}\n\t\t#endif /* configUSE_NEWLIB_REENTRANT */\n\t}\n}\n/*-----------------------------------------------------------*/\n\nvoid vTaskPlaceOnEventList( List_t * const pxEventList, const uint32_t timeout )\n{\n\tconfigASSERT( pxEventList );\n\n\t/* THIS FUNCTION MUST BE CALLED WITH EITHER INTERRUPTS DISABLED OR THE\n\tSCHEDULER SUSPENDED AND THE QUEUE BEING ACCESSED LOCKED. */\n\n\t/* Place the event list item of the TCB in the appropriate event list.\n\tThis is placed in the list in priority order so the highest priority task\n\tis the first to be woken by the event.  The queue that contains the event\n\tlist is locked, preventing simultaneous access from interrupts. */\n\tvListInsert( pxEventList, &( pxCurrentTCB->xEventListItem ) );\n\n\tprvAddCurrentTaskToDelayedList( timeout, pdTRUE );\n}\n/*-----------------------------------------------------------*/\n\nvoid vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const uint32_t xItemValue, const uint32_t timeout )\n{\n\tconfigASSERT( pxEventList );\n\n\t/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED.  It is used by\n\tthe event groups implementation. */\n\tconfigASSERT( uxSchedulerSuspended != 0 );\n\n\t/* Store the item value in the event list item.  It is safe to access the\n\tevent list item here as interrupts won't access the event list item of a\n\ttask that is not in the Blocked state. */\n\tlistSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );\n\n\t/* Place the event list item of the TCB at the end of the appropriate event\n\tlist.  It is safe to access the event list here because it is part of an\n\tevent group implementation - and interrupts don't access event groups\n\tdirectly (instead they access them indirectly by pending function calls to\n\tthe task level). */\n\tvListInsertEnd( pxEventList, &( pxCurrentTCB->xEventListItem ) );\n\n\tprvAddCurrentTaskToDelayedList( timeout, pdTRUE );\n}\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TIMERS == 1 )\n\n\tvoid vTaskPlaceOnEventListRestricted( List_t * const pxEventList, uint32_t timeout, const int32_t xWaitIndefinitely )\n\t{\n\t\tconfigASSERT( pxEventList );\n\n\t\t/* This function should not be called by application code hence the\n\t\t'Restricted' in its name.  It is not part of the public API.  It is\n\t\tdesigned for use by kernel code, and has special calling requirements -\n\t\tit should be called with the scheduler suspended. */\n\n\n\t\t/* Place the event list item of the TCB in the appropriate event list.\n\t\tIn this case it is assume that this is the only task that is going to\n\t\tbe waiting on this event list, so the faster vListInsertEnd() function\n\t\tcan be used in place of vListInsert. */\n\t\tvListInsertEnd( pxEventList, &( pxCurrentTCB->xEventListItem ) );\n\n\t\t/* If the task should block indefinitely then set the block time to a\n\t\tvalue that will be recognised as an indefinite delay inside the\n\t\tprvAddCurrentTaskToDelayedList() function. */\n\t\tif( xWaitIndefinitely != pdFALSE )\n\t\t{\n\t\t\ttimeout = portMAX_DELAY;\n\t\t}\n\n\t\ttraceTASK_DELAY_UNTIL( ( xTickCount + timeout ) );\n\t\tprvAddCurrentTaskToDelayedList( timeout, xWaitIndefinitely );\n\t}\n\n#endif /* configUSE_TIMERS */\n/*-----------------------------------------------------------*/\n\nint32_t xTaskRemoveFromEventList( const List_t * const pxEventList )\n{\nTCB_t *pxUnblockedTCB;\nint32_t xReturn;\n\n\t/* THIS FUNCTION MUST BE CALLED FROM A CRITICAL SECTION.  It can also be\n\tcalled from a critical section within an ISR. */\n\n\t/* The event list is sorted in priority order, so the first in the list can\n\tbe removed as it is known to be the highest priority.  Remove the TCB from\n\tthe delayed list, and add it to the ready list.\n\n\tIf an event is for a queue that is locked then this function will never\n\tget called - the lock count on the queue will get modified instead.  This\n\tmeans exclusive access to the event list is guaranteed here.\n\n\tThis function assumes that a check has already been made to ensure that\n\tpxEventList is not empty. */\n\tpxUnblockedTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );\n\tconfigASSERT( pxUnblockedTCB );\n\t( void ) uxListRemove( &( pxUnblockedTCB->xEventListItem ) );\n\n\tif( uxSchedulerSuspended == ( uint32_t ) pdFALSE )\n\t{\n\t\t( void ) uxListRemove( &( pxUnblockedTCB->xStateListItem ) );\n\t\tprvAddTaskToReadyList( pxUnblockedTCB );\n\t}\n\telse\n\t{\n\t\t/* The delayed and ready lists cannot be accessed, so hold this task\n\t\tpending until the scheduler is resumed. */\n\t\tvListInsertEnd( &( xPendingReadyList ), &( pxUnblockedTCB->xEventListItem ) );\n\t}\n\n\tif( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority )\n\t{\n\t\t/* Return true if the task removed from the event list has a higher\n\t\tpriority than the calling task.  This allows the calling task to know if\n\t\tit should force a context switch now. */\n\t\txReturn = pdTRUE;\n\n\t\t/* Mark that a yield is pending in case the user is not using the\n\t\t\"xHigherPriorityTaskWoken\" parameter to an ISR safe FreeRTOS function. */\n\t\txYieldPending = pdTRUE;\n\t}\n\telse\n\t{\n\t\txReturn = pdFALSE;\n\t}\n\n\t#if( configUSE_TICKLESS_IDLE != 0 )\n\t{\n\t\t/* If a task is blocked on a kernel object then xNextTaskUnblockTime\n\t\tmight be set to the blocked task's time out time.  If the task is\n\t\tunblocked for a reason other than a timeout xNextTaskUnblockTime is\n\t\tnormally left unchanged, because it is automatically reset to a new\n\t\tvalue when the tick count equals xNextTaskUnblockTime.  However if\n\t\ttickless idling is used it might be more important to enter sleep mode\n\t\tat the earliest possible time - so reset xNextTaskUnblockTime here to\n\t\tensure it is updated at the earliest possible time. */\n\t\tprvResetNextTaskUnblockTime();\n\t}\n\t#endif\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nvoid vTaskRemoveFromUnorderedEventList( list_item_t * pxEventListItem, const uint32_t xItemValue )\n{\nTCB_t *pxUnblockedTCB;\n\n\t/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED.  It is used by\n\tthe event flags implementation. */\n\tconfigASSERT( uxSchedulerSuspended != pdFALSE );\n\n\t/* Store the new item value in the event list. */\n\tlistSET_LIST_ITEM_VALUE( pxEventListItem, xItemValue | taskEVENT_LIST_ITEM_VALUE_IN_USE );\n\n\t/* Remove the event list form the event flag.  Interrupts do not access\n\tevent flags. */\n\tpxUnblockedTCB = ( TCB_t * ) listGET_LIST_ITEM_OWNER( pxEventListItem );\n\tconfigASSERT( pxUnblockedTCB );\n\t( void ) uxListRemove( pxEventListItem );\n\n\t/* Remove the task from the delayed list and add it to the ready list.  The\n\tscheduler is suspended so interrupts will not be accessing the ready\n\tlists. */\n\t( void ) uxListRemove( &( pxUnblockedTCB->xStateListItem ) );\n\tprvAddTaskToReadyList( pxUnblockedTCB );\n\n\tif( pxUnblockedTCB->uxPriority > pxCurrentTCB->uxPriority )\n\t{\n\t\t/* The unblocked task has a priority above that of the calling task, so\n\t\ta context switch is required.  This function is called with the\n\t\tscheduler suspended so xYieldPending is set so the context switch\n\t\toccurs immediately that the scheduler is resumed (unsuspended). */\n\t\txYieldPending = pdTRUE;\n\t}\n}\n/*-----------------------------------------------------------*/\n\nvoid vTaskSetTimeOutState( TimeOut_t * const pxTimeOut )\n{\n\tconfigASSERT( pxTimeOut );\n\ttaskENTER_CRITICAL();\n\t{\n\t\tpxTimeOut->xOverflowCount = xNumOfOverflows;\n\t\tpxTimeOut->xTimeOnEntering = xTickCount;\n\t}\n\ttaskEXIT_CRITICAL();\n}\n/*-----------------------------------------------------------*/\n\nvoid vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut )\n{\n\t/* For internal use only as it does not use a critical section. */\n\tpxTimeOut->xOverflowCount = xNumOfOverflows;\n\tpxTimeOut->xTimeOnEntering = xTickCount;\n}\n/*-----------------------------------------------------------*/\n\nint32_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, uint32_t * const pxTicksToWait )\n{\nint32_t xReturn;\n\n\tconfigASSERT( pxTimeOut );\n\tconfigASSERT( pxTicksToWait );\n\n\ttaskENTER_CRITICAL();\n\t{\n\t\t/* Minor optimisation.  The tick count cannot change in this block. */\n\t\tconst uint32_t xConstTickCount = xTickCount;\n\t\tconst uint32_t xElapsedTime = xConstTickCount - pxTimeOut->xTimeOnEntering;\n\n\t\t#if( INCLUDE_xTaskAbortDelay == 1 )\n\t\t\tif( pxCurrentTCB->ucDelayAborted != pdFALSE )\n\t\t\t{\n\t\t\t\t/* The delay was aborted, which is not the same as a time out,\n\t\t\t\tbut has the same result. */\n\t\t\t\tpxCurrentTCB->ucDelayAborted = pdFALSE;\n\t\t\t\txReturn = pdTRUE;\n\t\t\t}\n\t\t\telse\n\t\t#endif\n\n\t\t#if ( INCLUDE_vTaskSuspend == 1 )\n\t\t\tif( *pxTicksToWait == portMAX_DELAY )\n\t\t\t{\n\t\t\t\t/* If INCLUDE_vTaskSuspend is set to 1 and the block time\n\t\t\t\tspecified is the maximum block time then the task should block\n\t\t\t\tindefinitely, and therefore never time out. */\n\t\t\t\txReturn = pdFALSE;\n\t\t\t}\n\t\t\telse\n\t\t#endif\n\n\t\tif( ( xNumOfOverflows != pxTimeOut->xOverflowCount ) && ( xConstTickCount >= pxTimeOut->xTimeOnEntering ) ) /*lint !e525 Indentation preferred as is to make code within pre-processor directives clearer. */\n\t\t{\n\t\t\t/* The tick count is greater than the time at which\n\t\t\tvTaskSetTimeout() was called, but has also overflowed since\n\t\t\tvTaskSetTimeOut() was called.  It must have wrapped all the way\n\t\t\taround and gone past again. This passed since vTaskSetTimeout()\n\t\t\twas called. */\n\t\t\txReturn = pdTRUE;\n\t\t}\n\t\telse if( xElapsedTime < *pxTicksToWait ) /*lint !e961 Explicit casting is only redundant with some compilers, whereas others require it to prevent integer conversion errors. */\n\t\t{\n\t\t\t/* Not a genuine timeout. Adjust parameters for time remaining. */\n\t\t\t*pxTicksToWait -= xElapsedTime;\n\t\t\tvTaskInternalSetTimeOutState( pxTimeOut );\n\t\t\txReturn = pdFALSE;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t*pxTicksToWait = 0;\n\t\t\txReturn = pdTRUE;\n\t\t}\n\t}\n\ttaskEXIT_CRITICAL();\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nvoid vTaskMissedYield( void )\n{\n\txYieldPending = pdTRUE;\n}\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tuint32_t uxTaskGetTaskNumber( task_t task )\n\t{\n\tuint32_t uxReturn;\n\tTCB_t *pxTCB;\n\n\t\tif( task != NULL )\n\t\t{\n\t\t\tpxTCB = ( TCB_t * ) task;\n\t\t\tuxReturn = pxTCB->uxTaskNumber;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tuxReturn = 0U;\n\t\t}\n\n\t\treturn uxReturn;\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tvoid vTaskSetTaskNumber( task_t task, const uint32_t uxHandle )\n\t{\n\tTCB_t *pxTCB;\n\n\t\tif( task != NULL )\n\t\t{\n\t\t\tpxTCB = ( TCB_t * ) task;\n\t\t\tpxTCB->uxTaskNumber = uxHandle;\n\t\t}\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n\n/*\n * -----------------------------------------------------------\n * The Idle task.\n * ----------------------------------------------------------\n *\n * The portTASK_FUNCTION() macro is used to allow port/compiler specific\n * language extensions.  The equivalent prototype for this function is:\n *\n * void prvIdleTask( void *pvParameters );\n *\n */\nstatic portTASK_FUNCTION( prvIdleTask, pvParameters )\n{\n\t/* Stop warnings. */\n\t( void ) pvParameters;\n\n\t/** THIS IS THE RTOS IDLE TASK - WHICH IS CREATED AUTOMATICALLY WHEN THE\n\tSCHEDULER IS STARTED. **/\n\n\t/* In case a task that has a secure context deletes itself, in which case\n\tthe idle task is responsible for deleting the task's secure context, if\n\tany. */\n\tportTASK_CALLS_SECURE_FUNCTIONS();\n\n\tfor( ;; )\n\t{\n\t\t/* See if any tasks have deleted themselves - if so then the idle task\n\t\tis responsible for freeing the deleted task's TCB and stack. */\n\t\tprvCheckTasksWaitingTermination();\n\n\t\t#if ( configUSE_PREEMPTION == 0 )\n\t\t{\n\t\t\t/* If we are not using preemption we keep forcing a task switch to\n\t\t\tsee if any other task has become available.  If we are using\n\t\t\tpreemption we don't need to do this as any task becoming available\n\t\t\twill automatically get the processor anyway. */\n\t\t\ttaskYIELD();\n\t\t}\n\t\t#endif /* configUSE_PREEMPTION */\n\n\t\t#if ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) )\n\t\t{\n\t\t\t/* When using preemption tasks of equal priority will be\n\t\t\ttimesliced.  If a task that is sharing the idle priority is ready\n\t\t\tto run then the idle task should yield before the end of the\n\t\t\ttimeslice.\n\n\t\t\tA critical region is not required here as we are just reading from\n\t\t\tthe list, and an occasional incorrect value will not matter.  If\n\t\t\tthe ready list at the idle priority contains more than one task\n\t\t\tthen a task other than the idle task is ready to execute. */\n\t\t\tif( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( uint32_t ) 1 )\n\t\t\t{\n\t\t\t\ttaskYIELD();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\t#endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configIDLE_SHOULD_YIELD == 1 ) ) */\n\n\t\t#if ( configUSE_IDLE_HOOK == 1 )\n\t\t{\n\t\t\textern void vApplicationIdleHook( void );\n\n\t\t\t/* Call the user defined function from within the idle task.  This\n\t\t\tallows the application designer to add background functionality\n\t\t\twithout the overhead of a separate task.\n\t\t\tNOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES,\n\t\t\tCALL A FUNCTION THAT MIGHT BLOCK. */\n\t\t\tvApplicationIdleHook();\n\t\t}\n\t\t#endif /* configUSE_IDLE_HOOK */\n\n\t\t/* This conditional compilation should use inequality to 0, not equality\n\t\tto 1.  This is to ensure portSUPPRESS_TICKS_AND_SLEEP() is called when\n\t\tuser defined low power mode\timplementations require\n\t\tconfigUSE_TICKLESS_IDLE to be set to a value other than 1. */\n\t\t#if ( configUSE_TICKLESS_IDLE != 0 )\n\t\t{\n\t\tuint32_t xExpectedIdleTime;\n\n\t\t\t/* It is not desirable to suspend then resume the scheduler on\n\t\t\teach iteration of the idle task.  Therefore, a preliminary\n\t\t\ttest of the expected idle time is performed without the\n\t\t\tscheduler suspended.  The result here is not necessarily\n\t\t\tvalid. */\n\t\t\txExpectedIdleTime = prvGetExpectedIdleTime();\n\n\t\t\tif( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )\n\t\t\t{\n\t\t\t\trtos_suspend_all();\n\t\t\t\t{\n\t\t\t\t\t/* Now the scheduler is suspended, the expected idle\n\t\t\t\t\ttime can be sampled again, and this time its value can\n\t\t\t\t\tbe used. */\n\t\t\t\t\tconfigASSERT( xNextTaskUnblockTime >= xTickCount );\n\t\t\t\t\txExpectedIdleTime = prvGetExpectedIdleTime();\n\n\t\t\t\t\t/* Define the following macro to set xExpectedIdleTime to 0\n\t\t\t\t\tif the application does not want\n\t\t\t\t\tportSUPPRESS_TICKS_AND_SLEEP() to be called. */\n\t\t\t\t\tconfigPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING( xExpectedIdleTime );\n\n\t\t\t\t\tif( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )\n\t\t\t\t\t{\n\t\t\t\t\t\ttraceLOW_POWER_IDLE_BEGIN();\n\t\t\t\t\t\tportSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime );\n\t\t\t\t\t\ttraceLOW_POWER_IDLE_END();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t( void ) rtos_resume_all();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\t#endif /* configUSE_TICKLESS_IDLE */\n\t}\n}\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TICKLESS_IDLE != 0 )\n\n\teSleepModeStatus eTaskConfirmSleepModeStatus( void )\n\t{\n\t/* The idle task exists in addition to the application tasks. */\n\tconst uint32_t uxNonApplicationTasks = 1;\n\teSleepModeStatus eReturn = eStandardSleep;\n\n\t\tif( listCURRENT_LIST_LENGTH( &xPendingReadyList ) != 0 )\n\t\t{\n\t\t\t/* A task was made ready while the scheduler was suspended. */\n\t\t\teReturn = eAbortSleep;\n\t\t}\n\t\telse if( xYieldPending != pdFALSE )\n\t\t{\n\t\t\t/* A yield was pended while the scheduler was suspended. */\n\t\t\teReturn = eAbortSleep;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* If all the tasks are in the suspended list (which might mean they\n\t\t\thave an infinite block time rather than actually being suspended)\n\t\t\tthen it is safe to turn all clocks off and just wait for external\n\t\t\tinterrupts. */\n\t\t\tif( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == ( uxCurrentNumberOfTasks - uxNonApplicationTasks ) )\n\t\t\t{\n\t\t\t\teReturn = eNoTasksWaitingTimeout;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\n\t\treturn eReturn;\n\t}\n\n#endif /* configUSE_TICKLESS_IDLE */\n/*-----------------------------------------------------------*/\n\n#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )\n\n\tvoid vTaskSetThreadLocalStoragePointer( task_t xTaskToSet, int32_t xIndex, void *pvValue )\n\t{\n\tTCB_t *pxTCB;\n\n\t\tif( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS )\n\t\t{\n\t\t\tpxTCB = prvGetTCBFromHandle( xTaskToSet );\n\t\t\tpxTCB->pvThreadLocalStoragePointers[ xIndex ] = pvValue;\n\t\t}\n\t}\n\n#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */\n/*-----------------------------------------------------------*/\n\n#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )\n\n\tvoid *pvTaskGetThreadLocalStoragePointer( task_t xTaskToQuery, int32_t xIndex )\n\t{\n\tvoid *pvReturn = NULL;\n\tTCB_t *pxTCB;\n\n\t\tif( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS )\n\t\t{\n\t\t\tpxTCB = prvGetTCBFromHandle( xTaskToQuery );\n\t\t\tpvReturn = pxTCB->pvThreadLocalStoragePointers[ xIndex ];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpvReturn = NULL;\n\t\t}\n\n\t\treturn pvReturn;\n\t}\n\n#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */\n/*-----------------------------------------------------------*/\n\nstatic void prvInitialiseTaskLists( void )\n{\nuint32_t uxPriority;\n\n\tfor( uxPriority = ( uint32_t ) 0U; uxPriority < ( uint32_t ) configMAX_PRIORITIES; uxPriority++ )\n\t{\n\t\tvListInitialise( &( pxReadyTasksLists[ uxPriority ] ) );\n\t}\n\n\tvListInitialise( &xDelayedTaskList1 );\n\tvListInitialise( &xDelayedTaskList2 );\n\tvListInitialise( &xPendingReadyList );\n\n\t#if ( INCLUDE_vTaskDelete == 1 )\n\t{\n\t\tvListInitialise( &xTasksWaitingTermination );\n\t}\n\t#endif /* INCLUDE_vTaskDelete */\n\n\t#if ( INCLUDE_vTaskSuspend == 1 )\n\t{\n\t\tvListInitialise( &xSuspendedTaskList );\n\t}\n\t#endif /* INCLUDE_vTaskSuspend */\n\n\t/* Start with pxDelayedTaskList using list1 and the pxOverflowDelayedTaskList\n\tusing list2. */\n\tpxDelayedTaskList = &xDelayedTaskList1;\n\tpxOverflowDelayedTaskList = &xDelayedTaskList2;\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvCheckTasksWaitingTermination( void )\n{\n\n\t/** THIS FUNCTION IS CALLED FROM THE RTOS IDLE TASK **/\n\n\t#if ( INCLUDE_vTaskDelete == 1 )\n\t{\n\t\tTCB_t *pxTCB;\n\n\t\t/* uxDeletedTasksWaitingCleanUp is used to prevent rtos_suspend_all()\n\t\tbeing called too often in the idle task. */\n\t\twhile( uxDeletedTasksWaitingCleanUp > ( uint32_t ) 0U )\n\t\t{\n\t\t\ttaskENTER_CRITICAL();\n\t\t\t{\n\t\t\t\tpxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &xTasksWaitingTermination ) );\n\t\t\t\t( void ) uxListRemove( &( pxTCB->xStateListItem ) );\n\t\t\t\t--uxCurrentNumberOfTasks;\n\t\t\t\t--uxDeletedTasksWaitingCleanUp;\n\t\t\t}\n\t\t\ttaskEXIT_CRITICAL();\n\n\t\t\tprvDeleteTCB( pxTCB );\n\t\t}\n\t}\n\t#endif /* INCLUDE_vTaskDelete */\n}\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TRACE_FACILITY == 1 )\n\n\tvoid vTaskGetInfo( task_t task, TaskStatus_t *pxTaskStatus, int32_t xGetFreeStackSpace, task_state_e_t eState )\n\t{\n\tTCB_t *pxTCB;\n\n\t\t/* task is NULL then get the state of the calling task. */\n\t\tpxTCB = prvGetTCBFromHandle( task );\n\n\t\tpxTaskStatus->xHandle = ( task_t ) pxTCB;\n\t\tpxTaskStatus->pcTaskName = ( const char * ) &( pxTCB->pcTaskName [ 0 ] );\n\t\tpxTaskStatus->uxCurrentPriority = pxTCB->uxPriority;\n\t\tpxTaskStatus->pxStackBase = pxTCB->pxStack;\n\t\tpxTaskStatus->xTaskNumber = pxTCB->uxTCBNumber;\n\n\t\t#if ( configUSE_MUTEXES == 1 )\n\t\t{\n\t\t\tpxTaskStatus->uxBasePriority = pxTCB->uxBasePriority;\n\t\t}\n\t\t#else\n\t\t{\n\t\t\tpxTaskStatus->uxBasePriority = 0;\n\t\t}\n\t\t#endif\n\n\t\t#if ( configGENERATE_RUN_TIME_STATS == 1 )\n\t\t{\n\t\t\tpxTaskStatus->ulRunTimeCounter = pxTCB->ulRunTimeCounter;\n\t\t}\n\t\t#else\n\t\t{\n\t\t\tpxTaskStatus->ulRunTimeCounter = 0;\n\t\t}\n\t\t#endif\n\n\t\t/* Obtaining the task state is a little fiddly, so is only done if the\n\t\tvalue of eState passed into this function is E_TASK_STATE_INVALID - otherwise the\n\t\tstate is just set to whatever is passed in. */\n\t\tif( eState != E_TASK_STATE_INVALID )\n\t\t{\n\t\t\tif( pxTCB == pxCurrentTCB )\n\t\t\t{\n\t\t\t\tpxTaskStatus->eCurrentState = E_TASK_STATE_RUNNING;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpxTaskStatus->eCurrentState = eState;\n\n\t\t\t\t#if ( INCLUDE_vTaskSuspend == 1 )\n\t\t\t\t{\n\t\t\t\t\t/* If the task is in the suspended list then there is a\n\t\t\t\t\tchance it is actually just blocked indefinitely - so really\n\t\t\t\t\tit should be reported as being in the Blocked state. */\n\t\t\t\t\tif( eState == E_TASK_STATE_SUSPENDED )\n\t\t\t\t\t{\n\t\t\t\t\t\trtos_suspend_all();\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) != NULL )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tpxTaskStatus->eCurrentState = E_TASK_STATE_BLOCKED;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t( void ) rtos_resume_all();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t#endif /* INCLUDE_vTaskSuspend */\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpxTaskStatus->eCurrentState = task_get_state( pxTCB );\n\t\t}\n\n\t\t/* Obtaining the stack space takes some time, so the xGetFreeStackSpace\n\t\tparameter is provided to allow it to be skipped. */\n\t\tif( xGetFreeStackSpace != pdFALSE )\n\t\t{\n\t\t\t#if ( portSTACK_GROWTH > 0 )\n\t\t\t{\n\t\t\t\tpxTaskStatus->usStackHighWaterMark = prvTaskCheckFreeStackSpace( ( uint8_t * ) pxTCB->pxEndOfStack );\n\t\t\t}\n\t\t\t#else\n\t\t\t{\n\t\t\t\tpxTaskStatus->usStackHighWaterMark = prvTaskCheckFreeStackSpace( ( uint8_t * ) pxTCB->pxStack );\n\t\t\t}\n\t\t\t#endif\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpxTaskStatus->usStackHighWaterMark = 0;\n\t\t}\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tstatic uint32_t prvListTasksWithinSingleList( TaskStatus_t *pxTaskStatusArray, List_t *pxList, task_state_e_t eState )\n\t{\n\tconfigLIST_VOLATILE TCB_t *pxNextTCB, *pxFirstTCB;\n\tuint32_t uxTask = 0;\n\n\t\tif( listCURRENT_LIST_LENGTH( pxList ) > ( uint32_t ) 0 )\n\t\t{\n\t\t\tlistGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\n\n\t\t\t/* Populate an TaskStatus_t structure within the\n\t\t\tpxTaskStatusArray array for each task that is referenced from\n\t\t\tpxList.  See the definition of TaskStatus_t in task.h for the\n\t\t\tmeaning of each TaskStatus_t structure member. */\n\t\t\tdo\n\t\t\t{\n\t\t\t\tlistGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );\n\t\t\t\tvTaskGetInfo( ( task_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState );\n\t\t\t\tuxTask++;\n\t\t\t} while( pxNextTCB != pxFirstTCB );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\treturn uxTask;\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*-----------------------------------------------------------*/\n\n#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )\n\n\tstatic uint16_t prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte )\n\t{\n\tuint32_t ulCount = 0U;\n\n\t\twhile( *pucStackByte == ( uint8_t ) tskSTACK_FILL_BYTE )\n\t\t{\n\t\t\tpucStackByte -= portSTACK_GROWTH;\n\t\t\tulCount++;\n\t\t}\n\n\t\tulCount /= ( uint32_t ) sizeof( task_stack_t ); /*lint !e961 Casting is not redundant on smaller architectures. */\n\n\t\treturn ( uint16_t ) ulCount;\n\t}\n\n#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) */\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )\n\n\tuint32_t uxTaskGetStackHighWaterMark( task_t task )\n\t{\n\tTCB_t *pxTCB;\n\tuint8_t *pucEndOfStack;\n\tuint32_t uxReturn;\n\n\t\tpxTCB = prvGetTCBFromHandle( task );\n\n\t\t#if portSTACK_GROWTH < 0\n\t\t{\n\t\t\tpucEndOfStack = ( uint8_t * ) pxTCB->pxStack;\n\t\t}\n\t\t#else\n\t\t{\n\t\t\tpucEndOfStack = ( uint8_t * ) pxTCB->pxEndOfStack;\n\t\t}\n\t\t#endif\n\n\t\tuxReturn = ( uint32_t ) prvTaskCheckFreeStackSpace( pucEndOfStack );\n\n\t\treturn uxReturn;\n\t}\n\n#endif /* INCLUDE_uxTaskGetStackHighWaterMark */\n/*-----------------------------------------------------------*/\n\n#if ( INCLUDE_vTaskDelete == 1 )\n\n\tstatic void prvDeleteTCB( TCB_t *pxTCB )\n\t{\n\t\t/* This call is required specifically for the TriCore port.  It must be\n\t\tabove the kfree() calls.  The call is also used by ports/demos that\n\t\twant to allocate and clean RAM statically. */\n\t\tportCLEAN_UP_TCB( pxTCB );\n\n\t\t/* Free up the memory allocated by the scheduler for the task.  It is up\n\t\tto the task to free any memory allocated at the application level. */\n\t\t#if ( configUSE_NEWLIB_REENTRANT == 1 )\n\t\t{\n\t\t\t_reclaim_reent( &( pxTCB->xNewLib_reent ) );\n\t\t}\n\t\t#endif /* configUSE_NEWLIB_REENTRANT */\n\n\t\t#if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ))\n\t\t{\n\t\t\t/* The task can only have been allocated dynamically - free both\n\t\t\tthe stack and TCB. */\n\t\t\tkfree( pxTCB->pxStack );\n\t\t\tkfree( pxTCB );\n\t\t}\n\t\t#elif( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 Macro has been consolidated for readability reasons. */\n\t\t{\n\t\t\t/* The task could have been allocated statically or dynamically, so\n\t\t\tcheck what was statically allocated before trying to free the\n\t\t\tmemory. */\n\t\t\tif( pxTCB->ucStaticallyAllocated == tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB )\n\t\t\t{\n\t\t\t\t/* Both the stack and TCB were allocated dynamically, so both\n\t\t\t\tmust be freed. */\n\t\t\t\tkfree( pxTCB->pxStack );\n\t\t\t\tkfree( pxTCB );\n\t\t\t}\n\t\t\telse if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_ONLY )\n\t\t\t{\n\t\t\t\t/* Only the stack was statically allocated, so the TCB is the\n\t\t\t\tonly memory that must be freed. */\n\t\t\t\tkfree( pxTCB );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* Neither the stack nor the TCB were allocated dynamically, so\n\t\t\t\tnothing needs to be freed. */\n\t\t\t\tconfigASSERT( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB\t);\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\t#endif /* configSUPPORT_DYNAMIC_ALLOCATION */\n\t}\n\n#endif /* INCLUDE_vTaskDelete */\n/*-----------------------------------------------------------*/\n\nstatic void prvResetNextTaskUnblockTime( void )\n{\nTCB_t *pxTCB;\n\n\tif( listLIST_IS_EMPTY( pxDelayedTaskList ) != pdFALSE )\n\t{\n\t\t/* The new current delayed list is empty.  Set xNextTaskUnblockTime to\n\t\tthe maximum possible value so it is\textremely unlikely that the\n\t\tif( xTickCount >= xNextTaskUnblockTime ) test will pass until\n\t\tthere is an item in the delayed list. */\n\t\txNextTaskUnblockTime = portMAX_DELAY;\n\t}\n\telse\n\t{\n\t\t/* The new current delayed list is not empty, get the value of\n\t\tthe item at the head of the delayed list.  This is the time at\n\t\twhich the task at the head of the delayed list should be removed\n\t\tfrom the Blocked state. */\n\t\t( pxTCB ) = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedTaskList );\n\t\txNextTaskUnblockTime = listGET_LIST_ITEM_VALUE( &( ( pxTCB )->xStateListItem ) );\n\t}\n}\n/*-----------------------------------------------------------*/\n\n#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) )\n\n\ttask_t task_get_current( void )\n\t{\n\ttask_t xReturn;\n\n\t\t/* A critical section is not required as this is not called from\n\t\tan interrupt and the current TCB will always be the same for any\n\t\tindividual execution thread. */\n\t\txReturn = pxCurrentTCB;\n\n\t\treturn xReturn;\n\t}\n\n#endif /* ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */\n/*-----------------------------------------------------------*/\n\n#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\n\n\tint32_t xTaskGetSchedulerState( void )\n\t{\n\tint32_t xReturn;\n\n\t\tif( xSchedulerRunning == pdFALSE )\n\t\t{\n\t\t\txReturn = taskSCHEDULER_NOT_STARTED;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif( uxSchedulerSuspended == ( uint32_t ) pdFALSE )\n\t\t\t{\n\t\t\t\txReturn = taskSCHEDULER_RUNNING;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\txReturn = taskSCHEDULER_SUSPENDED;\n\t\t\t}\n\t\t}\n\n\t\treturn xReturn;\n\t}\n\n#endif /* ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) ) */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_MUTEXES == 1 )\n\n\tint32_t xTaskPriorityInherit( task_t const pxMutexHolder )\n\t{\n\tTCB_t * const pxMutexHolderTCB = ( TCB_t * ) pxMutexHolder;\n\tint32_t xReturn = pdFALSE;\n\n\t\t/* If the mutex was given back by an interrupt while the queue was\n\t\tlocked then the mutex holder might now be NULL.  _RB_ Is this still\n\t\tneeded as interrupts can no longer use mutexes? */\n\t\tif( pxMutexHolder != NULL )\n\t\t{\n\t\t\t/* If the holder of the mutex has a priority below the priority of\n\t\t\tthe task attempting to obtain the mutex then it will temporarily\n\t\t\tinherit the priority of the task attempting to obtain the mutex. */\n\t\t\tif( pxMutexHolderTCB->uxPriority < pxCurrentTCB->uxPriority )\n\t\t\t{\n\t\t\t\t/* Adjust the mutex holder state to account for its new\n\t\t\t\tpriority.  Only reset the event list item value if the value is\n\t\t\t\tnot being used for anything else. */\n\t\t\t\tif( ( listGET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\n\t\t\t\t{\n\t\t\t\t\tlistSET_LIST_ITEM_VALUE( &( pxMutexHolderTCB->xEventListItem ), ( uint32_t ) configMAX_PRIORITIES - ( uint32_t ) pxCurrentTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\n\t\t\t\t/* If the task being modified is in the ready state it will need\n\t\t\t\tto be moved into a new list. */\n\t\t\t\tif( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ pxMutexHolderTCB->uxPriority ] ), &( pxMutexHolderTCB->xStateListItem ) ) != pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tif( uxListRemove( &( pxMutexHolderTCB->xStateListItem ) ) == ( uint32_t ) 0 )\n\t\t\t\t\t{\n\t\t\t\t\t\ttaskRESET_READY_PRIORITY( pxMutexHolderTCB->uxPriority );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\n\t\t\t\t\t/* Inherit the priority before being moved into the new list. */\n\t\t\t\t\tpxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority;\n\t\t\t\t\tprvAddTaskToReadyList( pxMutexHolderTCB );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* Just inherit the priority. */\n\t\t\t\t\tpxMutexHolderTCB->uxPriority = pxCurrentTCB->uxPriority;\n\t\t\t\t}\n\n\t\t\t\ttraceTASK_PRIORITY_INHERIT( pxMutexHolderTCB, pxCurrentTCB->uxPriority );\n\n\t\t\t\t/* Inheritance occurred. */\n\t\t\t\txReturn = pdTRUE;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif( pxMutexHolderTCB->uxBasePriority < pxCurrentTCB->uxPriority )\n\t\t\t\t{\n\t\t\t\t\t/* The base priority of the mutex holder is lower than the\n\t\t\t\t\tpriority of the task attempting to take the mutex, but the\n\t\t\t\t\tcurrent priority of the mutex holder is not lower than the\n\t\t\t\t\tpriority of the task attempting to take the mutex.\n\t\t\t\t\tTherefore the mutex holder must have already inherited a\n\t\t\t\t\tpriority, but inheritance would have occurred if that had\n\t\t\t\t\tnot been the case. */\n\t\t\t\t\txReturn = pdTRUE;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_MUTEXES */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_MUTEXES == 1 )\n\n\tint32_t xTaskPriorityDisinherit( task_t const pxMutexHolder )\n\t{\n\tTCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;\n\tint32_t xReturn = pdFALSE;\n\n\t\tif( pxMutexHolder != NULL )\n\t\t{\n\t\t\t/* A task can only have an inherited priority if it holds the mutex.\n\t\t\tIf the mutex is held by a task then it cannot be given from an\n\t\t\tinterrupt, and if a mutex is given by the holding task then it must\n\t\t\tbe the running state task. */\n\t\t\tconfigASSERT( pxTCB == pxCurrentTCB );\n\t\t\tconfigASSERT( pxTCB->uxMutexesHeld );\n\t\t\t( pxTCB->uxMutexesHeld )--;\n\n\t\t\t/* Has the holder of the mutex inherited the priority of another\n\t\t\ttask? */\n\t\t\tif( pxTCB->uxPriority != pxTCB->uxBasePriority )\n\t\t\t{\n\t\t\t\t/* Only disinherit if no other mutexes are held. */\n\t\t\t\tif( pxTCB->uxMutexesHeld == ( uint32_t ) 0 )\n\t\t\t\t{\n\t\t\t\t\t/* A task can only have an inherited priority if it holds\n\t\t\t\t\tthe mutex.  If the mutex is held by a task then it cannot be\n\t\t\t\t\tgiven from an interrupt, and if a mutex is given by the\n\t\t\t\t\tholding task then it must be the running state task.  Remove\n\t\t\t\t\tthe holding task from the ready list. */\n\t\t\t\t\tif( uxListRemove( &( pxTCB->xStateListItem ) ) == ( uint32_t ) 0 )\n\t\t\t\t\t{\n\t\t\t\t\t\ttaskRESET_READY_PRIORITY( pxTCB->uxPriority );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\n\t\t\t\t\t/* Disinherit the priority before adding the task into the\n\t\t\t\t\tnew\tready list. */\n\t\t\t\t\ttraceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );\n\t\t\t\t\tpxTCB->uxPriority = pxTCB->uxBasePriority;\n\n\t\t\t\t\t/* Reset the event list item value.  It cannot be in use for\n\t\t\t\t\tany other purpose if this task is running, and it must be\n\t\t\t\t\trunning to give back the mutex. */\n\t\t\t\t\tlistSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( uint32_t ) configMAX_PRIORITIES - ( uint32_t ) pxTCB->uxPriority ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\t\t\t\t\tprvAddTaskToReadyList( pxTCB );\n\n\t\t\t\t\t/* Return true to indicate that a context switch is required.\n\t\t\t\t\tThis is only actually required in the corner case whereby\n\t\t\t\t\tmultiple mutexes were held and the mutexes were given back\n\t\t\t\t\tin an order different to that in which they were taken.\n\t\t\t\t\tIf a context switch did not occur when the first mutex was\n\t\t\t\t\treturned, even if a task was waiting on it, then a context\n\t\t\t\t\tswitch should occur when the last mutex is returned whether\n\t\t\t\t\ta task is waiting on it or not. */\n\t\t\t\t\txReturn = pdTRUE;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_MUTEXES */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_MUTEXES == 1 )\n\n\tvoid vTaskPriorityDisinheritAfterTimeout( task_t const pxMutexHolder, uint32_t uxHighestPriorityWaitingTask )\n\t{\n\tTCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;\n\tuint32_t uxPriorityUsedOnEntry, uxPriorityToUse;\n\tconst uint32_t uxOnlyOneMutexHeld = ( uint32_t ) 1;\n\n\t\tif( pxMutexHolder != NULL )\n\t\t{\n\t\t\t/* If pxMutexHolder is not NULL then the holder must hold at least\n\t\t\tone mutex. */\n\t\t\tconfigASSERT( pxTCB->uxMutexesHeld );\n\n\t\t\t/* Determine the priority to which the priority of the task that\n\t\t\tholds the mutex should be set.  This will be the greater of the\n\t\t\tholding task's base priority and the priority of the highest\n\t\t\tpriority task that is waiting to obtain the mutex. */\n\t\t\tif( pxTCB->uxBasePriority < uxHighestPriorityWaitingTask )\n\t\t\t{\n\t\t\t\tuxPriorityToUse = uxHighestPriorityWaitingTask;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tuxPriorityToUse = pxTCB->uxBasePriority;\n\t\t\t}\n\n\t\t\t/* Does the priority need to change? */\n\t\t\tif( pxTCB->uxPriority != uxPriorityToUse )\n\t\t\t{\n\t\t\t\t/* Only disinherit if no other mutexes are held.  This is a\n\t\t\t\tsimplification in the priority inheritance implementation.  If\n\t\t\t\tthe task that holds the mutex is also holding other mutexes then\n\t\t\t\tthe other mutexes may have caused the priority inheritance. */\n\t\t\t\tif( pxTCB->uxMutexesHeld == uxOnlyOneMutexHeld )\n\t\t\t\t{\n\t\t\t\t\t/* If a task has timed out because it already holds the\n\t\t\t\t\tmutex it was trying to obtain then it cannot of inherited\n\t\t\t\t\tits own priority. */\n\t\t\t\t\tconfigASSERT( pxTCB != pxCurrentTCB );\n\n\t\t\t\t\t/* Disinherit the priority, remembering the previous\n\t\t\t\t\tpriority to facilitate determining the subject task's\n\t\t\t\t\tstate. */\n\t\t\t\t\ttraceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );\n\t\t\t\t\tuxPriorityUsedOnEntry = pxTCB->uxPriority;\n\t\t\t\t\tpxTCB->uxPriority = uxPriorityToUse;\n\n\t\t\t\t\t/* Only reset the event list item value if the value is not\n\t\t\t\t\tbeing used for anything else. */\n\t\t\t\t\tif( ( listGET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ) ) & taskEVENT_LIST_ITEM_VALUE_IN_USE ) == 0UL )\n\t\t\t\t\t{\n\t\t\t\t\t\tlistSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( uint32_t ) configMAX_PRIORITIES - ( uint32_t ) uxPriorityToUse ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\n\t\t\t\t\t/* If the running task is not the task that holds the mutex\n\t\t\t\t\tthen the task that holds the mutex could be in either the\n\t\t\t\t\tReady, Blocked or Suspended states.  Only remove the task\n\t\t\t\t\tfrom its current state list if it is in the Ready state as\n\t\t\t\t\tthe task's priority is going to change and there is one\n\t\t\t\t\tReady list per priority. */\n\t\t\t\t\tif( listIS_CONTAINED_WITHIN( &( pxReadyTasksLists[ uxPriorityUsedOnEntry ] ), &( pxTCB->xStateListItem ) ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\tif( uxListRemove( &( pxTCB->xStateListItem ) ) == ( uint32_t ) 0 )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttaskRESET_READY_PRIORITY( pxTCB->uxPriority );\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tprvAddTaskToReadyList( pxTCB );\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\n#endif /* configUSE_MUTEXES */\n/*-----------------------------------------------------------*/\n\n#if ( portCRITICAL_NESTING_IN_TCB == 1 )\n\n\tvoid vTaskEnterCritical( void )\n\t{\n\t\tportDISABLE_INTERRUPTS();\n\n\t\tif( xSchedulerRunning != pdFALSE )\n\t\t{\n\t\t\t( pxCurrentTCB->uxCriticalNesting )++;\n\n\t\t\t/* This is not the interrupt safe version of the enter critical\n\t\t\tfunction so\tassert() if it is being called from an interrupt\n\t\t\tcontext.  Only API functions that end in \"FromISR\" can be used in an\n\t\t\tinterrupt.  Only assert if the critical nesting count is 1 to\n\t\t\tprotect against recursive calls if the assert function also uses a\n\t\t\tcritical section. */\n\t\t\tif( pxCurrentTCB->uxCriticalNesting == 1 )\n\t\t\t{\n\t\t\t\tportASSERT_IF_IN_ISR();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\n#endif /* portCRITICAL_NESTING_IN_TCB */\n/*-----------------------------------------------------------*/\n\n#if ( portCRITICAL_NESTING_IN_TCB == 1 )\n\n\tvoid vTaskExitCritical( void )\n\t{\n\t\tif( xSchedulerRunning != pdFALSE )\n\t\t{\n\t\t\tif( pxCurrentTCB->uxCriticalNesting > 0U )\n\t\t\t{\n\t\t\t\t( pxCurrentTCB->uxCriticalNesting )--;\n\n\t\t\t\tif( pxCurrentTCB->uxCriticalNesting == 0U )\n\t\t\t\t{\n\t\t\t\t\tportENABLE_INTERRUPTS();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\n#endif /* portCRITICAL_NESTING_IN_TCB */\n/*-----------------------------------------------------------*/\n\n#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )\n\n\tstatic char *prvWriteNameToBuffer( char *pcBuffer, const char *pcTaskName )\n\t{\n\tsize_t x;\n\n\t\t/* Start by copying the entire string. */\n\t\tstrcpy( pcBuffer, pcTaskName );\n\n\t\t/* Pad the end of the string with spaces to ensure columns line up when\n\t\tprinted out. */\n\t\tfor( x = strlen( pcBuffer ); x < ( size_t ) ( configMAX_TASK_NAME_LEN - 1 ); x++ )\n\t\t{\n\t\t\tpcBuffer[ x ] = ' ';\n\t\t}\n\n\t\t/* Terminate. */\n\t\tpcBuffer[ x ] = 0x00;\n\n\t\t/* Return the new end of string. */\n\t\treturn &( pcBuffer[ x ] );\n\t}\n\n#endif /* ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) */\n/*-----------------------------------------------------------*/\n\n#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\n\n\tvoid vTaskList( char * pcWriteBuffer )\n\t{\n\tTaskStatus_t *pxTaskStatusArray;\n\tvolatile uint32_t uxArraySize, x;\n\tchar cStatus;\n\n\t\t/*\n\t\t * PLEASE NOTE:\n\t\t *\n\t\t * This function is provided for convenience only, and is used by many\n\t\t * of the demo applications.  Do not consider it to be part of the\n\t\t * scheduler.\n\t\t *\n\t\t * vTaskList() calls uxTaskGetSystemState(), then formats part of the\n\t\t * uxTaskGetSystemState() output into a human readable table that\n\t\t * displays task names, states and stack usage.\n\t\t *\n\t\t * vTaskList() has a dependency on the sprintf() C library function that\n\t\t * might bloat the code size, use a lot of stack, and provide different\n\t\t * results on different platforms.  An alternative, tiny, third party,\n\t\t * and limited functionality implementation of sprintf() is provided in\n\t\t * many of the FreeRTOS/Demo sub-directories in a file called\n\t\t * printf-stdarg.c (note printf-stdarg.c does not provide a full\n\t\t * snprintf() implementation!).\n\t\t *\n\t\t * It is recommended that production systems call uxTaskGetSystemState()\n\t\t * directly to get access to raw stats data, rather than indirectly\n\t\t * through a call to vTaskList().\n\t\t */\n\n\n\t\t/* Make sure the write buffer does not contain a string. */\n\t\t*pcWriteBuffer = 0x00;\n\n\t\t/* Take a snapshot of the number of tasks in case it changes while this\n\t\tfunction is executing. */\n\t\tuxArraySize = uxCurrentNumberOfTasks;\n\n\t\t/* Allocate an array index for each task.  NOTE!  if\n\t\tconfigSUPPORT_DYNAMIC_ALLOCATION is set to 0 then kmalloc() will\n\t\tequate to NULL. */\n\t\tpxTaskStatusArray = kmalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );\n\n\t\tif( pxTaskStatusArray != NULL )\n\t\t{\n\t\t\t/* Generate the (binary) data. */\n\t\t\tuxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, NULL );\n\n\t\t\t/* Create a human readable table from the binary data. */\n\t\t\tfor( x = 0; x < uxArraySize; x++ )\n\t\t\t{\n\t\t\t\tswitch( pxTaskStatusArray[ x ].eCurrentState )\n\t\t\t\t{\n\t\t\t\t\tcase E_TASK_STATE_RUNNING:\t\tcStatus = tskRUNNING_CHAR;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase E_TASK_STATE_READY:\t\tcStatus = tskREADY_CHAR;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase E_TASK_STATE_BLOCKED:\t\tcStatus = tskBLOCKED_CHAR;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase E_TASK_STATE_SUSPENDED:\tcStatus = tskSUSPENDED_CHAR;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase E_TASK_STATE_DELETED:\t\tcStatus = tskDELETED_CHAR;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tdefault:\t\t\t/* Should not get here, but it is included\n\t\t\t\t\t\t\t\t\t\tto prevent static checking errors. */\n\t\t\t\t\t\t\t\t\t\tcStatus = 0x00;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\t/* Write the task name to the string, padding with spaces so it\n\t\t\t\tcan be printed in tabular form more easily. */\n\t\t\t\tpcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName );\n\n\t\t\t\t/* Write the rest of the string. */\n\t\t\t\tsprintf( pcWriteBuffer, \"\\t%c\\t%u\\t%u\\t%u\\r\\n\", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber );\n\t\t\t\tpcWriteBuffer += strlen( pcWriteBuffer );\n\t\t\t}\n\n\t\t\t/* Free the array again.  NOTE!  If configSUPPORT_DYNAMIC_ALLOCATION\n\t\t\tis 0 then kfree() will be #defined to nothing. */\n\t\t\tkfree( pxTaskStatusArray );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\n#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */\n/*----------------------------------------------------------*/\n\n#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\n\n\tvoid vTaskGetRunTimeStats( char *pcWriteBuffer )\n\t{\n\tTaskStatus_t *pxTaskStatusArray;\n\tvolatile uint32_t uxArraySize, x;\n\tuint32_t ulTotalTime, ulStatsAsPercentage;\n\n\t\t#if( configUSE_TRACE_FACILITY != 1 )\n\t\t{\n\t\t\t#error configUSE_TRACE_FACILITY must also be set to 1 in FreeRTOSConfig.h to use vTaskGetRunTimeStats().\n\t\t}\n\t\t#endif\n\n\t\t/*\n\t\t * PLEASE NOTE:\n\t\t *\n\t\t * This function is provided for convenience only, and is used by many\n\t\t * of the demo applications.  Do not consider it to be part of the\n\t\t * scheduler.\n\t\t *\n\t\t * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part\n\t\t * of the uxTaskGetSystemState() output into a human readable table that\n\t\t * displays the amount of time each task has spent in the Running state\n\t\t * in both absolute and percentage terms.\n\t\t *\n\t\t * vTaskGetRunTimeStats() has a dependency on the sprintf() C library\n\t\t * function that might bloat the code size, use a lot of stack, and\n\t\t * provide different results on different platforms.  An alternative,\n\t\t * tiny, third party, and limited functionality implementation of\n\t\t * sprintf() is provided in many of the FreeRTOS/Demo sub-directories in\n\t\t * a file called printf-stdarg.c (note printf-stdarg.c does not provide\n\t\t * a full snprintf() implementation!).\n\t\t *\n\t\t * It is recommended that production systems call uxTaskGetSystemState()\n\t\t * directly to get access to raw stats data, rather than indirectly\n\t\t * through a call to vTaskGetRunTimeStats().\n\t\t */\n\n\t\t/* Make sure the write buffer does not contain a string. */\n\t\t*pcWriteBuffer = 0x00;\n\n\t\t/* Take a snapshot of the number of tasks in case it changes while this\n\t\tfunction is executing. */\n\t\tuxArraySize = uxCurrentNumberOfTasks;\n\n\t\t/* Allocate an array index for each task.  NOTE!  If\n\t\tconfigSUPPORT_DYNAMIC_ALLOCATION is set to 0 then kmalloc() will\n\t\tequate to NULL. */\n\t\tpxTaskStatusArray = kmalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );\n\n\t\tif( pxTaskStatusArray != NULL )\n\t\t{\n\t\t\t/* Generate the (binary) data. */\n\t\t\tuxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalTime );\n\n\t\t\t/* For percentage calculations. */\n\t\t\tulTotalTime /= 100UL;\n\n\t\t\t/* Avoid divide by zero errors. */\n\t\t\tif( ulTotalTime > 0 )\n\t\t\t{\n\t\t\t\t/* Create a human readable table from the binary data. */\n\t\t\t\tfor( x = 0; x < uxArraySize; x++ )\n\t\t\t\t{\n\t\t\t\t\t/* What percentage of the total run time has the task used?\n\t\t\t\t\tThis will always be rounded down to the nearest integer.\n\t\t\t\t\tulTotalRunTimeDiv100 has already been divided by 100. */\n\t\t\t\t\tulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalTime;\n\n\t\t\t\t\t/* Write the task name to the string, padding with\n\t\t\t\t\tspaces so it can be printed in tabular form more\n\t\t\t\t\teasily. */\n\t\t\t\t\tpcWriteBuffer = prvWriteNameToBuffer( pcWriteBuffer, pxTaskStatusArray[ x ].pcTaskName );\n\n\t\t\t\t\tif( ulStatsAsPercentage > 0UL )\n\t\t\t\t\t{\n\t\t\t\t\t\t#ifdef portLU_PRINTF_SPECIFIER_REQUIRED\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsprintf( pcWriteBuffer, \"\\t%lu\\t\\t%lu%%\\r\\n\", pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );\n\t\t\t\t\t\t}\n\t\t\t\t\t\t#else\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* sizeof( int ) == sizeof( long ) so a smaller\n\t\t\t\t\t\t\tprintf() library can be used. */\n\t\t\t\t\t\t\tsprintf( pcWriteBuffer, \"\\t%u\\t\\t%u%%\\r\\n\", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter, ( unsigned int ) ulStatsAsPercentage );\n\t\t\t\t\t\t}\n\t\t\t\t\t\t#endif\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t/* If the percentage is zero here then the task has\n\t\t\t\t\t\tconsumed less than 1% of the total run time. */\n\t\t\t\t\t\t#ifdef portLU_PRINTF_SPECIFIER_REQUIRED\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsprintf( pcWriteBuffer, \"\\t%lu\\t\\t<1%%\\r\\n\", pxTaskStatusArray[ x ].ulRunTimeCounter );\n\t\t\t\t\t\t}\n\t\t\t\t\t\t#else\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/* sizeof( int ) == sizeof( long ) so a smaller\n\t\t\t\t\t\t\tprintf() library can be used. */\n\t\t\t\t\t\t\tsprintf( pcWriteBuffer, \"\\t%u\\t\\t<1%%\\r\\n\", ( unsigned int ) pxTaskStatusArray[ x ].ulRunTimeCounter );\n\t\t\t\t\t\t}\n\t\t\t\t\t\t#endif\n\t\t\t\t\t}\n\n\t\t\t\t\tpcWriteBuffer += strlen( pcWriteBuffer );\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\n\t\t\t/* Free the array again.  NOTE!  If configSUPPORT_DYNAMIC_ALLOCATION\n\t\t\tis 0 then kfree() will be #defined to nothing. */\n\t\t\tkfree( pxTaskStatusArray );\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\n#endif /* ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) */\n/*-----------------------------------------------------------*/\n\nuint32_t uxTaskResetEventItemValue( void )\n{\nuint32_t uxReturn;\n\n\tuxReturn = listGET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ) );\n\n\t/* Reset the event list item to its normal value - so it can be used with\n\tqueues and semaphores. */\n\tlistSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xEventListItem ), ( ( uint32_t ) configMAX_PRIORITIES - ( uint32_t ) pxCurrentTCB->uxPriority ) ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\n\treturn uxReturn;\n}\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_MUTEXES == 1 )\n\n\tvoid *pvTaskIncrementMutexHeldCount( void )\n\t{\n\t\t/* If mutex_create() is called before any tasks have been created\n\t\tthen pxCurrentTCB will be NULL. */\n\t\tif( pxCurrentTCB != NULL )\n\t\t{\n\t\t\t( pxCurrentTCB->uxMutexesHeld )++;\n\t\t}\n\n\t\treturn pxCurrentTCB;\n\t}\n\n#endif /* configUSE_MUTEXES */\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TASK_NOTIFICATIONS == 1 )\n\n\tuint32_t task_notify_take(bool clear_on_exit, uint32_t timeout)\n\t{\n\tuint32_t ulReturn;\n\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\t/* Only block if the notification count is not already non-zero. */\n\t\t\tif( pxCurrentTCB->ulNotifiedValue == 0UL )\n\t\t\t{\n\t\t\t\t/* Mark this task as waiting for a notification. */\n\t\t\t\tpxCurrentTCB->ucNotifyState = taskWAITING_NOTIFICATION;\n\n\t\t\t\tif( timeout > ( uint32_t ) 0 )\n\t\t\t\t{\n\t\t\t\t\tprvAddCurrentTaskToDelayedList( timeout, pdTRUE );\n\t\t\t\t\ttraceTASK_NOTIFY_TAKE_BLOCK();\n\n\t\t\t\t\t/* All ports are written to allow a yield in a critical\n\t\t\t\t\tsection (some will yield immediately, others wait until the\n\t\t\t\t\tcritical section exits) - but it is not something that\n\t\t\t\t\tapplication code should ever do. */\n\t\t\t\t\tportYIELD_WITHIN_API();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\ttraceTASK_NOTIFY_TAKE();\n\t\t\tulReturn = pxCurrentTCB->ulNotifiedValue;\n\n\t\t\tif( ulReturn != 0UL )\n\t\t\t{\n\t\t\t\tif( clear_on_exit != pdFALSE )\n\t\t\t\t{\n\t\t\t\t\tpxCurrentTCB->ulNotifiedValue = 0UL;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tpxCurrentTCB->ulNotifiedValue = ulReturn - ( uint32_t ) 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\n\t\t\tpxCurrentTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\treturn ulReturn;\n\t}\n\n#endif /* configUSE_TASK_NOTIFICATIONS */\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TASK_NOTIFICATIONS == 1 )\n\n\tint32_t task_notify_wait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, uint32_t timeout )\n\t{\n\tint32_t xReturn;\n\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\t/* Only block if a notification is not already pending. */\n\t\t\tif( pxCurrentTCB->ucNotifyState != taskNOTIFICATION_RECEIVED )\n\t\t\t{\n\t\t\t\t/* Clear bits in the task's notification value as bits may get\n\t\t\t\tset\tby the notifying task or interrupt.  This can be used to\n\t\t\t\tclear the value to zero. */\n\t\t\t\tpxCurrentTCB->ulNotifiedValue &= ~ulBitsToClearOnEntry;\n\n\t\t\t\t/* Mark this task as waiting for a notification. */\n\t\t\t\tpxCurrentTCB->ucNotifyState = taskWAITING_NOTIFICATION;\n\n\t\t\t\tif( timeout > ( uint32_t ) 0 )\n\t\t\t\t{\n\t\t\t\t\tprvAddCurrentTaskToDelayedList( timeout, pdTRUE );\n\t\t\t\t\ttraceTASK_NOTIFY_WAIT_BLOCK();\n\n\t\t\t\t\t/* All ports are written to allow a yield in a critical\n\t\t\t\t\tsection (some will yield immediately, others wait until the\n\t\t\t\t\tcritical section exits) - but it is not something that\n\t\t\t\t\tapplication code should ever do. */\n\t\t\t\t\tportYIELD_WITHIN_API();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\ttraceTASK_NOTIFY_WAIT();\n\n\t\t\tif( pulNotificationValue != NULL )\n\t\t\t{\n\t\t\t\t/* Output the current notification value, which may or may not\n\t\t\t\thave changed. */\n\t\t\t\t*pulNotificationValue = pxCurrentTCB->ulNotifiedValue;\n\t\t\t}\n\n\t\t\t/* If ucNotifyValue is set then either the task never entered the\n\t\t\tblocked state (because a notification was already pending) or the\n\t\t\ttask unblocked because of a notification.  Otherwise the task\n\t\t\tunblocked because of a timeout. */\n\t\t\tif( pxCurrentTCB->ucNotifyState != taskNOTIFICATION_RECEIVED )\n\t\t\t{\n\t\t\t\t/* A notification was not received. */\n\t\t\t\txReturn = pdFALSE;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* A notification was already pending or a notification was\n\t\t\t\treceived while the task was waiting. */\n\t\t\t\tpxCurrentTCB->ulNotifiedValue &= ~ulBitsToClearOnExit;\n\t\t\t\txReturn = pdTRUE;\n\t\t\t}\n\n\t\t\tpxCurrentTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_TASK_NOTIFICATIONS */\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TASK_NOTIFICATIONS == 1 )\n\n\tint32_t task_notify_ext(task_t task, uint32_t value, notify_action_e_t action, uint32_t* prev_value)\n\t{\n\tTCB_t * pxTCB;\n\tint32_t xReturn = pdPASS;\n\tuint8_t ucOriginalNotifyState;\n\n\t\tconfigASSERT( task );\n\t\tpxTCB = ( TCB_t * ) task;\n\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\tif( prev_value != NULL )\n\t\t\t{\n\t\t\t\t*prev_value = pxTCB->ulNotifiedValue;\n\t\t\t}\n\n\t\t\tucOriginalNotifyState = pxTCB->ucNotifyState;\n\n\t\t\tpxTCB->ucNotifyState = taskNOTIFICATION_RECEIVED;\n\n\t\t\tswitch( action )\n\t\t\t{\n\t\t\t\tcase E_NOTIFY_ACTION_BITS\t:\n\t\t\t\t\tpxTCB->ulNotifiedValue |= value;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase E_NOTIFY_ACTION_INCR\t:\n\t\t\t\t\t( pxTCB->ulNotifiedValue )++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase E_NOTIFY_ACTION_OWRITE\t:\n\t\t\t\t\tpxTCB->ulNotifiedValue = value;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase E_NOTIFY_ACTION_NO_OWRITE :\n\t\t\t\t\tif( ucOriginalNotifyState != taskNOTIFICATION_RECEIVED )\n\t\t\t\t\t{\n\t\t\t\t\t\tpxTCB->ulNotifiedValue = value;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The value could not be written to the task. */\n\t\t\t\t\t\txReturn = pdFAIL;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase E_NOTIFY_ACTION_NONE:\n\t\t\t\t\t/* The task is being notified without its notify value being\n\t\t\t\t\tupdated. */\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\ttraceTASK_NOTIFY();\n\n\t\t\t/* If the task is in the blocked state specifically to wait for a\n\t\t\tnotification then unblock it now. */\n\t\t\tif( ucOriginalNotifyState == taskWAITING_NOTIFICATION )\n\t\t\t{\n\t\t\t\t( void ) uxListRemove( &( pxTCB->xStateListItem ) );\n\t\t\t\tprvAddTaskToReadyList( pxTCB );\n\n\t\t\t\t/* The task should not have been on an event list. */\n\t\t\t\tconfigASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );\n\n\t\t\t\t#if( configUSE_TICKLESS_IDLE != 0 )\n\t\t\t\t{\n\t\t\t\t\t/* If a task is blocked waiting for a notification then\n\t\t\t\t\txNextTaskUnblockTime might be set to the blocked task's time\n\t\t\t\t\tout time.  If the task is unblocked for a reason other than\n\t\t\t\t\ta timeout xNextTaskUnblockTime is normally left unchanged,\n\t\t\t\t\tbecause it will automatically get reset to a new value when\n\t\t\t\t\tthe tick count equals xNextTaskUnblockTime.  However if\n\t\t\t\t\ttickless idling is used it might be more important to enter\n\t\t\t\t\tsleep mode at the earliest possible time - so reset\n\t\t\t\t\txNextTaskUnblockTime here to ensure it is updated at the\n\t\t\t\t\tearliest possible time. */\n\t\t\t\t\tprvResetNextTaskUnblockTime();\n\t\t\t\t}\n\t\t\t\t#endif\n\n\t\t\t\tif( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\n\t\t\t\t{\n\t\t\t\t\t/* The notified task has a priority above the currently\n\t\t\t\t\texecuting task so a yield is required. */\n\t\t\t\t\ttaskYIELD_IF_USING_PREEMPTION();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_TASK_NOTIFICATIONS */\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TASK_NOTIFICATIONS == 1 )\n\n\tint32_t xTaskGenericNotifyFromISR( task_t task, uint32_t value, notify_action_e_t action, uint32_t *prev_value, int32_t *pxHigherPriorityTaskWoken )\n\t{\n\tTCB_t * pxTCB;\n\tuint8_t ucOriginalNotifyState;\n\tint32_t xReturn = pdPASS;\n\tuint32_t uxSavedInterruptStatus;\n\n\t\tconfigASSERT( task );\n\n\t\t/* RTOS ports that support interrupt nesting have the concept of a\n\t\tmaximum\tsystem call (or maximum API call) interrupt priority.\n\t\tInterrupts that are\tabove the maximum system call priority are keep\n\t\tpermanently enabled, even when the RTOS kernel is in a critical section,\n\t\tbut cannot make any calls to FreeRTOS API functions.  If configASSERT()\n\t\tis defined in FreeRTOSConfig.h then\n\t\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\n\t\tfailure if a FreeRTOS API function is called from an interrupt that has\n\t\tbeen assigned a priority above the configured maximum system call\n\t\tpriority.  Only FreeRTOS functions that end in FromISR can be called\n\t\tfrom interrupts\tthat have been assigned a priority at or (logically)\n\t\tbelow the maximum system call interrupt priority.  FreeRTOS maintains a\n\t\tseparate interrupt safe API to ensure interrupt entry is as fast and as\n\t\tsimple as possible.  More information (albeit Cortex-M specific) is\n\t\tprovided on the following link:\n\t\thttp://www.freertos.org/RTOS-Cortex-M3-M4.html */\n\t\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID();\n\n\t\tpxTCB = ( TCB_t * ) task;\n\n\t\tuxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\n\t\t{\n\t\t\tif( prev_value != NULL )\n\t\t\t{\n\t\t\t\t*prev_value = pxTCB->ulNotifiedValue;\n\t\t\t}\n\n\t\t\tucOriginalNotifyState = pxTCB->ucNotifyState;\n\t\t\tpxTCB->ucNotifyState = taskNOTIFICATION_RECEIVED;\n\n\t\t\tswitch( action )\n\t\t\t{\n\t\t\t\tcase E_NOTIFY_ACTION_BITS\t:\n\t\t\t\t\tpxTCB->ulNotifiedValue |= value;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase E_NOTIFY_ACTION_INCR\t:\n\t\t\t\t\t( pxTCB->ulNotifiedValue )++;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase E_NOTIFY_ACTION_OWRITE\t:\n\t\t\t\t\tpxTCB->ulNotifiedValue = value;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase E_NOTIFY_ACTION_NO_OWRITE :\n\t\t\t\t\tif( ucOriginalNotifyState != taskNOTIFICATION_RECEIVED )\n\t\t\t\t\t{\n\t\t\t\t\t\tpxTCB->ulNotifiedValue = value;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The value could not be written to the task. */\n\t\t\t\t\t\txReturn = pdFAIL;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase E_NOTIFY_ACTION_NONE :\n\t\t\t\t\t/* The task is being notified without its notify value being\n\t\t\t\t\tupdated. */\n\t\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\ttraceTASK_NOTIFY_FROM_ISR();\n\n\t\t\t/* If the task is in the blocked state specifically to wait for a\n\t\t\tnotification then unblock it now. */\n\t\t\tif( ucOriginalNotifyState == taskWAITING_NOTIFICATION )\n\t\t\t{\n\t\t\t\t/* The task should not have been on an event list. */\n\t\t\t\tconfigASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );\n\n\t\t\t\tif( uxSchedulerSuspended == ( uint32_t ) pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t( void ) uxListRemove( &( pxTCB->xStateListItem ) );\n\t\t\t\t\tprvAddTaskToReadyList( pxTCB );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* The delayed and ready lists cannot be accessed, so hold\n\t\t\t\t\tthis task pending until the scheduler is resumed. */\n\t\t\t\t\tvListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\n\t\t\t\t}\n\n\t\t\t\tif( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\n\t\t\t\t{\n\t\t\t\t\t/* The notified task has a priority above the currently\n\t\t\t\t\texecuting task so a yield is required. */\n\t\t\t\t\tif( pxHigherPriorityTaskWoken != NULL )\n\t\t\t\t\t{\n\t\t\t\t\t\t*pxHigherPriorityTaskWoken = pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t/* Mark that a yield is pending in case the user is not\n\t\t\t\t\t\tusing the \"xHigherPriorityTaskWoken\" parameter to an ISR\n\t\t\t\t\t\tsafe FreeRTOS function. */\n\t\t\t\t\t\txYieldPending = pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_TASK_NOTIFICATIONS */\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TASK_NOTIFICATIONS == 1 )\n\n\tvoid vTaskNotifyGiveFromISR( task_t task, int32_t *pxHigherPriorityTaskWoken )\n\t{\n\tTCB_t * pxTCB;\n\tuint8_t ucOriginalNotifyState;\n\tuint32_t uxSavedInterruptStatus;\n\n\t\tconfigASSERT( task );\n\n\t\t/* RTOS ports that support interrupt nesting have the concept of a\n\t\tmaximum\tsystem call (or maximum API call) interrupt priority.\n\t\tInterrupts that are\tabove the maximum system call priority are keep\n\t\tpermanently enabled, even when the RTOS kernel is in a critical section,\n\t\tbut cannot make any calls to FreeRTOS API functions.  If configASSERT()\n\t\tis defined in FreeRTOSConfig.h then\n\t\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\n\t\tfailure if a FreeRTOS API function is called from an interrupt that has\n\t\tbeen assigned a priority above the configured maximum system call\n\t\tpriority.  Only FreeRTOS functions that end in FromISR can be called\n\t\tfrom interrupts\tthat have been assigned a priority at or (logically)\n\t\tbelow the maximum system call interrupt priority.  FreeRTOS maintains a\n\t\tseparate interrupt safe API to ensure interrupt entry is as fast and as\n\t\tsimple as possible.  More information (albeit Cortex-M specific) is\n\t\tprovided on the following link:\n\t\thttp://www.freertos.org/RTOS-Cortex-M3-M4.html */\n\t\tportASSERT_IF_INTERRUPT_PRIORITY_INVALID();\n\n\t\tpxTCB = ( TCB_t * ) task;\n\n\t\tuxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\n\t\t{\n\t\t\tucOriginalNotifyState = pxTCB->ucNotifyState;\n\t\t\tpxTCB->ucNotifyState = taskNOTIFICATION_RECEIVED;\n\n\t\t\t/* 'Giving' is equivalent to incrementing a count in a counting\n\t\t\tsemaphore. */\n\t\t\t( pxTCB->ulNotifiedValue )++;\n\n\t\t\ttraceTASK_NOTIFY_GIVE_FROM_ISR();\n\n\t\t\t/* If the task is in the blocked state specifically to wait for a\n\t\t\tnotification then unblock it now. */\n\t\t\tif( ucOriginalNotifyState == taskWAITING_NOTIFICATION )\n\t\t\t{\n\t\t\t\t/* The task should not have been on an event list. */\n\t\t\t\tconfigASSERT( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL );\n\n\t\t\t\tif( uxSchedulerSuspended == ( uint32_t ) pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t( void ) uxListRemove( &( pxTCB->xStateListItem ) );\n\t\t\t\t\tprvAddTaskToReadyList( pxTCB );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t/* The delayed and ready lists cannot be accessed, so hold\n\t\t\t\t\tthis task pending until the scheduler is resumed. */\n\t\t\t\t\tvListInsertEnd( &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\n\t\t\t\t}\n\n\t\t\t\tif( pxTCB->uxPriority > pxCurrentTCB->uxPriority )\n\t\t\t\t{\n\t\t\t\t\t/* The notified task has a priority above the currently\n\t\t\t\t\texecuting task so a yield is required. */\n\t\t\t\t\tif( pxHigherPriorityTaskWoken != NULL )\n\t\t\t\t\t{\n\t\t\t\t\t\t*pxHigherPriorityTaskWoken = pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t/* Mark that a yield is pending in case the user is not\n\t\t\t\t\t\tusing the \"xHigherPriorityTaskWoken\" parameter in an ISR\n\t\t\t\t\t\tsafe FreeRTOS function. */\n\t\t\t\t\t\txYieldPending = pdTRUE;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tportCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\n\t}\n\n#endif /* configUSE_TASK_NOTIFICATIONS */\n\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TASK_NOTIFICATIONS == 1 )\n\n\tint32_t task_notify_clear(task_t task)\n\t{\n\tTCB_t *pxTCB;\n\tint32_t xReturn;\n\n\t\t/* If null is passed in here then it is the calling task that is having\n\t\tits notification state cleared. */\n\t\tpxTCB = prvGetTCBFromHandle( task );\n\n\t\ttaskENTER_CRITICAL();\n\t\t{\n\t\t\tif( pxTCB->ucNotifyState == taskNOTIFICATION_RECEIVED )\n\t\t\t{\n\t\t\t\tpxTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\n\t\t\t\txReturn = pdPASS;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\txReturn = pdFAIL;\n\t\t\t}\n\t\t}\n\t\ttaskEXIT_CRITICAL();\n\n\t\treturn xReturn;\n\t}\n\n#endif /* configUSE_TASK_NOTIFICATIONS */\n/*-----------------------------------------------------------*/\n\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TASK_NOTIFICATIONS == 1 )\n\n\tint32_t task_notify(task_t task) {\n\t        return task_notify_ext((task), (0), E_NOTIFY_ACTION_INCR, NULL);\n\t}\n\n#endif /* configUSE_TASK_NOTIFICATIONS */\n/*-----------------------------------------------------------*/\n\n/*-----------------------------------------------------------*/\n\n#if( configUSE_TASK_NOTIFICATIONS == 1 )\n\n\tvoid task_join(task_t task) {\n\t\tif(!task) return;\n\t\tTaskStatus_t xTaskDetails;\n\t\textern void task_notify_when_deleting(task_t, task_t, uint32_t, notify_action_e_t);\n\t\ttask_notify_when_deleting(task, NULL, 1, E_NOTIFY_ACTION_INCR);\n\t\tdo\n\t\t{\n\t\t\tvTaskGetInfo(task, &xTaskDetails, pdTRUE, E_TASK_STATE_INVALID);\n\t\t} while (!task_notify_take(true, 20) && xTaskDetails.eCurrentState != E_TASK_STATE_DELETED);\n\t}\n\n#endif /* configUSE_TASK_NOTIFICATIONS */\n/*-----------------------------------------------------------*/\n\n/*-----------------------------------------------------------*/\n\nstatic void prvAddCurrentTaskToDelayedList( uint32_t timeout, const int32_t xCanBlockIndefinitely )\n{\nuint32_t xTimeToWake;\nconst uint32_t xConstTickCount = xTickCount;\n\n\t#if( INCLUDE_xTaskAbortDelay == 1 )\n\t{\n\t\t/* About to enter a delayed list, so ensure the ucDelayAborted flag is\n\t\treset to pdFALSE so it can be detected as having been set to pdTRUE\n\t\twhen the task leaves the Blocked state. */\n\t\tpxCurrentTCB->ucDelayAborted = pdFALSE;\n\t}\n\t#endif\n\n\t/* Remove the task from the ready list before adding it to the blocked list\n\tas the same list item is used for both lists. */\n\tif( uxListRemove( &( pxCurrentTCB->xStateListItem ) ) == ( uint32_t ) 0 )\n\t{\n\t\t/* The current task must be in a ready list, so there is no need to\n\t\tcheck, and the port reset macro can be called directly. */\n\t\tportRESET_READY_PRIORITY( pxCurrentTCB->uxPriority, uxTopReadyPriority );\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\t#if ( INCLUDE_vTaskSuspend == 1 )\n\t{\n\t\tif( ( timeout == portMAX_DELAY ) && ( xCanBlockIndefinitely != pdFALSE ) )\n\t\t{\n\t\t\t/* Add the task to the suspended task list instead of a delayed task\n\t\t\tlist to ensure it is not woken by a timing event.  It will block\n\t\t\tindefinitely. */\n\t\t\tvListInsertEnd( &xSuspendedTaskList, &( pxCurrentTCB->xStateListItem ) );\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* Calculate the time at which the task should be woken if the event\n\t\t\tdoes not occur.  This may overflow but this doesn't matter, the\n\t\t\tkernel will manage it correctly. */\n\t\t\txTimeToWake = xConstTickCount + timeout;\n\n\t\t\t/* The list item will be inserted in wake time order. */\n\t\t\tlistSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xStateListItem ), xTimeToWake );\n\n\t\t\tif( xTimeToWake < xConstTickCount )\n\t\t\t{\n\t\t\t\t/* Wake time has overflowed.  Place this item in the overflow\n\t\t\t\tlist. */\n\t\t\t\tvListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* The wake time has not overflowed, so the current block list\n\t\t\t\tis used. */\n\t\t\t\tvListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );\n\n\t\t\t\t/* If the task entering the blocked state was placed at the\n\t\t\t\thead of the list of blocked tasks then xNextTaskUnblockTime\n\t\t\t\tneeds to be updated too. */\n\t\t\t\tif( xTimeToWake < xNextTaskUnblockTime )\n\t\t\t\t{\n\t\t\t\t\txNextTaskUnblockTime = xTimeToWake;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t#else /* INCLUDE_vTaskSuspend */\n\t{\n\t\t/* Calculate the time at which the task should be woken if the event\n\t\tdoes not occur.  This may overflow but this doesn't matter, the kernel\n\t\twill manage it correctly. */\n\t\txTimeToWake = xConstTickCount + timeout;\n\n\t\t/* The list item will be inserted in wake time order. */\n\t\tlistSET_LIST_ITEM_VALUE( &( pxCurrentTCB->xStateListItem ), xTimeToWake );\n\n\t\tif( xTimeToWake < xConstTickCount )\n\t\t{\n\t\t\t/* Wake time has overflowed.  Place this item in the overflow list. */\n\t\t\tvListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );\n\t\t}\n\t\telse\n\t\t{\n\t\t\t/* The wake time has not overflowed, so the current block list is used. */\n\t\t\tvListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );\n\n\t\t\t/* If the task entering the blocked state was placed at the head of the\n\t\t\tlist of blocked tasks then xNextTaskUnblockTime needs to be updated\n\t\t\ttoo. */\n\t\t\tif( xTimeToWake < xNextTaskUnblockTime )\n\t\t\t{\n\t\t\t\txNextTaskUnblockTime = xTimeToWake;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\n\t\t/* Avoid compiler warning when INCLUDE_vTaskSuspend is not 1. */\n\t\t( void ) xCanBlockIndefinitely;\n\t}\n\t#endif /* INCLUDE_vTaskSuspend */\n}\n\n/* Code below here allows additional code to be inserted into this source file,\nespecially where access to file scope functions and data is needed (for example\nwhen performing module tests). */\n\n#ifdef FREERTOS_MODULE_TEST\n\t#include \"tasks_test_access_functions.h\"\n#endif\n\n\n#if( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 )\n\n\t#include \"freertos_tasks_c_additions.h\"\n\n\tstatic void freertos_tasks_c_additions_init( void )\n\t{\n\t\t#ifdef FREERTOS_TASKS_C_ADDITIONS_INIT\n\t\t\tFREERTOS_TASKS_C_ADDITIONS_INIT();\n\t\t#endif\n\t}\n\n#endif\n"
  },
  {
    "path": "src/rtos/timers.c",
    "content": "/*\n * FreeRTOS Kernel V10.0.1\n * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n * http://www.FreeRTOS.org\n * http://aws.amazon.com/freertos\n *\n * 1 tab == 4 spaces!\n */\n\n/* Standard includes. */\n#include <stdlib.h>\n\n/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining\nall the API functions to use the MPU wrappers.  That should only be done when\ntask.h is included from an application file. */\n#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE\n\n#include \"FreeRTOS.h\"\n#include \"task.h\"\n#include \"queue.h\"\n#include \"timers.h\"\n\n#if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 )\n\t#error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available.\n#endif\n\n/* Lint e961 and e750 are suppressed as a MISRA exception justified because the\nMPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined for the\nheader files above, but not in this file, in order to generate the correct\nprivileged Vs unprivileged linkage and placement. */\n#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750. */\n\n\n/* This entire source file will be skipped if the application is not configured\nto include software timer functionality.  This #if is closed at the very bottom\nof this file.  If you want to include software timer functionality then ensure\nconfigUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */\n#if ( configUSE_TIMERS == 1 )\n\n/* Misc definitions. */\n#define tmrNO_DELAY\t\t( uint32_t ) 0U\n\n/* The name assigned to the timer service task.  This can be overridden by\ndefining trmTIMER_SERVICE_TASK_NAME in FreeRTOSConfig.h. */\n#ifndef configTIMER_SERVICE_TASK_NAME\n\t#define configTIMER_SERVICE_TASK_NAME \"Tmr Svc\"\n#endif\n\n/* The definition of the timers themselves. */\ntypedef struct tmrTimerControl\n{\n\tconst char\t\t\t\t*pcTimerName;\t\t/*<< Text name.  This is not used by the kernel, it is included simply to make debugging easier. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\tlist_item_t\t\t\t\txTimerListItem;\t\t/*<< Standard linked list item as used by all kernel features for event management. */\n\tuint32_t\t\t\t\txTimerPeriodInTicks;/*<< How quickly and often the timer expires. */\n\tuint32_t\t\t\t\tuxAutoReload;\t\t/*<< Set to pdTRUE if the timer should be automatically restarted once expired.  Set to pdFALSE if the timer is, in effect, a one-shot timer. */\n\tvoid \t\t\t\t\t*pvTimerID;\t\t\t/*<< An ID to identify the timer.  This allows the timer to be identified when the same callback is used for multiple timers. */\n\tTimerCallbackFunction_t\tpxCallbackFunction;\t/*<< The function that will be called when the timer expires. */\n\t#if( configUSE_TRACE_FACILITY == 1 )\n\t\tuint32_t\t\t\tuxTimerNumber;\t\t/*<< An ID assigned by trace tools such as FreeRTOS+Trace */\n\t#endif\n\n\t#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\n\t\tuint8_t \t\t\tucStaticallyAllocated; /*<< Set to pdTRUE if the timer was created statically so no attempt is made to free the memory again if the timer is later deleted. */\n\t#endif\n} xTIMER;\n\n/* The old xTIMER name is maintained above then typedefed to the new Timer_t\nname below to enable the use of older kernel aware debuggers. */\ntypedef xTIMER Timer_t;\n\n/* The definition of messages that can be sent and received on the timer queue.\nTwo types of message can be queued - messages that manipulate a software timer,\nand messages that request the execution of a non-timer related callback.  The\ntwo message types are defined in two separate structures, xTimerParametersType\nand xCallbackParametersType respectively. */\ntypedef struct tmrTimerParameters\n{\n\tuint32_t\t\t\txMessageValue;\t\t/*<< An optional value used by a subset of commands, for example, when changing the period of a timer. */\n\tTimer_t *\t\t\tpxTimer;\t\t\t/*<< The timer to which the command will be applied. */\n} TimerParameter_t;\n\n\ntypedef struct tmrCallbackParameters\n{\n\tPendedFunction_t\tpxCallbackFunction;\t/* << The callback function to execute. */\n\tvoid *pvParameter1;\t\t\t\t\t\t/* << The value that will be used as the callback functions first parameter. */\n\tuint32_t ulParameter2;\t\t\t\t\t/* << The value that will be used as the callback functions second parameter. */\n} CallbackParameters_t;\n\n/* The structure that contains the two message types, along with an identifier\nthat is used to determine which message type is valid. */\ntypedef struct tmrTimerQueueMessage\n{\n\tint32_t\t\t\txMessageID;\t\t\t/*<< The command being sent to the timer service task. */\n\tunion\n\t{\n\t\tTimerParameter_t xTimerParameters;\n\n\t\t/* Don't include xCallbackParameters if it is not going to be used as\n\t\tit makes the structure (and therefore the timer queue) larger. */\n\t\t#if ( INCLUDE_xTimerPendFunctionCall == 1 )\n\t\t\tCallbackParameters_t xCallbackParameters;\n\t\t#endif /* INCLUDE_xTimerPendFunctionCall */\n\t} u;\n} DaemonTaskMessage_t;\n\n/*lint -save -e956 A manual analysis and inspection has been used to determine\nwhich static variables must be declared volatile. */\n\n/* The list in which active timers are stored.  Timers are referenced in expire\ntime order, with the nearest expiry time at the front of the list.  Only the\ntimer service task is allowed to access these lists. */\nstatic List_t xActiveTimerList1;\nstatic List_t xActiveTimerList2;\nstatic List_t *pxCurrentTimerList;\nstatic List_t *pxOverflowTimerList;\n\n/* A queue that is used to send commands to the timer service task. */\nstatic queue_t xTimerQueue = NULL;\nstatic task_t xTimerTaskHandle = NULL;\n\n/*lint -restore */\n\n/*-----------------------------------------------------------*/\n\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\n\t/* If static allocation is supported then the application must provide the\n\tfollowing callback function - which enables the application to optionally\n\tprovide the memory that will be used by the timer task as the task's stack\n\tand TCB. */\n\textern void vApplicationGetTimerTaskMemory( static_task_s_t **ppxTimerTaskTCBBuffer, task_stack_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize );\n\n#endif\n\n/*\n * Initialise the infrastructure used by the timer service task if it has not\n * been initialised already.\n */\nstatic void prvCheckForValidListAndQueue( void ) ;\n\n/*\n * The timer service task (daemon).  Timer functionality is controlled by this\n * task.  Other tasks communicate with the timer service task using the\n * xTimerQueue queue.\n */\nstatic void prvTimerTask( void *pvParameters ) ;\n\n/*\n * Called by the timer service task to interpret and process a command it\n * received on the timer queue.\n */\nstatic void prvProcessReceivedCommands( void ) ;\n\n/*\n * Insert the timer into either xActiveTimerList1, or xActiveTimerList2,\n * depending on if the expire time causes a timer counter overflow.\n */\nstatic int32_t prvInsertTimerInActiveList( Timer_t * const pxTimer, const uint32_t xNextExpiryTime, const uint32_t xTimeNow, const uint32_t xCommandTime ) ;\n\n/*\n * An active timer has reached its expire time.  Reload the timer if it is an\n * auto reload timer, then call its callback.\n */\nstatic void prvProcessExpiredTimer( const uint32_t xNextExpireTime, const uint32_t xTimeNow ) ;\n\n/*\n * The tick count has overflowed.  Switch the timer lists after ensuring the\n * current timer list does not still reference some timers.\n */\nstatic void prvSwitchTimerLists( void ) ;\n\n/*\n * Obtain the current tick count, setting *pxTimerListsWereSwitched to pdTRUE\n * if a tick count overflow occurred since prvSampleTimeNow() was last called.\n */\nstatic uint32_t prvSampleTimeNow( int32_t * const pxTimerListsWereSwitched ) ;\n\n/*\n * If the timer list contains any active timers then return the expire time of\n * the timer that will expire first and set *pxListWasEmpty to false.  If the\n * timer list does not contain any timers then return 0 and set *pxListWasEmpty\n * to pdTRUE.\n */\nstatic uint32_t prvGetNextExpireTime( int32_t * const pxListWasEmpty ) ;\n\n/*\n * If a timer has expired, process it.  Otherwise, block the timer service task\n * until either a timer does expire or a command is received.\n */\nstatic void prvProcessTimerOrBlockTask( const uint32_t xNextExpireTime, int32_t xListWasEmpty ) ;\n\n/*\n * Called after a Timer_t structure has been allocated either statically or\n * dynamically to fill in the structure's members.\n */\nstatic void prvInitialiseNewTimer(\tconst char * const pcTimerName,\t\t\t/*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t\t\t\t\t\t\t\t\tconst uint32_t xTimerPeriodInTicks,\n\t\t\t\t\t\t\t\t\tconst uint32_t uxAutoReload,\n\t\t\t\t\t\t\t\t\tvoid * const pvTimerID,\n\t\t\t\t\t\t\t\t\tTimerCallbackFunction_t pxCallbackFunction,\n\t\t\t\t\t\t\t\t\tTimer_t *pxNewTimer ) ;\n/*-----------------------------------------------------------*/\n\nint32_t xTimerCreateTimerTask( void )\n{\nint32_t xReturn = pdFAIL;\n\n\t/* This function is called when the scheduler is started if\n\tconfigUSE_TIMERS is set to 1.  Check that the infrastructure used by the\n\ttimer service task has been created/initialised.  If timers have already\n\tbeen created then the initialisation will already have been performed. */\n\tprvCheckForValidListAndQueue();\n\n\tif( xTimerQueue != NULL )\n\t{\n\t\t#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\t\t{\n\t\t\tstatic_task_s_t *pxTimerTaskTCBBuffer = NULL;\n\t\t\ttask_stack_t *pxTimerTaskStackBuffer = NULL;\n\t\t\tuint32_t ulTimerTaskStackSize;\n\n\t\t\tvApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize );\n\t\t\txTimerTaskHandle = task_create_static(\tprvTimerTask,\n\t\t\t\t\t\t\t\t\t\t\t\t\tNULL,\n\t\t\t\t\t\t\t\t\t\t\t\t\t( ( uint32_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,\n\t\t\t\t\t\t\t\t\t\t\t\t\tulTimerTaskStackSize,\n\t\t\t\t\t\t\t\t\t\t\t\t\tconfigTIMER_SERVICE_TASK_NAME,\n\t\t\t\t\t\t\t\t\t\t\t\t\tpxTimerTaskStackBuffer,\n\t\t\t\t\t\t\t\t\t\t\t\t\tpxTimerTaskTCBBuffer );\n\n\t\t\tif( xTimerTaskHandle != NULL )\n\t\t\t{\n\t\t\t\txReturn = pdPASS;\n\t\t\t}\n\t\t}\n\t\t#else\n\t\t{\n\t\t\txReturn = task_create(\tprvTimerTask,\n\t\t\t\t\t\t\t\t\tconfigTIMER_SERVICE_TASK_NAME,\n\t\t\t\t\t\t\t\t\tconfigTIMER_TASK_STACK_DEPTH,\n\t\t\t\t\t\t\t\t\tNULL,\n\t\t\t\t\t\t\t\t\t( ( uint32_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,\n\t\t\t\t\t\t\t\t\t&xTimerTaskHandle );\n\t\t}\n\t\t#endif /* configSUPPORT_STATIC_ALLOCATION */\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\tconfigASSERT( xReturn );\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\n#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\n\tTimerHandle_t xTimerCreate(\tconst char * const pcTimerName,\t\t\t/*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t\t\t\t\t\t\t\tconst uint32_t xTimerPeriodInTicks,\n\t\t\t\t\t\t\t\tconst uint32_t uxAutoReload,\n\t\t\t\t\t\t\t\tvoid * const pvTimerID,\n\t\t\t\t\t\t\t\tTimerCallbackFunction_t pxCallbackFunction )\n\t{\n\tTimer_t *pxNewTimer;\n\n\t\tpxNewTimer = ( Timer_t * ) kmalloc( sizeof( Timer_t ) );\n\n\t\tif( pxNewTimer != NULL )\n\t\t{\n\t\t\tprvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );\n\n\t\t\t#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\t\t\t{\n\t\t\t\t/* Timers can be created statically or dynamically, so note this\n\t\t\t\ttimer was created dynamically in case the timer is later\n\t\t\t\tdeleted. */\n\t\t\t\tpxNewTimer->ucStaticallyAllocated = pdFALSE;\n\t\t\t}\n\t\t\t#endif /* configSUPPORT_STATIC_ALLOCATION */\n\t\t}\n\n\t\treturn pxNewTimer;\n\t}\n\n#endif /* configSUPPORT_STATIC_ALLOCATION */\n/*-----------------------------------------------------------*/\n\n#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\n\tTimerHandle_t xTimerCreateStatic(\tconst char * const pcTimerName,\t\t/*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t\t\t\t\t\t\t\t\t\tconst uint32_t xTimerPeriodInTicks,\n\t\t\t\t\t\t\t\t\t\tconst uint32_t uxAutoReload,\n\t\t\t\t\t\t\t\t\t\tvoid * const pvTimerID,\n\t\t\t\t\t\t\t\t\t\tTimerCallbackFunction_t pxCallbackFunction,\n\t\t\t\t\t\t\t\t\t\tStaticTimer_t *pxTimerBuffer )\n\t{\n\tTimer_t *pxNewTimer;\n\n\t\t#if( configASSERT_DEFINED == 1 )\n\t\t{\n\t\t\t/* Sanity check that the size of the structure used to declare a\n\t\t\tvariable of type StaticTimer_t equals the size of the real timer\n\t\t\tstructure. */\n\t\t\tvolatile size_t xSize = sizeof( StaticTimer_t );\n\t\t\tconfigASSERT( xSize == sizeof( Timer_t ) );\n\t\t}\n\t\t#endif /* configASSERT_DEFINED */\n\n\t\t/* A pointer to a StaticTimer_t structure MUST be provided, use it. */\n\t\tconfigASSERT( pxTimerBuffer );\n\t\tpxNewTimer = ( Timer_t * ) pxTimerBuffer; /*lint !e740 Unusual cast is ok as the structures are designed to have the same alignment, and the size is checked by an assert. */\n\n\t\tif( pxNewTimer != NULL )\n\t\t{\n\t\t\tprvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );\n\n\t\t\t#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\n\t\t\t{\n\t\t\t\t/* Timers can be created statically or dynamically so note this\n\t\t\t\ttimer was created statically in case it is later deleted. */\n\t\t\t\tpxNewTimer->ucStaticallyAllocated = pdTRUE;\n\t\t\t}\n\t\t\t#endif /* configSUPPORT_DYNAMIC_ALLOCATION */\n\t\t}\n\n\t\treturn pxNewTimer;\n\t}\n\n#endif /* configSUPPORT_STATIC_ALLOCATION */\n/*-----------------------------------------------------------*/\n\nstatic void prvInitialiseNewTimer(\tconst char * const pcTimerName,\t\t\t/*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n\t\t\t\t\t\t\t\t\tconst uint32_t xTimerPeriodInTicks,\n\t\t\t\t\t\t\t\t\tconst uint32_t uxAutoReload,\n\t\t\t\t\t\t\t\t\tvoid * const pvTimerID,\n\t\t\t\t\t\t\t\t\tTimerCallbackFunction_t pxCallbackFunction,\n\t\t\t\t\t\t\t\t\tTimer_t *pxNewTimer )\n{\n\t/* 0 is not a valid value for xTimerPeriodInTicks. */\n\tconfigASSERT( ( xTimerPeriodInTicks > 0 ) );\n\n\tif( pxNewTimer != NULL )\n\t{\n\t\t/* Ensure the infrastructure used by the timer service task has been\n\t\tcreated/initialised. */\n\t\tprvCheckForValidListAndQueue();\n\n\t\t/* Initialise the timer structure members using the function\n\t\tparameters. */\n\t\tpxNewTimer->pcTimerName = pcTimerName;\n\t\tpxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks;\n\t\tpxNewTimer->uxAutoReload = uxAutoReload;\n\t\tpxNewTimer->pvTimerID = pvTimerID;\n\t\tpxNewTimer->pxCallbackFunction = pxCallbackFunction;\n\t\tvListInitialiseItem( &( pxNewTimer->xTimerListItem ) );\n\t\ttraceTIMER_CREATE( pxNewTimer );\n\t}\n}\n/*-----------------------------------------------------------*/\n\nint32_t xTimerGenericCommand( TimerHandle_t xTimer, const int32_t xCommandID, const uint32_t xOptionalValue, int32_t * const pxHigherPriorityTaskWoken, const uint32_t xTicksToWait )\n{\nint32_t xReturn = pdFAIL;\nDaemonTaskMessage_t xMessage;\n\n\tconfigASSERT( xTimer );\n\n\t/* Send a message to the timer service task to perform a particular action\n\ton a particular timer definition. */\n\tif( xTimerQueue != NULL )\n\t{\n\t\t/* Send a command to the timer service task to start the xTimer timer. */\n\t\txMessage.xMessageID = xCommandID;\n\t\txMessage.u.xTimerParameters.xMessageValue = xOptionalValue;\n\t\txMessage.u.xTimerParameters.pxTimer = ( Timer_t * ) xTimer;\n\n\t\tif( xCommandID < tmrFIRST_FROM_ISR_COMMAND )\n\t\t{\n\t\t\tif( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )\n\t\t\t{\n\t\t\t\txReturn = queue_append( xTimerQueue, &xMessage, xTicksToWait );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\txReturn = queue_append( xTimerQueue, &xMessage, tmrNO_DELAY );\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\txReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );\n\t\t}\n\n\t\ttraceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn );\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\ntask_t xTimerGetTimerDaemonTaskHandle( void )\n{\n\t/* If xTimerGetTimerDaemonTaskHandle() is called before the scheduler has been\n\tstarted, then xTimerTaskHandle will be NULL. */\n\tconfigASSERT( ( xTimerTaskHandle != NULL ) );\n\treturn xTimerTaskHandle;\n}\n/*-----------------------------------------------------------*/\n\nuint32_t xTimerGetPeriod( TimerHandle_t xTimer )\n{\nTimer_t *pxTimer = ( Timer_t * ) xTimer;\n\n\tconfigASSERT( xTimer );\n\treturn pxTimer->xTimerPeriodInTicks;\n}\n/*-----------------------------------------------------------*/\n\nuint32_t xTimerGetExpiryTime( TimerHandle_t xTimer )\n{\nTimer_t * pxTimer = ( Timer_t * ) xTimer;\nuint32_t xReturn;\n\n\tconfigASSERT( xTimer );\n\txReturn = listGET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ) );\n\treturn xReturn;\n}\n/*-----------------------------------------------------------*/\n\nconst char * pcTimerGetName( TimerHandle_t xTimer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\n{\nTimer_t *pxTimer = ( Timer_t * ) xTimer;\n\n\tconfigASSERT( xTimer );\n\treturn pxTimer->pcTimerName;\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvProcessExpiredTimer( const uint32_t xNextExpireTime, const uint32_t xTimeNow )\n{\nint32_t xResult;\nTimer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );\n\n\t/* Remove the timer from the list of active timers.  A check has already\n\tbeen performed to ensure the list is not empty. */\n\t( void ) uxListRemove( &( pxTimer->xTimerListItem ) );\n\ttraceTIMER_EXPIRED( pxTimer );\n\n\t/* If the timer is an auto reload timer then calculate the next\n\texpiry time and re-insert the timer in the list of active timers. */\n\tif( pxTimer->uxAutoReload == ( uint32_t ) pdTRUE )\n\t{\n\t\t/* The timer is inserted into a list using a time relative to anything\n\t\tother than the current time.  It will therefore be inserted into the\n\t\tcorrect list relative to the time this task thinks it is now. */\n\t\tif( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) != pdFALSE )\n\t\t{\n\t\t\t/* The timer expired before it was added to the active timer\n\t\t\tlist.  Reload it now.  */\n\t\t\txResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY );\n\t\t\tconfigASSERT( xResult );\n\t\t\t( void ) xResult;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\telse\n\t{\n\t\tmtCOVERAGE_TEST_MARKER();\n\t}\n\n\t/* Call the timer callback. */\n\tpxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvTimerTask( void *pvParameters )\n{\nuint32_t xNextExpireTime;\nint32_t xListWasEmpty;\n\n\t/* Just to avoid compiler warnings. */\n\t( void ) pvParameters;\n\n\t#if( configUSE_DAEMON_TASK_STARTUP_HOOK == 1 )\n\t{\n\t\textern void vApplicationDaemonTaskStartupHook( void );\n\n\t\t/* Allow the application writer to execute some code in the context of\n\t\tthis task at the point the task starts executing.  This is useful if the\n\t\tapplication includes initialisation code that would benefit from\n\t\texecuting after the scheduler has been started. */\n\t\tvApplicationDaemonTaskStartupHook();\n\t}\n\t#endif /* configUSE_DAEMON_TASK_STARTUP_HOOK */\n\n\tfor( ;; )\n\t{\n\t\t/* Query the timers list to see if it contains any timers, and if so,\n\t\tobtain the time at which the next timer will expire. */\n\t\txNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );\n\n\t\t/* If a timer has expired, process it.  Otherwise, block this task\n\t\tuntil either a timer does expire, or a command is received. */\n\t\tprvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );\n\n\t\t/* Empty the command queue. */\n\t\tprvProcessReceivedCommands();\n\t}\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvProcessTimerOrBlockTask( const uint32_t xNextExpireTime, int32_t xListWasEmpty )\n{\nuint32_t xTimeNow;\nint32_t xTimerListsWereSwitched;\n\n\trtos_suspend_all();\n\t{\n\t\t/* Obtain the time now to make an assessment as to whether the timer\n\t\thas expired or not.  If obtaining the time causes the lists to switch\n\t\tthen don't process this timer as any timers that remained in the list\n\t\twhen the lists were switched will have been processed within the\n\t\tprvSampleTimeNow() function. */\n\t\txTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );\n\t\tif( xTimerListsWereSwitched == pdFALSE )\n\t\t{\n\t\t\t/* The tick count has not overflowed, has the timer expired? */\n\t\t\tif( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )\n\t\t\t{\n\t\t\t\t( void ) rtos_resume_all();\n\t\t\t\tprvProcessExpiredTimer( xNextExpireTime, xTimeNow );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t/* The tick count has not overflowed, and the next expire\n\t\t\t\ttime has not been reached yet.  This task should therefore\n\t\t\t\tblock to wait for the next expire time or a command to be\n\t\t\t\treceived - whichever comes first.  The following line cannot\n\t\t\t\tbe reached unless xNextExpireTime > xTimeNow, except in the\n\t\t\t\tcase when the current timer list is empty. */\n\t\t\t\tif( xListWasEmpty != pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t/* The current timer list is empty - is the overflow list\n\t\t\t\t\talso empty? */\n\t\t\t\t\txListWasEmpty = listLIST_IS_EMPTY( pxOverflowTimerList );\n\t\t\t\t}\n\n\t\t\t\tvQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ), xListWasEmpty );\n\n\t\t\t\tif( rtos_resume_all() == pdFALSE )\n\t\t\t\t{\n\t\t\t\t\t/* Yield to wait for either a command to arrive, or the\n\t\t\t\t\tblock time to expire.  If a command arrived between the\n\t\t\t\t\tcritical section being exited and this yield then the yield\n\t\t\t\t\twill not cause the task to block. */\n\t\t\t\t\tportYIELD_WITHIN_API();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t( void ) rtos_resume_all();\n\t\t}\n\t}\n}\n/*-----------------------------------------------------------*/\n\nstatic uint32_t prvGetNextExpireTime( int32_t * const pxListWasEmpty )\n{\nuint32_t xNextExpireTime;\n\n\t/* Timers are listed in expiry time order, with the head of the list\n\treferencing the task that will expire first.  Obtain the time at which\n\tthe timer with the nearest expiry time will expire.  If there are no\n\tactive timers then just set the next expire time to 0.  That will cause\n\tthis task to unblock when the tick count overflows, at which point the\n\ttimer lists will be switched and the next expiry time can be\n\tre-assessed.  */\n\t*pxListWasEmpty = listLIST_IS_EMPTY( pxCurrentTimerList );\n\tif( *pxListWasEmpty == pdFALSE )\n\t{\n\t\txNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );\n\t}\n\telse\n\t{\n\t\t/* Ensure the task unblocks when the tick count rolls over. */\n\t\txNextExpireTime = ( uint32_t ) 0U;\n\t}\n\n\treturn xNextExpireTime;\n}\n/*-----------------------------------------------------------*/\n\nstatic uint32_t prvSampleTimeNow( int32_t * const pxTimerListsWereSwitched )\n{\nuint32_t xTimeNow;\nstatic uint32_t xLastTime = ( uint32_t ) 0U; /*lint !e956 Variable is only accessible to one task. */\n\n\txTimeNow = millis();\n\n\tif( xTimeNow < xLastTime )\n\t{\n\t\tprvSwitchTimerLists();\n\t\t*pxTimerListsWereSwitched = pdTRUE;\n\t}\n\telse\n\t{\n\t\t*pxTimerListsWereSwitched = pdFALSE;\n\t}\n\n\txLastTime = xTimeNow;\n\n\treturn xTimeNow;\n}\n/*-----------------------------------------------------------*/\n\nstatic int32_t prvInsertTimerInActiveList( Timer_t * const pxTimer, const uint32_t xNextExpiryTime, const uint32_t xTimeNow, const uint32_t xCommandTime )\n{\nint32_t xProcessTimerNow = pdFALSE;\n\n\tlistSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xNextExpiryTime );\n\tlistSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );\n\n\tif( xNextExpiryTime <= xTimeNow )\n\t{\n\t\t/* Has the expiry time elapsed between the command to start/reset a\n\t\ttimer was issued, and the time the command was processed? */\n\t\tif( ( ( uint32_t ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks ) /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\n\t\t{\n\t\t\t/* The time between a command being issued and the command being\n\t\t\tprocessed actually exceeds the timers period.  */\n\t\t\txProcessTimerNow = pdTRUE;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tvListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) );\n\t\t}\n\t}\n\telse\n\t{\n\t\tif( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) )\n\t\t{\n\t\t\t/* If, since the command was issued, the tick count has overflowed\n\t\t\tbut the expiry time has not, then the timer must have already passed\n\t\t\tits expiry time and should be processed immediately. */\n\t\t\txProcessTimerNow = pdTRUE;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tvListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );\n\t\t}\n\t}\n\n\treturn xProcessTimerNow;\n}\n/*-----------------------------------------------------------*/\n\nstatic void\tprvProcessReceivedCommands( void )\n{\nDaemonTaskMessage_t xMessage;\nTimer_t *pxTimer;\nint32_t xTimerListsWereSwitched, xResult;\nuint32_t xTimeNow;\n\n\twhile( queue_recv( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) /*lint !e603 xMessage does not have to be initialised as it is passed out, not in, and it is not used unless queue_recv() returns pdTRUE. */\n\t{\n\t\t#if ( INCLUDE_xTimerPendFunctionCall == 1 )\n\t\t{\n\t\t\t/* Negative commands are pended function calls rather than timer\n\t\t\tcommands. */\n\t\t\tif( xMessage.xMessageID < ( int32_t ) 0 )\n\t\t\t{\n\t\t\t\tconst CallbackParameters_t * const pxCallback = &( xMessage.u.xCallbackParameters );\n\n\t\t\t\t/* The timer uses the xCallbackParameters member to request a\n\t\t\t\tcallback be executed.  Check the callback is not NULL. */\n\t\t\t\tconfigASSERT( pxCallback );\n\n\t\t\t\t/* Call the function. */\n\t\t\t\tpxCallback->pxCallbackFunction( pxCallback->pvParameter1, pxCallback->ulParameter2 );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\t\t}\n\t\t#endif /* INCLUDE_xTimerPendFunctionCall */\n\n\t\t/* Commands that are positive are timer commands rather than pended\n\t\tfunction calls. */\n\t\tif( xMessage.xMessageID >= ( int32_t ) 0 )\n\t\t{\n\t\t\t/* The messages uses the xTimerParameters member to work on a\n\t\t\tsoftware timer. */\n\t\t\tpxTimer = xMessage.u.xTimerParameters.pxTimer;\n\n\t\t\tif( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) /*lint !e961. The cast is only redundant when NULL is passed into the macro. */\n\t\t\t{\n\t\t\t\t/* The timer is in a list, remove it. */\n\t\t\t\t( void ) uxListRemove( &( pxTimer->xTimerListItem ) );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t}\n\n\t\t\ttraceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.u.xTimerParameters.xMessageValue );\n\n\t\t\t/* In this case the xTimerListsWereSwitched parameter is not used, but\n\t\t\tit must be present in the function call.  prvSampleTimeNow() must be\n\t\t\tcalled after the message is received from xTimerQueue so there is no\n\t\t\tpossibility of a higher priority task adding a message to the message\n\t\t\tqueue with a time that is ahead of the timer daemon task (because it\n\t\t\tpre-empted the timer daemon task after the xTimeNow value was set). */\n\t\t\txTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );\n\n\t\t\tswitch( xMessage.xMessageID )\n\t\t\t{\n\t\t\t\tcase tmrCOMMAND_START :\n\t\t\t    case tmrCOMMAND_START_FROM_ISR :\n\t\t\t    case tmrCOMMAND_RESET :\n\t\t\t    case tmrCOMMAND_RESET_FROM_ISR :\n\t\t\t\tcase tmrCOMMAND_START_DONT_TRACE :\n\t\t\t\t\t/* Start or restart a timer. */\n\t\t\t\t\tif( prvInsertTimerInActiveList( pxTimer,  xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The timer expired before it was added to the active\n\t\t\t\t\t\ttimer list.  Process it now. */\n\t\t\t\t\t\tpxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );\n\t\t\t\t\t\ttraceTIMER_EXPIRED( pxTimer );\n\n\t\t\t\t\t\tif( pxTimer->uxAutoReload == ( uint32_t ) pdTRUE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\txResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY );\n\t\t\t\t\t\t\tconfigASSERT( xResult );\n\t\t\t\t\t\t\t( void ) xResult;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase tmrCOMMAND_STOP :\n\t\t\t\tcase tmrCOMMAND_STOP_FROM_ISR :\n\t\t\t\t\t/* The timer has already been removed from the active list.\n\t\t\t\t\tThere is nothing to do here. */\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase tmrCOMMAND_CHANGE_PERIOD :\n\t\t\t\tcase tmrCOMMAND_CHANGE_PERIOD_FROM_ISR :\n\t\t\t\t\tpxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue;\n\t\t\t\t\tconfigASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) );\n\n\t\t\t\t\t/* The new period does not really have a reference, and can\n\t\t\t\t\tbe longer or shorter than the old one.  The command time is\n\t\t\t\t\ttherefore set to the current time, and as the period cannot\n\t\t\t\t\tbe zero the next expiry time can only be in the future,\n\t\t\t\t\tmeaning (unlike for the xTimerStart() case above) there is\n\t\t\t\t\tno fail case that needs to be handled here. */\n\t\t\t\t\t( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow );\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase tmrCOMMAND_DELETE :\n\t\t\t\t\t/* The timer has already been removed from the active list,\n\t\t\t\t\tjust free up the memory if the memory was dynamically\n\t\t\t\t\tallocated. */\n\t\t\t\t\t#if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The timer can only have been allocated dynamically -\n\t\t\t\t\t\tfree it again. */\n\t\t\t\t\t\tkfree( pxTimer );\n\t\t\t\t\t}\n\t\t\t\t\t#elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\n\t\t\t\t\t{\n\t\t\t\t\t\t/* The timer could have been allocated statically or\n\t\t\t\t\t\tdynamically, so check before attempting to free the\n\t\t\t\t\t\tmemory. */\n\t\t\t\t\t\tif( pxTimer->ucStaticallyAllocated == ( uint8_t ) pdFALSE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tkfree( pxTimer );\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t#endif /* configSUPPORT_DYNAMIC_ALLOCATION */\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault\t:\n\t\t\t\t\t/* Don't expect to get here. */\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvSwitchTimerLists( void )\n{\nuint32_t xNextExpireTime, xReloadTime;\nList_t *pxTemp;\nTimer_t *pxTimer;\nint32_t xResult;\n\n\t/* The tick count has overflowed.  The timer lists must be switched.\n\tIf there are any timers still referenced from the current timer list\n\tthen they must have expired and should be processed before the lists\n\tare switched. */\n\twhile( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE )\n\t{\n\t\txNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );\n\n\t\t/* Remove the timer from the list. */\n\t\tpxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList );\n\t\t( void ) uxListRemove( &( pxTimer->xTimerListItem ) );\n\t\ttraceTIMER_EXPIRED( pxTimer );\n\n\t\t/* Execute its callback, then send a command to restart the timer if\n\t\tit is an auto-reload timer.  It cannot be restarted here as the lists\n\t\thave not yet been switched. */\n\t\tpxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );\n\n\t\tif( pxTimer->uxAutoReload == ( uint32_t ) pdTRUE )\n\t\t{\n\t\t\t/* Calculate the reload value, and if the reload value results in\n\t\t\tthe timer going into the same timer list then it has already expired\n\t\t\tand the timer should be re-inserted into the current list so it is\n\t\t\tprocessed again within this loop.  Otherwise a command should be sent\n\t\t\tto restart the timer to ensure it is only inserted into a list after\n\t\t\tthe lists have been swapped. */\n\t\t\txReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks );\n\t\t\tif( xReloadTime > xNextExpireTime )\n\t\t\t{\n\t\t\t\tlistSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xReloadTime );\n\t\t\t\tlistSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );\n\t\t\t\tvListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\txResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY );\n\t\t\t\tconfigASSERT( xResult );\n\t\t\t\t( void ) xResult;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\n\tpxTemp = pxCurrentTimerList;\n\tpxCurrentTimerList = pxOverflowTimerList;\n\tpxOverflowTimerList = pxTemp;\n}\n/*-----------------------------------------------------------*/\n\nstatic void prvCheckForValidListAndQueue( void )\n{\n\t/* Check that the list from which active timers are referenced, and the\n\tqueue used to communicate with the timer service, have been\n\tinitialised. */\n\ttaskENTER_CRITICAL();\n\t{\n\t\tif( xTimerQueue == NULL )\n\t\t{\n\t\t\tvListInitialise( &xActiveTimerList1 );\n\t\t\tvListInitialise( &xActiveTimerList2 );\n\t\t\tpxCurrentTimerList = &xActiveTimerList1;\n\t\t\tpxOverflowTimerList = &xActiveTimerList2;\n\n\t\t\t#if( configSUPPORT_STATIC_ALLOCATION == 1 )\n\t\t\t{\n\t\t\t\t/* The timer queue is allocated statically in case\n\t\t\t\tconfigSUPPORT_DYNAMIC_ALLOCATION is 0. */\n\t\t\t\tstatic static_queue_s_t xStaticTimerQueue; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */\n\t\t\t\tstatic uint8_t ucStaticTimerQueueStorage[ ( size_t ) configTIMER_QUEUE_LENGTH * sizeof( DaemonTaskMessage_t ) ]; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */\n\n\t\t\t\txTimerQueue = queue_create_static( ( uint32_t ) configTIMER_QUEUE_LENGTH, ( uint32_t ) sizeof( DaemonTaskMessage_t ), &( ucStaticTimerQueueStorage[ 0 ] ), &xStaticTimerQueue );\n\t\t\t}\n\t\t\t#else\n\t\t\t{\n\t\t\t\txTimerQueue = queue_create( ( uint32_t ) configTIMER_QUEUE_LENGTH, sizeof( DaemonTaskMessage_t ) );\n\t\t\t}\n\t\t\t#endif\n\n\t\t\t#if ( configQUEUE_REGISTRY_SIZE > 0 )\n\t\t\t{\n\t\t\t\tif( xTimerQueue != NULL )\n\t\t\t\t{\n\t\t\t\t\tvQueueAddToRegistry( xTimerQueue, \"TmrQ\" );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t\t\t}\n\t\t\t}\n\t\t\t#endif /* configQUEUE_REGISTRY_SIZE */\n\t\t}\n\t\telse\n\t\t{\n\t\t\tmtCOVERAGE_TEST_MARKER();\n\t\t}\n\t}\n\ttaskEXIT_CRITICAL();\n}\n/*-----------------------------------------------------------*/\n\nint32_t xTimerIsTimerActive( TimerHandle_t xTimer )\n{\nint32_t xTimerIsInActiveList;\nTimer_t *pxTimer = ( Timer_t * ) xTimer;\n\n\tconfigASSERT( xTimer );\n\n\t/* Is the timer in the list of active timers? */\n\ttaskENTER_CRITICAL();\n\t{\n\t\t/* Checking to see if it is in the NULL list in effect checks to see if\n\t\tit is referenced from either the current or the overflow timer lists in\n\t\tone go, but the logic has to be reversed, hence the '!'. */\n\t\txTimerIsInActiveList = ( int32_t ) !( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) ); /*lint !e961. Cast is only redundant when NULL is passed into the macro. */\n\t}\n\ttaskEXIT_CRITICAL();\n\n\treturn xTimerIsInActiveList;\n} /*lint !e818 Can't be pointer to const due to the typedef. */\n/*-----------------------------------------------------------*/\n\nvoid *pvTimerGetTimerID( const TimerHandle_t xTimer )\n{\nTimer_t * const pxTimer = ( Timer_t * ) xTimer;\nvoid *pvReturn;\n\n\tconfigASSERT( xTimer );\n\n\ttaskENTER_CRITICAL();\n\t{\n\t\tpvReturn = pxTimer->pvTimerID;\n\t}\n\ttaskEXIT_CRITICAL();\n\n\treturn pvReturn;\n}\n/*-----------------------------------------------------------*/\n\nvoid vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID )\n{\nTimer_t * const pxTimer = ( Timer_t * ) xTimer;\n\n\tconfigASSERT( xTimer );\n\n\ttaskENTER_CRITICAL();\n\t{\n\t\tpxTimer->pvTimerID = pvNewID;\n\t}\n\ttaskEXIT_CRITICAL();\n}\n/*-----------------------------------------------------------*/\n\n#if( INCLUDE_xTimerPendFunctionCall == 1 )\n\n\tint32_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, int32_t *pxHigherPriorityTaskWoken )\n\t{\n\tDaemonTaskMessage_t xMessage;\n\tint32_t xReturn;\n\n\t\t/* Complete the message with the function parameters and post it to the\n\t\tdaemon task. */\n\t\txMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR;\n\t\txMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;\n\t\txMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;\n\t\txMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;\n\n\t\txReturn = xQueueSendFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );\n\n\t\ttracePEND_FUNC_CALL_FROM_ISR( xFunctionToPend, pvParameter1, ulParameter2, xReturn );\n\n\t\treturn xReturn;\n\t}\n\n#endif /* INCLUDE_xTimerPendFunctionCall */\n/*-----------------------------------------------------------*/\n\n#if( INCLUDE_xTimerPendFunctionCall == 1 )\n\n\tint32_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, uint32_t xTicksToWait )\n\t{\n\tDaemonTaskMessage_t xMessage;\n\tint32_t xReturn;\n\n\t\t/* This function can only be called after a timer has been created or\n\t\tafter the scheduler has been started because, until then, the timer\n\t\tqueue does not exist. */\n\t\tconfigASSERT( xTimerQueue );\n\n\t\t/* Complete the message with the function parameters and post it to the\n\t\tdaemon task. */\n\t\txMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK;\n\t\txMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;\n\t\txMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;\n\t\txMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;\n\n\t\txReturn = queue_append( xTimerQueue, &xMessage, xTicksToWait );\n\n\t\ttracePEND_FUNC_CALL( xFunctionToPend, pvParameter1, ulParameter2, xReturn );\n\n\t\treturn xReturn;\n\t}\n\n#endif /* INCLUDE_xTimerPendFunctionCall */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tuint32_t uxTimerGetTimerNumber( TimerHandle_t xTimer )\n\t{\n\t\treturn ( ( Timer_t * ) xTimer )->uxTimerNumber;\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*-----------------------------------------------------------*/\n\n#if ( configUSE_TRACE_FACILITY == 1 )\n\n\tvoid vTimerSetTimerNumber( TimerHandle_t xTimer, uint32_t uxTimerNumber )\n\t{\n\t\t( ( Timer_t * ) xTimer )->uxTimerNumber = uxTimerNumber;\n\t}\n\n#endif /* configUSE_TRACE_FACILITY */\n/*-----------------------------------------------------------*/\n\n/* This entire source file will be skipped if the application is not configured\nto include software timer functionality.  If you want to include software timer\nfunctionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */\n#endif /* configUSE_TIMERS == 1 */\n\n\n\n"
  },
  {
    "path": "src/system/cpp_support.cpp",
    "content": "/**\n * \\file system/cpp_support.cpp\n *\n * C++ support hooks\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <cstddef>\n#include <cstdlib>\n#include <stdexcept>\n\n#include \"rtos/FreeRTOS.h\"\n#include \"rtos/task.h\"\n#include \"v5_api.h\"\n\nextern \"C\" void task_fn_wrapper(task_fn_t fn, void* args) {\n#ifdef __cpp_exceptions\n\ttry {\n#endif\n\t\tfn(args);\n#ifdef __cpp_exceptions\n\t} catch (const std::runtime_error& re) {\n\t\tfprintf(stderr, \"Runtime error: %s \\n\", re.what());\n\t\tvexDisplayString(5, \"A runtime error occurred:\");\n\t\tvexDisplayString(6, \"%s\", re.what());\n\t\tvexDisplayString(7, \"Note: open terminal for error message\");\n\t} catch (const std::exception& ex) {\n\t\tfprintf(stderr, \"Exception occurred: %s \\n\", ex.what());\n\t\tvexDisplayString(5, \"An exception occurred:\");\n\t\tvexDisplayString(6, \"%s\", ex.what());\n\t\tvexDisplayString(7, \"Note: open terminal for error message\");\n\t} catch (...) {\n\t\tfprintf(stderr, \"Unknown error occurred. \\n\");\n\t\tvexDisplayString(5, \"An unknown error occurred\");\n\t}\n#endif\n}\n\n/******************************************************************************/\n/**                        C++ Linkages for User Tasks                       **/\n/******************************************************************************/\n__attribute__((weak)) void autonomous() {}\n__attribute__((weak)) void initialize() {}\n__attribute__((weak)) void opcontrol() {}\n__attribute__((weak)) void disabled() {}\n__attribute__((weak)) void competition_initialize() {}\n\nextern \"C\" void cpp_autonomous() {\n\tautonomous();\n}\nextern \"C\" void cpp_initialize() {\n\tinitialize();\n}\nextern \"C\" void cpp_opcontrol() {\n\topcontrol();\n}\nextern \"C\" void cpp_disabled() {\n\tdisabled();\n}\nextern \"C\" void cpp_competition_initialize() {\n\tcompetition_initialize();\n}\n"
  },
  {
    "path": "src/system/dev/dev_driver.c",
    "content": "/**\n * \\file system/dev/dev_driver.c\n *\n * Generic Serial Device driver\n *\n * Contains the driver for writing to any smart port with no regard to the\n * device on the other end.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <fcntl.h>\n#include <stdio.h>\n#include <string.h>\n#include <sys/stat.h>\n#include <sys/types.h>\n\n#include \"common/set.h\"\n#include \"common/string.h\"\n#include \"kapi.h\"\n#include \"system/dev/dev.h\"\n#include \"system/dev/vfs.h\"\n#include \"system/optimizers.h\"\n#include \"v5_api.h\"\n#include \"vdml/vdml.h\"\n\n#define ASCII_ZERO 48\n\ntypedef struct dev_file_arg {\n\tuint32_t port;\n\tint flags;\n} dev_file_arg_t;\n\n/******************************************************************************/\n/**                         newlib driver functions                          **/\n/******************************************************************************/\nint dev_read_r(struct _reent* r, void* const arg, uint8_t* buffer, const size_t len) {\n\tdev_file_arg_t* file_arg = (dev_file_arg_t*)arg;\n\tuint32_t port = file_arg->port;\n\tint32_t recv = 0;\n\twhile (true) {\n\t\trecv = serial_read(port, (uint8_t*)(buffer + recv), len - recv);\n\t\tif (recv == PROS_ERR) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (file_arg->flags & O_NONBLOCK || recv >= 1) {\n\t\t\tbreak;\n\t\t}\n\t\ttask_delay(2);\n\t}\n\tif (recv == 0) {\n\t\terrno = EAGAIN;\n\t\treturn 0;\n\t}\n\treturn recv;\n}\n\nint dev_write_r(struct _reent* r, void* const arg, const uint8_t* buf, const size_t len) {\n\tdev_file_arg_t* file_arg = (dev_file_arg_t*)arg;\n\tuint32_t port = file_arg->port;\n\tint32_t wrtn = 0;\n\twhile (true) {\n\t\tint32_t w = serial_write(port, (uint8_t*)(buf + wrtn), len - wrtn);\n\t\tif (w == PROS_ERR) {\n\t\t\treturn wrtn;\n\t\t}\n\t\twrtn += w;\n\t\tif (file_arg->flags & O_NONBLOCK || wrtn >= len) {\n\t\t\tbreak;\n\t\t}\n\t\ttask_delay(2);\n\t}\n\tif (wrtn == 0) {\n\t\terrno = EAGAIN;\n\t\treturn 0;\n\t}\n\treturn wrtn;\n}\n\nint dev_close_r(struct _reent* r, void* const arg) {\n\treturn 0;\n}\n\nint dev_fstat_r(struct _reent* r, void* const arg, struct stat* st) {\n\t// this is a complete implementation\n\tst->st_mode = S_IFCHR;\n\treturn 0;\n}\n\nint dev_isatty_r(struct _reent* r, void* const arg) {\n\t// this is a complete implementation\n\treturn 0;\n}\n\noff_t dev_lseek_r(struct _reent* r, void* const arg, off_t ptr, int dir) {\n\t// lseek doesn't make sense on a serial line\n\tr->_errno = ESPIPE;\n\treturn -1;\n}\n\nint dev_ctl(void* const arg, const uint32_t cmd, void* const extra_arg) {\n\tdev_file_arg_t* file_arg = (dev_file_arg_t*)arg;\n\tuint32_t port = file_arg->port;\n\tswitch (cmd) {\n\t\tcase DEVCTL_FIONREAD:\n\t\t\treturn serial_get_read_avail(port);\n\t\tcase DEVCTL_FIONWRITE:\n\t\t\treturn serial_get_write_free(port);\n\t\tcase DEVCTL_SET_BAUDRATE:\n\t\t\treturn serial_set_baudrate(port, (int32_t)extra_arg);\n\t\tdefault:\n\t\t\terrno = EINVAL;\n\t\t\treturn PROS_ERR;\n\t}\n}\n\n/******************************************************************************/\n/**                           Driver description                             **/\n/******************************************************************************/\nconst struct fs_driver _dev_driver = {.close_r = dev_close_r,\n                                      .fstat_r = dev_fstat_r,\n                                      .isatty_r = dev_isatty_r,\n                                      .lseek_r = dev_lseek_r,\n                                      .read_r = dev_read_r,\n                                      .write_r = dev_write_r,\n                                      .ctl = dev_ctl};\n\nconst struct fs_driver* const dev_driver = &_dev_driver;\n\nint dev_open_r(struct _reent* r, const char* path, int flags, int mode) {\n\tif (*path == '\\0') {\n\t\treturn STDOUT_FILENO;\n\t}\n\n\tif (*path == '/') {\n\t\tpath++;\n\t}\n\n\t// check length of path - it MUST be at most 2 characters\n\tsize_t i;\n\tfor (i = 0; i < 3; i++) {\n\t\tif (path[i] == '\\0') {\n\t\t\tbreak;\n\t\t}\n\t}\n\tint32_t port;\n\tif (path[i] != '\\0') {  // i will the length of the path or the third character\n\t\tr->_errno = ENAMETOOLONG;\n\t\treturn -1;\n\t}\n\tif (i == 2) {\n\t\t// Port number is two characters\n\t\tport = 10 * (path[0] - ASCII_ZERO) + (path[1] - ASCII_ZERO);\n\t} else {\n\t\tport = path[0] - ASCII_ZERO;\n\t}\n\tserial_enable(port);\n\n\tdev_file_arg_t* arg = (dev_file_arg_t*)kmalloc(sizeof(dev_file_arg_t));\n\targ->port = port;\n\targ->flags = flags;\n\treturn vfs_add_entry_r(r, dev_driver, arg);\n}\n"
  },
  {
    "path": "src/system/dev/file_system_stubs.c",
    "content": "/**\r\n * \\file system/dev/dev_driver.c\r\n *\r\n * Generic Serial Device driver\r\n *\r\n * Contains temporary stubs for the file system to allow compilation under gcc 9.2\r\n * This is temporary and should be removed as part of #184\r\n *\r\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\r\n * All rights reserved.\r\n *\r\n * This Source Code Form is subject to the terms of the Mozilla Public\r\n * License, v. 2.0. If a copy of the MPL was not distributed with this\r\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\r\n */\r\n\r\n#include <errno.h>\r\n#include <sys/stat.h>\r\n\r\nint chdir(const char* path) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n\r\nint mkdir(const char* pathname, mode_t mode) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n\r\nint chmod(const char* pathname, mode_t mode) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n\r\nint fchmod(int fd, mode_t mode) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n\r\nint fchmodat(int dirfd, const char* pathname, mode_t mode, int flags) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n\r\nlong pathconf(const char* path, int name) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n\r\nchar* getcwd(char* buf, size_t size) {\r\n\terrno = ENOSYS;\r\n\treturn NULL;\r\n}\r\n\r\nint _unlink(const char* name) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n\r\nint _link(const char* old, const char* new) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n\r\nint _stat(const char* file, struct stat* st) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n\r\nint symlink(const char* file, const char* linkpath) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n\r\nssize_t readlink(const char* pathname, char* buf, size_t bufsiz) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n\r\nint truncate(const char* path, off_t length) {\r\n\terrno = ENOSYS;\r\n\treturn -1;\r\n}\r\n"
  },
  {
    "path": "src/system/dev/ser_daemon.c",
    "content": "/**\n * \\file system/dev/ser_daemon.c\n *\n * Serial Input Daemon\n *\n * The serial input daemon is responsible for polling the serial line for\n * characters and responding to any kernel commands (like printing the banner or\n * enabling COBS)\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n\n#include \"kapi.h\"\n#include \"pros/version.h\"\n#include \"system/dev/banners.h\"\n#include \"system/hot.h\"\n#include \"system/optimizers.h\"\n#include \"v5_api.h\"\n\n#define MAX_COMMAND_LENGTH 32\n\n__attribute__((weak)) char const* const _PROS_COMPILE_TIMESTAMP = \"Unknown\";\n__attribute__((weak)) char const* const _PROS_COMPILE_DIRECTORY = \"Unknown\";\n__attribute__((weak)) const int         _PROS_COMPILE_TIMESTAMP_INT = 0;\n\nstatic bool banner_is_enabled = true;\n\nvoid enable_banner(bool enabled) {\n\tbanner_is_enabled = enabled;\n}\n\nvoid print_small_banner(void) {\n\tif (!banner_is_enabled) return;\n\tuint32_t uptime = millis();\n\tchar const * const timestamp = (HOT_TABLE && HOT_TABLE->compile_timestamp) ? HOT_TABLE->compile_timestamp : _PROS_COMPILE_TIMESTAMP;\n\tchar const * const directory = (HOT_TABLE && HOT_TABLE->compile_directory) ? HOT_TABLE->compile_directory : _PROS_COMPILE_DIRECTORY;\n\tiprintf(short_banner, PROS_VERSION_STRING, uptime / 1000, uptime % 1000, timestamp,\n\t        directory);\n}\n\nvoid print_large_banner(void) {\n\tif (!banner_is_enabled) return;\n\tuint8_t version[4];\n\tuint32_t* sys_ver = (uint32_t*)version;\n\t*sys_ver = vexSystemVersion();\n\tuint32_t uptime = millis();\n\tchar const * const timestamp = (HOT_TABLE && HOT_TABLE->compile_timestamp) ? HOT_TABLE->compile_timestamp : _PROS_COMPILE_TIMESTAMP;\n\tchar const * const directory = (HOT_TABLE && HOT_TABLE->compile_directory) ? HOT_TABLE->compile_directory : _PROS_COMPILE_DIRECTORY;\n\tiprintf(large_banner, PROS_VERSION_STRING, version[3], version[2], version[1], version[0], uptime / 1000,\n\t        uptime % 1000, timestamp, directory);\n}\n\n/******************************************************************************/\n/**                              Input buffer                                **/\n/**                                                                          **/\n/** this is what read() reads from. Implemented as a ring buffer             **/\n/**  TODO: just use a FreeRTOS queue instead of 2 semaphores                 **/\n/******************************************************************************/\n#define INP_BUFFER_SIZE 0x1000  // 4KB... which is larger than VEX's output buffer -_-\n\nstatic static_stream_buf_s_t inp_stream_buf;\nstatic uint8_t inp_buffer[INP_BUFFER_SIZE];\nstatic stream_buf_t inp_stream;\n\nstatic inline void inp_buffer_initialize() {\n\tinp_stream = stream_buf_create_static(INP_BUFFER_SIZE, 1, inp_buffer, &inp_stream_buf);\n}\n\n// if you extern this function you can place characters on the rest of the\n// system's input buffer\nbool inp_buffer_post(uint8_t b) {\n\treturn stream_buf_send(inp_stream, &b, 1, TIMEOUT_MAX);\n}\n\nint32_t inp_buffer_read(uint32_t timeout) {\n\t// polling the semaphore from a higher priority task (as would be normal) will\n\t// starve the ser_daemon_task\n\tif (timeout == 0) {\n\t\ttimeout = 1;\n\t}\n\tuint8_t b;\n\tif (!stream_buf_recv(inp_stream, &b, 1, timeout)) {\n\t\treturn -1;\n\t}\n\treturn (int32_t)b;\n}\n\n// returns the number of bytes currently in the stream\nint32_t inp_buffer_available() {\n\treturn stream_buf_get_used(inp_stream);\n}\n\n/******************************************************************************/\n/**                              Serial Daemon                               **/\n/******************************************************************************/\nstatic task_stack_t ser_daemon_stack[TASK_STACK_DEPTH_MIN];\nstatic static_task_s_t ser_daemon_task_buffer;\n\nstatic inline uint8_t vex_read_char() {\n\tint32_t b = vexSerialReadChar(1);\n\twhile (b == -1L) {\n\t\ttask_delay(1);\n\t\tb = vexSerialReadChar(1);\n\t}\n\t// Don't get rid of the literal type suffix, it ensures optimiziations don't\n\t// break this condition\n\treturn (uint8_t)b;\n}\n\nstatic void ser_daemon_task(void* ign) {\n\tuint8_t command_stack[MAX_COMMAND_LENGTH];\n\tsize_t command_stack_idx = 0;\n\n\tprint_large_banner();\n\n\twhile (1) {\n\t\tuint8_t b = vex_read_char();\n\t\tif (b == 'p') {  // TODO: make the command prefix not typeable\n\t\t\tcommand_stack[command_stack_idx++] = b;\n\t\t\tb = command_stack[command_stack_idx++] = vex_read_char();\n\t\t\tif (b == 'R') {\n\t\t\t\tb = command_stack[command_stack_idx++] = vex_read_char();\n\t\t\t\tswitch (b) {\n\t\t\t\t\tcase 'a':\n\t\t\t\t\t\tfprintf(stderr, \"I'm alive!\\n\");\n\t\t\t\t\t\tcommand_stack_idx = 0;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'b':\n\t\t\t\t\t\ttask_delay(20);\n\t\t\t\t\t\tprint_small_banner();\n\t\t\t\t\t\tcommand_stack_idx = 0;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'B':\n\t\t\t\t\t\ttask_delay(20);\n\t\t\t\t\t\tprint_large_banner();\n\t\t\t\t\t\tcommand_stack_idx = 0;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'e':\n\t\t\t\t\t\t// read next 4 bytes\n\t\t\t\t\t\tcommand_stack[command_stack_idx++] = vex_read_char();\n\t\t\t\t\t\tcommand_stack[command_stack_idx++] = vex_read_char();\n\t\t\t\t\t\tcommand_stack[command_stack_idx++] = vex_read_char();\n\t\t\t\t\t\tcommand_stack[command_stack_idx++] = vex_read_char();\n\t\t\t\t\t\t// the parameter expected to serctl is the stream id (a uint32_t), so\n\t\t\t\t\t\t// we\n\t\t\t\t\t\t// need to cast to a uint32_t pointer, dereference it, and cast to a\n\t\t\t\t\t\t// void* to make the compiler happy\n\t\t\t\t\t\tserctl(SERCTL_ACTIVATE, (void*)(*(uint32_t*)(command_stack + 3)));\n\t\t\t\t\t\t// printf(\"enabled %s\\n\", command_stack + 3);\n\t\t\t\t\t\tcommand_stack_idx = 0;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'd':\n\t\t\t\t\t\t// read next 4 bytes\n\t\t\t\t\t\tcommand_stack[command_stack_idx++] = vex_read_char();\n\t\t\t\t\t\tcommand_stack[command_stack_idx++] = vex_read_char();\n\t\t\t\t\t\tcommand_stack[command_stack_idx++] = vex_read_char();\n\t\t\t\t\t\tcommand_stack[command_stack_idx++] = vex_read_char();\n\t\t\t\t\t\tserctl(SERCTL_DEACTIVATE, (void*)(*(uint32_t*)(command_stack + 3)));\n\t\t\t\t\t\t// printf(\"disabled %s\\n\", command_stack+3);\n\t\t\t\t\t\tcommand_stack_idx = 0;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'c':\n\t\t\t\t\t\tserctl(SERCTL_ENABLE_COBS, NULL);\n\t\t\t\t\t\tcommand_stack_idx = 0;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'r':\n\t\t\t\t\t\tserctl(SERCTL_DISABLE_COBS, NULL);\n\t\t\t\t\t\tcommand_stack_idx = 0;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tcommand_stack_idx = 0;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (size_t i = 0; i < command_stack_idx; i++) {\n\t\t\t\t// empty out the command stack onto the input buffer since something\n\t\t\t\t// wasn't right with the command\n\t\t\t\tinp_buffer_post(command_stack[i]);\n\t\t\t}\n\t\t\tcommand_stack_idx = 0;\n\t\t} else {\n\t\t\tinp_buffer_post(b);\n\t\t}\n\t}\n}\n\nvoid ser_initialize(void) {\n\tinp_buffer_initialize();\n\textern void ser_driver_initialize(void);\n\tser_driver_initialize();\n\n\ttask_create_static(ser_daemon_task, NULL, TASK_PRIORITY_MIN + 1, TASK_STACK_DEPTH_MIN, \"Serial Daemon (PROS)\",\n\t                   ser_daemon_stack, &ser_daemon_task_buffer);\n}\n"
  },
  {
    "path": "src/system/dev/ser_driver.c",
    "content": "/**\n * \\file system/dev/ser_driver.c\n *\n * Serial Driver\n *\n * Contains the driver for communicating over the serial line. The serial driver\n * is responsible for shipping out all data.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <string.h>\n\n#include \"common/cobs.h\"\n#include \"common/set.h\"\n#include \"common/string.h\"\n#include \"kapi.h\"\n#include \"system/dev/ser.h\"\n#include \"system/dev/vfs.h\"\n#include \"system/optimizers.h\"\n#include \"v5_api.h\"\n\n#define VEX_SERIAL_BUFFER_SIZE 2047\n\n// ser_file_arg is 2 words (64 bits). The first word is the stream_id\n// (i.e. sout/serr/jinx/kdbg) and is exactly 4 characters. The second word\n// contains flags for serial driver operation\ntypedef struct ser_file_arg {\n\tunion {\n\t\tuint32_t stream_id;\n\t\tuint8_t stream[4];\n\t};\n\tenum { E_NOBLK_WRITE = 1 } flags;\n} ser_file_s_t;\n\n#define STDIN_STREAM_ID 0x706e6973   // 'sinp' little endian\n#define STDOUT_STREAM_ID 0x74756f73  // 'sout' little endian\n#define STDERR_STREAM_ID 0x72726573  // 'serr' little endian\n#define KDBG_STREAM_ID 0x6762646b    // 'kdbg' little endian\n\n// This array contains the serial driver's arguments for the 4 reserved file\n// descriptors. The fact that this array matches the order of the 4 reserved\n// file descriptors is mostly irrelevant. We do need to know which one is which,\n// but they get mapped in ser_driver_initialize.\nstatic ser_file_s_t RESERVED_SER_FILES[] = {\n    {.stream_id = STDIN_STREAM_ID, .flags = 0},\n    {.stream_id = STDOUT_STREAM_ID, .flags = 0},\n    {.stream_id = STDERR_STREAM_ID, .flags = 0},\n    {.stream_id = KDBG_STREAM_ID, .flags = 0},\n};\n\n// These mutexes are initialized in ser_driver_initialize\nstatic static_sem_s_t read_mtx_buf;\nstatic static_sem_s_t write_mtx_buf;\nstatic mutex_t read_mtx;   // ensures that only one read is happening at a time\nstatic mutex_t write_mtx;  // ensures that only one write is happening at a time\n\n// Write buffer as a stream buffer. Initialized below in ser_driver_initialize\nstatic static_stream_buf_s_t write_stream_buf;\nstatic uint8_t write_buf[VEX_SERIAL_BUFFER_SIZE + 1];\nstatic uint8_t write_scratch_buf[VEX_SERIAL_BUFFER_SIZE];  // scratch buffer\nstatic stream_buf_t write_stream;\n\n// We maintain a set of streams which should actually be sent over the serial\n// line. This is maintained as a separate list and don't traverse through\n// open files b/c enabled streams is done per ID not per file (multiple\n// files may map to one stream ID)\n// Initialized below in ser_driver_initialize\nstatic struct set enabled_streams_set;\n\n// stderr is ALWAYS guaranteed to be sent over the serial line. stdout and\n// others may be disabled\nstatic const uint32_t guaranteed_delivery_streams[] = {\n    // STDIN_STREAM_ID,\n    // STDOUT_STREAM_ID,  stdout isn't guaranteed delivery, but enabled by\n    // default\n    STDERR_STREAM_ID,\n    // KDBG_STREAM_ID,\n};\n#define guaranteed_delivery_streams_size (sizeof(guaranteed_delivery_streams) / sizeof(*guaranteed_delivery_streams))\n\n// global runtime config for the serial driver\nstatic enum { E_COBS_ENABLED = 1 } ser_driver_runtime_config;\n\n// comes from ser_daemon\nextern int32_t inp_buffer_read(uint32_t timeout);\n\n/******************************************************************************/\n/**                              Output queue                                **/\n/**                                                                          **/\n/** vexSerialWriteBuffer doesn't seem to be very thread safe, so the system  **/\n/** daemon flushes an intermediary buffer once before vexBackgroundProcessing**/\n/** calls to write add to the queue. Flushing is optimized because we have   **/\n/** underlying access to the write buffer, as opposed to calling queue_recv  **/\n/** a bunch of times                                                         **/\n/******************************************************************************/\nvoid ser_output_flush(void) {\n\tsize_t len = stream_buf_recv(write_stream, write_scratch_buf, vexSerialWriteFree(1), 0);\n\tuint32_t ret = vexSerialWriteBuffer(1, write_scratch_buf, len);\n\tif (ret != len) {\n\t\tkprintf(\"WARNING: some serial data has been dropped\");\n\t}\n}\n\nbool ser_output_write(const uint8_t* buffer, size_t size, bool noblock) {\n\treturn stream_buf_send(write_stream, buffer, size, noblock ? 0 : TIMEOUT_MAX);\n}\n\n/******************************************************************************/\n/**                         newlib driver functions                          **/\n/******************************************************************************/\nint ser_read_r(struct _reent* r, void* const arg, uint8_t* buffer, const size_t len) {\n\t// arg isn't used since serial reads aren't stream-based\n\tsize_t read = 0;\n\tint32_t c;\n\tif (!mutex_take(read_mtx, TIMEOUT_MAX)) {\n\t\tr->_errno = EACCES;\n\t\treturn 0;\n\t}\n\twhile (read < len) {\n\t\t// the logic inside this loop is a bit funky but seems to make newlib behave\n\t\t// properly\n\t\tc = inp_buffer_read(0);\n\t\t// Don't get rid of the literal type suffix, it ensures optimiziations don't\n\t\t// break this condition\n\t\tif (c == -1L) {\n\t\t\tif (read) {\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\t*(buffer++) = (uint8_t)c;\n\t\tread++;\n\t\tif (c == '\\n') {\n\t\t\tbreak;\n\t\t}\n\t}\n\tmutex_give(read_mtx);\n\t*buffer = 0;\n\treturn read;\n}\n\nint ser_write_r(struct _reent* r, void* const arg, const uint8_t* buf, const size_t len) {\n\tconst ser_file_s_t file = *(ser_file_s_t*)arg;\n\n\tif (!list_contains(guaranteed_delivery_streams, guaranteed_delivery_streams_size, file.stream_id) &&\n\t    !set_contains(&enabled_streams_set, file.stream_id)) {\n\t\t// the stream isn't a guaranteed delivery or hasn't been enabled so just\n\t\t// pretend like the data was shipped just fine\n\t\treturn len;\n\t}\n\n\tif (ser_driver_runtime_config &= E_COBS_ENABLED) {\n\t\t// allocate stack space for the buffer to be cobs encoded\n\t\tconst size_t cobs_len = cobs_encode_measure(buf, len, file.stream_id);\n\t\tuint8_t cobs_buf[cobs_len + 1];\n\n\t\t// need to guarantee writes are in order\n\t\tif (!mutex_take(write_mtx, (file.flags & E_NOBLK_WRITE) ? 0 : TIMEOUT_MAX)) {\n\t\t\tr->_errno = EACCES;\n\t\t\treturn 0;\n\t\t}\n\t\tcobs_encode(cobs_buf, buf, len, file.stream_id);\n\t\tcobs_buf[cobs_len] = 0;\n\n\t\tbool ret = ser_output_write(cobs_buf, cobs_len + 1, file.flags & E_NOBLK_WRITE);\n\t\tmutex_give(write_mtx);\n\n\t\tif (!ret) {\n\t\t\tr->_errno = EIO;\n\t\t\treturn 0;\n\t\t}\n\t\treturn len;\n\t} else {\n\t\t// need to guarantee writes are in order\n\t\tif (!mutex_take(write_mtx, TIMEOUT_MAX)) {\n\t\t\tr->_errno = EACCES;\n\t\t\treturn 0;\n\t\t}\n\n\t\tbool ret = ser_output_write(buf, len, file.flags & E_NOBLK_WRITE);\n\n\t\tmutex_give(write_mtx);\n\t\tif (!ret) {\n\t\t\tr->_errno = EIO;\n\t\t\treturn 0;\n\t\t}\n\t\treturn len;\n\t}\n}\n\nint ser_close_r(struct _reent* r, void* const arg) {\n\t// This does nothing for now, may be implemented later\n\treturn 0;\n}\n\nint ser_fstat_r(struct _reent* r, void* const arg, struct stat* st) {\n\t// this is a complete implementation\n\tst->st_mode = S_IFCHR;\n\treturn 0;\n}\n\nint ser_isatty_r(struct _reent* r, void* const arg) {\n\t// this is a complete implementation\n\treturn 1;\n}\n\noff_t ser_lseek_r(struct _reent* r, void* const arg, off_t ptr, int dir) {\n\t// lseek doesn't make sense on a serial line\n\tr->_errno = ESPIPE;\n\treturn -1;\n}\n\nint ser_ctl(void* const arg, const uint32_t cmd, void* const extra_arg) {\n\tser_file_s_t file = *(ser_file_s_t*)arg;\n\tswitch (cmd) {\n\t\tcase SERCTL_ACTIVATE:\n\t\t\tif (!list_contains(guaranteed_delivery_streams, guaranteed_delivery_streams_size, (uint32_t)file.stream_id)) {\n\t\t\t\tset_add(&enabled_streams_set, (uint32_t)file.stream_id);\n\t\t\t}\n\t\t\treturn 0;\n\t\tcase SERCTL_DEACTIVATE:\n\t\t\tif (!list_contains(guaranteed_delivery_streams, guaranteed_delivery_streams_size, (uint32_t)file.stream_id)) {\n\t\t\t\tset_rm(&enabled_streams_set, (uint32_t)file.stream_id);\n\t\t\t}\n\t\t\treturn 0;\n\t\tcase SERCTL_BLKWRITE:\n\t\t\tfile.flags &= ~E_NOBLK_WRITE;\n\t\t\treturn 0;\n\t\tcase SERCTL_NOBLKWRITE:\n\t\t\tfile.flags |= E_NOBLK_WRITE;\n\t\t\treturn 0;\n\t\tdefault:\n\t\t\terrno = EINVAL;\n\t\t\treturn PROS_ERR;\n\t}\n}\n\n/******************************************************************************/\n/**                           Driver description                             **/\n/******************************************************************************/\nconst struct fs_driver _ser_driver = {.close_r = ser_close_r,\n                                      .fstat_r = ser_fstat_r,\n                                      .isatty_r = ser_isatty_r,\n                                      .lseek_r = ser_lseek_r,\n                                      .read_r = ser_read_r,\n                                      .write_r = ser_write_r,\n                                      .ctl = ser_ctl};\n\nconst struct fs_driver* const ser_driver = &_ser_driver;\n\nint ser_open_r(struct _reent* r, const char* path, int flags, int mode) {\n\tif (*path == '\\0') {\n\t\treturn STDOUT_FILENO;\n\t}\n\n\tif (*path == '/') {\n\t\tpath++;\n\t}\n\n\t// check length of path - it MUST be at most 4 characters\n\tsize_t i;\n\tfor (i = 0; i < 4; i++) {\n\t\tif (path[i] == '\\0') {\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (path[i] != '\\0') {  // i will the length of the path or the fifth character\n\t\tr->_errno = ENAMETOOLONG;\n\t\treturn -1;\n\t}\n\n\tif (!strcmp(path, \"sout\")) {\n\t\treturn STDOUT_FILENO;\n\t}\n\tif (!strcmp(path, \"sin\")) {\n\t\treturn STDIN_FILENO;\n\t}\n\tif (!strcmp(path, \"serr\")) {\n\t\treturn STDERR_FILENO;\n\t}\n\n\tser_file_s_t* arg = kmalloc(sizeof(*arg));\n\tmemcpy(arg->stream, path, strlen(path));\n\treturn vfs_add_entry_r(r, ser_driver, arg);\n}\n\n// control various components of the serial driver or a file\nint32_t serctl(const uint32_t action, void* const extra_arg) {\n\tswitch (action) {\n\t\tcase SERCTL_ACTIVATE:\n\t\t\tif (!list_contains(guaranteed_delivery_streams, guaranteed_delivery_streams_size, (uint32_t)extra_arg)) {\n\t\t\t\tset_add(&enabled_streams_set, (uint32_t)extra_arg);\n\t\t\t} else {\n\t\t\t\terrno = EIO;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 0;\n\t\tcase SERCTL_DEACTIVATE:\n\t\t\tif (!list_contains(guaranteed_delivery_streams, guaranteed_delivery_streams_size, (uint32_t)extra_arg)) {\n\t\t\t\tset_rm(&enabled_streams_set, (uint32_t)extra_arg);\n\t\t\t} else {\n\t\t\t\terrno = EIO;\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn 0;\n\t\tcase SERCTL_ENABLE_COBS:\n\t\t\tser_driver_runtime_config |= E_COBS_ENABLED;\n\t\t\treturn 0;\n\t\tcase SERCTL_DISABLE_COBS:\n\t\t\tser_driver_runtime_config &= ~E_COBS_ENABLED;\n\t\t\treturn 0;\n\t\tdefault:\n\t\t\terrno = EINVAL;\n\t\t\treturn PROS_ERR;\n\t}\n}\n\n// called by ser_initialize() in ser_daemon.c\n// vfs_initialize() calls ser_initialize()\nvoid ser_driver_initialize(void) {\n\tser_driver_runtime_config |= E_COBS_ENABLED;  // start with cobs enabled\n\n\tread_mtx = mutex_create_static(&read_mtx_buf);\n\twrite_mtx = mutex_create_static(&write_mtx_buf);\n\n\tset_initialize(&enabled_streams_set);\n\tset_add(&enabled_streams_set, STDOUT_STREAM_ID);  // 'sout' little endian\n\n\twrite_stream = stream_buf_create_static(VEX_SERIAL_BUFFER_SIZE, 0, write_buf, &write_stream_buf);\n\n\tvfs_update_entry(STDIN_FILENO, ser_driver, &(RESERVED_SER_FILES[0]));\n\tvfs_update_entry(STDOUT_FILENO, ser_driver, &(RESERVED_SER_FILES[1]));\n\tvfs_update_entry(STDERR_FILENO, ser_driver, &(RESERVED_SER_FILES[2]));\n\tvfs_update_entry(KDBG_FILENO, ser_driver, &(RESERVED_SER_FILES[3]));\n}\n"
  },
  {
    "path": "src/system/dev/usd_driver.c",
    "content": "/**\n * \\file system/dev/usd_driver.c\n *\n * Contains the driver for writing files to the microSD card.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <fcntl.h>\n#include <stdio.h>\n#include <string.h>\n#include <sys/stat.h>\n#include <sys/types.h>\n\n#include \"common/set.h\"\n#include \"common/string.h\"\n#include \"kapi.h\"\n#include \"system/dev/usd.h\"\n#include \"system/dev/vfs.h\"\n#include \"system/optimizers.h\"\n#include \"v5_api.h\"\n\ntypedef struct usd_file_arg {\n\tFIL* ifi_fptr;\n} usd_file_arg_t;\n\nstatic const int FRESULTMAP[] = {0,       EIO,    EINVAL, EBUSY, ENOENT,  ENOENT, EINVAL, EACCES,  // FR_DENIED\n                                 EEXIST,  EINVAL, EROFS,  ENXIO, ENOBUFS, ENXIO,  EIO,    EACCES,  // FR_LOCKED\n                                 ENOBUFS, ENFILE, EINVAL};\nenum fa_flags {\n\tFA_READ = 1 << 0,\n\tFA_WRITE = 1 << 1,\n\tFA_CREATE_ALWAYS = 1 << 2,\n\tFA_OPEN_APPEND = 1 << 3,\n\tFA_CREATE_NEW = 1 << 4\n};\n\n/******************************************************************************/\n/**                         newlib driver functions                          **/\n/******************************************************************************/\nint usd_read_r(struct _reent* r, void* const arg, uint8_t* buffer, const size_t len) {\n\tusd_file_arg_t* file_arg = (usd_file_arg_t*)arg;\n\t// TODO: mutex here. Global or file lock?\n\tint32_t result = vexFileRead((char*)buffer, sizeof(*buffer), len, file_arg->ifi_fptr);\n\treturn result;\n}\n\nint usd_write_r(struct _reent* r, void* const arg, const uint8_t* buf, const size_t len) {\n\tusd_file_arg_t* file_arg = (usd_file_arg_t*)arg;\n\t// TODO: mutex here. Global or file lock?\n\tint32_t result = vexFileWrite((char*)buf, sizeof(*buf), len, file_arg->ifi_fptr);\n\t// Flush the buffer\n\tvexFileSync(file_arg->ifi_fptr);\n\treturn result;\n}\n\nint usd_close_r(struct _reent* r, void* const arg) {\n\tusd_file_arg_t* file_arg = (usd_file_arg_t*)arg;\n\tvexFileClose(file_arg->ifi_fptr);\n\treturn 0;\n}\n\nint usd_fstat_r(struct _reent* r, void* const arg, struct stat* st) {\n\tusd_file_arg_t* file_arg = (usd_file_arg_t*)arg;\n\tst->st_size = vexFileSize(file_arg->ifi_fptr);\n\treturn 0;\n}\n\nint usd_isatty_r(struct _reent* r, void* const arg) {\n\treturn 0;\n}\n\noff_t usd_lseek_r(struct _reent* r, void* const arg, off_t ptr, int dir) {\n\tusd_file_arg_t* file_arg = (usd_file_arg_t*)arg;\n\t// TODO: mutex here. Global or file lock?\n\tFRESULT result = vexFileSeek(file_arg->ifi_fptr, ptr, dir);\n\tif (result != FR_OK) {\n\t\tr->_errno = FRESULTMAP[result];\n\t\treturn (off_t)-1;\n\t}\n\treturn vexFileTell(file_arg->ifi_fptr);\n}\n\nint usd_ctl(void* const arg, const uint32_t cmd, void* const extra_arg) {\n\treturn 0;\n}\n\n/******************************************************************************/\n/**                           Driver description                             **/\n/******************************************************************************/\n\nconst struct fs_driver _usd_driver = {.close_r = usd_close_r,\n                                      .fstat_r = usd_fstat_r,\n                                      .isatty_r = usd_isatty_r,\n                                      .lseek_r = usd_lseek_r,\n                                      .read_r = usd_read_r,\n                                      .write_r = usd_write_r,\n                                      .ctl = usd_ctl};\nconst struct fs_driver* const usd_driver = &_usd_driver;\n\nint usd_open_r(struct _reent* r, const char* path, int flags, int mode) {\n\tFRESULT result = vexFileMountSD();\n\tif (result != F_OK) {\n\t\tr->_errno = FRESULTMAP[result];\n\t\treturn -1;\n\t}\n\n\tusd_file_arg_t* file_arg = kmalloc(sizeof(*file_arg));\n\n\tswitch (flags & O_ACCMODE) {\n\t\tcase O_RDONLY:\n\t\t\tfile_arg->ifi_fptr = vexFileOpen(path, \"\");  // mode is ignored\n\t\t\tbreak;\n\t\tcase O_WRONLY:\n\t\t\tif (flags & O_APPEND) {\n\t\t\t\tfile_arg->ifi_fptr = vexFileOpenWrite(path);\n\t\t\t} else {\n\t\t\t\tfile_arg->ifi_fptr = vexFileOpenCreate(path);\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tr->_errno = EINVAL;\n\t\t\treturn -1;\n\t}\n\n\tif (!file_arg->ifi_fptr) {\n\t\tr->_errno = ENFILE;  // up to 8 files max as of vexOS 0.7.4b55\n\t\treturn -1;\n\t}\n\treturn vfs_add_entry_r(r, usd_driver, file_arg);\n}\n"
  },
  {
    "path": "src/system/dev/vfs.c",
    "content": "/**\n * \\file system/dev/vfs.c\n *\n * Virtual File System\n *\n * VFS is responsible for maintaining the global file table and routing all\n * basic I/O to the appropriate driver. There are three drivers implemented,\n * ser, dev, and usd which correspond to the serial driver, generic smart port\n * communication, and microSD card, respectively.\n *\n * VFS implements all of the I/O newlib stubs like open/read/write and delegates\n * them to the file's driver. Drivers don't actually have any knowledge of the\n * fileno. A file number maps to a driver and driver argument, which would be\n * whatever metadata the driver needs to open the file\n *\n * Copyright (c) 2017-2026, Purdue University ACM SIGBots\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n#include <stdint.h>\n#include <unistd.h>\n\n#include \"common/gid.h\"\n#include \"common/string.h\"\n#include \"kapi.h\"\n#include \"system/dev/dev.h\"\n#include \"system/dev/ser.h\"\n#include \"system/dev/usd.h\"\n#include \"system/dev/vfs.h\"\n#include \"v5_api.h\"\n\n#define MAX_FILELEN 128\n#define MAX_FILES_OPEN 31\n\n#define RESERVED_FILENOS 4  // reserve stdin, stdout, stderr, kdbg\n\n// gids bitmap buffer\nstatic uint32_t file_table_bmp[gid_size_to_words(MAX_FILES_OPEN)];\n// the gid structure itself\nstatic struct gid_metadata file_table_gids = {.bitmap = file_table_bmp,\n                                              .max = MAX_FILES_OPEN,\n                                              .reserved = RESERVED_FILENOS,\n                                              .bitmap_size = gid_size_to_words(MAX_FILES_OPEN)};\n\n// file table mapping a file descriptor number to a driver and driver argument\nstatic struct file_entry file_table[MAX_FILES_OPEN];\n\nvoid vfs_initialize(void) {\n\tgid_init(&file_table_gids);\n\n\tser_initialize();\n\n\t// Force _GLOBAL_REENT initialization for C++ stdio to work. See D97\n\textern void __sinit(struct _reent * s);\n\tif (!_GLOBAL_REENT->__cleanup) __sinit(_GLOBAL_REENT);\n}\n\n// adds an entry to the the file system\nint vfs_add_entry_r(struct _reent* r, struct fs_driver const* const driver, void* arg) {\n\tuint32_t gid = gid_alloc(&file_table_gids);\n\tif (gid == 0) {\n\t\tr->_errno = ENFILE;\n\t\treturn -1;\n\t}\n\n\tfile_table[gid].driver = driver;\n\tfile_table[gid].arg = arg;\n\treturn gid;\n}\n\n// update a given fileno driver and arg. Used by ser_driver_initialize to\n// initialize stdout, stdin, stderr, and kdbg\nint vfs_update_entry(int file, struct fs_driver const* const driver, void* arg) {\n\tif (file < 0 || !gid_check(&file_table_gids, file)) {\n\t\tkprintf(\"BAD vfs update %d\", file);\n\t\treturn -1;\n\t}\n\tif (driver != NULL) {\n\t\tfile_table[file].driver = driver;\n\t}\n\tif (arg != (void*)-1) {\n\t\tfile_table[file].arg = arg;\n\t}\n\treturn 0;\n}\n\nint _open(const char* file, int flags, int mode) {\n\tstruct _reent* r = _REENT;\n\t// Check if the filename is too long or not NULL terminated\n\tsize_t i = 0;\n\tfor (i = 0; i < MAX_FILELEN; i++) {\n\t\tif (file[i] == '\\0') {\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (i == MAX_FILELEN) {\n\t\tr->_errno = ENAMETOOLONG;\n\t\treturn -1;\n\t}\n\tif (strstr(file, \"/ser\") == file) {\n\t\t// is a serial pseudofile\n\t\treturn ser_open_r(r, file + strlen(\"/ser\"), flags, mode);\n\t} else if (strstr(file, \"/usd\") == file) {\n\t\treturn usd_open_r(r, file + strlen(\"/usd\"), flags, mode);\n\t} else if (strstr(file, \"/dev\") == file) {\n\t\treturn dev_open_r(r, file + strlen(\"/dev\"), flags, mode);\n\t} else {\n\t\treturn usd_open_r(r, file, flags, mode);\n\t}\n}\n\nssize_t _write(int file, const void* buf, size_t len) {\n\tstruct _reent* r = _REENT;\n\tif (file < 0 || !gid_check(&file_table_gids, file)) {\n\t\tr->_errno = EBADF;\n\t\tkprintf(\"BAD write %d\", file);\n\t\treturn -1;\n\t}\n\treturn file_table[file].driver->write_r(r, file_table[file].arg, buf, len);\n}\n\nssize_t _read(int file, void* buf, size_t len) {\n\tstruct _reent* r = _REENT;\n\tif (file < 0 || !gid_check(&file_table_gids, file)) {\n\t\tr->_errno = EBADF;\n\t\tkprintf(\"BAD read %d\", file);\n\t\treturn -1;\n\t}\n\treturn file_table[file].driver->read_r(r, file_table[file].arg, buf, len);\n}\n\nint _close(int file) {\n\tstruct _reent* r = _REENT;\n\t// NOTE: newlib automatically closes all open files for a given task when\n\t// the task is deleted.\n\tif (file > 0 && file < RESERVED_FILENOS) {\n\t\t// Do not close the reserved file handles\n\t\treturn 0;\n\t}\n\tif (file < 0 || !gid_check(&file_table_gids, file)) {\n\t\tr->_errno = EBADF;\n\t\tkprintf(\"BAD close %d\", file);\n\t\treturn -1;\n\t}\n\tint ret = file_table[file].driver->close_r(r, file_table[file].arg);\n\tif (ret == 0) {\n\t\tgid_free(&file_table_gids, file);\n\t}\n\treturn ret;\n}\n\nint _fstat(int file, struct stat* st) {\n\tstruct _reent* r = _REENT;\n\tif (file < 0 || !gid_check(&file_table_gids, file)) {\n\t\tr->_errno = EBADF;\n\t\tkprintf(\"BAD fstat %d\", file);\n\t\treturn -1;\n\t}\n\treturn file_table[file].driver->fstat_r(r, file_table[file].arg, st);\n}\n\noff_t _lseek(int file, off_t ptr, int dir) {\n\tstruct _reent* r = _REENT;\n\tif (file < 0 || !gid_check(&file_table_gids, file)) {\n\t\tr->_errno = EBADF;\n\t\tkprintf(\"BAD lseek %d\", file);\n\t\treturn -1;\n\t}\n\treturn file_table[file].driver->lseek_r(r, file_table[file].arg, ptr, dir);\n}\n\nint _isatty(int file) {\n\tstruct _reent* r = _REENT;\n\tif (file < 0 || !gid_check(&file_table_gids, file)) {\n\t\tr->_errno = EBADF;\n\t\tkprintf(\"BAD isatty %d\", file);\n\t\treturn -1;\n\t}\n\treturn file_table[file].driver->isatty_r(r, file_table[file].arg);\n}\n\nint32_t fdctl(int file, const uint32_t action, void* const extra_arg) {\n\tif (file < 0 || !gid_check(&file_table_gids, file)) {\n\t\terrno = EBADF;\n\t\treturn -1;\n\t}\n\treturn file_table[file].driver->ctl(file_table[file].arg, action, extra_arg);\n}\n"
  },
  {
    "path": "src/system/envlock.c",
    "content": "/**\n * \\file system/envlock.c\n *\n * environment lock newlib stubs\n *\n * Contains implementations of environment-locking functions for newlib.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"rtos/task.h\"\n\nvoid __env_lock(void) {\n\trtos_suspend_all();\n}\n\nvoid __env_unlock(void) {\n\trtos_resume_all();\n}\n"
  },
  {
    "path": "src/system/hot.c",
    "content": "#include \"system/hot.h\"\n#include \"kapi.h\"\n#include \"v5_api.h\"\n\n// stored only in cold\nstruct hot_table __HOT_TABLE = {0};\nstruct hot_table* const HOT_TABLE = &__HOT_TABLE;\n\n#define MAGIC0 0x52616368\n#define MAGIC1 0x8CEF7310\n\nextern void set_get_timestamp_int_func(const int (*func)(void));\nstatic const int get_timestamp_int(void);\n\n__attribute__((section(\".hot_magic\"))) uint32_t MAGIC[] = {MAGIC0, MAGIC1};\nuint32_t const volatile* const MAGIC_ADDR = MAGIC;\n\n// The linker decides on these symbols in each section just as normal\n// When linking in hot, these pointers work just like any other weak symbol\n// Note: to get C++ style initialize and friends, we strip out cpp_initialize and friends so that linker\n// regenerates that function with the call to the correct (user-written) C++ version\nextern char const* _PROS_COMPILE_TIMESTAMP;\nextern char const* _PROS_COMPILE_DIRECTORY;\nextern const int   _PROS_COMPILE_TIMESTAMP_INT;\n\nextern unsigned __exidx_start;\nextern unsigned __exidx_end;\n\n// this expands to a bunch of:\n// extern void autonomous();\n#define FUNC(F) void F();\n#include \"system/user_functions/list.h\"\n#undef FUNC\n\n__attribute__((section(\".hot_init\"))) void install_hot_table(struct hot_table* const tbl) {\n\t// printf(\"Hot initializing\\n\");\n\ttbl->compile_timestamp = _PROS_COMPILE_TIMESTAMP;\n\ttbl->compile_directory = _PROS_COMPILE_DIRECTORY;\n\ttbl->__exidx_start = &__exidx_start;\n\ttbl->__exidx_end = &__exidx_end;\n\n// this expands to a bunch of:\n// tbl->functions.autonomous = autonomous;\n#define FUNC(F) tbl->functions.F = F;\n#include \"system/user_functions/list.h\"\n#undef FUNC\n\n\t// all of these weak symbols are given to us by the linker\n\t// These values should come from the hot region, since that's where this\n\t// function is linked\n\textern __attribute__((weak)) uint8_t* __sbss_start[];\n\textern __attribute__((weak)) uint8_t* __sbss_end[];\n\tmemset(__sbss_start, 0, (size_t)__sbss_end - (size_t)__sbss_start);\n\n\textern __attribute__((weak)) uint8_t* __bss_start[];\n\textern __attribute__((weak)) uint8_t* __bss_end[];\n\tmemset(__bss_start, 0, (size_t)__bss_end - (size_t)__bss_start);\n\n\textern __attribute__((weak)) void (*const __preinit_array_start[])(void);\n\textern __attribute__((weak)) void (*const __preinit_array_end[])(void);\n\tfor (void (*const* ctor)() = __preinit_array_start; ctor < __preinit_array_end; ctor++) {\n\t\t(*ctor)();\n\t}\n\n\textern __attribute__((weak)) void (*const __init_array_start[])(void);\n\textern __attribute__((weak)) void (*const __init_array_end[])(void);\n\tfor (void (*const* ctor)() = __init_array_start; ctor < __init_array_end; ctor++) {\n\t\t(*ctor)();\n\t}\n\n\t// Set the function pointer in newlib_stubs so that it can fetch the\n\t// timestamp in the hot package. \n\tset_get_timestamp_int_func(get_timestamp_int);\n}\n\n// this function really exists on the cold section! Called by pros_init\n// this does the check if we're running with hot/cold and invokes the hot table\n// installer (install_hot_table) located in hot memory\nvoid invoke_install_hot_table() {\n\t// install_hot_table is at 0x07800008\n\t// MAGIC_ADDR is at 0x0780000\n\t// printf(\"%s %p %p %x %x\\n\", __FUNCTION__, (void*)install_hot_table, (void*)HOT_TABLE, MAGIC_ADDR[0], MAGIC_ADDR[1]);\n\tif (vexSystemLinkAddrGet() == (uint32_t)0x03800000 && MAGIC_ADDR[0] == MAGIC0 && MAGIC_ADDR[1] == MAGIC1) {\n\t\tinstall_hot_table(HOT_TABLE);\n\t} else {\n\t\tmemset(HOT_TABLE, 0, sizeof(*HOT_TABLE));\n\t}\n}\n\n// This is a callback function used by newlib to get the unix timestamp\n// newlib cannot access any symbols in the hot package, so we have the hot\n// package pass a function pointer to this function. Newlib then uses that\n// function pointer. \nstatic const int get_timestamp_int(void) {\n\treturn _PROS_COMPILE_TIMESTAMP_INT;\n}\n"
  },
  {
    "path": "src/system/mlock.c",
    "content": "/**\n * \\file system/mlock.c\n *\n * memory lock newlib stubs\n *\n * Contains implementations of memory-locking functions for newlib.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"rtos/task.h\"\n\n void __malloc_lock(void) {\n \trtos_suspend_all();\n }\n\n void __malloc_unlock(void) {\n \trtos_resume_all();\n }\n"
  },
  {
    "path": "src/system/newlib_stubs.c",
    "content": "/**\n * \\file system/newlib_stubs.c\n *\n * Port of newlib to PROS for the V5\n *\n * Contains the various methods needed to enable standard C library support\n * through the use of the Arm-distributed implementation of newlib.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <errno.h>\n#include <stdint.h>\n#include <sys/time.h>\n#include <unistd.h>\n#include <stdio.h>\n\n#include \"rtos/task.h\"\n#include \"v5_api.h\"\n\n#include \"hot.h\"\n#include \"pros/misc.h\"\n\n#define SEC_TO_MSEC 1000\n#define SEC_TO_MICRO 1000000\n#define MICRO_TO_NANO 1000\n\nvoid _exit(int status) {\n\textern void flush_output_streams();\n\tflush_output_streams();\n\textern void ser_output_flush();\n\tser_output_flush();\n\trtos_suspend_all();\n\tif(status != 0) dprintf(3, \"Error %d\\n\", status); // kprintf\n\tuint32_t start_time = millis();\n\tstatic const uint32_t max_flush_time = 50;\n\twhile (vexSerialWriteFree(1) != 2048 || millis() - start_time > max_flush_time) {\n\t\tvexBackgroundProcessing();\n\t}\n\tvexSystemExitRequest();\n\twhile (1) vexBackgroundProcessing();\n}\n\nint usleep( useconds_t period ) {\n\t// Compromise: If the delay is in microsecond range, it will block threads.\n\t// if not, it will not block threads but not be accurate to the microsecond range.\n\tif(period >= 1000) {\n\t\ttask_delay (period / SEC_TO_MSEC);\n\t\treturn 0;\n\t}\n\tuint64_t endTime = vexSystemHighResTimeGet() + period;\n\twhile(vexSystemHighResTimeGet() < endTime) asm(\"YIELD\");\n\treturn 0;\n}\n\nunsigned sleep( unsigned period ) {\n\ttask_delay(period * SEC_TO_MSEC);\n\treturn 1;\n}\n\nint getentropy(void *_buffer, size_t _length) {\n\terrno = ENOSYS;\n\treturn -1;\n}\n\n// HACK: this helps confused libc++ functions call the right instruction. for\n// info see https://github.com/purduesigbots/pros/issues/153#issuecomment-519335375\n#pragma GCC diagnostic push\n#pragma GCC diagnostic ignored \"-Winfinite-recursion\"\nvoid __sync_synchronize(void) {\n\t__sync_synchronize();\n}\n#pragma GCC diagnostic pop\n\n// These variables are used to store the user-set time.\n// When user_time_set is false, the realtime clock will use the timestamp as the\n// base time. When it is true will use user_time_spec as the base time instead.\n// set_microseconds stores the value of the microsecond timer when the user set\n// the time.\nstatic bool user_time_set = false;\nstatic struct timespec user_time_spec;\nstatic int64_t set_microseconds = 0;\n\nint clock_settime(clockid_t clock_id, const struct timespec *tp) {\n\tif(tp == NULL) {\n\t\terrno = EINVAL;\n\t\treturn -1;\n\t}\n\n\tint retval = -1;\n\n\tswitch(clock_id) {\n\tcase CLOCK_REALTIME:\n\t\tuser_time_set = true;\n\t\tuser_time_spec\t = *tp;\n\t\tset_microseconds = vexSystemHighResTimeGet();\n\t\tretval = 0;\n\tdefault:\n\t\terrno = EINVAL;\n\t}\n\n\treturn retval;\n}\n\nint clock_gettime(clockid_t clock_id, struct timespec* tp) {\n\tif(tp == NULL) {\n\t\terrno = EINVAL;\n\t\treturn -1;\n\t}\n\n\tstruct timeval tv;\n\tint retval = -1;\n\n\tswitch (clock_id)\n\t{\n\tcase CLOCK_REALTIME:\n\t\tretval = gettimeofday(&tv, NULL);\n\t\tif (!retval) TIMEVAL_TO_TIMESPEC(&tv, tp);\n\t\tbreak;\n\tcase CLOCK_MONOTONIC: {\n\t\tuint64_t totalTime = vexSystemHighResTimeGet();\n\t\tuint64_t secs = totalTime / SEC_TO_MICRO;\n\t\tuint64_t micros = totalTime - secs * SEC_TO_MICRO;\n\n\t\ttp->tv_sec = secs;\n\t\ttp->tv_nsec = micros * MICRO_TO_NANO;\n\t\tbreak;\n\t}\n\tdefault:\n\t\terrno = EINVAL;\n\t\tbreak;\n\t}\n\n\treturn retval;\n}\n\n// HACK:\n//\n// This function pointer serves as a callback so that _gettimeofday() can call\n// a function inside the hot package. Without this, _gettimeofday() cannot\n// access any symbols in the hot package (where _PROS_COMPILE_TIMESTAMP_INT \n// lives), and linker errors occur. \n//\n// When the hot package is initialized, it calls set_get_timestamp_int_func()\n// and sets the callback to a function that returns the unix timestamp.\n//\n// Essentially, when the hot process starts:\n//   1) Pass the get_timestamp_int_func to the cold package\n//   2) When the cold package (this library) needs to access the timestamp,\n//      call the callback\n//   3) Then the cold package \nstatic const int (*get_timestamp_int_func)(void) = NULL;\n\nvoid set_get_timestamp_int_func(const int (*func)(void))\n{\n\tget_timestamp_int_func = func;\n}\n\nint _gettimeofday(struct timeval* tp, void* tzvp) {\n\tif(get_timestamp_int_func == NULL) {\n\t\treturn -1;\n\t}\n\n\tif(user_time_set) {\n\t\ttp->tv_sec = user_time_spec.tv_sec;\n\t\ttp->tv_usec = user_time_spec.tv_nsec * 1000;\n\t\ttp->tv_usec += vexSystemHighResTimeGet() - set_microseconds;\n\t}\n\telse if (competition_is_connected()) {\n\t\t// TODO: update this to get the date/time through VexOS. Apparently,\n\t\t// the time is kept properly only when competition controls are\n\t\t// connected. I haven't had time to check or confirm this.\n\t\t//https://github.com/purduesigbots/pros/pull/127#issuecomment-1095361338\n\t\ttp->tv_sec = get_timestamp_int_func();\n\t\ttp->tv_usec = vexSystemHighResTimeGet();\n\t}\n\telse {\n\t\t// When competition isn't connected, the vex's date/time functions do\n\t\t// not work. Here we use a timestamp compiled into the program and then\n\t\t// add the number of microseconds the program has been running to get \n\t\t// the best estimate.\n\t\ttp->tv_sec = get_timestamp_int_func();\n\t\ttp->tv_usec = vexSystemHighResTimeGet();\n\t}\n\n\treturn 1;\n}\n"
  },
  {
    "path": "src/system/newlib_stubs_support.cpp",
    "content": "#include <cstdio>\n#include <iostream>\n\n// called by _exit in newlib_stubs.c\nextern \"C\" void flush_output_streams() {\n    fflush(stdout);\n    std::cout.flush();\n}"
  },
  {
    "path": "src/system/rtos_hooks.c",
    "content": "/**\n * \\file system/rtos_hooks.c\n *\n * FreeRTOS hooks for initialization and interrupts\n *\n * FreeRTOS requires some porting to each platform to handle certain tasks. This\n * file contains the various methods required to be implemented for FreeRTOS.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n#include \"pros/motors.h\"\n#include \"rtos/FreeRTOS.h\"\n#include \"rtos/semphr.h\"\n#include \"rtos/task.h\"\n#include \"rtos/tcb.h\"\n\n#include \"v5_api.h\"\n#include \"v5_color.h\"\n\n// Fast interrupt handler\nvoid FIQInterrupt() {\n\tvexSystemFIQInterrupt();\n}\n// Replacement for DataAbortInterrupt\nvoid DataAbortInterrupt() {\n\ttaskDISABLE_INTERRUPTS();\n\tregister int sp;\n\tasm(\"add %0,sp,#8\\n\" : \"=r\"(sp));\n\textern void report_fatal_error(uint32_t _sp, const char* error_name);\n\treport_fatal_error(sp, \"DATA ABORT EXCEPTION\");\n\tfor(uint8_t i = 1; i <= 21; i++) {\n\t\tmotor_move_voltage(i, 0);\n\t}\n\tfor (;;) {\n\t\tvexBackgroundProcessing();\n\t\textern void ser_output_flush();\n\t\tser_output_flush();\n\t}\n}\n// Replacement for PrefetchAbortInterrupt\nvoid PrefetchAbortInterrupt() {\n\ttaskDISABLE_INTERRUPTS();\n\tregister int sp;\n\tasm(\"add %0,sp,#8\\n\" : \"=r\"(sp));\n\textern void report_fatal_error(uint32_t _sp, const char* error_name);\n\treport_fatal_error(sp, \"PREFETCH ABORT EXCEPTION\");\n\tfor(uint8_t i = 1; i <= 21; i++) {\n\t\tmotor_move_voltage(i, 0);\n\t}\n\tfor (;;) {\n\t\tvexBackgroundProcessing();\n\t\textern void ser_output_flush();\n\t\tser_output_flush();\n\t}\n}\n\nvoid _boot() {\n\tvexSystemBoot();\n}\n\nextern void vPortInstallFreeRTOSVectorTable(void);\nvoid rtos_initialize() {\n\tvexSystemTimerStop();\n\n\tportDISABLE_INTERRUPTS();\n\n\tvPortInstallFreeRTOSVectorTable();\n\n\tvoid task_notify_when_deleting_init();\n\ttask_notify_when_deleting_init();\n}\n\nextern void FreeRTOS_Tick_Handler(void);\nvoid rtos_tick_interrupt_config() {\n\tvexSystemTimerReinitForRtos(portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT,\n\t                            (void (*)(void*))FreeRTOS_Tick_Handler);\n}\n\nvoid rtos_tick_interrupt_clear() {\n\tvexSystemTimerClearInterrupt();\n}\n\nvoid vApplicationFPUSafeIRQHandler(uint32_t ulICCIAR) {\n\tvexSystemApplicationIRQHandler(ulICCIAR);\n}\n\nvoid vInitialiseTimerForRunTimeStats(void) {\n\tvexSystemWatchdogReinitRtos();\n}\n\nvoid vApplicationMallocFailedHook(void) {\n\t// Called if a call to kmalloc() fails because there is insufficient free\n\t// memory available in the FreeRTOS heap.  kmalloc() is called internally by\n\t// FreeRTOS API functions that create tasks, queues, software timers, and\n\t// semaphores.  The size of the FreeRTOS heap is set by the\n\t// configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h.\n\ttaskDISABLE_INTERRUPTS();\n\n\tfor (;;)\n\t\t;\n}\n\nvoid vApplicationStackOverflowHook(task_t pxTask, char* pcTaskName) {\n\t(void)pcTaskName;\n\t(void)pxTask;\n\n\tvexSerialWriteBuffer(1, (uint8_t*)\"FATAL ERROR!! Task \", 19);\n\tvexSerialWriteBuffer(1, (uint8_t*)pcTaskName, 30);\n\tvexSerialWriteBuffer(1, (uint8_t*)\" overflowed its stack!\\n\", 23);\n\n\t// Run time stack overflow checking is performed if\n\t// configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook function is\n\t// called if a stack overflow is detected.\n\ttaskDISABLE_INTERRUPTS();\n\tfor (;;) vexBackgroundProcessing();\n\t;\n}\n\nvoid vApplicationIdleHook(void) {\n\tvolatile size_t xFreeHeapSpace;\n\n\t// This is just a trivial example of an idle hook.  It is called on each cycle\n\t// of the idle task.  It must *NOT* attempt to block.  In this case the idle\n\t// task just queries the amount of FreeRTOS heap that remains.  See the memory\n\t// management section on the http://www.FreeRTOS.org web site for memory\n\t// management options.  If there is a lot of heap memory free then the\n\t// configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\n\t// RAM.\n\txFreeHeapSpace = xPortGetFreeHeapSize();\n\n\t// Remove compiler warning about xFreeHeapSpace being set but never used.\n\t(void)xFreeHeapSpace;\n}\n\nvoid vAssertCalled(const char* pcFile, unsigned long ulLine) {\n\tvolatile unsigned long ul = 0;\n\n\t(void)pcFile;\n\t(void)ulLine;\n\n\ttaskENTER_CRITICAL();\n\t{\n\t\t// Set ul to a non-zero value using the debugger to step out of\n\t\t// this function.\n\t\twhile (ul == 0) {\n\t\t\tportNOP();\n\t\t}\n\t}\n\ttaskEXIT_CRITICAL();\n}\n\n// FreeRTOS V9 now allows static memory allocation for tasks\n// the helper functions below are copied verbatim from demo code\n#if (configSUPPORT_STATIC_ALLOCATION == 1)\n// configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide\n// an implementation of vApplicationGetIdleTaskMemory() to provide the memory\n// that is used by the Idle task.\nvoid vApplicationGetIdleTaskMemory(static_task_s_t** ppxIdleTaskTCBBuffer, task_stack_t** ppxIdleTaskStackBuffer,\n                                   uint32_t* pulIdleTaskStackSize) {\n\t// If the buffers to be provided to the Idle task are declared inside this\n\t// function then they must be declared static - otherwise they will be\n\t// allocated on the stack and so not exists after this function exits.\n\tstatic static_task_s_t xIdleTaskTCB;\n\tstatic task_stack_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];\n\n\t// Pass out a pointer to the static_task_s_t structure in which the Idle\n\t// task's state will be stored.\n\t*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\n\n\t// Pass out the array that will be used as the Idle task's stack.\n\t*ppxIdleTaskStackBuffer = uxIdleTaskStack;\n\n\t// Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.\n\t// Note that, as the array is necessarily of type task_stack_t,\n\t// configMINIMAL_STACK_SIZE is specified in words, not bytes.\n\t*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;\n}\n\n// configSUPPORT_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so\n// the application must provide an implementation of\n// vApplicationGetTimerTaskMemory() to provide the memory that is used by the\n// Timer service task.\nvoid vApplicationGetTimerTaskMemory(static_task_s_t** ppxTimerTaskTCBBuffer, task_stack_t** ppxTimerTaskStackBuffer,\n                                    uint32_t* pulTimerTaskStackSize) {\n\t// If the buffers to be provided to the Timer task are declared inside this\n\t// function then they must be declared static - otherwise they will be\n\t// allocated on the stack and so not exists after this function exits.\n\tstatic static_task_s_t xTimerTaskTCB;\n\tstatic task_stack_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH];\n\n\t// Pass out a pointer to the static_task_s_t structure in which the Timer\n\t// task's state will be stored.\n\t*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\n\n\t// Pass out the array that will be used as the Timer task's stack.\n\t*ppxTimerTaskStackBuffer = uxTimerTaskStack;\n\n\t// Pass out the size of the array pointed to by\n\t// *ppxTimerTaskStackBuffer. Note that, as the array is necessarily of type\n\t// task_stack_t, configMINIMAL_STACK_SIZE is specified in words, not bytes.\n\t*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\n}\n#endif\n\n/******************************************************************************/\n/**                      Replacements for mem functions                      **/\n/**                                                                          **/\n/** See https://goo.gl/cHUA9b for more details                               **/\n/** Unsure if necessary due to Arm's newlib optimization                     **/\n/******************************************************************************/\n#if 0\n#if (configUSE_TASK_FPU_SUPPORT == 2)\nvoid* memcpy(void* restrict out, void const* restrict in, size_t n) {\n  // modified GNU algorithm to copy a word at a time\n  uint32_t* restrict lout;\n  uint32_t const* restrict lin;\n\n  if (!((uint32_t)in & 0xFFFFFFFC) && !((uint32_t)out & 0xFFFFFFFC)) {\n    while(n >= sizeof(unt32_t)) {\n      *lout++ = *lin++;\n      n -= sizeof(uint32_t);\n    }\n  }\n}\nvoid* memcpy(void *pvDest, void const *pvSource, size_t len) {\n  long *plDst = (long *)pvDest;\n  long const *plSrc = (long const *)pvSource;\n\n  if (!((uint32_t)pvSource & 0xFFFFFFFC) && !((uint32_t)pvDest & 0xFFFFFFFC)) {\n    while (len >= 4) {\n      *plDst++ = *plSrc++;\n      len -= 4;\n    }\n  }\n\n  char *pcDst = (char *)plDst;\n  char const *pcSrc = (char const *)plSrc;\n\n  while (len--)\n    *pcDst++ = *pcSrc++;\n\n  return (pvDest);\n}\n\n/*-----------------------------------------------------------*/\n\nvoid *memset(void *pvDest, int iValue, size_t ulBytes) {\n  volatile unsigned char *pcDest = (unsigned char *)pvDest;\n\n  if (ulBytes > 0) {\n    do {\n      *pcDest++ = (unsigned char)iValue;\n    } while (--ulBytes != 0);\n  }\n\n  return pvDest;\n}\n\n/*-----------------------------------------------------------*/\n\nint memcmp(const void *pvMem1, const void *pvMem2, size_t ulBytes) {\n  const unsigned char *pucMem1 = pvMem1, *pucMem2 = pvMem2;\n  size_t x;\n\n  for (x = 0; x < ulBytes; x++) {\n    if (pucMem1[x] != pucMem2[x]) {\n      break;\n    }\n  }\n\n  return ulBytes - x;\n}\n#endif\n#endif\n"
  },
  {
    "path": "src/system/startup.c",
    "content": "/**\n * \\file system/startup.c\n *\n * Contains the main startup code for PROS 3.0. main is called from vexStartup\n * code. Our main() initializes data structures and starts the FreeRTOS\n * scheduler.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <stdio.h>\n\n#include \"kapi.h\"\n#include \"v5_api.h\"\n\nextern void rtos_initialize();\nextern void vfs_initialize();\nextern void system_daemon_initialize();\nextern void graphical_context_daemon_initialize(void);\nextern __attribute__((weak)) void display_initialize(void) {}\nextern void rtos_sched_start();\nextern void vdml_initialize();\nextern void invoke_install_hot_table();\n\n// XXX: pros_init happens inside __libc_init_array, and before any global\n// C++ constructors are invoked. This is accomplished by instructing\n// GCC to include this function in the __init_array. The 102 argument\n// gives the compiler instructions on the priority of the constructor,\n// from 0-~65k. The first 0-100 priorities are reserved for language\n// implementation. Priority 101 is not used to allow functions such as\n// banner_enable to run before PROS initializes.\n__attribute__((constructor(102))) static void pros_init(void) {\n\trtos_initialize();\n\n\tvfs_initialize();\n\n\tvdml_initialize();\n\n\tgraphical_context_daemon_initialize();\n\n\tdisplay_initialize();\n\n\t// NOTE: this function should be called after all other initialize\n\t// functions. for an example of what could happen if this is not\n\t// the case, see\n\t// https://github.com/purduesigbots/pros/pull/144/#issuecomment-496901942\n\tsystem_daemon_initialize();\n\n\tinvoke_install_hot_table();\n}\n\nint main() {\n\trtos_sched_start();\n\n\tvexDisplayPrintf(10, 60, 1, \"failed to start scheduler\\n\");\n\n\tprintf(\"Failed to start Scheduler\\n\");\n\tfor (;;)\n\t\t;\n}\n"
  },
  {
    "path": "src/system/system_daemon.c",
    "content": "/**\n * \\file system/system_daemon.c\n *\n * Competition control daemon responsible for invoking the user tasks.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"kapi.h\"\n#include \"system/optimizers.h\"\n#include \"system/user_functions.h\"\n#include \"v5_api.h\"\n\nextern void vdml_background_processing();\n\nextern void port_mutex_take_all();\nextern void port_mutex_give_all();\n\nstatic task_stack_t competition_task_stack[TASK_STACK_DEPTH_DEFAULT];\nstatic static_task_s_t competition_task_buffer;\nstatic task_t competition_task;\n\nstatic task_stack_t system_daemon_task_stack[TASK_STACK_DEPTH_DEFAULT];\nstatic static_task_s_t system_daemon_task_buffer;\nstatic task_t system_daemon_task;\n\nstatic void _disabled_task(void* ign);\nstatic void _autonomous_task(void* ign);\nstatic void _opcontrol_task(void* ign);\nstatic void _competition_initialize_task(void* ign);\n\nstatic void _initialize_task(void* ign);\nstatic void _system_daemon_task(void* ign);\n\nenum state_task { E_OPCONTROL_TASK = 0, E_AUTON_TASK, E_DISABLED_TASK, E_COMP_INIT_TASK };\n\nchar task_names[4][32] = {\"User Operator Control (PROS)\", \"User Autonomous (PROS)\", \"User Disabled (PROS)\",\n                          \"User Comp. Init. (PROS)\"};\ntask_fn_t task_fns[4] = {_opcontrol_task, _autonomous_task, _disabled_task, _competition_initialize_task};\n\nextern void ser_output_flush(void);\n\n// does the basic background operations that need to occur every 2ms\nstatic inline void do_background_operations() {\n\tport_mutex_take_all();\n\tser_output_flush();\n\trtos_suspend_all();\n\tvexBackgroundProcessing();\n\trtos_resume_all();\n\tvdml_background_processing();\n\tport_mutex_give_all();\n}\n\nstatic void _system_daemon_task(void* ign) {\n\tuint32_t time = millis();\n\t// Initialize status to an invalid state to force an update the first loop\n\tuint32_t status = (uint32_t)(1 << 8);\n\tuint32_t task_state;\n\n\t// XXX: Delay likely necessary for shared memory to get copied over\n\t// (discovered b/c VDML would crash and burn)\n\t// Take all port mutexes to prevent user code from attempting to access VDML during this time. User code could be\n\t// running if a task is created from a global ctor\n\tport_mutex_take_all();\n\ttask_delay(2);\n\tport_mutex_give_all();\n\n\t// start up user initialize task. once the user initialize function completes,\n\t// the _initialize_task will notify us and we can go into normal competition\n\t// monitoring mode\n\tcompetition_task = task_create_static(_initialize_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT,\n\t                                      \"User Initialization (PROS)\", competition_task_stack, &competition_task_buffer);\n\n\ttime = millis();\n\twhile (!task_notify_take(true, 2)) {\n\t\t// wait for initialize to finish\n\t\tdo_background_operations();\n\t}\n\twhile (1) {\n\t\tdo_background_operations();\n\n\t\tif (unlikely(status != competition_get_status())) {\n\t\t\t// Have a new competition status, need to clean up whatever's running\n\t\t\tuint32_t old_status = status;\n\t\t\tstatus = competition_get_status();\n\t\t\tenum state_task state = E_OPCONTROL_TASK;\n\t\t\tif ((status & COMPETITION_DISABLED) && (old_status & COMPETITION_DISABLED)) {\n\t\t\t\t// Don't restart the disabled task even if other bits have changed (e.g. auton bit)\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// competition initialize runs only when entering disabled and we're\n\t\t\t// connected to competition control\n\t\t\tif ((status ^ old_status) & COMPETITION_CONNECTED &&\n\t\t\t    (status & (COMPETITION_DISABLED | COMPETITION_CONNECTED)) == (COMPETITION_DISABLED | COMPETITION_CONNECTED)) {\n\t\t\t\tstate = E_COMP_INIT_TASK;\n\t\t\t} else if (status & COMPETITION_DISABLED) {\n\t\t\t\tstate = E_DISABLED_TASK;\n\t\t\t} else if (status & COMPETITION_AUTONOMOUS) {\n\t\t\t\tstate = E_AUTON_TASK;\n\t\t\t}\n\n\t\t\ttask_state = task_get_state(competition_task);\n\t\t\t// delete the task only if it's in normal operation (e.g. not deleted)\n\t\t\t// The valid task states AREN'T deleted, invalid, or running (running\n\t\t\t// means it's the current task, which will never be the case)\n\t\t\tif (task_state == E_TASK_STATE_READY || task_state == E_TASK_STATE_BLOCKED ||\n\t\t\t    task_state == E_TASK_STATE_SUSPENDED) {\n\t\t\t\ttask_delete(competition_task);\n\t\t\t}\n\n\t\t\tcompetition_task = task_create_static(task_fns[state], NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT,\n\t\t\t                                      task_names[state], competition_task_stack, &competition_task_buffer);\n\t\t}\n\n\t\ttask_delay_until(&time, 2);\n\t}\n}\n\nvoid system_daemon_initialize() {\n\tsystem_daemon_task = task_create_static(_system_daemon_task, NULL, TASK_PRIORITY_MAX - 2, TASK_STACK_DEPTH_DEFAULT,\n\t                                        \"PROS System Daemon\", system_daemon_task_stack, &system_daemon_task_buffer);\n}\n\n// these functions are what actually get called by the system daemon, which\n// attempt to call whatever the user declares\n#define FUNC(NAME)                        \\\n\tstatic void _##NAME##_task(void* ign) { \\\n\t\tuser_##NAME();                        \\\n\t\ttask_notify(system_daemon_task);      \\\n\t}\n#include \"system/user_functions/c_list.h\"\n#undef FUNC\n"
  },
  {
    "path": "src/system/unwind.c",
    "content": "/**\n * unwind.c - Unwind functions specialized for PROS\n *\n * Unwinding is necessary in PROS because tasks containing C++ stack frames may\n * be arbitrarily stopped, requiring us to call all the destructors of the task\n * to be killed.\n *\n * \\Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include <malloc.h>\n#include <stdio.h>\n#include <unwind.h>\n\n#include \"unwind-arm-common.h\"\n\n#include \"rtos/task.h\"\n#include \"rtos/tcb.h\"\n#include \"system/hot.h\"\n\n#include \"v5_api.h\"\n\n/******************************************************************************/\n/**                           Helpful Unwind Files                           **/\n/*******************************************************************************\nhttps://github.com/gcc-mirror/gcc/blob/master/libgcc/unwind-arm-common.inc\nhttps://github.com/gcc-mirror/gcc/blob/master/libgcc/config/arm/unwind-arm.c\nhttps://github.com/gcc-mirror/gcc/blob/master/libgcc/config/arm/unwind-arm.h\nhttps://github.com/gcc-mirror/gcc/blob/master/gcc/ginclude/unwind-arm-common.h\nhttp://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf\n*******************************************************************************/\n\n/******************************************************************************/\n/**                            Unwind Definitions                            **/\n/**                                                                          **/\n/** These structs and extern'd functions come from unwind-arm.c              **/\n/******************************************************************************/\n#define R_SP 12\n#define R_LR 13\n#define R_PC 15\n\nstruct core_regs {\n\t_uw r[16];\n};\n\nstruct phase2_vrs {\n\t_uw demand_save_flags;\n\tstruct core_regs core;\n};\n\n// from unwind-arm-common.inc\nextern _Unwind_Reason_Code __gnu_Unwind_Backtrace(_Unwind_Trace_Fn, void*, struct phase2_vrs*);\n\n/******************************************************************************/\n/**                              Unwind Helpers                              **/\n/**                                                                          **/\n/** These functions and definitions are helpers for supporting PROS's usage  **/\n/** of unwinding                                                             **/\n/******************************************************************************/\nstatic inline void print_phase2_vrs(struct phase2_vrs* vrs) {\n\tstatic const char registers[16][4] = {\"r0\", \"r1\", \"r2\",  \"r3\",  \"r4\",  \"r5\", \"r6\", \"r7\",\n\t                                      \"r8\", \"r9\", \"r10\", \"r11\", \"r12\", \"sp\", \"lr\", \"pc\"};\n\tfor (size_t i = 0; i < 16; i++) {\n\t\tfprintf(stderr, \"%3s: 0x%08x \", registers[i], vrs->core.r[i]);\n\t\tif (i % 8 == 7) printf(\"\\n\");\n\t}\n\tfputs(\"\\n\", stderr);\n}\n\n// exidx is the table that tells the unwinder how to unwind a stack frame\n// for a PC. Under hot/cold, there's two tables and the unwinder was kind\n// enough to let us implement a function to give it a table for a PC so\n// support for hot/cold is as easy as it gets\nstruct __EIT_entry {\n\t_uw fnoffset;\n\t_uw content;\n};\n// these are all defined by the linker\nextern struct __EIT_entry __exidx_start;\nextern struct __EIT_entry __exidx_end;\nextern uint8_t start_of_cold_mem, end_of_cold_mem, start_of_hot_mem, end_of_hot_mem;\n\n_Unwind_Ptr __gnu_Unwind_Find_exidx(_Unwind_Ptr pc, int* nrec) {\n\t// check if pc is in the hot region\n\tif (HOT_TABLE && (void*)&start_of_hot_mem < (void*)pc && (void*)pc < (void*)&end_of_hot_mem) {\n\t\t*nrec = (struct __EIT_entry*)HOT_TABLE->__exidx_end - (struct __EIT_entry*)HOT_TABLE->__exidx_start;\n\t\treturn (_Unwind_Ptr)HOT_TABLE->__exidx_start;\n\t}\n\t// otherwise, we're in a monolith build or the cold region of a hot/cold build\n\t*nrec = &__exidx_end - &__exidx_start;\n\treturn (_Unwind_Ptr)&__exidx_start;\n}\n\nstruct trace_t {\n\tuint32_t pcs[20];\n\tsize_t size;\n\tbool truncated;\n};\n\n_Unwind_Reason_Code trace_fn(_Unwind_Context* unwind_ctx, void* d) {\n\tstruct trace_t* trace = (struct trace_t*)d;\n\tuint32_t pc = _Unwind_GetIP(unwind_ctx);\n\tfprintf(stderr, \"\\t%p\\n\", (void*)pc);\n\tif (trace) {\n\t\tif (trace->size < sizeof(trace->pcs) / sizeof(trace->pcs[0])) {\n\t\t\ttrace->pcs[trace->size++] = pc;\n\t\t} else {\n\t\t\ttrace->truncated = true;\n\t\t}\n\t}\n\textern void task_clean_up();\n\tif (pc == (uint32_t)task_clean_up) {\n\t\treturn _URC_FAILURE;\n\t}\n\treturn _URC_NO_REASON;\n}\n\n/******************************************************************************/\n/**                            Data Abort Handler                            **/\n/**                                                                          **/\n/** These functions use the __gnu_Unwind_* functions providing our helper    **/\n/** functions and phase2_vrs structure based on a target task                **/\n/******************************************************************************/\n// recover registers from a data abort. Specific knowledge about callee stack\n// used from FreeRTOS_DataAbortHandler and it calling DataAbortInterrupt\n// NOTE: this function needs to be compiled in ARM mode and not Thumb mode \n// (hence the attribute), due to the specific assembly used here, which is\n// not supported in Thumb mode.\n__attribute__((target(\"arm\")))\nvoid p2vrs_from_data_abort(_uw* sp, struct phase2_vrs* vrs) {\n\t// sp is stack pointer when FreeRTOS_DataAbortHandler invokes DataAbortInterrupt\n\tvrs->demand_save_flags = 0;\n\t// start pulling these registers off the stack\n\t// see xilinx_vectors.s:114 stmdb\tsp!,{r0-r3,r12,lr}\n\tvrs->core.r[0] = sp[0];\n\tvrs->core.r[1] = sp[1];\n\tvrs->core.r[2] = sp[2];\n\tvrs->core.r[3] = sp[3];\n\tvrs->core.r[4] = sp[-1];  // DataAbortInterrupt pushes this onto stack, so grab it back\n\t// r5-r11 were never touched, so we can just plop them in\n\tasm(\"stm %0!, {r5-r11}\\n\" : : \"r\"(vrs->core.r + 5));\n\tvrs->core.r[12] = sp[4];\n\t// sp/lr are in (banked) user registers. recover them from there. ref B9.3.17 of AARM for v7-a/r\n\tasm(\"stm %0, {r13,r14}^\" : : \"r\"(vrs->core.r + 13));\n\tvrs->core.r[15] = sp[5] - 8;\n}\n\n// called by DataAbortInterrupt and PrefetchAbortInterrupt in rtos_hooks.c\n//void report_data_abort(uint32_t _sp) {\nvoid report_fatal_error(uint32_t _sp, const char* error_name) {\n\tstruct phase2_vrs vrs;\n\tp2vrs_from_data_abort((_uw*)_sp, &vrs);\n\n\tfputs(\"\\n\\n\", stderr);\n\tfputs(error_name, stderr);\n\tfputs(\"\\n\\n\", stderr);\n\tvexDisplayForegroundColor(ClrWhite);\n\tvexDisplayBackgroundColor(ClrRed);\n\tvexDisplayRectClear(0, 25, 480, 200);\n\tvexDisplayString(2, error_name);\n\tvexDisplayString(3, \"PC: %x\", vrs.core.r[R_PC]);\n\n\tint brain_line_no = 4;\n\t\n\tif (pxCurrentTCB) {\n\t\tvexDisplayString(brain_line_no++, \"CURRENT TASK: %.32s\\n\", pxCurrentTCB->pcTaskName);\n\t\tfprintf(stderr, \"CURRENT TASK: %.32s\\n\", pxCurrentTCB->pcTaskName);\n\t}\n\n\tfputs(\"REGISTERS AT ERROR\\n\", stderr);\n\tprint_phase2_vrs(&vrs);\n\n\tfputs(\"BEGIN STACK TRACE\\n\", stderr);\n\tfprintf(stderr, \"\\t%p\\n\", (void*)vrs.core.r[R_PC]);\n\tstruct trace_t trace = {{0}, 0, false};\n\t__gnu_Unwind_Backtrace(trace_fn, &trace, &vrs);\n\tfputs(\"END OF TRACE\\n\", stderr);\n\n\tfor(size_t i = 0; i < trace.size; i += 4) {\n\t\tswitch (trace.size - i) {\n\t\t\tcase 1:\n\t\t\t\tvexDisplayString(brain_line_no++, \"TRACE: 0x%x\", trace.pcs[i]);\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tvexDisplayString(brain_line_no++, \"TRACE: 0x%x 0x%x\", trace.pcs[i], trace.pcs[i+1]);\n\t\t\t\tbreak;\n\t\t\tcase 3:\n\t\t\t\tvexDisplayString(brain_line_no++, \"TRACE: 0x%x 0x%x 0x%x\", trace.pcs[i], trace.pcs[i+1], trace.pcs[i+2]);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tvexDisplayString(brain_line_no++, \"TRACE: 0x%x 0x%x 0x%x 0x%x\", trace.pcs[i], trace.pcs[i+1], trace.pcs[i+2], trace.pcs[i+3]);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (trace.truncated) {\n\t\tvexDisplayString(brain_line_no++, \"Trace was truncated, see terminal for full trace\");\n\t}\n\tstruct mallinfo info = mallinfo();\n\tfprintf(stderr, \"HEAP USED: %d bytes\\n\", info.uordblks);\n\tif (pxCurrentTCB) {\n\t\tfprintf(stderr, \"STACK REMAINING AT ERROR: %lu bytes\\n\", vrs.core.r[R_SP] - (uint32_t)pxCurrentTCB->pxStack);\n\t}\n}\n\n/******************************************************************************/\n/**               Modified RTOS-Task Target Unwinder Functions               **/\n/**                                                                          **/\n/** These functions use the __gnu_Unwind_* functions providing our helper    **/\n/** functions and phase2_vrs structure based on a target task                **/\n/******************************************************************************/\n#define REGISTER_BASE 67\nstatic inline struct phase2_vrs p2vrs_from_task(task_t task) {\n\t// should be called with the task scheduler suspended\n\ttaskENTER_CRITICAL();\n\n\tTCB_t* tcb = (TCB_t*)task;\n\tsize_t i;\n\n\tstruct phase2_vrs vrs;\n\tif (tcb == NULL) {\n\t\ttcb = pxCurrentTCB;\n\t}\n\n\tvrs.demand_save_flags = 0;\n\tswitch (task_get_state(task)) {\n\t\tcase E_TASK_STATE_READY:\n\t\t\tfor (i = 0; i < 12; i++) {\n\t\t\t\tvrs.core.r[i] = tcb->pxTopOfStack[REGISTER_BASE + i];\n\t\t\t}\n\t\t\tvrs.core.r[13] = (_uw)(tcb->pxTopOfStack + REGISTER_BASE + 16);  // r13 is sp\n\t\t\tvrs.core.r[14] = tcb->pxTopOfStack[REGISTER_BASE + 13];          // r14 is lr\n\t\t\tvrs.core.r[15] = tcb->pxTopOfStack[REGISTER_BASE + 14];          // r15 is pc\n\t\t\tbreak;\n\t\tcase E_TASK_STATE_BLOCKED:\n\t\t\t// for(i = 0; i < 12; i++) {\n\t\t\t// \tvrs.core.r[i] = tcb->pxTopOfStack[REGISTER_BASE + i];\n\t\t\t// }\n\t\t\t// vrs.core.r[13] = (_uw)(tcb->pxTopOfStack + REGISTER_BASE + 29);\n\t\t\t// vrs.core.r[14] = tcb->pxTopOfStack[REGISTER_BASE + ]\n\t\t\tbreak;\n\t\tcase E_TASK_STATE_RUNNING:\n\t\t\tbreak;\n\t\tcase E_TASK_STATE_SUSPENDED:\n\t\t\tbreak;\n\t\tcase E_TASK_STATE_DELETED:  // will never happen\n\t\tcase E_TASK_STATE_INVALID:\n\t\tdefault:\n\t\t\tbreak;\n\t}\n\ttaskEXIT_CRITICAL();\n\treturn vrs;\n}\n\nvoid backtrace_task(task_t task) {\n\tstruct phase2_vrs vrs = p2vrs_from_task(task);\n\tprintf(\"Trace:\\n\");\n\t__gnu_Unwind_Backtrace(trace_fn, NULL, &vrs);\n\tprintf(\"finished trace\\n\");\n}\n"
  },
  {
    "path": "src/system/user_functions.c",
    "content": "#include \"system/user_functions.h\"\n#include \"kapi.h\"\n#include \"system/hot.h\"\n\n// how this all works...\n// system daemon starts an autonomous task which calls user_autonomous()\n// user_autonomous will invoke a hot-linked autonomous if one is available\n// The invoked autonomous may actually just invoke user_cpp_autonomous\n// which will invoke a C routine which calls C++ autonomous routine\n\n// Our weak functions call C++ links of these functions, allowing users to only optionally extern \"C\" the task functions\n// these are implemented in cpp_support.cpp\n// FUNC(cpp_autonomous) expands to:\n// extern void cpp_autonomous();\n#define FUNC(NAME) extern void NAME();\n#include \"system/user_functions/cpp_list.h\"\n#undef FUNC\n\n// default implementations of the different competition modes attempt to call\n// the C++ linkage version of the function\n// FUNC(autonomous) exapnds to:\n// __attribute__((weak)) void autonomous() { user_cpp_autonomous(); }\n#define FUNC(NAME)                    \\\n\t__attribute__((weak)) void NAME() { \\\n\t\tuser_cpp_##NAME();                \\\n\t}\n#include \"system/user_functions/c_list.h\"\n#undef FUNC\n\n// FUNC(cpp_autonomous) exapnds to:\n// void user_cpp_autonomous() {\n//   if(HOT_TABLE && HOT_TABLE->functions.cpp_autonomous) {\n//     HOT_TABLE->functions.cpp_autonomous();\n//   } else {\n//     cpp_autonomous();\n//   }\n// }\n#define FUNC(NAME)                                \\\n\tvoid user_##NAME() {                            \\\n\t\tif (HOT_TABLE && HOT_TABLE->functions.NAME) { \\\n\t\t\tHOT_TABLE->functions.NAME();                \\\n\t\t} else {                                      \\\n\t\t\tNAME();                                     \\\n\t\t}                                             \\\n\t}\n#include \"system/user_functions/list.h\"\n#undef FUNC\n"
  },
  {
    "path": "src/system/xilinx_vectors.s",
    "content": "/******************************************************************************\n*\n* (c) Copyright 2009-13 Xilinx, Inc. All rights reserved.\n*\n* This file contains confidential and proprietary information of Xilinx, Inc.\n* and is protected under U.S. and international copyright and other\n* intellectual property laws.\n*\n* DISCLAIMER\n* This disclaimer is not a license and does not grant any rights to the\n* materials distributed herewith. Except as otherwise provided in a valid\n* license issued to you by Xilinx, and to the maximum extent permitted by\n* applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE \"AS IS\" AND WITH ALL\n* FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,\n* IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF\n* MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;\n* and (2) Xilinx shall not be liable (whether in contract or tort, including\n* negligence, or under any other theory of liability) for any loss or damage\n* of any kind or nature related to, arising under or in connection with these\n* materials, including for any direct, or any indirect, special, incidental,\n* or consequential loss or damage (including loss of data, profits, goodwill,\n* or any type of loss or damage suffered as a result of any action brought by\n* a third party) even if such damage or loss was reasonably foreseeable or\n* Xilinx had been advised of the possibility of the same.\n*\n* CRITICAL APPLICATIONS\n* Xilinx products are not designed or intended to be fail-safe, or for use in\n* any application requiring fail-safe performance, such as life-support or\n* safety devices or systems, Class III medical devices, nuclear facilities,\n* applications related to the deployment of airbags, or any other applications\n* that could lead to death, personal injury, or severe property or\n* environmental damage (individually and collectively, \"Critical\n* Applications\"). Customer assumes the sole risk and liability of any use of\n* Xilinx products in Critical Applications, subject only to applicable laws\n* and regulations governing limitations on product liability.\n*\n* THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE\n* AT ALL TIMES.\n*\n******************************************************************************/\n/*****************************************************************************/\n/**\n* @file asm_vectors.s\n*\n* This file contains the initial vector table for the Cortex A9 processor\n*\n* <pre>\n* MODIFICATION HISTORY:\n*\n* Ver   Who     Date     Changes\n* ----- ------- -------- ---------------------------------------------------\n* 1.00a ecm/sdm 10/20/09 Initial version\n* 3.05a sdm\t02/02/12 Save lr when profiling is enabled\n* 3.10a srt     04/18/13 Implemented ARM Erratas. Please refer to file\n*\t\t\t 'xil_errata.h' for errata description\n* </pre>\n*\n* @note\n*\n* None.\n*\n******************************************************************************/\n\n//#include \"xil_errata.h\"\n#define  CONFIG_ARM_ERRATA_775420  1\n\n.org 0\n.text\n.arm\n\n.global _boot\n.global _freertos_vector_table\n\n.global FIQInterrupt\n.global DataAbortInterrupt\n.global PrefetchAbortInterrupt\n.global vPortInstallFreeRTOSVectorTable\n\n.extern FreeRTOS_IRQ_Handler\n.extern FreeRTOS_SWI_Handler\n\n.section .freertos_vectors\n_freertos_vector_table:\n\tB\t  _boot\n\tB\t  FreeRTOS_Undefined\n\tldr   pc, _swi\n\tB\t  FreeRTOS_PrefetchAbortHandler\n\tB\t  FreeRTOS_DataAbortHandler\n\tNOP\t  /* Placeholder for address exception vector*/\n\tLDR   PC, _irq\n\tB\t  FreeRTOS_FIQHandler\n\n_irq:   .word FreeRTOS_IRQ_Handler\n_swi:   .word FreeRTOS_SWI_Handler\n\n\n.align 4\nFreeRTOS_FIQHandler:\t\t\t/* FIQ vector handler */\n\tstmdb\tsp!,{r0-r3,r12,lr}\t/* state save from compiled code */\nFIQLoop:\n\tblx\tFIQInterrupt\t\t\t/* FIQ vector */\n\tldmia\tsp!,{r0-r3,r12,lr}\t/* state restore from compiled code */\n\tsubs\tpc, lr, #4\t\t\t/* adjust return */\n\n.align 4\nFreeRTOS_Undefined:\t\t\t\t/* Undefined handler */\n\tb\t\t.\n\n.align 4\nFreeRTOS_DataAbortHandler:\t\t/* Data Abort handler */\n#ifdef CONFIG_ARM_ERRATA_775420\n\tdsb\n#endif\n\tstmdb\tsp!,{r0-r3,r12,lr}\t/* state save from compiled code */\n\tblx\tDataAbortInterrupt\t\t/*DataAbortInterrupt :call C function here */\n\tldmia\tsp!,{r0-r3,r12,lr}\t/* state restore from compiled code */\n\tsubs\tpc, lr, #4\t\t\t/* adjust return */\n\n.align 4\nFreeRTOS_PrefetchAbortHandler:\t/* Prefetch Abort handler */\n#ifdef CONFIG_ARM_ERRATA_775420\n\tdsb\n#endif\n\tstmdb\tsp!,{r0-r3,r12,lr}\t/* state save from compiled code */\n\tblx\tPrefetchAbortInterrupt\t/* PrefetchAbortInterrupt: call C function here */\n\tldmia\tsp!,{r0-r3,r12,lr}\t/* state restore from compiled code */\n\tsubs\tpc, lr, #4\t\t\t/* adjust return */\n\n.align 4\n.type vPortInstallFreeRTOSVectorTable, %function\nvPortInstallFreeRTOSVectorTable:\n\n\t/* Set VBAR to the vector table that contains the FreeRTOS handlers. */\n\tldr\tr0, =_freertos_vector_table\n\tmcr\tp15, 0, r0, c12, c0, 0\n\tdsb\n\tisb\n\tbx lr\n\n\n.end\n"
  },
  {
    "path": "src/tests/adi.cpp",
    "content": "/**\n * \\file tests/adi.cpp\n *\n * Test code for various ADI things\n *\n * NOTE: There should also be a call to the constructor for the gyroscope object\n * in initialize() for calibration to occur before the opcontrol code.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n#include \"main.h\"\nvoid opcontrol() {\n\tpros::ADIGyro gyro ('c', 1/1.8);\n\tpros::ADIDigitalIn dig (4);\n\tpros::ADIEncoder enc (5, 6, true);\n\tuint32_t now = pros::millis();\n \twhile (true) {\n \t\tif (dig.get_new_press())\n\t\t\tpros::lcd::print(4, \"here\");\n\t\tpros::lcd::print(2, \"%d\", enc.get_value());\n\t\tpros::lcd::print(1, \"%f\", gyro.get_value());\n\n \t\tif (pros::millis() - now > 5000) {\n \t\t\tgyro.reset();\n \t\t\tnow = pros::millis();\n \t\t}\n\n \t\tpros::delay(20);\n \t}\n }\n"
  },
  {
    "path": "src/tests/basic_test.c",
    "content": "#include \"main.h\"\n\nvoid my_task(void* ign) {\n\twhile (true) {\n\t\tprintf(\"There are %d objects\\n\", vision_get_object_count(20));\n\t\tdelay(20);\n\t}\n}\n\nvoid my_task2(void* ign) {\n\twhile (true) {\n\t\tint left = controller_get_analog(CONTROLLER_MASTER, ANALOG_LEFT_Y);\n\t\tint right = controller_get_analog(CONTROLLER_MASTER, ANALOG_RIGHT_Y);\n\t\tmotor_move(1, left);\n\t\tmotor_move(11, right);\n\t\tdelay(20);\n\t}\n}\n\nvoid opcontrol() {\n\ttask_create(my_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"My Task\");\n\t// task_create(my_task2, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"my Task 2\");\n\twhile (true) {\n\t\tint left = controller_get_analog(CONTROLLER_MASTER, ANALOG_LEFT_Y);\n\t\tint right = controller_get_analog(CONTROLLER_MASTER, ANALOG_RIGHT_Y);\n\t\t// printf(\"%d, %d\\n\", left, right);\n\t\tputs(\"Hello from opcontrol\");\n\t\tmotor_move(11, left);\n\t\tmotor_move(1, -right);\n\t\tdelay(20);\n\t}\n}\n"
  },
  {
    "path": "src/tests/basic_test.cpp",
    "content": "#include <iostream>\n#include \"main.h\"\n\nvoid my_task(void* str) {\n\tpros::Vision vision(20);\n\twhile (true) {\n\t\tstd::cout << (char*)str << std::endl;\n\t\tstd::cout << vision.get_object_count() << std::endl;\n\t\tpros::delay(20);\n\t}\n}\n\nvoid opcontrol() {\n\t{\n\t\tstd::string s = \"Hello world\";\n\t\tpros::Task t(my_task, (void*)(s.c_str()));\n\t}\n\twhile (true) {\n\t\tpros::Motor(11).move(pros::Controller(E_CONTROLLER_MASTER).get_analog(E_CONTROLLER_ANALOG_LEFT_Y));\n\t\tpros::Motor(1).move(-pros::Controller(E_CONTROLLER_MASTER).get_analog(E_CONTROLLER_ANALOG_RIGHT_Y));\n\t\tstd::puts(\"Hello from opcontrol\");\n\t\tpros::Task::delay(20);\n\t}\n}\n"
  },
  {
    "path": "src/tests/errno_reentrancy.c",
    "content": "#include <errno.h>\n#include \"api.h\"\n#include \"v5_api.h\"\n\nvoid task_a_fn(void* ign) {\n\tvexDisplayString(2, \"Errno from A is: %d\\n\", errno);\n\ttask_delay(1000);\n\terrno = ENOEXEC;\n\twhile (1) {\n\t\tvexDisplayString(2, \"Errno from A is: %d\\n\", errno);\n\t\ttask_delay(10);\n\t}\n}\n\nvoid task_b_fn(void* ign) {\n\twhile (1) {\n\t\tvexDisplayString(3, \"Errno from B is: %d\\n\", errno);\n\t\ttask_delay(10);\n\t}\n}\n\nvoid test_errno_reentrancy() {\n\ttask_create(task_a_fn, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"Task A\");\n\ttask_create(task_b_fn, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"Task B\");\n}\n"
  },
  {
    "path": "src/tests/exceptions.cpp",
    "content": "#include <stdexcept>\n#include <string>\n\n#include \"v5_api.h\"\n\n#include \"rtos/FreeRTOS.h\"\n#include \"rtos/task.h\"\n\nextern \"C\" void throw_it() {\n\tthrow std::runtime_error(\"RT err in function\");\n}\n\nextern \"C\" void test_exceptions() {\n\tvexDisplayErase();\n\tvexDisplayString(0, \"Starting test\");\n\tthrow_it();\n\tvexDisplayString(3, \"it didn't work\");\n}\n"
  },
  {
    "path": "src/tests/ext_adi.cpp",
    "content": "/**\n * \\file tests/ext_adi.cpp\n *\n * Test code for various External ADI things\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n#include \"main.h\"\nvoid opcontrol() {\n\tpros::ADIUltrasonic ultra({1, 'a', 'b'});\n\tpros::ADIButton button({1, 'c'});\n\tpros::ADIEncoder enc({1, 5, 6}, true);\n\tuint32_t now = pros::millis();\n\twhile (true) {\n\t\tpros::lcd::print(3, \"%d\", ultra.get_value());\n\t\tpros::lcd::print(2, \"%d\", button.get_value());\n\t\tpros::lcd::print(1, \"%d\", enc.get_value());\n\n\t\tpros::delay(20);\n\t}\n}\n"
  },
  {
    "path": "src/tests/generic_serial.cpp",
    "content": "/**\n * \\file tests/generic_serial.cpp\n *\n * Test code for the generic serial driver\n *\n * NOTE: There should be a cable plugged into ports 1 and 2, connecting\n * them together\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n#include \"main.h\"\n#include <stdarg.h>\n#include \"pros/apix.h\"\n\npros::Serial *serial_w = nullptr, *serial_r = nullptr;\n\nconstexpr bool VERBOSE_OUTPUT = false;\n\nconstexpr uint32_t BUF_SIZE = 65536;\nuint8_t out_buf[BUF_SIZE], in_buf[BUF_SIZE];\n\nvoid verbose_printf(const char *format, ...) {\n\tif (VERBOSE_OUTPUT) {\n\t\tva_list va;\n\t\tva_start(va, format);\n\t\tvprintf(format, va);\n\t\tva_end(va);\n\t}\n}\n\nbool test_send_recv_byte(const uint32_t interval, const uint32_t bytes) {\n\tprintf(\"%07d Starting send/recv byte test with an interval of %dms for %d bytes...\\n\", pros::millis(), interval, bytes);\n\n\tuint8_t count = 0, expected = 0;\n\tuint32_t last_send_time = 0, cur_time, recv_count = 0;\n\tbool pass = true;\n\n\tdo {\n\t\tcur_time = pros::millis();\n\n\t\tif (cur_time - last_send_time >= interval) {\n\t\t\tint32_t w = serial_w->write_byte(count);\n\t\t\tif (w == PROS_ERR) {\n\t\t\t\tpass = false;\n\t\t\t\tprintf(\"%07d Write failed with error %d\\n\", cur_time, errno);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (w) {\n\t\t\t\tcount++;\n\t\t\t\tlast_send_time = cur_time;\n\t\t\t}\n\t\t}\n\n\t\tint32_t read = serial_r->read_byte();\n\t\tif (read == PROS_ERR) {\n\t\t\tpass = false;\n\t\t\tprintf(\"%07d Read failed with error %d\\n\", cur_time, errno);\n\t\t\tbreak;\n\t\t}\n\t\telse if (read >= 0) {\n\t\t\tif (read != expected) {\n\t\t\t\tprintf(\"%07d ERR Read: 0x%02x, Expt: 0x%02x\\n\", cur_time, read, expected);\n\t\t\t\tpass = false;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tverbose_printf(\"%07d 0x%02x\\n\", cur_time, read);\n\t\t\t}\n\t\t\texpected++;\n\t\t\trecv_count++;\n\t\t}\n\n\t\tpros::delay(interval);\n\t} while (recv_count < bytes);\n\n\tif (pass)\n\t\tprintf(\"%07d PASS\\n\", pros::millis());\n\telse\n\t\tprintf(\"%07d FAIL\\n\", pros::millis());\n\n\treturn pass;\n}\n\nbool test_send_recv_block() {\n\tprintf(\"%07d Starting send/recv block test...\\n\", pros::millis());\n\n\tuint32_t written = 0, read = 0;\n\tbool pass = true;\n\n\tfor (uint32_t i = 0; i < BUF_SIZE; i++) {\n\t\tout_buf[i] = i;\n\t}\n\n\twhile (written < BUF_SIZE || read < BUF_SIZE) {\n\t\tuint32_t cur_time = pros::millis();\n\n\t\tint32_t r = serial_r->read(in_buf + read, BUF_SIZE - read);\n\t\tif (r == PROS_ERR) {\n\t\t\tpass = false;\n\t\t\tprintf(\"%07d Read failed with error %d\\n\", cur_time, errno);\n\t\t\tbreak;\n\t\t}\n\t\telse if (r) {\n\t\t\tverbose_printf(\"%07d R %d [\", cur_time, r);\n\t\t\tfor (int32_t i = 0; i < r; i++) {\n\t\t\t\tverbose_printf(\"%02x\", in_buf[read + i]);\n\t\t\t\tif (in_buf[read + i] != out_buf[read + i]) {\n\t\t\t\t\tpass = false;\n\t\t\t\t\tverbose_printf(\" (%02x)\", out_buf[read + i]);\n\t\t\t\t}\n\t\t\t\tif (i < r - 1)\n\t\t\t\t\tverbose_printf(\", \");\n\t\t\t}\n\t\t\tverbose_printf(\"]\\n\");\n\n\t\t\tread += r;\n\t\t}\n\n\t\tint32_t w = serial_w->write(out_buf + written, BUF_SIZE - written);\n\t\tif (w == PROS_ERR) {\n\t\t\tpass = false;\n\t\t\tprintf(\"%07d Write failed with error %d\\n\", cur_time, errno);\n\t\t\tbreak;\n\t\t}\n\t\telse if (w) {\n\t\t\tverbose_printf(\"%07d, W %d\\n\", cur_time, w);\n\t\t\twritten += w;\n\t\t}\n\n\t\tpros::delay(1);\n\t}\n\n\tif (pass)\n\t\tprintf(\"%07d PASS\\n\", pros::millis());\n\telse\n\t\tprintf(\"%07d FAIL\\n\", pros::millis());\n\n\treturn pass;\n}\n\nvoid set_baudrate(const int32_t baudrate) {\n\tprintf(\"%07d Setting baudrate to %d\\n\", pros::millis(), baudrate);\n\tserial_w->set_baudrate(baudrate);\n\tserial_r->set_baudrate(baudrate);\n}\n\nvoid flush() {\n\tserial_w->flush();\n\tpros::delay(100);\n\tserial_r->flush();\n}\n\nvoid init_ports(uint8_t write_port, uint8_t recv_port) {\n\tprintf(\"%07d Using port %d to write and %d to recv\\n\", pros::millis(), write_port, recv_port);\n\n\tif (serial_w != nullptr) delete serial_w;\n\tserial_w = new pros::Serial(write_port);\n\tif (serial_r != nullptr) delete serial_r;\n\tserial_r = new pros::Serial(recv_port);\n}\n\nbool run_tests() {\n\tflush();\n\tset_baudrate(115200);\n\tif (!test_send_recv_byte(5, 1000)) return false;\n\n\tflush();\n\tset_baudrate(230400);\n\tif (!test_send_recv_byte(2, 2500)) return false;\n\n\tfor (int i = 0; i < 5; i++) {\n\t\tflush();\n\t\tif (!test_send_recv_block()) return false;\n\t}\n\n\treturn true;\n}\n\nvoid opcontrol() {\n\tprintf(\"---Generic Serial Test---\\nPlease ensure a cable is plugged into port 1 and port 2, connecting them together\\n\\n%07d Starting serial tests...\\n\", pros::millis());\n\n\tinit_ports(1, 2);\n\tif (!run_tests()) return;\n\n\tinit_ports(2, 1);\n\tif (!run_tests()) return;\n\n\tprintf(\"%07d All tests passed!\\n\", pros::millis());\n}\n"
  },
  {
    "path": "src/tests/generic_serial_file.cpp",
    "content": "/**\n * \\file tests/generic_serial_file.cpp\n *\n * Test code for the generic serial filesystem driver\n *\n * NOTE: There should be a cable plugged into ports 1 and 2, connecting\n * them together\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n#include \"main.h\"\n#include <stdarg.h>\n#include \"pros/apix.h\"\n\nFILE *serial_w = nullptr, *serial_r = nullptr;\nchar serial_w_name[8], serial_r_name[8];\nint serial_w_port, serial_r_port;\n\nconstexpr bool VERBOSE_OUTPUT = false;\n\nconstexpr uint32_t BUF_SIZE = 65536;\nuint8_t out_buf[BUF_SIZE], in_buf[BUF_SIZE];\n\nvoid verbose_printf(const char *format, ...) {\n\tif (VERBOSE_OUTPUT) {\n\t\tva_list va;\n\t\tva_start(va, format);\n\t\tvprintf(format, va);\n\t\tva_end(va);\n\t}\n}\n\nbool test_send_recv_byte(const uint32_t interval, const uint32_t bytes) {\n\tprintf(\"%07d Starting send/recv byte test with an interval of %dms for %d bytes...\\n\", pros::millis(), interval, bytes);\n\n\tuint8_t count = 0, expected = 0;\n\tuint32_t last_send_time = 0, cur_time, recv_count = 0;\n\tbool pass = true;\n\n\tdo {\n\t\tcur_time = pros::millis();\n\n\t\tif (cur_time - last_send_time >= interval) {\n\t\t\tint32_t w = fputc(count, serial_w);\n\t\t\tfflush(serial_w);\n\t\t\tif (w == EOF) {\n\t\t\t\tpass = false;\n\t\t\t\tprintf(\"%07d Write failed with error %d\\n\", cur_time, errno);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (w == count) {\n\t\t\t\tcount++;\n\t\t\t\tlast_send_time = cur_time;\n\t\t\t}\n\t\t}\n\n\t\tint32_t read = fgetc(serial_r);\n\t\tif (read == EOF) {\n\t\t\tpass = false;\n\t\t\tprintf(\"%07d Read failed with error %d\\n\", cur_time, errno);\n\t\t\tbreak;\n\t\t}\n\t\telse {\n\t\t\tif (read != expected) {\n\t\t\t\tprintf(\"%07d ERR Read: 0x%02x, Expt: 0x%02x\\n\", cur_time, read, expected);\n\t\t\t\tpass = false;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tverbose_printf(\"%07d 0x%02x\\n\", cur_time, read);\n\t\t\t}\n\t\t\texpected++;\n\t\t\trecv_count++;\n\t\t}\n\n\t\tpros::delay(interval);\n\t} while (recv_count < bytes);\n\n\tif (pass)\n\t\tprintf(\"%07d PASS\\n\", pros::millis());\n\telse\n\t\tprintf(\"%07d FAIL\\n\", pros::millis());\n\n\treturn pass;\n}\n\nbool test_send_recv_block() {\n\tprintf(\"%07d Starting send/recv block test...\\n\", pros::millis());\n\n\tuint32_t written = 0, read = 0;\n\tbool pass = true;\n\n\tfor (uint32_t i = 0; i < BUF_SIZE; i++) {\n\t\tout_buf[i] = i;\n\t}\n\n\twhile (written < BUF_SIZE || read < BUF_SIZE) {\n\t\tuint32_t cur_time = pros::millis();\n\t\tint32_t free = pros::c::fdctl(fileno(serial_w), DEVCTL_FIONWRITE, NULL);\n\t\tint32_t w = fwrite(out_buf + written, 1, BUF_SIZE - written > free ? free : BUF_SIZE - written, serial_w);\n\t\tfflush(serial_w);\n\t\tif (w == EOF) {\n\t\t\tpass = false;\n\t\t\tprintf(\"%07d Write failed with error %d\\n\", cur_time, errno);\n\t\t\tbreak;\n\t\t}\n\t\telse if (w) {\n\t\t\tverbose_printf(\"%07d, W %d\\n\", cur_time, w);\n\t\t\twritten += w;\n\t\t}\n\n\t\tint32_t avail = pros::c::fdctl(fileno(serial_r), DEVCTL_FIONREAD, NULL);\n\t\tint32_t r = fread(in_buf + read, 1, BUF_SIZE - read > avail ? avail : BUF_SIZE - read, serial_r);\n\t\tif (r == EOF) {\n\t\t\tpass = false;\n\t\t\tprintf(\"%07d Read failed with error %d\\n\", cur_time, errno);\n\t\t\tbreak;\n\t\t}\n\t\telse if (r) {\n\t\t\tverbose_printf(\"%07d R %d [\", cur_time, r);\n\t\t\tfor (int32_t i = 0; i < r; i++) {\n\t\t\t\tverbose_printf(\"%02x\", in_buf[read + i]);\n\t\t\t\tif (in_buf[read + i] != out_buf[read + i]) {\n\t\t\t\t\tpass = false;\n\t\t\t\t\tverbose_printf(\" (%02x)\", out_buf[read + i]);\n\t\t\t\t}\n\t\t\t\tif (i < r - 1)\n\t\t\t\t\tverbose_printf(\", \");\n\t\t\t}\n\t\t\tverbose_printf(\"]\\n\");\n\n\t\t\tread += r;\n\t\t}\n\n\t\tpros::delay(1);\n\t}\n\n\tif (pass)\n\t\tprintf(\"%07d PASS\\n\", pros::millis());\n\telse\n\t\tprintf(\"%07d FAIL\\n\", pros::millis());\n\n\treturn pass;\n}\n\nvoid set_baudrate(const int32_t baudrate) {\n\tprintf(\"%07d Setting baudrate to %d\\n\", pros::millis(), baudrate);\n\tpros::c::fdctl(fileno(serial_w), DEVCTL_SET_BAUDRATE, (void *)baudrate);\n\tpros::c::fdctl(fileno(serial_r), DEVCTL_SET_BAUDRATE, (void *)baudrate);\n}\n\nvoid flush() {\n\tpros::c::serial_flush(serial_w_port);\n\tpros::delay(100);\n\tpros::c::serial_flush(serial_r_port);\n}\n\nvoid init_ports(uint8_t write_port, uint8_t recv_port) {\n\tprintf(\"%07d Using port %d to write and %d to recv\\n\", pros::millis(), write_port, recv_port);\n\n\tserial_w_port = write_port;\n\tif (serial_w != nullptr) fclose(serial_w);\n\tsprintf(serial_w_name, \"/dev/%d\", write_port);\n\tserial_w = fopen(serial_w_name, \"wb\");\n\tserial_r_port = recv_port;\n\tif (serial_r != nullptr) fclose(serial_r);\n\tsprintf(serial_r_name, \"/dev/%d\", recv_port);\n\tserial_r = fopen(serial_r_name, \"rb\");\n}\n\nbool run_tests() {\n\tflush();\n\tset_baudrate(115200);\n\tif (!test_send_recv_byte(5, 1000)) return false;\n\n\tflush();\n\tset_baudrate(230400);\n\tif (!test_send_recv_byte(2, 2500)) return false;\n\n\tfor (int i = 0; i < 5; i++) {\n\t\tflush();\n\t\tif (!test_send_recv_block()) return false;\n\t}\n\n\treturn true;\n}\n\nvoid opcontrol() {\n\tprintf(\"---Generic Serial Test---\\nPlease ensure a cable is plugged into port 1 and port 2, connecting them together\\n\\n%07d Starting serial tests...\\n\", pros::millis());\n\n\tinit_ports(1, 2);\n\tif (!run_tests()) return;\n\n\tinit_ports(2, 1);\n\tif (!run_tests()) return;\n\n\tprintf(\"%07d All tests passed!\\n\", pros::millis());\n}\n"
  },
  {
    "path": "src/tests/gyro.c",
    "content": "/**\n * \\file tests/gyro.c\n *\n * Test code for the gyroscope driver\n *\n * NOTE: There should also be a call to the constructor for the gyroscope object\n * in initialize() for calibration to occur before the opcontrol code.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n#include \"main.h\"\nvoid opcontrol() {\n\tmotor_pid_s_t pid = motor_convert_pid(1.0, 0.0001, 1.0, 2.0);\n\tlcd_print(2, \"%d %d %d %d\", pid.kp, pid.ki, pid.kd, pid.kf);\n\tmotor_set_vel_pid(1, pid);\n\tadi_gyro_t gyro = adi_gyro_init('c', 1 / 1.8);\n\tmotor_pid_full_s_t pidf = motor_get_vel_pid(1);\n\tlcd_print(3, \"%d %d %d %d\", pidf.kp, pidf.ki, pidf.kd, pidf.kf);\n\tuint32_t now = millis();\n\twhile (true) {\n\t\tlcd_print(1, \"%f\", adi_gyro_get(gyro));\n\n\t\tif (millis() - now > 5000) {\n\t\t\tadi_gyro_reset(gyro);\n\t\t\tnow = millis();\n\t\t}\n\t\tdelay(20);\n\t}\n}\n"
  },
  {
    "path": "src/tests/gyro.cpp",
    "content": "/**\n * \\file tests/gyro.cpp\n *\n * Test code for the gyroscope driver\n *\n * NOTE: There should also be a call to the constructor for the gyroscope object\n * in initialize() for calibration to occur before the opcontrol code.\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n#include \"main.h\"\nvoid opcontrol() {\n\tpros::Motor left_mtr(1);\n\tpros::motor_pid_s_t pid = pros::Motor::convert_pid(1.0, 0.0001, 1.0, 2.0);\n\tpros::lcd::print(2, \"%d %d %d %d\", pid.kp, pid.ki, pid.kd, pid.kf);\n\tleft_mtr.set_vel_pid(pid);\n\tpros::ADIGyro gyro('c', 1 / 1.8);\n\tpros::motor_pid_full_s_t pidf = left_mtr.get_vel_pid();\n\tpros::lcd::print(3, \"%d %d %d %d\", pidf.kp, pidf.ki, pidf.kd, pidf.kf);\n\tuint32_t now = pros::millis();\n\twhile (true) {\n\t\tpros::lcd::print(1, \"%f\", gyro.get_value());\n\n\t\tif (pros::millis() - now > 5000) {\n\t\t\tgyro.reset();\n\t\t\tnow = pros::millis();\n\t\t}\n\t\tpros::delay(20);\n\t}\n}\n"
  },
  {
    "path": "src/tests/mutexes.c",
    "content": "void test_mutex() {\n\tmutex_t mut = mutex_create();\n\n\tmutex_take(mut, TIMEOUT_MAX);\n\n\tmutex_give(mut);\n}\n"
  },
  {
    "path": "src/tests/pnuematics.cpp",
    "content": "#include \"main.h\"\n\n/**\n * A callback function for LLEMU's center button.\n *\n * When this callback is fired, it will toggle line 2 of the LCD text between\n * \"I was pressed!\" and nothing.\n */\n\nvoid on_center_button() {\n\tstatic bool pressed = false;\n\tpressed = !pressed;\n\tif (pressed) {\n\t\tpros::lcd::set_text(2, \"I was pressed!\");\n\t} else {\n\t\tpros::lcd::clear_line(2);\n\t}\n}\n\n/**\n * Runs initialization code. This occurs as soon as the program is started.\n *\n * All other competition modes are blocked by initialize; it is recommended\n * to keep execution time for this mode under a few seconds.\n */\nvoid initialize() {\n\tlvgl_init();\n\tpros::lcd::initialize();\n\tpros::lcd::set_text(1, \"Hello PROS User!\");\n\tpros::lcd::register_btn1_cb(on_center_button);\n\n}\n\n/**\n * Runs while the robot is in the disabled state of Field Management System or\n * the VEX Competition Switch, following either autonomous or opcontrol. When\n * the robot is enabled, this task will exit.\n */\nvoid disabled() {}\n\n/**\n * Runs after initialize(), and before autonomous when connected to the Field\n * Management System or the VEX Competition Switch. This is intended for\n * competition-specific initialization routines, such as an autonomous selector\n * on the LCD.\n *\n * This task will exit when the robot is enabled and autonomous or opcontrol\n * starts.\n */\nvoid competition_initialize() {}\n\n/**\n * Runs the user autonomous code. This function will be started in its own task\n * with the default priority and stack size whenever the robot is enabled via\n * the Field Management System or the VEX Competition Switch in the autonomous\n * mode. Alternatively, this function may be called in initialize or opcontrol\n * for non-competition testing purposes.\n *\n * If the robot is disabled or communications is lost, the autonomous task\n * will be stopped. Re-enabling the robot will restart the task, not re-start it\n * from where it left off.\n */\nvoid autonomous() {}\n\n/**\n * Runs the operator control code. This function will be started in its own task\n * with the default priority and stack size whenever the robot is enabled via\n * the Field Management System or the VEX Competition Switch in the operator\n * control mode.\n *\n * If no competition control is connected, this function will run immediately\n * following initialize().\n *\n * If the robot is disabled or communications is lost, the\n * operator control task will be stopped. Re-enabling the robot will restart the\n * task, not resume it from where it left off.\n */\nvoid opcontrol() {\n\tpros::Controller master(pros::E_CONTROLLER_MASTER);\n\n\tpros::adi::Pneumatics n('H', true);\n\n\twhile (true) {\n\t\tpros::lcd::print(0, \"%d %d %d\", (pros::lcd::read_buttons() & LCD_BTN_LEFT) >> 2,\n\t\t                 (pros::lcd::read_buttons() & LCD_BTN_CENTER) >> 1,\n\t\t                 (pros::lcd::read_buttons() & LCD_BTN_RIGHT) >> 0);\n\n\t\tif(master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_A)){\n\t\t\tprintf(\"Toggling Pnuematic\\n\");\n\t\t\tn.toggle();\n\t\t}\n\t\tif(master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_X)) {\n\t\t\tprintf(\"Extending Pnuematic\\n\");\n\t\t\tn.extend();\n\t\t}\n\t\tif(master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_B)) {\n\t\t\tprintf(\"Retracting Pnuematic\\n\");\n\t\t\tn.retract();\n\t\t}\n\t\tif(master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_Y)) {\n\t\t\tprintf(\"Pneumatic state is: %i\\n\", (int)n.get_state());\n\t\t}\n \n\t\tpros::delay(20);\n\t}\n}\n"
  },
  {
    "path": "src/tests/rtos_function_linking.c",
    "content": "/**\n * \\file tests/rtos_function_linking.c\n *\n * Test that all the FreeRTOS functions link correctly.\n *\n * Do not actually run this test - just make sure it compiles\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"api.h\"\n\nvoid x(void* ign) {}\nvoid test_all() {\n\ttask_delete(task_create(x, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"no name\"));\n\ttask_delay(1);\n\n\ttask_delay_until(NULL, 3);\n\n\ttask_get_priority(NULL);\n\n\ttask_set_priority(NULL, 4);\n\n\ttask_get_state(NULL);\n\n\ttask_suspend(NULL);\n\ttask_resume(NULL);\n\n\ttask_get_count();\n\n\ttask_get_name(NULL);\n\n\ttask_get_by_name(\"Hello\");\n\n\ttask_notify(NULL);\n\n\ttask_notify_ext(NULL, 4, E_NOTIFY_ACTION_NONE, NULL);\n\n\ttask_notify_take(false, MAX_TIMEOUT);\n\n\ttask_notify_clear(NULL);\n\n\tmutex_t mutex = mutex_create();\n\tmutex_take(mutex, MAX_TIMEOUT);\n\tmutex_give(mutex);\n\n\tsem_t sem = sem_create(4, 0);\n\tsem_wait(sem, MAX_TIMEOUT);\n\tsem_post(sem);\n}\n"
  },
  {
    "path": "src/tests/segfault.cpp",
    "content": "#include \"main.h\"\n\n[[gnu::noinline]] static void thing_1(uint8_t i) {\n    printf(\"thing_1(%i)\\n\", i);\n    if (i == 0) {\n        asm volatile(\"mov r0, #0 \\n\\tSTR sp, [r0]\\n\\t\");\n    } else {\n        thing_1(i - 1);\n        printf(\"%s\", \"Never prints!\");\n    }\n}\n\n\n\n/**\n * Runs initialization code. This occurs as soon as the program is started.\n *\n * All other competition modes are blocked by initialize; it is recommended\n * to keep execution time for this mode under a few seconds.\n */\nvoid initialize() {\n  printf(\"%s\", \"Hello world!\");\n\tthing_1(10);\n}\n\nvoid disabled() {}\n\nvoid competition_initialize() {}\n\nvoid autonomous() {}\n\nvoid opcontrol() {}"
  },
  {
    "path": "src/tests/simple_names.c",
    "content": "/**\n * \\file tests/simple_names.c\n *\n * Test that all the PROS_USE_SIMPLE_NAMES definitions compile correctly\n *\n * Do not actually run this test - just make sure it compiles\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"main.h\"\n\nvoid opcontrol() {\n\t// ADI Simple Names\n\tadi_port_set_config(1, ADI_ANALOG_IN);\n\tadi_port_set_config(1, ADI_ANALOG_OUT);\n\tadi_port_set_config(1, ADI_DIGITAL_IN);\n\tadi_port_set_config(1, ADI_DIGITAL_OUT);\n\tadi_port_set_config(1, ADI_SMART_BUTTON);\n\tadi_port_set_config(1, ADI_SMART_POT);\n\tadi_port_set_config(1, ADI_LEGACY_BUTTON);\n\tadi_port_set_config(1, ADI_LEGACY_LINE_SENSOR);\n\tadi_port_set_config(1, ADI_LEGACY_LIGHT_SENSOR);\n\tadi_port_set_config(1, ADI_LEGACY_GYRO);\n\tadi_port_set_config(1, ADI_LEGACY_ACCELEROMETER);\n\tadi_port_set_config(1, ADI_LEGACY_SERVO);\n\tadi_port_set_config(1, ADI_LEGACY_PWM);\n\tadi_port_set_config(1, ADI_LEGACY_ENCODER);\n\tadi_port_set_config(1, ADI_LEGACY_ULTRASONIC);\n\tadi_port_set_config(1, ADI_TYPE_UNDEFINED);\n\tadi_port_set_config(1, ADI_ERR);\n\n\t// Misc Simple Names\n\tcontroller_is_connected(CONTROLLER_MASTER);\n\tcontroller_is_connected(CONTROLLER_PARTNER);\n\tcontroller_get_analog(CONTROLLER_MASTER, ANALOG_LEFT_X);\n\tcontroller_get_analog(CONTROLLER_MASTER, ANALOG_LEFT_Y);\n\tcontroller_get_analog(CONTROLLER_MASTER, ANALOG_RIGHT_X);\n\tcontroller_get_analog(CONTROLLER_MASTER, ANALOG_RIGHT_Y);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_L1);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_L2);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_R1);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_R2);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_UP);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_DOWN);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_LEFT);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_RIGHT);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_X);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_B);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_Y);\n\tcontroller_get_digital(CONTROLLER_MASTER, DIGITAL_A);\n\n\t// Motors Simple Names\n\tint result = motor_get_faults(1) & MOTOR_FAULT_NO_FAULTS;\n\tresult = motor_get_faults(1) & MOTOR_FAULT_MOTOR_OVER_TEMP;\n\tresult = motor_get_faults(1) & MOTOR_FAULT_DRIVER_FAULT;\n\tresult = motor_get_faults(1) & MOTOR_FAULT_OVER_CURRENT;\n\tresult = motor_get_faults(1) & MOTOR_FAULT_DRV_OVER_CURRENT;\n\tresult = motor_get_flags(1) & MOTOR_FLAGS_NONE;\n\tresult = motor_get_flags(1) & MOTOR_FLAGS_BUSY;\n\tresult = motor_get_flags(1) & MOTOR_FLAGS_ZERO_VELOCITY;\n\tresult = motor_get_flags(1) & MOTOR_FLAGS_ZERO_POSITION;\n\tmotor_set_brake_mode(1, MOTOR_BRAKE_COAST);\n\tmotor_set_brake_mode(1, MOTOR_BRAKE_BRAKE);\n\tmotor_set_brake_mode(1, MOTOR_BRAKE_HOLD);\n\tmotor_set_brake_mode(1, MOTOR_BRAKE_INVALID);\n\tmotor_set_encoder_units(1, MOTOR_ENCODER_DEGREES);\n\tmotor_set_encoder_units(1, MOTOR_ENCODER_ROTATIONS);\n\tmotor_set_encoder_units(1, MOTOR_ENCODER_COUNTS);\n\tmotor_set_encoder_units(1, MOTOR_ENCODER_INVALID);\n\tmotor_set_gearing(1, MOTOR_GEARSET_36);\n\tmotor_set_gearing(1, MOTOR_GEARSET_18);\n\tmotor_set_gearing(1, MOTOR_GEARSET_06);\n\tmotor_set_gearing(1, MOTOR_GEARSET_6);\n\tmotor_set_gearing(1, MOTOR_GEARSET_INVALID);\n\n\t// RTOS Simple Names\n\tint res = task_get_state(CURRENT_TASK) & TASK_STATE_RUNNING;\n\tres = task_get_state(CURRENT_TASK) & TASK_STATE_READY;\n\tres = task_get_state(CURRENT_TASK) & TASK_STATE_BLOCKED;\n\tres = task_get_state(CURRENT_TASK) & TASK_STATE_SUSPENDED;\n\tres = task_get_state(CURRENT_TASK) & TASK_STATE_DELETED;\n\tres = task_get_state(CURRENT_TASK) & TASK_STATE_INVALID;\n\ttask_notify_ext(CURRENT_TASK, 0, NOTIFY_ACTION_NONE, NULL);\n\ttask_notify_ext(CURRENT_TASK, 0, NOTIFY_ACTION_BITS, NULL);\n\ttask_notify_ext(CURRENT_TASK, 0, NOTIFY_ACTION_INCR, NULL);\n\ttask_notify_ext(CURRENT_TASK, 0, NOTIFY_ACTION_OWRITE, NULL);\n\ttask_notify_ext(CURRENT_TASK, 0, NOTIFY_ACTION_NO_OWRITE, NULL);\n\n\t// Vision Simple Names\n\tvision_object_s_t object;\n\tbool equal = object.type == VISION_OBJECT_NORMAL;\n\tequal = object.type == VISION_OBJECT_COLOR_CODE;\n\tequal = object.type == VISION_OBJECT_LINE;\n\tvision_set_zero_point(1, VISION_ZERO_TOPLEFT);\n\tvision_set_zero_point(1, VISION_ZERO_CENTER);\n}\n"
  },
  {
    "path": "src/tests/simple_names.cpp",
    "content": "/**\n * \\file tests/simple_names.cpp\n *\n * Test that all the PROS_USE_SIMPLE_NAMES definitions compile correctly\n *\n * Do not actually run this test - just make sure it compiles\n *\n * \\copyright Copyright (c) 2017-2026, Purdue University ACM SIGBots.\n * All rights reserved.\n *\n * This Source Code Form is subject to the terms of the Mozilla Public\n * License, v. 2.0. If a copy of the MPL was not distributed with this\n * file, You can obtain one at http://mozilla.org/MPL/2.0/.\n */\n\n#include \"main.h\"\n\nvoid opcontrol() {\n \t// ADI Simple Names\n\tpros::ADIPort test1 (1, ADI_ANALOG_IN);\n \tpros::ADIPort test2 (1, ADI_ANALOG_OUT);\n \tpros::ADIPort test3 (1, ADI_DIGITAL_IN);\n \tpros::ADIPort test4 (1, ADI_DIGITAL_OUT);\n \tpros::ADIPort test5 (1, ADI_SMART_BUTTON);\n \tpros::ADIPort test6 (1, ADI_SMART_POT);\n \tpros::ADIPort test7 (1, ADI_LEGACY_BUTTON);\n \tpros::ADIPort test8 (1, ADI_LEGACY_LINE_SENSOR);\n \tpros::ADIPort test9 (1, ADI_LEGACY_LIGHT_SENSOR);\n \tpros::ADIPort test10 (1, ADI_LEGACY_GYRO);\n \tpros::ADIPort test11 (1, ADI_LEGACY_ACCELEROMETER);\n \tpros::ADIPort test12 (1, ADI_LEGACY_SERVO);\n \tpros::ADIPort test13 (1, ADI_LEGACY_PWM);\n \tpros::ADIPort test14 (1, ADI_LEGACY_ENCODER);\n \tpros::ADIPort test15 (1, ADI_LEGACY_ULTRASONIC);\n \tpros::ADIPort test16 (1, ADI_TYPE_UNDEFINED);\n \tpros::ADIPort test17 (1, ADI_ERR);\n\n \t// Misc Simple Names\n\tpros::Controller master (CONTROLLER_MASTER);\n\tpros::Controller partner (CONTROLLER_PARTNER);\n \tmaster.get_analog(ANALOG_LEFT_X);\n \tmaster.get_analog(ANALOG_LEFT_Y);\n \tmaster.get_analog(ANALOG_RIGHT_X);\n \tmaster.get_analog(ANALOG_RIGHT_Y);\n \tmaster.get_digital(DIGITAL_L1);\n \tmaster.get_digital(DIGITAL_L2);\n \tmaster.get_digital(DIGITAL_R1);\n \tmaster.get_digital(DIGITAL_R2);\n \tmaster.get_digital(DIGITAL_UP);\n \tmaster.get_digital(DIGITAL_DOWN);\n \tmaster.get_digital(DIGITAL_LEFT);\n \tmaster.get_digital(DIGITAL_RIGHT);\n \tmaster.get_digital(DIGITAL_X);\n \tmaster.get_digital(DIGITAL_B);\n \tmaster.get_digital(DIGITAL_Y);\n \tmaster.get_digital(DIGITAL_A);\n\n \t// Motors Simple Names\n\tpros::Motor motor (1);\n \tint result = motor.get_faults() & MOTOR_FAULT_NO_FAULTS;\n \tresult = motor.get_faults() & MOTOR_FAULT_MOTOR_OVER_TEMP;\n \tresult = motor.get_faults() & MOTOR_FAULT_DRIVER_FAULT;\n \tresult = motor.get_faults() & MOTOR_FAULT_OVER_CURRENT;\n \tresult = motor.get_faults() & MOTOR_FAULT_DRV_OVER_CURRENT;\n \tresult = motor.get_flags() & MOTOR_FLAGS_NONE;\n \tresult = motor.get_flags() & MOTOR_FLAGS_BUSY;\n \tresult = motor.get_flags() & MOTOR_FLAGS_ZERO_VELOCITY;\n \tresult = motor.get_flags() & MOTOR_FLAGS_ZERO_POSITION;\n \tmotor.set_brake_mode(MOTOR_BRAKE_COAST);\n \tmotor.set_brake_mode(MOTOR_BRAKE_BRAKE);\n \tmotor.set_brake_mode(MOTOR_BRAKE_HOLD);\n \tmotor.set_brake_mode(MOTOR_BRAKE_INVALID);\n \tmotor.set_encoder_units(MOTOR_ENCODER_DEGREES);\n \tmotor.set_encoder_units(MOTOR_ENCODER_ROTATIONS);\n \tmotor.set_encoder_units(MOTOR_ENCODER_COUNTS);\n \tmotor.set_encoder_units(MOTOR_ENCODER_INVALID);\n \tmotor.set_gearing(MOTOR_GEARSET_36);\n \tmotor.set_gearing(MOTOR_GEARSET_18);\n \tmotor.set_gearing(MOTOR_GEARSET_06);\n \tmotor.set_gearing(MOTOR_GEARSET_6);\n \tmotor.set_gearing(MOTOR_GEARSET_INVALID);\n\n \t// RTOS Simple Names\n\tpros::Task task (CURRENT_TASK);\n \tint res = task.get_state() & TASK_STATE_RUNNING;\n \tres = task.get_state() & TASK_STATE_READY;\n \tres = task.get_state() & TASK_STATE_BLOCKED;\n \tres = task.get_state() & TASK_STATE_SUSPENDED;\n \tres = task.get_state() & TASK_STATE_DELETED;\n \tres = task.get_state() & TASK_STATE_INVALID;\n \ttask.notify_ext(0, NOTIFY_ACTION_NONE, NULL);\n \ttask.notify_ext(0, NOTIFY_ACTION_BITS, NULL);\n \ttask.notify_ext(0, NOTIFY_ACTION_INCR, NULL);\n \ttask.notify_ext(0, NOTIFY_ACTION_OWRITE, NULL);\n \ttask.notify_ext(0, NOTIFY_ACTION_NO_OWRITE, NULL);\n\n \t// Vision Simple Names\n \tpros::vision_object_s_t object;\n \tbool equal = object.type == VISION_OBJECT_NORMAL;\n \tequal = object.type == VISION_OBJECT_COLOR_CODE;\n \tequal = object.type == VISION_OBJECT_LINE;\n\tpros::Vision vision (1);\n \tvision.set_zero_point(VISION_ZERO_TOPLEFT);\n \tvision.set_zero_point(VISION_ZERO_CENTER);\n }\n"
  },
  {
    "path": "src/tests/static_tast_states.c",
    "content": "// This test is mostly verifying that the idle task isn't being starved\n\n#include <stdio.h>\n\n#include \"rtos/FreeRTOS.h\"\n#include \"rtos/task.h\"\n\n#define STACK_SIZE 0x2000\n\ntask_stack_t staticTaskStack[STACK_SIZE];\nstatic_task_s_t staticTaskTask;\ntask_t staticTaskHandle;\n\nvoid myStaticTask(void*);\n// the task_delay(5) SHOULD NOT BE REQUIRED but FreeRTOS is buggy af\nvoid myTask(void* ign) {\n\tprintf(\"myTask %d task_notify_take\\n\", __LINE__);\n\ttask_delay(10);\n\ttask_notify_take(true, 0xffffffffUL);\n\tprintf(\"myTask %d task_create_static\\n\", __LINE__);\n\ttask_delay(10);\n\ttask_create_static(myStaticTask, NULL, 8, STACK_SIZE, \"My Static Task\", staticTaskStack, &staticTaskTask);\n\tprintf(\"myTask %d task_delete\\n\", __LINE__);\n\ttask_delay(10);\n\ttask_delete(NULL);\n}\n\nvoid myStaticTask(void* ign) {\n\tprintf(\"myStaticTask %d task_create\\n\", __LINE__);\n\ttask_delay(10);\n\ttask_t task = task_create(myTask, NULL, 8, STACK_SIZE, \"My Task\");\n\tprintf(\"myStaticTask %d task_notify %p\\n\", __LINE__, task);\n\ttask_delay(10);\n\ttask_notify(task);\n\tprintf(\"myStaticTask %d task_delete\\n\", __LINE__);\n\ttask_delay(10);\n\ttask_delete(NULL);\n}\n\nvoid opcontrol() {\n\ttask_create_static(myStaticTask, NULL, 8, STACK_SIZE, \"My Static Task\", staticTaskStack, &staticTaskTask);\n}\n"
  },
  {
    "path": "src/tests/task_notify_when_deleting.c",
    "content": "#include \"main.h\"\n#include \"pros/apix.h\"\n\nvoid target_task(void* ignore) {\n\tlcd_print(0, \"%s says hello\", task_get_name(NULL));\n\ttask_delay(1000);\n\tlcd_print(0, \"I don't feel so good - %s\", task_get_name(NULL));\n}\n\nvoid notify_task(void* ignore) {\n\tlcd_set_text(2, \"I don't know - I don't know what's happening\");\n\ttask_notify_take(true, TIMEOUT_MAX);\n\tlcd_set_text(4, \"God damn you all to hell!\");\n}\n\nvoid opcontrol() {\n\ttask_t peter = task_create(target_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"Peter Parker\");\n\ttask_notify_when_deleting(peter, NULL, 1, E_NOTIFY_ACTION_BITS);\n\n\ttask_notify_take(true, TIMEOUT_MAX);\n\tlcd_set_text(1, \"Are you alright?\");\n\n\ttask_t peter2 = task_create(notify_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, \"Peter Parker's Son\");\n\t// task_delay(1000);\n\ttask_notify_when_deleting(NULL, peter2, 1, E_NOTIFY_ACTION_INCR);\n\t// task_delay(1000);\n\tlcd_set_text(3, \"Goodbye, cruel world!\");\n\t// task_delay(1000);\n}\n"
  },
  {
    "path": "src/tests/vision_test.cpp",
    "content": "#include \"main.h\"\n\nvoid opcontrol() {\n\tpros::Vision vis(10);\n\tpros::delay(2000);\n\tpros::vision_color_code_t code;\n\tcode = vis.create_color_code(1, 2, 3);\n\tprintf(\"%d\\n\", code);\n\twhile (true) {\n\t\tpros::vision_object_s_t obj_arr[5];\n\t\tvis.read_by_size(0, 5, obj_arr);\n\t\tfor(int i=0; i < 5; i++) {\n\t\t\tprintf(\"%o %d %d   \", obj_arr[i].signature, obj_arr[i].x_middle_coord, obj_arr[i].y_middle_coord);\n\t\t}\n\t\tprintf(\"\\n\");\n\t\tpros::delay(20);\n\t}\n}\n"
  },
  {
    "path": "template-Makefile",
    "content": "################################################################################\n######################### User configurable parameters #########################\n# filename extensions\nCEXTS:=c\nASMEXTS:=s S\nCXXEXTS:=cpp c++ cc\n\n# probably shouldn't modify these, but you may need them below\nROOT=.\nFWDIR:=$(ROOT)/firmware\nBINDIR=$(ROOT)/bin\nSRCDIR=$(ROOT)/src\nINCDIR=$(ROOT)/include\n\nWARNFLAGS+=\nEXTRA_CFLAGS=\nEXTRA_CXXFLAGS=\n\n# Set to 1 to enable hot/cold linking\nUSE_PACKAGE:=1\n\n# Add libraries you do not wish to include in the cold image here\n# EXCLUDE_COLD_LIBRARIES:= $(FWDIR)/your_library.a\nEXCLUDE_COLD_LIBRARIES:= \n\n# Set this to 1 to add additional rules to compile your project as a PROS library template\nIS_LIBRARY:=0\n# TODO: CHANGE THIS! \n# Be sure that your header files are in the include directory inside of a folder with the\n# same name as what you set LIBNAME to below.\nLIBNAME:=libbest\nVERSION:=1.0.0\n# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c\n# this line excludes opcontrol.c and similar files\nEXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/main,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext)))\n\n# files that get distributed to every user (beyond your source archive) - add\n# whatever files you want here. This line is configured to add all header files\n# that are in the directory include/LIBNAME\nTEMPLATE_FILES=$(INCDIR)/$(LIBNAME)/*.h $(INCDIR)/$(LIBNAME)/*.hpp\n\n.DEFAULT_GOAL=quick\n\n################################################################################\n################################################################################\n########## Nothing below this line should be edited by typical users ###########\n-include ./common.mk\n"
  },
  {
    "path": "template-gitignore",
    "content": "# Compiled Object files\n*.o\n*.obj\n\n# Executables\n*.bin\n*.elf\n\n# PROS\nbin/\n.vscode/\n.cache/\ncompile_commands.json\ntemp.log\ntemp.errors\n*.ini\n.d/"
  },
  {
    "path": "verify-symbols.sh",
    "content": "#!/usr/bin/env bash\n\n# when running this script, there should be nothing red or dark blue on the right panel (what's the in header files) with the following exceptions\n\n# the pros::c::* functions. They're #ifdef __cplusplus'd out into a namespace. The C linkages demonsrtate that it's fine\n# Default arguments exist in the constructor in the header file, but not in the implementation\n\nshopt -s globstar\n# Convenience script to manually verify that all functions in the public headers exist in the source directory\nvimdiff <(ctags --sort=yes --c-kinds=f --extra=-f+q --fields=S -f - src/**/* | awk '{if(index($0, \"signature:\")) print $1, substr($0, index($0, \"signature:\"))}' | sort ) <(ctags --sort=yes --c-kinds=p --extra=-f+q --fields=S -f - include/pros/**/* | awk '{if(index($0, \"signature:\")) print $1, substr($0, index($0, \"signature:\"))}' | sort)\n"
  },
  {
    "path": "version.py",
    "content": "from __future__ import print_function\nimport subprocess\nimport io\nimport os\n\ntry:\n    v = subprocess.check_output(['git', 'describe', '--dirty', '--abbrev']).decode().strip()\n    if '-' in v:\n        bv = v[:v.index('-')]\n        bv = bv[:bv.rindex('.') + 1] + str(int(bv[bv.rindex('.') + 1:]) + 1)\n        if os.environ.get('SYSTEM_PULLREQUEST_PULLREQUESTNUMBER', None):  # for Azure Pipelines PR builder\n            sempre = 'pr{}'.format(os.environ.get('SYSTEM_PULLREQUEST_PULLREQUESTNUMBER'))\n            build = os.environ.get('BUILD_BUILDID')\n        else:\n            sempre = 'dirty' if v.endswith('-dirty') else 'commit'\n            # pippre = 'alpha' if v.endswith('-dirty') else 'pre'\n            build = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode().strip()\n            number_since = subprocess.check_output(['git', 'rev-list', v[:v.index('-')] + '..HEAD', '--count']).decode().strip()\n            build = \"{}.{}\".format(number_since, build)\n        semver = bv + '-' + sempre + '.' + build\n    else:\n        semver = v\n\n    with open('version', 'w') as f:\n        print('Semantic version is ' + semver)\n        f.write(semver)\n\n    assert semver.count('.') >= 2\n    major, minor, patch = semver.split('.', 2)\n    patch = patch.split('-', 1)[0]\n    with io.open('include/pros/version.h', 'r', encoding='ascii') as file:\n        data = file.readlines()\n    for i, line in enumerate(data):\n        if '#define PROS_VERSION_MAJOR' in line:\n            data[i] = u'#define PROS_VERSION_MAJOR {}\\n'.format(major)\n        if '#define PROS_VERSION_MINOR' in line:\n            data[i] = u'#define PROS_VERSION_MINOR {}\\n'.format(minor)\n        if '#define PROS_VERSION_PATCH' in line:\n            data[i] = u'#define PROS_VERSION_PATCH {}\\n'.format(patch)\n        if '#define PROS_VERSION_STRING ' in line:\n            data[i] = u'#define PROS_VERSION_STRING \"{}\"\\n'.format(semver)\n    with io.open('include/pros/version.h', 'w', newline='\\n', encoding='ascii') as file:\n        file.writelines(data)\n\nexcept subprocess.CalledProcessError as e:\n    print('Error calling git')\n"
  }
]