Compare commits
2 commits
master
...
experiment
Author | SHA1 | Date | |
---|---|---|---|
|
384cae324f | ||
|
83cb660915 |
861 changed files with 20617 additions and 276021 deletions
|
@ -6,20 +6,4 @@
|
||||||
(c-file-style . "bsd")
|
(c-file-style . "bsd")
|
||||||
(c-basic-offset . 4)
|
(c-basic-offset . 4)
|
||||||
)
|
)
|
||||||
(asm-mode
|
|
||||||
(indent-tabs-mode . nil)
|
|
||||||
; this is basically a hack so asm-mode indents with spaces not tabs
|
|
||||||
; taken from http://stackoverflow.com/questions/2668563/emacs-indentation-in-asm-mode
|
|
||||||
; (moving to gas-mode may be a better choice)
|
|
||||||
(tab-stop-list (quote (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120)))
|
|
||||||
(asm-comment-char . "#")
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
; IMPORTANT: If you want to write assembly and have indenting to not be infuriating,
|
|
||||||
; you probably also want this in your .emacs file:
|
|
||||||
;
|
|
||||||
; (add-hook 'asm-mode-hook '(lambda () (setq indent-line-function 'indent-relative)))
|
|
||||||
;
|
|
||||||
; This is not safe to set as a local variable.
|
|
||||||
|
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -10,4 +10,3 @@ firmware
|
||||||
local.mk
|
local.mk
|
||||||
local.h
|
local.h
|
||||||
screenlog.*
|
screenlog.*
|
||||||
*.swp
|
|
||||||
|
|
51
.gitmodules
vendored
51
.gitmodules
vendored
|
@ -1,48 +1,7 @@
|
||||||
[submodule "lwip/lwip"]
|
[submodule "lwip/lwip"]
|
||||||
path = lwip/lwip
|
path = lwip/lwip
|
||||||
url = https://github.com/ourairquality/lwip.git
|
url = https://github.com/SuperHouse/esp-lwip.git
|
||||||
[submodule "extras/mbedtls/mbedtls"]
|
[submodule "axtls/axtls"]
|
||||||
path = extras/mbedtls/mbedtls
|
path = axtls/axtls
|
||||||
url = https://github.com/ARMmbed/mbedtls.git
|
url = https://github.com/SuperHouse/axtls.git
|
||||||
[submodule "extras/jsmn/jsmn"]
|
|
||||||
path = extras/jsmn/jsmn
|
|
||||||
url = https://github.com/zserge/jsmn.git
|
|
||||||
[submodule "bootloader/rboot"]
|
|
||||||
path = bootloader/rboot
|
|
||||||
url = https://github.com/raburton/rboot.git
|
|
||||||
[submodule "extras/spiffs/spiffs"]
|
|
||||||
path = extras/spiffs/spiffs
|
|
||||||
url = https://github.com/pellepl/spiffs.git
|
|
||||||
[submodule "tests/unity"]
|
|
||||||
path = tests/unity
|
|
||||||
url = https://github.com/ThrowTheSwitch/Unity.git
|
|
||||||
[submodule "tests/fs-test"]
|
|
||||||
path = tests/fs-test
|
|
||||||
url = https://github.com/sheinz/fs-test
|
|
||||||
[submodule "extras/bearssl/BearSSL"]
|
|
||||||
path = extras/bearssl/BearSSL
|
|
||||||
url = https://www.bearssl.org/git/BearSSL
|
|
||||||
[submodule "extras/http-parser/http-parser"]
|
|
||||||
path = extras/http-parser/http-parser
|
|
||||||
url = https://github.com/nodejs/http-parser
|
|
||||||
[submodule "extras/crc_generic/crc_lib"]
|
|
||||||
path = extras/crc_generic/crc_lib
|
|
||||||
url = https://github.com/Zaltora/crc_generic_lib.git
|
|
||||||
[submodule "extras/libesphttpd/libesphttpd"]
|
|
||||||
path = extras/libesphttpd/libesphttpd
|
|
||||||
url = https://github.com/nochkin/libesphttpd
|
|
||||||
[submodule "extras/libesphttpd/libesphttpd/lib/heatshrink"]
|
|
||||||
path = extras/libesphttpd/libesphttpd/lib/heatshrink
|
|
||||||
url = https://github.com/atomicobject/heatshrink
|
|
||||||
[submodule "extras/multipwm"]
|
|
||||||
path = extras/multipwm
|
|
||||||
url = https://github.com/nochkin/multipwm
|
|
||||||
[submodule "lvgl/lvgl"]
|
|
||||||
path = lvgl/lvgl
|
|
||||||
url = https://github.com/littlevgl/lvgl.git
|
|
||||||
[submodule "lvgl/lv_drivers"]
|
|
||||||
path = lvgl/lv_drivers
|
|
||||||
url = https://github.com/littlevgl/lv_drivers.git
|
|
||||||
[submodule "lvgl/lv_examples"]
|
|
||||||
path = lvgl/lv_examples
|
|
||||||
url = https://github.com/littlevgl/lv_examples.git
|
|
||||||
|
|
42
.travis.yml
42
.travis.yml
|
@ -2,15 +2,17 @@ language: c
|
||||||
sudo: false
|
sudo: false
|
||||||
env:
|
env:
|
||||||
# Target commit for https://github.com/pfalcon/esp-open-sdk/
|
# Target commit for https://github.com/pfalcon/esp-open-sdk/
|
||||||
OPENSDK_COMMIT=b069537
|
OPENSDK_COMMIT=b44afa47
|
||||||
CROSS_ROOT="${HOME}/toolchain-${OPENSDK_COMMIT}"
|
CROSS_ROOT="${HOME}/toolchain-${OPENSDK_COMMIT}"
|
||||||
CROSS_BINDIR="${CROSS_ROOT}/bin"
|
CROSS_BINDIR="${CROSS_ROOT}/bin"
|
||||||
CROSS="ccache xtensa-lx106-elf-"
|
ESPTOOL2_COMMIT=92530bb8
|
||||||
MAKE_CMD="make WARNINGS_AS_ERRORS=1 -C examples/ build-examples"
|
ESPTOOL2_BINDIR="${HOME}/esptool2-${ESPTOOL2_COMMIT}"
|
||||||
PATH=${PATH}:${CROSS_BINDIR}
|
PATH=${PATH}:${CROSS_BINDIR}:${ESPTOOL2_BINDIR}
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- ${CROSS_ROOT}
|
- ${CROSS_ROOT}
|
||||||
|
- ${HOME}/.ccache
|
||||||
|
- ${ESPTOOL2_BINDIR}
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
|
@ -29,22 +31,32 @@ addons:
|
||||||
- libncurses5-dev
|
- libncurses5-dev
|
||||||
- libexpat1-dev
|
- libexpat1-dev
|
||||||
- python
|
- python
|
||||||
- python-pip
|
- python-serial
|
||||||
- sed
|
- sed
|
||||||
- git
|
- git
|
||||||
- help2man
|
|
||||||
- vim-common
|
|
||||||
- zlib1g-dev
|
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- pip install --user pyserial
|
# Install a toolchain using esp-open-sdk (parts we need for this are the GNU toolchain and libhal)
|
||||||
- travis_wait 30 utils/travis_build/install_toolchain.sh
|
#
|
||||||
|
# Adds hack of "{$HAS_TC} || -Buildstep-" to avoid rebuilding toolchain if it's already
|
||||||
|
# installed from the cache. If this gets any more complex it should be spun out to a standalone shell script.
|
||||||
|
- export HAS_TC="test -d ${CROSS_BINDIR}"
|
||||||
|
- unset CC # Travis sets this due to "language: c", but it confuses autotools configure when cross-building
|
||||||
|
- ${HAS_TC} || git clone --recursive https://github.com/pfalcon/esp-open-sdk.git
|
||||||
|
- ${HAS_TC} || cd esp-open-sdk
|
||||||
|
- ${HAS_TC} || git reset --hard ${OPENSDK_COMMIT}
|
||||||
|
- ${HAS_TC} || git submodule update
|
||||||
|
- ${HAS_TC} || sed -i "s/2.69/2.68/" lx106-hal/configure.ac # this is a nasty hack as Ubuntu Precise only has autoconf 2.68 not 2.69...
|
||||||
|
- ${HAS_TC} || sed -r -i 's%TOOLCHAIN ?=.*%TOOLCHAIN=${CROSS_ROOT}%' Makefile
|
||||||
|
- ${HAS_TC} || make STANDALONE=n
|
||||||
|
- export HAS_ET2="test -f ${ESPTOOL2_BINDIR}/esptool2"
|
||||||
|
- ${HAS_ET2} || git clone https://github.com/raburton/esp8266 ${HOME}/raburton
|
||||||
|
- ${HAS_ET2} || make -C ${HOME}/raburton/esptool2
|
||||||
|
- ${HAS_ET2} || mkdir -p ${ESPTOOL2_BINDIR}
|
||||||
|
- ${HAS_ET2} || cp -a ${HOME}/raburton/esptool2/esptool2 ${ESPTOOL2_BINDIR}/
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- cd ${TRAVIS_BUILD_DIR}
|
- cd ${TRAVIS_BUILD_DIR}
|
||||||
# Remove ssid_config requirement for examples
|
# Remove ssid_config requirement for examples
|
||||||
- echo -e '#define WIFI_SSID "mywifissid"\n#define WIFI_PASS "my secret password"\n' > include/private_ssid_config.h
|
- sed -i "s%#warning%//#warning%" include/ssid_config.h
|
||||||
# Don't verbose-build all examples (too much output), only verbose-build errors
|
- make -C examples/ build-examples CROSS="ccache xtensa-lx106-elf-"
|
||||||
- ( ${MAKE_CMD} ) || ( ${MAKE_CMD} V=1 )
|
|
||||||
# build bootloader
|
|
||||||
- make -C bootloader/
|
|
||||||
|
|
|
@ -1,37 +1,440 @@
|
||||||
The FreeRTOS kernel is released under the MIT open source license, the text of
|
The FreeRTOS.org source code is licensed by the *modified* GNU General Public
|
||||||
which is provided below.
|
License (GPL), text provided below. A special exception to the GPL is
|
||||||
|
included to allow you to distribute a combined work that includes FreeRTOS
|
||||||
|
without being obliged to provide the source code for any proprietary
|
||||||
|
components. See the licensing section of http://www.FreeRTOS.org for full
|
||||||
|
details. The exception text is also included at the bottom of this file.
|
||||||
|
|
||||||
This license covers the FreeRTOS kernel source files, which are located in the
|
The FreeRTOS download also includes demo application source code, some of
|
||||||
/FreeRTOS/Source directory of the official FreeRTOS kernel download. It also
|
which is provided by third parties AND IS LICENSED SEPARATELY FROM FREERTOS.
|
||||||
covers most of the source files in the demo application projects, which are
|
|
||||||
located in the /FreeRTOS/Demo directory of the official FreeRTOS download. The
|
For the avoidance of any doubt refer to the comment included at the top
|
||||||
demo projects may also include third party software that is not part of FreeRTOS
|
of each source and header file for license and copyright information.
|
||||||
and is licensed separately to FreeRTOS. Examples of third party software
|
|
||||||
includes header files provided by chip or tools vendors, linker scripts,
|
This is a list of files for which Real Time Engineers Ltd are not the
|
||||||
peripheral drivers, etc. All the software in subdirectories of the /FreeRTOS
|
copyright owner and are NOT COVERED BY THE GPL.
|
||||||
directory is either open source or distributed with permission, and is free for
|
|
||||||
use. For the avoidance of doubt, refer to the comments at the top of each
|
|
||||||
source file.
|
|
||||||
|
|
||||||
|
|
||||||
License text:
|
1) Various header files provided by silicon manufacturers and tool vendors
|
||||||
-------------
|
that define processor specific memory addresses and utility macros.
|
||||||
|
Permission has been granted by the various copyright holders for these
|
||||||
|
files to be included in the FreeRTOS download. Users must ensure license
|
||||||
|
conditions are adhered to for any use other than compilation of the
|
||||||
|
FreeRTOS demo applications.
|
||||||
|
|
||||||
Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2) The uIP TCP/IP stack the copyright of which is held by Adam Dunkels.
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Users must ensure the open source license conditions stated at the top
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
of each uIP source file is understood and adhered to.
|
||||||
the Software without restriction, including without limitation the rights to
|
|
||||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
3) The lwIP TCP/IP stack the copyright of which is held by the Swedish
|
||||||
copies or substantial portions of the Software.
|
Institute of Computer Science. Users must ensure the open source license
|
||||||
|
conditions stated at the top of each lwIP source file is understood and
|
||||||
|
adhered to.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
4) Various peripheral driver source files and binaries provided by silicon
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
manufacturers and tool vendors. Permission has been granted by the
|
||||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
various copyright holders for these files to be included in the FreeRTOS
|
||||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
download. Users must ensure license conditions are adhered to for any
|
||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
use other than compilation of the FreeRTOS demo applications.
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
|
5) The files contained within FreeRTOS\Demo\WizNET_DEMO_TERN_186\tern_code,
|
||||||
|
which are slightly modified versions of code provided by and copyright to
|
||||||
|
Tern Inc.
|
||||||
|
|
||||||
|
Errors and omissions should be reported to Richard Barry, contact details for
|
||||||
|
whom can be obtained from http://www.FreeRTOS.org.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
The GPL license text follows.
|
||||||
|
|
||||||
|
A special exception to the GPL is included to allow you to distribute a
|
||||||
|
combined work that includes FreeRTOS without being obliged to provide
|
||||||
|
the source code for any proprietary components. See the licensing section
|
||||||
|
of http://www.FreeRTOS.org for full details. The exception text is also
|
||||||
|
included at the bottom of this file.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||||
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
License is intended to guarantee your freedom to share and change free
|
||||||
|
software--to make sure the software is free for all its users. This
|
||||||
|
General Public License applies to most of the Free Software
|
||||||
|
Foundation's software and to any other program whose authors commit to
|
||||||
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
|
the GNU Library General Public License instead.) You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
this service if you wish), that you receive source code or can get it
|
||||||
|
if you want it, that you can change the software or use pieces of it
|
||||||
|
in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
|
These restrictions translate to certain responsibilities for you if you
|
||||||
|
distribute copies of the software, or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must give the recipients all the rights that
|
||||||
|
you have. You must make sure that they, too, receive or can get the
|
||||||
|
source code. And you must show them these terms so they know their
|
||||||
|
rights.
|
||||||
|
|
||||||
|
We protect your rights with two steps: (1) copyright the software, and
|
||||||
|
(2) offer you this license which gives you legal permission to copy,
|
||||||
|
distribute and/or modify the software.
|
||||||
|
|
||||||
|
Also, for each author's protection and ours, we want to make certain
|
||||||
|
that everyone understands that there is no warranty for this free
|
||||||
|
software. If the software is modified by someone else and passed on, we
|
||||||
|
want its recipients to know that what they have is not the original, so
|
||||||
|
that any problems introduced by others will not reflect on the original
|
||||||
|
authors' reputations.
|
||||||
|
|
||||||
|
Finally, any free program is threatened constantly by software
|
||||||
|
patents. We wish to avoid the danger that redistributors of a free
|
||||||
|
program will individually obtain patent licenses, in effect making the
|
||||||
|
program proprietary. To prevent this, we have made it clear that any
|
||||||
|
patent must be licensed for everyone's free use or not licensed at all.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License applies to any program or other work which contains
|
||||||
|
a notice placed by the copyright holder saying it may be distributed
|
||||||
|
under the terms of this General Public License. The "Program", below,
|
||||||
|
refers to any such program or work, and a "work based on the Program"
|
||||||
|
means either the Program or any derivative work under copyright law:
|
||||||
|
that is to say, a work containing the Program or a portion of it,
|
||||||
|
either verbatim or with modifications and/or translated into another
|
||||||
|
language. (Hereinafter, translation is included without limitation in
|
||||||
|
the term "modification".) Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running the Program is not restricted, and the output from the Program
|
||||||
|
is covered only if its contents constitute a work based on the
|
||||||
|
Program (independent of having been made by running the Program).
|
||||||
|
Whether that is true depends on what the Program does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Program's
|
||||||
|
source code as you receive it, in any medium, provided that you
|
||||||
|
conspicuously and appropriately publish on each copy an appropriate
|
||||||
|
copyright notice and disclaimer of warranty; keep intact all the
|
||||||
|
notices that refer to this License and to the absence of any warranty;
|
||||||
|
and give any other recipients of the Program a copy of this License
|
||||||
|
along with the Program.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and
|
||||||
|
you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Program or any portion
|
||||||
|
of it, thus forming a work based on the Program, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) You must cause the modified files to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
b) You must cause any work that you distribute or publish, that in
|
||||||
|
whole or in part contains or is derived from the Program or any
|
||||||
|
part thereof, to be licensed as a whole at no charge to all third
|
||||||
|
parties under the terms of this License.
|
||||||
|
|
||||||
|
c) If the modified program normally reads commands interactively
|
||||||
|
when run, you must cause it, when started running for such
|
||||||
|
interactive use in the most ordinary way, to print or display an
|
||||||
|
announcement including an appropriate copyright notice and a
|
||||||
|
notice that there is no warranty (or else, saying that you provide
|
||||||
|
a warranty) and that users may redistribute the program under
|
||||||
|
these conditions, and telling the user how to view a copy of this
|
||||||
|
License. (Exception: if the Program itself is interactive but
|
||||||
|
does not normally print such an announcement, your work based on
|
||||||
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Program,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Program, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Program.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Program
|
||||||
|
with the Program (or with a work based on the Program) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may copy and distribute the Program (or a work based on it,
|
||||||
|
under Section 2) in object code or executable form under the terms of
|
||||||
|
Sections 1 and 2 above provided that you also do one of the following:
|
||||||
|
|
||||||
|
a) Accompany it with the complete corresponding machine-readable
|
||||||
|
source code, which must be distributed under the terms of Sections
|
||||||
|
1 and 2 above on a medium customarily used for software interchange; or,
|
||||||
|
|
||||||
|
b) Accompany it with a written offer, valid for at least three
|
||||||
|
years, to give any third party, for a charge no more than your
|
||||||
|
cost of physically performing source distribution, a complete
|
||||||
|
machine-readable copy of the corresponding source code, to be
|
||||||
|
distributed under the terms of Sections 1 and 2 above on a medium
|
||||||
|
customarily used for software interchange; or,
|
||||||
|
|
||||||
|
c) Accompany it with the information you received as to the offer
|
||||||
|
to distribute corresponding source code. (This alternative is
|
||||||
|
allowed only for noncommercial distribution and only if you
|
||||||
|
received the program in object code or executable form with such
|
||||||
|
an offer, in accord with Subsection b above.)
|
||||||
|
|
||||||
|
The source code for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For an executable work, complete source
|
||||||
|
code means all the source code for all modules it contains, plus any
|
||||||
|
associated interface definition files, plus the scripts used to
|
||||||
|
control compilation and installation of the executable. However, as a
|
||||||
|
special exception, the source code distributed need not include
|
||||||
|
anything that is normally distributed (in either source or binary
|
||||||
|
form) with the major components (compiler, kernel, and so on) of the
|
||||||
|
operating system on which the executable runs, unless that component
|
||||||
|
itself accompanies the executable.
|
||||||
|
|
||||||
|
If distribution of executable or object code is made by offering
|
||||||
|
access to copy from a designated place, then offering equivalent
|
||||||
|
access to copy the source code from the same place counts as
|
||||||
|
distribution of the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
|
except as expressly provided under this License. Any attempt
|
||||||
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
|
void, and will automatically terminate your rights under this License.
|
||||||
|
However, parties who have received copies, or rights, from you under
|
||||||
|
this License will not have their licenses terminated so long as such
|
||||||
|
parties remain in full compliance.
|
||||||
|
|
||||||
|
5. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Program or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Program (or any work based on the
|
||||||
|
Program), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Program or works based on it.
|
||||||
|
|
||||||
|
6. Each time you redistribute the Program (or any work based on the
|
||||||
|
Program), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute or modify the Program subject to
|
||||||
|
these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties to
|
||||||
|
this License.
|
||||||
|
|
||||||
|
7. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Program at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Program by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Program.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under
|
||||||
|
any particular circumstance, the balance of the section is intended to
|
||||||
|
apply and the section as a whole is intended to apply in other
|
||||||
|
circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system, which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Program under this License
|
||||||
|
may add an explicit geographical distribution limitation excluding
|
||||||
|
those countries, so that distribution is permitted only in or among
|
||||||
|
countries not thus excluded. In such case, this License incorporates
|
||||||
|
the limitation as if written in the body of this License.
|
||||||
|
|
||||||
|
9. The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies a version number of this License which applies to it and "any
|
||||||
|
later version", you have the option of following the terms and conditions
|
||||||
|
either of that version or of any later version published by the Free
|
||||||
|
Software Foundation. If the Program does not specify a version number of
|
||||||
|
this License, you may choose any version ever published by the Free Software
|
||||||
|
Foundation.
|
||||||
|
|
||||||
|
10. If you wish to incorporate parts of the Program into other free
|
||||||
|
programs whose distribution conditions are different, write to the author
|
||||||
|
to ask for permission. For software which is copyrighted by the Free
|
||||||
|
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||||
|
make exceptions for this. Our decision will be guided by the two goals
|
||||||
|
of preserving the free status of all derivatives of our free software and
|
||||||
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||||
|
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||||
|
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||||
|
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||||
|
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||||
|
REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||||
|
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||||
|
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||||
|
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||||
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License** as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program is interactive, make it output a short notice like this
|
||||||
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
|
Gnomovision version 69, Copyright (C) year name of author
|
||||||
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, the commands you use may
|
||||||
|
be called something other than `show w' and `show c'; they could even be
|
||||||
|
mouse-clicks or menu items--whatever suits your program.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||||
|
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1989
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
This General Public License does not permit incorporating your program into
|
||||||
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
|
consider it more useful to permit linking proprietary applications with the
|
||||||
|
library. If this is what you want to do, use the GNU Library General
|
||||||
|
Public License instead of this License.
|
||||||
|
|
||||||
|
----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
The FreeRTOS GPL Exception Text:
|
||||||
|
|
||||||
|
Any FreeRTOS source code, whether modified or in it's original release form,
|
||||||
|
or whether in whole or in part, can only be distributed by you under the terms
|
||||||
|
of the GNU General Public License plus this exception. An independent module is
|
||||||
|
a module which is not derived from or based on FreeRTOS.
|
||||||
|
|
||||||
|
Clause 1:
|
||||||
|
|
||||||
|
Linking FreeRTOS statically or dynamically with other modules is making a
|
||||||
|
combined work based on FreeRTOS. Thus, the terms and conditions of the GNU
|
||||||
|
General Public License cover the whole combination.
|
||||||
|
|
||||||
|
As a special exception, the copyright holder of FreeRTOS gives you permission
|
||||||
|
to link FreeRTOS with independent modules that communicate with FreeRTOS
|
||||||
|
solely through the FreeRTOS API interface, regardless of the license terms of
|
||||||
|
these independent modules, and to copy and distribute the resulting combined
|
||||||
|
work under terms of your choice, provided that
|
||||||
|
|
||||||
|
+ Every copy of the combined work is accompanied by a written statement that
|
||||||
|
details to the recipient the version of FreeRTOS used and an offer by yourself
|
||||||
|
to provide the FreeRTOS source code (including any modifications you may have
|
||||||
|
made) should the recipient request it.
|
||||||
|
|
||||||
|
+ The combined work is not itself an RTOS, scheduler, kernel or related product.
|
||||||
|
|
||||||
|
+ The independent modules add significant and primary functionality to FreeRTOS
|
||||||
|
and do not merely extend the existing functionality already present in FreeRTOS.
|
||||||
|
|
||||||
|
Clause 2:
|
||||||
|
|
||||||
|
FreeRTOS may not be used for any competitive or comparative purpose, including the
|
||||||
|
publication of any form of run time or compile time metric, without the express
|
||||||
|
permission of Real Time Engineers Ltd. (this is the norm within the industry and
|
||||||
|
is intended to ensure information accuracy).
|
||||||
|
|
|
@ -1,37 +1,71 @@
|
||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.2.0
|
FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
***************************************************************************
|
||||||
* the Software without restriction, including without limitation the rights to
|
* *
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* FreeRTOS provides completely free yet professionally developed, *
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* robust, strictly quality controlled, supported, and cross *
|
||||||
* subject to the following conditions:
|
* platform software that has become a de facto standard. *
|
||||||
*
|
* *
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* Help yourself get started quickly and support the FreeRTOS *
|
||||||
* copies or substantial portions of the Software.
|
* project by purchasing a FreeRTOS tutorial book, reference *
|
||||||
*
|
* manual, or both from: http://www.FreeRTOS.org/Documentation *
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* *
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* Thank you! *
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* *
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
***************************************************************************
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
This file is part of the FreeRTOS distribution.
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
* http://aws.amazon.com/freertos
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
*
|
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
>>! NOTE: The modification to the GPL is included to allow you to distribute
|
||||||
|
>>! a combined work that includes FreeRTOS without being obliged to provide
|
||||||
|
>>! the source code for proprietary components outside of the FreeRTOS
|
||||||
|
>>! kernel.
|
||||||
|
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. Full license text is available from the following
|
||||||
|
link: http://www.freertos.org/a00114.html
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* Having a problem? Start by reading the FAQ "My application does *
|
||||||
|
* not run, what could be wrong?" *
|
||||||
|
* *
|
||||||
|
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||||
|
license and Real Time Engineers Ltd. contact details.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||||
|
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||||
|
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||||
|
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||||
|
licenses offer ticketed support, indemnification and middleware.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||||
|
engineered and independently SIL3 certified version for use in safety and
|
||||||
|
mission critical applications that require provable dependability.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
*/
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "croutine.h"
|
#include "croutine.h"
|
||||||
|
|
||||||
/* Remove the whole file is co-routines are not being used. */
|
|
||||||
#if( configUSE_CO_ROUTINES != 0 )
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Some kernel aware debuggers require data to be viewed to be global, rather
|
* Some kernel aware debuggers require data to be viewed to be global, rather
|
||||||
* than file scope.
|
* than file scope.
|
||||||
|
@ -42,17 +76,17 @@
|
||||||
|
|
||||||
|
|
||||||
/* Lists for ready and blocked co-routines. --------------------*/
|
/* Lists for ready and blocked co-routines. --------------------*/
|
||||||
static List_t pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */
|
static xList pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */
|
||||||
static List_t xDelayedCoRoutineList1; /*< Delayed co-routines. */
|
static xList xDelayedCoRoutineList1; /*< Delayed co-routines. */
|
||||||
static List_t xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */
|
static xList xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */
|
||||||
static List_t * pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */
|
static xList * pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */
|
||||||
static List_t * pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
|
static xList * pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
|
||||||
static List_t xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */
|
static xList xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */
|
||||||
|
|
||||||
/* Other file private variables. --------------------------------*/
|
/* Other file private variables. --------------------------------*/
|
||||||
CRCB_t * pxCurrentCoRoutine = NULL;
|
corCRCB * pxCurrentCoRoutine = NULL;
|
||||||
static UBaseType_t uxTopCoRoutineReadyPriority = 0;
|
static unsigned portBASE_TYPE uxTopCoRoutineReadyPriority = 0;
|
||||||
static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;
|
static portTickType xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;
|
||||||
|
|
||||||
/* The initial state of the co-routine when it is created. */
|
/* The initial state of the co-routine when it is created. */
|
||||||
#define corINITIAL_STATE ( 0 )
|
#define corINITIAL_STATE ( 0 )
|
||||||
|
@ -70,7 +104,7 @@ static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;
|
||||||
{ \
|
{ \
|
||||||
uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \
|
uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \
|
||||||
} \
|
} \
|
||||||
vListInsertEnd( ( List_t * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \
|
vListInsertEnd( ( xList * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -99,13 +133,13 @@ static void prvCheckDelayedList( void );
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex )
|
signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex )
|
||||||
{
|
{
|
||||||
BaseType_t xReturn;
|
signed portBASE_TYPE xReturn;
|
||||||
CRCB_t *pxCoRoutine;
|
corCRCB *pxCoRoutine;
|
||||||
|
|
||||||
/* Allocate the memory that will store the co-routine control block. */
|
/* Allocate the memory that will store the co-routine control block. */
|
||||||
pxCoRoutine = ( CRCB_t * ) pvPortMalloc( sizeof( CRCB_t ) );
|
pxCoRoutine = ( corCRCB * ) pvPortMalloc( sizeof( corCRCB ) );
|
||||||
if( pxCoRoutine )
|
if( pxCoRoutine )
|
||||||
{
|
{
|
||||||
/* If pxCurrentCoRoutine is NULL then this is the first co-routine to
|
/* If pxCurrentCoRoutine is NULL then this is the first co-routine to
|
||||||
|
@ -132,14 +166,14 @@ CRCB_t *pxCoRoutine;
|
||||||
vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) );
|
vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) );
|
||||||
vListInitialiseItem( &( pxCoRoutine->xEventListItem ) );
|
vListInitialiseItem( &( pxCoRoutine->xEventListItem ) );
|
||||||
|
|
||||||
/* Set the co-routine control block as a link back from the ListItem_t.
|
/* Set the co-routine control block as a link back from the xListItem.
|
||||||
This is so we can get back to the containing CRCB from a generic item
|
This is so we can get back to the containing CRCB from a generic item
|
||||||
in a list. */
|
in a list. */
|
||||||
listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine );
|
listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine );
|
||||||
listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine );
|
listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine );
|
||||||
|
|
||||||
/* Event lists are always in priority order. */
|
/* Event lists are always in priority order. */
|
||||||
listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), ( ( TickType_t ) configMAX_CO_ROUTINE_PRIORITIES - ( TickType_t ) uxPriority ) );
|
listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );
|
||||||
|
|
||||||
/* Now the co-routine has been initialised it can be added to the ready
|
/* Now the co-routine has been initialised it can be added to the ready
|
||||||
list at the correct priority. */
|
list at the correct priority. */
|
||||||
|
@ -156,9 +190,9 @@ CRCB_t *pxCoRoutine;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList )
|
void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList )
|
||||||
{
|
{
|
||||||
TickType_t xTimeToWake;
|
portTickType xTimeToWake;
|
||||||
|
|
||||||
/* Calculate the time to wake - this may overflow but this is
|
/* Calculate the time to wake - this may overflow but this is
|
||||||
not a problem. */
|
not a problem. */
|
||||||
|
@ -167,7 +201,7 @@ TickType_t xTimeToWake;
|
||||||
/* We must remove ourselves from the ready list before adding
|
/* We must remove ourselves from the ready list before adding
|
||||||
ourselves to the blocked list as the same list item is used for
|
ourselves to the blocked list as the same list item is used for
|
||||||
both lists. */
|
both lists. */
|
||||||
( void ) uxListRemove( ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );
|
( void ) uxListRemove( ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );
|
||||||
|
|
||||||
/* The list item will be inserted in wake time order. */
|
/* The list item will be inserted in wake time order. */
|
||||||
listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake );
|
listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake );
|
||||||
|
@ -176,13 +210,13 @@ TickType_t xTimeToWake;
|
||||||
{
|
{
|
||||||
/* Wake time has overflowed. Place this item in the
|
/* Wake time has overflowed. Place this item in the
|
||||||
overflow list. */
|
overflow list. */
|
||||||
vListInsert( ( List_t * ) pxOverflowDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );
|
vListInsert( ( xList * ) pxOverflowDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* The wake time has not overflowed, so we can use the
|
/* The wake time has not overflowed, so we can use the
|
||||||
current block list. */
|
current block list. */
|
||||||
vListInsert( ( List_t * ) pxDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );
|
vListInsert( ( xList * ) pxDelayedCoRoutineList, ( xListItem * ) &( pxCurrentCoRoutine->xGenericListItem ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( pxEventList )
|
if( pxEventList )
|
||||||
|
@ -201,12 +235,12 @@ static void prvCheckPendingReadyList( void )
|
||||||
the ready lists itself. */
|
the ready lists itself. */
|
||||||
while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE )
|
while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE )
|
||||||
{
|
{
|
||||||
CRCB_t *pxUnblockedCRCB;
|
corCRCB *pxUnblockedCRCB;
|
||||||
|
|
||||||
/* The pending ready list can be accessed by an ISR. */
|
/* The pending ready list can be accessed by an ISR. */
|
||||||
portDISABLE_INTERRUPTS();
|
portDISABLE_INTERRUPTS();
|
||||||
{
|
{
|
||||||
pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) );
|
pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) );
|
||||||
( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );
|
( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );
|
||||||
}
|
}
|
||||||
portENABLE_INTERRUPTS();
|
portENABLE_INTERRUPTS();
|
||||||
|
@ -219,7 +253,7 @@ static void prvCheckPendingReadyList( void )
|
||||||
|
|
||||||
static void prvCheckDelayedList( void )
|
static void prvCheckDelayedList( void )
|
||||||
{
|
{
|
||||||
CRCB_t *pxCRCB;
|
corCRCB *pxCRCB;
|
||||||
|
|
||||||
xPassedTicks = xTaskGetTickCount() - xLastTickCount;
|
xPassedTicks = xTaskGetTickCount() - xLastTickCount;
|
||||||
while( xPassedTicks )
|
while( xPassedTicks )
|
||||||
|
@ -230,7 +264,7 @@ CRCB_t *pxCRCB;
|
||||||
/* If the tick count has overflowed we need to swap the ready lists. */
|
/* If the tick count has overflowed we need to swap the ready lists. */
|
||||||
if( xCoRoutineTickCount == 0 )
|
if( xCoRoutineTickCount == 0 )
|
||||||
{
|
{
|
||||||
List_t * pxTemp;
|
xList * pxTemp;
|
||||||
|
|
||||||
/* Tick count has overflowed so we need to swap the delay lists. If there are
|
/* Tick count has overflowed so we need to swap the delay lists. If there are
|
||||||
any items in pxDelayedCoRoutineList here then there is an error! */
|
any items in pxDelayedCoRoutineList here then there is an error! */
|
||||||
|
@ -242,7 +276,7 @@ CRCB_t *pxCRCB;
|
||||||
/* See if this tick has made a timeout expire. */
|
/* See if this tick has made a timeout expire. */
|
||||||
while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE )
|
while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE )
|
||||||
{
|
{
|
||||||
pxCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList );
|
pxCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList );
|
||||||
|
|
||||||
if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) )
|
if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) )
|
||||||
{
|
{
|
||||||
|
@ -257,10 +291,10 @@ CRCB_t *pxCRCB;
|
||||||
have been moved to the pending ready list and the following
|
have been moved to the pending ready list and the following
|
||||||
line is still valid. Also the pvContainer parameter will have
|
line is still valid. Also the pvContainer parameter will have
|
||||||
been set to NULL so the following lines are also valid. */
|
been set to NULL so the following lines are also valid. */
|
||||||
( void ) uxListRemove( &( pxCRCB->xGenericListItem ) );
|
uxListRemove( &( pxCRCB->xGenericListItem ) );
|
||||||
|
|
||||||
/* Is the co-routine waiting on an event also? */
|
/* Is the co-routine waiting on an event also? */
|
||||||
if( pxCRCB->xEventListItem.pxContainer )
|
if( pxCRCB->xEventListItem.pvContainer )
|
||||||
{
|
{
|
||||||
( void ) uxListRemove( &( pxCRCB->xEventListItem ) );
|
( void ) uxListRemove( &( pxCRCB->xEventListItem ) );
|
||||||
}
|
}
|
||||||
|
@ -307,16 +341,16 @@ void vCoRoutineSchedule( void )
|
||||||
|
|
||||||
static void prvInitialiseCoRoutineLists( void )
|
static void prvInitialiseCoRoutineLists( void )
|
||||||
{
|
{
|
||||||
UBaseType_t uxPriority;
|
unsigned portBASE_TYPE uxPriority;
|
||||||
|
|
||||||
for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ )
|
for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ )
|
||||||
{
|
{
|
||||||
vListInitialise( ( List_t * ) &( pxReadyCoRoutineLists[ uxPriority ] ) );
|
vListInitialise( ( xList * ) &( pxReadyCoRoutineLists[ uxPriority ] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
vListInitialise( ( List_t * ) &xDelayedCoRoutineList1 );
|
vListInitialise( ( xList * ) &xDelayedCoRoutineList1 );
|
||||||
vListInitialise( ( List_t * ) &xDelayedCoRoutineList2 );
|
vListInitialise( ( xList * ) &xDelayedCoRoutineList2 );
|
||||||
vListInitialise( ( List_t * ) &xPendingReadyCoRoutineList );
|
vListInitialise( ( xList * ) &xPendingReadyCoRoutineList );
|
||||||
|
|
||||||
/* Start with pxDelayedCoRoutineList using list1 and the
|
/* Start with pxDelayedCoRoutineList using list1 and the
|
||||||
pxOverflowDelayedCoRoutineList using list2. */
|
pxOverflowDelayedCoRoutineList using list2. */
|
||||||
|
@ -325,17 +359,17 @@ UBaseType_t uxPriority;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList )
|
signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList )
|
||||||
{
|
{
|
||||||
CRCB_t *pxUnblockedCRCB;
|
corCRCB *pxUnblockedCRCB;
|
||||||
BaseType_t xReturn;
|
signed portBASE_TYPE xReturn;
|
||||||
|
|
||||||
/* This function is called from within an interrupt. It can only access
|
/* This function is called from within an interrupt. It can only access
|
||||||
event lists and the pending ready list. This function assumes that a
|
event lists and the pending ready list. This function assumes that a
|
||||||
check has already been made to ensure pxEventList is not empty. */
|
check has already been made to ensure pxEventList is not empty. */
|
||||||
pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );
|
pxUnblockedCRCB = ( corCRCB * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );
|
||||||
( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );
|
( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );
|
||||||
vListInsertEnd( ( List_t * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) );
|
vListInsertEnd( ( xList * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) );
|
||||||
|
|
||||||
if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority )
|
if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority )
|
||||||
{
|
{
|
||||||
|
@ -349,5 +383,3 @@ BaseType_t xReturn;
|
||||||
return xReturn;
|
return xReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* configUSE_CO_ROUTINES == 0 */
|
|
||||||
|
|
||||||
|
|
|
@ -1,753 +0,0 @@
|
||||||
/*
|
|
||||||
* FreeRTOS Kernel V10.2.0
|
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
|
||||||
* http://aws.amazon.com/freertos
|
|
||||||
*
|
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Standard includes. */
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
|
|
||||||
all the API functions to use the MPU wrappers. That should only be done when
|
|
||||||
task.h is included from an application file. */
|
|
||||||
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
|
||||||
|
|
||||||
/* FreeRTOS includes. */
|
|
||||||
#include "FreeRTOS.h"
|
|
||||||
#include "task.h"
|
|
||||||
#include "timers.h"
|
|
||||||
#include "event_groups.h"
|
|
||||||
|
|
||||||
/* Lint e961, e750 and e9021 are suppressed as a MISRA exception justified
|
|
||||||
because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
|
|
||||||
for the header files above, but not in this file, in order to generate the
|
|
||||||
correct privileged Vs unprivileged linkage and placement. */
|
|
||||||
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021 See comment above. */
|
|
||||||
|
|
||||||
/* The following bit fields convey control information in a task's event list
|
|
||||||
item value. It is important they don't clash with the
|
|
||||||
taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */
|
|
||||||
#if configUSE_16_BIT_TICKS == 1
|
|
||||||
#define eventCLEAR_EVENTS_ON_EXIT_BIT 0x0100U
|
|
||||||
#define eventUNBLOCKED_DUE_TO_BIT_SET 0x0200U
|
|
||||||
#define eventWAIT_FOR_ALL_BITS 0x0400U
|
|
||||||
#define eventEVENT_BITS_CONTROL_BYTES 0xff00U
|
|
||||||
#else
|
|
||||||
#define eventCLEAR_EVENTS_ON_EXIT_BIT 0x01000000UL
|
|
||||||
#define eventUNBLOCKED_DUE_TO_BIT_SET 0x02000000UL
|
|
||||||
#define eventWAIT_FOR_ALL_BITS 0x04000000UL
|
|
||||||
#define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct EventGroupDef_t
|
|
||||||
{
|
|
||||||
EventBits_t uxEventBits;
|
|
||||||
List_t xTasksWaitingForBits; /*< List of tasks waiting for a bit to be set. */
|
|
||||||
|
|
||||||
#if( configUSE_TRACE_FACILITY == 1 )
|
|
||||||
UBaseType_t uxEventGroupNumber;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
|
|
||||||
uint8_t ucStaticallyAllocated; /*< Set to pdTRUE if the event group is statically allocated to ensure no attempt is made to free the memory. */
|
|
||||||
#endif
|
|
||||||
} EventGroup_t;
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test the bits set in uxCurrentEventBits to see if the wait condition is met.
|
|
||||||
* The wait condition is defined by xWaitForAllBits. If xWaitForAllBits is
|
|
||||||
* pdTRUE then the wait condition is met if all the bits set in uxBitsToWaitFor
|
|
||||||
* are also set in uxCurrentEventBits. If xWaitForAllBits is pdFALSE then the
|
|
||||||
* wait condition is met if any of the bits set in uxBitsToWait for are also set
|
|
||||||
* in uxCurrentEventBits.
|
|
||||||
*/
|
|
||||||
static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
|
||||||
|
|
||||||
EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t *pxEventGroupBuffer )
|
|
||||||
{
|
|
||||||
EventGroup_t *pxEventBits;
|
|
||||||
|
|
||||||
/* A StaticEventGroup_t object must be provided. */
|
|
||||||
configASSERT( pxEventGroupBuffer );
|
|
||||||
|
|
||||||
#if( configASSERT_DEFINED == 1 )
|
|
||||||
{
|
|
||||||
/* Sanity check that the size of the structure used to declare a
|
|
||||||
variable of type StaticEventGroup_t equals the size of the real
|
|
||||||
event group structure. */
|
|
||||||
volatile size_t xSize = sizeof( StaticEventGroup_t );
|
|
||||||
configASSERT( xSize == sizeof( EventGroup_t ) );
|
|
||||||
} /*lint !e529 xSize is referenced if configASSERT() is defined. */
|
|
||||||
#endif /* configASSERT_DEFINED */
|
|
||||||
|
|
||||||
/* The user has provided a statically allocated event group - use it. */
|
|
||||||
pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer; /*lint !e740 !e9087 EventGroup_t and StaticEventGroup_t are deliberately aliased for data hiding purposes and guaranteed to have the same size and alignment requirement - checked by configASSERT(). */
|
|
||||||
|
|
||||||
if( pxEventBits != NULL )
|
|
||||||
{
|
|
||||||
pxEventBits->uxEventBits = 0;
|
|
||||||
vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
|
|
||||||
|
|
||||||
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
|
|
||||||
{
|
|
||||||
/* Both static and dynamic allocation can be used, so note that
|
|
||||||
this event group was created statically in case the event group
|
|
||||||
is later deleted. */
|
|
||||||
pxEventBits->ucStaticallyAllocated = pdTRUE;
|
|
||||||
}
|
|
||||||
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
|
||||||
|
|
||||||
traceEVENT_GROUP_CREATE( pxEventBits );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* xEventGroupCreateStatic should only ever be called with
|
|
||||||
pxEventGroupBuffer pointing to a pre-allocated (compile time
|
|
||||||
allocated) StaticEventGroup_t variable. */
|
|
||||||
traceEVENT_GROUP_CREATE_FAILED();
|
|
||||||
}
|
|
||||||
|
|
||||||
return pxEventBits;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
|
|
||||||
|
|
||||||
EventGroupHandle_t xEventGroupCreate( void )
|
|
||||||
{
|
|
||||||
EventGroup_t *pxEventBits;
|
|
||||||
|
|
||||||
/* Allocate the event group. Justification for MISRA deviation as
|
|
||||||
follows: pvPortMalloc() always ensures returned memory blocks are
|
|
||||||
aligned per the requirements of the MCU stack. In this case
|
|
||||||
pvPortMalloc() must return a pointer that is guaranteed to meet the
|
|
||||||
alignment requirements of the EventGroup_t structure - which (if you
|
|
||||||
follow it through) is the alignment requirements of the TickType_t type
|
|
||||||
(EventBits_t being of TickType_t itself). Therefore, whenever the
|
|
||||||
stack alignment requirements are greater than or equal to the
|
|
||||||
TickType_t alignment requirements the cast is safe. In other cases,
|
|
||||||
where the natural word size of the architecture is less than
|
|
||||||
sizeof( TickType_t ), the TickType_t variables will be accessed in two
|
|
||||||
or more reads operations, and the alignment requirements is only that
|
|
||||||
of each individual read. */
|
|
||||||
pxEventBits = ( EventGroup_t * ) pvPortMalloc( sizeof( EventGroup_t ) ); /*lint !e9087 !e9079 see comment above. */
|
|
||||||
|
|
||||||
if( pxEventBits != NULL )
|
|
||||||
{
|
|
||||||
pxEventBits->uxEventBits = 0;
|
|
||||||
vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
|
|
||||||
|
|
||||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
|
||||||
{
|
|
||||||
/* Both static and dynamic allocation can be used, so note this
|
|
||||||
event group was allocated statically in case the event group is
|
|
||||||
later deleted. */
|
|
||||||
pxEventBits->ucStaticallyAllocated = pdFALSE;
|
|
||||||
}
|
|
||||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
|
||||||
|
|
||||||
traceEVENT_GROUP_CREATE( pxEventBits );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
traceEVENT_GROUP_CREATE_FAILED(); /*lint !e9063 Else branch only exists to allow tracing and does not generate code if trace macros are not defined. */
|
|
||||||
}
|
|
||||||
|
|
||||||
return pxEventBits;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait )
|
|
||||||
{
|
|
||||||
EventBits_t uxOriginalBitValue, uxReturn;
|
|
||||||
EventGroup_t *pxEventBits = xEventGroup;
|
|
||||||
BaseType_t xAlreadyYielded;
|
|
||||||
BaseType_t xTimeoutOccurred = pdFALSE;
|
|
||||||
|
|
||||||
configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
|
|
||||||
configASSERT( uxBitsToWaitFor != 0 );
|
|
||||||
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
|
|
||||||
{
|
|
||||||
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
vTaskSuspendAll();
|
|
||||||
{
|
|
||||||
uxOriginalBitValue = pxEventBits->uxEventBits;
|
|
||||||
|
|
||||||
( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet );
|
|
||||||
|
|
||||||
if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )
|
|
||||||
{
|
|
||||||
/* All the rendezvous bits are now set - no need to block. */
|
|
||||||
uxReturn = ( uxOriginalBitValue | uxBitsToSet );
|
|
||||||
|
|
||||||
/* Rendezvous always clear the bits. They will have been cleared
|
|
||||||
already unless this is the only task in the rendezvous. */
|
|
||||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
|
||||||
|
|
||||||
xTicksToWait = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( xTicksToWait != ( TickType_t ) 0 )
|
|
||||||
{
|
|
||||||
traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor );
|
|
||||||
|
|
||||||
/* Store the bits that the calling task is waiting for in the
|
|
||||||
task's event list item so the kernel knows when a match is
|
|
||||||
found. Then enter the blocked state. */
|
|
||||||
vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait );
|
|
||||||
|
|
||||||
/* This assignment is obsolete as uxReturn will get set after
|
|
||||||
the task unblocks, but some compilers mistakenly generate a
|
|
||||||
warning about uxReturn being returned without being set if the
|
|
||||||
assignment is omitted. */
|
|
||||||
uxReturn = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The rendezvous bits were not set, but no block time was
|
|
||||||
specified - just return the current event bit value. */
|
|
||||||
uxReturn = pxEventBits->uxEventBits;
|
|
||||||
xTimeoutOccurred = pdTRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xAlreadyYielded = xTaskResumeAll();
|
|
||||||
|
|
||||||
if( xTicksToWait != ( TickType_t ) 0 )
|
|
||||||
{
|
|
||||||
if( xAlreadyYielded == pdFALSE )
|
|
||||||
{
|
|
||||||
portYIELD_WITHIN_API();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The task blocked to wait for its required bits to be set - at this
|
|
||||||
point either the required bits were set or the block time expired. If
|
|
||||||
the required bits were set they will have been stored in the task's
|
|
||||||
event list item, and they should now be retrieved then cleared. */
|
|
||||||
uxReturn = uxTaskResetEventItemValue();
|
|
||||||
|
|
||||||
if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
|
|
||||||
{
|
|
||||||
/* The task timed out, just return the current event bit value. */
|
|
||||||
taskENTER_CRITICAL();
|
|
||||||
{
|
|
||||||
uxReturn = pxEventBits->uxEventBits;
|
|
||||||
|
|
||||||
/* Although the task got here because it timed out before the
|
|
||||||
bits it was waiting for were set, it is possible that since it
|
|
||||||
unblocked another task has set the bits. If this is the case
|
|
||||||
then it needs to clear the bits before exiting. */
|
|
||||||
if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )
|
|
||||||
{
|
|
||||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
taskEXIT_CRITICAL();
|
|
||||||
|
|
||||||
xTimeoutOccurred = pdTRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The task unblocked because the bits were set. */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Control bits might be set as the task had blocked should not be
|
|
||||||
returned. */
|
|
||||||
uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
|
|
||||||
}
|
|
||||||
|
|
||||||
traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred );
|
|
||||||
|
|
||||||
/* Prevent compiler warnings when trace macros are not used. */
|
|
||||||
( void ) xTimeoutOccurred;
|
|
||||||
|
|
||||||
return uxReturn;
|
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait )
|
|
||||||
{
|
|
||||||
EventGroup_t *pxEventBits = xEventGroup;
|
|
||||||
EventBits_t uxReturn, uxControlBits = 0;
|
|
||||||
BaseType_t xWaitConditionMet, xAlreadyYielded;
|
|
||||||
BaseType_t xTimeoutOccurred = pdFALSE;
|
|
||||||
|
|
||||||
/* Check the user is not attempting to wait on the bits used by the kernel
|
|
||||||
itself, and that at least one bit is being requested. */
|
|
||||||
configASSERT( xEventGroup );
|
|
||||||
configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
|
|
||||||
configASSERT( uxBitsToWaitFor != 0 );
|
|
||||||
#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
|
|
||||||
{
|
|
||||||
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
vTaskSuspendAll();
|
|
||||||
{
|
|
||||||
const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits;
|
|
||||||
|
|
||||||
/* Check to see if the wait condition is already met or not. */
|
|
||||||
xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );
|
|
||||||
|
|
||||||
if( xWaitConditionMet != pdFALSE )
|
|
||||||
{
|
|
||||||
/* The wait condition has already been met so there is no need to
|
|
||||||
block. */
|
|
||||||
uxReturn = uxCurrentEventBits;
|
|
||||||
xTicksToWait = ( TickType_t ) 0;
|
|
||||||
|
|
||||||
/* Clear the wait bits if requested to do so. */
|
|
||||||
if( xClearOnExit != pdFALSE )
|
|
||||||
{
|
|
||||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( xTicksToWait == ( TickType_t ) 0 )
|
|
||||||
{
|
|
||||||
/* The wait condition has not been met, but no block time was
|
|
||||||
specified, so just return the current value. */
|
|
||||||
uxReturn = uxCurrentEventBits;
|
|
||||||
xTimeoutOccurred = pdTRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The task is going to block to wait for its required bits to be
|
|
||||||
set. uxControlBits are used to remember the specified behaviour of
|
|
||||||
this call to xEventGroupWaitBits() - for use when the event bits
|
|
||||||
unblock the task. */
|
|
||||||
if( xClearOnExit != pdFALSE )
|
|
||||||
{
|
|
||||||
uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( xWaitForAllBits != pdFALSE )
|
|
||||||
{
|
|
||||||
uxControlBits |= eventWAIT_FOR_ALL_BITS;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Store the bits that the calling task is waiting for in the
|
|
||||||
task's event list item so the kernel knows when a match is
|
|
||||||
found. Then enter the blocked state. */
|
|
||||||
vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait );
|
|
||||||
|
|
||||||
/* This is obsolete as it will get set after the task unblocks, but
|
|
||||||
some compilers mistakenly generate a warning about the variable
|
|
||||||
being returned without being set if it is not done. */
|
|
||||||
uxReturn = 0;
|
|
||||||
|
|
||||||
traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xAlreadyYielded = xTaskResumeAll();
|
|
||||||
|
|
||||||
if( xTicksToWait != ( TickType_t ) 0 )
|
|
||||||
{
|
|
||||||
if( xAlreadyYielded == pdFALSE )
|
|
||||||
{
|
|
||||||
portYIELD_WITHIN_API();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The task blocked to wait for its required bits to be set - at this
|
|
||||||
point either the required bits were set or the block time expired. If
|
|
||||||
the required bits were set they will have been stored in the task's
|
|
||||||
event list item, and they should now be retrieved then cleared. */
|
|
||||||
uxReturn = uxTaskResetEventItemValue();
|
|
||||||
|
|
||||||
if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
|
|
||||||
{
|
|
||||||
taskENTER_CRITICAL();
|
|
||||||
{
|
|
||||||
/* The task timed out, just return the current event bit value. */
|
|
||||||
uxReturn = pxEventBits->uxEventBits;
|
|
||||||
|
|
||||||
/* It is possible that the event bits were updated between this
|
|
||||||
task leaving the Blocked state and running again. */
|
|
||||||
if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )
|
|
||||||
{
|
|
||||||
if( xClearOnExit != pdFALSE )
|
|
||||||
{
|
|
||||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
xTimeoutOccurred = pdTRUE;
|
|
||||||
}
|
|
||||||
taskEXIT_CRITICAL();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The task unblocked because the bits were set. */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The task blocked so control bits may have been set. */
|
|
||||||
uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
|
|
||||||
}
|
|
||||||
traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred );
|
|
||||||
|
|
||||||
/* Prevent compiler warnings when trace macros are not used. */
|
|
||||||
( void ) xTimeoutOccurred;
|
|
||||||
|
|
||||||
return uxReturn;
|
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )
|
|
||||||
{
|
|
||||||
EventGroup_t *pxEventBits = xEventGroup;
|
|
||||||
EventBits_t uxReturn;
|
|
||||||
|
|
||||||
/* Check the user is not attempting to clear the bits used by the kernel
|
|
||||||
itself. */
|
|
||||||
configASSERT( xEventGroup );
|
|
||||||
configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
|
|
||||||
|
|
||||||
taskENTER_CRITICAL();
|
|
||||||
{
|
|
||||||
traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );
|
|
||||||
|
|
||||||
/* The value returned is the event group value prior to the bits being
|
|
||||||
cleared. */
|
|
||||||
uxReturn = pxEventBits->uxEventBits;
|
|
||||||
|
|
||||||
/* Clear the bits. */
|
|
||||||
pxEventBits->uxEventBits &= ~uxBitsToClear;
|
|
||||||
}
|
|
||||||
taskEXIT_CRITICAL();
|
|
||||||
|
|
||||||
return uxReturn;
|
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
|
|
||||||
|
|
||||||
BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )
|
|
||||||
{
|
|
||||||
BaseType_t xReturn;
|
|
||||||
|
|
||||||
traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear );
|
|
||||||
xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
|
|
||||||
|
|
||||||
return xReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup )
|
|
||||||
{
|
|
||||||
UBaseType_t uxSavedInterruptStatus;
|
|
||||||
EventGroup_t const * const pxEventBits = xEventGroup;
|
|
||||||
EventBits_t uxReturn;
|
|
||||||
|
|
||||||
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
|
|
||||||
{
|
|
||||||
uxReturn = pxEventBits->uxEventBits;
|
|
||||||
}
|
|
||||||
portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
|
|
||||||
|
|
||||||
return uxReturn;
|
|
||||||
} /*lint !e818 EventGroupHandle_t is a typedef used in other functions to so can't be pointer to const. */
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet )
|
|
||||||
{
|
|
||||||
ListItem_t *pxListItem, *pxNext;
|
|
||||||
ListItem_t const *pxListEnd;
|
|
||||||
List_t const * pxList;
|
|
||||||
EventBits_t uxBitsToClear = 0, uxBitsWaitedFor, uxControlBits;
|
|
||||||
EventGroup_t *pxEventBits = xEventGroup;
|
|
||||||
BaseType_t xMatchFound = pdFALSE;
|
|
||||||
|
|
||||||
/* Check the user is not attempting to set the bits used by the kernel
|
|
||||||
itself. */
|
|
||||||
configASSERT( xEventGroup );
|
|
||||||
configASSERT( ( uxBitsToSet & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
|
|
||||||
|
|
||||||
pxList = &( pxEventBits->xTasksWaitingForBits );
|
|
||||||
pxListEnd = listGET_END_MARKER( pxList ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
|
||||||
vTaskSuspendAll();
|
|
||||||
{
|
|
||||||
traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet );
|
|
||||||
|
|
||||||
pxListItem = listGET_HEAD_ENTRY( pxList );
|
|
||||||
|
|
||||||
/* Set the bits. */
|
|
||||||
pxEventBits->uxEventBits |= uxBitsToSet;
|
|
||||||
|
|
||||||
/* See if the new bit value should unblock any tasks. */
|
|
||||||
while( pxListItem != pxListEnd )
|
|
||||||
{
|
|
||||||
pxNext = listGET_NEXT( pxListItem );
|
|
||||||
uxBitsWaitedFor = listGET_LIST_ITEM_VALUE( pxListItem );
|
|
||||||
xMatchFound = pdFALSE;
|
|
||||||
|
|
||||||
/* Split the bits waited for from the control bits. */
|
|
||||||
uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;
|
|
||||||
uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;
|
|
||||||
|
|
||||||
if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 )
|
|
||||||
{
|
|
||||||
/* Just looking for single bit being set. */
|
|
||||||
if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 )
|
|
||||||
{
|
|
||||||
xMatchFound = pdTRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor )
|
|
||||||
{
|
|
||||||
/* All bits are set. */
|
|
||||||
xMatchFound = pdTRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Need all bits to be set, but not all the bits were set. */
|
|
||||||
}
|
|
||||||
|
|
||||||
if( xMatchFound != pdFALSE )
|
|
||||||
{
|
|
||||||
/* The bits match. Should the bits be cleared on exit? */
|
|
||||||
if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 )
|
|
||||||
{
|
|
||||||
uxBitsToClear |= uxBitsWaitedFor;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Store the actual event flag value in the task's event list
|
|
||||||
item before removing the task from the event list. The
|
|
||||||
eventUNBLOCKED_DUE_TO_BIT_SET bit is set so the task knows
|
|
||||||
that is was unblocked due to its required bits matching, rather
|
|
||||||
than because it timed out. */
|
|
||||||
vTaskRemoveFromUnorderedEventList( pxListItem, pxEventBits->uxEventBits | eventUNBLOCKED_DUE_TO_BIT_SET );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Move onto the next list item. Note pxListItem->pxNext is not
|
|
||||||
used here as the list item may have been removed from the event list
|
|
||||||
and inserted into the ready/pending reading list. */
|
|
||||||
pxListItem = pxNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clear any bits that matched when the eventCLEAR_EVENTS_ON_EXIT_BIT
|
|
||||||
bit was set in the control word. */
|
|
||||||
pxEventBits->uxEventBits &= ~uxBitsToClear;
|
|
||||||
}
|
|
||||||
( void ) xTaskResumeAll();
|
|
||||||
|
|
||||||
return pxEventBits->uxEventBits;
|
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
void vEventGroupDelete( EventGroupHandle_t xEventGroup )
|
|
||||||
{
|
|
||||||
EventGroup_t *pxEventBits = xEventGroup;
|
|
||||||
const List_t *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
|
|
||||||
|
|
||||||
vTaskSuspendAll();
|
|
||||||
{
|
|
||||||
traceEVENT_GROUP_DELETE( xEventGroup );
|
|
||||||
|
|
||||||
while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 )
|
|
||||||
{
|
|
||||||
/* Unblock the task, returning 0 as the event list is being deleted
|
|
||||||
and cannot therefore have any bits set. */
|
|
||||||
configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( const ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) );
|
|
||||||
vTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET );
|
|
||||||
}
|
|
||||||
|
|
||||||
#if( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 0 ) )
|
|
||||||
{
|
|
||||||
/* The event group can only have been allocated dynamically - free
|
|
||||||
it again. */
|
|
||||||
vPortFree( pxEventBits );
|
|
||||||
}
|
|
||||||
#elif( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
|
|
||||||
{
|
|
||||||
/* The event group could have been allocated statically or
|
|
||||||
dynamically, so check before attempting to free the memory. */
|
|
||||||
if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
|
|
||||||
{
|
|
||||||
vPortFree( pxEventBits );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
|
||||||
}
|
|
||||||
( void ) xTaskResumeAll();
|
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* For internal use only - execute a 'set bits' command that was pended from
|
|
||||||
an interrupt. */
|
|
||||||
void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet )
|
|
||||||
{
|
|
||||||
( void ) xEventGroupSetBits( pvEventGroup, ( EventBits_t ) ulBitsToSet ); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
|
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* For internal use only - execute a 'clear bits' command that was pended from
|
|
||||||
an interrupt. */
|
|
||||||
void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear )
|
|
||||||
{
|
|
||||||
( void ) xEventGroupClearBits( pvEventGroup, ( EventBits_t ) ulBitsToClear ); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
|
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits )
|
|
||||||
{
|
|
||||||
BaseType_t xWaitConditionMet = pdFALSE;
|
|
||||||
|
|
||||||
if( xWaitForAllBits == pdFALSE )
|
|
||||||
{
|
|
||||||
/* Task only has to wait for one bit within uxBitsToWaitFor to be
|
|
||||||
set. Is one already set? */
|
|
||||||
if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 )
|
|
||||||
{
|
|
||||||
xWaitConditionMet = pdTRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Task has to wait for all the bits in uxBitsToWaitFor to be set.
|
|
||||||
Are they set already? */
|
|
||||||
if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )
|
|
||||||
{
|
|
||||||
xWaitConditionMet = pdTRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return xWaitConditionMet;
|
|
||||||
}
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
|
|
||||||
|
|
||||||
BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken )
|
|
||||||
{
|
|
||||||
BaseType_t xReturn;
|
|
||||||
|
|
||||||
traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet );
|
|
||||||
xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
|
|
||||||
|
|
||||||
return xReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if (configUSE_TRACE_FACILITY == 1)
|
|
||||||
|
|
||||||
UBaseType_t uxEventGroupGetNumber( void* xEventGroup )
|
|
||||||
{
|
|
||||||
UBaseType_t xReturn;
|
|
||||||
EventGroup_t const *pxEventBits = ( EventGroup_t * ) xEventGroup; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
|
|
||||||
|
|
||||||
if( xEventGroup == NULL )
|
|
||||||
{
|
|
||||||
xReturn = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
xReturn = pxEventBits->uxEventGroupNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
return xReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* configUSE_TRACE_FACILITY */
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
|
||||||
|
|
||||||
void vEventGroupSetNumber( void * xEventGroup, UBaseType_t uxEventGroupNumber )
|
|
||||||
{
|
|
||||||
( ( EventGroup_t * ) xEventGroup )->uxEventGroupNumber = uxEventGroupNumber; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* configUSE_TRACE_FACILITY */
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,31 +1,15 @@
|
||||||
/*
|
/* Default esp-open-sdk FreeRTOSConfig file.
|
||||||
* FreeRTOS Kernel V10.2.0
|
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software. If you wish to use our Amazon
|
|
||||||
* FreeRTOS name, please do so in a fair use way that does not cause confusion.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
|
||||||
* http://aws.amazon.com/freertos
|
|
||||||
*
|
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
You can override settings in here by creating your own
|
||||||
|
FreeRTOSConfig.h file in your program directory.
|
||||||
|
|
||||||
|
You could just copy this file there and edit it, but it's
|
||||||
|
recommended you instead define whatever you want to override and
|
||||||
|
then use #include_next<FreeRTOSConfig.h> to pick up these defaults.
|
||||||
|
|
||||||
|
The "blink" example in "examples/blink" provides an example of how
|
||||||
|
to do this.
|
||||||
|
*/
|
||||||
#ifndef __DEFAULT_FREERTOS_CONFIG_H
|
#ifndef __DEFAULT_FREERTOS_CONFIG_H
|
||||||
#define __DEFAULT_FREERTOS_CONFIG_H
|
#define __DEFAULT_FREERTOS_CONFIG_H
|
||||||
|
|
||||||
|
@ -36,7 +20,7 @@
|
||||||
* application requirements.
|
* application requirements.
|
||||||
*
|
*
|
||||||
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
|
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
|
||||||
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
|
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
|
||||||
*
|
*
|
||||||
* See http://www.freertos.org/a00110.html.
|
* See http://www.freertos.org/a00110.html.
|
||||||
*----------------------------------------------------------*/
|
*----------------------------------------------------------*/
|
||||||
|
@ -50,20 +34,13 @@
|
||||||
#define configUSE_TICK_HOOK 0
|
#define configUSE_TICK_HOOK 0
|
||||||
#endif
|
#endif
|
||||||
#ifndef configCPU_CLOCK_HZ
|
#ifndef configCPU_CLOCK_HZ
|
||||||
/* This is the _default_ clock speed for the CPU. Can be either 80MHz
|
|
||||||
* or 160MHz, and the system will set the clock speed to match at startup.
|
|
||||||
*
|
|
||||||
* Note that it's possible to change the clock speed at runtime, so you
|
|
||||||
* can/should use sdk_system_get_cpu_frequency() in order to determine the
|
|
||||||
* current CPU frequency, in preference to this macro.
|
|
||||||
*/
|
|
||||||
#define configCPU_CLOCK_HZ ( ( unsigned long ) 80000000 )
|
#define configCPU_CLOCK_HZ ( ( unsigned long ) 80000000 )
|
||||||
#endif
|
#endif
|
||||||
#ifndef configTICK_RATE_HZ
|
#ifndef configTICK_RATE_HZ
|
||||||
#define configTICK_RATE_HZ ( ( TickType_t ) 100 )
|
#define configTICK_RATE_HZ ( ( portTickType ) 100 )
|
||||||
#endif
|
#endif
|
||||||
#ifndef configMAX_PRIORITIES
|
#ifndef configMAX_PRIORITIES
|
||||||
#define configMAX_PRIORITIES ( 15 )
|
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 15 )
|
||||||
#endif
|
#endif
|
||||||
#ifndef configMINIMAL_STACK_SIZE
|
#ifndef configMINIMAL_STACK_SIZE
|
||||||
#define configMINIMAL_STACK_SIZE ( ( unsigned short )256 )
|
#define configMINIMAL_STACK_SIZE ( ( unsigned short )256 )
|
||||||
|
@ -97,9 +74,6 @@
|
||||||
#ifndef configCHECK_FOR_STACK_OVERFLOW
|
#ifndef configCHECK_FOR_STACK_OVERFLOW
|
||||||
#define configCHECK_FOR_STACK_OVERFLOW 2
|
#define configCHECK_FOR_STACK_OVERFLOW 2
|
||||||
#endif
|
#endif
|
||||||
#ifndef configUSE_RECURSIVE_MUTEXES
|
|
||||||
#define configUSE_RECURSIVE_MUTEXES 1
|
|
||||||
#endif
|
|
||||||
#ifndef configUSE_MUTEXES
|
#ifndef configUSE_MUTEXES
|
||||||
#define configUSE_MUTEXES 1
|
#define configUSE_MUTEXES 1
|
||||||
#endif
|
#endif
|
||||||
|
@ -107,6 +81,7 @@
|
||||||
#define configUSE_TIMERS 1
|
#define configUSE_TIMERS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if configUSE_TIMERS
|
#if configUSE_TIMERS
|
||||||
#ifndef configTIMER_TASK_PRIORITY
|
#ifndef configTIMER_TASK_PRIORITY
|
||||||
#define configTIMER_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
#define configTIMER_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
|
||||||
|
@ -127,10 +102,6 @@
|
||||||
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
|
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef configUSE_NEWLIB_REENTRANT
|
|
||||||
#define configUSE_NEWLIB_REENTRANT 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set the following definitions to 1 to include the API function, or zero
|
/* Set the following definitions to 1 to include the API function, or zero
|
||||||
to exclude the API function. */
|
to exclude the API function. */
|
||||||
#ifndef INCLUDE_vTaskPrioritySet
|
#ifndef INCLUDE_vTaskPrioritySet
|
||||||
|
@ -163,14 +134,5 @@ to exclude the API function. */
|
||||||
#define INCLUDE_uxTaskGetStackHighWaterMark 1
|
#define INCLUDE_uxTaskGetStackHighWaterMark 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef configENABLE_BACKWARD_COMPATIBILITY
|
|
||||||
#define configENABLE_BACKWARD_COMPATIBILITY 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Normal assert() semantics without relying on the provision of an assert.h
|
|
||||||
header file. */
|
|
||||||
void vAssertCalled(const char * pcFile, unsigned long ulLine);
|
|
||||||
#define configASSERT(x) if((x) == 0) vAssertCalled(__FILE__, __LINE__);
|
|
||||||
|
|
||||||
#endif /* __DEFAULT_FREERTOS_CONFIG_H */
|
#endif /* __DEFAULT_FREERTOS_CONFIG_H */
|
||||||
|
|
||||||
|
|
179
FreeRTOS/Source/include/StackMacros.h
Normal file
179
FreeRTOS/Source/include/StackMacros.h
Normal file
|
@ -0,0 +1,179 @@
|
||||||
|
/*
|
||||||
|
FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||||
|
|
||||||
|
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* FreeRTOS provides completely free yet professionally developed, *
|
||||||
|
* robust, strictly quality controlled, supported, and cross *
|
||||||
|
* platform software that has become a de facto standard. *
|
||||||
|
* *
|
||||||
|
* Help yourself get started quickly and support the FreeRTOS *
|
||||||
|
* project by purchasing a FreeRTOS tutorial book, reference *
|
||||||
|
* manual, or both from: http://www.FreeRTOS.org/Documentation *
|
||||||
|
* *
|
||||||
|
* Thank you! *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
This file is part of the FreeRTOS distribution.
|
||||||
|
|
||||||
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
|
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||||
|
|
||||||
|
>>! NOTE: The modification to the GPL is included to allow you to distribute
|
||||||
|
>>! a combined work that includes FreeRTOS without being obliged to provide
|
||||||
|
>>! the source code for proprietary components outside of the FreeRTOS
|
||||||
|
>>! kernel.
|
||||||
|
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. Full license text is available from the following
|
||||||
|
link: http://www.freertos.org/a00114.html
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* Having a problem? Start by reading the FAQ "My application does *
|
||||||
|
* not run, what could be wrong?" *
|
||||||
|
* *
|
||||||
|
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||||
|
license and Real Time Engineers Ltd. contact details.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||||
|
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||||
|
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||||
|
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||||
|
licenses offer ticketed support, indemnification and middleware.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||||
|
engineered and independently SIL3 certified version for use in safety and
|
||||||
|
mission critical applications that require provable dependability.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef STACK_MACROS_H
|
||||||
|
#define STACK_MACROS_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Call the stack overflow hook function if the stack of the task being swapped
|
||||||
|
* out is currently overflowed, or looks like it might have overflowed in the
|
||||||
|
* past.
|
||||||
|
*
|
||||||
|
* Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
|
||||||
|
* the current stack state only - comparing the current top of stack value to
|
||||||
|
* the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
|
||||||
|
* will also cause the last few stack bytes to be checked to ensure the value
|
||||||
|
* to which the bytes were set when the task was created have not been
|
||||||
|
* overwritten. Note this second test does not guarantee that an overflowed
|
||||||
|
* stack will always be recognised.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if( configCHECK_FOR_STACK_OVERFLOW == 0 )
|
||||||
|
|
||||||
|
/* FreeRTOSConfig.h is not set to check for stack overflows. */
|
||||||
|
#define taskFIRST_CHECK_FOR_STACK_OVERFLOW()
|
||||||
|
#define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
|
||||||
|
|
||||||
|
#endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if( configCHECK_FOR_STACK_OVERFLOW == 1 )
|
||||||
|
|
||||||
|
/* FreeRTOSConfig.h is only set to use the first method of
|
||||||
|
overflow checking. */
|
||||||
|
#define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
|
||||||
|
|
||||||
|
#endif
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )
|
||||||
|
|
||||||
|
/* Only the current stack state is to be checked. */
|
||||||
|
#define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
|
||||||
|
{ \
|
||||||
|
/* Is the currently saved stack pointer within the stack limit? */ \
|
||||||
|
if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \
|
||||||
|
{ \
|
||||||
|
vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* configCHECK_FOR_STACK_OVERFLOW > 0 */
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )
|
||||||
|
|
||||||
|
/* Only the current stack state is to be checked. */
|
||||||
|
#define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
|
||||||
|
{ \
|
||||||
|
\
|
||||||
|
/* Is the currently saved stack pointer within the stack limit? */ \
|
||||||
|
if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \
|
||||||
|
{ \
|
||||||
|
vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
|
||||||
|
|
||||||
|
#define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
|
||||||
|
{ \
|
||||||
|
static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||||
|
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||||
|
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||||
|
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||||
|
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
|
||||||
|
\
|
||||||
|
\
|
||||||
|
/* Has the extremity of the task stack ever been written over? */ \
|
||||||
|
if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
|
||||||
|
{ \
|
||||||
|
vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
|
||||||
|
|
||||||
|
#define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
|
||||||
|
{ \
|
||||||
|
char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack; \
|
||||||
|
static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||||
|
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||||
|
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||||
|
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
||||||
|
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
|
||||||
|
\
|
||||||
|
\
|
||||||
|
pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
|
||||||
|
\
|
||||||
|
/* Has the extremity of the task stack ever been written over? */ \
|
||||||
|
if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
|
||||||
|
{ \
|
||||||
|
vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#endif /* STACK_MACROS_H */
|
||||||
|
|
|
@ -1,29 +1,66 @@
|
||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.2.0
|
FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
***************************************************************************
|
||||||
* the Software without restriction, including without limitation the rights to
|
* *
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* FreeRTOS provides completely free yet professionally developed, *
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* robust, strictly quality controlled, supported, and cross *
|
||||||
* subject to the following conditions:
|
* platform software that has become a de facto standard. *
|
||||||
*
|
* *
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* Help yourself get started quickly and support the FreeRTOS *
|
||||||
* copies or substantial portions of the Software.
|
* project by purchasing a FreeRTOS tutorial book, reference *
|
||||||
*
|
* manual, or both from: http://www.FreeRTOS.org/Documentation *
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* *
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* Thank you! *
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* *
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
***************************************************************************
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
This file is part of the FreeRTOS distribution.
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
* http://aws.amazon.com/freertos
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
*
|
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
>>! NOTE: The modification to the GPL is included to allow you to distribute
|
||||||
|
>>! a combined work that includes FreeRTOS without being obliged to provide
|
||||||
|
>>! the source code for proprietary components outside of the FreeRTOS
|
||||||
|
>>! kernel.
|
||||||
|
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. Full license text is available from the following
|
||||||
|
link: http://www.freertos.org/a00114.html
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* Having a problem? Start by reading the FAQ "My application does *
|
||||||
|
* not run, what could be wrong?" *
|
||||||
|
* *
|
||||||
|
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||||
|
license and Real Time Engineers Ltd. contact details.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||||
|
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||||
|
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||||
|
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||||
|
licenses offer ticketed support, indemnification and middleware.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||||
|
engineered and independently SIL3 certified version for use in safety and
|
||||||
|
mission critical applications that require provable dependability.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef CO_ROUTINE_H
|
#ifndef CO_ROUTINE_H
|
||||||
#define CO_ROUTINE_H
|
#define CO_ROUTINE_H
|
||||||
|
@ -41,28 +78,28 @@ extern "C" {
|
||||||
/* Used to hide the implementation of the co-routine control block. The
|
/* Used to hide the implementation of the co-routine control block. The
|
||||||
control block structure however has to be included in the header due to
|
control block structure however has to be included in the header due to
|
||||||
the macro implementation of the co-routine functionality. */
|
the macro implementation of the co-routine functionality. */
|
||||||
typedef void * CoRoutineHandle_t;
|
typedef void * xCoRoutineHandle;
|
||||||
|
|
||||||
/* Defines the prototype to which co-routine functions must conform. */
|
/* Defines the prototype to which co-routine functions must conform. */
|
||||||
typedef void (*crCOROUTINE_CODE)( CoRoutineHandle_t, UBaseType_t );
|
typedef void (*crCOROUTINE_CODE)( xCoRoutineHandle, unsigned portBASE_TYPE );
|
||||||
|
|
||||||
typedef struct corCoRoutineControlBlock
|
typedef struct corCoRoutineControlBlock
|
||||||
{
|
{
|
||||||
crCOROUTINE_CODE pxCoRoutineFunction;
|
crCOROUTINE_CODE pxCoRoutineFunction;
|
||||||
ListItem_t xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */
|
xListItem xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */
|
||||||
ListItem_t xEventListItem; /*< List item used to place the CRCB in event lists. */
|
xListItem xEventListItem; /*< List item used to place the CRCB in event lists. */
|
||||||
UBaseType_t uxPriority; /*< The priority of the co-routine in relation to other co-routines. */
|
unsigned portBASE_TYPE uxPriority; /*< The priority of the co-routine in relation to other co-routines. */
|
||||||
UBaseType_t uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */
|
unsigned portBASE_TYPE uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */
|
||||||
uint16_t uxState; /*< Used internally by the co-routine implementation. */
|
unsigned short uxState; /*< Used internally by the co-routine implementation. */
|
||||||
} CRCB_t; /* Co-routine control block. Note must be identical in size down to uxPriority with TCB_t. */
|
} corCRCB; /* Co-routine control block. Note must be identical in size down to uxPriority with tskTCB. */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* croutine. h
|
* croutine. h
|
||||||
*<pre>
|
*<pre>
|
||||||
BaseType_t xCoRoutineCreate(
|
portBASE_TYPE xCoRoutineCreate(
|
||||||
crCOROUTINE_CODE pxCoRoutineCode,
|
crCOROUTINE_CODE pxCoRoutineCode,
|
||||||
UBaseType_t uxPriority,
|
unsigned portBASE_TYPE uxPriority,
|
||||||
UBaseType_t uxIndex
|
unsigned portBASE_TYPE uxIndex
|
||||||
);</pre>
|
);</pre>
|
||||||
*
|
*
|
||||||
* Create a new co-routine and add it to the list of co-routines that are
|
* Create a new co-routine and add it to the list of co-routines that are
|
||||||
|
@ -85,12 +122,12 @@ typedef struct corCoRoutineControlBlock
|
||||||
* Example usage:
|
* Example usage:
|
||||||
<pre>
|
<pre>
|
||||||
// Co-routine to be created.
|
// Co-routine to be created.
|
||||||
void vFlashCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
|
void vFlashCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
|
||||||
{
|
{
|
||||||
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
||||||
// This may not be necessary for const variables.
|
// This may not be necessary for const variables.
|
||||||
static const char cLedToFlash[ 2 ] = { 5, 6 };
|
static const char cLedToFlash[ 2 ] = { 5, 6 };
|
||||||
static const TickType_t uxFlashRates[ 2 ] = { 200, 400 };
|
static const portTickType uxFlashRates[ 2 ] = { 200, 400 };
|
||||||
|
|
||||||
// Must start every co-routine with a call to crSTART();
|
// Must start every co-routine with a call to crSTART();
|
||||||
crSTART( xHandle );
|
crSTART( xHandle );
|
||||||
|
@ -100,7 +137,7 @@ typedef struct corCoRoutineControlBlock
|
||||||
// This co-routine just delays for a fixed period, then toggles
|
// This co-routine just delays for a fixed period, then toggles
|
||||||
// an LED. Two co-routines are created using this function, so
|
// an LED. Two co-routines are created using this function, so
|
||||||
// the uxIndex parameter is used to tell the co-routine which
|
// the uxIndex parameter is used to tell the co-routine which
|
||||||
// LED to flash and how int32_t to delay. This assumes xQueue has
|
// LED to flash and how long to delay. This assumes xQueue has
|
||||||
// already been created.
|
// already been created.
|
||||||
vParTestToggleLED( cLedToFlash[ uxIndex ] );
|
vParTestToggleLED( cLedToFlash[ uxIndex ] );
|
||||||
crDELAY( xHandle, uxFlashRates[ uxIndex ] );
|
crDELAY( xHandle, uxFlashRates[ uxIndex ] );
|
||||||
|
@ -113,9 +150,9 @@ typedef struct corCoRoutineControlBlock
|
||||||
// Function that creates two co-routines.
|
// Function that creates two co-routines.
|
||||||
void vOtherFunction( void )
|
void vOtherFunction( void )
|
||||||
{
|
{
|
||||||
uint8_t ucParameterToPass;
|
unsigned char ucParameterToPass;
|
||||||
TaskHandle_t xHandle;
|
xTaskHandle xHandle;
|
||||||
|
|
||||||
// Create two co-routines at priority 0. The first is given index 0
|
// Create two co-routines at priority 0. The first is given index 0
|
||||||
// so (from the code above) toggles LED 5 every 200 ticks. The second
|
// so (from the code above) toggles LED 5 every 200 ticks. The second
|
||||||
// is given index 1 so toggles LED 6 every 400 ticks.
|
// is given index 1 so toggles LED 6 every 400 ticks.
|
||||||
|
@ -128,7 +165,7 @@ typedef struct corCoRoutineControlBlock
|
||||||
* \defgroup xCoRoutineCreate xCoRoutineCreate
|
* \defgroup xCoRoutineCreate xCoRoutineCreate
|
||||||
* \ingroup Tasks
|
* \ingroup Tasks
|
||||||
*/
|
*/
|
||||||
BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex );
|
signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,17 +212,17 @@ void vCoRoutineSchedule( void );
|
||||||
/**
|
/**
|
||||||
* croutine. h
|
* croutine. h
|
||||||
* <pre>
|
* <pre>
|
||||||
crSTART( CoRoutineHandle_t xHandle );</pre>
|
crSTART( xCoRoutineHandle xHandle );</pre>
|
||||||
*
|
*
|
||||||
* This macro MUST always be called at the start of a co-routine function.
|
* This macro MUST always be called at the start of a co-routine function.
|
||||||
*
|
*
|
||||||
* Example usage:
|
* Example usage:
|
||||||
<pre>
|
<pre>
|
||||||
// Co-routine to be created.
|
// Co-routine to be created.
|
||||||
void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
|
void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
|
||||||
{
|
{
|
||||||
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
||||||
static int32_t ulAVariable;
|
static long ulAVariable;
|
||||||
|
|
||||||
// Must start every co-routine with a call to crSTART();
|
// Must start every co-routine with a call to crSTART();
|
||||||
crSTART( xHandle );
|
crSTART( xHandle );
|
||||||
|
@ -201,7 +238,7 @@ void vCoRoutineSchedule( void );
|
||||||
* \defgroup crSTART crSTART
|
* \defgroup crSTART crSTART
|
||||||
* \ingroup Tasks
|
* \ingroup Tasks
|
||||||
*/
|
*/
|
||||||
#define crSTART( pxCRCB ) switch( ( ( CRCB_t * )( pxCRCB ) )->uxState ) { case 0:
|
#define crSTART( pxCRCB ) switch( ( ( corCRCB * )( pxCRCB ) )->uxState ) { case 0:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* croutine. h
|
* croutine. h
|
||||||
|
@ -213,10 +250,10 @@ void vCoRoutineSchedule( void );
|
||||||
* Example usage:
|
* Example usage:
|
||||||
<pre>
|
<pre>
|
||||||
// Co-routine to be created.
|
// Co-routine to be created.
|
||||||
void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
|
void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
|
||||||
{
|
{
|
||||||
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
||||||
static int32_t ulAVariable;
|
static long ulAVariable;
|
||||||
|
|
||||||
// Must start every co-routine with a call to crSTART();
|
// Must start every co-routine with a call to crSTART();
|
||||||
crSTART( xHandle );
|
crSTART( xHandle );
|
||||||
|
@ -238,13 +275,13 @@ void vCoRoutineSchedule( void );
|
||||||
* These macros are intended for internal use by the co-routine implementation
|
* These macros are intended for internal use by the co-routine implementation
|
||||||
* only. The macros should not be used directly by application writers.
|
* only. The macros should not be used directly by application writers.
|
||||||
*/
|
*/
|
||||||
#define crSET_STATE0( xHandle ) ( ( CRCB_t * )( xHandle ) )->uxState = (__LINE__ * 2); return; case (__LINE__ * 2):
|
#define crSET_STATE0( xHandle ) ( ( corCRCB * )( xHandle ) )->uxState = (__LINE__ * 2); return; case (__LINE__ * 2):
|
||||||
#define crSET_STATE1( xHandle ) ( ( CRCB_t * )( xHandle ) )->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1):
|
#define crSET_STATE1( xHandle ) ( ( corCRCB * )( xHandle ) )->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* croutine. h
|
* croutine. h
|
||||||
*<pre>
|
*<pre>
|
||||||
crDELAY( CoRoutineHandle_t xHandle, TickType_t xTicksToDelay );</pre>
|
crDELAY( xCoRoutineHandle xHandle, portTickType xTicksToDelay );</pre>
|
||||||
*
|
*
|
||||||
* Delay a co-routine for a fixed period of time.
|
* Delay a co-routine for a fixed period of time.
|
||||||
*
|
*
|
||||||
|
@ -257,18 +294,18 @@ void vCoRoutineSchedule( void );
|
||||||
*
|
*
|
||||||
* @param xTickToDelay The number of ticks that the co-routine should delay
|
* @param xTickToDelay The number of ticks that the co-routine should delay
|
||||||
* for. The actual amount of time this equates to is defined by
|
* for. The actual amount of time this equates to is defined by
|
||||||
* configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant portTICK_PERIOD_MS
|
* configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant portTICK_RATE_MS
|
||||||
* can be used to convert ticks to milliseconds.
|
* can be used to convert ticks to milliseconds.
|
||||||
*
|
*
|
||||||
* Example usage:
|
* Example usage:
|
||||||
<pre>
|
<pre>
|
||||||
// Co-routine to be created.
|
// Co-routine to be created.
|
||||||
void vACoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
|
void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
|
||||||
{
|
{
|
||||||
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
||||||
// This may not be necessary for const variables.
|
// This may not be necessary for const variables.
|
||||||
// We are to delay for 200ms.
|
// We are to delay for 200ms.
|
||||||
static const xTickType xDelayTime = 200 / portTICK_PERIOD_MS;
|
static const xTickType xDelayTime = 200 / portTICK_RATE_MS;
|
||||||
|
|
||||||
// Must start every co-routine with a call to crSTART();
|
// Must start every co-routine with a call to crSTART();
|
||||||
crSTART( xHandle );
|
crSTART( xHandle );
|
||||||
|
@ -297,11 +334,11 @@ void vCoRoutineSchedule( void );
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
crQUEUE_SEND(
|
crQUEUE_SEND(
|
||||||
CoRoutineHandle_t xHandle,
|
xCoRoutineHandle xHandle,
|
||||||
QueueHandle_t pxQueue,
|
xQueueHandle pxQueue,
|
||||||
void *pvItemToQueue,
|
void *pvItemToQueue,
|
||||||
TickType_t xTicksToWait,
|
portTickType xTicksToWait,
|
||||||
BaseType_t *pxResult
|
portBASE_TYPE *pxResult
|
||||||
)</pre>
|
)</pre>
|
||||||
*
|
*
|
||||||
* The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine
|
* The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine
|
||||||
|
@ -334,7 +371,7 @@ void vCoRoutineSchedule( void );
|
||||||
* to wait for space to become available on the queue, should space not be
|
* to wait for space to become available on the queue, should space not be
|
||||||
* available immediately. The actual amount of time this equates to is defined
|
* available immediately. The actual amount of time this equates to is defined
|
||||||
* by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant
|
* by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant
|
||||||
* portTICK_PERIOD_MS can be used to convert ticks to milliseconds (see example
|
* portTICK_RATE_MS can be used to convert ticks to milliseconds (see example
|
||||||
* below).
|
* below).
|
||||||
*
|
*
|
||||||
* @param pxResult The variable pointed to by pxResult will be set to pdPASS if
|
* @param pxResult The variable pointed to by pxResult will be set to pdPASS if
|
||||||
|
@ -345,11 +382,11 @@ void vCoRoutineSchedule( void );
|
||||||
<pre>
|
<pre>
|
||||||
// Co-routine function that blocks for a fixed period then posts a number onto
|
// Co-routine function that blocks for a fixed period then posts a number onto
|
||||||
// a queue.
|
// a queue.
|
||||||
static void prvCoRoutineFlashTask( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
|
static void prvCoRoutineFlashTask( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
|
||||||
{
|
{
|
||||||
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
||||||
static BaseType_t xNumberToPost = 0;
|
static portBASE_TYPE xNumberToPost = 0;
|
||||||
static BaseType_t xResult;
|
static portBASE_TYPE xResult;
|
||||||
|
|
||||||
// Co-routines must begin with a call to crSTART().
|
// Co-routines must begin with a call to crSTART().
|
||||||
crSTART( xHandle );
|
crSTART( xHandle );
|
||||||
|
@ -396,11 +433,11 @@ void vCoRoutineSchedule( void );
|
||||||
* croutine. h
|
* croutine. h
|
||||||
* <pre>
|
* <pre>
|
||||||
crQUEUE_RECEIVE(
|
crQUEUE_RECEIVE(
|
||||||
CoRoutineHandle_t xHandle,
|
xCoRoutineHandle xHandle,
|
||||||
QueueHandle_t pxQueue,
|
xQueueHandle pxQueue,
|
||||||
void *pvBuffer,
|
void *pvBuffer,
|
||||||
TickType_t xTicksToWait,
|
portTickType xTicksToWait,
|
||||||
BaseType_t *pxResult
|
portBASE_TYPE *pxResult
|
||||||
)</pre>
|
)</pre>
|
||||||
*
|
*
|
||||||
* The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine
|
* The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine
|
||||||
|
@ -432,7 +469,7 @@ void vCoRoutineSchedule( void );
|
||||||
* to wait for data to become available from the queue, should data not be
|
* to wait for data to become available from the queue, should data not be
|
||||||
* available immediately. The actual amount of time this equates to is defined
|
* available immediately. The actual amount of time this equates to is defined
|
||||||
* by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant
|
* by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant
|
||||||
* portTICK_PERIOD_MS can be used to convert ticks to milliseconds (see the
|
* portTICK_RATE_MS can be used to convert ticks to milliseconds (see the
|
||||||
* crQUEUE_SEND example).
|
* crQUEUE_SEND example).
|
||||||
*
|
*
|
||||||
* @param pxResult The variable pointed to by pxResult will be set to pdPASS if
|
* @param pxResult The variable pointed to by pxResult will be set to pdPASS if
|
||||||
|
@ -443,11 +480,11 @@ void vCoRoutineSchedule( void );
|
||||||
<pre>
|
<pre>
|
||||||
// A co-routine receives the number of an LED to flash from a queue. It
|
// A co-routine receives the number of an LED to flash from a queue. It
|
||||||
// blocks on the queue until the number is received.
|
// blocks on the queue until the number is received.
|
||||||
static void prvCoRoutineFlashWorkTask( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
|
static void prvCoRoutineFlashWorkTask( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
|
||||||
{
|
{
|
||||||
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
// Variables in co-routines must be declared static if they must maintain value across a blocking call.
|
||||||
static BaseType_t xResult;
|
static portBASE_TYPE xResult;
|
||||||
static UBaseType_t uxLEDToFlash;
|
static unsigned portBASE_TYPE uxLEDToFlash;
|
||||||
|
|
||||||
// All co-routines must start with a call to crSTART().
|
// All co-routines must start with a call to crSTART().
|
||||||
crSTART( xHandle );
|
crSTART( xHandle );
|
||||||
|
@ -488,9 +525,9 @@ void vCoRoutineSchedule( void );
|
||||||
* croutine. h
|
* croutine. h
|
||||||
* <pre>
|
* <pre>
|
||||||
crQUEUE_SEND_FROM_ISR(
|
crQUEUE_SEND_FROM_ISR(
|
||||||
QueueHandle_t pxQueue,
|
xQueueHandle pxQueue,
|
||||||
void *pvItemToQueue,
|
void *pvItemToQueue,
|
||||||
BaseType_t xCoRoutinePreviouslyWoken
|
portBASE_TYPE xCoRoutinePreviouslyWoken
|
||||||
)</pre>
|
)</pre>
|
||||||
*
|
*
|
||||||
* The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the
|
* The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the
|
||||||
|
@ -528,10 +565,10 @@ void vCoRoutineSchedule( void );
|
||||||
* Example usage:
|
* Example usage:
|
||||||
<pre>
|
<pre>
|
||||||
// A co-routine that blocks on a queue waiting for characters to be received.
|
// A co-routine that blocks on a queue waiting for characters to be received.
|
||||||
static void vReceivingCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
|
static void vReceivingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
|
||||||
{
|
{
|
||||||
char cRxedChar;
|
char cRxedChar;
|
||||||
BaseType_t xResult;
|
portBASE_TYPE xResult;
|
||||||
|
|
||||||
// All co-routines must start with a call to crSTART().
|
// All co-routines must start with a call to crSTART().
|
||||||
crSTART( xHandle );
|
crSTART( xHandle );
|
||||||
|
@ -558,7 +595,7 @@ void vCoRoutineSchedule( void );
|
||||||
void vUART_ISR( void )
|
void vUART_ISR( void )
|
||||||
{
|
{
|
||||||
char cRxedChar;
|
char cRxedChar;
|
||||||
BaseType_t xCRWokenByPost = pdFALSE;
|
portBASE_TYPE xCRWokenByPost = pdFALSE;
|
||||||
|
|
||||||
// We loop around reading characters until there are none left in the UART.
|
// We loop around reading characters until there are none left in the UART.
|
||||||
while( UART_RX_REG_NOT_EMPTY() )
|
while( UART_RX_REG_NOT_EMPTY() )
|
||||||
|
@ -585,9 +622,9 @@ void vCoRoutineSchedule( void );
|
||||||
* croutine. h
|
* croutine. h
|
||||||
* <pre>
|
* <pre>
|
||||||
crQUEUE_SEND_FROM_ISR(
|
crQUEUE_SEND_FROM_ISR(
|
||||||
QueueHandle_t pxQueue,
|
xQueueHandle pxQueue,
|
||||||
void *pvBuffer,
|
void *pvBuffer,
|
||||||
BaseType_t * pxCoRoutineWoken
|
portBASE_TYPE * pxCoRoutineWoken
|
||||||
)</pre>
|
)</pre>
|
||||||
*
|
*
|
||||||
* The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the
|
* The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the
|
||||||
|
@ -626,12 +663,12 @@ void vCoRoutineSchedule( void );
|
||||||
<pre>
|
<pre>
|
||||||
// A co-routine that posts a character to a queue then blocks for a fixed
|
// A co-routine that posts a character to a queue then blocks for a fixed
|
||||||
// period. The character is incremented each time.
|
// period. The character is incremented each time.
|
||||||
static void vSendingCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
|
static void vSendingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
|
||||||
{
|
{
|
||||||
// cChar holds its value while this co-routine is blocked and must therefore
|
// cChar holds its value while this co-routine is blocked and must therefore
|
||||||
// be declared static.
|
// be declared static.
|
||||||
static char cCharToTx = 'a';
|
static char cCharToTx = 'a';
|
||||||
BaseType_t xResult;
|
portBASE_TYPE xResult;
|
||||||
|
|
||||||
// All co-routines must start with a call to crSTART().
|
// All co-routines must start with a call to crSTART().
|
||||||
crSTART( xHandle );
|
crSTART( xHandle );
|
||||||
|
@ -674,7 +711,7 @@ void vCoRoutineSchedule( void );
|
||||||
void vUART_ISR( void )
|
void vUART_ISR( void )
|
||||||
{
|
{
|
||||||
char cCharToTx;
|
char cCharToTx;
|
||||||
BaseType_t xCRWokenByPost = pdFALSE;
|
portBASE_TYPE xCRWokenByPost = pdFALSE;
|
||||||
|
|
||||||
while( UART_TX_REG_EMPTY() )
|
while( UART_TX_REG_EMPTY() )
|
||||||
{
|
{
|
||||||
|
@ -702,7 +739,7 @@ void vCoRoutineSchedule( void );
|
||||||
* Removes the current co-routine from its ready list and places it in the
|
* Removes the current co-routine from its ready list and places it in the
|
||||||
* appropriate delayed list.
|
* appropriate delayed list.
|
||||||
*/
|
*/
|
||||||
void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList );
|
void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function is intended for internal use by the queue implementation only.
|
* This function is intended for internal use by the queue implementation only.
|
||||||
|
@ -711,7 +748,7 @@ void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList )
|
||||||
* Removes the highest priority co-routine from the event list and places it in
|
* Removes the highest priority co-routine from the event list and places it in
|
||||||
* the pending ready list.
|
* the pending ready list.
|
||||||
*/
|
*/
|
||||||
BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList );
|
signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,279 +0,0 @@
|
||||||
/*
|
|
||||||
* FreeRTOS Kernel V10.2.0
|
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
|
||||||
* http://aws.amazon.com/freertos
|
|
||||||
*
|
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DEPRECATED_DEFINITIONS_H
|
|
||||||
#define DEPRECATED_DEFINITIONS_H
|
|
||||||
|
|
||||||
|
|
||||||
/* Each FreeRTOS port has a unique portmacro.h header file. Originally a
|
|
||||||
pre-processor definition was used to ensure the pre-processor found the correct
|
|
||||||
portmacro.h file for the port being used. That scheme was deprecated in favour
|
|
||||||
of setting the compiler's include path such that it found the correct
|
|
||||||
portmacro.h file - removing the need for the constant and allowing the
|
|
||||||
portmacro.h file to be located anywhere in relation to the port being used. The
|
|
||||||
definitions below remain in the code for backward compatibility only. New
|
|
||||||
projects should not use them. */
|
|
||||||
|
|
||||||
#ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT
|
|
||||||
#include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h"
|
|
||||||
typedef void ( __interrupt __far *pxISR )();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef OPEN_WATCOM_FLASH_LITE_186_PORT
|
|
||||||
#include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h"
|
|
||||||
typedef void ( __interrupt __far *pxISR )();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_MEGA_AVR
|
|
||||||
#include "../portable/GCC/ATMega323/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IAR_MEGA_AVR
|
|
||||||
#include "../portable/IAR/ATMega323/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MPLAB_PIC24_PORT
|
|
||||||
#include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MPLAB_DSPIC_PORT
|
|
||||||
#include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MPLAB_PIC18F_PORT
|
|
||||||
#include "../../Source/portable/MPLAB/PIC18F/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MPLAB_PIC32MX_PORT
|
|
||||||
#include "../../Source/portable/MPLAB/PIC32MX/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _FEDPICC
|
|
||||||
#include "libFreeRTOS/Include/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SDCC_CYGNAL
|
|
||||||
#include "../../Source/portable/SDCC/Cygnal/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_ARM7
|
|
||||||
#include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_ARM7_ECLIPSE
|
|
||||||
#include "portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ROWLEY_LPC23xx
|
|
||||||
#include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IAR_MSP430
|
|
||||||
#include "..\..\Source\portable\IAR\MSP430\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_MSP430
|
|
||||||
#include "../../Source/portable/GCC/MSP430F449/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ROWLEY_MSP430
|
|
||||||
#include "../../Source/portable/Rowley/MSP430F449/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ARM7_LPC21xx_KEIL_RVDS
|
|
||||||
#include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SAM7_GCC
|
|
||||||
#include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SAM7_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SAM9XE_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LPC2000_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\LPC2000\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STR71X_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\STR71x\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STR75X_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\STR75x\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STR75X_GCC
|
|
||||||
#include "..\..\Source\portable\GCC\STR75x\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STR91X_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\STR91x\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_H8S
|
|
||||||
#include "../../Source/portable/GCC/H8S2329/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_AT91FR40008
|
|
||||||
#include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef RVDS_ARMCM3_LM3S102
|
|
||||||
#include "../../Source/portable/RVDS/ARM_CM3/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_ARMCM3_LM3S102
|
|
||||||
#include "../../Source/portable/GCC/ARM_CM3/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_ARMCM3
|
|
||||||
#include "../../Source/portable/GCC/ARM_CM3/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IAR_ARM_CM3
|
|
||||||
#include "../../Source/portable/IAR/ARM_CM3/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IAR_ARMCM3_LM
|
|
||||||
#include "../../Source/portable/IAR/ARM_CM3/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HCS12_CODE_WARRIOR
|
|
||||||
#include "../../Source/portable/CodeWarrior/HCS12/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MICROBLAZE_GCC
|
|
||||||
#include "../../Source/portable/GCC/MicroBlaze/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TERN_EE
|
|
||||||
#include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_HCS12
|
|
||||||
#include "../../Source/portable/GCC/HCS12/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_MCF5235
|
|
||||||
#include "../../Source/portable/GCC/MCF5235/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef COLDFIRE_V2_GCC
|
|
||||||
#include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef COLDFIRE_V2_CODEWARRIOR
|
|
||||||
#include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_PPC405
|
|
||||||
#include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_PPC440
|
|
||||||
#include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _16FX_SOFTUNE
|
|
||||||
#include "..\..\Source\portable\Softune\MB96340\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BCC_INDUSTRIAL_PC_PORT
|
|
||||||
/* A short file name has to be used in place of the normal
|
|
||||||
FreeRTOSConfig.h when using the Borland compiler. */
|
|
||||||
#include "frconfig.h"
|
|
||||||
#include "..\portable\BCC\16BitDOS\PC\prtmacro.h"
|
|
||||||
typedef void ( __interrupt __far *pxISR )();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BCC_FLASH_LITE_186_PORT
|
|
||||||
/* A short file name has to be used in place of the normal
|
|
||||||
FreeRTOSConfig.h when using the Borland compiler. */
|
|
||||||
#include "frconfig.h"
|
|
||||||
#include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h"
|
|
||||||
typedef void ( __interrupt __far *pxISR )();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#ifdef __AVR32_AVR32A__
|
|
||||||
#include "portmacro.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __ICCAVR32__
|
|
||||||
#ifdef __CORE__
|
|
||||||
#if __CORE__ == __AVR32A__
|
|
||||||
#include "portmacro.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __91467D
|
|
||||||
#include "portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __96340
|
|
||||||
#include "portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __IAR_V850ES_Fx3__
|
|
||||||
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_V850ES_Jx3__
|
|
||||||
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_V850ES_Jx3_L__
|
|
||||||
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_V850ES_Jx2__
|
|
||||||
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_V850ES_Hx2__
|
|
||||||
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_78K0R_Kx3__
|
|
||||||
#include "../../Source/portable/IAR/78K0R/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_78K0R_Kx3L__
|
|
||||||
#include "../../Source/portable/IAR/78K0R/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* DEPRECATED_DEFINITIONS_H */
|
|
||||||
|
|
|
@ -1,757 +0,0 @@
|
||||||
/*
|
|
||||||
* FreeRTOS Kernel V10.2.0
|
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
|
||||||
* http://aws.amazon.com/freertos
|
|
||||||
*
|
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef EVENT_GROUPS_H
|
|
||||||
#define EVENT_GROUPS_H
|
|
||||||
|
|
||||||
#ifndef INC_FREERTOS_H
|
|
||||||
#error "include FreeRTOS.h" must appear in source files before "include event_groups.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* FreeRTOS includes. */
|
|
||||||
#include "timers.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An event group is a collection of bits to which an application can assign a
|
|
||||||
* meaning. For example, an application may create an event group to convey
|
|
||||||
* the status of various CAN bus related events in which bit 0 might mean "A CAN
|
|
||||||
* message has been received and is ready for processing", bit 1 might mean "The
|
|
||||||
* application has queued a message that is ready for sending onto the CAN
|
|
||||||
* network", and bit 2 might mean "It is time to send a SYNC message onto the
|
|
||||||
* CAN network" etc. A task can then test the bit values to see which events
|
|
||||||
* are active, and optionally enter the Blocked state to wait for a specified
|
|
||||||
* bit or a group of specified bits to be active. To continue the CAN bus
|
|
||||||
* example, a CAN controlling task can enter the Blocked state (and therefore
|
|
||||||
* not consume any processing time) until either bit 0, bit 1 or bit 2 are
|
|
||||||
* active, at which time the bit that was actually active would inform the task
|
|
||||||
* which action it had to take (process a received message, send a message, or
|
|
||||||
* send a SYNC).
|
|
||||||
*
|
|
||||||
* The event groups implementation contains intelligence to avoid race
|
|
||||||
* conditions that would otherwise occur were an application to use a simple
|
|
||||||
* variable for the same purpose. This is particularly important with respect
|
|
||||||
* to when a bit within an event group is to be cleared, and when bits have to
|
|
||||||
* be set and then tested atomically - as is the case where event groups are
|
|
||||||
* used to create a synchronisation point between multiple tasks (a
|
|
||||||
* 'rendezvous').
|
|
||||||
*
|
|
||||||
* \defgroup EventGroup
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*
|
|
||||||
* Type by which event groups are referenced. For example, a call to
|
|
||||||
* xEventGroupCreate() returns an EventGroupHandle_t variable that can then
|
|
||||||
* be used as a parameter to other event group functions.
|
|
||||||
*
|
|
||||||
* \defgroup EventGroupHandle_t EventGroupHandle_t
|
|
||||||
* \ingroup EventGroup
|
|
||||||
*/
|
|
||||||
struct EventGroupDef_t;
|
|
||||||
typedef struct EventGroupDef_t * EventGroupHandle_t;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The type that holds event bits always matches TickType_t - therefore the
|
|
||||||
* number of bits it holds is set by configUSE_16_BIT_TICKS (16 bits if set to 1,
|
|
||||||
* 32 bits if set to 0.
|
|
||||||
*
|
|
||||||
* \defgroup EventBits_t EventBits_t
|
|
||||||
* \ingroup EventGroup
|
|
||||||
*/
|
|
||||||
typedef TickType_t EventBits_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*<pre>
|
|
||||||
EventGroupHandle_t xEventGroupCreate( void );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Create a new event group.
|
|
||||||
*
|
|
||||||
* Internally, within the FreeRTOS implementation, event groups use a [small]
|
|
||||||
* block of memory, in which the event group's structure is stored. If an event
|
|
||||||
* groups is created using xEventGropuCreate() then the required memory is
|
|
||||||
* automatically dynamically allocated inside the xEventGroupCreate() function.
|
|
||||||
* (see http://www.freertos.org/a00111.html). If an event group is created
|
|
||||||
* using xEventGropuCreateStatic() then the application writer must instead
|
|
||||||
* provide the memory that will get used by the event group.
|
|
||||||
* xEventGroupCreateStatic() therefore allows an event group to be created
|
|
||||||
* without using any dynamic memory allocation.
|
|
||||||
*
|
|
||||||
* Although event groups are not related to ticks, for internal implementation
|
|
||||||
* reasons the number of bits available for use in an event group is dependent
|
|
||||||
* on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If
|
|
||||||
* configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit
|
|
||||||
* 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has
|
|
||||||
* 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store
|
|
||||||
* event bits within an event group.
|
|
||||||
*
|
|
||||||
* @return If the event group was created then a handle to the event group is
|
|
||||||
* returned. If there was insufficient FreeRTOS heap available to create the
|
|
||||||
* event group then NULL is returned. See http://www.freertos.org/a00111.html
|
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
<pre>
|
|
||||||
// Declare a variable to hold the created event group.
|
|
||||||
EventGroupHandle_t xCreatedEventGroup;
|
|
||||||
|
|
||||||
// Attempt to create the event group.
|
|
||||||
xCreatedEventGroup = xEventGroupCreate();
|
|
||||||
|
|
||||||
// Was the event group created successfully?
|
|
||||||
if( xCreatedEventGroup == NULL )
|
|
||||||
{
|
|
||||||
// The event group was not created because there was insufficient
|
|
||||||
// FreeRTOS heap available.
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// The event group was created.
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xEventGroupCreate xEventGroupCreate
|
|
||||||
* \ingroup EventGroup
|
|
||||||
*/
|
|
||||||
#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
|
|
||||||
EventGroupHandle_t xEventGroupCreate( void ) PRIVILEGED_FUNCTION;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*<pre>
|
|
||||||
EventGroupHandle_t xEventGroupCreateStatic( EventGroupHandle_t * pxEventGroupBuffer );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Create a new event group.
|
|
||||||
*
|
|
||||||
* Internally, within the FreeRTOS implementation, event groups use a [small]
|
|
||||||
* block of memory, in which the event group's structure is stored. If an event
|
|
||||||
* groups is created using xEventGropuCreate() then the required memory is
|
|
||||||
* automatically dynamically allocated inside the xEventGroupCreate() function.
|
|
||||||
* (see http://www.freertos.org/a00111.html). If an event group is created
|
|
||||||
* using xEventGropuCreateStatic() then the application writer must instead
|
|
||||||
* provide the memory that will get used by the event group.
|
|
||||||
* xEventGroupCreateStatic() therefore allows an event group to be created
|
|
||||||
* without using any dynamic memory allocation.
|
|
||||||
*
|
|
||||||
* Although event groups are not related to ticks, for internal implementation
|
|
||||||
* reasons the number of bits available for use in an event group is dependent
|
|
||||||
* on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If
|
|
||||||
* configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit
|
|
||||||
* 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has
|
|
||||||
* 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store
|
|
||||||
* event bits within an event group.
|
|
||||||
*
|
|
||||||
* @param pxEventGroupBuffer pxEventGroupBuffer must point to a variable of type
|
|
||||||
* StaticEventGroup_t, which will be then be used to hold the event group's data
|
|
||||||
* structures, removing the need for the memory to be allocated dynamically.
|
|
||||||
*
|
|
||||||
* @return If the event group was created then a handle to the event group is
|
|
||||||
* returned. If pxEventGroupBuffer was NULL then NULL is returned.
|
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
<pre>
|
|
||||||
// StaticEventGroup_t is a publicly accessible structure that has the same
|
|
||||||
// size and alignment requirements as the real event group structure. It is
|
|
||||||
// provided as a mechanism for applications to know the size of the event
|
|
||||||
// group (which is dependent on the architecture and configuration file
|
|
||||||
// settings) without breaking the strict data hiding policy by exposing the
|
|
||||||
// real event group internals. This StaticEventGroup_t variable is passed
|
|
||||||
// into the xSemaphoreCreateEventGroupStatic() function and is used to store
|
|
||||||
// the event group's data structures
|
|
||||||
StaticEventGroup_t xEventGroupBuffer;
|
|
||||||
|
|
||||||
// Create the event group without dynamically allocating any memory.
|
|
||||||
xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
|
|
||||||
</pre>
|
|
||||||
*/
|
|
||||||
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
|
|
||||||
EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t *pxEventGroupBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*<pre>
|
|
||||||
EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
|
|
||||||
const EventBits_t uxBitsToWaitFor,
|
|
||||||
const BaseType_t xClearOnExit,
|
|
||||||
const BaseType_t xWaitForAllBits,
|
|
||||||
const TickType_t xTicksToWait );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* [Potentially] block to wait for one or more bits to be set within a
|
|
||||||
* previously created event group.
|
|
||||||
*
|
|
||||||
* This function cannot be called from an interrupt.
|
|
||||||
*
|
|
||||||
* @param xEventGroup The event group in which the bits are being tested. The
|
|
||||||
* event group must have previously been created using a call to
|
|
||||||
* xEventGroupCreate().
|
|
||||||
*
|
|
||||||
* @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test
|
|
||||||
* inside the event group. For example, to wait for bit 0 and/or bit 2 set
|
|
||||||
* uxBitsToWaitFor to 0x05. To wait for bits 0 and/or bit 1 and/or bit 2 set
|
|
||||||
* uxBitsToWaitFor to 0x07. Etc.
|
|
||||||
*
|
|
||||||
* @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within
|
|
||||||
* uxBitsToWaitFor that are set within the event group will be cleared before
|
|
||||||
* xEventGroupWaitBits() returns if the wait condition was met (if the function
|
|
||||||
* returns for a reason other than a timeout). If xClearOnExit is set to
|
|
||||||
* pdFALSE then the bits set in the event group are not altered when the call to
|
|
||||||
* xEventGroupWaitBits() returns.
|
|
||||||
*
|
|
||||||
* @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then
|
|
||||||
* xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor
|
|
||||||
* are set or the specified block time expires. If xWaitForAllBits is set to
|
|
||||||
* pdFALSE then xEventGroupWaitBits() will return when any one of the bits set
|
|
||||||
* in uxBitsToWaitFor is set or the specified block time expires. The block
|
|
||||||
* time is specified by the xTicksToWait parameter.
|
|
||||||
*
|
|
||||||
* @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
|
|
||||||
* for one/all (depending on the xWaitForAllBits value) of the bits specified by
|
|
||||||
* uxBitsToWaitFor to become set.
|
|
||||||
*
|
|
||||||
* @return The value of the event group at the time either the bits being waited
|
|
||||||
* for became set, or the block time expired. Test the return value to know
|
|
||||||
* which bits were set. If xEventGroupWaitBits() returned because its timeout
|
|
||||||
* expired then not all the bits being waited for will be set. If
|
|
||||||
* xEventGroupWaitBits() returned because the bits it was waiting for were set
|
|
||||||
* then the returned value is the event group value before any bits were
|
|
||||||
* automatically cleared in the case that xClearOnExit parameter was set to
|
|
||||||
* pdTRUE.
|
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
<pre>
|
|
||||||
#define BIT_0 ( 1 << 0 )
|
|
||||||
#define BIT_4 ( 1 << 4 )
|
|
||||||
|
|
||||||
void aFunction( EventGroupHandle_t xEventGroup )
|
|
||||||
{
|
|
||||||
EventBits_t uxBits;
|
|
||||||
const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
|
|
||||||
|
|
||||||
// Wait a maximum of 100ms for either bit 0 or bit 4 to be set within
|
|
||||||
// the event group. Clear the bits before exiting.
|
|
||||||
uxBits = xEventGroupWaitBits(
|
|
||||||
xEventGroup, // The event group being tested.
|
|
||||||
BIT_0 | BIT_4, // The bits within the event group to wait for.
|
|
||||||
pdTRUE, // BIT_0 and BIT_4 should be cleared before returning.
|
|
||||||
pdFALSE, // Don't wait for both bits, either bit will do.
|
|
||||||
xTicksToWait ); // Wait a maximum of 100ms for either bit to be set.
|
|
||||||
|
|
||||||
if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
|
|
||||||
{
|
|
||||||
// xEventGroupWaitBits() returned because both bits were set.
|
|
||||||
}
|
|
||||||
else if( ( uxBits & BIT_0 ) != 0 )
|
|
||||||
{
|
|
||||||
// xEventGroupWaitBits() returned because just BIT_0 was set.
|
|
||||||
}
|
|
||||||
else if( ( uxBits & BIT_4 ) != 0 )
|
|
||||||
{
|
|
||||||
// xEventGroupWaitBits() returned because just BIT_4 was set.
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// xEventGroupWaitBits() returned because xTicksToWait ticks passed
|
|
||||||
// without either BIT_0 or BIT_4 becoming set.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xEventGroupWaitBits xEventGroupWaitBits
|
|
||||||
* \ingroup EventGroup
|
|
||||||
*/
|
|
||||||
EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*<pre>
|
|
||||||
EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Clear bits within an event group. This function cannot be called from an
|
|
||||||
* interrupt.
|
|
||||||
*
|
|
||||||
* @param xEventGroup The event group in which the bits are to be cleared.
|
|
||||||
*
|
|
||||||
* @param uxBitsToClear A bitwise value that indicates the bit or bits to clear
|
|
||||||
* in the event group. For example, to clear bit 3 only, set uxBitsToClear to
|
|
||||||
* 0x08. To clear bit 3 and bit 0 set uxBitsToClear to 0x09.
|
|
||||||
*
|
|
||||||
* @return The value of the event group before the specified bits were cleared.
|
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
<pre>
|
|
||||||
#define BIT_0 ( 1 << 0 )
|
|
||||||
#define BIT_4 ( 1 << 4 )
|
|
||||||
|
|
||||||
void aFunction( EventGroupHandle_t xEventGroup )
|
|
||||||
{
|
|
||||||
EventBits_t uxBits;
|
|
||||||
|
|
||||||
// Clear bit 0 and bit 4 in xEventGroup.
|
|
||||||
uxBits = xEventGroupClearBits(
|
|
||||||
xEventGroup, // The event group being updated.
|
|
||||||
BIT_0 | BIT_4 );// The bits being cleared.
|
|
||||||
|
|
||||||
if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
|
|
||||||
{
|
|
||||||
// Both bit 0 and bit 4 were set before xEventGroupClearBits() was
|
|
||||||
// called. Both will now be clear (not set).
|
|
||||||
}
|
|
||||||
else if( ( uxBits & BIT_0 ) != 0 )
|
|
||||||
{
|
|
||||||
// Bit 0 was set before xEventGroupClearBits() was called. It will
|
|
||||||
// now be clear.
|
|
||||||
}
|
|
||||||
else if( ( uxBits & BIT_4 ) != 0 )
|
|
||||||
{
|
|
||||||
// Bit 4 was set before xEventGroupClearBits() was called. It will
|
|
||||||
// now be clear.
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Neither bit 0 nor bit 4 were set in the first place.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xEventGroupClearBits xEventGroupClearBits
|
|
||||||
* \ingroup EventGroup
|
|
||||||
*/
|
|
||||||
EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*<pre>
|
|
||||||
BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* A version of xEventGroupClearBits() that can be called from an interrupt.
|
|
||||||
*
|
|
||||||
* Setting bits in an event group is not a deterministic operation because there
|
|
||||||
* are an unknown number of tasks that may be waiting for the bit or bits being
|
|
||||||
* set. FreeRTOS does not allow nondeterministic operations to be performed
|
|
||||||
* while interrupts are disabled, so protects event groups that are accessed
|
|
||||||
* from tasks by suspending the scheduler rather than disabling interrupts. As
|
|
||||||
* a result event groups cannot be accessed directly from an interrupt service
|
|
||||||
* routine. Therefore xEventGroupClearBitsFromISR() sends a message to the
|
|
||||||
* timer task to have the clear operation performed in the context of the timer
|
|
||||||
* task.
|
|
||||||
*
|
|
||||||
* @param xEventGroup The event group in which the bits are to be cleared.
|
|
||||||
*
|
|
||||||
* @param uxBitsToClear A bitwise value that indicates the bit or bits to clear.
|
|
||||||
* For example, to clear bit 3 only, set uxBitsToClear to 0x08. To clear bit 3
|
|
||||||
* and bit 0 set uxBitsToClear to 0x09.
|
|
||||||
*
|
|
||||||
* @return If the request to execute the function was posted successfully then
|
|
||||||
* pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned
|
|
||||||
* if the timer service queue was full.
|
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
<pre>
|
|
||||||
#define BIT_0 ( 1 << 0 )
|
|
||||||
#define BIT_4 ( 1 << 4 )
|
|
||||||
|
|
||||||
// An event group which it is assumed has already been created by a call to
|
|
||||||
// xEventGroupCreate().
|
|
||||||
EventGroupHandle_t xEventGroup;
|
|
||||||
|
|
||||||
void anInterruptHandler( void )
|
|
||||||
{
|
|
||||||
// Clear bit 0 and bit 4 in xEventGroup.
|
|
||||||
xResult = xEventGroupClearBitsFromISR(
|
|
||||||
xEventGroup, // The event group being updated.
|
|
||||||
BIT_0 | BIT_4 ); // The bits being set.
|
|
||||||
|
|
||||||
if( xResult == pdPASS )
|
|
||||||
{
|
|
||||||
// The message was posted successfully.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xEventGroupClearBitsFromISR xEventGroupClearBitsFromISR
|
|
||||||
* \ingroup EventGroup
|
|
||||||
*/
|
|
||||||
#if( configUSE_TRACE_FACILITY == 1 )
|
|
||||||
BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) PRIVILEGED_FUNCTION;
|
|
||||||
#else
|
|
||||||
#define xEventGroupClearBitsFromISR( xEventGroup, uxBitsToClear ) xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*<pre>
|
|
||||||
EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Set bits within an event group.
|
|
||||||
* This function cannot be called from an interrupt. xEventGroupSetBitsFromISR()
|
|
||||||
* is a version that can be called from an interrupt.
|
|
||||||
*
|
|
||||||
* Setting bits in an event group will automatically unblock tasks that are
|
|
||||||
* blocked waiting for the bits.
|
|
||||||
*
|
|
||||||
* @param xEventGroup The event group in which the bits are to be set.
|
|
||||||
*
|
|
||||||
* @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
|
|
||||||
* For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
|
|
||||||
* and bit 0 set uxBitsToSet to 0x09.
|
|
||||||
*
|
|
||||||
* @return The value of the event group at the time the call to
|
|
||||||
* xEventGroupSetBits() returns. There are two reasons why the returned value
|
|
||||||
* might have the bits specified by the uxBitsToSet parameter cleared. First,
|
|
||||||
* if setting a bit results in a task that was waiting for the bit leaving the
|
|
||||||
* blocked state then it is possible the bit will be cleared automatically
|
|
||||||
* (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any
|
|
||||||
* unblocked (or otherwise Ready state) task that has a priority above that of
|
|
||||||
* the task that called xEventGroupSetBits() will execute and may change the
|
|
||||||
* event group value before the call to xEventGroupSetBits() returns.
|
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
<pre>
|
|
||||||
#define BIT_0 ( 1 << 0 )
|
|
||||||
#define BIT_4 ( 1 << 4 )
|
|
||||||
|
|
||||||
void aFunction( EventGroupHandle_t xEventGroup )
|
|
||||||
{
|
|
||||||
EventBits_t uxBits;
|
|
||||||
|
|
||||||
// Set bit 0 and bit 4 in xEventGroup.
|
|
||||||
uxBits = xEventGroupSetBits(
|
|
||||||
xEventGroup, // The event group being updated.
|
|
||||||
BIT_0 | BIT_4 );// The bits being set.
|
|
||||||
|
|
||||||
if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
|
|
||||||
{
|
|
||||||
// Both bit 0 and bit 4 remained set when the function returned.
|
|
||||||
}
|
|
||||||
else if( ( uxBits & BIT_0 ) != 0 )
|
|
||||||
{
|
|
||||||
// Bit 0 remained set when the function returned, but bit 4 was
|
|
||||||
// cleared. It might be that bit 4 was cleared automatically as a
|
|
||||||
// task that was waiting for bit 4 was removed from the Blocked
|
|
||||||
// state.
|
|
||||||
}
|
|
||||||
else if( ( uxBits & BIT_4 ) != 0 )
|
|
||||||
{
|
|
||||||
// Bit 4 remained set when the function returned, but bit 0 was
|
|
||||||
// cleared. It might be that bit 0 was cleared automatically as a
|
|
||||||
// task that was waiting for bit 0 was removed from the Blocked
|
|
||||||
// state.
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Neither bit 0 nor bit 4 remained set. It might be that a task
|
|
||||||
// was waiting for both of the bits to be set, and the bits were
|
|
||||||
// cleared as the task left the Blocked state.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xEventGroupSetBits xEventGroupSetBits
|
|
||||||
* \ingroup EventGroup
|
|
||||||
*/
|
|
||||||
EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*<pre>
|
|
||||||
BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* A version of xEventGroupSetBits() that can be called from an interrupt.
|
|
||||||
*
|
|
||||||
* Setting bits in an event group is not a deterministic operation because there
|
|
||||||
* are an unknown number of tasks that may be waiting for the bit or bits being
|
|
||||||
* set. FreeRTOS does not allow nondeterministic operations to be performed in
|
|
||||||
* interrupts or from critical sections. Therefore xEventGroupSetBitsFromISR()
|
|
||||||
* sends a message to the timer task to have the set operation performed in the
|
|
||||||
* context of the timer task - where a scheduler lock is used in place of a
|
|
||||||
* critical section.
|
|
||||||
*
|
|
||||||
* @param xEventGroup The event group in which the bits are to be set.
|
|
||||||
*
|
|
||||||
* @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
|
|
||||||
* For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
|
|
||||||
* and bit 0 set uxBitsToSet to 0x09.
|
|
||||||
*
|
|
||||||
* @param pxHigherPriorityTaskWoken As mentioned above, calling this function
|
|
||||||
* will result in a message being sent to the timer daemon task. If the
|
|
||||||
* priority of the timer daemon task is higher than the priority of the
|
|
||||||
* currently running task (the task the interrupt interrupted) then
|
|
||||||
* *pxHigherPriorityTaskWoken will be set to pdTRUE by
|
|
||||||
* xEventGroupSetBitsFromISR(), indicating that a context switch should be
|
|
||||||
* requested before the interrupt exits. For that reason
|
|
||||||
* *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
|
|
||||||
* example code below.
|
|
||||||
*
|
|
||||||
* @return If the request to execute the function was posted successfully then
|
|
||||||
* pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned
|
|
||||||
* if the timer service queue was full.
|
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
<pre>
|
|
||||||
#define BIT_0 ( 1 << 0 )
|
|
||||||
#define BIT_4 ( 1 << 4 )
|
|
||||||
|
|
||||||
// An event group which it is assumed has already been created by a call to
|
|
||||||
// xEventGroupCreate().
|
|
||||||
EventGroupHandle_t xEventGroup;
|
|
||||||
|
|
||||||
void anInterruptHandler( void )
|
|
||||||
{
|
|
||||||
BaseType_t xHigherPriorityTaskWoken, xResult;
|
|
||||||
|
|
||||||
// xHigherPriorityTaskWoken must be initialised to pdFALSE.
|
|
||||||
xHigherPriorityTaskWoken = pdFALSE;
|
|
||||||
|
|
||||||
// Set bit 0 and bit 4 in xEventGroup.
|
|
||||||
xResult = xEventGroupSetBitsFromISR(
|
|
||||||
xEventGroup, // The event group being updated.
|
|
||||||
BIT_0 | BIT_4 // The bits being set.
|
|
||||||
&xHigherPriorityTaskWoken );
|
|
||||||
|
|
||||||
// Was the message posted successfully?
|
|
||||||
if( xResult == pdPASS )
|
|
||||||
{
|
|
||||||
// If xHigherPriorityTaskWoken is now set to pdTRUE then a context
|
|
||||||
// switch should be requested. The macro used is port specific and
|
|
||||||
// will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
|
|
||||||
// refer to the documentation page for the port being used.
|
|
||||||
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR
|
|
||||||
* \ingroup EventGroup
|
|
||||||
*/
|
|
||||||
#if( configUSE_TRACE_FACILITY == 1 )
|
|
||||||
BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
|
|
||||||
#else
|
|
||||||
#define xEventGroupSetBitsFromISR( xEventGroup, uxBitsToSet, pxHigherPriorityTaskWoken ) xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*<pre>
|
|
||||||
EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup,
|
|
||||||
const EventBits_t uxBitsToSet,
|
|
||||||
const EventBits_t uxBitsToWaitFor,
|
|
||||||
TickType_t xTicksToWait );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Atomically set bits within an event group, then wait for a combination of
|
|
||||||
* bits to be set within the same event group. This functionality is typically
|
|
||||||
* used to synchronise multiple tasks, where each task has to wait for the other
|
|
||||||
* tasks to reach a synchronisation point before proceeding.
|
|
||||||
*
|
|
||||||
* This function cannot be used from an interrupt.
|
|
||||||
*
|
|
||||||
* The function will return before its block time expires if the bits specified
|
|
||||||
* by the uxBitsToWait parameter are set, or become set within that time. In
|
|
||||||
* this case all the bits specified by uxBitsToWait will be automatically
|
|
||||||
* cleared before the function returns.
|
|
||||||
*
|
|
||||||
* @param xEventGroup The event group in which the bits are being tested. The
|
|
||||||
* event group must have previously been created using a call to
|
|
||||||
* xEventGroupCreate().
|
|
||||||
*
|
|
||||||
* @param uxBitsToSet The bits to set in the event group before determining
|
|
||||||
* if, and possibly waiting for, all the bits specified by the uxBitsToWait
|
|
||||||
* parameter are set.
|
|
||||||
*
|
|
||||||
* @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test
|
|
||||||
* inside the event group. For example, to wait for bit 0 and bit 2 set
|
|
||||||
* uxBitsToWaitFor to 0x05. To wait for bits 0 and bit 1 and bit 2 set
|
|
||||||
* uxBitsToWaitFor to 0x07. Etc.
|
|
||||||
*
|
|
||||||
* @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
|
|
||||||
* for all of the bits specified by uxBitsToWaitFor to become set.
|
|
||||||
*
|
|
||||||
* @return The value of the event group at the time either the bits being waited
|
|
||||||
* for became set, or the block time expired. Test the return value to know
|
|
||||||
* which bits were set. If xEventGroupSync() returned because its timeout
|
|
||||||
* expired then not all the bits being waited for will be set. If
|
|
||||||
* xEventGroupSync() returned because all the bits it was waiting for were
|
|
||||||
* set then the returned value is the event group value before any bits were
|
|
||||||
* automatically cleared.
|
|
||||||
*
|
|
||||||
* Example usage:
|
|
||||||
<pre>
|
|
||||||
// Bits used by the three tasks.
|
|
||||||
#define TASK_0_BIT ( 1 << 0 )
|
|
||||||
#define TASK_1_BIT ( 1 << 1 )
|
|
||||||
#define TASK_2_BIT ( 1 << 2 )
|
|
||||||
|
|
||||||
#define ALL_SYNC_BITS ( TASK_0_BIT | TASK_1_BIT | TASK_2_BIT )
|
|
||||||
|
|
||||||
// Use an event group to synchronise three tasks. It is assumed this event
|
|
||||||
// group has already been created elsewhere.
|
|
||||||
EventGroupHandle_t xEventBits;
|
|
||||||
|
|
||||||
void vTask0( void *pvParameters )
|
|
||||||
{
|
|
||||||
EventBits_t uxReturn;
|
|
||||||
TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
|
|
||||||
|
|
||||||
for( ;; )
|
|
||||||
{
|
|
||||||
// Perform task functionality here.
|
|
||||||
|
|
||||||
// Set bit 0 in the event flag to note this task has reached the
|
|
||||||
// sync point. The other two tasks will set the other two bits defined
|
|
||||||
// by ALL_SYNC_BITS. All three tasks have reached the synchronisation
|
|
||||||
// point when all the ALL_SYNC_BITS are set. Wait a maximum of 100ms
|
|
||||||
// for this to happen.
|
|
||||||
uxReturn = xEventGroupSync( xEventBits, TASK_0_BIT, ALL_SYNC_BITS, xTicksToWait );
|
|
||||||
|
|
||||||
if( ( uxReturn & ALL_SYNC_BITS ) == ALL_SYNC_BITS )
|
|
||||||
{
|
|
||||||
// All three tasks reached the synchronisation point before the call
|
|
||||||
// to xEventGroupSync() timed out.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void vTask1( void *pvParameters )
|
|
||||||
{
|
|
||||||
for( ;; )
|
|
||||||
{
|
|
||||||
// Perform task functionality here.
|
|
||||||
|
|
||||||
// Set bit 1 in the event flag to note this task has reached the
|
|
||||||
// synchronisation point. The other two tasks will set the other two
|
|
||||||
// bits defined by ALL_SYNC_BITS. All three tasks have reached the
|
|
||||||
// synchronisation point when all the ALL_SYNC_BITS are set. Wait
|
|
||||||
// indefinitely for this to happen.
|
|
||||||
xEventGroupSync( xEventBits, TASK_1_BIT, ALL_SYNC_BITS, portMAX_DELAY );
|
|
||||||
|
|
||||||
// xEventGroupSync() was called with an indefinite block time, so
|
|
||||||
// this task will only reach here if the syncrhonisation was made by all
|
|
||||||
// three tasks, so there is no need to test the return value.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void vTask2( void *pvParameters )
|
|
||||||
{
|
|
||||||
for( ;; )
|
|
||||||
{
|
|
||||||
// Perform task functionality here.
|
|
||||||
|
|
||||||
// Set bit 2 in the event flag to note this task has reached the
|
|
||||||
// synchronisation point. The other two tasks will set the other two
|
|
||||||
// bits defined by ALL_SYNC_BITS. All three tasks have reached the
|
|
||||||
// synchronisation point when all the ALL_SYNC_BITS are set. Wait
|
|
||||||
// indefinitely for this to happen.
|
|
||||||
xEventGroupSync( xEventBits, TASK_2_BIT, ALL_SYNC_BITS, portMAX_DELAY );
|
|
||||||
|
|
||||||
// xEventGroupSync() was called with an indefinite block time, so
|
|
||||||
// this task will only reach here if the syncrhonisation was made by all
|
|
||||||
// three tasks, so there is no need to test the return value.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
</pre>
|
|
||||||
* \defgroup xEventGroupSync xEventGroupSync
|
|
||||||
* \ingroup EventGroup
|
|
||||||
*/
|
|
||||||
EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*<pre>
|
|
||||||
EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Returns the current value of the bits in an event group. This function
|
|
||||||
* cannot be used from an interrupt.
|
|
||||||
*
|
|
||||||
* @param xEventGroup The event group being queried.
|
|
||||||
*
|
|
||||||
* @return The event group bits at the time xEventGroupGetBits() was called.
|
|
||||||
*
|
|
||||||
* \defgroup xEventGroupGetBits xEventGroupGetBits
|
|
||||||
* \ingroup EventGroup
|
|
||||||
*/
|
|
||||||
#define xEventGroupGetBits( xEventGroup ) xEventGroupClearBits( xEventGroup, 0 )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*<pre>
|
|
||||||
EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* A version of xEventGroupGetBits() that can be called from an ISR.
|
|
||||||
*
|
|
||||||
* @param xEventGroup The event group being queried.
|
|
||||||
*
|
|
||||||
* @return The event group bits at the time xEventGroupGetBitsFromISR() was called.
|
|
||||||
*
|
|
||||||
* \defgroup xEventGroupGetBitsFromISR xEventGroupGetBitsFromISR
|
|
||||||
* \ingroup EventGroup
|
|
||||||
*/
|
|
||||||
EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* event_groups.h
|
|
||||||
*<pre>
|
|
||||||
void xEventGroupDelete( EventGroupHandle_t xEventGroup );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Delete an event group that was previously created by a call to
|
|
||||||
* xEventGroupCreate(). Tasks that are blocked on the event group will be
|
|
||||||
* unblocked and obtain 0 as the event group's value.
|
|
||||||
*
|
|
||||||
* @param xEventGroup The event group being deleted.
|
|
||||||
*/
|
|
||||||
void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/* For internal use only. */
|
|
||||||
void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet ) PRIVILEGED_FUNCTION;
|
|
||||||
void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
|
|
||||||
#if (configUSE_TRACE_FACILITY == 1)
|
|
||||||
UBaseType_t uxEventGroupGetNumber( void* xEventGroup ) PRIVILEGED_FUNCTION;
|
|
||||||
void vEventGroupSetNumber( void* xEventGroup, UBaseType_t uxEventGroupNumber ) PRIVILEGED_FUNCTION;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* EVENT_GROUPS_H */
|
|
||||||
|
|
||||||
|
|
|
@ -1,36 +1,73 @@
|
||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.2.0
|
FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
***************************************************************************
|
||||||
* the Software without restriction, including without limitation the rights to
|
* *
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* FreeRTOS provides completely free yet professionally developed, *
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* robust, strictly quality controlled, supported, and cross *
|
||||||
* subject to the following conditions:
|
* platform software that has become a de facto standard. *
|
||||||
*
|
* *
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* Help yourself get started quickly and support the FreeRTOS *
|
||||||
* copies or substantial portions of the Software.
|
* project by purchasing a FreeRTOS tutorial book, reference *
|
||||||
*
|
* manual, or both from: http://www.FreeRTOS.org/Documentation *
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* *
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* Thank you! *
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* *
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
***************************************************************************
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
This file is part of the FreeRTOS distribution.
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
* http://aws.amazon.com/freertos
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
*
|
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
>>! NOTE: The modification to the GPL is included to allow you to distribute
|
||||||
|
>>! a combined work that includes FreeRTOS without being obliged to provide
|
||||||
|
>>! the source code for proprietary components outside of the FreeRTOS
|
||||||
|
>>! kernel.
|
||||||
|
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. Full license text is available from the following
|
||||||
|
link: http://www.freertos.org/a00114.html
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* Having a problem? Start by reading the FAQ "My application does *
|
||||||
|
* not run, what could be wrong?" *
|
||||||
|
* *
|
||||||
|
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||||
|
license and Real Time Engineers Ltd. contact details.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||||
|
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||||
|
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||||
|
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||||
|
licenses offer ticketed support, indemnification and middleware.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||||
|
engineered and independently SIL3 certified version for use in safety and
|
||||||
|
mission critical applications that require provable dependability.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the list implementation used by the scheduler. While it is tailored
|
* This is the list implementation used by the scheduler. While it is tailored
|
||||||
* heavily for the schedulers needs, it is also available for use by
|
* heavily for the schedulers needs, it is also available for use by
|
||||||
* application code.
|
* application code.
|
||||||
*
|
*
|
||||||
* list_ts can only store pointers to list_item_ts. Each ListItem_t contains a
|
* xLists can only store pointers to xListItems. Each xListItem contains a
|
||||||
* numeric value (xItemValue). Most of the time the lists are sorted in
|
* numeric value (xItemValue). Most of the time the lists are sorted in
|
||||||
* descending item value order.
|
* descending item value order.
|
||||||
*
|
*
|
||||||
|
@ -53,9 +90,6 @@
|
||||||
* \ingroup FreeRTOSIntro
|
* \ingroup FreeRTOSIntro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef INC_FREERTOS_H
|
|
||||||
#error FreeRTOS.h must be included before list.h
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef LIST_H
|
#ifndef LIST_H
|
||||||
#define LIST_H
|
#define LIST_H
|
||||||
|
@ -80,8 +114,8 @@
|
||||||
* complete and obvious failure of the scheduler. If this is ever experienced
|
* complete and obvious failure of the scheduler. If this is ever experienced
|
||||||
* then the volatile qualifier can be inserted in the relevant places within the
|
* then the volatile qualifier can be inserted in the relevant places within the
|
||||||
* list structures by simply defining configLIST_VOLATILE to volatile in
|
* list structures by simply defining configLIST_VOLATILE to volatile in
|
||||||
* FreeRTOSConfig.h (as per the example at the bottom of this comment block).
|
* FreeRTOSConfig.h (as per the example at the bottom of this comment block).
|
||||||
* If configLIST_VOLATILE is not defined then the preprocessor directives below
|
* If configLIST_VOLATILE is not defined then the preprocessor directives below
|
||||||
* will simply #define configLIST_VOLATILE away completely.
|
* will simply #define configLIST_VOLATILE away completely.
|
||||||
*
|
*
|
||||||
* To use volatile list structure members then add the following line to
|
* To use volatile list structure members then add the following line to
|
||||||
|
@ -95,80 +129,36 @@
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Macros that can be used to place known values within the list structures,
|
|
||||||
then check that the known values do not get corrupted during the execution of
|
|
||||||
the application. These may catch the list data structures being overwritten in
|
|
||||||
memory. They will not catch data errors caused by incorrect configuration or
|
|
||||||
use of FreeRTOS.*/
|
|
||||||
#if( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 0 )
|
|
||||||
/* Define the macros to do nothing. */
|
|
||||||
#define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE
|
|
||||||
#define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE
|
|
||||||
#define listFIRST_LIST_INTEGRITY_CHECK_VALUE
|
|
||||||
#define listSECOND_LIST_INTEGRITY_CHECK_VALUE
|
|
||||||
#define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )
|
|
||||||
#define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )
|
|
||||||
#define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList )
|
|
||||||
#define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList )
|
|
||||||
#define listTEST_LIST_ITEM_INTEGRITY( pxItem )
|
|
||||||
#define listTEST_LIST_INTEGRITY( pxList )
|
|
||||||
#else
|
|
||||||
/* Define macros that add new members into the list structures. */
|
|
||||||
#define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue1;
|
|
||||||
#define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue2;
|
|
||||||
#define listFIRST_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue1;
|
|
||||||
#define listSECOND_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue2;
|
|
||||||
|
|
||||||
/* Define macros that set the new structure members to known values. */
|
|
||||||
#define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue1 = pdINTEGRITY_CHECK_VALUE
|
|
||||||
#define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue2 = pdINTEGRITY_CHECK_VALUE
|
|
||||||
#define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ) ( pxList )->xListIntegrityValue1 = pdINTEGRITY_CHECK_VALUE
|
|
||||||
#define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ) ( pxList )->xListIntegrityValue2 = pdINTEGRITY_CHECK_VALUE
|
|
||||||
|
|
||||||
/* Define macros that will assert if one of the structure members does not
|
|
||||||
contain its expected value. */
|
|
||||||
#define listTEST_LIST_ITEM_INTEGRITY( pxItem ) configASSERT( ( ( pxItem )->xListItemIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxItem )->xListItemIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) )
|
|
||||||
#define listTEST_LIST_INTEGRITY( pxList ) configASSERT( ( ( pxList )->xListIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxList )->xListIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) )
|
|
||||||
#endif /* configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES */
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Definition of the only type of object that a list can contain.
|
* Definition of the only type of object that a list can contain.
|
||||||
*/
|
*/
|
||||||
struct xLIST;
|
|
||||||
struct xLIST_ITEM
|
struct xLIST_ITEM
|
||||||
{
|
{
|
||||||
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
|
configLIST_VOLATILE portTickType xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */
|
||||||
configLIST_VOLATILE TickType_t xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */
|
struct xLIST_ITEM * configLIST_VOLATILE pxNext; /*< Pointer to the next xListItem in the list. */
|
||||||
struct xLIST_ITEM * configLIST_VOLATILE pxNext; /*< Pointer to the next ListItem_t in the list. */
|
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;/*< Pointer to the previous xListItem in the list. */
|
||||||
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; /*< Pointer to the previous ListItem_t in the list. */
|
void * pvOwner; /*< 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. */
|
||||||
void * pvOwner; /*< 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. */
|
void * configLIST_VOLATILE pvContainer; /*< Pointer to the list in which this list item is placed (if any). */
|
||||||
struct xLIST * configLIST_VOLATILE pxContainer; /*< Pointer to the list in which this list item is placed (if any). */
|
|
||||||
listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
|
|
||||||
};
|
};
|
||||||
typedef struct xLIST_ITEM ListItem_t; /* For some reason lint wants this as two separate definitions. */
|
typedef struct xLIST_ITEM xListItem; /* For some reason lint wants this as two separate definitions. */
|
||||||
|
|
||||||
struct xMINI_LIST_ITEM
|
struct xMINI_LIST_ITEM
|
||||||
{
|
{
|
||||||
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
|
configLIST_VOLATILE portTickType xItemValue;
|
||||||
configLIST_VOLATILE TickType_t xItemValue;
|
|
||||||
struct xLIST_ITEM * configLIST_VOLATILE pxNext;
|
struct xLIST_ITEM * configLIST_VOLATILE pxNext;
|
||||||
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;
|
struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;
|
||||||
};
|
};
|
||||||
typedef struct xMINI_LIST_ITEM MiniListItem_t;
|
typedef struct xMINI_LIST_ITEM xMiniListItem;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Definition of the type of queue used by the scheduler.
|
* Definition of the type of queue used by the scheduler.
|
||||||
*/
|
*/
|
||||||
typedef struct xLIST
|
typedef struct xLIST
|
||||||
{
|
{
|
||||||
listFIRST_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
|
configLIST_VOLATILE unsigned portBASE_TYPE uxNumberOfItems;
|
||||||
volatile UBaseType_t uxNumberOfItems;
|
xListItem * configLIST_VOLATILE pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to pvListGetOwnerOfNextEntry (). */
|
||||||
ListItem_t * configLIST_VOLATILE pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to listGET_OWNER_OF_NEXT_ENTRY (). */
|
xMiniListItem xListEnd; /*< 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. */
|
||||||
MiniListItem_t xListEnd; /*< 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. */
|
} xList;
|
||||||
listSECOND_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
|
|
||||||
} List_t;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Access macro to set the owner of a list item. The owner of a list item
|
* Access macro to set the owner of a list item. The owner of a list item
|
||||||
|
@ -186,7 +176,7 @@ typedef struct xLIST
|
||||||
* \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
|
* \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
|
||||||
* \ingroup LinkedList
|
* \ingroup LinkedList
|
||||||
*/
|
*/
|
||||||
#define listGET_LIST_ITEM_OWNER( pxListItem ) ( ( pxListItem )->pvOwner )
|
#define listGET_LIST_ITEM_OWNER( pxListItem ) ( pxListItem )->pvOwner
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Access macro to set the value of the list item. In most cases the value is
|
* Access macro to set the value of the list item. In most cases the value is
|
||||||
|
@ -195,50 +185,26 @@ typedef struct xLIST
|
||||||
* \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE
|
* \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE
|
||||||
* \ingroup LinkedList
|
* \ingroup LinkedList
|
||||||
*/
|
*/
|
||||||
#define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( ( pxListItem )->xItemValue = ( xValue ) )
|
#define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( ( pxListItem )->xItemValue = ( xValue ) )
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Access macro to retrieve the value of the list item. The value can
|
* Access macro to retrieve the value of the list item. The value can
|
||||||
* represent anything - for example the priority of a task, or the time at
|
* represent anything - for example a the priority of a task, or the time at
|
||||||
* which a task should be unblocked.
|
* which a task should be unblocked.
|
||||||
*
|
*
|
||||||
* \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
|
* \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
|
||||||
* \ingroup LinkedList
|
* \ingroup LinkedList
|
||||||
*/
|
*/
|
||||||
#define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue )
|
#define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue )
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Access macro to retrieve the value of the list item at the head of a given
|
* Access macro the retrieve the value of the list item at the head of a given
|
||||||
* list.
|
* list.
|
||||||
*
|
*
|
||||||
* \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
|
* \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
|
||||||
* \ingroup LinkedList
|
* \ingroup LinkedList
|
||||||
*/
|
*/
|
||||||
#define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext->xItemValue )
|
#define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList ) ( (&( ( pxList )->xListEnd ))->pxNext->xItemValue )
|
||||||
|
|
||||||
/*
|
|
||||||
* Return the list item at the head of the list.
|
|
||||||
*
|
|
||||||
* \page listGET_HEAD_ENTRY listGET_HEAD_ENTRY
|
|
||||||
* \ingroup LinkedList
|
|
||||||
*/
|
|
||||||
#define listGET_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext )
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return the list item at the head of the list.
|
|
||||||
*
|
|
||||||
* \page listGET_NEXT listGET_NEXT
|
|
||||||
* \ingroup LinkedList
|
|
||||||
*/
|
|
||||||
#define listGET_NEXT( pxListItem ) ( ( pxListItem )->pxNext )
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Return the list item that marks the end of the list
|
|
||||||
*
|
|
||||||
* \page listGET_END_MARKER listGET_END_MARKER
|
|
||||||
* \ingroup LinkedList
|
|
||||||
*/
|
|
||||||
#define listGET_END_MARKER( pxList ) ( ( ListItem_t const * ) ( &( ( pxList )->xListEnd ) ) )
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Access macro to determine if a list contains any items. The macro will
|
* Access macro to determine if a list contains any items. The macro will
|
||||||
|
@ -247,19 +213,19 @@ typedef struct xLIST
|
||||||
* \page listLIST_IS_EMPTY listLIST_IS_EMPTY
|
* \page listLIST_IS_EMPTY listLIST_IS_EMPTY
|
||||||
* \ingroup LinkedList
|
* \ingroup LinkedList
|
||||||
*/
|
*/
|
||||||
#define listLIST_IS_EMPTY( pxList ) ( ( ( pxList )->uxNumberOfItems == ( UBaseType_t ) 0 ) ? pdTRUE : pdFALSE )
|
#define listLIST_IS_EMPTY( pxList ) ( ( portBASE_TYPE ) ( ( pxList )->uxNumberOfItems == ( unsigned portBASE_TYPE ) 0 ) )
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Access macro to return the number of items in the list.
|
* Access macro to return the number of items in the list.
|
||||||
*/
|
*/
|
||||||
#define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems )
|
#define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems )
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Access function to obtain the owner of the next entry in a list.
|
* Access function to obtain the owner of the next entry in a list.
|
||||||
*
|
*
|
||||||
* The list member pxIndex is used to walk through a list. Calling
|
* The list member pxIndex is used to walk through a list. Calling
|
||||||
* listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list
|
* listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list
|
||||||
* and returns that entry's pxOwner parameter. Using multiple calls to this
|
* and returns that entries pxOwner parameter. Using multiple calls to this
|
||||||
* function it is therefore possible to move through every item contained in
|
* function it is therefore possible to move through every item contained in
|
||||||
* a list.
|
* a list.
|
||||||
*
|
*
|
||||||
|
@ -268,7 +234,6 @@ typedef struct xLIST
|
||||||
* The pxOwner parameter effectively creates a two way link between the list
|
* The pxOwner parameter effectively creates a two way link between the list
|
||||||
* item and its owner.
|
* item and its owner.
|
||||||
*
|
*
|
||||||
* @param pxTCB pxTCB is set to the address of the owner of the next list item.
|
|
||||||
* @param pxList The list from which the next item owner is to be returned.
|
* @param pxList The list from which the next item owner is to be returned.
|
||||||
*
|
*
|
||||||
* \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY
|
* \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY
|
||||||
|
@ -276,7 +241,7 @@ typedef struct xLIST
|
||||||
*/
|
*/
|
||||||
#define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \
|
#define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \
|
||||||
{ \
|
{ \
|
||||||
List_t * const pxConstList = ( pxList ); \
|
xList * const pxConstList = ( pxList ); \
|
||||||
/* Increment the index to the next item and return the item, ensuring */ \
|
/* Increment the index to the next item and return the item, ensuring */ \
|
||||||
/* we don't return the marker used at the end of the list. */ \
|
/* we don't return the marker used at the end of the list. */ \
|
||||||
( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \
|
( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \
|
||||||
|
@ -313,17 +278,18 @@ List_t * const pxConstList = ( pxList ); \
|
||||||
*
|
*
|
||||||
* @param pxList The list we want to know if the list item is within.
|
* @param pxList The list we want to know if the list item is within.
|
||||||
* @param pxListItem The list item we want to know if is in the list.
|
* @param pxListItem The list item we want to know if is in the list.
|
||||||
* @return pdTRUE if the list item is in the list, otherwise pdFALSE.
|
* @return pdTRUE is the list item is in the list, otherwise pdFALSE.
|
||||||
|
* pointer against
|
||||||
*/
|
*/
|
||||||
#define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( ( pxListItem )->pxContainer == ( pxList ) ) ? ( pdTRUE ) : ( pdFALSE ) )
|
#define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( portBASE_TYPE ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) ) )
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the list a list item is contained within (referenced from).
|
* Return the list a list item is contained within (referenced from).
|
||||||
*
|
*
|
||||||
* @param pxListItem The list item being queried.
|
* @param pxListItem The list item being queried.
|
||||||
* @return A pointer to the List_t object that references the pxListItem
|
* @return A pointer to the xList object that references the pxListItem
|
||||||
*/
|
*/
|
||||||
#define listLIST_ITEM_CONTAINER( pxListItem ) ( ( pxListItem )->pxContainer )
|
#define listLIST_ITEM_CONTAINER( pxListItem ) ( ( pxListItem )->pvContainer )
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This provides a crude means of knowing if a list has been initialised, as
|
* This provides a crude means of knowing if a list has been initialised, as
|
||||||
|
@ -342,7 +308,7 @@ List_t * const pxConstList = ( pxList ); \
|
||||||
* \page vListInitialise vListInitialise
|
* \page vListInitialise vListInitialise
|
||||||
* \ingroup LinkedList
|
* \ingroup LinkedList
|
||||||
*/
|
*/
|
||||||
void vListInitialise( List_t * const pxList ) PRIVILEGED_FUNCTION;
|
void vListInitialise( xList * const pxList );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Must be called before a list item is used. This sets the list container to
|
* Must be called before a list item is used. This sets the list container to
|
||||||
|
@ -353,7 +319,7 @@ void vListInitialise( List_t * const pxList ) PRIVILEGED_FUNCTION;
|
||||||
* \page vListInitialiseItem vListInitialiseItem
|
* \page vListInitialiseItem vListInitialiseItem
|
||||||
* \ingroup LinkedList
|
* \ingroup LinkedList
|
||||||
*/
|
*/
|
||||||
void vListInitialiseItem( ListItem_t * const pxItem ) PRIVILEGED_FUNCTION;
|
void vListInitialiseItem( xListItem * const pxItem );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Insert a list item into a list. The item will be inserted into the list in
|
* Insert a list item into a list. The item will be inserted into the list in
|
||||||
|
@ -361,24 +327,24 @@ void vListInitialiseItem( ListItem_t * const pxItem ) PRIVILEGED_FUNCTION;
|
||||||
*
|
*
|
||||||
* @param pxList The list into which the item is to be inserted.
|
* @param pxList The list into which the item is to be inserted.
|
||||||
*
|
*
|
||||||
* @param pxNewListItem The item that is to be placed in the list.
|
* @param pxNewListItem The item to that is to be placed in the list.
|
||||||
*
|
*
|
||||||
* \page vListInsert vListInsert
|
* \page vListInsert vListInsert
|
||||||
* \ingroup LinkedList
|
* \ingroup LinkedList
|
||||||
*/
|
*/
|
||||||
void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION;
|
void vListInsert( xList * const pxList, xListItem * const pxNewListItem );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Insert a list item into a list. The item will be inserted in a position
|
* Insert a list item into a list. The item will be inserted in a position
|
||||||
* such that it will be the last item within the list returned by multiple
|
* such that it will be the last item within the list returned by multiple
|
||||||
* calls to listGET_OWNER_OF_NEXT_ENTRY.
|
* calls to listGET_OWNER_OF_NEXT_ENTRY.
|
||||||
*
|
*
|
||||||
* The list member pxIndex is used to walk through a list. Calling
|
* The list member pvIndex is used to walk through a list. Calling
|
||||||
* listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list.
|
* listGET_OWNER_OF_NEXT_ENTRY increments pvIndex to the next item in the list.
|
||||||
* Placing an item in a list using vListInsertEnd effectively places the item
|
* Placing an item in a list using vListInsertEnd effectively places the item
|
||||||
* in the list position pointed to by pxIndex. This means that every other
|
* in the list position pointed to by pvIndex. This means that every other
|
||||||
* item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before
|
* item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before
|
||||||
* the pxIndex parameter again points to the item being inserted.
|
* the pvIndex parameter again points to the item being inserted.
|
||||||
*
|
*
|
||||||
* @param pxList The list into which the item is to be inserted.
|
* @param pxList The list into which the item is to be inserted.
|
||||||
*
|
*
|
||||||
|
@ -387,7 +353,7 @@ void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem ) PRIV
|
||||||
* \page vListInsertEnd vListInsertEnd
|
* \page vListInsertEnd vListInsertEnd
|
||||||
* \ingroup LinkedList
|
* \ingroup LinkedList
|
||||||
*/
|
*/
|
||||||
void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem ) PRIVILEGED_FUNCTION;
|
void vListInsertEnd( xList * const pxList, xListItem * const pxNewListItem );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove an item from a list. The list item has a pointer to the list that
|
* Remove an item from a list. The list item has a pointer to the list that
|
||||||
|
@ -402,7 +368,7 @@ void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem ) P
|
||||||
* \page uxListRemove uxListRemove
|
* \page uxListRemove uxListRemove
|
||||||
* \ingroup LinkedList
|
* \ingroup LinkedList
|
||||||
*/
|
*/
|
||||||
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) PRIVILEGED_FUNCTION;
|
unsigned portBASE_TYPE uxListRemove( xListItem * const pxItemToRemove );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,798 +0,0 @@
|
||||||
/*
|
|
||||||
* FreeRTOS Kernel V10.2.0
|
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
|
||||||
* http://aws.amazon.com/freertos
|
|
||||||
*
|
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Message buffers build functionality on top of FreeRTOS stream buffers.
|
|
||||||
* Whereas stream buffers are used to send a continuous stream of data from one
|
|
||||||
* task or interrupt to another, message buffers are used to send variable
|
|
||||||
* length discrete messages from one task or interrupt to another. Their
|
|
||||||
* implementation is light weight, making them particularly suited for interrupt
|
|
||||||
* to task and core to core communication scenarios.
|
|
||||||
*
|
|
||||||
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
|
|
||||||
* implementation (so also the message buffer implementation, as message buffers
|
|
||||||
* are built on top of stream buffers) assumes there is only one task or
|
|
||||||
* interrupt that will write to the buffer (the writer), and only one task or
|
|
||||||
* interrupt that will read from the buffer (the reader). It is safe for the
|
|
||||||
* writer and reader to be different tasks or interrupts, but, unlike other
|
|
||||||
* FreeRTOS objects, it is not safe to have multiple different writers or
|
|
||||||
* multiple different readers. If there are to be multiple different writers
|
|
||||||
* then the application writer must place each call to a writing API function
|
|
||||||
* (such as xMessageBufferSend()) inside a critical section and set the send
|
|
||||||
* block time to 0. Likewise, if there are to be multiple different readers
|
|
||||||
* then the application writer must place each call to a reading API function
|
|
||||||
* (such as xMessageBufferRead()) inside a critical section and set the receive
|
|
||||||
* timeout to 0.
|
|
||||||
*
|
|
||||||
* Message buffers hold variable length messages. To enable that, when a
|
|
||||||
* message is written to the message buffer an additional sizeof( size_t ) bytes
|
|
||||||
* are also written to store the message's length (that happens internally, with
|
|
||||||
* the API function). sizeof( size_t ) is typically 4 bytes on a 32-bit
|
|
||||||
* architecture, so writing a 10 byte message to a message buffer on a 32-bit
|
|
||||||
* architecture will actually reduce the available space in the message buffer
|
|
||||||
* by 14 bytes (10 byte are used by the message, and 4 bytes to hold the length
|
|
||||||
* of the message).
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FREERTOS_MESSAGE_BUFFER_H
|
|
||||||
#define FREERTOS_MESSAGE_BUFFER_H
|
|
||||||
|
|
||||||
/* Message buffers are built onto of stream buffers. */
|
|
||||||
#include "stream_buffer.h"
|
|
||||||
|
|
||||||
#if defined( __cplusplus )
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type by which message buffers are referenced. For example, a call to
|
|
||||||
* xMessageBufferCreate() returns an MessageBufferHandle_t variable that can
|
|
||||||
* then be used as a parameter to xMessageBufferSend(), xMessageBufferReceive(),
|
|
||||||
* etc.
|
|
||||||
*/
|
|
||||||
typedef void * MessageBufferHandle_t;
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
MessageBufferHandle_t xMessageBufferCreate( size_t xBufferSizeBytes );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Creates a new message buffer using dynamically allocated memory. See
|
|
||||||
* xMessageBufferCreateStatic() for a version that uses statically allocated
|
|
||||||
* memory (memory that is allocated at compile time).
|
|
||||||
*
|
|
||||||
* configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in
|
|
||||||
* FreeRTOSConfig.h for xMessageBufferCreate() to be available.
|
|
||||||
*
|
|
||||||
* @param xBufferSizeBytes The total number of bytes (not messages) the message
|
|
||||||
* buffer will be able to hold at any one time. When a message is written to
|
|
||||||
* the message buffer an additional sizeof( size_t ) bytes are also written to
|
|
||||||
* store the message's length. sizeof( size_t ) is typically 4 bytes on a
|
|
||||||
* 32-bit architecture, so on most 32-bit architectures a 10 byte message will
|
|
||||||
* take up 14 bytes of message buffer space.
|
|
||||||
*
|
|
||||||
* @return If NULL is returned, then the message buffer cannot be created
|
|
||||||
* because there is insufficient heap memory available for FreeRTOS to allocate
|
|
||||||
* the message buffer data structures and storage area. A non-NULL value being
|
|
||||||
* returned indicates that the message buffer has been created successfully -
|
|
||||||
* the returned value should be stored as the handle to the created message
|
|
||||||
* buffer.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
|
|
||||||
void vAFunction( void )
|
|
||||||
{
|
|
||||||
MessageBufferHandle_t xMessageBuffer;
|
|
||||||
const size_t xMessageBufferSizeBytes = 100;
|
|
||||||
|
|
||||||
// Create a message buffer that can hold 100 bytes. The memory used to hold
|
|
||||||
// both the message buffer structure and the messages themselves is allocated
|
|
||||||
// dynamically. Each message added to the buffer consumes an additional 4
|
|
||||||
// bytes which are used to hold the lengh of the message.
|
|
||||||
xMessageBuffer = xMessageBufferCreate( xMessageBufferSizeBytes );
|
|
||||||
|
|
||||||
if( xMessageBuffer == NULL )
|
|
||||||
{
|
|
||||||
// There was not enough heap memory space available to create the
|
|
||||||
// message buffer.
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// The message buffer was created successfully and can now be used.
|
|
||||||
}
|
|
||||||
|
|
||||||
</pre>
|
|
||||||
* \defgroup xMessageBufferCreate xMessageBufferCreate
|
|
||||||
* \ingroup MessageBufferManagement
|
|
||||||
*/
|
|
||||||
#define xMessageBufferCreate( xBufferSizeBytes ) ( MessageBufferHandle_t ) xStreamBufferGenericCreate( xBufferSizeBytes, ( size_t ) 0, pdTRUE )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
MessageBufferHandle_t xMessageBufferCreateStatic( size_t xBufferSizeBytes,
|
|
||||||
uint8_t *pucMessageBufferStorageArea,
|
|
||||||
StaticMessageBuffer_t *pxStaticMessageBuffer );
|
|
||||||
</pre>
|
|
||||||
* Creates a new message buffer using statically allocated memory. See
|
|
||||||
* xMessageBufferCreate() for a version that uses dynamically allocated memory.
|
|
||||||
*
|
|
||||||
* @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the
|
|
||||||
* pucMessageBufferStorageArea parameter. When a message is written to the
|
|
||||||
* message buffer an additional sizeof( size_t ) bytes are also written to store
|
|
||||||
* the message's length. sizeof( size_t ) is typically 4 bytes on a 32-bit
|
|
||||||
* architecture, so on most 32-bit architecture a 10 byte message will take up
|
|
||||||
* 14 bytes of message buffer space. The maximum number of bytes that can be
|
|
||||||
* stored in the message buffer is actually (xBufferSizeBytes - 1).
|
|
||||||
*
|
|
||||||
* @param pucMessageBufferStorageArea Must point to a uint8_t array that is at
|
|
||||||
* least xBufferSizeBytes + 1 big. This is the array to which messages are
|
|
||||||
* copied when they are written to the message buffer.
|
|
||||||
*
|
|
||||||
* @param pxStaticMessageBuffer Must point to a variable of type
|
|
||||||
* StaticMessageBuffer_t, which will be used to hold the message buffer's data
|
|
||||||
* structure.
|
|
||||||
*
|
|
||||||
* @return If the message buffer is created successfully then a handle to the
|
|
||||||
* created message buffer is returned. If either pucMessageBufferStorageArea or
|
|
||||||
* pxStaticmessageBuffer are NULL then NULL is returned.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
|
|
||||||
// Used to dimension the array used to hold the messages. The available space
|
|
||||||
// will actually be one less than this, so 999.
|
|
||||||
#define STORAGE_SIZE_BYTES 1000
|
|
||||||
|
|
||||||
// Defines the memory that will actually hold the messages within the message
|
|
||||||
// buffer.
|
|
||||||
static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
|
|
||||||
|
|
||||||
// The variable used to hold the message buffer structure.
|
|
||||||
StaticMessageBuffer_t xMessageBufferStruct;
|
|
||||||
|
|
||||||
void MyFunction( void )
|
|
||||||
{
|
|
||||||
MessageBufferHandle_t xMessageBuffer;
|
|
||||||
|
|
||||||
xMessageBuffer = xMessageBufferCreateStatic( sizeof( ucBufferStorage ),
|
|
||||||
ucBufferStorage,
|
|
||||||
&xMessageBufferStruct );
|
|
||||||
|
|
||||||
// As neither the pucMessageBufferStorageArea or pxStaticMessageBuffer
|
|
||||||
// parameters were NULL, xMessageBuffer will not be NULL, and can be used to
|
|
||||||
// reference the created message buffer in other message buffer API calls.
|
|
||||||
|
|
||||||
// Other code that uses the message buffer can go here.
|
|
||||||
}
|
|
||||||
|
|
||||||
</pre>
|
|
||||||
* \defgroup xMessageBufferCreateStatic xMessageBufferCreateStatic
|
|
||||||
* \ingroup MessageBufferManagement
|
|
||||||
*/
|
|
||||||
#define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) ( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
size_t xMessageBufferSend( MessageBufferHandle_t xMessageBuffer,
|
|
||||||
const void *pvTxData,
|
|
||||||
size_t xDataLengthBytes,
|
|
||||||
TickType_t xTicksToWait );
|
|
||||||
<pre>
|
|
||||||
*
|
|
||||||
* Sends a discrete message to the message buffer. The message can be any
|
|
||||||
* length that fits within the buffer's free space, and is copied into the
|
|
||||||
* buffer.
|
|
||||||
*
|
|
||||||
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
|
|
||||||
* implementation (so also the message buffer implementation, as message buffers
|
|
||||||
* are built on top of stream buffers) assumes there is only one task or
|
|
||||||
* interrupt that will write to the buffer (the writer), and only one task or
|
|
||||||
* interrupt that will read from the buffer (the reader). It is safe for the
|
|
||||||
* writer and reader to be different tasks or interrupts, but, unlike other
|
|
||||||
* FreeRTOS objects, it is not safe to have multiple different writers or
|
|
||||||
* multiple different readers. If there are to be multiple different writers
|
|
||||||
* then the application writer must place each call to a writing API function
|
|
||||||
* (such as xMessageBufferSend()) inside a critical section and set the send
|
|
||||||
* block time to 0. Likewise, if there are to be multiple different readers
|
|
||||||
* then the application writer must place each call to a reading API function
|
|
||||||
* (such as xMessageBufferRead()) inside a critical section and set the receive
|
|
||||||
* block time to 0.
|
|
||||||
*
|
|
||||||
* Use xMessageBufferSend() to write to a message buffer from a task. Use
|
|
||||||
* xMessageBufferSendFromISR() to write to a message buffer from an interrupt
|
|
||||||
* service routine (ISR).
|
|
||||||
*
|
|
||||||
* @param xMessageBuffer The handle of the message buffer to which a message is
|
|
||||||
* being sent.
|
|
||||||
*
|
|
||||||
* @param pvTxData A pointer to the message that is to be copied into the
|
|
||||||
* message buffer.
|
|
||||||
*
|
|
||||||
* @param xDataLengthBytes The length of the message. That is, the number of
|
|
||||||
* bytes to copy from pvTxData into the message buffer. When a message is
|
|
||||||
* written to the message buffer an additional sizeof( size_t ) bytes are also
|
|
||||||
* written to store the message's length. sizeof( size_t ) is typically 4 bytes
|
|
||||||
* on a 32-bit architecture, so on most 32-bit architecture setting
|
|
||||||
* xDataLengthBytes to 20 will reduce the free space in the message buffer by 24
|
|
||||||
* bytes (20 bytes of message data and 4 bytes to hold the message length).
|
|
||||||
*
|
|
||||||
* @param xTicksToWait The maximum amount of time the calling task should remain
|
|
||||||
* in the Blocked state to wait for enough space to become available in the
|
|
||||||
* message buffer, should the message buffer have insufficient space when
|
|
||||||
* xMessageBufferSend() is called. The calling task will never block if
|
|
||||||
* xTicksToWait is zero. The block time is specified in tick periods, so the
|
|
||||||
* absolute time it represents is dependent on the tick frequency. The macro
|
|
||||||
* pdMS_TO_TICKS() can be used to convert a time specified in milliseconds into
|
|
||||||
* a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will cause
|
|
||||||
* the task to wait indefinitely (without timing out), provided
|
|
||||||
* INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. Tasks do not use any
|
|
||||||
* CPU time when they are in the Blocked state.
|
|
||||||
*
|
|
||||||
* @return The number of bytes written to the message buffer. If the call to
|
|
||||||
* xMessageBufferSend() times out before there was enough space to write the
|
|
||||||
* message into the message buffer then zero is returned. If the call did not
|
|
||||||
* time out then xDataLengthBytes is returned.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
void vAFunction( MessageBufferHandle_t xMessageBuffer )
|
|
||||||
{
|
|
||||||
size_t xBytesSent;
|
|
||||||
uint8_t ucArrayToSend[] = { 0, 1, 2, 3 };
|
|
||||||
char *pcStringToSend = "String to send";
|
|
||||||
const TickType_t x100ms = pdMS_TO_TICKS( 100 );
|
|
||||||
|
|
||||||
// Send an array to the message buffer, blocking for a maximum of 100ms to
|
|
||||||
// wait for enough space to be available in the message buffer.
|
|
||||||
xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );
|
|
||||||
|
|
||||||
if( xBytesSent != sizeof( ucArrayToSend ) )
|
|
||||||
{
|
|
||||||
// The call to xMessageBufferSend() times out before there was enough
|
|
||||||
// space in the buffer for the data to be written.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the string to the message buffer. Return immediately if there is
|
|
||||||
// not enough space in the buffer.
|
|
||||||
xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );
|
|
||||||
|
|
||||||
if( xBytesSent != strlen( pcStringToSend ) )
|
|
||||||
{
|
|
||||||
// The string could not be added to the message buffer because there was
|
|
||||||
// not enough free space in the buffer.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xMessageBufferSend xMessageBufferSend
|
|
||||||
* \ingroup MessageBufferManagement
|
|
||||||
*/
|
|
||||||
#define xMessageBufferSend( xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait ) xStreamBufferSend( ( StreamBufferHandle_t ) xMessageBuffer, pvTxData, xDataLengthBytes, xTicksToWait )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
size_t xMessageBufferSendFromISR( MessageBufferHandle_t xMessageBuffer,
|
|
||||||
const void *pvTxData,
|
|
||||||
size_t xDataLengthBytes,
|
|
||||||
BaseType_t *pxHigherPriorityTaskWoken );
|
|
||||||
<pre>
|
|
||||||
*
|
|
||||||
* Interrupt safe version of the API function that sends a discrete message to
|
|
||||||
* the message buffer. The message can be any length that fits within the
|
|
||||||
* buffer's free space, and is copied into the buffer.
|
|
||||||
*
|
|
||||||
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
|
|
||||||
* implementation (so also the message buffer implementation, as message buffers
|
|
||||||
* are built on top of stream buffers) assumes there is only one task or
|
|
||||||
* interrupt that will write to the buffer (the writer), and only one task or
|
|
||||||
* interrupt that will read from the buffer (the reader). It is safe for the
|
|
||||||
* writer and reader to be different tasks or interrupts, but, unlike other
|
|
||||||
* FreeRTOS objects, it is not safe to have multiple different writers or
|
|
||||||
* multiple different readers. If there are to be multiple different writers
|
|
||||||
* then the application writer must place each call to a writing API function
|
|
||||||
* (such as xMessageBufferSend()) inside a critical section and set the send
|
|
||||||
* block time to 0. Likewise, if there are to be multiple different readers
|
|
||||||
* then the application writer must place each call to a reading API function
|
|
||||||
* (such as xMessageBufferRead()) inside a critical section and set the receive
|
|
||||||
* block time to 0.
|
|
||||||
*
|
|
||||||
* Use xMessageBufferSend() to write to a message buffer from a task. Use
|
|
||||||
* xMessageBufferSendFromISR() to write to a message buffer from an interrupt
|
|
||||||
* service routine (ISR).
|
|
||||||
*
|
|
||||||
* @param xMessageBuffer The handle of the message buffer to which a message is
|
|
||||||
* being sent.
|
|
||||||
*
|
|
||||||
* @param pvTxData A pointer to the message that is to be copied into the
|
|
||||||
* message buffer.
|
|
||||||
*
|
|
||||||
* @param xDataLengthBytes The length of the message. That is, the number of
|
|
||||||
* bytes to copy from pvTxData into the message buffer. When a message is
|
|
||||||
* written to the message buffer an additional sizeof( size_t ) bytes are also
|
|
||||||
* written to store the message's length. sizeof( size_t ) is typically 4 bytes
|
|
||||||
* on a 32-bit architecture, so on most 32-bit architecture setting
|
|
||||||
* xDataLengthBytes to 20 will reduce the free space in the message buffer by 24
|
|
||||||
* bytes (20 bytes of message data and 4 bytes to hold the message length).
|
|
||||||
*
|
|
||||||
* @param pxHigherPriorityTaskWoken It is possible that a message buffer will
|
|
||||||
* have a task blocked on it waiting for data. Calling
|
|
||||||
* xMessageBufferSendFromISR() can make data available, and so cause a task that
|
|
||||||
* was waiting for data to leave the Blocked state. If calling
|
|
||||||
* xMessageBufferSendFromISR() causes a task to leave the Blocked state, and the
|
|
||||||
* unblocked task has a priority higher than the currently executing task (the
|
|
||||||
* task that was interrupted), then, internally, xMessageBufferSendFromISR()
|
|
||||||
* will set *pxHigherPriorityTaskWoken to pdTRUE. If
|
|
||||||
* xMessageBufferSendFromISR() sets this value to pdTRUE, then normally a
|
|
||||||
* context switch should be performed before the interrupt is exited. This will
|
|
||||||
* ensure that the interrupt returns directly to the highest priority Ready
|
|
||||||
* state task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it
|
|
||||||
* is passed into the function. See the code example below for an example.
|
|
||||||
*
|
|
||||||
* @return The number of bytes actually written to the message buffer. If the
|
|
||||||
* message buffer didn't have enough free space for the message to be stored
|
|
||||||
* then 0 is returned, otherwise xDataLengthBytes is returned.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
// A message buffer that has already been created.
|
|
||||||
MessageBufferHandle_t xMessageBuffer;
|
|
||||||
|
|
||||||
void vAnInterruptServiceRoutine( void )
|
|
||||||
{
|
|
||||||
size_t xBytesSent;
|
|
||||||
char *pcStringToSend = "String to send";
|
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
|
|
||||||
|
|
||||||
// Attempt to send the string to the message buffer.
|
|
||||||
xBytesSent = xMessageBufferSendFromISR( xMessageBuffer,
|
|
||||||
( void * ) pcStringToSend,
|
|
||||||
strlen( pcStringToSend ),
|
|
||||||
&xHigherPriorityTaskWoken );
|
|
||||||
|
|
||||||
if( xBytesSent != strlen( pcStringToSend ) )
|
|
||||||
{
|
|
||||||
// The string could not be added to the message buffer because there was
|
|
||||||
// not enough free space in the buffer.
|
|
||||||
}
|
|
||||||
|
|
||||||
// If xHigherPriorityTaskWoken was set to pdTRUE inside
|
|
||||||
// xMessageBufferSendFromISR() then a task that has a priority above the
|
|
||||||
// priority of the currently executing task was unblocked and a context
|
|
||||||
// switch should be performed to ensure the ISR returns to the unblocked
|
|
||||||
// task. In most FreeRTOS ports this is done by simply passing
|
|
||||||
// xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
|
|
||||||
// variables value, and perform the context switch if necessary. Check the
|
|
||||||
// documentation for the port in use for port specific instructions.
|
|
||||||
taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xMessageBufferSendFromISR xMessageBufferSendFromISR
|
|
||||||
* \ingroup MessageBufferManagement
|
|
||||||
*/
|
|
||||||
#define xMessageBufferSendFromISR( xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken ) xStreamBufferSendFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pvTxData, xDataLengthBytes, pxHigherPriorityTaskWoken )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
size_t xMessageBufferReceive( MessageBufferHandle_t xMessageBuffer,
|
|
||||||
void *pvRxData,
|
|
||||||
size_t xBufferLengthBytes,
|
|
||||||
TickType_t xTicksToWait );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Receives a discrete message from a message buffer. Messages can be of
|
|
||||||
* variable length and are copied out of the buffer.
|
|
||||||
*
|
|
||||||
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
|
|
||||||
* implementation (so also the message buffer implementation, as message buffers
|
|
||||||
* are built on top of stream buffers) assumes there is only one task or
|
|
||||||
* interrupt that will write to the buffer (the writer), and only one task or
|
|
||||||
* interrupt that will read from the buffer (the reader). It is safe for the
|
|
||||||
* writer and reader to be different tasks or interrupts, but, unlike other
|
|
||||||
* FreeRTOS objects, it is not safe to have multiple different writers or
|
|
||||||
* multiple different readers. If there are to be multiple different writers
|
|
||||||
* then the application writer must place each call to a writing API function
|
|
||||||
* (such as xMessageBufferSend()) inside a critical section and set the send
|
|
||||||
* block time to 0. Likewise, if there are to be multiple different readers
|
|
||||||
* then the application writer must place each call to a reading API function
|
|
||||||
* (such as xMessageBufferRead()) inside a critical section and set the receive
|
|
||||||
* block time to 0.
|
|
||||||
*
|
|
||||||
* Use xMessageBufferReceive() to read from a message buffer from a task. Use
|
|
||||||
* xMessageBufferReceiveFromISR() to read from a message buffer from an
|
|
||||||
* interrupt service routine (ISR).
|
|
||||||
*
|
|
||||||
* @param xMessageBuffer The handle of the message buffer from which a message
|
|
||||||
* is being received.
|
|
||||||
*
|
|
||||||
* @param pvRxData A pointer to the buffer into which the received message is
|
|
||||||
* to be copied.
|
|
||||||
*
|
|
||||||
* @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData
|
|
||||||
* parameter. This sets the maximum length of the message that can be received.
|
|
||||||
* If xBufferLengthBytes is too small to hold the next message then the message
|
|
||||||
* will be left in the message buffer and 0 will be returned.
|
|
||||||
*
|
|
||||||
* @param xTicksToWait The maximum amount of time the task should remain in the
|
|
||||||
* Blocked state to wait for a message, should the message buffer be empty.
|
|
||||||
* xMessageBufferReceive() will return immediately if xTicksToWait is zero and
|
|
||||||
* the message buffer is empty. The block time is specified in tick periods, so
|
|
||||||
* the absolute time it represents is dependent on the tick frequency. The
|
|
||||||
* macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds
|
|
||||||
* into a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will
|
|
||||||
* cause the task to wait indefinitely (without timing out), provided
|
|
||||||
* INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. Tasks do not use any
|
|
||||||
* CPU time when they are in the Blocked state.
|
|
||||||
*
|
|
||||||
* @return The length, in bytes, of the message read from the message buffer, if
|
|
||||||
* any. If xMessageBufferReceive() times out before a message became available
|
|
||||||
* then zero is returned. If the length of the message is greater than
|
|
||||||
* xBufferLengthBytes then the message will be left in the message buffer and
|
|
||||||
* zero is returned.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
void vAFunction( MessageBuffer_t xMessageBuffer )
|
|
||||||
{
|
|
||||||
uint8_t ucRxData[ 20 ];
|
|
||||||
size_t xReceivedBytes;
|
|
||||||
const TickType_t xBlockTime = pdMS_TO_TICKS( 20 );
|
|
||||||
|
|
||||||
// Receive the next message from the message buffer. Wait in the Blocked
|
|
||||||
// state (so not using any CPU processing time) for a maximum of 100ms for
|
|
||||||
// a message to become available.
|
|
||||||
xReceivedBytes = xMessageBufferReceive( xMessageBuffer,
|
|
||||||
( void * ) ucRxData,
|
|
||||||
sizeof( ucRxData ),
|
|
||||||
xBlockTime );
|
|
||||||
|
|
||||||
if( xReceivedBytes > 0 )
|
|
||||||
{
|
|
||||||
// A ucRxData contains a message that is xReceivedBytes long. Process
|
|
||||||
// the message here....
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xMessageBufferReceive xMessageBufferReceive
|
|
||||||
* \ingroup MessageBufferManagement
|
|
||||||
*/
|
|
||||||
#define xMessageBufferReceive( xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait ) xStreamBufferReceive( ( StreamBufferHandle_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, xTicksToWait )
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
size_t xMessageBufferReceiveFromISR( MessageBufferHandle_t xMessageBuffer,
|
|
||||||
void *pvRxData,
|
|
||||||
size_t xBufferLengthBytes,
|
|
||||||
BaseType_t *pxHigherPriorityTaskWoken );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* An interrupt safe version of the API function that receives a discrete
|
|
||||||
* message from a message buffer. Messages can be of variable length and are
|
|
||||||
* copied out of the buffer.
|
|
||||||
*
|
|
||||||
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
|
|
||||||
* implementation (so also the message buffer implementation, as message buffers
|
|
||||||
* are built on top of stream buffers) assumes there is only one task or
|
|
||||||
* interrupt that will write to the buffer (the writer), and only one task or
|
|
||||||
* interrupt that will read from the buffer (the reader). It is safe for the
|
|
||||||
* writer and reader to be different tasks or interrupts, but, unlike other
|
|
||||||
* FreeRTOS objects, it is not safe to have multiple different writers or
|
|
||||||
* multiple different readers. If there are to be multiple different writers
|
|
||||||
* then the application writer must place each call to a writing API function
|
|
||||||
* (such as xMessageBufferSend()) inside a critical section and set the send
|
|
||||||
* block time to 0. Likewise, if there are to be multiple different readers
|
|
||||||
* then the application writer must place each call to a reading API function
|
|
||||||
* (such as xMessageBufferRead()) inside a critical section and set the receive
|
|
||||||
* block time to 0.
|
|
||||||
*
|
|
||||||
* Use xMessageBufferReceive() to read from a message buffer from a task. Use
|
|
||||||
* xMessageBufferReceiveFromISR() to read from a message buffer from an
|
|
||||||
* interrupt service routine (ISR).
|
|
||||||
*
|
|
||||||
* @param xMessageBuffer The handle of the message buffer from which a message
|
|
||||||
* is being received.
|
|
||||||
*
|
|
||||||
* @param pvRxData A pointer to the buffer into which the received message is
|
|
||||||
* to be copied.
|
|
||||||
*
|
|
||||||
* @param xBufferLengthBytes The length of the buffer pointed to by the pvRxData
|
|
||||||
* parameter. This sets the maximum length of the message that can be received.
|
|
||||||
* If xBufferLengthBytes is too small to hold the next message then the message
|
|
||||||
* will be left in the message buffer and 0 will be returned.
|
|
||||||
*
|
|
||||||
* @param pxHigherPriorityTaskWoken It is possible that a message buffer will
|
|
||||||
* have a task blocked on it waiting for space to become available. Calling
|
|
||||||
* xMessageBufferReceiveFromISR() can make space available, and so cause a task
|
|
||||||
* that is waiting for space to leave the Blocked state. If calling
|
|
||||||
* xMessageBufferReceiveFromISR() causes a task to leave the Blocked state, and
|
|
||||||
* the unblocked task has a priority higher than the currently executing task
|
|
||||||
* (the task that was interrupted), then, internally,
|
|
||||||
* xMessageBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE.
|
|
||||||
* If xMessageBufferReceiveFromISR() sets this value to pdTRUE, then normally a
|
|
||||||
* context switch should be performed before the interrupt is exited. That will
|
|
||||||
* ensure the interrupt returns directly to the highest priority Ready state
|
|
||||||
* task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it is
|
|
||||||
* passed into the function. See the code example below for an example.
|
|
||||||
*
|
|
||||||
* @return The length, in bytes, of the message read from the message buffer, if
|
|
||||||
* any.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
// A message buffer that has already been created.
|
|
||||||
MessageBuffer_t xMessageBuffer;
|
|
||||||
|
|
||||||
void vAnInterruptServiceRoutine( void )
|
|
||||||
{
|
|
||||||
uint8_t ucRxData[ 20 ];
|
|
||||||
size_t xReceivedBytes;
|
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
|
|
||||||
|
|
||||||
// Receive the next message from the message buffer.
|
|
||||||
xReceivedBytes = xMessageBufferReceiveFromISR( xMessageBuffer,
|
|
||||||
( void * ) ucRxData,
|
|
||||||
sizeof( ucRxData ),
|
|
||||||
&xHigherPriorityTaskWoken );
|
|
||||||
|
|
||||||
if( xReceivedBytes > 0 )
|
|
||||||
{
|
|
||||||
// A ucRxData contains a message that is xReceivedBytes long. Process
|
|
||||||
// the message here....
|
|
||||||
}
|
|
||||||
|
|
||||||
// If xHigherPriorityTaskWoken was set to pdTRUE inside
|
|
||||||
// xMessageBufferReceiveFromISR() then a task that has a priority above the
|
|
||||||
// priority of the currently executing task was unblocked and a context
|
|
||||||
// switch should be performed to ensure the ISR returns to the unblocked
|
|
||||||
// task. In most FreeRTOS ports this is done by simply passing
|
|
||||||
// xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
|
|
||||||
// variables value, and perform the context switch if necessary. Check the
|
|
||||||
// documentation for the port in use for port specific instructions.
|
|
||||||
taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xMessageBufferReceiveFromISR xMessageBufferReceiveFromISR
|
|
||||||
* \ingroup MessageBufferManagement
|
|
||||||
*/
|
|
||||||
#define xMessageBufferReceiveFromISR( xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken ) xStreamBufferReceiveFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pvRxData, xBufferLengthBytes, pxHigherPriorityTaskWoken )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
void vMessageBufferDelete( MessageBufferHandle_t xMessageBuffer );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Deletes a message buffer that was previously created using a call to
|
|
||||||
* xMessageBufferCreate() or xMessageBufferCreateStatic(). If the message
|
|
||||||
* buffer was created using dynamic memory (that is, by xMessageBufferCreate()),
|
|
||||||
* then the allocated memory is freed.
|
|
||||||
*
|
|
||||||
* A message buffer handle must not be used after the message buffer has been
|
|
||||||
* deleted.
|
|
||||||
*
|
|
||||||
* @param xMessageBuffer The handle of the message buffer to be deleted.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#define vMessageBufferDelete( xMessageBuffer ) vStreamBufferDelete( ( StreamBufferHandle_t ) xMessageBuffer )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
<pre>
|
|
||||||
BaseType_t xMessageBufferIsFull( MessageBufferHandle_t xMessageBuffer ) );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Tests to see if a message buffer is full. A message buffer is full if it
|
|
||||||
* cannot accept any more messages, of any size, until space is made available
|
|
||||||
* by a message being removed from the message buffer.
|
|
||||||
*
|
|
||||||
* @param xMessageBuffer The handle of the message buffer being queried.
|
|
||||||
*
|
|
||||||
* @return If the message buffer referenced by xMessageBuffer is full then
|
|
||||||
* pdTRUE is returned. Otherwise pdFALSE is returned.
|
|
||||||
*/
|
|
||||||
#define xMessageBufferIsFull( xMessageBuffer ) xStreamBufferIsFull( ( StreamBufferHandle_t ) xMessageBuffer )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
<pre>
|
|
||||||
BaseType_t xMessageBufferIsEmpty( MessageBufferHandle_t xMessageBuffer ) );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Tests to see if a message buffer is empty (does not contain any messages).
|
|
||||||
*
|
|
||||||
* @param xMessageBuffer The handle of the message buffer being queried.
|
|
||||||
*
|
|
||||||
* @return If the message buffer referenced by xMessageBuffer is empty then
|
|
||||||
* pdTRUE is returned. Otherwise pdFALSE is returned.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#define xMessageBufferIsEmpty( xMessageBuffer ) xStreamBufferIsEmpty( ( StreamBufferHandle_t ) xMessageBuffer )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
<pre>
|
|
||||||
BaseType_t xMessageBufferReset( MessageBufferHandle_t xMessageBuffer );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Resets a message buffer to its initial empty state, discarding any message it
|
|
||||||
* contained.
|
|
||||||
*
|
|
||||||
* A message buffer can only be reset if there are no tasks blocked on it.
|
|
||||||
*
|
|
||||||
* @param xMessageBuffer The handle of the message buffer being reset.
|
|
||||||
*
|
|
||||||
* @return If the message buffer was reset then pdPASS is returned. If the
|
|
||||||
* message buffer could not be reset because either there was a task blocked on
|
|
||||||
* the message queue to wait for space to become available, or to wait for a
|
|
||||||
* a message to be available, then pdFAIL is returned.
|
|
||||||
*
|
|
||||||
* \defgroup xMessageBufferReset xMessageBufferReset
|
|
||||||
* \ingroup MessageBufferManagement
|
|
||||||
*/
|
|
||||||
#define xMessageBufferReset( xMessageBuffer ) xStreamBufferReset( ( StreamBufferHandle_t ) xMessageBuffer )
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
<pre>
|
|
||||||
size_t xMessageBufferSpaceAvailable( MessageBufferHandle_t xMessageBuffer ) );
|
|
||||||
</pre>
|
|
||||||
* Returns the number of bytes of free space in the message buffer.
|
|
||||||
*
|
|
||||||
* @param xMessageBuffer The handle of the message buffer being queried.
|
|
||||||
*
|
|
||||||
* @return The number of bytes that can be written to the message buffer before
|
|
||||||
* the message buffer would be full. When a message is written to the message
|
|
||||||
* buffer an additional sizeof( size_t ) bytes are also written to store the
|
|
||||||
* message's length. sizeof( size_t ) is typically 4 bytes on a 32-bit
|
|
||||||
* architecture, so if xMessageBufferSpacesAvailable() returns 10, then the size
|
|
||||||
* of the largest message that can be written to the message buffer is 6 bytes.
|
|
||||||
*
|
|
||||||
* \defgroup xMessageBufferSpaceAvailable xMessageBufferSpaceAvailable
|
|
||||||
* \ingroup MessageBufferManagement
|
|
||||||
*/
|
|
||||||
#define xMessageBufferSpaceAvailable( xMessageBuffer ) xStreamBufferSpacesAvailable( ( StreamBufferHandle_t ) xMessageBuffer )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
<pre>
|
|
||||||
size_t xMessageBufferNextLengthBytes( MessageBufferHandle_t xMessageBuffer ) );
|
|
||||||
</pre>
|
|
||||||
* Returns the length (in bytes) of the next message in a message buffer.
|
|
||||||
* Useful if xMessageBufferReceive() returned 0 because the size of the buffer
|
|
||||||
* passed into xMessageBufferReceive() was too small to hold the next message.
|
|
||||||
*
|
|
||||||
* @param xMessageBuffer The handle of the message buffer being queried.
|
|
||||||
*
|
|
||||||
* @return The length (in bytes) of the next message in the message buffer, or 0
|
|
||||||
* if the message buffer is empty.
|
|
||||||
*
|
|
||||||
* \defgroup xMessageBufferNextLengthBytes xMessageBufferNextLengthBytes
|
|
||||||
* \ingroup MessageBufferManagement
|
|
||||||
*/
|
|
||||||
#define xMessageBufferNextLengthBytes( xMessageBuffer ) xStreamBufferNextMessageLengthBytes( ( StreamBufferHandle_t ) xMessageBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
BaseType_t xMessageBufferSendCompletedFromISR( MessageBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* For advanced users only.
|
|
||||||
*
|
|
||||||
* The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when
|
|
||||||
* data is sent to a message buffer or stream buffer. If there was a task that
|
|
||||||
* was blocked on the message or stream buffer waiting for data to arrive then
|
|
||||||
* the sbSEND_COMPLETED() macro sends a notification to the task to remove it
|
|
||||||
* from the Blocked state. xMessageBufferSendCompletedFromISR() does the same
|
|
||||||
* thing. It is provided to enable application writers to implement their own
|
|
||||||
* version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME.
|
|
||||||
*
|
|
||||||
* See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
|
|
||||||
* additional information.
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer to which data was
|
|
||||||
* written.
|
|
||||||
*
|
|
||||||
* @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
|
|
||||||
* initialised to pdFALSE before it is passed into
|
|
||||||
* xMessageBufferSendCompletedFromISR(). If calling
|
|
||||||
* xMessageBufferSendCompletedFromISR() removes a task from the Blocked state,
|
|
||||||
* and the task has a priority above the priority of the currently running task,
|
|
||||||
* then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
|
|
||||||
* context switch should be performed before exiting the ISR.
|
|
||||||
*
|
|
||||||
* @return If a task was removed from the Blocked state then pdTRUE is returned.
|
|
||||||
* Otherwise pdFALSE is returned.
|
|
||||||
*
|
|
||||||
* \defgroup xMessageBufferSendCompletedFromISR xMessageBufferSendCompletedFromISR
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
#define xMessageBufferSendCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) xStreamBufferSendCompletedFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pxHigherPriorityTaskWoken )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
BaseType_t xMessageBufferReceiveCompletedFromISR( MessageBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* For advanced users only.
|
|
||||||
*
|
|
||||||
* The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when
|
|
||||||
* data is read out of a message buffer or stream buffer. If there was a task
|
|
||||||
* that was blocked on the message or stream buffer waiting for data to arrive
|
|
||||||
* then the sbRECEIVE_COMPLETED() macro sends a notification to the task to
|
|
||||||
* remove it from the Blocked state. xMessageBufferReceiveCompletedFromISR()
|
|
||||||
* does the same thing. It is provided to enable application writers to
|
|
||||||
* implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT
|
|
||||||
* ANY OTHER TIME.
|
|
||||||
*
|
|
||||||
* See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
|
|
||||||
* additional information.
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer from which data was
|
|
||||||
* read.
|
|
||||||
*
|
|
||||||
* @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
|
|
||||||
* initialised to pdFALSE before it is passed into
|
|
||||||
* xMessageBufferReceiveCompletedFromISR(). If calling
|
|
||||||
* xMessageBufferReceiveCompletedFromISR() removes a task from the Blocked state,
|
|
||||||
* and the task has a priority above the priority of the currently running task,
|
|
||||||
* then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
|
|
||||||
* context switch should be performed before exiting the ISR.
|
|
||||||
*
|
|
||||||
* @return If a task was removed from the Blocked state then pdTRUE is returned.
|
|
||||||
* Otherwise pdFALSE is returned.
|
|
||||||
*
|
|
||||||
* \defgroup xMessageBufferReceiveCompletedFromISR xMessageBufferReceiveCompletedFromISR
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
#define xMessageBufferReceiveCompletedFromISR( xMessageBuffer, pxHigherPriorityTaskWoken ) xStreamBufferReceiveCompletedFromISR( ( StreamBufferHandle_t ) xMessageBuffer, pxHigherPriorityTaskWoken )
|
|
||||||
|
|
||||||
#if defined( __cplusplus )
|
|
||||||
} /* extern "C" */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* !defined( FREERTOS_MESSAGE_BUFFER_H ) */
|
|
|
@ -1,157 +0,0 @@
|
||||||
/*
|
|
||||||
* FreeRTOS Kernel V10.2.0
|
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
|
||||||
* http://aws.amazon.com/freertos
|
|
||||||
*
|
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* When the MPU is used the standard (non MPU) API functions are mapped to
|
|
||||||
* equivalents that start "MPU_", the prototypes for which are defined in this
|
|
||||||
* header files. This will cause the application code to call the MPU_ version
|
|
||||||
* which wraps the non-MPU version with privilege promoting then demoting code,
|
|
||||||
* so the kernel code always runs will full privileges.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MPU_PROTOTYPES_H
|
|
||||||
#define MPU_PROTOTYPES_H
|
|
||||||
|
|
||||||
/* MPU versions of tasks.h API functions. */
|
|
||||||
BaseType_t MPU_xTaskCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TaskHandle_t MPU_xTaskCreateStatic( TaskFunction_t pxTaskCode, const char * const pcName, const uint32_t ulStackDepth, void * const pvParameters, UBaseType_t uxPriority, StackType_t * const puxStackBuffer, StaticTask_t * const pxTaskBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskDelete( TaskHandle_t xTaskToDelete ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskDelay( const TickType_t xTicksToDelay ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTaskAbortDelay( TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL;
|
|
||||||
UBaseType_t MPU_uxTaskPriorityGet( const TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL;
|
|
||||||
eTaskState MPU_eTaskGetState( TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskSuspend( TaskHandle_t xTaskToSuspend ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskResume( TaskHandle_t xTaskToResume ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskStartScheduler( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskSuspendAll( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTaskResumeAll( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TickType_t MPU_xTaskGetTickCount( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
UBaseType_t MPU_uxTaskGetNumberOfTasks( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
char * MPU_pcTaskGetName( TaskHandle_t xTaskToQuery ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TaskHandle_t MPU_xTaskGetHandle( const char *pcNameToQuery ) FREERTOS_SYSTEM_CALL;
|
|
||||||
UBaseType_t MPU_uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL;
|
|
||||||
configSTACK_DEPTH_TYPE MPU_uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TaskHookFunction_t MPU_xTaskGetApplicationTaskTag( TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void * MPU_pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TaskHandle_t MPU_xTaskGetIdleTaskHandle( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
UBaseType_t MPU_uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TickType_t MPU_xTaskGetIdleRunTimeCounter( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskList( char * pcWriteBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskGetRunTimeStats( char *pcWriteBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
uint32_t MPU_ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTaskNotifyStateClear( TaskHandle_t xTask ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTaskIncrementTick( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TaskHandle_t MPU_xTaskGetCurrentTaskHandle( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTaskMissedYield( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTaskGetSchedulerState( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
|
|
||||||
/* MPU versions of queue.h API functions. */
|
|
||||||
BaseType_t MPU_xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
UBaseType_t MPU_uxQueueMessagesWaiting( const QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
UBaseType_t MPU_uxQueueSpacesAvailable( const QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vQueueDelete( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
QueueHandle_t MPU_xQueueCreateMutex( const uint8_t ucQueueType ) FREERTOS_SYSTEM_CALL;
|
|
||||||
QueueHandle_t MPU_xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
QueueHandle_t MPU_xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ) FREERTOS_SYSTEM_CALL;
|
|
||||||
QueueHandle_t MPU_xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TaskHandle_t MPU_xQueueGetMutexHolder( QueueHandle_t xSemaphore ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xQueueTakeMutexRecursive( QueueHandle_t xMutex, TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xQueueGiveMutexRecursive( QueueHandle_t pxMutex ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vQueueAddToRegistry( QueueHandle_t xQueue, const char *pcName ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vQueueUnregisterQueue( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
const char * MPU_pcQueueGetName( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
QueueHandle_t MPU_xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ) FREERTOS_SYSTEM_CALL;
|
|
||||||
QueueHandle_t MPU_xQueueGenericCreateStatic( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ) FREERTOS_SYSTEM_CALL;
|
|
||||||
QueueSetHandle_t MPU_xQueueCreateSet( const UBaseType_t uxEventQueueLength ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet ) FREERTOS_SYSTEM_CALL;
|
|
||||||
QueueSetMemberHandle_t MPU_xQueueSelectFromSet( QueueSetHandle_t xQueueSet, const TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xQueueGenericReset( QueueHandle_t xQueue, BaseType_t xNewQueue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vQueueSetQueueNumber( QueueHandle_t xQueue, UBaseType_t uxQueueNumber ) FREERTOS_SYSTEM_CALL;
|
|
||||||
UBaseType_t MPU_uxQueueGetQueueNumber( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
uint8_t MPU_ucQueueGetQueueType( QueueHandle_t xQueue ) FREERTOS_SYSTEM_CALL;
|
|
||||||
|
|
||||||
/* MPU versions of timers.h API functions. */
|
|
||||||
TimerHandle_t MPU_xTimerCreate( const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TimerHandle_t MPU_xTimerCreateStatic( const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction, StaticTimer_t *pxTimerBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void * MPU_pvTimerGetTimerID( const TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTimerIsTimerActive( TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TaskHandle_t MPU_xTimerGetTimerDaemonTaskHandle( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
const char * MPU_pcTimerGetName( TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vTimerSetReloadMode( TimerHandle_t xTimer, const UBaseType_t uxAutoReload ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TickType_t MPU_xTimerGetPeriod( TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
TickType_t MPU_xTimerGetExpiryTime( TimerHandle_t xTimer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTimerCreateTimerTask( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
|
|
||||||
/* MPU versions of event_group.h API functions. */
|
|
||||||
EventGroupHandle_t MPU_xEventGroupCreate( void ) FREERTOS_SYSTEM_CALL;
|
|
||||||
EventGroupHandle_t MPU_xEventGroupCreateStatic( StaticEventGroup_t *pxEventGroupBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
EventBits_t MPU_xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
EventBits_t MPU_xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear ) FREERTOS_SYSTEM_CALL;
|
|
||||||
EventBits_t MPU_xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet ) FREERTOS_SYSTEM_CALL;
|
|
||||||
EventBits_t MPU_xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vEventGroupDelete( EventGroupHandle_t xEventGroup ) FREERTOS_SYSTEM_CALL;
|
|
||||||
UBaseType_t MPU_uxEventGroupGetNumber( void* xEventGroup ) FREERTOS_SYSTEM_CALL;
|
|
||||||
|
|
||||||
/* MPU versions of message/stream_buffer.h API functions. */
|
|
||||||
size_t MPU_xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
size_t MPU_xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, TickType_t xTicksToWait ) FREERTOS_SYSTEM_CALL;
|
|
||||||
size_t MPU_xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
void MPU_vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
size_t MPU_xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
size_t MPU_xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
BaseType_t MPU_xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel ) FREERTOS_SYSTEM_CALL;
|
|
||||||
StreamBufferHandle_t MPU_xStreamBufferGenericCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, BaseType_t xIsMessageBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
StreamBufferHandle_t MPU_xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, size_t xTriggerLevelBytes, BaseType_t xIsMessageBuffer, uint8_t * const pucStreamBufferStorageArea, StaticStreamBuffer_t * const pxStaticStreamBuffer ) FREERTOS_SYSTEM_CALL;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* MPU_PROTOTYPES_H */
|
|
||||||
|
|
|
@ -1,29 +1,66 @@
|
||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.2.0
|
FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
***************************************************************************
|
||||||
* the Software without restriction, including without limitation the rights to
|
* *
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* FreeRTOS provides completely free yet professionally developed, *
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* robust, strictly quality controlled, supported, and cross *
|
||||||
* subject to the following conditions:
|
* platform software that has become a de facto standard. *
|
||||||
*
|
* *
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* Help yourself get started quickly and support the FreeRTOS *
|
||||||
* copies or substantial portions of the Software.
|
* project by purchasing a FreeRTOS tutorial book, reference *
|
||||||
*
|
* manual, or both from: http://www.FreeRTOS.org/Documentation *
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* *
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* Thank you! *
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* *
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
***************************************************************************
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
This file is part of the FreeRTOS distribution.
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
* http://aws.amazon.com/freertos
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
*
|
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
>>! NOTE: The modification to the GPL is included to allow you to distribute
|
||||||
|
>>! a combined work that includes FreeRTOS without being obliged to provide
|
||||||
|
>>! the source code for proprietary components outside of the FreeRTOS
|
||||||
|
>>! kernel.
|
||||||
|
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. Full license text is available from the following
|
||||||
|
link: http://www.freertos.org/a00114.html
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* Having a problem? Start by reading the FAQ "My application does *
|
||||||
|
* not run, what could be wrong?" *
|
||||||
|
* *
|
||||||
|
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||||
|
license and Real Time Engineers Ltd. contact details.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||||
|
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||||
|
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||||
|
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||||
|
licenses offer ticketed support, indemnification and middleware.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||||
|
engineered and independently SIL3 certified version for use in safety and
|
||||||
|
mission critical applications that require provable dependability.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef MPU_WRAPPERS_H
|
#ifndef MPU_WRAPPERS_H
|
||||||
#define MPU_WRAPPERS_H
|
#define MPU_WRAPPERS_H
|
||||||
|
@ -37,138 +74,68 @@ only for ports that are using the MPU. */
|
||||||
those files. */
|
those files. */
|
||||||
#ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
#ifndef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||||
|
|
||||||
/*
|
#define xTaskGenericCreate MPU_xTaskGenericCreate
|
||||||
* Map standard (non MPU) API functions to equivalents that start
|
#define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions
|
||||||
* "MPU_". This will cause the application code to call the MPU_
|
#define vTaskDelete MPU_vTaskDelete
|
||||||
* version, which wraps the non-MPU version with privilege promoting
|
#define vTaskDelayUntil MPU_vTaskDelayUntil
|
||||||
* then demoting code, so the kernel code always runs will full
|
#define vTaskDelay MPU_vTaskDelay
|
||||||
* privileges.
|
#define uxTaskPriorityGet MPU_uxTaskPriorityGet
|
||||||
*/
|
#define vTaskPrioritySet MPU_vTaskPrioritySet
|
||||||
|
#define eTaskGetState MPU_eTaskGetState
|
||||||
|
#define vTaskSuspend MPU_vTaskSuspend
|
||||||
|
#define xTaskIsTaskSuspended MPU_xTaskIsTaskSuspended
|
||||||
|
#define vTaskResume MPU_vTaskResume
|
||||||
|
#define vTaskSuspendAll MPU_vTaskSuspendAll
|
||||||
|
#define xTaskResumeAll MPU_xTaskResumeAll
|
||||||
|
#define xTaskGetTickCount MPU_xTaskGetTickCount
|
||||||
|
#define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks
|
||||||
|
#define vTaskList MPU_vTaskList
|
||||||
|
#define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats
|
||||||
|
#define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag
|
||||||
|
#define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag
|
||||||
|
#define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook
|
||||||
|
#define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark
|
||||||
|
#define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle
|
||||||
|
#define xTaskGetSchedulerState MPU_xTaskGetSchedulerState
|
||||||
|
#define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle
|
||||||
|
#define uxTaskGetSystemState MPU_uxTaskGetSystemState
|
||||||
|
|
||||||
/* Map standard tasks.h API functions to the MPU equivalents. */
|
#define xQueueGenericCreate MPU_xQueueGenericCreate
|
||||||
#define xTaskCreate MPU_xTaskCreate
|
#define xQueueCreateMutex MPU_xQueueCreateMutex
|
||||||
#define xTaskCreateStatic MPU_xTaskCreateStatic
|
#define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive
|
||||||
#define xTaskCreateRestricted MPU_xTaskCreateRestricted
|
#define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive
|
||||||
#define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions
|
#define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore
|
||||||
#define vTaskDelete MPU_vTaskDelete
|
#define xQueueGenericSend MPU_xQueueGenericSend
|
||||||
#define vTaskDelay MPU_vTaskDelay
|
#define xQueueAltGenericSend MPU_xQueueAltGenericSend
|
||||||
#define vTaskDelayUntil MPU_vTaskDelayUntil
|
#define xQueueAltGenericReceive MPU_xQueueAltGenericReceive
|
||||||
#define xTaskAbortDelay MPU_xTaskAbortDelay
|
#define xQueueGenericReceive MPU_xQueueGenericReceive
|
||||||
#define uxTaskPriorityGet MPU_uxTaskPriorityGet
|
#define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting
|
||||||
#define eTaskGetState MPU_eTaskGetState
|
#define vQueueDelete MPU_vQueueDelete
|
||||||
#define vTaskGetInfo MPU_vTaskGetInfo
|
#define xQueueGenericReset MPU_xQueueGenericReset
|
||||||
#define vTaskPrioritySet MPU_vTaskPrioritySet
|
#define xQueueCreateSet MPU_xQueueCreateSet
|
||||||
#define vTaskSuspend MPU_vTaskSuspend
|
#define xQueueSelectFromSet MPU_xQueueSelectFromSet
|
||||||
#define vTaskResume MPU_vTaskResume
|
#define xQueueAddToSet MPU_xQueueAddToSet
|
||||||
#define vTaskSuspendAll MPU_vTaskSuspendAll
|
#define xQueueRemoveFromSet MPU_xQueueRemoveFromSet
|
||||||
#define xTaskResumeAll MPU_xTaskResumeAll
|
#define xQueuePeekFromISR MPU_xQueuePeekFromISR
|
||||||
#define xTaskGetTickCount MPU_xTaskGetTickCount
|
|
||||||
#define uxTaskGetNumberOfTasks MPU_uxTaskGetNumberOfTasks
|
|
||||||
#define pcTaskGetName MPU_pcTaskGetName
|
|
||||||
#define xTaskGetHandle MPU_xTaskGetHandle
|
|
||||||
#define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark
|
|
||||||
#define uxTaskGetStackHighWaterMark2 MPU_uxTaskGetStackHighWaterMark2
|
|
||||||
#define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag
|
|
||||||
#define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag
|
|
||||||
#define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer
|
|
||||||
#define pvTaskGetThreadLocalStoragePointer MPU_pvTaskGetThreadLocalStoragePointer
|
|
||||||
#define xTaskCallApplicationTaskHook MPU_xTaskCallApplicationTaskHook
|
|
||||||
#define xTaskGetIdleTaskHandle MPU_xTaskGetIdleTaskHandle
|
|
||||||
#define uxTaskGetSystemState MPU_uxTaskGetSystemState
|
|
||||||
#define vTaskList MPU_vTaskList
|
|
||||||
#define vTaskGetRunTimeStats MPU_vTaskGetRunTimeStats
|
|
||||||
#define xTaskGetIdleRunTimeCounter MPU_xTaskGetIdleRunTimeCounter
|
|
||||||
#define xTaskGenericNotify MPU_xTaskGenericNotify
|
|
||||||
#define xTaskNotifyWait MPU_xTaskNotifyWait
|
|
||||||
#define ulTaskNotifyTake MPU_ulTaskNotifyTake
|
|
||||||
#define xTaskNotifyStateClear MPU_xTaskNotifyStateClear
|
|
||||||
|
|
||||||
#define xTaskGetCurrentTaskHandle MPU_xTaskGetCurrentTaskHandle
|
#define pvPortMalloc MPU_pvPortMalloc
|
||||||
#define vTaskSetTimeOutState MPU_vTaskSetTimeOutState
|
#define vPortFree MPU_vPortFree
|
||||||
#define xTaskCheckForTimeOut MPU_xTaskCheckForTimeOut
|
#define xPortGetFreeHeapSize MPU_xPortGetFreeHeapSize
|
||||||
#define xTaskGetSchedulerState MPU_xTaskGetSchedulerState
|
#define vPortInitialiseBlocks MPU_vPortInitialiseBlocks
|
||||||
|
|
||||||
/* Map standard queue.h API functions to the MPU equivalents. */
|
#if configQUEUE_REGISTRY_SIZE > 0
|
||||||
#define xQueueGenericSend MPU_xQueueGenericSend
|
#define vQueueAddToRegistry MPU_vQueueAddToRegistry
|
||||||
#define xQueueReceive MPU_xQueueReceive
|
#define vQueueUnregisterQueue MPU_vQueueUnregisterQueue
|
||||||
#define xQueuePeek MPU_xQueuePeek
|
|
||||||
#define xQueueSemaphoreTake MPU_xQueueSemaphoreTake
|
|
||||||
#define uxQueueMessagesWaiting MPU_uxQueueMessagesWaiting
|
|
||||||
#define uxQueueSpacesAvailable MPU_uxQueueSpacesAvailable
|
|
||||||
#define vQueueDelete MPU_vQueueDelete
|
|
||||||
#define xQueueCreateMutex MPU_xQueueCreateMutex
|
|
||||||
#define xQueueCreateMutexStatic MPU_xQueueCreateMutexStatic
|
|
||||||
#define xQueueCreateCountingSemaphore MPU_xQueueCreateCountingSemaphore
|
|
||||||
#define xQueueCreateCountingSemaphoreStatic MPU_xQueueCreateCountingSemaphoreStatic
|
|
||||||
#define xQueueGetMutexHolder MPU_xQueueGetMutexHolder
|
|
||||||
#define xQueueTakeMutexRecursive MPU_xQueueTakeMutexRecursive
|
|
||||||
#define xQueueGiveMutexRecursive MPU_xQueueGiveMutexRecursive
|
|
||||||
#define xQueueGenericCreate MPU_xQueueGenericCreate
|
|
||||||
#define xQueueGenericCreateStatic MPU_xQueueGenericCreateStatic
|
|
||||||
#define xQueueCreateSet MPU_xQueueCreateSet
|
|
||||||
#define xQueueAddToSet MPU_xQueueAddToSet
|
|
||||||
#define xQueueRemoveFromSet MPU_xQueueRemoveFromSet
|
|
||||||
#define xQueueSelectFromSet MPU_xQueueSelectFromSet
|
|
||||||
#define xQueueGenericReset MPU_xQueueGenericReset
|
|
||||||
|
|
||||||
#if( configQUEUE_REGISTRY_SIZE > 0 )
|
|
||||||
#define vQueueAddToRegistry MPU_vQueueAddToRegistry
|
|
||||||
#define vQueueUnregisterQueue MPU_vQueueUnregisterQueue
|
|
||||||
#define pcQueueGetName MPU_pcQueueGetName
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Map standard timer.h API functions to the MPU equivalents. */
|
/* Remove the privileged function macro. */
|
||||||
#define xTimerCreate MPU_xTimerCreate
|
|
||||||
#define xTimerCreateStatic MPU_xTimerCreateStatic
|
|
||||||
#define pvTimerGetTimerID MPU_pvTimerGetTimerID
|
|
||||||
#define vTimerSetTimerID MPU_vTimerSetTimerID
|
|
||||||
#define xTimerIsTimerActive MPU_xTimerIsTimerActive
|
|
||||||
#define xTimerGetTimerDaemonTaskHandle MPU_xTimerGetTimerDaemonTaskHandle
|
|
||||||
#define xTimerPendFunctionCall MPU_xTimerPendFunctionCall
|
|
||||||
#define pcTimerGetName MPU_pcTimerGetName
|
|
||||||
#define vTimerSetReloadMode MPU_vTimerSetReloadMode
|
|
||||||
#define xTimerGetPeriod MPU_xTimerGetPeriod
|
|
||||||
#define xTimerGetExpiryTime MPU_xTimerGetExpiryTime
|
|
||||||
#define xTimerGenericCommand MPU_xTimerGenericCommand
|
|
||||||
|
|
||||||
/* Map standard event_group.h API functions to the MPU equivalents. */
|
|
||||||
#define xEventGroupCreate MPU_xEventGroupCreate
|
|
||||||
#define xEventGroupCreateStatic MPU_xEventGroupCreateStatic
|
|
||||||
#define xEventGroupWaitBits MPU_xEventGroupWaitBits
|
|
||||||
#define xEventGroupClearBits MPU_xEventGroupClearBits
|
|
||||||
#define xEventGroupSetBits MPU_xEventGroupSetBits
|
|
||||||
#define xEventGroupSync MPU_xEventGroupSync
|
|
||||||
#define vEventGroupDelete MPU_vEventGroupDelete
|
|
||||||
|
|
||||||
/* Map standard message/stream_buffer.h API functions to the MPU
|
|
||||||
equivalents. */
|
|
||||||
#define xStreamBufferSend MPU_xStreamBufferSend
|
|
||||||
#define xStreamBufferReceive MPU_xStreamBufferReceive
|
|
||||||
#define xStreamBufferNextMessageLengthBytes MPU_xStreamBufferNextMessageLengthBytes
|
|
||||||
#define vStreamBufferDelete MPU_vStreamBufferDelete
|
|
||||||
#define xStreamBufferIsFull MPU_xStreamBufferIsFull
|
|
||||||
#define xStreamBufferIsEmpty MPU_xStreamBufferIsEmpty
|
|
||||||
#define xStreamBufferReset MPU_xStreamBufferReset
|
|
||||||
#define xStreamBufferSpacesAvailable MPU_xStreamBufferSpacesAvailable
|
|
||||||
#define xStreamBufferBytesAvailable MPU_xStreamBufferBytesAvailable
|
|
||||||
#define xStreamBufferSetTriggerLevel MPU_xStreamBufferSetTriggerLevel
|
|
||||||
#define xStreamBufferGenericCreate MPU_xStreamBufferGenericCreate
|
|
||||||
#define xStreamBufferGenericCreateStatic MPU_xStreamBufferGenericCreateStatic
|
|
||||||
|
|
||||||
|
|
||||||
/* Remove the privileged function macro, but keep the PRIVILEGED_DATA
|
|
||||||
macro so applications can place data in privileged access sections
|
|
||||||
(useful when using statically allocated objects). */
|
|
||||||
#define PRIVILEGED_FUNCTION
|
#define PRIVILEGED_FUNCTION
|
||||||
#define PRIVILEGED_DATA __attribute__((section("privileged_data")))
|
|
||||||
#define FREERTOS_SYSTEM_CALL
|
|
||||||
|
|
||||||
#else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
|
#else /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
|
||||||
|
|
||||||
/* Ensure API functions go in the privileged execution section. */
|
/* Ensure API functions go in the privileged execution section. */
|
||||||
#define PRIVILEGED_FUNCTION __attribute__((section("privileged_functions")))
|
#define PRIVILEGED_FUNCTION __attribute__((section("privileged_functions")))
|
||||||
#define PRIVILEGED_DATA __attribute__((section("privileged_data")))
|
#define PRIVILEGED_DATA __attribute__((section("privileged_data")))
|
||||||
#define FREERTOS_SYSTEM_CALL __attribute__((section( "freertos_system_calls")))
|
|
||||||
|
|
||||||
#endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
|
#endif /* MPU_WRAPPERS_INCLUDED_FROM_API_FILE */
|
||||||
|
|
||||||
|
@ -176,7 +143,6 @@ only for ports that are using the MPU. */
|
||||||
|
|
||||||
#define PRIVILEGED_FUNCTION
|
#define PRIVILEGED_FUNCTION
|
||||||
#define PRIVILEGED_DATA
|
#define PRIVILEGED_DATA
|
||||||
#define FREERTOS_SYSTEM_CALL
|
|
||||||
#define portUSING_MPU_WRAPPERS 0
|
#define portUSING_MPU_WRAPPERS 0
|
||||||
|
|
||||||
#endif /* portUSING_MPU_WRAPPERS */
|
#endif /* portUSING_MPU_WRAPPERS */
|
||||||
|
|
|
@ -1,29 +1,66 @@
|
||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.2.0
|
FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
***************************************************************************
|
||||||
* the Software without restriction, including without limitation the rights to
|
* *
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* FreeRTOS provides completely free yet professionally developed, *
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* robust, strictly quality controlled, supported, and cross *
|
||||||
* subject to the following conditions:
|
* platform software that has become a de facto standard. *
|
||||||
*
|
* *
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* Help yourself get started quickly and support the FreeRTOS *
|
||||||
* copies or substantial portions of the Software.
|
* project by purchasing a FreeRTOS tutorial book, reference *
|
||||||
*
|
* manual, or both from: http://www.FreeRTOS.org/Documentation *
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* *
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* Thank you! *
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* *
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
***************************************************************************
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
This file is part of the FreeRTOS distribution.
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
* http://aws.amazon.com/freertos
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
*
|
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
>>! NOTE: The modification to the GPL is included to allow you to distribute
|
||||||
|
>>! a combined work that includes FreeRTOS without being obliged to provide
|
||||||
|
>>! the source code for proprietary components outside of the FreeRTOS
|
||||||
|
>>! kernel.
|
||||||
|
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. Full license text is available from the following
|
||||||
|
link: http://www.freertos.org/a00114.html
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* Having a problem? Start by reading the FAQ "My application does *
|
||||||
|
* not run, what could be wrong?" *
|
||||||
|
* *
|
||||||
|
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||||
|
license and Real Time Engineers Ltd. contact details.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||||
|
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||||
|
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||||
|
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||||
|
licenses offer ticketed support, indemnification and middleware.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||||
|
engineered and independently SIL3 certified version for use in safety and
|
||||||
|
mission critical applications that require provable dependability.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
*/
|
||||||
|
|
||||||
/*-----------------------------------------------------------
|
/*-----------------------------------------------------------
|
||||||
* Portable layer API. Each function must be defined for each port.
|
* Portable layer API. Each function must be defined for each port.
|
||||||
|
@ -32,32 +69,253 @@
|
||||||
#ifndef PORTABLE_H
|
#ifndef PORTABLE_H
|
||||||
#define PORTABLE_H
|
#define PORTABLE_H
|
||||||
|
|
||||||
/* Each FreeRTOS port has a unique portmacro.h header file. Originally a
|
/* Include the macro file relevant to the port being used. */
|
||||||
pre-processor definition was used to ensure the pre-processor found the correct
|
|
||||||
portmacro.h file for the port being used. That scheme was deprecated in favour
|
|
||||||
of setting the compiler's include path such that it found the correct
|
|
||||||
portmacro.h file - removing the need for the constant and allowing the
|
|
||||||
portmacro.h file to be located anywhere in relation to the port being used.
|
|
||||||
Purely for reasons of backward compatibility the old method is still valid, but
|
|
||||||
to make it clear that new projects should not use it, support for the port
|
|
||||||
specific constants has been moved into the deprecated_definitions.h header
|
|
||||||
file. */
|
|
||||||
#include "deprecated_definitions.h"
|
|
||||||
|
|
||||||
/* If portENTER_CRITICAL is not defined then including deprecated_definitions.h
|
#ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT
|
||||||
did not result in a portmacro.h header file being included - and it should be
|
#include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h"
|
||||||
included here. In this case the path to the correct portmacro.h header file
|
typedef void ( __interrupt __far *pxISR )();
|
||||||
must be set in the compiler's include path. */
|
#endif
|
||||||
#ifndef portENTER_CRITICAL
|
|
||||||
|
#ifdef OPEN_WATCOM_FLASH_LITE_186_PORT
|
||||||
|
#include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h"
|
||||||
|
typedef void ( __interrupt __far *pxISR )();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_MEGA_AVR
|
||||||
|
#include "../portable/GCC/ATMega323/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IAR_MEGA_AVR
|
||||||
|
#include "../portable/IAR/ATMega323/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MPLAB_PIC24_PORT
|
||||||
|
#include "..\..\Source\portable\MPLAB\PIC24_dsPIC\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MPLAB_DSPIC_PORT
|
||||||
|
#include "..\..\Source\portable\MPLAB\PIC24_dsPIC\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MPLAB_PIC18F_PORT
|
||||||
|
#include "..\..\Source\portable\MPLAB\PIC18F\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MPLAB_PIC32MX_PORT
|
||||||
|
#include "..\..\Source\portable\MPLAB\PIC32MX\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _FEDPICC
|
||||||
|
#include "libFreeRTOS/Include/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SDCC_CYGNAL
|
||||||
|
#include "../../Source/portable/SDCC/Cygnal/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_ARM7
|
||||||
|
#include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_ARM7_ECLIPSE
|
||||||
#include "portmacro.h"
|
#include "portmacro.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if portBYTE_ALIGNMENT == 32
|
#ifdef ROWLEY_LPC23xx
|
||||||
#define portBYTE_ALIGNMENT_MASK ( 0x001f )
|
#include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if portBYTE_ALIGNMENT == 16
|
#ifdef IAR_MSP430
|
||||||
#define portBYTE_ALIGNMENT_MASK ( 0x000f )
|
#include "..\..\Source\portable\IAR\MSP430\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_MSP430
|
||||||
|
#include "../../Source/portable/GCC/MSP430F449/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ROWLEY_MSP430
|
||||||
|
#include "../../Source/portable/Rowley/MSP430F449/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ARM7_LPC21xx_KEIL_RVDS
|
||||||
|
#include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SAM7_GCC
|
||||||
|
#include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SAM7_IAR
|
||||||
|
#include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SAM9XE_IAR
|
||||||
|
#include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LPC2000_IAR
|
||||||
|
#include "..\..\Source\portable\IAR\LPC2000\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef STR71X_IAR
|
||||||
|
#include "..\..\Source\portable\IAR\STR71x\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef STR75X_IAR
|
||||||
|
#include "..\..\Source\portable\IAR\STR75x\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef STR75X_GCC
|
||||||
|
#include "..\..\Source\portable\GCC\STR75x\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef STR91X_IAR
|
||||||
|
#include "..\..\Source\portable\IAR\STR91x\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_H8S
|
||||||
|
#include "../../Source/portable/GCC/H8S2329/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_AT91FR40008
|
||||||
|
#include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef RVDS_ARMCM3_LM3S102
|
||||||
|
#include "../../Source/portable/RVDS/ARM_CM3/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_ARMCM3_LM3S102
|
||||||
|
#include "../../Source/portable/GCC/ARM_CM3/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_ARMCM3
|
||||||
|
#include "../../Source/portable/GCC/ARM_CM3/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IAR_ARM_CM3
|
||||||
|
#include "../../Source/portable/IAR/ARM_CM3/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IAR_ARMCM3_LM
|
||||||
|
#include "../../Source/portable/IAR/ARM_CM3/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HCS12_CODE_WARRIOR
|
||||||
|
#include "../../Source/portable/CodeWarrior/HCS12/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MICROBLAZE_GCC
|
||||||
|
#include "../../Source/portable/GCC/MicroBlaze/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef TERN_EE
|
||||||
|
#include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_HCS12
|
||||||
|
#include "../../Source/portable/GCC/HCS12/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_MCF5235
|
||||||
|
#include "../../Source/portable/GCC/MCF5235/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLDFIRE_V2_GCC
|
||||||
|
#include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef COLDFIRE_V2_CODEWARRIOR
|
||||||
|
#include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_PPC405
|
||||||
|
#include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef GCC_PPC440
|
||||||
|
#include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _16FX_SOFTUNE
|
||||||
|
#include "..\..\Source\portable\Softune\MB96340\portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BCC_INDUSTRIAL_PC_PORT
|
||||||
|
/* A short file name has to be used in place of the normal
|
||||||
|
FreeRTOSConfig.h when using the Borland compiler. */
|
||||||
|
#include "frconfig.h"
|
||||||
|
#include "..\portable\BCC\16BitDOS\PC\prtmacro.h"
|
||||||
|
typedef void ( __interrupt __far *pxISR )();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BCC_FLASH_LITE_186_PORT
|
||||||
|
/* A short file name has to be used in place of the normal
|
||||||
|
FreeRTOSConfig.h when using the Borland compiler. */
|
||||||
|
#include "frconfig.h"
|
||||||
|
#include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h"
|
||||||
|
typedef void ( __interrupt __far *pxISR )();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#ifdef __AVR32_AVR32A__
|
||||||
|
#include "portmacro.h"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __ICCAVR32__
|
||||||
|
#ifdef __CORE__
|
||||||
|
#if __CORE__ == __AVR32A__
|
||||||
|
#include "portmacro.h"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __91467D
|
||||||
|
#include "portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __96340
|
||||||
|
#include "portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __IAR_V850ES_Fx3__
|
||||||
|
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __IAR_V850ES_Jx3__
|
||||||
|
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __IAR_V850ES_Jx3_L__
|
||||||
|
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __IAR_V850ES_Jx2__
|
||||||
|
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __IAR_V850ES_Hx2__
|
||||||
|
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __IAR_78K0R_Kx3__
|
||||||
|
#include "../../Source/portable/IAR/78K0R/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __IAR_78K0R_Kx3L__
|
||||||
|
#include "../../Source/portable/IAR/78K0R/portmacro.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Catch all to ensure portmacro.h is included in the build. Newer demos
|
||||||
|
have the path as part of the project options, rather than as relative from
|
||||||
|
the project location. If portENTER_CRITICAL() has not been defined then
|
||||||
|
portmacro.h has not yet been included - as every portmacro.h provides a
|
||||||
|
portENTER_CRITICAL() definition. Check the demo application for your demo
|
||||||
|
to find the path to the correct portmacro.h file. */
|
||||||
|
#ifndef portENTER_CRITICAL
|
||||||
|
#include "portmacro.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if portBYTE_ALIGNMENT == 8
|
#if portBYTE_ALIGNMENT == 8
|
||||||
|
@ -84,14 +342,6 @@ must be set in the compiler's include path. */
|
||||||
#define portNUM_CONFIGURABLE_REGIONS 1
|
#define portNUM_CONFIGURABLE_REGIONS 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef portHAS_STACK_OVERFLOW_CHECKING
|
|
||||||
#define portHAS_STACK_OVERFLOW_CHECKING 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef portARCH_NAME
|
|
||||||
#define portARCH_NAME NULL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -105,40 +355,11 @@ extern "C" {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#if( portUSING_MPU_WRAPPERS == 1 )
|
#if( portUSING_MPU_WRAPPERS == 1 )
|
||||||
#if( portHAS_STACK_OVERFLOW_CHECKING == 1 )
|
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters, portBASE_TYPE xRunPrivileged ) PRIVILEGED_FUNCTION;
|
||||||
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION;
|
|
||||||
#else
|
|
||||||
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION;
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
#if( portHAS_STACK_OVERFLOW_CHECKING == 1 )
|
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters ) PRIVILEGED_FUNCTION;
|
||||||
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION;
|
|
||||||
#else
|
|
||||||
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION;
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Used by heap_5.c. */
|
|
||||||
typedef struct HeapRegion
|
|
||||||
{
|
|
||||||
uint8_t *pucStartAddress;
|
|
||||||
size_t xSizeInBytes;
|
|
||||||
} HeapRegion_t;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Used to define multiple heap regions for use by heap_5.c. This function
|
|
||||||
* must be called before any calls to pvPortMalloc() - not creating a task,
|
|
||||||
* queue, semaphore, mutex, software timer, event group, etc. will result in
|
|
||||||
* pvPortMalloc being called.
|
|
||||||
*
|
|
||||||
* pxHeapRegions passes in an array of HeapRegion_t structures - each of which
|
|
||||||
* defines a region of memory that can be used as the heap. The array is
|
|
||||||
* terminated by a HeapRegions_t structure that has a size of 0. The region
|
|
||||||
* with the lowest start address must appear first in the array.
|
|
||||||
*/
|
|
||||||
void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Map to the memory management routines required for the port.
|
* Map to the memory management routines required for the port.
|
||||||
*/
|
*/
|
||||||
|
@ -146,13 +367,12 @@ void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;
|
||||||
void vPortFree( void *pv ) PRIVILEGED_FUNCTION;
|
void vPortFree( void *pv ) PRIVILEGED_FUNCTION;
|
||||||
void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;
|
void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;
|
||||||
size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION;
|
size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION;
|
||||||
size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup the hardware ready for the scheduler to take control. This generally
|
* Setup the hardware ready for the scheduler to take control. This generally
|
||||||
* sets up a tick interrupt and sets timers for the correct tick frequency.
|
* sets up a tick interrupt and sets timers for the correct tick frequency.
|
||||||
*/
|
*/
|
||||||
BaseType_t xPortStartScheduler( void ) PRIVILEGED_FUNCTION;
|
portBASE_TYPE xPortStartScheduler( void ) PRIVILEGED_FUNCTION;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Undo any hardware/ISR setup that was performed by xPortStartScheduler() so
|
* Undo any hardware/ISR setup that was performed by xPortStartScheduler() so
|
||||||
|
@ -170,7 +390,7 @@ void vPortEndScheduler( void ) PRIVILEGED_FUNCTION;
|
||||||
*/
|
*/
|
||||||
#if( portUSING_MPU_WRAPPERS == 1 )
|
#if( portUSING_MPU_WRAPPERS == 1 )
|
||||||
struct xMEMORY_REGION;
|
struct xMEMORY_REGION;
|
||||||
void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, StackType_t *pxBottomOfStack, uint32_t ulStackDepth ) PRIVILEGED_FUNCTION;
|
void vPortStoreTaskMPUSettings( xMPU_SETTINGS *xMPUSettings, const struct xMEMORY_REGION * const xRegions, portSTACK_TYPE *pxBottomOfStack, unsigned short usStackDepth ) PRIVILEGED_FUNCTION;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -1,123 +1,87 @@
|
||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.2.0
|
FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
***************************************************************************
|
||||||
* the Software without restriction, including without limitation the rights to
|
* *
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* FreeRTOS provides completely free yet professionally developed, *
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* robust, strictly quality controlled, supported, and cross *
|
||||||
* subject to the following conditions:
|
* platform software that has become a de facto standard. *
|
||||||
*
|
* *
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* Help yourself get started quickly and support the FreeRTOS *
|
||||||
* copies or substantial portions of the Software.
|
* project by purchasing a FreeRTOS tutorial book, reference *
|
||||||
*
|
* manual, or both from: http://www.FreeRTOS.org/Documentation *
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* *
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* Thank you! *
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* *
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
***************************************************************************
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
This file is part of the FreeRTOS distribution.
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
* http://aws.amazon.com/freertos
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
*
|
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
>>! NOTE: The modification to the GPL is included to allow you to distribute
|
||||||
|
>>! a combined work that includes FreeRTOS without being obliged to provide
|
||||||
|
>>! the source code for proprietary components outside of the FreeRTOS
|
||||||
|
>>! kernel.
|
||||||
|
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. Full license text is available from the following
|
||||||
|
link: http://www.freertos.org/a00114.html
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* Having a problem? Start by reading the FAQ "My application does *
|
||||||
|
* not run, what could be wrong?" *
|
||||||
|
* *
|
||||||
|
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||||
|
license and Real Time Engineers Ltd. contact details.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||||
|
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||||
|
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||||
|
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||||
|
licenses offer ticketed support, indemnification and middleware.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||||
|
engineered and independently SIL3 certified version for use in safety and
|
||||||
|
mission critical applications that require provable dependability.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef PROJDEFS_H
|
#ifndef PROJDEFS_H
|
||||||
#define PROJDEFS_H
|
#define PROJDEFS_H
|
||||||
|
|
||||||
/*
|
/* Defines the prototype to which task functions must conform. */
|
||||||
* Defines the prototype to which task functions must conform. Defined in this
|
typedef void (*pdTASK_CODE)( void * );
|
||||||
* file to ensure the type is known before portable.h is included.
|
|
||||||
*/
|
|
||||||
typedef void (*TaskFunction_t)( void * );
|
|
||||||
|
|
||||||
/* Converts a time in milliseconds to a time in ticks. This macro can be
|
#define pdFALSE ( ( portBASE_TYPE ) 0 )
|
||||||
overridden by a macro of the same name defined in FreeRTOSConfig.h in case the
|
#define pdTRUE ( ( portBASE_TYPE ) 1 )
|
||||||
definition here is not suitable for your application. */
|
|
||||||
#ifndef pdMS_TO_TICKS
|
|
||||||
#define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000 ) )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define pdFALSE ( ( BaseType_t ) 0 )
|
#define pdPASS ( pdTRUE )
|
||||||
#define pdTRUE ( ( BaseType_t ) 1 )
|
#define pdFAIL ( pdFALSE )
|
||||||
|
#define errQUEUE_EMPTY ( ( portBASE_TYPE ) 0 )
|
||||||
|
#define errQUEUE_FULL ( ( portBASE_TYPE ) 0 )
|
||||||
|
|
||||||
#define pdPASS ( pdTRUE )
|
/* Error definitions. */
|
||||||
#define pdFAIL ( pdFALSE )
|
|
||||||
#define errQUEUE_EMPTY ( ( BaseType_t ) 0 )
|
|
||||||
#define errQUEUE_FULL ( ( BaseType_t ) 0 )
|
|
||||||
|
|
||||||
/* FreeRTOS error definitions. */
|
|
||||||
#define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 )
|
#define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 )
|
||||||
|
#define errNO_TASK_TO_RUN ( -2 )
|
||||||
#define errQUEUE_BLOCKED ( -4 )
|
#define errQUEUE_BLOCKED ( -4 )
|
||||||
#define errQUEUE_YIELD ( -5 )
|
#define errQUEUE_YIELD ( -5 )
|
||||||
|
|
||||||
/* Macros used for basic data corruption checks. */
|
|
||||||
#ifndef configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES
|
|
||||||
#define configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if( configUSE_16_BIT_TICKS == 1 )
|
|
||||||
#define pdINTEGRITY_CHECK_VALUE 0x5a5a
|
|
||||||
#else
|
|
||||||
#define pdINTEGRITY_CHECK_VALUE 0x5a5a5a5aUL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* The following errno values are used by FreeRTOS+ components, not FreeRTOS
|
|
||||||
itself. */
|
|
||||||
#define pdFREERTOS_ERRNO_NONE 0 /* No errors */
|
|
||||||
#define pdFREERTOS_ERRNO_ENOENT 2 /* No such file or directory */
|
|
||||||
#define pdFREERTOS_ERRNO_EINTR 4 /* Interrupted system call */
|
|
||||||
#define pdFREERTOS_ERRNO_EIO 5 /* I/O error */
|
|
||||||
#define pdFREERTOS_ERRNO_ENXIO 6 /* No such device or address */
|
|
||||||
#define pdFREERTOS_ERRNO_EBADF 9 /* Bad file number */
|
|
||||||
#define pdFREERTOS_ERRNO_EAGAIN 11 /* No more processes */
|
|
||||||
#define pdFREERTOS_ERRNO_EWOULDBLOCK 11 /* Operation would block */
|
|
||||||
#define pdFREERTOS_ERRNO_ENOMEM 12 /* Not enough memory */
|
|
||||||
#define pdFREERTOS_ERRNO_EACCES 13 /* Permission denied */
|
|
||||||
#define pdFREERTOS_ERRNO_EFAULT 14 /* Bad address */
|
|
||||||
#define pdFREERTOS_ERRNO_EBUSY 16 /* Mount device busy */
|
|
||||||
#define pdFREERTOS_ERRNO_EEXIST 17 /* File exists */
|
|
||||||
#define pdFREERTOS_ERRNO_EXDEV 18 /* Cross-device link */
|
|
||||||
#define pdFREERTOS_ERRNO_ENODEV 19 /* No such device */
|
|
||||||
#define pdFREERTOS_ERRNO_ENOTDIR 20 /* Not a directory */
|
|
||||||
#define pdFREERTOS_ERRNO_EISDIR 21 /* Is a directory */
|
|
||||||
#define pdFREERTOS_ERRNO_EINVAL 22 /* Invalid argument */
|
|
||||||
#define pdFREERTOS_ERRNO_ENOSPC 28 /* No space left on device */
|
|
||||||
#define pdFREERTOS_ERRNO_ESPIPE 29 /* Illegal seek */
|
|
||||||
#define pdFREERTOS_ERRNO_EROFS 30 /* Read only file system */
|
|
||||||
#define pdFREERTOS_ERRNO_EUNATCH 42 /* Protocol driver not attached */
|
|
||||||
#define pdFREERTOS_ERRNO_EBADE 50 /* Invalid exchange */
|
|
||||||
#define pdFREERTOS_ERRNO_EFTYPE 79 /* Inappropriate file type or format */
|
|
||||||
#define pdFREERTOS_ERRNO_ENMFILE 89 /* No more files */
|
|
||||||
#define pdFREERTOS_ERRNO_ENOTEMPTY 90 /* Directory not empty */
|
|
||||||
#define pdFREERTOS_ERRNO_ENAMETOOLONG 91 /* File or path name too long */
|
|
||||||
#define pdFREERTOS_ERRNO_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
|
|
||||||
#define pdFREERTOS_ERRNO_ENOBUFS 105 /* No buffer space available */
|
|
||||||
#define pdFREERTOS_ERRNO_ENOPROTOOPT 109 /* Protocol not available */
|
|
||||||
#define pdFREERTOS_ERRNO_EADDRINUSE 112 /* Address already in use */
|
|
||||||
#define pdFREERTOS_ERRNO_ETIMEDOUT 116 /* Connection timed out */
|
|
||||||
#define pdFREERTOS_ERRNO_EINPROGRESS 119 /* Connection already in progress */
|
|
||||||
#define pdFREERTOS_ERRNO_EALREADY 120 /* Socket already connected */
|
|
||||||
#define pdFREERTOS_ERRNO_EADDRNOTAVAIL 125 /* Address not available */
|
|
||||||
#define pdFREERTOS_ERRNO_EISCONN 127 /* Socket is already connected */
|
|
||||||
#define pdFREERTOS_ERRNO_ENOTCONN 128 /* Socket is not connected */
|
|
||||||
#define pdFREERTOS_ERRNO_ENOMEDIUM 135 /* No medium inserted */
|
|
||||||
#define pdFREERTOS_ERRNO_EILSEQ 138 /* An invalid UTF-16 sequence was encountered. */
|
|
||||||
#define pdFREERTOS_ERRNO_ECANCELED 140 /* Operation canceled. */
|
|
||||||
|
|
||||||
/* The following endian values are used by FreeRTOS+ components, not FreeRTOS
|
|
||||||
itself. */
|
|
||||||
#define pdFREERTOS_LITTLE_ENDIAN 0
|
|
||||||
#define pdFREERTOS_BIG_ENDIAN 1
|
|
||||||
|
|
||||||
/* Re-defining endian values for generic naming. */
|
|
||||||
#define pdLITTLE_ENDIAN pdFREERTOS_LITTLE_ENDIAN
|
|
||||||
#define pdBIG_ENDIAN pdFREERTOS_BIG_ENDIAN
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* PROJDEFS_H */
|
#endif /* PROJDEFS_H */
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,129 +0,0 @@
|
||||||
/*
|
|
||||||
* FreeRTOS Kernel V10.2.0
|
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
|
||||||
* http://aws.amazon.com/freertos
|
|
||||||
*
|
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef STACK_MACROS_H
|
|
||||||
#define STACK_MACROS_H
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Call the stack overflow hook function if the stack of the task being swapped
|
|
||||||
* out is currently overflowed, or looks like it might have overflowed in the
|
|
||||||
* past.
|
|
||||||
*
|
|
||||||
* Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
|
|
||||||
* the current stack state only - comparing the current top of stack value to
|
|
||||||
* the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
|
|
||||||
* will also cause the last few stack bytes to be checked to ensure the value
|
|
||||||
* to which the bytes were set when the task was created have not been
|
|
||||||
* overwritten. Note this second test does not guarantee that an overflowed
|
|
||||||
* stack will always be recognised.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) )
|
|
||||||
|
|
||||||
/* Only the current stack state is to be checked. */
|
|
||||||
#define taskCHECK_FOR_STACK_OVERFLOW() \
|
|
||||||
{ \
|
|
||||||
/* Is the currently saved stack pointer within the stack limit? */ \
|
|
||||||
if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \
|
|
||||||
{ \
|
|
||||||
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) )
|
|
||||||
|
|
||||||
/* Only the current stack state is to be checked. */
|
|
||||||
#define taskCHECK_FOR_STACK_OVERFLOW() \
|
|
||||||
{ \
|
|
||||||
\
|
|
||||||
/* Is the currently saved stack pointer within the stack limit? */ \
|
|
||||||
if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \
|
|
||||||
{ \
|
|
||||||
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
|
|
||||||
|
|
||||||
#define taskCHECK_FOR_STACK_OVERFLOW() \
|
|
||||||
{ \
|
|
||||||
const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
|
|
||||||
const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \
|
|
||||||
\
|
|
||||||
if( ( pulStack[ 0 ] != ulCheckValue ) || \
|
|
||||||
( pulStack[ 1 ] != ulCheckValue ) || \
|
|
||||||
( pulStack[ 2 ] != ulCheckValue ) || \
|
|
||||||
( pulStack[ 3 ] != ulCheckValue ) ) \
|
|
||||||
{ \
|
|
||||||
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
|
|
||||||
|
|
||||||
#define taskCHECK_FOR_STACK_OVERFLOW() \
|
|
||||||
{ \
|
|
||||||
int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \
|
|
||||||
static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
|
||||||
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
|
||||||
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
|
||||||
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
|
|
||||||
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
|
|
||||||
\
|
|
||||||
\
|
|
||||||
pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
|
|
||||||
\
|
|
||||||
/* Has the extremity of the task stack ever been written over? */ \
|
|
||||||
if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
|
|
||||||
{ \
|
|
||||||
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
|
|
||||||
/*-----------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Remove stack overflow macro if not being used. */
|
|
||||||
#ifndef taskCHECK_FOR_STACK_OVERFLOW
|
|
||||||
#define taskCHECK_FOR_STACK_OVERFLOW()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* STACK_MACROS_H */
|
|
||||||
|
|
|
@ -1,855 +0,0 @@
|
||||||
/*
|
|
||||||
* FreeRTOS Kernel V10.2.0
|
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
|
||||||
* http://aws.amazon.com/freertos
|
|
||||||
*
|
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Stream buffers are used to send a continuous stream of data from one task or
|
|
||||||
* interrupt to another. Their implementation is light weight, making them
|
|
||||||
* particularly suited for interrupt to task and core to core communication
|
|
||||||
* scenarios.
|
|
||||||
*
|
|
||||||
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
|
|
||||||
* implementation (so also the message buffer implementation, as message buffers
|
|
||||||
* are built on top of stream buffers) assumes there is only one task or
|
|
||||||
* interrupt that will write to the buffer (the writer), and only one task or
|
|
||||||
* interrupt that will read from the buffer (the reader). It is safe for the
|
|
||||||
* writer and reader to be different tasks or interrupts, but, unlike other
|
|
||||||
* FreeRTOS objects, it is not safe to have multiple different writers or
|
|
||||||
* multiple different readers. If there are to be multiple different writers
|
|
||||||
* then the application writer must place each call to a writing API function
|
|
||||||
* (such as xStreamBufferSend()) inside a critical section and set the send
|
|
||||||
* block time to 0. Likewise, if there are to be multiple different readers
|
|
||||||
* then the application writer must place each call to a reading API function
|
|
||||||
* (such as xStreamBufferRead()) inside a critical section section and set the
|
|
||||||
* receive block time to 0.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef STREAM_BUFFER_H
|
|
||||||
#define STREAM_BUFFER_H
|
|
||||||
|
|
||||||
#if defined( __cplusplus )
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type by which stream buffers are referenced. For example, a call to
|
|
||||||
* xStreamBufferCreate() returns an StreamBufferHandle_t variable that can
|
|
||||||
* then be used as a parameter to xStreamBufferSend(), xStreamBufferReceive(),
|
|
||||||
* etc.
|
|
||||||
*/
|
|
||||||
struct StreamBufferDef_t;
|
|
||||||
typedef struct StreamBufferDef_t * StreamBufferHandle_t;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* message_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
StreamBufferHandle_t xStreamBufferCreate( size_t xBufferSizeBytes, size_t xTriggerLevelBytes );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Creates a new stream buffer using dynamically allocated memory. See
|
|
||||||
* xStreamBufferCreateStatic() for a version that uses statically allocated
|
|
||||||
* memory (memory that is allocated at compile time).
|
|
||||||
*
|
|
||||||
* configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 or left undefined in
|
|
||||||
* FreeRTOSConfig.h for xStreamBufferCreate() to be available.
|
|
||||||
*
|
|
||||||
* @param xBufferSizeBytes The total number of bytes the stream buffer will be
|
|
||||||
* able to hold at any one time.
|
|
||||||
*
|
|
||||||
* @param xTriggerLevelBytes The number of bytes that must be in the stream
|
|
||||||
* buffer before a task that is blocked on the stream buffer to wait for data is
|
|
||||||
* moved out of the blocked state. For example, if a task is blocked on a read
|
|
||||||
* of an empty stream buffer that has a trigger level of 1 then the task will be
|
|
||||||
* unblocked when a single byte is written to the buffer or the task's block
|
|
||||||
* time expires. As another example, if a task is blocked on a read of an empty
|
|
||||||
* stream buffer that has a trigger level of 10 then the task will not be
|
|
||||||
* unblocked until the stream buffer contains at least 10 bytes or the task's
|
|
||||||
* block time expires. If a reading task's block time expires before the
|
|
||||||
* trigger level is reached then the task will still receive however many bytes
|
|
||||||
* are actually available. Setting a trigger level of 0 will result in a
|
|
||||||
* trigger level of 1 being used. It is not valid to specify a trigger level
|
|
||||||
* that is greater than the buffer size.
|
|
||||||
*
|
|
||||||
* @return If NULL is returned, then the stream buffer cannot be created
|
|
||||||
* because there is insufficient heap memory available for FreeRTOS to allocate
|
|
||||||
* the stream buffer data structures and storage area. A non-NULL value being
|
|
||||||
* returned indicates that the stream buffer has been created successfully -
|
|
||||||
* the returned value should be stored as the handle to the created stream
|
|
||||||
* buffer.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
|
|
||||||
void vAFunction( void )
|
|
||||||
{
|
|
||||||
StreamBufferHandle_t xStreamBuffer;
|
|
||||||
const size_t xStreamBufferSizeBytes = 100, xTriggerLevel = 10;
|
|
||||||
|
|
||||||
// Create a stream buffer that can hold 100 bytes. The memory used to hold
|
|
||||||
// both the stream buffer structure and the data in the stream buffer is
|
|
||||||
// allocated dynamically.
|
|
||||||
xStreamBuffer = xStreamBufferCreate( xStreamBufferSizeBytes, xTriggerLevel );
|
|
||||||
|
|
||||||
if( xStreamBuffer == NULL )
|
|
||||||
{
|
|
||||||
// There was not enough heap memory space available to create the
|
|
||||||
// stream buffer.
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// The stream buffer was created successfully and can now be used.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xStreamBufferCreate xStreamBufferCreate
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
#define xStreamBufferCreate( xBufferSizeBytes, xTriggerLevelBytes ) xStreamBufferGenericCreate( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
StreamBufferHandle_t xStreamBufferCreateStatic( size_t xBufferSizeBytes,
|
|
||||||
size_t xTriggerLevelBytes,
|
|
||||||
uint8_t *pucStreamBufferStorageArea,
|
|
||||||
StaticStreamBuffer_t *pxStaticStreamBuffer );
|
|
||||||
</pre>
|
|
||||||
* Creates a new stream buffer using statically allocated memory. See
|
|
||||||
* xStreamBufferCreate() for a version that uses dynamically allocated memory.
|
|
||||||
*
|
|
||||||
* configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h for
|
|
||||||
* xStreamBufferCreateStatic() to be available.
|
|
||||||
*
|
|
||||||
* @param xBufferSizeBytes The size, in bytes, of the buffer pointed to by the
|
|
||||||
* pucStreamBufferStorageArea parameter.
|
|
||||||
*
|
|
||||||
* @param xTriggerLevelBytes The number of bytes that must be in the stream
|
|
||||||
* buffer before a task that is blocked on the stream buffer to wait for data is
|
|
||||||
* moved out of the blocked state. For example, if a task is blocked on a read
|
|
||||||
* of an empty stream buffer that has a trigger level of 1 then the task will be
|
|
||||||
* unblocked when a single byte is written to the buffer or the task's block
|
|
||||||
* time expires. As another example, if a task is blocked on a read of an empty
|
|
||||||
* stream buffer that has a trigger level of 10 then the task will not be
|
|
||||||
* unblocked until the stream buffer contains at least 10 bytes or the task's
|
|
||||||
* block time expires. If a reading task's block time expires before the
|
|
||||||
* trigger level is reached then the task will still receive however many bytes
|
|
||||||
* are actually available. Setting a trigger level of 0 will result in a
|
|
||||||
* trigger level of 1 being used. It is not valid to specify a trigger level
|
|
||||||
* that is greater than the buffer size.
|
|
||||||
*
|
|
||||||
* @param pucStreamBufferStorageArea Must point to a uint8_t array that is at
|
|
||||||
* least xBufferSizeBytes + 1 big. This is the array to which streams are
|
|
||||||
* copied when they are written to the stream buffer.
|
|
||||||
*
|
|
||||||
* @param pxStaticStreamBuffer Must point to a variable of type
|
|
||||||
* StaticStreamBuffer_t, which will be used to hold the stream buffer's data
|
|
||||||
* structure.
|
|
||||||
*
|
|
||||||
* @return If the stream buffer is created successfully then a handle to the
|
|
||||||
* created stream buffer is returned. If either pucStreamBufferStorageArea or
|
|
||||||
* pxStaticstreamBuffer are NULL then NULL is returned.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
|
|
||||||
// Used to dimension the array used to hold the streams. The available space
|
|
||||||
// will actually be one less than this, so 999.
|
|
||||||
#define STORAGE_SIZE_BYTES 1000
|
|
||||||
|
|
||||||
// Defines the memory that will actually hold the streams within the stream
|
|
||||||
// buffer.
|
|
||||||
static uint8_t ucStorageBuffer[ STORAGE_SIZE_BYTES ];
|
|
||||||
|
|
||||||
// The variable used to hold the stream buffer structure.
|
|
||||||
StaticStreamBuffer_t xStreamBufferStruct;
|
|
||||||
|
|
||||||
void MyFunction( void )
|
|
||||||
{
|
|
||||||
StreamBufferHandle_t xStreamBuffer;
|
|
||||||
const size_t xTriggerLevel = 1;
|
|
||||||
|
|
||||||
xStreamBuffer = xStreamBufferCreateStatic( sizeof( ucBufferStorage ),
|
|
||||||
xTriggerLevel,
|
|
||||||
ucBufferStorage,
|
|
||||||
&xStreamBufferStruct );
|
|
||||||
|
|
||||||
// As neither the pucStreamBufferStorageArea or pxStaticStreamBuffer
|
|
||||||
// parameters were NULL, xStreamBuffer will not be NULL, and can be used to
|
|
||||||
// reference the created stream buffer in other stream buffer API calls.
|
|
||||||
|
|
||||||
// Other code that uses the stream buffer can go here.
|
|
||||||
}
|
|
||||||
|
|
||||||
</pre>
|
|
||||||
* \defgroup xStreamBufferCreateStatic xStreamBufferCreateStatic
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
#define xStreamBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pucStreamBufferStorageArea, pxStaticStreamBuffer )
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
|
|
||||||
const void *pvTxData,
|
|
||||||
size_t xDataLengthBytes,
|
|
||||||
TickType_t xTicksToWait );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Sends bytes to a stream buffer. The bytes are copied into the stream buffer.
|
|
||||||
*
|
|
||||||
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
|
|
||||||
* implementation (so also the message buffer implementation, as message buffers
|
|
||||||
* are built on top of stream buffers) assumes there is only one task or
|
|
||||||
* interrupt that will write to the buffer (the writer), and only one task or
|
|
||||||
* interrupt that will read from the buffer (the reader). It is safe for the
|
|
||||||
* writer and reader to be different tasks or interrupts, but, unlike other
|
|
||||||
* FreeRTOS objects, it is not safe to have multiple different writers or
|
|
||||||
* multiple different readers. If there are to be multiple different writers
|
|
||||||
* then the application writer must place each call to a writing API function
|
|
||||||
* (such as xStreamBufferSend()) inside a critical section and set the send
|
|
||||||
* block time to 0. Likewise, if there are to be multiple different readers
|
|
||||||
* then the application writer must place each call to a reading API function
|
|
||||||
* (such as xStreamBufferRead()) inside a critical section and set the receive
|
|
||||||
* block time to 0.
|
|
||||||
*
|
|
||||||
* Use xStreamBufferSend() to write to a stream buffer from a task. Use
|
|
||||||
* xStreamBufferSendFromISR() to write to a stream buffer from an interrupt
|
|
||||||
* service routine (ISR).
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer to which a stream is
|
|
||||||
* being sent.
|
|
||||||
*
|
|
||||||
* @param pvTxData A pointer to the buffer that holds the bytes to be copied
|
|
||||||
* into the stream buffer.
|
|
||||||
*
|
|
||||||
* @param xDataLengthBytes The maximum number of bytes to copy from pvTxData
|
|
||||||
* into the stream buffer.
|
|
||||||
*
|
|
||||||
* @param xTicksToWait The maximum amount of time the task should remain in the
|
|
||||||
* Blocked state to wait for enough space to become available in the stream
|
|
||||||
* buffer, should the stream buffer contain too little space to hold the
|
|
||||||
* another xDataLengthBytes bytes. The block time is specified in tick periods,
|
|
||||||
* so the absolute time it represents is dependent on the tick frequency. The
|
|
||||||
* macro pdMS_TO_TICKS() can be used to convert a time specified in milliseconds
|
|
||||||
* into a time specified in ticks. Setting xTicksToWait to portMAX_DELAY will
|
|
||||||
* cause the task to wait indefinitely (without timing out), provided
|
|
||||||
* INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. If a task times out
|
|
||||||
* before it can write all xDataLengthBytes into the buffer it will still write
|
|
||||||
* as many bytes as possible. A task does not use any CPU time when it is in
|
|
||||||
* the blocked state.
|
|
||||||
*
|
|
||||||
* @return The number of bytes written to the stream buffer. If a task times
|
|
||||||
* out before it can write all xDataLengthBytes into the buffer it will still
|
|
||||||
* write as many bytes as possible.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
void vAFunction( StreamBufferHandle_t xStreamBuffer )
|
|
||||||
{
|
|
||||||
size_t xBytesSent;
|
|
||||||
uint8_t ucArrayToSend[] = { 0, 1, 2, 3 };
|
|
||||||
char *pcStringToSend = "String to send";
|
|
||||||
const TickType_t x100ms = pdMS_TO_TICKS( 100 );
|
|
||||||
|
|
||||||
// Send an array to the stream buffer, blocking for a maximum of 100ms to
|
|
||||||
// wait for enough space to be available in the stream buffer.
|
|
||||||
xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) ucArrayToSend, sizeof( ucArrayToSend ), x100ms );
|
|
||||||
|
|
||||||
if( xBytesSent != sizeof( ucArrayToSend ) )
|
|
||||||
{
|
|
||||||
// The call to xStreamBufferSend() times out before there was enough
|
|
||||||
// space in the buffer for the data to be written, but it did
|
|
||||||
// successfully write xBytesSent bytes.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the string to the stream buffer. Return immediately if there is not
|
|
||||||
// enough space in the buffer.
|
|
||||||
xBytesSent = xStreamBufferSend( xStreamBuffer, ( void * ) pcStringToSend, strlen( pcStringToSend ), 0 );
|
|
||||||
|
|
||||||
if( xBytesSent != strlen( pcStringToSend ) )
|
|
||||||
{
|
|
||||||
// The entire string could not be added to the stream buffer because
|
|
||||||
// there was not enough free space in the buffer, but xBytesSent bytes
|
|
||||||
// were sent. Could try again to send the remaining bytes.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xStreamBufferSend xStreamBufferSend
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
|
|
||||||
const void *pvTxData,
|
|
||||||
size_t xDataLengthBytes,
|
|
||||||
TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
|
|
||||||
const void *pvTxData,
|
|
||||||
size_t xDataLengthBytes,
|
|
||||||
BaseType_t *pxHigherPriorityTaskWoken );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Interrupt safe version of the API function that sends a stream of bytes to
|
|
||||||
* the stream buffer.
|
|
||||||
*
|
|
||||||
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
|
|
||||||
* implementation (so also the message buffer implementation, as message buffers
|
|
||||||
* are built on top of stream buffers) assumes there is only one task or
|
|
||||||
* interrupt that will write to the buffer (the writer), and only one task or
|
|
||||||
* interrupt that will read from the buffer (the reader). It is safe for the
|
|
||||||
* writer and reader to be different tasks or interrupts, but, unlike other
|
|
||||||
* FreeRTOS objects, it is not safe to have multiple different writers or
|
|
||||||
* multiple different readers. If there are to be multiple different writers
|
|
||||||
* then the application writer must place each call to a writing API function
|
|
||||||
* (such as xStreamBufferSend()) inside a critical section and set the send
|
|
||||||
* block time to 0. Likewise, if there are to be multiple different readers
|
|
||||||
* then the application writer must place each call to a reading API function
|
|
||||||
* (such as xStreamBufferRead()) inside a critical section and set the receive
|
|
||||||
* block time to 0.
|
|
||||||
*
|
|
||||||
* Use xStreamBufferSend() to write to a stream buffer from a task. Use
|
|
||||||
* xStreamBufferSendFromISR() to write to a stream buffer from an interrupt
|
|
||||||
* service routine (ISR).
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer to which a stream is
|
|
||||||
* being sent.
|
|
||||||
*
|
|
||||||
* @param pvTxData A pointer to the data that is to be copied into the stream
|
|
||||||
* buffer.
|
|
||||||
*
|
|
||||||
* @param xDataLengthBytes The maximum number of bytes to copy from pvTxData
|
|
||||||
* into the stream buffer.
|
|
||||||
*
|
|
||||||
* @param pxHigherPriorityTaskWoken It is possible that a stream buffer will
|
|
||||||
* have a task blocked on it waiting for data. Calling
|
|
||||||
* xStreamBufferSendFromISR() can make data available, and so cause a task that
|
|
||||||
* was waiting for data to leave the Blocked state. If calling
|
|
||||||
* xStreamBufferSendFromISR() causes a task to leave the Blocked state, and the
|
|
||||||
* unblocked task has a priority higher than the currently executing task (the
|
|
||||||
* task that was interrupted), then, internally, xStreamBufferSendFromISR()
|
|
||||||
* will set *pxHigherPriorityTaskWoken to pdTRUE. If
|
|
||||||
* xStreamBufferSendFromISR() sets this value to pdTRUE, then normally a
|
|
||||||
* context switch should be performed before the interrupt is exited. This will
|
|
||||||
* ensure that the interrupt returns directly to the highest priority Ready
|
|
||||||
* state task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it
|
|
||||||
* is passed into the function. See the example code below for an example.
|
|
||||||
*
|
|
||||||
* @return The number of bytes actually written to the stream buffer, which will
|
|
||||||
* be less than xDataLengthBytes if the stream buffer didn't have enough free
|
|
||||||
* space for all the bytes to be written.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
// A stream buffer that has already been created.
|
|
||||||
StreamBufferHandle_t xStreamBuffer;
|
|
||||||
|
|
||||||
void vAnInterruptServiceRoutine( void )
|
|
||||||
{
|
|
||||||
size_t xBytesSent;
|
|
||||||
char *pcStringToSend = "String to send";
|
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
|
|
||||||
|
|
||||||
// Attempt to send the string to the stream buffer.
|
|
||||||
xBytesSent = xStreamBufferSendFromISR( xStreamBuffer,
|
|
||||||
( void * ) pcStringToSend,
|
|
||||||
strlen( pcStringToSend ),
|
|
||||||
&xHigherPriorityTaskWoken );
|
|
||||||
|
|
||||||
if( xBytesSent != strlen( pcStringToSend ) )
|
|
||||||
{
|
|
||||||
// There was not enough free space in the stream buffer for the entire
|
|
||||||
// string to be written, ut xBytesSent bytes were written.
|
|
||||||
}
|
|
||||||
|
|
||||||
// If xHigherPriorityTaskWoken was set to pdTRUE inside
|
|
||||||
// xStreamBufferSendFromISR() then a task that has a priority above the
|
|
||||||
// priority of the currently executing task was unblocked and a context
|
|
||||||
// switch should be performed to ensure the ISR returns to the unblocked
|
|
||||||
// task. In most FreeRTOS ports this is done by simply passing
|
|
||||||
// xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
|
|
||||||
// variables value, and perform the context switch if necessary. Check the
|
|
||||||
// documentation for the port in use for port specific instructions.
|
|
||||||
taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xStreamBufferSendFromISR xStreamBufferSendFromISR
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
size_t xStreamBufferSendFromISR( StreamBufferHandle_t xStreamBuffer,
|
|
||||||
const void *pvTxData,
|
|
||||||
size_t xDataLengthBytes,
|
|
||||||
BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
|
|
||||||
void *pvRxData,
|
|
||||||
size_t xBufferLengthBytes,
|
|
||||||
TickType_t xTicksToWait );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Receives bytes from a stream buffer.
|
|
||||||
*
|
|
||||||
* ***NOTE***: Uniquely among FreeRTOS objects, the stream buffer
|
|
||||||
* implementation (so also the message buffer implementation, as message buffers
|
|
||||||
* are built on top of stream buffers) assumes there is only one task or
|
|
||||||
* interrupt that will write to the buffer (the writer), and only one task or
|
|
||||||
* interrupt that will read from the buffer (the reader). It is safe for the
|
|
||||||
* writer and reader to be different tasks or interrupts, but, unlike other
|
|
||||||
* FreeRTOS objects, it is not safe to have multiple different writers or
|
|
||||||
* multiple different readers. If there are to be multiple different writers
|
|
||||||
* then the application writer must place each call to a writing API function
|
|
||||||
* (such as xStreamBufferSend()) inside a critical section and set the send
|
|
||||||
* block time to 0. Likewise, if there are to be multiple different readers
|
|
||||||
* then the application writer must place each call to a reading API function
|
|
||||||
* (such as xStreamBufferRead()) inside a critical section and set the receive
|
|
||||||
* block time to 0.
|
|
||||||
*
|
|
||||||
* Use xStreamBufferReceive() to read from a stream buffer from a task. Use
|
|
||||||
* xStreamBufferReceiveFromISR() to read from a stream buffer from an
|
|
||||||
* interrupt service routine (ISR).
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer from which bytes are to
|
|
||||||
* be received.
|
|
||||||
*
|
|
||||||
* @param pvRxData A pointer to the buffer into which the received bytes will be
|
|
||||||
* copied.
|
|
||||||
*
|
|
||||||
* @param xBufferLengthBytes The length of the buffer pointed to by the
|
|
||||||
* pvRxData parameter. This sets the maximum number of bytes to receive in one
|
|
||||||
* call. xStreamBufferReceive will return as many bytes as possible up to a
|
|
||||||
* maximum set by xBufferLengthBytes.
|
|
||||||
*
|
|
||||||
* @param xTicksToWait The maximum amount of time the task should remain in the
|
|
||||||
* Blocked state to wait for data to become available if the stream buffer is
|
|
||||||
* empty. xStreamBufferReceive() will return immediately if xTicksToWait is
|
|
||||||
* zero. The block time is specified in tick periods, so the absolute time it
|
|
||||||
* represents is dependent on the tick frequency. The macro pdMS_TO_TICKS() can
|
|
||||||
* be used to convert a time specified in milliseconds into a time specified in
|
|
||||||
* ticks. Setting xTicksToWait to portMAX_DELAY will cause the task to wait
|
|
||||||
* indefinitely (without timing out), provided INCLUDE_vTaskSuspend is set to 1
|
|
||||||
* in FreeRTOSConfig.h. A task does not use any CPU time when it is in the
|
|
||||||
* Blocked state.
|
|
||||||
*
|
|
||||||
* @return The number of bytes actually read from the stream buffer, which will
|
|
||||||
* be less than xBufferLengthBytes if the call to xStreamBufferReceive() timed
|
|
||||||
* out before xBufferLengthBytes were available.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
void vAFunction( StreamBuffer_t xStreamBuffer )
|
|
||||||
{
|
|
||||||
uint8_t ucRxData[ 20 ];
|
|
||||||
size_t xReceivedBytes;
|
|
||||||
const TickType_t xBlockTime = pdMS_TO_TICKS( 20 );
|
|
||||||
|
|
||||||
// Receive up to another sizeof( ucRxData ) bytes from the stream buffer.
|
|
||||||
// Wait in the Blocked state (so not using any CPU processing time) for a
|
|
||||||
// maximum of 100ms for the full sizeof( ucRxData ) number of bytes to be
|
|
||||||
// available.
|
|
||||||
xReceivedBytes = xStreamBufferReceive( xStreamBuffer,
|
|
||||||
( void * ) ucRxData,
|
|
||||||
sizeof( ucRxData ),
|
|
||||||
xBlockTime );
|
|
||||||
|
|
||||||
if( xReceivedBytes > 0 )
|
|
||||||
{
|
|
||||||
// A ucRxData contains another xRecievedBytes bytes of data, which can
|
|
||||||
// be processed here....
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xStreamBufferReceive xStreamBufferReceive
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
size_t xStreamBufferReceive( StreamBufferHandle_t xStreamBuffer,
|
|
||||||
void *pvRxData,
|
|
||||||
size_t xBufferLengthBytes,
|
|
||||||
TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
|
|
||||||
void *pvRxData,
|
|
||||||
size_t xBufferLengthBytes,
|
|
||||||
BaseType_t *pxHigherPriorityTaskWoken );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* An interrupt safe version of the API function that receives bytes from a
|
|
||||||
* stream buffer.
|
|
||||||
*
|
|
||||||
* Use xStreamBufferReceive() to read bytes from a stream buffer from a task.
|
|
||||||
* Use xStreamBufferReceiveFromISR() to read bytes from a stream buffer from an
|
|
||||||
* interrupt service routine (ISR).
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer from which a stream
|
|
||||||
* is being received.
|
|
||||||
*
|
|
||||||
* @param pvRxData A pointer to the buffer into which the received bytes are
|
|
||||||
* copied.
|
|
||||||
*
|
|
||||||
* @param xBufferLengthBytes The length of the buffer pointed to by the
|
|
||||||
* pvRxData parameter. This sets the maximum number of bytes to receive in one
|
|
||||||
* call. xStreamBufferReceive will return as many bytes as possible up to a
|
|
||||||
* maximum set by xBufferLengthBytes.
|
|
||||||
*
|
|
||||||
* @param pxHigherPriorityTaskWoken It is possible that a stream buffer will
|
|
||||||
* have a task blocked on it waiting for space to become available. Calling
|
|
||||||
* xStreamBufferReceiveFromISR() can make space available, and so cause a task
|
|
||||||
* that is waiting for space to leave the Blocked state. If calling
|
|
||||||
* xStreamBufferReceiveFromISR() causes a task to leave the Blocked state, and
|
|
||||||
* the unblocked task has a priority higher than the currently executing task
|
|
||||||
* (the task that was interrupted), then, internally,
|
|
||||||
* xStreamBufferReceiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE.
|
|
||||||
* If xStreamBufferReceiveFromISR() sets this value to pdTRUE, then normally a
|
|
||||||
* context switch should be performed before the interrupt is exited. That will
|
|
||||||
* ensure the interrupt returns directly to the highest priority Ready state
|
|
||||||
* task. *pxHigherPriorityTaskWoken should be set to pdFALSE before it is
|
|
||||||
* passed into the function. See the code example below for an example.
|
|
||||||
*
|
|
||||||
* @return The number of bytes read from the stream buffer, if any.
|
|
||||||
*
|
|
||||||
* Example use:
|
|
||||||
<pre>
|
|
||||||
// A stream buffer that has already been created.
|
|
||||||
StreamBuffer_t xStreamBuffer;
|
|
||||||
|
|
||||||
void vAnInterruptServiceRoutine( void )
|
|
||||||
{
|
|
||||||
uint8_t ucRxData[ 20 ];
|
|
||||||
size_t xReceivedBytes;
|
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.
|
|
||||||
|
|
||||||
// Receive the next stream from the stream buffer.
|
|
||||||
xReceivedBytes = xStreamBufferReceiveFromISR( xStreamBuffer,
|
|
||||||
( void * ) ucRxData,
|
|
||||||
sizeof( ucRxData ),
|
|
||||||
&xHigherPriorityTaskWoken );
|
|
||||||
|
|
||||||
if( xReceivedBytes > 0 )
|
|
||||||
{
|
|
||||||
// ucRxData contains xReceivedBytes read from the stream buffer.
|
|
||||||
// Process the stream here....
|
|
||||||
}
|
|
||||||
|
|
||||||
// If xHigherPriorityTaskWoken was set to pdTRUE inside
|
|
||||||
// xStreamBufferReceiveFromISR() then a task that has a priority above the
|
|
||||||
// priority of the currently executing task was unblocked and a context
|
|
||||||
// switch should be performed to ensure the ISR returns to the unblocked
|
|
||||||
// task. In most FreeRTOS ports this is done by simply passing
|
|
||||||
// xHigherPriorityTaskWoken into taskYIELD_FROM_ISR(), which will test the
|
|
||||||
// variables value, and perform the context switch if necessary. Check the
|
|
||||||
// documentation for the port in use for port specific instructions.
|
|
||||||
taskYIELD_FROM_ISR( xHigherPriorityTaskWoken );
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
* \defgroup xStreamBufferReceiveFromISR xStreamBufferReceiveFromISR
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
size_t xStreamBufferReceiveFromISR( StreamBufferHandle_t xStreamBuffer,
|
|
||||||
void *pvRxData,
|
|
||||||
size_t xBufferLengthBytes,
|
|
||||||
BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Deletes a stream buffer that was previously created using a call to
|
|
||||||
* xStreamBufferCreate() or xStreamBufferCreateStatic(). If the stream
|
|
||||||
* buffer was created using dynamic memory (that is, by xStreamBufferCreate()),
|
|
||||||
* then the allocated memory is freed.
|
|
||||||
*
|
|
||||||
* A stream buffer handle must not be used after the stream buffer has been
|
|
||||||
* deleted.
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer to be deleted.
|
|
||||||
*
|
|
||||||
* \defgroup vStreamBufferDelete vStreamBufferDelete
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Queries a stream buffer to see if it is full. A stream buffer is full if it
|
|
||||||
* does not have any free space, and therefore cannot accept any more data.
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer being queried.
|
|
||||||
*
|
|
||||||
* @return If the stream buffer is full then pdTRUE is returned. Otherwise
|
|
||||||
* pdFALSE is returned.
|
|
||||||
*
|
|
||||||
* \defgroup xStreamBufferIsFull xStreamBufferIsFull
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
BaseType_t xStreamBufferIsFull( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Queries a stream buffer to see if it is empty. A stream buffer is empty if
|
|
||||||
* it does not contain any data.
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer being queried.
|
|
||||||
*
|
|
||||||
* @return If the stream buffer is empty then pdTRUE is returned. Otherwise
|
|
||||||
* pdFALSE is returned.
|
|
||||||
*
|
|
||||||
* \defgroup xStreamBufferIsEmpty xStreamBufferIsEmpty
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
BaseType_t xStreamBufferIsEmpty( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Resets a stream buffer to its initial, empty, state. Any data that was in
|
|
||||||
* the stream buffer is discarded. A stream buffer can only be reset if there
|
|
||||||
* are no tasks blocked waiting to either send to or receive from the stream
|
|
||||||
* buffer.
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer being reset.
|
|
||||||
*
|
|
||||||
* @return If the stream buffer is reset then pdPASS is returned. If there was
|
|
||||||
* a task blocked waiting to send to or read from the stream buffer then the
|
|
||||||
* stream buffer is not reset and pdFAIL is returned.
|
|
||||||
*
|
|
||||||
* \defgroup xStreamBufferReset xStreamBufferReset
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
BaseType_t xStreamBufferReset( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Queries a stream buffer to see how much free space it contains, which is
|
|
||||||
* equal to the amount of data that can be sent to the stream buffer before it
|
|
||||||
* is full.
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer being queried.
|
|
||||||
*
|
|
||||||
* @return The number of bytes that can be written to the stream buffer before
|
|
||||||
* the stream buffer would be full.
|
|
||||||
*
|
|
||||||
* \defgroup xStreamBufferSpacesAvailable xStreamBufferSpacesAvailable
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
size_t xStreamBufferSpacesAvailable( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* Queries a stream buffer to see how much data it contains, which is equal to
|
|
||||||
* the number of bytes that can be read from the stream buffer before the stream
|
|
||||||
* buffer would be empty.
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer being queried.
|
|
||||||
*
|
|
||||||
* @return The number of bytes that can be read from the stream buffer before
|
|
||||||
* the stream buffer would be empty.
|
|
||||||
*
|
|
||||||
* \defgroup xStreamBufferBytesAvailable xStreamBufferBytesAvailable
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
size_t xStreamBufferBytesAvailable( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* A stream buffer's trigger level is the number of bytes that must be in the
|
|
||||||
* stream buffer before a task that is blocked on the stream buffer to
|
|
||||||
* wait for data is moved out of the blocked state. For example, if a task is
|
|
||||||
* blocked on a read of an empty stream buffer that has a trigger level of 1
|
|
||||||
* then the task will be unblocked when a single byte is written to the buffer
|
|
||||||
* or the task's block time expires. As another example, if a task is blocked
|
|
||||||
* on a read of an empty stream buffer that has a trigger level of 10 then the
|
|
||||||
* task will not be unblocked until the stream buffer contains at least 10 bytes
|
|
||||||
* or the task's block time expires. If a reading task's block time expires
|
|
||||||
* before the trigger level is reached then the task will still receive however
|
|
||||||
* many bytes are actually available. Setting a trigger level of 0 will result
|
|
||||||
* in a trigger level of 1 being used. It is not valid to specify a trigger
|
|
||||||
* level that is greater than the buffer size.
|
|
||||||
*
|
|
||||||
* A trigger level is set when the stream buffer is created, and can be modified
|
|
||||||
* using xStreamBufferSetTriggerLevel().
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer being updated.
|
|
||||||
*
|
|
||||||
* @param xTriggerLevel The new trigger level for the stream buffer.
|
|
||||||
*
|
|
||||||
* @return If xTriggerLevel was less than or equal to the stream buffer's length
|
|
||||||
* then the trigger level will be updated and pdTRUE is returned. Otherwise
|
|
||||||
* pdFALSE is returned.
|
|
||||||
*
|
|
||||||
* \defgroup xStreamBufferSetTriggerLevel xStreamBufferSetTriggerLevel
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
BaseType_t xStreamBufferSetTriggerLevel( StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevel ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* For advanced users only.
|
|
||||||
*
|
|
||||||
* The sbSEND_COMPLETED() macro is called from within the FreeRTOS APIs when
|
|
||||||
* data is sent to a message buffer or stream buffer. If there was a task that
|
|
||||||
* was blocked on the message or stream buffer waiting for data to arrive then
|
|
||||||
* the sbSEND_COMPLETED() macro sends a notification to the task to remove it
|
|
||||||
* from the Blocked state. xStreamBufferSendCompletedFromISR() does the same
|
|
||||||
* thing. It is provided to enable application writers to implement their own
|
|
||||||
* version of sbSEND_COMPLETED(), and MUST NOT BE USED AT ANY OTHER TIME.
|
|
||||||
*
|
|
||||||
* See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
|
|
||||||
* additional information.
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer to which data was
|
|
||||||
* written.
|
|
||||||
*
|
|
||||||
* @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
|
|
||||||
* initialised to pdFALSE before it is passed into
|
|
||||||
* xStreamBufferSendCompletedFromISR(). If calling
|
|
||||||
* xStreamBufferSendCompletedFromISR() removes a task from the Blocked state,
|
|
||||||
* and the task has a priority above the priority of the currently running task,
|
|
||||||
* then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
|
|
||||||
* context switch should be performed before exiting the ISR.
|
|
||||||
*
|
|
||||||
* @return If a task was removed from the Blocked state then pdTRUE is returned.
|
|
||||||
* Otherwise pdFALSE is returned.
|
|
||||||
*
|
|
||||||
* \defgroup xStreamBufferSendCompletedFromISR xStreamBufferSendCompletedFromISR
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
BaseType_t xStreamBufferSendCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stream_buffer.h
|
|
||||||
*
|
|
||||||
<pre>
|
|
||||||
BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken );
|
|
||||||
</pre>
|
|
||||||
*
|
|
||||||
* For advanced users only.
|
|
||||||
*
|
|
||||||
* The sbRECEIVE_COMPLETED() macro is called from within the FreeRTOS APIs when
|
|
||||||
* data is read out of a message buffer or stream buffer. If there was a task
|
|
||||||
* that was blocked on the message or stream buffer waiting for data to arrive
|
|
||||||
* then the sbRECEIVE_COMPLETED() macro sends a notification to the task to
|
|
||||||
* remove it from the Blocked state. xStreamBufferReceiveCompletedFromISR()
|
|
||||||
* does the same thing. It is provided to enable application writers to
|
|
||||||
* implement their own version of sbRECEIVE_COMPLETED(), and MUST NOT BE USED AT
|
|
||||||
* ANY OTHER TIME.
|
|
||||||
*
|
|
||||||
* See the example implemented in FreeRTOS/Demo/Minimal/MessageBufferAMP.c for
|
|
||||||
* additional information.
|
|
||||||
*
|
|
||||||
* @param xStreamBuffer The handle of the stream buffer from which data was
|
|
||||||
* read.
|
|
||||||
*
|
|
||||||
* @param pxHigherPriorityTaskWoken *pxHigherPriorityTaskWoken should be
|
|
||||||
* initialised to pdFALSE before it is passed into
|
|
||||||
* xStreamBufferReceiveCompletedFromISR(). If calling
|
|
||||||
* xStreamBufferReceiveCompletedFromISR() removes a task from the Blocked state,
|
|
||||||
* and the task has a priority above the priority of the currently running task,
|
|
||||||
* then *pxHigherPriorityTaskWoken will get set to pdTRUE indicating that a
|
|
||||||
* context switch should be performed before exiting the ISR.
|
|
||||||
*
|
|
||||||
* @return If a task was removed from the Blocked state then pdTRUE is returned.
|
|
||||||
* Otherwise pdFALSE is returned.
|
|
||||||
*
|
|
||||||
* \defgroup xStreamBufferReceiveCompletedFromISR xStreamBufferReceiveCompletedFromISR
|
|
||||||
* \ingroup StreamBufferManagement
|
|
||||||
*/
|
|
||||||
BaseType_t xStreamBufferReceiveCompletedFromISR( StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
/* Functions below here are not part of the public API. */
|
|
||||||
StreamBufferHandle_t xStreamBufferGenericCreate( size_t xBufferSizeBytes,
|
|
||||||
size_t xTriggerLevelBytes,
|
|
||||||
BaseType_t xIsMessageBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
|
|
||||||
size_t xTriggerLevelBytes,
|
|
||||||
BaseType_t xIsMessageBuffer,
|
|
||||||
uint8_t * const pucStreamBufferStorageArea,
|
|
||||||
StaticStreamBuffer_t * const pxStaticStreamBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
|
|
||||||
#if( configUSE_TRACE_FACILITY == 1 )
|
|
||||||
void vStreamBufferSetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer, UBaseType_t uxStreamBufferNumber ) PRIVILEGED_FUNCTION;
|
|
||||||
UBaseType_t uxStreamBufferGetStreamBufferNumber( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
uint8_t ucStreamBufferGetStreamBufferType( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined( __cplusplus )
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* !defined( STREAM_BUFFER_H ) */
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,29 +1,66 @@
|
||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.2.0
|
FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
***************************************************************************
|
||||||
* the Software without restriction, including without limitation the rights to
|
* *
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* FreeRTOS provides completely free yet professionally developed, *
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* robust, strictly quality controlled, supported, and cross *
|
||||||
* subject to the following conditions:
|
* platform software that has become a de facto standard. *
|
||||||
*
|
* *
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* Help yourself get started quickly and support the FreeRTOS *
|
||||||
* copies or substantial portions of the Software.
|
* project by purchasing a FreeRTOS tutorial book, reference *
|
||||||
*
|
* manual, or both from: http://www.FreeRTOS.org/Documentation *
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* *
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* Thank you! *
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
* *
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
***************************************************************************
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
This file is part of the FreeRTOS distribution.
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
* http://aws.amazon.com/freertos
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
*
|
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
>>! NOTE: The modification to the GPL is included to allow you to distribute
|
||||||
|
>>! a combined work that includes FreeRTOS without being obliged to provide
|
||||||
|
>>! the source code for proprietary components outside of the FreeRTOS
|
||||||
|
>>! kernel.
|
||||||
|
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. Full license text is available from the following
|
||||||
|
link: http://www.freertos.org/a00114.html
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* Having a problem? Start by reading the FAQ "My application does *
|
||||||
|
* not run, what could be wrong?" *
|
||||||
|
* *
|
||||||
|
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||||
|
license and Real Time Engineers Ltd. contact details.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||||
|
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||||
|
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||||
|
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||||
|
licenses offer ticketed support, indemnification and middleware.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||||
|
engineered and independently SIL3 certified version for use in safety and
|
||||||
|
mission critical applications that require provable dependability.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -34,12 +71,12 @@
|
||||||
* PUBLIC LIST API documented in list.h
|
* PUBLIC LIST API documented in list.h
|
||||||
*----------------------------------------------------------*/
|
*----------------------------------------------------------*/
|
||||||
|
|
||||||
void vListInitialise( List_t * const pxList )
|
void vListInitialise( xList * const pxList )
|
||||||
{
|
{
|
||||||
/* The list structure contains a list item which is used to mark the
|
/* The list structure contains a list item which is used to mark the
|
||||||
end of the list. To initialise the list the list end is inserted
|
end of the list. To initialise the list the list end is inserted
|
||||||
as the only list entry. */
|
as the only list entry. */
|
||||||
pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
pxList->pxIndex = ( xListItem * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
||||||
|
|
||||||
/* The list end value is the highest possible value in the list to
|
/* The list end value is the highest possible value in the list to
|
||||||
ensure it remains at the end of the list. */
|
ensure it remains at the end of the list. */
|
||||||
|
@ -47,78 +84,56 @@ void vListInitialise( List_t * const pxList )
|
||||||
|
|
||||||
/* The list end next and previous pointers point to itself so we know
|
/* The list end next and previous pointers point to itself so we know
|
||||||
when the list is empty. */
|
when the list is empty. */
|
||||||
pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
pxList->xListEnd.pxNext = ( xListItem * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
||||||
pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );/*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
pxList->xListEnd.pxPrevious = ( xListItem * ) &( pxList->xListEnd );/*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
|
||||||
|
|
||||||
pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
|
pxList->uxNumberOfItems = ( unsigned portBASE_TYPE ) 0U;
|
||||||
|
|
||||||
/* Write known values into the list if
|
|
||||||
configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
|
|
||||||
listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
|
|
||||||
listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vListInitialiseItem( ListItem_t * const pxItem )
|
void vListInitialiseItem( xListItem * const pxItem )
|
||||||
{
|
{
|
||||||
/* Make sure the list item is not recorded as being on a list. */
|
/* Make sure the list item is not recorded as being on a list. */
|
||||||
pxItem->pxContainer = NULL;
|
pxItem->pvContainer = NULL;
|
||||||
|
|
||||||
/* Write known values into the list item if
|
|
||||||
configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
|
|
||||||
listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
|
|
||||||
listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
|
void IRAM vListInsertEnd( xList * const pxList, xListItem * const pxNewListItem )
|
||||||
{
|
{
|
||||||
ListItem_t * const pxIndex = pxList->pxIndex;
|
xListItem * pxIndex;
|
||||||
|
|
||||||
/* Only effective when configASSERT() is also defined, these tests may catch
|
|
||||||
the list data structures being overwritten in memory. They will not catch
|
|
||||||
data errors caused by incorrect configuration or use of FreeRTOS. */
|
|
||||||
listTEST_LIST_INTEGRITY( pxList );
|
|
||||||
listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
|
|
||||||
|
|
||||||
/* Insert a new list item into pxList, but rather than sort the list,
|
/* Insert a new list item into pxList, but rather than sort the list,
|
||||||
makes the new list item the last item to be removed by a call to
|
makes the new list item the last item to be removed by a call to
|
||||||
listGET_OWNER_OF_NEXT_ENTRY(). */
|
pvListGetOwnerOfNextEntry. */
|
||||||
|
pxIndex = pxList->pxIndex;
|
||||||
|
|
||||||
pxNewListItem->pxNext = pxIndex;
|
pxNewListItem->pxNext = pxIndex;
|
||||||
pxNewListItem->pxPrevious = pxIndex->pxPrevious;
|
pxNewListItem->pxPrevious = pxIndex->pxPrevious;
|
||||||
|
|
||||||
/* Only used during decision coverage testing. */
|
|
||||||
mtCOVERAGE_TEST_DELAY();
|
|
||||||
|
|
||||||
pxIndex->pxPrevious->pxNext = pxNewListItem;
|
pxIndex->pxPrevious->pxNext = pxNewListItem;
|
||||||
pxIndex->pxPrevious = pxNewListItem;
|
pxIndex->pxPrevious = pxNewListItem;
|
||||||
|
|
||||||
/* Remember which list the item is in. */
|
/* Remember which list the item is in. */
|
||||||
pxNewListItem->pxContainer = pxList;
|
pxNewListItem->pvContainer = ( void * ) pxList;
|
||||||
|
|
||||||
( pxList->uxNumberOfItems )++;
|
( pxList->uxNumberOfItems )++;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
|
void IRAM vListInsert( xList * const pxList, xListItem * const pxNewListItem )
|
||||||
{
|
{
|
||||||
ListItem_t *pxIterator;
|
xListItem *pxIterator;
|
||||||
const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
portTickType xValueOfInsertion;
|
||||||
|
|
||||||
/* Only effective when configASSERT() is also defined, these tests may catch
|
/* Insert the new list item into the list, sorted in ulListItem order. */
|
||||||
the list data structures being overwritten in memory. They will not catch
|
xValueOfInsertion = pxNewListItem->xItemValue;
|
||||||
data errors caused by incorrect configuration or use of FreeRTOS. */
|
|
||||||
listTEST_LIST_INTEGRITY( pxList );
|
|
||||||
listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
|
|
||||||
|
|
||||||
/* Insert the new list item into the list, sorted in xItemValue order.
|
/* If the list already contains a list item with the same item value then
|
||||||
|
the new list item should be placed after it. This ensures that TCB's which
|
||||||
If the list already contains a list item with the same item value then the
|
are stored in ready lists (all of which have the same ulListItem value)
|
||||||
new list item should be placed after it. This ensures that TCBs which are
|
get an equal share of the CPU. However, if the xItemValue is the same as
|
||||||
stored in ready lists (all of which have the same xItemValue value) get a
|
the back marker the iteration loop below will not end. This means we need
|
||||||
share of the CPU. However, if the xItemValue is the same as the back marker
|
to guard against this by checking the value first and modifying the
|
||||||
the iteration loop below will not end. Therefore the value is checked
|
algorithm slightly if necessary. */
|
||||||
first, and the algorithm slightly modified if necessary. */
|
|
||||||
if( xValueOfInsertion == portMAX_DELAY )
|
if( xValueOfInsertion == portMAX_DELAY )
|
||||||
{
|
{
|
||||||
pxIterator = pxList->xListEnd.pxPrevious;
|
pxIterator = pxList->xListEnd.pxPrevious;
|
||||||
|
@ -126,31 +141,26 @@ const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* *** NOTE ***********************************************************
|
/* *** NOTE ***********************************************************
|
||||||
If you find your application is crashing here then likely causes are
|
If you find your application is crashing here then likely causes are:
|
||||||
listed below. In addition see https://www.freertos.org/FAQHelp.html for
|
|
||||||
more tips, and ensure configASSERT() is defined!
|
|
||||||
https://www.freertos.org/a00110.html#configASSERT
|
|
||||||
|
|
||||||
1) Stack overflow -
|
1) Stack overflow -
|
||||||
see https://www.freertos.org/Stacks-and-stack-overflow-checking.html
|
see http://www.freertos.org/Stacks-and-stack-overflow-checking.html
|
||||||
2) Incorrect interrupt priority assignment, especially on Cortex-M
|
2) Incorrect interrupt priority assignment, especially on Cortex-M3
|
||||||
parts where numerically high priority values denote low actual
|
parts where numerically high priority values denote low actual
|
||||||
interrupt priorities, which can seem counter intuitive. See
|
interrupt priories, which can seem counter intuitive. See
|
||||||
https://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition
|
configMAX_SYSCALL_INTERRUPT_PRIORITY on http://www.freertos.org/a00110.html
|
||||||
of configMAX_SYSCALL_INTERRUPT_PRIORITY on
|
|
||||||
https://www.freertos.org/a00110.html
|
|
||||||
3) Calling an API function from within a critical section or when
|
3) Calling an API function from within a critical section or when
|
||||||
the scheduler is suspended, or calling an API function that does
|
the scheduler is suspended, or calling an API function that does
|
||||||
not end in "FromISR" from an interrupt.
|
not end in "FromISR" from an interrupt.
|
||||||
4) Using a queue or semaphore before it has been initialised or
|
4) Using a queue or semaphore before it has been initialised or
|
||||||
before the scheduler has been started (are interrupts firing
|
before the scheduler has been started (are interrupts firing
|
||||||
before vTaskStartScheduler() has been called?).
|
before vTaskStartScheduler() has been called?).
|
||||||
|
See http://www.freertos.org/FAQHelp.html for more tips.
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */
|
for( pxIterator = ( xListItem * ) &( 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. */
|
||||||
{
|
{
|
||||||
/* There is nothing to do here, just iterating to the wanted
|
/* There is nothing to do here, we are just iterating to the
|
||||||
insertion position. */
|
wanted insertion position. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,35 +171,30 @@ const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
||||||
|
|
||||||
/* Remember which list the item is in. This allows fast removal of the
|
/* Remember which list the item is in. This allows fast removal of the
|
||||||
item later. */
|
item later. */
|
||||||
pxNewListItem->pxContainer = pxList;
|
pxNewListItem->pvContainer = ( void * ) pxList;
|
||||||
|
|
||||||
( pxList->uxNumberOfItems )++;
|
( pxList->uxNumberOfItems )++;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
|
unsigned portBASE_TYPE IRAM uxListRemove( xListItem * const pxItemToRemove )
|
||||||
{
|
{
|
||||||
/* The list item knows which list it is in. Obtain the list from the list
|
xList * pxList;
|
||||||
item. */
|
|
||||||
List_t * const pxList = pxItemToRemove->pxContainer;
|
|
||||||
|
|
||||||
pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
|
pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
|
||||||
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
|
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
|
||||||
|
|
||||||
/* Only used during decision coverage testing. */
|
/* The list item knows which list it is in. Obtain the list from the list
|
||||||
mtCOVERAGE_TEST_DELAY();
|
item. */
|
||||||
|
pxList = ( xList * ) pxItemToRemove->pvContainer;
|
||||||
|
|
||||||
/* Make sure the index is left pointing to a valid item. */
|
/* Make sure the index is left pointing to a valid item. */
|
||||||
if( pxList->pxIndex == pxItemToRemove )
|
if( pxList->pxIndex == pxItemToRemove )
|
||||||
{
|
{
|
||||||
pxList->pxIndex = pxItemToRemove->pxPrevious;
|
pxList->pxIndex = pxItemToRemove->pxPrevious;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
mtCOVERAGE_TEST_MARKER();
|
|
||||||
}
|
|
||||||
|
|
||||||
pxItemToRemove->pxContainer = NULL;
|
pxItemToRemove->pvContainer = NULL;
|
||||||
( pxList->uxNumberOfItems )--;
|
( pxList->uxNumberOfItems )--;
|
||||||
|
|
||||||
return pxList->uxNumberOfItems;
|
return pxList->uxNumberOfItems;
|
||||||
|
|
|
@ -1,30 +1,66 @@
|
||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.2.0
|
FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
***************************************************************************
|
||||||
* the Software without restriction, including without limitation the rights to
|
* *
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* FreeRTOS provides completely free yet professionally developed, *
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* robust, strictly quality controlled, supported, and cross *
|
||||||
* subject to the following conditions:
|
* platform software that has become a de facto standard. *
|
||||||
*
|
* *
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* Help yourself get started quickly and support the FreeRTOS *
|
||||||
* copies or substantial portions of the Software. If you wish to use our Amazon
|
* project by purchasing a FreeRTOS tutorial book, reference *
|
||||||
* FreeRTOS name, please do so in a fair use way that does not cause confusion.
|
* manual, or both from: http://www.FreeRTOS.org/Documentation *
|
||||||
*
|
* *
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* Thank you! *
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* *
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
***************************************************************************
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
This file is part of the FreeRTOS distribution.
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
* http://www.FreeRTOS.org
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
* http://aws.amazon.com/freertos
|
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||||
*
|
|
||||||
* 1 tab == 4 spaces!
|
>>! NOTE: The modification to the GPL is included to allow you to distribute
|
||||||
*/
|
>>! a combined work that includes FreeRTOS without being obliged to provide
|
||||||
|
>>! the source code for proprietary components outside of the FreeRTOS
|
||||||
|
>>! kernel.
|
||||||
|
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. Full license text is available from the following
|
||||||
|
link: http://www.freertos.org/a00114.html
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* Having a problem? Start by reading the FAQ "My application does *
|
||||||
|
* not run, what could be wrong?" *
|
||||||
|
* *
|
||||||
|
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||||
|
license and Real Time Engineers Ltd. contact details.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||||
|
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||||
|
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||||
|
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||||
|
licenses offer ticketed support, indemnification and middleware.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||||
|
engineered and independently SIL3 certified version for use in safety and
|
||||||
|
mission critical applications that require provable dependability.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
*/
|
||||||
|
|
||||||
/*-----------------------------------------------------------
|
/*-----------------------------------------------------------
|
||||||
* Implementation of functions defined in portable.h for ESP8266
|
* Implementation of functions defined in portable.h for ESP8266
|
||||||
|
@ -37,43 +73,32 @@
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <xtensa_ops.h>
|
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "queue.h"
|
|
||||||
#include "xtensa_rtos.h"
|
#include "xtensa_rtos.h"
|
||||||
|
|
||||||
unsigned cpu_sr;
|
unsigned cpu_sr;
|
||||||
char level1_int_disabled;
|
char level1_int_disabled;
|
||||||
|
|
||||||
/* Supervisor stack pointer entry. This is the "high water mark" of
|
/* Supervisor stack pointer entry. This is the "high water mark" of how far the
|
||||||
how far the supervisor stack grew down before task started. Is zero
|
supervisor stack grew down before task started.
|
||||||
before the scheduler starts.
|
|
||||||
|
|
||||||
After the scheduler starts, task stacks are all allocated from the
|
After tasks start, task stacks are all allocated from the heap and
|
||||||
heap and FreeRTOS checks for stack overflow.
|
FreeRTOS checks for stack overflow.
|
||||||
*/
|
*/
|
||||||
void *xPortSupervisorStackPointer;
|
static uint32_t xPortSupervisorStackPointer;
|
||||||
|
|
||||||
void vAssertCalled(const char * pcFile, unsigned long ulLine)
|
|
||||||
{
|
|
||||||
printf("rtos assert %s %lu\n", pcFile, ulLine);
|
|
||||||
abort();
|
|
||||||
//for (;;);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stack initialization
|
* Stack initialization
|
||||||
*/
|
*/
|
||||||
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
|
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
|
||||||
{
|
{
|
||||||
#define SET_STKREG(r,v) sp[(r) >> 2] = (portSTACK_TYPE)(v)
|
#define SET_STKREG(r,v) sp[(r) >> 2] = (portSTACK_TYPE)(v)
|
||||||
portSTACK_TYPE *sp, *tp;
|
portSTACK_TYPE *sp, *tp;
|
||||||
|
|
||||||
/* Create interrupt stack frame aligned to 16 byte boundary */
|
/* Create interrupt stack frame aligned to 16 byte boundary */
|
||||||
sp = (portSTACK_TYPE*) (((uint32_t)(pxTopOfStack + 1) - XT_CP_SIZE - XT_STK_FRMSZ) & ~0xf);
|
sp = (portSTACK_TYPE*) (((uint32_t)(pxTopOfStack+1) - XT_CP_SIZE - XT_STK_FRMSZ) & ~0xf);
|
||||||
|
|
||||||
/* Clear the entire frame (do not use memset() because we don't depend on C library) */
|
/* Clear the entire frame (do not use memset() because we don't depend on C library) */
|
||||||
for (tp = sp; tp <= pxTopOfStack; ++tp)
|
for (tp = sp; tp <= pxTopOfStack; ++tp)
|
||||||
|
@ -94,29 +119,30 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, TaskFunctio
|
||||||
static int pending_soft_sv;
|
static int pending_soft_sv;
|
||||||
static int pending_maclayer_sv;
|
static int pending_maclayer_sv;
|
||||||
|
|
||||||
/*
|
/* PendSV is called in place of vPortYield() to request a supervisor
|
||||||
* The portYIELD macro calls PendSV with SVC_Software to set a pending interrupt
|
call.
|
||||||
* service callback that allows a task switch, and this occur when interrupts
|
|
||||||
* are enabled which might be after exiting the critical region below.
|
The portYIELD macro calls pendSV if it's a software request.
|
||||||
*
|
|
||||||
* The wdev NMI calls this function from pp_post() with SVC_MACLayer to set a
|
The libpp and libudhcp libraries also call this function, assuming
|
||||||
* pending interrupt service callback which flushs the queue of messages that
|
always with arg==2 (but maybe sometimes with arg==1?)
|
||||||
* the NMI stashes away. This interrupt will be triggered after the return from
|
|
||||||
* the NMI and when interrupts are enabled. The NMI can not touch the FreeRTOS
|
In the original esp_iot_rtos_sdk implementation, arg was a char. Using an
|
||||||
* queues itself. The NMI must not touch the interrupt masks so that path must
|
enum is ABI-compatible, though.
|
||||||
* not call vPortEnterCritical and vPortExitCritical.
|
*/
|
||||||
*/
|
|
||||||
void IRAM PendSV(enum SVC_ReqType req)
|
void IRAM PendSV(enum SVC_ReqType req)
|
||||||
{
|
{
|
||||||
if (req == SVC_Software) {
|
vPortEnterCritical();
|
||||||
vPortEnterCritical();
|
|
||||||
pending_soft_sv = 1;
|
if(req == SVC_Software)
|
||||||
WSR(BIT(INUM_SOFT), interrupt);
|
{
|
||||||
vPortExitCritical();
|
pending_soft_sv = 1;
|
||||||
} else if (req == SVC_MACLayer) {
|
}
|
||||||
pending_maclayer_sv= 1;
|
else if(req == SVC_MACLayer)
|
||||||
WSR(BIT(INUM_SOFT), interrupt);
|
pending_maclayer_sv= 1;
|
||||||
}
|
|
||||||
|
xthal_set_intset(BIT(INUM_SOFT));
|
||||||
|
vPortExitCritical();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This MAC layer ISR handler is defined in libpp.a, and is called
|
/* This MAC layer ISR handler is defined in libpp.a, and is called
|
||||||
|
@ -125,37 +151,53 @@ void IRAM PendSV(enum SVC_ReqType req)
|
||||||
*/
|
*/
|
||||||
extern portBASE_TYPE sdk_MacIsrSigPostDefHdl(void);
|
extern portBASE_TYPE sdk_MacIsrSigPostDefHdl(void);
|
||||||
|
|
||||||
void IRAM SV_ISR(void *arg)
|
void IRAM SV_ISR(void)
|
||||||
{
|
{
|
||||||
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE ;
|
portBASE_TYPE xHigherPriorityTaskWoken=pdFALSE ;
|
||||||
if (pending_maclayer_sv) {
|
if(pending_maclayer_sv)
|
||||||
xHigherPriorityTaskWoken = sdk_MacIsrSigPostDefHdl();
|
{
|
||||||
pending_maclayer_sv = 0;
|
xHigherPriorityTaskWoken = sdk_MacIsrSigPostDefHdl();
|
||||||
}
|
pending_maclayer_sv = 0;
|
||||||
if (xHigherPriorityTaskWoken || pending_soft_sv) {
|
}
|
||||||
sdk__xt_timer_int1();
|
if( xHigherPriorityTaskWoken || pending_soft_sv)
|
||||||
pending_soft_sv = 0;
|
{
|
||||||
}
|
sdk__xt_timer_int1();
|
||||||
|
pending_soft_sv = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void xPortSysTickHandle (void)
|
void xPortSysTickHandle (void)
|
||||||
{
|
{
|
||||||
if (xTaskIncrementTick() != pdFALSE) {
|
//CloseNMI();
|
||||||
vTaskSwitchContext();
|
{
|
||||||
}
|
if(xTaskIncrementTick() !=pdFALSE )
|
||||||
|
{
|
||||||
|
vTaskSwitchContext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//OpenNMI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool sdk_compat_initialised;
|
||||||
|
void sdk_compat_initialise(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* See header file for description.
|
* See header file for description.
|
||||||
*/
|
*/
|
||||||
portBASE_TYPE xPortStartScheduler( void )
|
portBASE_TYPE xPortStartScheduler( void )
|
||||||
{
|
{
|
||||||
_xt_isr_attach(INUM_SOFT, SV_ISR, NULL);
|
_xt_isr_attach(INUM_SOFT, SV_ISR);
|
||||||
_xt_isr_unmask(BIT(INUM_SOFT));
|
_xt_isr_unmask(BIT(INUM_SOFT));
|
||||||
|
|
||||||
|
/* ENORMOUS HACK: Call the sdk_compat_initialise() function.
|
||||||
|
This can be removed happily once we have open source startup code.
|
||||||
|
*/
|
||||||
|
if(!sdk_compat_initialised) {
|
||||||
|
sdk_compat_initialised = true;
|
||||||
|
sdk_compat_initialise();
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize system tick timer interrupt and schedule the first tick. */
|
/* Initialize system tick timer interrupt and schedule the first tick. */
|
||||||
_xt_isr_attach(INUM_TICK, sdk__xt_timer_int, NULL);
|
|
||||||
_xt_isr_unmask(BIT(INUM_TICK));
|
|
||||||
sdk__xt_tick_timer_init();
|
sdk__xt_tick_timer_init();
|
||||||
|
|
||||||
vTaskSwitchContext();
|
vTaskSwitchContext();
|
||||||
|
@ -185,11 +227,9 @@ size_t xPortGetFreeHeapSize( void )
|
||||||
struct mallinfo mi = mallinfo();
|
struct mallinfo mi = mallinfo();
|
||||||
uint32_t brk_val = (uint32_t) sbrk(0);
|
uint32_t brk_val = (uint32_t) sbrk(0);
|
||||||
|
|
||||||
intptr_t sp = (intptr_t)xPortSupervisorStackPointer;
|
uint32_t sp = xPortSupervisorStackPointer;
|
||||||
if (sp == 0) {
|
if(sp == 0) /* scheduler not started */
|
||||||
/* scheduler not started */
|
__asm__ __volatile__ ("mov %0, a1\n" : "=a"(sp));
|
||||||
SP(sp);
|
|
||||||
}
|
|
||||||
return sp - brk_val + mi.fordblks;
|
return sp - brk_val + mi.fordblks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,6 +240,8 @@ void vPortEndScheduler( void )
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each task maintains its own interrupt status in the critical nesting
|
||||||
|
variable. */
|
||||||
static unsigned portBASE_TYPE uxCriticalNesting = 0;
|
static unsigned portBASE_TYPE uxCriticalNesting = 0;
|
||||||
|
|
||||||
/* These nested vPortEnter/ExitCritical macros are called by SDK
|
/* These nested vPortEnter/ExitCritical macros are called by SDK
|
||||||
|
@ -208,42 +250,75 @@ static unsigned portBASE_TYPE uxCriticalNesting = 0;
|
||||||
* It may be possible to replace the global nesting count variable
|
* It may be possible to replace the global nesting count variable
|
||||||
* with a save/restore of interrupt level, although it's difficult as
|
* with a save/restore of interrupt level, although it's difficult as
|
||||||
* the functions have no return value.
|
* the functions have no return value.
|
||||||
*
|
|
||||||
* These should not be called from the NMI in regular operation and
|
|
||||||
* the NMI must not touch the interrupt mask, but that might occur in
|
|
||||||
* exceptional paths such as aborts and debug code.
|
|
||||||
*/
|
*/
|
||||||
void IRAM vPortEnterCritical(void) {
|
void IRAM vPortEnterCritical( void )
|
||||||
|
{
|
||||||
portDISABLE_INTERRUPTS();
|
portDISABLE_INTERRUPTS();
|
||||||
uxCriticalNesting++;
|
uxCriticalNesting++;
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void IRAM vPortExitCritical( void )
|
||||||
|
{
|
||||||
|
uxCriticalNesting--;
|
||||||
|
if( uxCriticalNesting == 0 )
|
||||||
|
portENABLE_INTERRUPTS();
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
void IRAM vPortExitCritical(void) {
|
/* Main ISR handler for FreeRTOS side of the ESP libs?
|
||||||
uxCriticalNesting--;
|
|
||||||
if (uxCriticalNesting == 0)
|
As far as I can tell, the "real" Xtensa ISRs ("Exceptions") are
|
||||||
portENABLE_INTERRUPTS();
|
handled in libmain.a (xtensa_vectors.o) which then can call into here
|
||||||
|
passing an interrupt mask.
|
||||||
|
*/
|
||||||
|
|
||||||
|
_xt_isr isr[16];
|
||||||
|
|
||||||
|
void IRAM _xt_isr_attach(uint8_t i, _xt_isr func)
|
||||||
|
{
|
||||||
|
isr[i] = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Backward compatibility, for the sdk library. */
|
uint16_t IRAM _xt_isr_handler(uint16_t i)
|
||||||
|
{
|
||||||
|
uint8_t index;
|
||||||
|
|
||||||
signed portBASE_TYPE xTaskGenericCreate(TaskFunction_t pxTaskCode,
|
/* I think this is implementing some kind of interrupt priority or
|
||||||
const signed char * const pcName,
|
short-circuiting an expensive ffs for most common interrupts - ie
|
||||||
unsigned short usStackDepth,
|
WDT And GPIO are common or high priority, then remaining flags.
|
||||||
void *pvParameters,
|
*/
|
||||||
unsigned portBASE_TYPE uxPriority,
|
if (i & (1 << INUM_WDT)) {
|
||||||
TaskHandle_t *pxCreatedTask,
|
index = INUM_WDT;
|
||||||
portSTACK_TYPE *puxStackBuffer,
|
}
|
||||||
const MemoryRegion_t * const xRegions) {
|
else if (i & (1 << INUM_GPIO)) {
|
||||||
(void)puxStackBuffer;
|
index = INUM_GPIO;
|
||||||
(void)xRegions;
|
}else {
|
||||||
return xTaskCreate(pxTaskCode, (const char * const)pcName, usStackDepth,
|
index = __builtin_ffs(i) - 1;
|
||||||
pvParameters, uxPriority, pxCreatedTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseType_t xQueueGenericReceive(QueueHandle_t xQueue, void * const pvBuffer,
|
if (index == INUM_MAX) {
|
||||||
TickType_t xTicksToWait, const BaseType_t xJustPeeking) {
|
/* I don't understand what happens here. INUM_MAX is not
|
||||||
configASSERT(xJustPeeking == 0);
|
the highest interrupt number listed (and the isr array
|
||||||
return xQueueReceive(xQueue, pvBuffer, xTicksToWait);
|
has 16 entries).
|
||||||
|
|
||||||
|
Clearing that flag and then setting index to
|
||||||
|
__builtin_ffs(i)-1 may result in index == 255 if no
|
||||||
|
higher flags are set, unless this is guarded against
|
||||||
|
somehow by the caller?
|
||||||
|
|
||||||
|
I also don't understand why the code is written like
|
||||||
|
this in esp_iot_rtos_sdk instead of just putting the i
|
||||||
|
&= line near the top... Probably no good reason?
|
||||||
|
*/
|
||||||
|
i &= ~(1 << INUM_MAX);
|
||||||
|
index = __builtin_ffs(i) - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_xt_clear_ints(1<<index);
|
||||||
|
|
||||||
|
isr[index]();
|
||||||
|
|
||||||
|
return i & ~(1 << index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,67 @@
|
||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.2.0
|
FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
|
||||||
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
***************************************************************************
|
||||||
* the Software without restriction, including without limitation the rights to
|
* *
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
* FreeRTOS provides completely free yet professionally developed, *
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
* robust, strictly quality controlled, supported, and cross *
|
||||||
* subject to the following conditions:
|
* platform software that has become a de facto standard. *
|
||||||
*
|
* *
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* Help yourself get started quickly and support the FreeRTOS *
|
||||||
* copies or substantial portions of the Software. If you wish to use our Amazon
|
* project by purchasing a FreeRTOS tutorial book, reference *
|
||||||
* FreeRTOS name, please do so in a fair use way that does not cause confusion.
|
* manual, or both from: http://www.FreeRTOS.org/Documentation *
|
||||||
*
|
* *
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* Thank you! *
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
* *
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
***************************************************************************
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
This file is part of the FreeRTOS distribution.
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
||||||
* http://www.FreeRTOS.org
|
the terms of the GNU General Public License (version 2) as published by the
|
||||||
* http://aws.amazon.com/freertos
|
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
|
||||||
*
|
|
||||||
* 1 tab == 4 spaces!
|
>>! NOTE: The modification to the GPL is included to allow you to distribute
|
||||||
*/
|
>>! a combined work that includes FreeRTOS without being obliged to provide
|
||||||
|
>>! the source code for proprietary components outside of the FreeRTOS
|
||||||
|
>>! kernel.
|
||||||
|
|
||||||
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. Full license text is available from the following
|
||||||
|
link: http://www.freertos.org/a00114.html
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
|
||||||
|
***************************************************************************
|
||||||
|
* *
|
||||||
|
* Having a problem? Start by reading the FAQ "My application does *
|
||||||
|
* not run, what could be wrong?" *
|
||||||
|
* *
|
||||||
|
* http://www.FreeRTOS.org/FAQHelp.html *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
|
||||||
|
license and Real Time Engineers Ltd. contact details.
|
||||||
|
|
||||||
|
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
|
||||||
|
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
|
||||||
|
compatible FAT file system, and our tiny thread aware UDP/IP stack.
|
||||||
|
|
||||||
|
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
|
||||||
|
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
|
||||||
|
licenses offer ticketed support, indemnification and middleware.
|
||||||
|
|
||||||
|
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
|
||||||
|
engineered and independently SIL3 certified version for use in safety and
|
||||||
|
mission critical applications that require provable dependability.
|
||||||
|
|
||||||
|
1 tab == 4 spaces!
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef PORTMACRO_H
|
#ifndef PORTMACRO_H
|
||||||
#define PORTMACRO_H
|
#define PORTMACRO_H
|
||||||
|
@ -36,8 +73,8 @@ extern "C" {
|
||||||
#include "esp8266.h"
|
#include "esp8266.h"
|
||||||
#include "espressif/esp8266/ets_sys.h"
|
#include "espressif/esp8266/ets_sys.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "xtensa_rtos.h"
|
#include "xtensa_rtos.h"
|
||||||
#include <esp/interrupts.h>
|
#include "xtensa_interrupts.h"
|
||||||
|
|
||||||
/*-----------------------------------------------------------
|
/*-----------------------------------------------------------
|
||||||
* Port specific definitions for ESP8266
|
* Port specific definitions for ESP8266
|
||||||
|
@ -55,20 +92,15 @@ extern "C" {
|
||||||
#define portDOUBLE double
|
#define portDOUBLE double
|
||||||
#define portLONG long
|
#define portLONG long
|
||||||
#define portSHORT short
|
#define portSHORT short
|
||||||
#define portSTACK_TYPE uint32_t
|
#define portSTACK_TYPE unsigned portLONG
|
||||||
#define portBASE_TYPE long
|
#define portBASE_TYPE long
|
||||||
|
|
||||||
typedef portSTACK_TYPE StackType_t;
|
typedef uint32_t portTickType;
|
||||||
typedef portBASE_TYPE BaseType_t;
|
#define portMAX_DELAY ( portTickType ) 0xffffffff
|
||||||
typedef unsigned portBASE_TYPE UBaseType_t;
|
|
||||||
|
|
||||||
typedef uint32_t TickType_t;
|
|
||||||
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
|
|
||||||
|
|
||||||
/* Architecture specifics. */
|
/* Architecture specifics. */
|
||||||
#define portARCH_NAME "ESP8266"
|
|
||||||
#define portSTACK_GROWTH ( -1 )
|
#define portSTACK_GROWTH ( -1 )
|
||||||
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
|
#define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ )
|
||||||
#define portBYTE_ALIGNMENT 8
|
#define portBYTE_ALIGNMENT 8
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -107,7 +139,7 @@ void PendSV(enum SVC_ReqType);
|
||||||
ESPTODO: It may be possible to just read the 'ps' register instead
|
ESPTODO: It may be possible to just read the 'ps' register instead
|
||||||
of accessing thisvariable.
|
of accessing thisvariable.
|
||||||
*/
|
*/
|
||||||
extern uint8_t sdk_NMIIrqIsOn;
|
extern char sdk_NMIIrqIsOn;
|
||||||
extern char level1_int_disabled;
|
extern char level1_int_disabled;
|
||||||
extern unsigned cpu_sr;
|
extern unsigned cpu_sr;
|
||||||
|
|
||||||
|
@ -119,9 +151,6 @@ extern unsigned cpu_sr;
|
||||||
prefer to _xt_disable_interrupts & _xt_enable_interrupts and store
|
prefer to _xt_disable_interrupts & _xt_enable_interrupts and store
|
||||||
the ps value in a local variable - that approach is recursive-safe
|
the ps value in a local variable - that approach is recursive-safe
|
||||||
and generally better.
|
and generally better.
|
||||||
|
|
||||||
The NMI must not touch the interrupt mask and it should not in
|
|
||||||
regular operation, but there is a guard here just in case.
|
|
||||||
*/
|
*/
|
||||||
inline static __attribute__((always_inline)) void portDISABLE_INTERRUPTS(void)
|
inline static __attribute__((always_inline)) void portDISABLE_INTERRUPTS(void)
|
||||||
{
|
{
|
||||||
|
@ -151,10 +180,6 @@ not necessary for to use this port. They are defined so the common demo files
|
||||||
(which build with all the ports) will build. */
|
(which build with all the ports) will build. */
|
||||||
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
|
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
|
||||||
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
|
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
|
||||||
|
|
||||||
/* FreeRTOS API functions should not be called from the NMI handler. */
|
|
||||||
#define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() configASSERT(sdk_NMIIrqIsOn == 0)
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
Each real time kernel port consists of three files that contain the core kernel
|
|
||||||
components and are common to every port, and one or more files that are
|
|
||||||
specific to a particular microcontroller and/or compiler.
|
|
||||||
|
|
||||||
|
|
||||||
+ The FreeRTOS/Source/Portable/MemMang directory contains the five sample
|
|
||||||
memory allocators as described on the http://www.FreeRTOS.org WEB site.
|
|
||||||
|
|
||||||
+ The other directories each contain files specific to a particular
|
|
||||||
microcontroller or compiler, where the directory name denotes the compiler
|
|
||||||
specific files the directory contains.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
For example, if you are interested in the [compiler] port for the [architecture]
|
|
||||||
microcontroller, then the port specific files are contained in
|
|
||||||
FreeRTOS/Source/Portable/[compiler]/[architecture] directory. If this is the
|
|
||||||
only port you are interested in then all the other directories can be
|
|
||||||
ignored.
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
21
FreeRTOS/readme.txt
Normal file
21
FreeRTOS/readme.txt
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
Directories:
|
||||||
|
|
||||||
|
+ The FreeRTOS/Source directory contains the FreeRTOS source code, and contains
|
||||||
|
its own readme file.
|
||||||
|
|
||||||
|
+ The FreeRTOS/Demo directory contains a demo application for every official
|
||||||
|
FreeRTOS port, and contains its own readme file.
|
||||||
|
|
||||||
|
+ See http://www.freertos.org/a00017.html for full details of the directory
|
||||||
|
structure and information on locating the files you require.
|
||||||
|
|
||||||
|
The easiest way to use FreeRTOS is to start with one of the pre-configured demo
|
||||||
|
application projects (found in the FreeRTOS/Demo directory). That way you will
|
||||||
|
have the correct FreeRTOS source files included, and the correct include paths
|
||||||
|
configured. Once a demo application is building and executing you can remove
|
||||||
|
the demo application file, and start to add in your own application source
|
||||||
|
files.
|
||||||
|
|
||||||
|
See also -
|
||||||
|
http://www.freertos.org/FreeRTOS-quick-start-guide.html
|
||||||
|
http://www.freertos.org/FAQHelp.html
|
44
README.md
44
README.md
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
A community developed open source [FreeRTOS](http://www.freertos.org/)-based framework for ESP8266 WiFi-enabled microcontrollers. Intended for use in both commercial and open source projects.
|
A community developed open source [FreeRTOS](http://www.freertos.org/)-based framework for ESP8266 WiFi-enabled microcontrollers. Intended for use in both commercial and open source projects.
|
||||||
|
|
||||||
Originally based on, but substantially different from, the [Espressif IOT RTOS SDK](https://github.com/espressif/ESP8266_RTOS_SDK).
|
Originally based on, but substantially different from, the [Espressif IOT RTOS SDK](https://github.com/espressif/esp_iot_rtos_sdk).
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
|
|
||||||
|
@ -10,15 +10,13 @@ Originally based on, but substantially different from, the [Espressif IOT RTOS S
|
||||||
|
|
||||||
Email discussion list: https://groups.google.com/d/forum/esp-open-rtos
|
Email discussion list: https://groups.google.com/d/forum/esp-open-rtos
|
||||||
|
|
||||||
IRC channel: #esp-open-rtos on Freenode ([Web Chat Link](http://webchat.freenode.net/?channels=%23esp-open-rtos&uio=d4)).
|
Github issues list/bugtracker: http://github.com/superhouse/esp-open-rtos/issues
|
||||||
|
|
||||||
Github issues list/bugtracker: https://github.com/superhouse/esp-open-rtos/issues
|
|
||||||
|
|
||||||
Please note that this project is released with a [Contributor Code of Conduct](https://github.com/SuperHouse/esp-open-rtos/blob/master/code_of_conduct.md). By participating in this project you agree to abide by its terms.
|
Please note that this project is released with a [Contributor Code of Conduct](https://github.com/SuperHouse/esp-open-rtos/blob/master/code_of_conduct.md). By participating in this project you agree to abide by its terms.
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
* Install [esp-open-sdk](https://github.com/pfalcon/esp-open-sdk/), build it with `make toolchain esptool libhal STANDALONE=n`, then edit your PATH and add the generated toolchain `bin` directory. The path will be something like `/path/to/esp-open-sdk/xtensa-lx106-elf/bin`. (Despite the similar name esp-open-sdk has different maintainers - but we think it's fantastic!)
|
* Install [esp-open-sdk](https://github.com/pfalcon/esp-open-sdk/), build it with `make STANDALONE=n`, then edit your PATH and add the generated toolchain `bin` directory. (Despite the similar name esp-open-sdk has different maintainers - but we think it's fantastic!)
|
||||||
|
|
||||||
(Other toolchains may also work, as long as a gcc cross-compiler is available on the PATH and libhal (and libhal headers) are compiled and available to gcc. The proprietary Tensilica "xcc" compiler will probably not work.)
|
(Other toolchains may also work, as long as a gcc cross-compiler is available on the PATH and libhal (and libhal headers) are compiled and available to gcc. The proprietary Tensilica "xcc" compiler will probably not work.)
|
||||||
|
|
||||||
|
@ -33,13 +31,15 @@ git clone --recursive https://github.com/Superhouse/esp-open-rtos.git
|
||||||
cd esp-open-rtos
|
cd esp-open-rtos
|
||||||
```
|
```
|
||||||
|
|
||||||
* To build any examples that use WiFi, create `include/private_ssid_config.h` defining the two macro defines:
|
* To build any examples that use WiFi, edit `include/ssid_config.h` and change the two macro defines:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
#define WIFI_SSID "mywifissid"
|
#define WIFI_SSID "mywifissid"
|
||||||
#define WIFI_PASS "my secret password"
|
#define WIFI_PASS "my secret password"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Remove the `#warning` line and follow the git ignore instructions written in the header file to keep your credentials from being pushed to Github.
|
||||||
|
|
||||||
* Build an example project (found in the 'examples' directory) and flash it to a serial port:
|
* Build an example project (found in the 'examples' directory) and flash it to a serial port:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -67,19 +67,19 @@ Current status is alpha quality, actively developed. AP STATION mode (ie wifi cl
|
||||||
* `include` contains header files from Espressif RTOS SDK, relating to the binary libraries & Xtensa core.
|
* `include` contains header files from Espressif RTOS SDK, relating to the binary libraries & Xtensa core.
|
||||||
* `core` contains source & headers for low-level ESP8266 functions & peripherals. `core/include/esp` contains useful headers for peripheral access, etc. Minimal to no FreeRTOS dependencies.
|
* `core` contains source & headers for low-level ESP8266 functions & peripherals. `core/include/esp` contains useful headers for peripheral access, etc. Minimal to no FreeRTOS dependencies.
|
||||||
* `extras` is a directory that contains optional components that can be added to your project. Most 'extras' components will have a corresponding example in the `examples` directory. Extras include:
|
* `extras` is a directory that contains optional components that can be added to your project. Most 'extras' components will have a corresponding example in the `examples` directory. Extras include:
|
||||||
- mbedtls - [mbedTLS](https://tls.mbed.org/) is a TLS/SSL library providing up to date secure connectivity and encryption support.
|
|
||||||
- i2c - software i2c driver ([upstream project](https://github.com/kanflo/esp-open-rtos-driver-i2c))
|
- i2c - software i2c driver ([upstream project](https://github.com/kanflo/esp-open-rtos-driver-i2c))
|
||||||
- rboot-ota - OTA support (over-the-air updates) including a TFTP server for receiving updates ([for rboot by @raburton](http://richard.burtons.org/2015/05/18/rboot-a-new-boot-loader-for-esp8266/))
|
- rboot-ota - OTA support (over-the-air updates) including a TFTP server for receiving updates ([for rboot by @raburton](http://richard.burtons.org/2015/05/18/rboot-a-new-boot-loader-for-esp8266/))
|
||||||
- bmp180 driver for digital pressure sensor ([upstream project](https://github.com/Angus71/esp-open-rtos-driver-bmp180))
|
- bmp180 driver for digital pressure sensor ([upstream project](https://github.com/Angus71/esp-open-rtos-driver-bmp180))
|
||||||
* `FreeRTOS` contains FreeRTOS implementation, subdirectory structure is the standard FreeRTOS structure. `FreeRTOS/source/portable/esp8266/` contains the ESP8266 port.
|
* `FreeRTOS` contains FreeRTOS implementation, subdirectory structure is the standard FreeRTOS structure. `FreeRTOS/source/portable/esp8266/` contains the ESP8266 port.
|
||||||
* `lwip` contains the lwIP TCP/IP library. See [Third Party Libraries](https://github.com/SuperHouse/esp-open-rtos/wiki/Third-Party-Libraries) wiki page for details.
|
* `lwip` and `axtls` contain the lwIP TCP/IP library and the axTLS TLS library ('libssl' in the esp8266 SDKs), respectively. See [Third Party Libraries](https://github.com/SuperHouse/esp-open-rtos/wiki/Third-Party-Libraries) wiki page for details.
|
||||||
* `libc` contains the newlib libc. [Libc details here](https://github.com/SuperHouse/esp-open-rtos/wiki/libc-configuration).
|
* `libc` contains the newlib libc. [Libc details here](https://github.com/SuperHouse/esp-open-rtos/wiki/libc-configuration).
|
||||||
|
|
||||||
## Open Source Components
|
## Open Source Components
|
||||||
|
|
||||||
* [FreeRTOS](http://www.freertos.org/) V10.2.0
|
* [FreeRTOS](http://freertos.org) V7.5.2
|
||||||
* [lwIP](http://lwip.wikia.com/wiki/LwIP_Wiki) v2.0.3, with [some modifications](https://github.com/ourairquality/lwip/).
|
* [lwIP](http://lwip.wikia.com/wiki/LwIP_Wiki) v1.4.1, modified via the [esp-lwip project](https://github.com/kadamski/esp-lwip) by @kadamski.
|
||||||
* [newlib](https://github.com/ourairquality/newlib) v3.0.0, with patches for xtensa support and locking stubs for thread-safe operation on FreeRTOS.
|
* [axTLS](http://axtls.sourceforge.net/) compiled from development version v1.5.3, plus modifications for low memory devices.
|
||||||
|
* [newlib](https://github.com/projectgus/newlib-xtensa) v2.2.0, with patches for xtensa support and locking stubs for thread-safe operation on FreeRTOS.
|
||||||
|
|
||||||
For details of how third party libraries are integrated, [see the wiki page](https://github.com/SuperHouse/esp-open-rtos/wiki/Third-Party-Libraries).
|
For details of how third party libraries are integrated, [see the wiki page](https://github.com/SuperHouse/esp-open-rtos/wiki/Third-Party-Libraries).
|
||||||
|
|
||||||
|
@ -89,8 +89,6 @@ Binary libraries (inside the `lib` dir) are all supplied by Espressif as part of
|
||||||
|
|
||||||
As part of the esp-open-rtos build process, all binary SDK symbols are prefixed with `sdk_`. This makes it easier to differentiate binary & open source code, and also prevents namespace conflicts.
|
As part of the esp-open-rtos build process, all binary SDK symbols are prefixed with `sdk_`. This makes it easier to differentiate binary & open source code, and also prevents namespace conflicts.
|
||||||
|
|
||||||
Espressif's RTOS SDK provided a "libssl" based on axTLS. This has been replaced with the more up to date mbedTLS library (see below).
|
|
||||||
|
|
||||||
Some binary libraries appear to contain unattributed open source code:
|
Some binary libraries appear to contain unattributed open source code:
|
||||||
|
|
||||||
* libnet80211.a & libwpa.a appear to be based on FreeBSD net80211/wpa, or forks of them. ([See this issue](https://github.com/SuperHouse/esp-open-rtos/issues/4)).
|
* libnet80211.a & libwpa.a appear to be based on FreeBSD net80211/wpa, or forks of them. ([See this issue](https://github.com/SuperHouse/esp-open-rtos/issues/4)).
|
||||||
|
@ -98,16 +96,14 @@ Some binary libraries appear to contain unattributed open source code:
|
||||||
|
|
||||||
## Licensing
|
## Licensing
|
||||||
|
|
||||||
* BSD license (as described in LICENSE) applies to original source files, [lwIP](http://lwip.wikia.com/wiki/LwIP_Wiki). lwIP is Copyright (C) Swedish Institute of Computer Science.
|
* BSD license (as described in LICENSE) applies to original source files, [lwIP](http://lwip.wikia.com/wiki/LwIP_Wiki), and [axTLS](http://axtls.sourceforge.net/). lwIP is Copyright (C) Swedish Institute of Computer Science. axTLS is Copyright (C) Cameron Rich.
|
||||||
|
|
||||||
* FreeRTOS (since v10) is provided under the MIT license. License details in files under FreeRTOS dir. FreeRTOS is Copyright (C) Amazon.
|
* FreeRTOS is provided under the GPL with the FreeRTOS linking exception, allowing non-GPL firmwares to be produced using FreeRTOS as the RTOS core. License details in files under FreeRTOS dir. FreeRTOS is Copyright (C) Real Time Engineers Ltd.
|
||||||
|
|
||||||
* Source & binary components from the [Espressif IOT RTOS SDK](https://github.com/espressif/esp_iot_rtos_sdk) were released under the MIT license. Source code components are relicensed here under the BSD license. The original parts are Copyright (C) Espressif Systems.
|
* Source & binary components from the [Espressif IOT RTOS SDK](https://github.com/espressif/esp_iot_rtos_sdk) were released under the MIT license. Source code components are relicensed here under the BSD license. The original parts are Copyright (C) Espressif Systems.
|
||||||
|
|
||||||
* Newlib is covered by several copyrights and licenses, as per the files in the `libc` directory.
|
* Newlib is covered by several copyrights and licenses, as per the files in the `libc` directory.
|
||||||
|
|
||||||
* [mbedTLS](https://tls.mbed.org/) is provided under the Apache 2.0 license as described in the file extras/mbedtls/mbedtls/apache-2.0.txt. mbedTLS is Copyright (C) ARM Limited.
|
|
||||||
|
|
||||||
Components under `extras/` may contain different licenses, please see those directories for details.
|
Components under `extras/` may contain different licenses, please see those directories for details.
|
||||||
|
|
||||||
## Contributions
|
## Contributions
|
||||||
|
@ -124,7 +120,7 @@ If you are contributing code, *please ensure that it can be licensed under the B
|
||||||
|
|
||||||
* Code from Espressif IoT SDK cannot be merged, as it is provided under either the "Espressif General Public License" or the "Espressif MIT License", which are not compatible with the BSD license.
|
* Code from Espressif IoT SDK cannot be merged, as it is provided under either the "Espressif General Public License" or the "Espressif MIT License", which are not compatible with the BSD license.
|
||||||
|
|
||||||
* Recent releases of the Espressif IoT RTOS SDK cannot be merged, as they changed from MIT License to the "Espressif MIT License" which is not BSD compatible. The Espressif binaries used in esp-open-rtos were taken from [revision ec75c85, as this was the last MIT Licensed revision](https://github.com/espressif/ESP8266_RTOS_SDK/commit/43585fa74550054076bdf4bfe185e808ad0da83e).
|
* Recent releases of the Espressif IoT RTOS SDK cannot be merged, as they changed from MIT License to the "Espressif MIT License" which is not BSD compatible. The Espressif binaries used in esp-open-rtos were taken from [revision ec75c85, as this was the last MIT Licensed revision](https://github.com/espressif/esp_iot_rtos_sdk/commit/43585fa74550054076bdf4bfe185e808ad0da83e).
|
||||||
|
|
||||||
For code submissions based on reverse engineered binary functionality, please either reverse engineer functionality from MIT Licensed Espressif releases or make sure that the reverse engineered code does not directly copy the code structure of the binaries - it cannot be a "derivative work" of an incompatible binary.
|
For code submissions based on reverse engineered binary functionality, please either reverse engineer functionality from MIT Licensed Espressif releases or make sure that the reverse engineered code does not directly copy the code structure of the binaries - it cannot be a "derivative work" of an incompatible binary.
|
||||||
|
|
||||||
|
@ -132,17 +128,7 @@ The best way to write suitable code is to first add documentation somewhere like
|
||||||
|
|
||||||
## Coding Style
|
## Coding Style
|
||||||
|
|
||||||
For new contributions in C, please use BSD style and indent using 4 spaces.
|
For new contributions, please use BSD style and indent using 4 spaces. If you're an emacs user then there is a .dir-locals.el file in the root which configures cc-mode.
|
||||||
|
|
||||||
For assembly, please use the following:
|
|
||||||
* Instructions indented using 8 spaces.
|
|
||||||
* Inline comments use `#` as a comment delimiter.
|
|
||||||
* Comments on their own line(s) use `/*`..`*/`.
|
|
||||||
* First operand of each instruction should be vertically aligned where possible.
|
|
||||||
* For xtensa special registers, prefer `wsr aX, SR` over `wsr.SR aX`
|
|
||||||
|
|
||||||
If you're an emacs user then there is a .dir-locals.el file in the root which configures cc-mode and asm-mode (you will need to approve some variable values as safe). See also
|
|
||||||
the additional comments in .dir-locals.el, if you're editing assembly code.
|
|
||||||
|
|
||||||
Upstream code is left with the indentation and style of the upstream project.
|
Upstream code is left with the indentation and style of the upstream project.
|
||||||
|
|
||||||
|
|
1
axtls/axtls
Submodule
1
axtls/axtls
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit a4860ef68d7f5d98a8731f99787d51cc44c433c9
|
33
axtls/axtls_esp_stubs.c
Normal file
33
axtls/axtls_esp_stubs.c
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Stub time-related functions for TLS time-related operations
|
||||||
|
*
|
||||||
|
* ESPTODO: Revisit these ASAP as gettimeofday() is used for entropy
|
||||||
|
*
|
||||||
|
* Part of esp-open-rtos
|
||||||
|
* Copyright (C) 2015 Superhouse Automation Pty Ltd
|
||||||
|
* BSD Licensed as described in the file LICENSE
|
||||||
|
*/
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
time_t time(time_t *t)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t mktime(struct tm *tm)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gettimeofday(struct timeval *tv, void *tz)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void abort(void)
|
||||||
|
{
|
||||||
|
printf("abort() was called.\r\n");
|
||||||
|
while(1) {}
|
||||||
|
}
|
22
axtls/component.mk
Normal file
22
axtls/component.mk
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Component makefile for axTLS
|
||||||
|
|
||||||
|
# axTLS has its own configure and build system, but it's not particularly
|
||||||
|
# designed for embedded systems. For now we're just imposing the ESP Open RTOS
|
||||||
|
# build system over the top.
|
||||||
|
|
||||||
|
# We supply our own hand tweaked config.h in the external 'include' dir.
|
||||||
|
|
||||||
|
AXTLS_DIR = $(axtls_ROOT)axtls/
|
||||||
|
INC_DIRS += $(axtls_ROOT)include $(AXTLS_DIR)ssl $(AXTLS_DIR)crypto
|
||||||
|
|
||||||
|
# args for passing into compile rule generation
|
||||||
|
axtls_INC_DIR = $(AXTLS_DIR)include $(AXTLS_DIR)
|
||||||
|
axtls_SRC_DIR = $(AXTLS_DIR)crypto $(AXTLS_DIR)ssl $(axtls_ROOT)
|
||||||
|
|
||||||
|
#axtls_CFLAGS = $(CFLAGS) -Wno-address
|
||||||
|
|
||||||
|
$(eval $(call component_compile_rules,axtls))
|
||||||
|
|
||||||
|
# Helpful error if git submodule not initialised
|
||||||
|
$(axtls_SRC_DIR):
|
||||||
|
$(error "axtls git submodule not installed. Please run 'git submodule init' then 'git submodule update'")
|
128
axtls/include/config.h
Normal file
128
axtls/include/config.h
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
/*
|
||||||
|
* Automatically generated header file: don't edit
|
||||||
|
*/
|
||||||
|
#define HAVE_DOT_CONFIG 0
|
||||||
|
#undef CONFIG_PLATFORM_LINUX
|
||||||
|
#undef CONFIG_PLATFORM_CYGWIN
|
||||||
|
#undef CONFIG_PLATFORM_WIN32
|
||||||
|
|
||||||
|
/*
|
||||||
|
* General Configuration
|
||||||
|
*/
|
||||||
|
#define PREFIX "/usr/local"
|
||||||
|
#define CROSS "xtensa-lx106-elf-"
|
||||||
|
#undef CONFIG_DEBUG
|
||||||
|
#define CONFIG_STRIP_UNWANTED_SECTIONS 1
|
||||||
|
#undef CONFIG_VISUAL_STUDIO_7_0
|
||||||
|
#undef CONFIG_VISUAL_STUDIO_8_0
|
||||||
|
#undef CONFIG_VISUAL_STUDIO_10_0
|
||||||
|
#define CONFIG_VISUAL_STUDIO_7_0_BASE ""
|
||||||
|
#define CONFIG_VISUAL_STUDIO_8_0_BASE ""
|
||||||
|
#define CONFIG_VISUAL_STUDIO_10_0_BASE ""
|
||||||
|
#define CONFIG_EXTRA_CFLAGS_OPTIONS ""
|
||||||
|
#define CONFIG_EXTRA_LDFLAGS_OPTIONS ""
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Embedded System Options (added for ESP RTOS SDK, don't have config entries yetr)
|
||||||
|
*/
|
||||||
|
#define CONFIG_NO_FILESYSTEM 1
|
||||||
|
#define CONFIG_USE_RAND 1
|
||||||
|
#define CONFIG_MAX_PLAIN_LENGTH 1024
|
||||||
|
#define CONFIG_MAX_KEY_BYTE_SIZE 256 /* for max 2048 bit keys (untested with >1024 bit keys) */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SSL Library
|
||||||
|
*/
|
||||||
|
#undef CONFIG_SSL_SERVER_ONLY
|
||||||
|
#undef CONFIG_SSL_CERT_VERIFICATION
|
||||||
|
#define CONFIG_SSL_ENABLE_CLIENT 1
|
||||||
|
#undef CONFIG_SSL_FULL_MODE
|
||||||
|
#undef CONFIG_SSL_SKELETON_MODE
|
||||||
|
#undef CONFIG_SSL_PROT_LOW
|
||||||
|
#define CONFIG_SSL_PROT_MEDIUM 1
|
||||||
|
#undef CONFIG_SSL_PROT_HIGH
|
||||||
|
#undef CONFIG_SSL_USE_DEFAULT_KEY
|
||||||
|
#define CONFIG_SSL_PRIVATE_KEY_LOCATION ""
|
||||||
|
#define CONFIG_SSL_PRIVATE_KEY_PASSWORD ""
|
||||||
|
#define CONFIG_SSL_X509_CERT_LOCATION ""
|
||||||
|
#undef CONFIG_SSL_GENERATE_X509_CERT
|
||||||
|
#define CONFIG_SSL_X509_COMMON_NAME ""
|
||||||
|
#define CONFIG_SSL_X509_ORGANIZATION_NAME ""
|
||||||
|
#define CONFIG_SSL_X509_ORGANIZATION_UNIT_NAME ""
|
||||||
|
#undef CONFIG_SSL_ENABLE_V23_HANDSHAKE
|
||||||
|
#undef CONFIG_SSL_HAS_PEM
|
||||||
|
#undef CONFIG_SSL_USE_PKCS12
|
||||||
|
#define CONFIG_SSL_EXPIRY_TIME 24
|
||||||
|
#define CONFIG_X509_MAX_CA_CERTS 1
|
||||||
|
#define CONFIG_SSL_MAX_CERTS 3
|
||||||
|
#undef CONFIG_SSL_CTX_MUTEXING
|
||||||
|
#undef CONFIG_USE_DEV_URANDOM
|
||||||
|
#undef CONFIG_WIN32_USE_CRYPTO_LIB
|
||||||
|
#undef CONFIG_OPENSSL_COMPATIBLE
|
||||||
|
#undef CONFIG_PERFORMANCE_TESTING
|
||||||
|
#undef CONFIG_SSL_TEST
|
||||||
|
#undef CONFIG_AXTLSWRAP
|
||||||
|
#undef CONFIG_AXHTTPD
|
||||||
|
#undef CONFIG_HTTP_STATIC_BUILD
|
||||||
|
#define CONFIG_HTTP_PORT
|
||||||
|
#define CONFIG_HTTP_HTTPS_PORT
|
||||||
|
#define CONFIG_HTTP_SESSION_CACHE_SIZE
|
||||||
|
#define CONFIG_HTTP_WEBROOT ""
|
||||||
|
#define CONFIG_HTTP_TIMEOUT
|
||||||
|
#undef CONFIG_HTTP_HAS_CGI
|
||||||
|
#define CONFIG_HTTP_CGI_EXTENSIONS ""
|
||||||
|
#undef CONFIG_HTTP_ENABLE_LUA
|
||||||
|
#define CONFIG_HTTP_LUA_PREFIX ""
|
||||||
|
#undef CONFIG_HTTP_BUILD_LUA
|
||||||
|
#define CONFIG_HTTP_CGI_LAUNCHER ""
|
||||||
|
#undef CONFIG_HTTP_DIRECTORIES
|
||||||
|
#undef CONFIG_HTTP_HAS_AUTHORIZATION
|
||||||
|
#undef CONFIG_HTTP_HAS_IPV6
|
||||||
|
#undef CONFIG_HTTP_ENABLE_DIFFERENT_USER
|
||||||
|
#define CONFIG_HTTP_USER ""
|
||||||
|
#undef CONFIG_HTTP_VERBOSE
|
||||||
|
#undef CONFIG_HTTP_IS_DAEMON
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Language Bindings
|
||||||
|
*/
|
||||||
|
#undef CONFIG_BINDINGS
|
||||||
|
#undef CONFIG_CSHARP_BINDINGS
|
||||||
|
#undef CONFIG_VBNET_BINDINGS
|
||||||
|
#define CONFIG_DOT_NET_FRAMEWORK_BASE ""
|
||||||
|
#undef CONFIG_JAVA_BINDINGS
|
||||||
|
#define CONFIG_JAVA_HOME ""
|
||||||
|
#undef CONFIG_PERL_BINDINGS
|
||||||
|
#define CONFIG_PERL_CORE ""
|
||||||
|
#define CONFIG_PERL_LIB ""
|
||||||
|
#undef CONFIG_LUA_BINDINGS
|
||||||
|
#define CONFIG_LUA_CORE ""
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Samples
|
||||||
|
*/
|
||||||
|
#undef CONFIG_SAMPLES
|
||||||
|
#undef CONFIG_C_SAMPLES
|
||||||
|
#undef CONFIG_CSHARP_SAMPLES
|
||||||
|
#undef CONFIG_VBNET_SAMPLES
|
||||||
|
#undef CONFIG_JAVA_SAMPLES
|
||||||
|
#undef CONFIG_PERL_SAMPLES
|
||||||
|
#undef CONFIG_LUA_SAMPLES
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BigInt Options
|
||||||
|
*/
|
||||||
|
#undef CONFIG_BIGINT_CLASSICAL
|
||||||
|
#undef CONFIG_BIGINT_MONTGOMERY
|
||||||
|
#define CONFIG_BIGINT_BARRETT 1
|
||||||
|
#define CONFIG_BIGINT_CRT 1
|
||||||
|
#undef CONFIG_BIGINT_KARATSUBA
|
||||||
|
#define MUL_KARATSUBA_THRESH
|
||||||
|
#define SQU_KARATSUBA_THRESH
|
||||||
|
#define CONFIG_BIGINT_SLIDING_WINDOW 1
|
||||||
|
#define CONFIG_BIGINT_SQUARE 1
|
||||||
|
#define CONFIG_BIGINT_CHECK_ON 1
|
||||||
|
#define CONFIG_INTEGER_32BIT 1
|
||||||
|
#undef CONFIG_INTEGER_16BIT
|
||||||
|
#undef CONFIG_INTEGER_8BIT
|
||||||
|
|
6
axtls/include/os_int.h
Normal file
6
axtls/include/os_int.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef _OS_INT_H
|
||||||
|
#define _OS_INT_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#endif
|
95
axtls/include/os_port.h
Normal file
95
axtls/include/os_port.h
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007-2015, Cameron Rich
|
||||||
|
* Modifications Copyright (c) 2015 Superhouse Automation Pty Ltd
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the axTLS project nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file os_port.h
|
||||||
|
*
|
||||||
|
* Some stuff to minimise the differences between windows and linux/unix
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _HEADER_OS_PORT_H
|
||||||
|
#define _HEADER_OS_PORT_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "os_int.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
//#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <posix/sys/socket.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <ipv4/lwip/inet.h>
|
||||||
|
#if defined(CONFIG_SSL_CTX_MUTEXING)
|
||||||
|
#include "semphr.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SOCKET_READ(A,B,C) read(A,B,C)
|
||||||
|
#define SOCKET_WRITE(A,B,C) write(A,B,C)
|
||||||
|
#define SOCKET_CLOSE(A) if (A >= 0) close(A)
|
||||||
|
#define TTY_FLUSH()
|
||||||
|
|
||||||
|
static inline uint64_t be64toh(uint64_t x) {
|
||||||
|
return ntohl(x>>32) | ((uint64_t)(ntohl(x)) << 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
void exit_now(const char *format, ...) __attribute((noreturn));
|
||||||
|
|
||||||
|
#define EXP_FUNC
|
||||||
|
#define STDCALL
|
||||||
|
|
||||||
|
/* Mutex definitions */
|
||||||
|
#if defined(CONFIG_SSL_CTX_MUTEXING)
|
||||||
|
#define SSL_CTX_MUTEX_TYPE xSemaphoreHandle
|
||||||
|
#define SSL_CTX_MUTEX_INIT(A) vSemaphoreCreateBinaryCreateMutex(A)
|
||||||
|
#define SSL_CTX_MUTEX_DESTROY(A) vSemaphoreDelete(A)
|
||||||
|
#define SSL_CTX_LOCK(A) xSemaphoreTakeRecursive(A, portMAX_DELAY)
|
||||||
|
#define SSL_CTX_UNLOCK(A) xSemaphoreGiveRecursive(A)
|
||||||
|
#else
|
||||||
|
#define SSL_CTX_MUTEX_TYPE
|
||||||
|
#define SSL_CTX_MUTEX_INIT(A)
|
||||||
|
#define SSL_CTX_MUTEX_DESTROY(A)
|
||||||
|
#define SSL_CTX_LOCK(A)
|
||||||
|
#define SSL_CTX_UNLOCK(A)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
10
axtls/include/version.h
Normal file
10
axtls/include/version.h
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
/* axTLS version header
|
||||||
|
|
||||||
|
We need this because we're using axTLS from source repo, not from a release.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _VERSION_H
|
||||||
|
|
||||||
|
#define AXTLS_VERSION "esp-open-rtos axTLS " GITSHORTREV
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,59 +0,0 @@
|
||||||
# This is a wrapper around the rboot makefile, which gives us the parameters
|
|
||||||
# we need to use rboot with esp-open-rtos.
|
|
||||||
#
|
|
||||||
# Use 'make bootloader' to build a custom bootloader.
|
|
||||||
#
|
|
||||||
# 'make flash' for any esp-open-rtos program will use the compiled
|
|
||||||
# bootloader if it exists, or a prebuilt bootloader if no custom
|
|
||||||
# bootloader was compiled.
|
|
||||||
#
|
|
||||||
# The wrapper means we don't require esptool2 in the build process, so we can just use
|
|
||||||
# esptool.py (still need xxd, grep, sed to generate the header - see below.)
|
|
||||||
BOOTLOADER_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
|
||||||
|
|
||||||
include ../parameters.mk
|
|
||||||
|
|
||||||
all: $(FIRMWARE_DIR)/rboot.bin
|
|
||||||
|
|
||||||
rboot/Makefile:
|
|
||||||
$(error rboot git submodule is not checkedo out. Try running 'git submodule update --init --recursive')
|
|
||||||
|
|
||||||
$(FIRMWARE_DIR)/rboot.bin: $(BUILD_DIR)/rboot.elf $(FIRMWARE_DIR)
|
|
||||||
@echo "FW rboot.bin"
|
|
||||||
$(Q) $(ESPTOOL) elf2image $(ESPTOOL_ARGS) $< -o $(BUILD_DIR)/
|
|
||||||
$(Q) mv $(BUILD_DIR)/0x00000.bin $@
|
|
||||||
|
|
||||||
# rboot generates this header using the 'esptool2 -header' option. To try and avoid
|
|
||||||
# esptool2 as a dependency, we try it here using grep, sed, xxd (all fairly common Unix tools)
|
|
||||||
$(BUILD_DIR)/rboot-hex2a.h: $(BUILD_DIR)/rboot-stage2a.elf $(BUILD_DIR)
|
|
||||||
@echo "Extracting stub image header..."
|
|
||||||
$(Q) xtensa-lx106-elf-objcopy $< --only-section .text -Obinary $(BUILD_DIR)/rboot-hex2a.bin
|
|
||||||
$(Q) xxd -i $(BUILD_DIR)/rboot-hex2a.bin > $@.in
|
|
||||||
$(Q) sed -i "s/unsigned char .\+\[\]/const uint8 _text_data[]/" $@.in
|
|
||||||
$(Q) sed -i "s/unsigned int .\+_len/const uint32 _text_len/" $@.in
|
|
||||||
$(Q) echo "const uint32 entry_addr = $$(xtensa-lx106-elf-objdump -f $< | grep 'start address' | grep -o '0x.\+');" >> $@.in
|
|
||||||
$(Q) echo "const uint32 _text_addr = 0x$$(xtensa-lx106-elf-objdump -h -j .text $< | grep ".text" | grep -o '401.....' | head -n1);" >> $@.in
|
|
||||||
$(Q) mv $@.in $@
|
|
||||||
|
|
||||||
|
|
||||||
RBOOT_BUILD_BASE="$(abspath $(BUILD_DIR))"
|
|
||||||
RBOOT_FW_BASE="$(abspath $(FIRMWARE_DIR))"
|
|
||||||
MAKE_VARS=RBOOT_EXTRA_INCDIR=$(BOOTLOADER_DIR) RBOOT_BUILD_BASE=$(RBOOT_BUILD_BASE) RBOOT_FW_BASE=$(RBOOT_FW_BASE)
|
|
||||||
|
|
||||||
$(BUILD_DIR)/rboot-stage2a.elf: $(BUILD_DIR)
|
|
||||||
$(Q) $(MAKE) -C rboot $(RBOOT_BUILD_BASE)/rboot-stage2a.elf $(MAKE_VARS)
|
|
||||||
|
|
||||||
$(BUILD_DIR)/rboot.elf: $(BUILD_DIR)/rboot-hex2a.h
|
|
||||||
$(Q) $(MAKE) -C rboot $(RBOOT_BUILD_BASE)/rboot.elf $(MAKE_VARS)
|
|
||||||
|
|
||||||
$(BUILD_DIR) $(FIRMWARE_DIR):
|
|
||||||
mkdir -p $@
|
|
||||||
|
|
||||||
flash: $(FIRMWARE_DIR)/rboot.bin
|
|
||||||
$(Q) $(ESPTOOL) -p $(ESPPORT) -b $(ESPBAUD) write_flash $(ESPTOOL_ARGS) 0x0 $<
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(Q) rm -rf $(BUILD_DIR)
|
|
||||||
$(Q) rm -rf $(FIRMWARE_DIR)
|
|
||||||
|
|
||||||
.PHONY: all
|
|
|
@ -1,12 +0,0 @@
|
||||||
OTA Bootloader (rboot) source module and support files.
|
|
||||||
|
|
||||||
rboot is an open source bootloader by Richard Burton:
|
|
||||||
https://github.com/raburton/rboot
|
|
||||||
|
|
||||||
Can be used to build an esp-open-rtos compatible rboot bootloader. Run 'make bootloader' in this directory to compile a new bootloader.
|
|
||||||
|
|
||||||
Compiling a new bootloader is optional, there's a prebuilt one in the "firmware_prebuilt" directory that will be used if no new bootloader was compiled.
|
|
||||||
|
|
||||||
It is also possible to use rboot from upstream verbatim, but *ensure that the `RBOOT_BIG_FLASH` option is enabled or images in slots other than 0 won't work correctly.
|
|
||||||
|
|
||||||
See the contents of the 'rboot' directory for more information on rboot.
|
|
|
@ -1,10 +0,0 @@
|
||||||
/* rboot type definitions */
|
|
||||||
|
|
||||||
|
|
||||||
typedef int int32;
|
|
||||||
typedef unsigned short uint16;
|
|
||||||
typedef unsigned int uint32;
|
|
||||||
typedef unsigned char uint8;
|
|
||||||
|
|
||||||
#define TRUE 1
|
|
||||||
#define FALSE 0
|
|
Binary file not shown.
Binary file not shown.
|
@ -1 +0,0 @@
|
||||||
Subproject commit 3b067a8686a07474c5f722953d3b2f0e71db681f
|
|
|
@ -1,23 +0,0 @@
|
||||||
/* rboot header overrides
|
|
||||||
|
|
||||||
This "wrapper" header contains default values for building rboot
|
|
||||||
on/for esp-open-rtos. It gets included both when building the
|
|
||||||
bootloader and when building extras/rboot-ota support. It includes
|
|
||||||
the default bootloader/rboot/rboot.h header via the gcc
|
|
||||||
include_next mechanism.
|
|
||||||
*/
|
|
||||||
#ifndef __RBOOT_H__
|
|
||||||
|
|
||||||
// Big flash support is required for esp-open-rtos (we use 8Mbit
|
|
||||||
// "slots" only.)
|
|
||||||
#define BOOT_BIG_FLASH
|
|
||||||
|
|
||||||
// enable 2 way communication between
|
|
||||||
// rBoot and the user app via the esp rtc data area
|
|
||||||
#define BOOT_RTC_ENABLED
|
|
||||||
|
|
||||||
// Call 'main' rboot.h to pick up defaults for other parameters
|
|
||||||
#include_next "rboot.h"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
253
common.mk
253
common.mk
|
@ -20,10 +20,115 @@
|
||||||
# assume the 'root' directory (ie top of the tree) is the directory common.mk is in
|
# assume the 'root' directory (ie top of the tree) is the directory common.mk is in
|
||||||
ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
|
ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||||
|
|
||||||
include $(ROOT)parameters.mk
|
# include optional local overrides at the root level, then in program directory
|
||||||
|
#
|
||||||
|
# Create either of these files for local system overrides if possible,
|
||||||
|
# instead of editing this makefile directly.
|
||||||
|
-include $(ROOT)local.mk
|
||||||
|
-include local.mk
|
||||||
|
|
||||||
|
# Flash size in megabits
|
||||||
|
# Valid values are same as for esptool.py - 2,4,8,16,32
|
||||||
|
FLASH_SIZE ?= 16
|
||||||
|
|
||||||
|
# Flash mode, valid values are same as for esptool.py - qio,qout,dio.dout
|
||||||
|
FLASH_MODE ?= qio
|
||||||
|
|
||||||
|
# Flash speed in MHz, valid values are same as for esptool.py - 80, 40, 26, 20
|
||||||
|
FLASH_SPEED ?= 40
|
||||||
|
|
||||||
|
# Output directories to store intermediate compiled files
|
||||||
|
# relative to the program directory
|
||||||
|
BUILD_DIR ?= $(PROGRAM_DIR)build/
|
||||||
|
FW_BASE ?= $(PROGRAM_DIR)firmware/
|
||||||
|
|
||||||
|
# esptool.py from https://github.com/themadinventor/esptool
|
||||||
|
ESPTOOL ?= esptool.py
|
||||||
|
# serial port settings for esptool.py
|
||||||
|
ESPPORT ?= /dev/ttyUSB0
|
||||||
|
ESPBAUD ?= 115200
|
||||||
|
|
||||||
|
# Set OTA to 1 to build an image that supports rBoot OTA bootloader
|
||||||
|
#
|
||||||
|
# Currently only works with 16mbit or more flash sizes, with 8mbit
|
||||||
|
# images for each "slot"
|
||||||
|
OTA ?= 0
|
||||||
|
|
||||||
|
ifeq ($(OTA),1)
|
||||||
|
# for OTA, we build a "SDK v1.2 bootloader" compatible image where everything is in
|
||||||
|
# one file (should work with the v1.2 binary bootloader, and the FOSS rBoot bootloader).
|
||||||
|
IMGTOOL ?= esptool2
|
||||||
|
|
||||||
|
# Tell C preprocessor that we're building for OTA
|
||||||
|
CPPFLAGS = -DOTA
|
||||||
|
endif
|
||||||
|
|
||||||
|
FLAVOR ?= release # or debug
|
||||||
|
|
||||||
|
# Compiler names, etc. assume gdb
|
||||||
|
CROSS ?= xtensa-lx106-elf-
|
||||||
|
|
||||||
|
AR = $(CROSS)ar
|
||||||
|
CC = $(CROSS)gcc
|
||||||
|
CPP = $(CROSS)cpp
|
||||||
|
LD = $(CROSS)gcc
|
||||||
|
NM = $(CROSS)nm
|
||||||
|
C++ = $(CROSS)g++
|
||||||
|
SIZE = $(CROSS)size
|
||||||
|
OBJCOPY = $(CROSS)objcopy
|
||||||
|
OBJDUMP = $(CROSS)objdump
|
||||||
|
|
||||||
|
# Source components to compile and link. Each of these are subdirectories
|
||||||
|
# of the root, with a 'component.mk' file.
|
||||||
|
COMPONENTS ?= $(EXTRA_COMPONENTS) FreeRTOS lwip axtls core
|
||||||
|
|
||||||
|
# binary esp-iot-rtos SDK libraries to link. These are pre-processed prior to linking.
|
||||||
|
SDK_LIBS ?= main net80211 phy pp wpa
|
||||||
|
|
||||||
|
# open source libraries linked in
|
||||||
|
LIBS ?= hal gcc c
|
||||||
|
|
||||||
|
# set to 0 if you want to use the toolchain libc instead of esp-open-rtos newlib
|
||||||
|
OWN_LIBC ?= 1
|
||||||
|
|
||||||
|
# Note: you will need a recent esp
|
||||||
|
ENTRY_SYMBOL ?= call_user_start
|
||||||
|
|
||||||
|
# Common flags for both C & C++_
|
||||||
|
C_CXX_FLAGS = -Wall -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals $(CPPFLAGS)
|
||||||
|
# Flags for C only
|
||||||
|
CFLAGS = $(C_CXX_FLAGS) -std=gnu99
|
||||||
|
# Flags for C++ only
|
||||||
|
CXXFLAGS = $(C_CXX_FLAGS) -fno-exceptions -fno-rtti
|
||||||
|
LDFLAGS = -nostdlib -Wl,--no-check-sections -Wl,-L$(BUILD_DIR)sdklib -Wl,-L$(ROOT)lib -u $(ENTRY_SYMBOL) -Wl,-static -Wl,-Map=build/${PROGRAM}.map $(EXTRA_LDFLAGS)
|
||||||
|
|
||||||
|
ifeq ($(FLAVOR),debug)
|
||||||
|
C_CXX_FLAGS += -g -O0
|
||||||
|
LDFLAGS += -g -O0
|
||||||
|
else ifeq ($(FLAVOR),sdklike)
|
||||||
|
# These are flags intended to produce object code as similar as possible to
|
||||||
|
# the output of the compiler used to build the SDK libs (for comparison of
|
||||||
|
# disassemblies when coding replacement routines). It is not normally
|
||||||
|
# intended to be used otherwise.
|
||||||
|
CFLAGS += -O2 -Os -fno-inline -fno-ipa-cp -fno-toplevel-reorder
|
||||||
|
LDFLAGS += -O2
|
||||||
|
else
|
||||||
|
C_CXX_FLAGS += -g -O2
|
||||||
|
LDFLAGS += -g -O2
|
||||||
|
endif
|
||||||
|
|
||||||
|
GITSHORTREV=\"$(shell cd $(ROOT); git rev-parse --short -q HEAD)\"
|
||||||
|
CPPFLAGS += -DGITSHORTREV=$(GITSHORTREV) -DFLASH_SIZE=$(FLASH_SIZE)
|
||||||
|
|
||||||
|
# Linker scripts, all found in $(ROOT)/ld
|
||||||
|
LINKER_SCRIPTS = eagle.app.v6.ld eagle.rom.addr.v6.ld
|
||||||
|
|
||||||
|
####
|
||||||
|
#### no user configurable options below here
|
||||||
|
####
|
||||||
|
|
||||||
ifndef PROGRAM
|
ifndef PROGRAM
|
||||||
$(error "Set the PROGRAM environment variable in your Makefile before including common.mk")
|
$(error "Set the PROGRAM environment variable in your Makefile before including common.mk"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# hacky way to get a single space value
|
# hacky way to get a single space value
|
||||||
|
@ -36,13 +141,42 @@ lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(s
|
||||||
# assume the program dir is the directory the top-level makefile was run in
|
# assume the program dir is the directory the top-level makefile was run in
|
||||||
PROGRAM_DIR := $(dir $(firstword $(MAKEFILE_LIST)))
|
PROGRAM_DIR := $(dir $(firstword $(MAKEFILE_LIST)))
|
||||||
|
|
||||||
|
# linker scripts get run through the C preprocessor
|
||||||
|
ifeq ($(OTA),1)
|
||||||
|
LD_DIR = $(BUILD_DIR)ld-$(FLASH_SIZE)-ota/
|
||||||
|
else
|
||||||
|
LD_DIR = $(BUILD_DIR)ld-$(FLASH_SIZE)/
|
||||||
|
endif
|
||||||
|
LINKER_SCRIPTS_PROCESSED = $(addprefix $(LD_DIR),$(LINKER_SCRIPTS))
|
||||||
|
|
||||||
# derive various parts of compiler/linker arguments
|
# derive various parts of compiler/linker arguments
|
||||||
SDK_LIB_ARGS = $(addprefix -l,$(SDK_LIBS))
|
SDK_LIB_ARGS = $(addprefix -l,$(SDK_LIBS))
|
||||||
LIB_ARGS = $(addprefix -l,$(LIBS))
|
LIB_ARGS = $(addprefix -l,$(LIBS))
|
||||||
PROGRAM_OUT = $(BUILD_DIR)$(PROGRAM).out
|
PROGRAM_OUT = $(BUILD_DIR)$(PROGRAM).out
|
||||||
LDFLAGS += $(addprefix -T,$(LINKER_SCRIPTS))
|
LDFLAGS += $(addprefix -T,$(LINKER_SCRIPTS_PROCESSED))
|
||||||
|
|
||||||
FW_FILE = $(addprefix $(FIRMWARE_DIR),$(PROGRAM).bin)
|
ifeq ($(OTA),0)
|
||||||
|
# for non-OTA, we create two different files for uploading into the flash
|
||||||
|
# these are the names and options to generate them
|
||||||
|
FW_ADDR_1 = 0x00000
|
||||||
|
FW_ADDR_2 = 0x40000
|
||||||
|
FW_FILE_1 = $(addprefix $(FW_BASE),$(FW_ADDR_1).bin)
|
||||||
|
FW_FILE_2 = $(addprefix $(FW_BASE),$(FW_ADDR_2).bin)
|
||||||
|
else
|
||||||
|
# for OTA, it's a single monolithic image
|
||||||
|
FW_FILE = $(addprefix $(FW_BASE),$(PROGRAM).bin)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# firmware tool arguments
|
||||||
|
ESPTOOL_ARGS=-fs $(FLASH_SIZE)m -fm $(FLASH_MODE) -ff $(FLASH_SPEED)m
|
||||||
|
|
||||||
|
IMGTOOL_FLASH_SIZE_2=256
|
||||||
|
IMGTOOL_FLASH_SIZE_4=512
|
||||||
|
IMGTOOL_FLASH_SIZE_8=1024
|
||||||
|
IMGTOOL_FLASH_SIZE_16=2048
|
||||||
|
IMGTOOL_FLASH_SIZE_32=4096
|
||||||
|
IMGTOOL_FLASH_SIZE=$(value IMGTOOL_FLASH_SIZE_$(FLASH_SIZE))
|
||||||
|
IMGTOOL_ARGS=-$(IMGTOOL_FLASH_SIZE) -$(FLASH_MODE) -$(FLASH_SPEED)
|
||||||
|
|
||||||
# Common include directories, shared across all "components"
|
# Common include directories, shared across all "components"
|
||||||
# components will add their include directories to this argument
|
# components will add their include directories to this argument
|
||||||
|
@ -55,9 +189,6 @@ INC_DIRS = $(PROGRAM_DIR) $(PROGRAM_DIR)include $(ROOT)include
|
||||||
ifeq ($(OWN_LIBC),1)
|
ifeq ($(OWN_LIBC),1)
|
||||||
INC_DIRS += $(ROOT)libc/xtensa-lx106-elf/include
|
INC_DIRS += $(ROOT)libc/xtensa-lx106-elf/include
|
||||||
LDFLAGS += -L$(ROOT)libc/xtensa-lx106-elf/lib
|
LDFLAGS += -L$(ROOT)libc/xtensa-lx106-elf/lib
|
||||||
ifeq ($(PRINTF_SCANF_FLOAT_SUPPORT),1)
|
|
||||||
LDFLAGS += -u _printf_float -u _scanf_float
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ("$(V)","1")
|
ifeq ("$(V)","1")
|
||||||
|
@ -68,7 +199,7 @@ Q := @
|
||||||
vecho := @echo
|
vecho := @echo
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: all clean flash erase_flash test size rebuild
|
.PHONY: all clean debug_print
|
||||||
|
|
||||||
all: $(PROGRAM_OUT) $(FW_FILE_1) $(FW_FILE_2) $(FW_FILE)
|
all: $(PROGRAM_OUT) $(FW_FILE_1) $(FW_FILE_2) $(FW_FILE)
|
||||||
|
|
||||||
|
@ -89,9 +220,8 @@ all: $(PROGRAM_OUT) $(FW_FILE_1) $(FW_FILE_2) $(FW_FILE)
|
||||||
# $(1)_INC_DIR = List of include directories specific for the component
|
# $(1)_INC_DIR = List of include directories specific for the component
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Each call appends to COMPONENT_ARS or WHOLE_ARCHIVES which are lists of archive files for compiled components
|
# Each call appends to COMPONENT_ARS which is a list of archive files for compiled components
|
||||||
COMPONENT_ARS =
|
COMPONENT_ARS =
|
||||||
WHOLE_ARCHIVES =
|
|
||||||
define component_compile_rules
|
define component_compile_rules
|
||||||
$(1)_DEFAULT_ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
|
$(1)_DEFAULT_ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||||
$(1)_ROOT ?= $$($(1)_DEFAULT_ROOT)
|
$(1)_ROOT ?= $$($(1)_DEFAULT_ROOT)
|
||||||
|
@ -111,82 +241,48 @@ $(1)_OBJ_FILES = $$(patsubst $$($(1)_REAL_ROOT)%.S,$$($(1)_OBJ_DIR)%.o,$$($(1)_O
|
||||||
$(1)_MAKEFILE ?= $(lastword $(MAKEFILE_LIST))
|
$(1)_MAKEFILE ?= $(lastword $(MAKEFILE_LIST))
|
||||||
|
|
||||||
### determine compiler arguments ###
|
### determine compiler arguments ###
|
||||||
$(1)_CPPFLAGS ?= $(CPPFLAGS)
|
|
||||||
$(1)_CFLAGS ?= $(CFLAGS)
|
$(1)_CFLAGS ?= $(CFLAGS)
|
||||||
$(1)_CXXFLAGS ?= $(CXXFLAGS)
|
$(1)_CXXFLAGS ?= $(CXXFLAGS)
|
||||||
$(1)_CC_BASE = $(Q) $(CC) $$(addprefix -I,$$(INC_DIRS)) $$(addprefix -I,$$($(1)_INC_DIR)) $$($(1)_CPPFLAGS)
|
$(1)_CC_ARGS = $(Q) $(CC) $$(addprefix -I,$$(INC_DIRS)) $$(addprefix -I,$$($(1)_INC_DIR)) $$($(1)_CFLAGS)
|
||||||
|
$(1)_CXX_ARGS = $(Q) $(C++) $$(addprefix -I,$$(INC_DIRS)) $$(addprefix -I,$$($(1)_INC_DIR)) $$($(1)_CXXFLAGS)
|
||||||
$(1)_AR = $(call lc,$(BUILD_DIR)$(1).a)
|
$(1)_AR = $(call lc,$(BUILD_DIR)$(1).a)
|
||||||
|
|
||||||
$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.c $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR)
|
$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.c $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR)
|
||||||
$(vecho) "CC $$<"
|
$(vecho) "CC $$<"
|
||||||
$(Q) mkdir -p $$(dir $$@)
|
$(Q) mkdir -p $$(dir $$@)
|
||||||
$$($(1)_CC_BASE) $$($(1)_CFLAGS) -c $$< -o $$@
|
$$($(1)_CC_ARGS) -c $$< -o $$@
|
||||||
$$($(1)_CC_BASE) $$($(1)_CFLAGS) -MM -MT $$@ -MF $$(@:.o=.d) $$<
|
$$($(1)_CC_ARGS) -MM -MT $$@ -MF $$(@:.o=.d) $$<
|
||||||
|
|
||||||
$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.cpp $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR)
|
$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.cpp $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR)
|
||||||
$(vecho) "C++ $$<"
|
$(vecho) "C++ $$<"
|
||||||
$(Q) mkdir -p $$(dir $$@)
|
$(Q) mkdir -p $$(dir $$@)
|
||||||
$$($(1)_CC_BASE) $$($(1)_CXXFLAGS) -c $$< -o $$@
|
$$($(1)_CXX_ARGS) -c $$< -o $$@
|
||||||
$$($(1)_CC_BASE) $$($(1)_CXXFLAGS) -MM -MT $$@ -MF $$(@:.o=.d) $$<
|
$$($(1)_CXX_ARGS) -MM -MT $$@ -MF $$(@:.o=.d) $$<
|
||||||
|
|
||||||
$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.S $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR)
|
$$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.S $$($(1)_MAKEFILE) $(wildcard $(ROOT)*.mk) | $$($(1)_SRC_DIR)
|
||||||
$(vecho) "AS $$<"
|
$(vecho) "AS $$<"
|
||||||
$(Q) mkdir -p $$(dir $$@)
|
$(Q) mkdir -p $$(dir $$@)
|
||||||
$$($(1)_CC_BASE) -c $$< -o $$@
|
$$($(1)_CC_ARGS) -c $$< -o $$@
|
||||||
$$($(1)_CC_BASE) -MM -MT $$@ -MF $$(@:.o=.d) $$<
|
|
||||||
|
|
||||||
$(1)_AR_IN_FILES = $$($(1)_OBJ_FILES)
|
# the component is shown to depend on both obj and source files so we get a meaningful error message
|
||||||
|
# for missing explicitly named source files
|
||||||
# The component is shown to depend on both obj and source files so we get
|
$$($(1)_AR): $$($(1)_OBJ_FILES) $$($(1)_SRC_FILES)
|
||||||
# a meaningful error message for missing explicitly named source files.
|
|
||||||
# But do not include source files into a static library because when adding this
|
|
||||||
# library with '--whole-archive' linker gives error that archive contains
|
|
||||||
# unknown objects (source files)
|
|
||||||
ifndef $(1)_WHOLE_ARCHIVE
|
|
||||||
$(1)_AR_IN_FILES += $$($(1)_SRC_FILES)
|
|
||||||
endif
|
|
||||||
|
|
||||||
$$($(1)_AR): $$($(1)_AR_IN_FILES)
|
|
||||||
$(vecho) "AR $$@"
|
$(vecho) "AR $$@"
|
||||||
$(Q) mkdir -p $$(dir $$@)
|
$(Q) mkdir -p $$(dir $$@)
|
||||||
$(Q) $(AR) cru $$@ $$^
|
$(Q) $(AR) cru $$@ $$^
|
||||||
|
|
||||||
ifdef $(1)_WHOLE_ARCHIVE
|
COMPONENT_ARS += $$($(1)_AR)
|
||||||
WHOLE_ARCHIVES += $$($(1)_AR)
|
|
||||||
else
|
|
||||||
COMPONENT_ARS += $$($(1)_AR)
|
|
||||||
endif
|
|
||||||
|
|
||||||
-include $$($(1)_OBJ_FILES:.o=.d)
|
-include $$($(1)_OBJ_FILES:.o=.d)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# Remove comment lines from libgcc.remove file
|
|
||||||
$(BUILD_DIR)libgcc.remove: $(ROOT)lib/libgcc.remove | $(BUILD_DIR)
|
|
||||||
$(Q) grep -v "^#" $< | cat > $@
|
|
||||||
|
|
||||||
# Remove unwanted object files listed in libgcc.remove
|
|
||||||
$(BUILD_DIR)libgcc.a: $(ROOT)lib/libgcc.a $(BUILD_DIR)libgcc.remove | $(BUILD_DIR)
|
|
||||||
@echo "Removing unwanted objects from $<"
|
|
||||||
$(Q) cat $< > $@
|
|
||||||
$(Q) $(AR) d $@ @$(word 2,$^)
|
|
||||||
|
|
||||||
# Remove comment lines from libc.remove file
|
|
||||||
$(BUILD_DIR)libc.remove: $(ROOT)libc/libc.remove | $(BUILD_DIR)
|
|
||||||
$(Q) grep -v "^#" $< | cat > $@
|
|
||||||
|
|
||||||
# Remove unwanted object files listed in libgcc.remove
|
|
||||||
$(BUILD_DIR)libc.a: $(ROOT)libc/xtensa-lx106-elf/lib/libc.a $(BUILD_DIR)libc.remove | $(BUILD_DIR)
|
|
||||||
@echo "Removing unwanted objects from $<"
|
|
||||||
$(Q) cat $< > $@
|
|
||||||
$(Q) $(AR) d $@ @$(word 2,$^)
|
|
||||||
|
|
||||||
## Linking rules for SDK libraries
|
## Linking rules for SDK libraries
|
||||||
## SDK libraries are preprocessed to:
|
## SDK libraries are preprocessed to:
|
||||||
# - remove object files named in <libname>.remove
|
# - remove object files named in <libname>.remove
|
||||||
# - prefix all defined symbols with 'sdk_'
|
# - prefix all defined symbols with 'sdk_'
|
||||||
# - weaken all global symbols so they can be overriden from the open SDK side
|
# - weaken all global symbols so they can be overriden from the open SDK side
|
||||||
#
|
#
|
||||||
# SDK binary libraries are preprocessed into $(BUILD_DIR)/sdklib
|
# SDK binary libraries are preprocessed into build/sdklib
|
||||||
SDK_PROCESSED_LIBS = $(addsuffix .a,$(addprefix $(BUILD_DIR)sdklib/lib,$(SDK_LIBS)))
|
SDK_PROCESSED_LIBS = $(addsuffix .a,$(addprefix $(BUILD_DIR)sdklib/lib,$(SDK_LIBS)))
|
||||||
|
|
||||||
# Make rules for preprocessing each SDK library
|
# Make rules for preprocessing each SDK library
|
||||||
|
@ -227,38 +323,39 @@ $(foreach component,$(COMPONENTS), \
|
||||||
) \
|
) \
|
||||||
)
|
)
|
||||||
|
|
||||||
# final linking step to produce .elf
|
## Run linker scripts via C preprocessor to evaluate macros
|
||||||
$(PROGRAM_OUT): $(WHOLE_ARCHIVES) $(COMPONENT_ARS) $(BUILD_DIR)libgcc.a $(BUILD_DIR)libc.a $(SDK_PROCESSED_LIBS) $(LINKER_SCRIPTS)
|
$(LD_DIR)%.ld: $(ROOT)ld/%.ld | $(LD_DIR)
|
||||||
$(vecho) "LD $@"
|
$(Q) $(CPP) $(CPPFLAGS) -E -C -P $< > $@
|
||||||
$(Q) $(LD) $(LDFLAGS) -Wl,--whole-archive $(WHOLE_ARCHIVES) -Wl,--no-whole-archive -Wl,--start-group $(COMPONENT_ARS) $(BUILD_DIR)libgcc.a $(BUILD_DIR)libc.a $(LIB_ARGS) $(SDK_LIB_ARGS) -Wl,--end-group -o $@
|
|
||||||
|
|
||||||
$(BUILD_DIR) $(FIRMWARE_DIR) $(BUILD_DIR)sdklib:
|
# final linking step to produce .elf
|
||||||
|
$(PROGRAM_OUT): $(COMPONENT_ARS) $(SDK_PROCESSED_LIBS) $(LINKER_SCRIPTS_PROCESSED)
|
||||||
|
$(vecho) "LD $@"
|
||||||
|
$(Q) $(LD) $(LDFLAGS) -Wl,--start-group $(COMPONENT_ARS) $(LIB_ARGS) $(SDK_LIB_ARGS) -Wl,--end-group -o $@
|
||||||
|
|
||||||
|
$(BUILD_DIR) $(FW_BASE) $(BUILD_DIR)sdklib $(LD_DIR):
|
||||||
$(Q) mkdir -p $@
|
$(Q) mkdir -p $@
|
||||||
|
|
||||||
$(FW_FILE_1) $(FW_FILE_2): $(PROGRAM_OUT) $(FIRMWARE_DIR)
|
$(FW_FILE_1) $(FW_FILE_2): $(PROGRAM_OUT) $(FW_BASE)
|
||||||
$(vecho) "FW $@"
|
$(vecho) "FW $@"
|
||||||
$(Q) $(ESPTOOL) elf2image $(ESPTOOL_ARGS) $< -o $(FIRMWARE_DIR)
|
$(Q) $(ESPTOOL) elf2image $(ESPTOOL_ARGS) $< -o $(FW_BASE)
|
||||||
|
|
||||||
$(FW_FILE): $(PROGRAM_OUT) $(FIRMWARE_DIR)
|
$(FW_FILE): $(PROGRAM_OUT) $(FW_BASE)
|
||||||
$(vecho) "FW $@"
|
$(Q) $(IMGTOOL) $(IMGTOOL_ARGS) -bin -boot2 $(PROGRAM_OUT) $(FW_FILE) .text .data .rodata
|
||||||
$(Q) $(ESPTOOL) elf2image --version=2 $(ESPTOOL_ARGS) $< -o $(FW_FILE)
|
|
||||||
|
|
||||||
flash: all
|
ifeq ($(OTA),0)
|
||||||
$(if will_flash, $(call will_flash, "flash"))
|
flash: $(FW_FILE_1) $(FW_FILE_2)
|
||||||
$(ESPTOOL) -p $(ESPPORT) --baud $(ESPBAUD) write_flash $(ESPTOOL_ARGS) \
|
$(ESPTOOL) -p $(ESPPORT) --baud $(ESPBAUD) write_flash $(ESPTOOL_ARGS) $(FW_ADDR_2) $(FW_FILE_2) $(FW_ADDR_1) $(FW_FILE_1)
|
||||||
$(RBOOT_ARGS) 0x2000 $(FW_FILE) $(SPIFFS_ESPTOOL_ARGS)
|
else
|
||||||
$(if did_flash, $(call did_flash, "flash"))
|
flash: $(FW_FILE)
|
||||||
|
$(vecho) "Flashing OTA image slot 0 (bootloader not updated)"
|
||||||
erase_flash:
|
$(ESPTOOL) -p $(ESPPORT) --baud $(ESPBAUD) write_flash $(ESPTOOL_ARGS) 0x2000 $(FW_FILE)
|
||||||
$(if will_flash, $(call will_flash, "erase"))
|
endif
|
||||||
$(ESPTOOL) -p $(ESPPORT) --baud $(ESPBAUD) erase_flash
|
|
||||||
$(if did_flash, $(call did_flash, "erase"))
|
|
||||||
|
|
||||||
size: $(PROGRAM_OUT)
|
size: $(PROGRAM_OUT)
|
||||||
$(Q) $(CROSS)size --format=sysv $(PROGRAM_OUT)
|
$(Q) $(CROSS)size --format=sysv $(PROGRAM_OUT)
|
||||||
|
|
||||||
test: flash
|
test: flash
|
||||||
$(FILTEROUTPUT) --port $(ESPPORT) --baud 115200 --elf $(PROGRAM_OUT)
|
screen $(ESPPORT) 115200
|
||||||
|
|
||||||
# the rebuild target is written like this so it can be run in a parallel build
|
# the rebuild target is written like this so it can be run in a parallel build
|
||||||
# environment without causing weird side effects
|
# environment without causing weird side effects
|
||||||
|
@ -268,7 +365,7 @@ rebuild:
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(Q) rm -rf $(BUILD_DIR)
|
$(Q) rm -rf $(BUILD_DIR)
|
||||||
$(Q) rm -rf $(FIRMWARE_DIR)
|
$(Q) rm -rf $(FW_BASE)
|
||||||
|
|
||||||
# prevent "intermediate" files from being deleted
|
# prevent "intermediate" files from being deleted
|
||||||
.SECONDARY:
|
.SECONDARY:
|
||||||
|
|
294
core/app_main.c
294
core/app_main.c
|
@ -16,29 +16,24 @@
|
||||||
#include "common_macros.h"
|
#include "common_macros.h"
|
||||||
#include "xtensa_ops.h"
|
#include "xtensa_ops.h"
|
||||||
#include "esp/rom.h"
|
#include "esp/rom.h"
|
||||||
#include "esp/uart.h"
|
|
||||||
#include "esp/iomux_regs.h"
|
#include "esp/iomux_regs.h"
|
||||||
|
#include "esp/uart_regs.h"
|
||||||
#include "esp/spi_regs.h"
|
#include "esp/spi_regs.h"
|
||||||
#include "esp/dport_regs.h"
|
#include "esp/dport_regs.h"
|
||||||
#include "esp/wdev_regs.h"
|
#include "esp/wdev_regs.h"
|
||||||
#include "esp/wdt_regs.h"
|
|
||||||
#include "esp/rtcmem_regs.h"
|
|
||||||
#include "esp/hwrand.h"
|
|
||||||
#include "os_version.h"
|
#include "os_version.h"
|
||||||
|
|
||||||
#include "espressif/esp_common.h"
|
#include "espressif/esp_common.h"
|
||||||
#include "espressif/phy_info.h"
|
#include "sdk_internal.h"
|
||||||
#include "esplibs/libmain.h"
|
|
||||||
#include "esplibs/libnet80211.h"
|
|
||||||
#include "esplibs/libphy.h"
|
|
||||||
#include "esplibs/libpp.h"
|
|
||||||
#include "sysparam.h"
|
|
||||||
|
|
||||||
/* This is not declared in any header file (but arguably should be) */
|
/* This is not declared in any header file (but arguably should be) */
|
||||||
|
|
||||||
void user_init(void);
|
void user_init(void);
|
||||||
|
|
||||||
|
#define UART_DIVISOR 1068 // 74906 bps (yeah, I don't understand it either)
|
||||||
#define BOOT_INFO_SIZE 28
|
#define BOOT_INFO_SIZE 28
|
||||||
|
//TODO: phy_info should probably be a struct (no idea about its organization, though)
|
||||||
|
#define PHY_INFO_SIZE 128
|
||||||
|
|
||||||
// These are the offsets of these values within the RTCMEM regions. It appears
|
// These are the offsets of these values within the RTCMEM regions. It appears
|
||||||
// that the ROM saves them to RTCMEM before calling us, and we pull them out of
|
// that the ROM saves them to RTCMEM before calling us, and we pull them out of
|
||||||
|
@ -46,9 +41,31 @@ void user_init(void);
|
||||||
#define RTCMEM_BACKUP_PHY_VER 31
|
#define RTCMEM_BACKUP_PHY_VER 31
|
||||||
#define RTCMEM_SYSTEM_PP_VER 62
|
#define RTCMEM_SYSTEM_PP_VER 62
|
||||||
|
|
||||||
|
#define halt() while (1) {}
|
||||||
|
|
||||||
extern uint32_t _bss_start;
|
extern uint32_t _bss_start;
|
||||||
extern uint32_t _bss_end;
|
extern uint32_t _bss_end;
|
||||||
|
|
||||||
|
// .Ldata003 -- .irom.text+0x0
|
||||||
|
static const uint8_t IROM default_phy_info[PHY_INFO_SIZE] = {
|
||||||
|
0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02,
|
||||||
|
0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05,
|
||||||
|
0x04, 0xfe, 0xfd, 0xff, 0xf0, 0xf0, 0xf0, 0xe0,
|
||||||
|
0xe0, 0xe0, 0xe1, 0x0a, 0xff, 0xff, 0xf8, 0x00,
|
||||||
|
0xf8, 0xf8, 0x52, 0x4e, 0x4a, 0x44, 0x40, 0x38,
|
||||||
|
0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05,
|
||||||
|
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0xe1, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
};
|
||||||
|
|
||||||
// user_init_flag -- .bss+0x0
|
// user_init_flag -- .bss+0x0
|
||||||
uint8_t sdk_user_init_flag;
|
uint8_t sdk_user_init_flag;
|
||||||
|
|
||||||
|
@ -56,18 +73,21 @@ uint8_t sdk_user_init_flag;
|
||||||
struct sdk_info_st sdk_info;
|
struct sdk_info_st sdk_info;
|
||||||
|
|
||||||
// xUserTaskHandle -- .bss+0x28
|
// xUserTaskHandle -- .bss+0x28
|
||||||
TaskHandle_t sdk_xUserTaskHandle;
|
xTaskHandle sdk_xUserTaskHandle;
|
||||||
|
|
||||||
// xWatchDogTaskHandle -- .bss+0x2c
|
// xWatchDogTaskHandle -- .bss+0x2c
|
||||||
TaskHandle_t sdk_xWatchDogTaskHandle;
|
xTaskHandle sdk_xWatchDogTaskHandle;
|
||||||
|
|
||||||
/* Static function prototypes */
|
/* Static function prototypes */
|
||||||
|
|
||||||
static void IRAM get_otp_mac_address(uint8_t *buf);
|
static void IRAM get_otp_mac_address(uint8_t *buf);
|
||||||
static void IRAM set_spi0_divisor(uint32_t divisor);
|
static void IRAM set_spi0_divisor(uint32_t divisor);
|
||||||
|
static int IRAM default_putc(char c);
|
||||||
|
static void IRAM default_putc1(char c);
|
||||||
static void zero_bss(void);
|
static void zero_bss(void);
|
||||||
static void init_networking(sdk_phy_info_t *phy_info, uint8_t *mac_addr);
|
static void init_networking(uint8_t *phy_info, uint8_t *mac_addr);
|
||||||
static void init_g_ic(void);
|
static void init_g_ic(void);
|
||||||
|
static void dump_excinfo(void);
|
||||||
static void user_start_phase2(void);
|
static void user_start_phase2(void);
|
||||||
static void dump_flash_sector(uint32_t start_sector, uint32_t length);
|
static void dump_flash_sector(uint32_t start_sector, uint32_t length);
|
||||||
static void dump_flash_config_sectors(uint32_t start_sector);
|
static void dump_flash_config_sectors(uint32_t start_sector);
|
||||||
|
@ -84,11 +104,11 @@ static void IRAM get_otp_mac_address(uint8_t *buf) {
|
||||||
if (!(otp_flags & 0x8000)) {
|
if (!(otp_flags & 0x8000)) {
|
||||||
//FIXME: do we really need this check?
|
//FIXME: do we really need this check?
|
||||||
printf("Firmware ONLY supports ESP8266!!!\n");
|
printf("Firmware ONLY supports ESP8266!!!\n");
|
||||||
abort();
|
halt();
|
||||||
}
|
}
|
||||||
if (otp_id0 == 0 && otp_id1 == 0) {
|
if (otp_id0 == 0 && otp_id1 == 0) {
|
||||||
printf("empty otp\n");
|
printf("empty otp\n");
|
||||||
abort();
|
halt();
|
||||||
}
|
}
|
||||||
if (otp_flags & 0x1000) {
|
if (otp_flags & 0x1000) {
|
||||||
// If bit 12 is set, it indicates that the vendor portion of the MAC
|
// If bit 12 is set, it indicates that the vendor portion of the MAC
|
||||||
|
@ -129,14 +149,39 @@ static void IRAM set_spi0_divisor(uint32_t divisor) {
|
||||||
SPI(0).CTRL0 = SET_FIELD(SPI(0).CTRL0, SPI_CTRL0_CLOCK, clkdiv);
|
SPI(0).CTRL0 = SET_FIELD(SPI(0).CTRL0, SPI_CTRL0_CLOCK, clkdiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// .text+0x148
|
||||||
static void IRAM default_putc(char c) {
|
void IRAM sdk_user_fatal_exception_handler(void) {
|
||||||
uart_putc(0, c);
|
if (!sdk_NMIIrqIsOn) {
|
||||||
|
vPortEnterCritical();
|
||||||
|
do {
|
||||||
|
DPORT.DPORT0 &= 0xffffffe0;
|
||||||
|
} while (DPORT.DPORT0 & 0x00000001);
|
||||||
|
}
|
||||||
|
Cache_Read_Disable();
|
||||||
|
Cache_Read_Enable(0, 0, 1);
|
||||||
|
dump_excinfo();
|
||||||
|
while (FIELD2VAL(UART_STATUS_TXFIFO_COUNT, UART(0).STATUS)) {}
|
||||||
|
while (FIELD2VAL(UART_STATUS_TXFIFO_COUNT, UART(1).STATUS)) {}
|
||||||
|
sdk_system_restart_in_nmi();
|
||||||
|
halt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_newlib_locks(void);
|
// .Lfunc003 -- .text+0x1d0
|
||||||
extern uint8_t sdk_wDevCtrl[];
|
static int IRAM default_putc(char c) {
|
||||||
void nano_malloc_insert_chunk(void *start, size_t size);
|
while (FIELD2VAL(UART_STATUS_TXFIFO_COUNT, UART(0).STATUS) > 125) {}
|
||||||
|
UART(0).FIFO = c;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// .Lfunc004 -- .text+0x1f4
|
||||||
|
static void IRAM default_putc1(char c) {
|
||||||
|
if (c == '\n') {
|
||||||
|
default_putc('\r');
|
||||||
|
} else if (c == '\r') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
default_putc(c);
|
||||||
|
}
|
||||||
|
|
||||||
// .text+0x258
|
// .text+0x258
|
||||||
void IRAM sdk_user_start(void) {
|
void IRAM sdk_user_start(void) {
|
||||||
|
@ -150,8 +195,6 @@ void IRAM sdk_user_start(void) {
|
||||||
uint32_t cksum_len;
|
uint32_t cksum_len;
|
||||||
uint32_t cksum_value;
|
uint32_t cksum_value;
|
||||||
uint32_t ic_flash_addr;
|
uint32_t ic_flash_addr;
|
||||||
uint32_t sysparam_addr;
|
|
||||||
sysparam_status_t status;
|
|
||||||
|
|
||||||
SPI(0).USER0 |= SPI_USER0_CS_SETUP;
|
SPI(0).USER0 |= SPI_USER0_CS_SETUP;
|
||||||
sdk_SPIRead(0, buf32, 4);
|
sdk_SPIRead(0, buf32, 4);
|
||||||
|
@ -174,32 +217,25 @@ void IRAM sdk_user_start(void) {
|
||||||
}
|
}
|
||||||
switch (buf8[3] >> 4) {
|
switch (buf8[3] >> 4) {
|
||||||
case 0x0: // 4 Mbit (512 KByte)
|
case 0x0: // 4 Mbit (512 KByte)
|
||||||
flash_size = 524288;
|
flash_sectors = 128;
|
||||||
break;
|
break;
|
||||||
case 0x1: // 2 Mbit (256 Kbyte)
|
case 0x1: // 2 Mbit (256 Kbyte)
|
||||||
flash_size = 262144;
|
flash_sectors = 64;
|
||||||
break;
|
break;
|
||||||
case 0x2: // 8 Mbit (1 Mbyte)
|
case 0x2: // 8 Mbit (1 Mbyte)
|
||||||
flash_size = 1048576;
|
flash_sectors = 256;
|
||||||
break;
|
break;
|
||||||
case 0x3: // 16 Mbit (2 Mbyte)
|
case 0x3: // 16 Mbit (2 Mbyte)
|
||||||
case 0x5: // 16 Mbit (2 Mbyte)
|
flash_sectors = 512;
|
||||||
flash_size = 2097152;
|
|
||||||
break;
|
break;
|
||||||
case 0x4: // 32 Mbit (4 Mbyte)
|
case 0x4: // 32 Mbit (4 Mbyte)
|
||||||
case 0x6: // 32 Mbit (4 Mbyte)
|
flash_sectors = 1024;
|
||||||
flash_size = 4194304;
|
|
||||||
break;
|
|
||||||
case 0x8: // 64 Mbit (8 Mbyte)
|
|
||||||
flash_size = 8388608;
|
|
||||||
break;
|
|
||||||
case 0x9: // 128 Mbit (16 Mbyte)
|
|
||||||
flash_size = 16777216;
|
|
||||||
break;
|
break;
|
||||||
default: // Invalid -- Assume 4 Mbit (512 KByte)
|
default: // Invalid -- Assume 4 Mbit (512 KByte)
|
||||||
flash_size = 524288;
|
flash_sectors = 128;
|
||||||
}
|
}
|
||||||
flash_sectors = flash_size / sdk_flashchip.sector_size;
|
//FIXME: we should probably calculate flash_sectors by starting with flash_size and dividing by sdk_flashchip.sector_size instead of vice-versa.
|
||||||
|
flash_size = flash_sectors * 4096;
|
||||||
sdk_flashchip.chip_size = flash_size;
|
sdk_flashchip.chip_size = flash_size;
|
||||||
set_spi0_divisor(flash_speed_divisor);
|
set_spi0_divisor(flash_speed_divisor);
|
||||||
sdk_SPIRead(flash_size - 4096, buf32, BOOT_INFO_SIZE);
|
sdk_SPIRead(flash_size - 4096, buf32, BOOT_INFO_SIZE);
|
||||||
|
@ -211,16 +247,7 @@ void IRAM sdk_user_start(void) {
|
||||||
sdk_SPIRead(ic_flash_addr, buf32, sizeof(struct sdk_g_ic_saved_st));
|
sdk_SPIRead(ic_flash_addr, buf32, sizeof(struct sdk_g_ic_saved_st));
|
||||||
Cache_Read_Enable(0, 0, 1);
|
Cache_Read_Enable(0, 0, 1);
|
||||||
zero_bss();
|
zero_bss();
|
||||||
sdk_os_install_putc1(default_putc);
|
sdk_os_install_putc1(default_putc1);
|
||||||
|
|
||||||
/* HACK Reclaim a region of unused bss from wdev.o. This would not be
|
|
||||||
* necessary if the source code to wdev were available, and then it would
|
|
||||||
* not be a fragmented area, but the extra memory is desparately needed and
|
|
||||||
* it is in very useful dram. */
|
|
||||||
nano_malloc_insert_chunk((void *)(sdk_wDevCtrl + 0x2190), 8000);
|
|
||||||
|
|
||||||
init_newlib_locks();
|
|
||||||
|
|
||||||
if (cksum_magic == 0xffffffff) {
|
if (cksum_magic == 0xffffffff) {
|
||||||
// No checksum required
|
// No checksum required
|
||||||
} else if ((cksum_magic == 0x55aa55aa) &&
|
} else if ((cksum_magic == 0x55aa55aa) &&
|
||||||
|
@ -233,35 +260,21 @@ void IRAM sdk_user_start(void) {
|
||||||
}
|
}
|
||||||
memcpy(&sdk_g_ic.s, buf32, sizeof(struct sdk_g_ic_saved_st));
|
memcpy(&sdk_g_ic.s, buf32, sizeof(struct sdk_g_ic_saved_st));
|
||||||
|
|
||||||
// By default, put the sysparam region just below the config sectors at the
|
|
||||||
// top of the flash space, and allowing one extra sector spare.
|
|
||||||
sysparam_addr = flash_size - (5 + DEFAULT_SYSPARAM_SECTORS) * sdk_flashchip.sector_size;
|
|
||||||
status = sysparam_init(sysparam_addr, flash_size);
|
|
||||||
if (status == SYSPARAM_NOTFOUND) {
|
|
||||||
status = sysparam_create_area(sysparam_addr, DEFAULT_SYSPARAM_SECTORS, false);
|
|
||||||
if (status == SYSPARAM_OK) {
|
|
||||||
status = sysparam_init(sysparam_addr, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (status != SYSPARAM_OK) {
|
|
||||||
printf("WARNING: Could not initialize sysparams (%d)!\n", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
user_start_phase2();
|
user_start_phase2();
|
||||||
}
|
}
|
||||||
|
|
||||||
// .text+0x3a8
|
// .text+0x3a8
|
||||||
void IRAM vApplicationStackOverflowHook(TaskHandle_t task, char *task_name) {
|
void IRAM vApplicationStackOverflowHook(xTaskHandle task, char *task_name) {
|
||||||
printf("Task stack overflow (high water mark=%lu name=\"%s\")\n", uxTaskGetStackHighWaterMark(task), task_name);
|
printf("\"%s\"(stack_size = %lu) overflow the heap_size.\n", task_name, uxTaskGetStackHighWaterMark(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
// .text+0x3d8
|
// .text+0x3d8
|
||||||
void __attribute__((weak)) IRAM vApplicationIdleHook(void) {
|
void IRAM vApplicationIdleHook(void) {
|
||||||
printf("idle %u\n", WDEV.SYS_TIME);
|
printf("idle %u\n", WDEV.SYS_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
// .text+0x404
|
// .text+0x404
|
||||||
void __attribute__((weak)) IRAM vApplicationTickHook(void) {
|
void IRAM vApplicationTickHook(void) {
|
||||||
printf("tick %u\n", WDEV.SYS_TIME);
|
printf("tick %u\n", WDEV.SYS_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,26 +288,13 @@ static void zero_bss(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// .Lfunc006 -- .irom0.text+0x70
|
// .Lfunc006 -- .irom0.text+0x70
|
||||||
static void init_networking(sdk_phy_info_t *phy_info, uint8_t *mac_addr) {
|
static void init_networking(uint8_t *phy_info, uint8_t *mac_addr) {
|
||||||
// The call to sdk_register_chipv6_phy appears to change the bus clock,
|
|
||||||
// perhaps from 40MHz to 26MHz, at least it has such an effect on the uart
|
|
||||||
// baud rate. The caller flushes the TX fifos.
|
|
||||||
if (sdk_register_chipv6_phy(phy_info)) {
|
if (sdk_register_chipv6_phy(phy_info)) {
|
||||||
printf("FATAL: sdk_register_chipv6_phy failed");
|
printf("FATAL: sdk_register_chipv6_phy failed");
|
||||||
abort();
|
halt();
|
||||||
}
|
}
|
||||||
|
sdk_uart_div_modify(0, UART_DIVISOR);
|
||||||
// The boot rom initializes uart0 for a 115200 baud rate but the bus clock
|
sdk_uart_div_modify(1, UART_DIVISOR);
|
||||||
// does not appear to be as expected so the initial baud rate is actually
|
|
||||||
// 74906. On a cold boot, to keep the 74906 baud rate the uart0 divisor
|
|
||||||
// would need to changed here to 74906. On a warm boot the bus clock is
|
|
||||||
// expected to have already been set so the boot baud rate is 115200.
|
|
||||||
// Reset the rate here and settle on a 115200 baud rate.
|
|
||||||
if (sdk_rst_if.reason > 0) {
|
|
||||||
uart_set_baud(0, 115200);
|
|
||||||
uart_set_baud(1, 115200);
|
|
||||||
}
|
|
||||||
|
|
||||||
sdk_phy_disable_agc();
|
sdk_phy_disable_agc();
|
||||||
sdk_ieee80211_phy_init(sdk_g_ic.s.phy_mode);
|
sdk_ieee80211_phy_init(sdk_g_ic.s.phy_mode);
|
||||||
sdk_lmacInit();
|
sdk_lmacInit();
|
||||||
|
@ -331,13 +331,13 @@ static void init_g_ic(void) {
|
||||||
if (sdk_g_ic.s._unknown310 > 4) {
|
if (sdk_g_ic.s._unknown310 > 4) {
|
||||||
sdk_g_ic.s._unknown310 = 4;
|
sdk_g_ic.s._unknown310 = 4;
|
||||||
}
|
}
|
||||||
if (sdk_g_ic.s.sta_ssid.ssid_length == 0xffffffff) {
|
if (sdk_g_ic.s._unknown1e4._unknown1e4 == 0xffffffff) {
|
||||||
bzero(&sdk_g_ic.s.sta_ssid, sizeof(sdk_g_ic.s.sta_ssid));
|
bzero(&sdk_g_ic.s._unknown1e4, sizeof(sdk_g_ic.s._unknown1e4));
|
||||||
bzero(&sdk_g_ic.s.sta_password, sizeof(sdk_g_ic.s.sta_password));
|
bzero(&sdk_g_ic.s._unknown20f, sizeof(sdk_g_ic.s._unknown20f));
|
||||||
}
|
}
|
||||||
sdk_g_ic.s.wifi_led_enable = 0;
|
sdk_g_ic.s.wifi_led_enable = 0;
|
||||||
if (sdk_g_ic.s.sta_bssid_set > 1) {
|
if (sdk_g_ic.s._unknown281 > 1) {
|
||||||
sdk_g_ic.s.sta_bssid_set = 0;
|
sdk_g_ic.s._unknown281 = 0;
|
||||||
}
|
}
|
||||||
if (sdk_g_ic.s.ap_number > 5) {
|
if (sdk_g_ic.s.ap_number > 5) {
|
||||||
sdk_g_ic.s.ap_number = 1;
|
sdk_g_ic.s.ap_number = 1;
|
||||||
|
@ -347,6 +347,46 @@ static void init_g_ic(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// .Lfunc008 -- .irom0.text+0x2a0
|
||||||
|
static void dump_excinfo(void) {
|
||||||
|
uint32_t exccause, epc1, epc2, epc3, excvaddr, depc, excsave1;
|
||||||
|
uint32_t excinfo[8];
|
||||||
|
|
||||||
|
RSR(exccause, exccause);
|
||||||
|
printf("Fatal exception (%d): \n", (int)exccause);
|
||||||
|
RSR(epc1, epc1);
|
||||||
|
RSR(epc2, epc2);
|
||||||
|
RSR(epc3, epc3);
|
||||||
|
RSR(excvaddr, excvaddr);
|
||||||
|
RSR(depc, depc);
|
||||||
|
RSR(excsave1, excsave1);
|
||||||
|
printf("%s=0x%08x\n", "epc1", epc1);
|
||||||
|
printf("%s=0x%08x\n", "epc2", epc2);
|
||||||
|
printf("%s=0x%08x\n", "epc3", epc3);
|
||||||
|
printf("%s=0x%08x\n", "excvaddr", excvaddr);
|
||||||
|
printf("%s=0x%08x\n", "depc", depc);
|
||||||
|
printf("%s=0x%08x\n", "excsave1", excsave1);
|
||||||
|
sdk_system_rtc_mem_read(0, excinfo, 32); // Why?
|
||||||
|
excinfo[0] = 2;
|
||||||
|
excinfo[1] = exccause;
|
||||||
|
excinfo[2] = epc1;
|
||||||
|
excinfo[3] = epc2;
|
||||||
|
excinfo[4] = epc3;
|
||||||
|
excinfo[5] = excvaddr;
|
||||||
|
excinfo[6] = depc;
|
||||||
|
excinfo[7] = excsave1;
|
||||||
|
sdk_system_rtc_mem_write(0, excinfo, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
// .irom0.text+0x368
|
||||||
|
int sdk_uart_rx_one_char(char *buf) {
|
||||||
|
if (FIELD2VAL(UART_STATUS_RXFIFO_COUNT, UART(0).STATUS)) {
|
||||||
|
*buf = UART(0).FIFO;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// .irom0.text+0x398
|
// .irom0.text+0x398
|
||||||
void sdk_wdt_init(void) {
|
void sdk_wdt_init(void) {
|
||||||
WDT.CTRL &= ~WDT_CTRL_ENABLE;
|
WDT.CTRL &= ~WDT_CTRL_ENABLE;
|
||||||
|
@ -359,16 +399,10 @@ void sdk_wdt_init(void) {
|
||||||
sdk_pp_soft_wdt_init();
|
sdk_pp_soft_wdt_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void *xPortSupervisorStackPointer;
|
|
||||||
|
|
||||||
// .irom0.text+0x474
|
// .irom0.text+0x474
|
||||||
void sdk_user_init_task(void *params) {
|
void sdk_user_init_task(void *params) {
|
||||||
int phy_ver, pp_ver;
|
int phy_ver, pp_ver;
|
||||||
|
|
||||||
/* The start up stack is not used after scheduling has started, so all of
|
|
||||||
* the top area of RAM which was stack can be used for the dynamic heap. */
|
|
||||||
xPortSupervisorStackPointer = (void *)0x40000000;
|
|
||||||
|
|
||||||
sdk_ets_timer_init();
|
sdk_ets_timer_init();
|
||||||
printf("\nESP-Open-SDK ver: %s compiled @ %s %s\n", OS_VERSION_STR, __DATE__, __TIME__);
|
printf("\nESP-Open-SDK ver: %s compiled @ %s %s\n", OS_VERSION_STR, __DATE__, __TIME__);
|
||||||
phy_ver = RTCMEM_BACKUP[RTCMEM_BACKUP_PHY_VER] >> 16;
|
phy_ver = RTCMEM_BACKUP[RTCMEM_BACKUP_PHY_VER] >> 16;
|
||||||
|
@ -378,24 +412,18 @@ void sdk_user_init_task(void *params) {
|
||||||
user_init();
|
user_init();
|
||||||
sdk_user_init_flag = 1;
|
sdk_user_init_flag = 1;
|
||||||
sdk_wifi_mode_set(sdk_g_ic.s.wifi_mode);
|
sdk_wifi_mode_set(sdk_g_ic.s.wifi_mode);
|
||||||
if (sdk_g_ic.s.wifi_mode == STATION_MODE) {
|
if (sdk_g_ic.s.wifi_mode == 1) {
|
||||||
sdk_wifi_station_start();
|
sdk_wifi_station_start();
|
||||||
LOCK_TCPIP_CORE();
|
|
||||||
netif_set_default(sdk_g_ic.v.station_netif_info->netif);
|
netif_set_default(sdk_g_ic.v.station_netif_info->netif);
|
||||||
UNLOCK_TCPIP_CORE();
|
|
||||||
}
|
}
|
||||||
if (sdk_g_ic.s.wifi_mode == SOFTAP_MODE) {
|
if (sdk_g_ic.s.wifi_mode == 2) {
|
||||||
sdk_wifi_softap_start();
|
sdk_wifi_softap_start();
|
||||||
LOCK_TCPIP_CORE();
|
|
||||||
netif_set_default(sdk_g_ic.v.softap_netif_info->netif);
|
netif_set_default(sdk_g_ic.v.softap_netif_info->netif);
|
||||||
UNLOCK_TCPIP_CORE();
|
|
||||||
}
|
}
|
||||||
if (sdk_g_ic.s.wifi_mode == STATIONAP_MODE) {
|
if (sdk_g_ic.s.wifi_mode == 3) {
|
||||||
sdk_wifi_station_start();
|
sdk_wifi_station_start();
|
||||||
sdk_wifi_softap_start();
|
sdk_wifi_softap_start();
|
||||||
LOCK_TCPIP_CORE();
|
netif_set_default(sdk_g_ic.v.softap_netif_info->netif);
|
||||||
netif_set_default(sdk_g_ic.v.station_netif_info->netif);
|
|
||||||
UNLOCK_TCPIP_CORE();
|
|
||||||
}
|
}
|
||||||
if (sdk_wifi_station_get_auto_connect()) {
|
if (sdk_wifi_station_get_auto_connect()) {
|
||||||
sdk_wifi_station_connect();
|
sdk_wifi_station_connect();
|
||||||
|
@ -403,17 +431,14 @@ void sdk_user_init_task(void *params) {
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void (*__init_array_start)(void);
|
|
||||||
extern void (*__init_array_end)(void);
|
|
||||||
|
|
||||||
// .Lfunc009 -- .irom0.text+0x5b4
|
// .Lfunc009 -- .irom0.text+0x5b4
|
||||||
static __attribute__((noinline)) void user_start_phase2(void) {
|
static void user_start_phase2(void) {
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
sdk_phy_info_t phy_info, default_phy_info;
|
uint8_t *phy_info;
|
||||||
|
|
||||||
sdk_system_rtc_mem_read(0, &sdk_rst_if, sizeof(sdk_rst_if));
|
sdk_system_rtc_mem_read(0, &sdk_rst_if, sizeof(sdk_rst_if));
|
||||||
if (sdk_rst_if.reason > 3) {
|
if (sdk_rst_if.version > 3) {
|
||||||
// Bad reason. Probably garbage.
|
// Bad version number. Probably garbage.
|
||||||
bzero(&sdk_rst_if, sizeof(sdk_rst_if));
|
bzero(&sdk_rst_if, sizeof(sdk_rst_if));
|
||||||
}
|
}
|
||||||
buf = malloc(sizeof(sdk_rst_if));
|
buf = malloc(sizeof(sdk_rst_if));
|
||||||
|
@ -423,42 +448,27 @@ static __attribute__((noinline)) void user_start_phase2(void) {
|
||||||
sdk_sleep_reset_analog_rtcreg_8266();
|
sdk_sleep_reset_analog_rtcreg_8266();
|
||||||
get_otp_mac_address(sdk_info.sta_mac_addr);
|
get_otp_mac_address(sdk_info.sta_mac_addr);
|
||||||
sdk_wifi_softap_cacl_mac(sdk_info.softap_mac_addr, sdk_info.sta_mac_addr);
|
sdk_wifi_softap_cacl_mac(sdk_info.softap_mac_addr, sdk_info.sta_mac_addr);
|
||||||
sdk_info.softap_ipaddr.addr = 0x0104a8c0; // 192.168.4.1
|
sdk_info._unknown0 = 0x0104a8c0;
|
||||||
sdk_info.softap_netmask.addr = 0x00ffffff; // 255.255.255.0
|
sdk_info._unknown1 = 0x00ffffff;
|
||||||
sdk_info.softap_gw.addr = 0x0104a8c0; // 192.168.4.1
|
sdk_info._unknown2 = 0x0104a8c0;
|
||||||
init_g_ic();
|
init_g_ic();
|
||||||
|
phy_info = malloc(PHY_INFO_SIZE);
|
||||||
read_saved_phy_info(&phy_info);
|
sdk_spi_flash_read(sdk_flashchip.chip_size - sdk_flashchip.sector_size * 4, (uint32_t *)phy_info, PHY_INFO_SIZE);
|
||||||
get_default_phy_info(&default_phy_info);
|
|
||||||
|
|
||||||
if (phy_info.version != default_phy_info.version) {
|
|
||||||
/* Versions don't match, use default for PHY info
|
|
||||||
(may be a blank config sector, or a new default version.)
|
|
||||||
*/
|
|
||||||
memcpy(&phy_info, &default_phy_info, sizeof(sdk_phy_info_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for UARTs to finish sending anything in their queues.
|
// Wait for UARTs to finish sending anything in their queues.
|
||||||
uart_flush_txfifo(0);
|
while (FIELD2VAL(UART_STATUS_TXFIFO_COUNT, UART(0).STATUS) > 0) {}
|
||||||
uart_flush_txfifo(1);
|
while (FIELD2VAL(UART_STATUS_TXFIFO_COUNT, UART(1).STATUS) > 0) {}
|
||||||
|
|
||||||
init_networking(&phy_info, sdk_info.sta_mac_addr);
|
if (phy_info[0] != 5) {
|
||||||
|
// Bad version byte. Discard what we read and use default values
|
||||||
srand(hwrand()); /* seed libc rng */
|
// instead.
|
||||||
|
memcpy(phy_info, default_phy_info, PHY_INFO_SIZE);
|
||||||
// Set intial CPU clock speed to 160MHz if necessary
|
|
||||||
_Static_assert(configCPU_CLOCK_HZ == 80000000 || configCPU_CLOCK_HZ == 160000000, "FreeRTOSConfig must define initial clock speed as either 80MHz or 160MHz");
|
|
||||||
sdk_system_update_cpu_freq(configCPU_CLOCK_HZ / 1000000);
|
|
||||||
|
|
||||||
// Call gcc constructor functions
|
|
||||||
void (**ctor)(void);
|
|
||||||
for ( ctor = &__init_array_start; ctor != &__init_array_end; ++ctor) {
|
|
||||||
(*ctor)();
|
|
||||||
}
|
}
|
||||||
|
init_networking(phy_info, sdk_info.sta_mac_addr);
|
||||||
|
free(phy_info);
|
||||||
tcpip_init(NULL, NULL);
|
tcpip_init(NULL, NULL);
|
||||||
sdk_wdt_init();
|
sdk_wdt_init();
|
||||||
xTaskCreate(sdk_user_init_task, "uiT", 1024, 0, 14, &sdk_xUserTaskHandle);
|
xTaskCreate(sdk_user_init_task, (signed char *)"uiT", 1024, 0, 14, &sdk_xUserTaskHandle);
|
||||||
vTaskStartScheduler();
|
vTaskStartScheduler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,11 +495,11 @@ static void dump_flash_sector(uint32_t start_sector, uint32_t length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// .Lfunc011 -- .irom0.text+0x790
|
// .Lfunc011 -- .irom0.text+0x790
|
||||||
static __attribute__((noinline)) void dump_flash_config_sectors(uint32_t start_sector) {
|
static void dump_flash_config_sectors(uint32_t start_sector) {
|
||||||
printf("system param error\n");
|
printf("system param error\n");
|
||||||
// Note: original SDK code didn't dump PHY info
|
// Note: original SDK code didn't dump PHY info
|
||||||
printf("phy_info:\n");
|
printf("phy_info:\n");
|
||||||
dump_flash_sector(start_sector, sizeof(sdk_phy_info_t));
|
dump_flash_sector(start_sector, PHY_INFO_SIZE);
|
||||||
printf("\ng_ic saved 0:\n");
|
printf("\ng_ic saved 0:\n");
|
||||||
dump_flash_sector(start_sector + 1, sizeof(struct sdk_g_ic_saved_st));
|
dump_flash_sector(start_sector + 1, sizeof(struct sdk_g_ic_saved_st));
|
||||||
printf("\ng_ic saved 1:\n");
|
printf("\ng_ic saved 1:\n");
|
||||||
|
|
|
@ -4,22 +4,22 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void * __attribute__((weak)) operator new(size_t size)
|
void *operator new(size_t size)
|
||||||
{
|
{
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * __attribute__((weak)) operator new[](size_t size)
|
void *operator new[](size_t size)
|
||||||
{
|
{
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __attribute__((weak)) operator delete(void * ptr)
|
void operator delete(void * ptr)
|
||||||
{
|
{
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __attribute__((weak)) operator delete[](void * ptr)
|
void operator delete[](void * ptr)
|
||||||
{
|
{
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,245 +0,0 @@
|
||||||
/* Code for dumping status/debug output/etc, including fatal
|
|
||||||
* exception handling & abort implementation.
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
*
|
|
||||||
* Partially reverse engineered from MIT licensed Espressif RTOS SDK Copyright (C) Espressif Systems.
|
|
||||||
* Additions Copyright (C) 2015 Superhouse Automation Pty Ltd
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <FreeRTOS.h>
|
|
||||||
#include <task.h>
|
|
||||||
#include <malloc.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "debug_dumps.h"
|
|
||||||
#include "common_macros.h"
|
|
||||||
#include "xtensa_ops.h"
|
|
||||||
#include "esp/rom.h"
|
|
||||||
#include "esp/uart.h"
|
|
||||||
#include "esp/dport_regs.h"
|
|
||||||
#include "espressif/esp_common.h"
|
|
||||||
#include "esplibs/libmain.h"
|
|
||||||
#include "user_exception.h"
|
|
||||||
|
|
||||||
/* Forward declarations */
|
|
||||||
static void IRAM fatal_handler_prelude(void);
|
|
||||||
/* Inner parts of crash handlers */
|
|
||||||
typedef void __attribute__((noreturn)) (*fatal_exception_handler_fn)(uint32_t *sp, bool registers_saved_on_stack);
|
|
||||||
static void __attribute__((noreturn)) standard_fatal_exception_handler_inner(uint32_t *sp, bool registers_saved_on_stack);
|
|
||||||
static void __attribute__((noreturn)) second_fatal_exception_handler_inner(uint32_t *sp, bool registers_saved_on_stack);
|
|
||||||
static void __attribute__((noinline)) __attribute__((noreturn)) abort_handler_inner(uint32_t *caller, uint32_t *sp);
|
|
||||||
|
|
||||||
static IRAM_DATA fatal_exception_handler_fn fatal_exception_handler_inner = standard_fatal_exception_handler_inner;
|
|
||||||
|
|
||||||
static void (*user_exception_handler)(void) = NULL;
|
|
||||||
|
|
||||||
/* fatal_exception_handler called from any unhandled user exception
|
|
||||||
*
|
|
||||||
* (similar to a hard fault on other processor architectures)
|
|
||||||
*
|
|
||||||
* This function is run from IRAM, but the majority of the handler
|
|
||||||
* runs from flash after fatal_handler_prelude ensures it is mapped
|
|
||||||
* safely.
|
|
||||||
*/
|
|
||||||
void IRAM __attribute__((noreturn)) fatal_exception_handler(uint32_t *sp, bool registers_saved_on_stack) {
|
|
||||||
fatal_handler_prelude();
|
|
||||||
fatal_exception_handler_fn inner_fn = fatal_exception_handler_inner;
|
|
||||||
inner_fn(sp, registers_saved_on_stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Abort implementation
|
|
||||||
*
|
|
||||||
* Replaces the weak-linked abort implementation provided by newlib libc.
|
|
||||||
*
|
|
||||||
* Disable interrupts, enable flash mapping, dump stack & caller
|
|
||||||
* address, restart.
|
|
||||||
*
|
|
||||||
* This function is run from IRAM, but the majority of the abort
|
|
||||||
* handler runs from flash after fatal_handler_prelude ensures it is
|
|
||||||
* mapped safely.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void IRAM abort(void) {
|
|
||||||
uint32_t *sp, *caller;
|
|
||||||
RETADDR(caller);
|
|
||||||
/* abort() caller is one instruction before our return address */
|
|
||||||
caller = (uint32_t *)((intptr_t)caller - 3);
|
|
||||||
SP(sp);
|
|
||||||
fatal_handler_prelude();
|
|
||||||
abort_handler_inner(caller, sp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dump exception information from special function registers */
|
|
||||||
static void dump_excinfo(void) {
|
|
||||||
uint32_t exccause, epc1, epc2, epc3, excvaddr, depc, excsave1;
|
|
||||||
uint32_t excinfo[8];
|
|
||||||
|
|
||||||
RSR(exccause, exccause);
|
|
||||||
printf("Fatal exception (%d): \n", (int)exccause);
|
|
||||||
RSR(epc1, epc1);
|
|
||||||
RSR(epc2, epc2);
|
|
||||||
RSR(epc3, epc3);
|
|
||||||
RSR(excvaddr, excvaddr);
|
|
||||||
RSR(depc, depc);
|
|
||||||
RSR(excsave1, excsave1);
|
|
||||||
printf("%s=0x%08x\n", "epc1", epc1);
|
|
||||||
printf("%s=0x%08x\n", "epc2", epc2);
|
|
||||||
printf("%s=0x%08x\n", "epc3", epc3);
|
|
||||||
printf("%s=0x%08x\n", "excvaddr", excvaddr);
|
|
||||||
printf("%s=0x%08x\n", "depc", depc);
|
|
||||||
printf("%s=0x%08x\n", "excsave1", excsave1);
|
|
||||||
sdk_system_rtc_mem_read(0, excinfo, 32); // Why?
|
|
||||||
excinfo[0] = 2;
|
|
||||||
excinfo[1] = exccause;
|
|
||||||
excinfo[2] = epc1;
|
|
||||||
excinfo[3] = epc2;
|
|
||||||
excinfo[4] = epc3;
|
|
||||||
excinfo[5] = excvaddr;
|
|
||||||
excinfo[6] = depc;
|
|
||||||
excinfo[7] = excsave1;
|
|
||||||
sdk_system_rtc_mem_write(0, excinfo, 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* dump stack memory (frames above sp) to stdout
|
|
||||||
|
|
||||||
There's a lot of smart stuff we could do while dumping stack
|
|
||||||
but for now we just dump what looks like our stack region.
|
|
||||||
|
|
||||||
Probably dumps more memory than it needs to, the first instance of
|
|
||||||
0xa5a5a5a5 probably constitutes the end of our stack.
|
|
||||||
*/
|
|
||||||
void dump_stack(uint32_t *sp) {
|
|
||||||
printf("\nStack: SP=%p\n", sp);
|
|
||||||
for(uint32_t *p = sp; p < sp + 32; p += 4) {
|
|
||||||
if((intptr_t)p >= 0x3fffc000) {
|
|
||||||
break; /* approximate end of RAM */
|
|
||||||
}
|
|
||||||
printf("%p: %08x %08x %08x %08x\n", p, p[0], p[1], p[2], p[3]);
|
|
||||||
if(p[0] == 0xa5a5a5a5 && p[1] == 0xa5a5a5a5
|
|
||||||
&& p[2] == 0xa5a5a5a5 && p[3] == 0xa5a5a5a5) {
|
|
||||||
break; /* FreeRTOS uses this pattern to mark untouched stack space */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dump normal registers that were stored above 'sp'
|
|
||||||
by the exception handler preamble
|
|
||||||
*/
|
|
||||||
void dump_registers_in_exception_handler(uint32_t *sp) {
|
|
||||||
uint32_t excsave1;
|
|
||||||
uint32_t *saved = sp - (0x50 / sizeof(uint32_t));
|
|
||||||
printf("Registers:\n");
|
|
||||||
RSR(excsave1, excsave1);
|
|
||||||
printf("a0 %08x ", excsave1);
|
|
||||||
printf("a1 %08x ", (intptr_t)sp);
|
|
||||||
for(int a = 2; a < 14; a++) {
|
|
||||||
printf("a%-2d %08x%c", a, saved[a+3], a == 3 || a == 7 || a == 11 ? '\n':' ');
|
|
||||||
}
|
|
||||||
printf("SAR %08x\n", saved[0x13]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __attribute__((noreturn)) post_crash_reset(void) {
|
|
||||||
uart_flush_txfifo(0);
|
|
||||||
uart_flush_txfifo(1);
|
|
||||||
sdk_system_restart_in_nmi();
|
|
||||||
while(1) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Prelude ensures exceptions/NMI off and flash is mapped, allowing
|
|
||||||
calls to non-IRAM functions.
|
|
||||||
*/
|
|
||||||
static void IRAM fatal_handler_prelude(void) {
|
|
||||||
if (!sdk_NMIIrqIsOn) {
|
|
||||||
vPortEnterCritical();
|
|
||||||
do {
|
|
||||||
DPORT.DPORT0 &= 0xffffffe0;
|
|
||||||
} while (DPORT.DPORT0 & 0x00000001);
|
|
||||||
}
|
|
||||||
Cache_Read_Disable();
|
|
||||||
Cache_Read_Enable(0, 0, 1);
|
|
||||||
|
|
||||||
if (user_exception_handler != NULL) {
|
|
||||||
user_exception_handler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Main part of fatal exception handler, is run from flash to save
|
|
||||||
some IRAM.
|
|
||||||
*/
|
|
||||||
static void standard_fatal_exception_handler_inner(uint32_t *sp, bool registers_saved_on_stack) {
|
|
||||||
/* Replace the fatal exception handler 'inner' function so we
|
|
||||||
don't end up in a crash loop if this handler crashes. */
|
|
||||||
fatal_exception_handler_inner = second_fatal_exception_handler_inner;
|
|
||||||
dump_excinfo();
|
|
||||||
if (sp) {
|
|
||||||
if (registers_saved_on_stack) {
|
|
||||||
dump_registers_in_exception_handler(sp);
|
|
||||||
}
|
|
||||||
dump_stack(sp);
|
|
||||||
}
|
|
||||||
dump_heapinfo();
|
|
||||||
post_crash_reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is the exception handler that gets called if a crash occurs inside the standard handler,
|
|
||||||
so we don't end up in a crash loop. It doesn't rely on contents of stack or heap.
|
|
||||||
*/
|
|
||||||
static void second_fatal_exception_handler_inner(uint32_t *sp, bool registers_saved_on_stack) {
|
|
||||||
dump_excinfo();
|
|
||||||
printf("Second fatal exception occured inside fatal exception handler. Can't continue.\n");
|
|
||||||
post_crash_reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void dump_heapinfo(void)
|
|
||||||
{
|
|
||||||
extern char _heap_start;
|
|
||||||
extern uint32_t xPortSupervisorStackPointer;
|
|
||||||
struct mallinfo mi = mallinfo();
|
|
||||||
uint32_t brk_val = (uint32_t) sbrk(0);
|
|
||||||
uint32_t sp = xPortSupervisorStackPointer;
|
|
||||||
if(sp == 0) {
|
|
||||||
SP(sp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Total free heap is all memory that could be allocated via
|
|
||||||
malloc (assuming fragmentation doesn't become a problem) */
|
|
||||||
printf("\nFree Heap: %d\n", sp - brk_val + mi.fordblks);
|
|
||||||
|
|
||||||
/* delta between brk & supervisor sp is the contiguous memory
|
|
||||||
region that is available to be put into heap space via
|
|
||||||
brk(). */
|
|
||||||
printf("_heap_start %p brk 0x%08x supervisor sp 0x%08x sp-brk %d bytes\n",
|
|
||||||
&_heap_start, brk_val, sp, sp-brk_val);
|
|
||||||
|
|
||||||
/* arena/fordblks/uordblks determines the amount of free space
|
|
||||||
inside the heap region already added via brk(). May be
|
|
||||||
fragmented.
|
|
||||||
|
|
||||||
The values in parentheses are the values used internally by
|
|
||||||
nano-mallocr.c, the field names outside parentheses are the
|
|
||||||
POSIX compliant field names of the mallinfo structure.
|
|
||||||
|
|
||||||
"arena" should be equal to brk-_heap_start ie total size available.
|
|
||||||
*/
|
|
||||||
printf("arena (total_size) %d fordblks (free_size) %d uordblocks (used_size) %d\n",
|
|
||||||
mi.arena, mi.fordblks, mi.uordblks);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Main part of abort handler, can be run from flash to save some
|
|
||||||
IRAM.
|
|
||||||
*/
|
|
||||||
static void abort_handler_inner(uint32_t *caller, uint32_t *sp) {
|
|
||||||
printf("abort() invoked at %p.\n", caller);
|
|
||||||
dump_stack(sp);
|
|
||||||
dump_heapinfo();
|
|
||||||
post_crash_reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_user_exception_handler(void (*fn)(void))
|
|
||||||
{
|
|
||||||
user_exception_handler = fn;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,89 +0,0 @@
|
||||||
/* GPIO management functions
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (C) 2015 Angus Gratton
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#include <esp/gpio.h>
|
|
||||||
#include <esp/rtc_regs.h>
|
|
||||||
|
|
||||||
void gpio_enable(const uint8_t gpio_num, const gpio_direction_t direction)
|
|
||||||
{
|
|
||||||
if (gpio_num == 16) {
|
|
||||||
RTC.GPIO_CFG[3] = (RTC.GPIO_CFG[3] & 0xffffffbc) | 1;
|
|
||||||
RTC.GPIO_CONF = (RTC.GPIO_CONF & 0xfffffffe) | 0;
|
|
||||||
switch (direction) {
|
|
||||||
case GPIO_INPUT:
|
|
||||||
RTC.GPIO_ENABLE = (RTC.GPIO_OUT & 0xfffffffe);
|
|
||||||
break;
|
|
||||||
case GPIO_OUTPUT:
|
|
||||||
case GPIO_OUT_OPEN_DRAIN:
|
|
||||||
/* TODO open drain? */
|
|
||||||
RTC.GPIO_ENABLE = (RTC.GPIO_OUT & 0xfffffffe) | 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (direction) {
|
|
||||||
case GPIO_INPUT:
|
|
||||||
GPIO.ENABLE_OUT_CLEAR = BIT(gpio_num);
|
|
||||||
iomux_set_gpio_function(gpio_num, false);
|
|
||||||
break;
|
|
||||||
case GPIO_OUTPUT:
|
|
||||||
GPIO.CONF[gpio_num] &= ~GPIO_CONF_OPEN_DRAIN;
|
|
||||||
GPIO.ENABLE_OUT_SET = BIT(gpio_num);
|
|
||||||
iomux_set_gpio_function(gpio_num, true);
|
|
||||||
break;
|
|
||||||
case GPIO_OUT_OPEN_DRAIN:
|
|
||||||
GPIO.CONF[gpio_num] |= GPIO_CONF_OPEN_DRAIN;
|
|
||||||
GPIO.ENABLE_OUT_SET = BIT(gpio_num);
|
|
||||||
iomux_set_gpio_function(gpio_num, true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void gpio_set_pullup(uint8_t gpio_num, bool enabled, bool enabled_during_sleep)
|
|
||||||
{
|
|
||||||
uint32_t flags = 0;
|
|
||||||
|
|
||||||
if (enabled) {
|
|
||||||
flags |= IOMUX_PIN_PULLUP;
|
|
||||||
}
|
|
||||||
if (enabled_during_sleep) {
|
|
||||||
flags |= IOMUX_PIN_PULLUP_SLEEP;
|
|
||||||
}
|
|
||||||
iomux_set_pullup_flags(gpio_to_iomux(gpio_num), flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gpio_interrupt_handler_t gpio_interrupt_handlers[16] = { 0 };
|
|
||||||
|
|
||||||
void __attribute__((weak)) IRAM gpio_interrupt_handler(void *arg)
|
|
||||||
{
|
|
||||||
uint32_t status_reg = GPIO.STATUS;
|
|
||||||
GPIO.STATUS_CLEAR = status_reg;
|
|
||||||
|
|
||||||
uint8_t gpio_idx;
|
|
||||||
while ((gpio_idx = __builtin_ffs(status_reg)))
|
|
||||||
{
|
|
||||||
gpio_idx--;
|
|
||||||
status_reg &= ~BIT(gpio_idx);
|
|
||||||
if (FIELD2VAL(GPIO_CONF_INTTYPE, GPIO.CONF[gpio_idx])) {
|
|
||||||
gpio_interrupt_handler_t handler = gpio_interrupt_handlers[gpio_idx];
|
|
||||||
if (handler) {
|
|
||||||
handler(gpio_idx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void gpio_set_interrupt(const uint8_t gpio_num, const gpio_inttype_t int_type, gpio_interrupt_handler_t handler)
|
|
||||||
{
|
|
||||||
gpio_interrupt_handlers[gpio_num] = handler;
|
|
||||||
|
|
||||||
GPIO.CONF[gpio_num] = SET_FIELD(GPIO.CONF[gpio_num], GPIO_CONF_INTTYPE, int_type);
|
|
||||||
if (int_type != GPIO_INTTYPE_NONE) {
|
|
||||||
_xt_isr_attach(INUM_GPIO, gpio_interrupt_handler, NULL);
|
|
||||||
_xt_isr_unmask(1<<INUM_GPIO);
|
|
||||||
}
|
|
||||||
}
|
|
80
core/esp_gpio_interrupts.c
Normal file
80
core/esp_gpio_interrupts.c
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/* ESP GPIO interrupts.
|
||||||
|
|
||||||
|
Use with gpio_set_interrupt(), defined in esp/gpio.h
|
||||||
|
|
||||||
|
These interrupt vectors are default implementations with weak
|
||||||
|
linkage. If you write your own GPIO interrupt vectors in your program
|
||||||
|
then they will replace these at link time.
|
||||||
|
|
||||||
|
Look in examples/button/ for a simple GPIO interrupt example.
|
||||||
|
|
||||||
|
You can implement GPIO interrupt handlers in either of two ways:
|
||||||
|
|
||||||
|
- Implement gpXX_interrupt_handler() for each GPIO pin number that
|
||||||
|
you want to use interrupt with. This is simple but it may not
|
||||||
|
be enough in all cases.
|
||||||
|
|
||||||
|
void gpio01_interrupt_handler(void) {
|
||||||
|
// Do something when GPIO 01 changes
|
||||||
|
}
|
||||||
|
|
||||||
|
void gpio12_interrupt_handler(void) {
|
||||||
|
// Do something when GPIO 12 changes
|
||||||
|
}
|
||||||
|
|
||||||
|
OR
|
||||||
|
|
||||||
|
- Implement a single function named gpio_interrupt_handler(). This
|
||||||
|
will need to manually check GPIO.STATUS and clear any status
|
||||||
|
bits after handling interrupts. This gives you full control, but
|
||||||
|
you can't combine it with the first approach.
|
||||||
|
|
||||||
|
|
||||||
|
Part of esp-open-rtos
|
||||||
|
Copyright (C) 2015 Superhouse Automation Pty Ltd
|
||||||
|
BSD Licensed as described in the file LICENSE
|
||||||
|
*/
|
||||||
|
#include "esp8266.h"
|
||||||
|
|
||||||
|
void gpio_interrupt_handler(void);
|
||||||
|
void gpio_noop_interrupt_handler(void) { }
|
||||||
|
void gpio00_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio01_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio02_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio03_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio04_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio05_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio06_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio07_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio08_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio09_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio10_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio11_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio12_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio13_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio14_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
void gpio15_interrupt_handler(void) __attribute__((weak, alias("gpio_noop_interrupt_handler")));
|
||||||
|
|
||||||
|
typedef void (* gpio_interrupt_handler_t)(void);
|
||||||
|
|
||||||
|
const gpio_interrupt_handler_t gpio_interrupt_handlers[16] = {
|
||||||
|
gpio00_interrupt_handler, gpio01_interrupt_handler, gpio02_interrupt_handler,
|
||||||
|
gpio03_interrupt_handler, gpio04_interrupt_handler, gpio05_interrupt_handler,
|
||||||
|
gpio06_interrupt_handler, gpio07_interrupt_handler, gpio08_interrupt_handler,
|
||||||
|
gpio09_interrupt_handler, gpio10_interrupt_handler, gpio11_interrupt_handler,
|
||||||
|
gpio12_interrupt_handler, gpio13_interrupt_handler, gpio14_interrupt_handler,
|
||||||
|
gpio15_interrupt_handler };
|
||||||
|
|
||||||
|
void __attribute__((weak)) IRAM gpio_interrupt_handler(void)
|
||||||
|
{
|
||||||
|
uint32_t status_reg = GPIO.STATUS;
|
||||||
|
GPIO.STATUS_CLEAR = status_reg;
|
||||||
|
uint8_t gpio_idx;
|
||||||
|
while((gpio_idx = __builtin_ffs(status_reg)))
|
||||||
|
{
|
||||||
|
gpio_idx--;
|
||||||
|
status_reg &= ~BIT(gpio_idx);
|
||||||
|
if(FIELD2VAL(GPIO_CONF_INTTYPE, GPIO.CONF[gpio_idx]))
|
||||||
|
gpio_interrupt_handlers[gpio_idx]();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,32 +0,0 @@
|
||||||
/* Hardware Random Number Generator Functions
|
|
||||||
*
|
|
||||||
* For documentation, see http://esp8266-re.foogod.com/wiki/Random_Number_Generator
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (C) 2015 Angus Gratton
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#include <esp/hwrand.h>
|
|
||||||
#include <esp/wdev_regs.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
/* Return a random 32-bit number.
|
|
||||||
*
|
|
||||||
* This is also used as a substitute for rand() called from
|
|
||||||
* lmac.a:sdk_lmacTxFrame to avoid touching the newlib reent structures within
|
|
||||||
* the NMI and the NMI code needs to be in IRAM.
|
|
||||||
*/
|
|
||||||
uint32_t IRAM hwrand(void)
|
|
||||||
{
|
|
||||||
return WDEV.HWRNG;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fill a variable size buffer with data from the Hardware RNG */
|
|
||||||
void hwrand_fill(uint8_t *buf, size_t len)
|
|
||||||
{
|
|
||||||
for(size_t i = 0; i < len; i+=4) {
|
|
||||||
uint32_t random = WDEV.HWRNG;
|
|
||||||
/* using memcpy here in case 'buf' is unaligned */
|
|
||||||
memcpy(buf + i, &random, (i+4 <= len) ? 4 : (len % 4));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
/* ESP8266 Xtensa interrupt management functions
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (C) 2015 Angus Gratton
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#include <esp/interrupts.h>
|
|
||||||
|
|
||||||
typedef struct _xt_isr_entry_ {
|
|
||||||
_xt_isr handler;
|
|
||||||
void *arg;
|
|
||||||
} _xt_isr_entry;
|
|
||||||
|
|
||||||
_xt_isr_entry isr[16];
|
|
||||||
|
|
||||||
bool esp_in_isr;
|
|
||||||
|
|
||||||
void IRAM _xt_isr_attach(uint8_t i, _xt_isr func, void *arg)
|
|
||||||
{
|
|
||||||
isr[i].handler = func;
|
|
||||||
isr[i].arg = arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Generic ISR handler.
|
|
||||||
|
|
||||||
Handles all flags set for interrupts in 'intset'.
|
|
||||||
*/
|
|
||||||
uint16_t IRAM _xt_isr_handler(uint16_t intset)
|
|
||||||
{
|
|
||||||
esp_in_isr = true;
|
|
||||||
|
|
||||||
/* WDT has highest priority (occasional WDT resets otherwise) */
|
|
||||||
if (intset & BIT(INUM_WDT)) {
|
|
||||||
_xt_clear_ints(BIT(INUM_WDT));
|
|
||||||
isr[INUM_WDT].handler(NULL);
|
|
||||||
intset -= BIT(INUM_WDT);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (intset) {
|
|
||||||
uint8_t index = __builtin_ffs(intset) - 1;
|
|
||||||
uint16_t mask = BIT(index);
|
|
||||||
_xt_clear_ints(mask);
|
|
||||||
_xt_isr handler = isr[index].handler;
|
|
||||||
if (handler) {
|
|
||||||
handler(isr[index].arg);
|
|
||||||
}
|
|
||||||
intset -= mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
esp_in_isr = false;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -7,15 +7,14 @@
|
||||||
#include "esp/iomux.h"
|
#include "esp/iomux.h"
|
||||||
#include "common_macros.h"
|
#include "common_macros.h"
|
||||||
|
|
||||||
const static IRAM_DATA uint32_t IOMUX_TO_GPIO[] = { 12, 13, 14, 15, 3, 1, 6, 7, 8, 9, 10, 11, 0, 2, 4, 5 };
|
/* These are non-static versions of the GPIO mapping tables in
|
||||||
const static IRAM_DATA uint32_t GPIO_TO_IOMUX[] = { 12, 5, 13, 4, 14, 15, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3 };
|
iomux.h, so if they need to be linked only one copy is linked for
|
||||||
|
the entire program.
|
||||||
|
|
||||||
uint8_t IRAM gpio_to_iomux(const uint8_t gpio_number)
|
These are only ever linked in if the arguments to gpio_to_ionum
|
||||||
{
|
or ionum_to_gpio are not known at compile time.
|
||||||
return GPIO_TO_IOMUX[gpio_number];
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t IRAM iomux_to_gpio(const uint8_t iomux_number)
|
Arrays are declared as 32-bit integers in IROM to save RAM.
|
||||||
{
|
*/
|
||||||
return IOMUX_TO_GPIO[iomux_number];
|
const IROM uint32_t GPIO_TO_IOMUX_MAP[] = _GPIO_TO_IOMUX;
|
||||||
}
|
const IROM uint32_t IOMUX_TO_GPIO_MAP[] = _IOMUX_TO_GPIO;
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
/** esp/phy.h
|
|
||||||
*
|
|
||||||
* PHY hardware management functions.
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (C) 2016 ChefSteps, Inc
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#include <esp/phy.h>
|
|
||||||
#include <esp/gpio.h>
|
|
||||||
|
|
||||||
void bt_coexist_configure(bt_coexist_mode_t mode, uint8_t bt_active_pin, uint8_t bt_priority_pin)
|
|
||||||
{
|
|
||||||
/* Disable coexistence entirely before changing pin assignments */
|
|
||||||
GPIO.OUT &= ~(GPIO_OUT_BT_COEXIST_MASK);
|
|
||||||
uint32_t new_mask = 0;
|
|
||||||
|
|
||||||
new_mask = VAL2FIELD_M(GPIO_OUT_BT_ACTIVE_PIN, bt_active_pin) +
|
|
||||||
VAL2FIELD_M(GPIO_OUT_BT_PRIORITY_PIN, bt_priority_pin);
|
|
||||||
|
|
||||||
if(mode == BT_COEXIST_USE_BT_ACTIVE || mode == BT_COEXIST_USE_BT_ACTIVE_PRIORITY) {
|
|
||||||
gpio_enable(bt_active_pin, GPIO_INPUT);
|
|
||||||
new_mask |= GPIO_OUT_BT_ACTIVE_ENABLE;
|
|
||||||
}
|
|
||||||
if(mode == BT_COEXIST_USE_BT_ACTIVE_PRIORITY) {
|
|
||||||
gpio_enable(bt_priority_pin, GPIO_INPUT);
|
|
||||||
new_mask |= GPIO_OUT_BT_PRIORITY_ENABLE;
|
|
||||||
}
|
|
||||||
GPIO.OUT |= new_mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
369
core/esp_spi.c
369
core/esp_spi.c
|
@ -1,369 +0,0 @@
|
||||||
/*
|
|
||||||
* ESP hardware SPI master driver
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (c) Ruslan V. Uss, 2016
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#include "esp/spi.h"
|
|
||||||
|
|
||||||
#include "esp/iomux.h"
|
|
||||||
#include "esp/gpio.h"
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define _SPI0_SCK_GPIO 6
|
|
||||||
#define _SPI0_MISO_GPIO 7
|
|
||||||
#define _SPI0_MOSI_GPIO 8
|
|
||||||
#define _SPI0_HD_GPIO 9
|
|
||||||
#define _SPI0_WP_GPIO 10
|
|
||||||
#define _SPI0_CS0_GPIO 11
|
|
||||||
|
|
||||||
#define _SPI1_MISO_GPIO 12
|
|
||||||
#define _SPI1_MOSI_GPIO 13
|
|
||||||
#define _SPI1_SCK_GPIO 14
|
|
||||||
#define _SPI1_CS0_GPIO 15
|
|
||||||
|
|
||||||
#define _SPI0_FUNC IOMUX_FUNC(1)
|
|
||||||
#define _SPI1_FUNC IOMUX_FUNC(2)
|
|
||||||
|
|
||||||
#define _SPI_BUF_SIZE 64
|
|
||||||
#define __min(a,b) ((a > b) ? (b):(a))
|
|
||||||
|
|
||||||
static bool _minimal_pins[2] = {false, false};
|
|
||||||
|
|
||||||
bool spi_init(uint8_t bus, spi_mode_t mode, uint32_t freq_divider, bool msb, spi_endianness_t endianness, bool minimal_pins)
|
|
||||||
{
|
|
||||||
switch (bus)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
gpio_set_iomux_function(_SPI0_MISO_GPIO, _SPI0_FUNC);
|
|
||||||
gpio_set_iomux_function(_SPI0_MOSI_GPIO, _SPI0_FUNC);
|
|
||||||
gpio_set_iomux_function(_SPI0_SCK_GPIO, _SPI0_FUNC);
|
|
||||||
if (!minimal_pins)
|
|
||||||
{
|
|
||||||
gpio_set_iomux_function(_SPI0_HD_GPIO, _SPI0_FUNC);
|
|
||||||
gpio_set_iomux_function(_SPI0_WP_GPIO, _SPI0_FUNC);
|
|
||||||
gpio_set_iomux_function(_SPI0_CS0_GPIO, _SPI0_FUNC);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
gpio_set_iomux_function(_SPI1_MISO_GPIO, _SPI1_FUNC);
|
|
||||||
gpio_set_iomux_function(_SPI1_MOSI_GPIO, _SPI1_FUNC);
|
|
||||||
gpio_set_iomux_function(_SPI1_SCK_GPIO, _SPI1_FUNC);
|
|
||||||
if (!minimal_pins)
|
|
||||||
gpio_set_iomux_function(_SPI1_CS0_GPIO, _SPI1_FUNC);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_minimal_pins[bus] = minimal_pins;
|
|
||||||
SPI(bus).USER0 = SPI_USER0_MOSI | SPI_USER0_CLOCK_IN_EDGE | SPI_USER0_DUPLEX |
|
|
||||||
(minimal_pins ? 0 : (SPI_USER0_CS_HOLD | SPI_USER0_CS_SETUP));
|
|
||||||
|
|
||||||
spi_set_frequency_div(bus, freq_divider);
|
|
||||||
spi_set_mode(bus, mode);
|
|
||||||
spi_set_msb(bus, msb);
|
|
||||||
spi_set_endianness(bus, endianness);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void spi_get_settings(uint8_t bus, spi_settings_t *s)
|
|
||||||
{
|
|
||||||
s->mode = spi_get_mode(bus);
|
|
||||||
s->freq_divider = spi_get_frequency_div(bus);
|
|
||||||
s->msb = spi_get_msb(bus);
|
|
||||||
s->endianness = spi_get_endianness(bus);
|
|
||||||
s->minimal_pins = _minimal_pins[bus];
|
|
||||||
}
|
|
||||||
|
|
||||||
void spi_set_mode(uint8_t bus, spi_mode_t mode)
|
|
||||||
{
|
|
||||||
bool cpha = (uint8_t)mode & 1;
|
|
||||||
bool cpol = (uint8_t)mode & 2;
|
|
||||||
if (cpol)
|
|
||||||
cpha = !cpha; // CPHA must be inverted when CPOL = 1, I have no idea why
|
|
||||||
|
|
||||||
// CPHA
|
|
||||||
if (cpha)
|
|
||||||
SPI(bus).USER0 |= SPI_USER0_CLOCK_OUT_EDGE;
|
|
||||||
else
|
|
||||||
SPI(bus).USER0 &= ~SPI_USER0_CLOCK_OUT_EDGE;
|
|
||||||
|
|
||||||
// CPOL - see http://bbs.espressif.com/viewtopic.php?t=342#p5384
|
|
||||||
if (cpol)
|
|
||||||
SPI(bus).PIN |= SPI_PIN_IDLE_EDGE;
|
|
||||||
else
|
|
||||||
SPI(bus).PIN &= ~SPI_PIN_IDLE_EDGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
spi_mode_t spi_get_mode(uint8_t bus)
|
|
||||||
{
|
|
||||||
uint8_t cpha = SPI(bus).USER0 & SPI_USER0_CLOCK_OUT_EDGE ? 1 : 0;
|
|
||||||
uint8_t cpol = SPI(bus).PIN & SPI_PIN_IDLE_EDGE ? 2 : 0;
|
|
||||||
|
|
||||||
return (spi_mode_t)(cpol | (cpol ? 1 - cpha : cpha)); // see spi_set_mode
|
|
||||||
}
|
|
||||||
|
|
||||||
void spi_set_msb(uint8_t bus, bool msb)
|
|
||||||
{
|
|
||||||
if (msb)
|
|
||||||
SPI(bus).CTRL0 &= ~(SPI_CTRL0_WR_BIT_ORDER | SPI_CTRL0_RD_BIT_ORDER);
|
|
||||||
else
|
|
||||||
SPI(bus).CTRL0 |= (SPI_CTRL0_WR_BIT_ORDER | SPI_CTRL0_RD_BIT_ORDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
void spi_set_endianness(uint8_t bus, spi_endianness_t endianness)
|
|
||||||
{
|
|
||||||
if (endianness == SPI_BIG_ENDIAN)
|
|
||||||
SPI(bus).USER0 |= (SPI_USER0_WR_BYTE_ORDER | SPI_USER0_RD_BYTE_ORDER);
|
|
||||||
else
|
|
||||||
SPI(bus).USER0 &= ~(SPI_USER0_WR_BYTE_ORDER | SPI_USER0_RD_BYTE_ORDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
void spi_set_frequency_div(uint8_t bus, uint32_t divider)
|
|
||||||
{
|
|
||||||
uint32_t predivider = (divider & 0xffff) - 1;
|
|
||||||
uint32_t count = (divider >> 16) - 1;
|
|
||||||
if (count || predivider)
|
|
||||||
{
|
|
||||||
IOMUX.CONF &= ~(bus == 0 ? IOMUX_CONF_SPI0_CLOCK_EQU_SYS_CLOCK : IOMUX_CONF_SPI1_CLOCK_EQU_SYS_CLOCK);
|
|
||||||
SPI(bus).CLOCK = VAL2FIELD_M(SPI_CLOCK_DIV_PRE, predivider) |
|
|
||||||
VAL2FIELD_M(SPI_CLOCK_COUNT_NUM, count) |
|
|
||||||
VAL2FIELD_M(SPI_CLOCK_COUNT_HIGH, count / 2) |
|
|
||||||
VAL2FIELD_M(SPI_CLOCK_COUNT_LOW, count);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IOMUX.CONF |= bus == 0 ? IOMUX_CONF_SPI0_CLOCK_EQU_SYS_CLOCK : IOMUX_CONF_SPI1_CLOCK_EQU_SYS_CLOCK;
|
|
||||||
SPI(bus).CLOCK = SPI_CLOCK_EQU_SYS_CLOCK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static void _set_size(uint8_t bus, uint8_t bytes)
|
|
||||||
{
|
|
||||||
uint32_t bits = ((uint32_t)bytes << 3) - 1;
|
|
||||||
SPI(bus).USER1 = SET_FIELD(SPI(bus).USER1, SPI_USER1_MISO_BITLEN, bits);
|
|
||||||
SPI(bus).USER1 = SET_FIELD(SPI(bus).USER1, SPI_USER1_MOSI_BITLEN, bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static void _wait(uint8_t bus)
|
|
||||||
{
|
|
||||||
while (SPI(bus).CMD & SPI_CMD_USR)
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static void _start(uint8_t bus)
|
|
||||||
{
|
|
||||||
SPI(bus).CMD |= SPI_CMD_USR;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static void _store_data(uint8_t bus, const void *data, size_t len)
|
|
||||||
{
|
|
||||||
uint8_t words = len / 4;
|
|
||||||
uint8_t tail = len % 4;
|
|
||||||
|
|
||||||
memcpy((void *)SPI(bus).W, data, len - tail);
|
|
||||||
|
|
||||||
if (!tail) return;
|
|
||||||
|
|
||||||
uint32_t last = 0;
|
|
||||||
uint8_t *offs = (uint8_t *)data + len - tail;
|
|
||||||
for (uint8_t i = 0; i < tail; i++)
|
|
||||||
last = last | (offs[i] << (i * 8));
|
|
||||||
SPI(bus).W[words] = last;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static uint32_t _swap_bytes(uint32_t value)
|
|
||||||
{
|
|
||||||
return (value << 24) | ((value << 8) & 0x00ff0000) | ((value >> 8) & 0x0000ff00) | (value >> 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static uint32_t _swap_words(uint32_t value)
|
|
||||||
{
|
|
||||||
return (value << 16) | (value >> 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _spi_buf_prepare(uint8_t bus, size_t len, spi_endianness_t e, spi_word_size_t word_size)
|
|
||||||
{
|
|
||||||
if (e == SPI_LITTLE_ENDIAN || word_size == SPI_32BIT) return;
|
|
||||||
|
|
||||||
size_t count = word_size == SPI_16BIT ? (len + 1) / 2 : (len + 3) / 4;
|
|
||||||
uint32_t *data = (uint32_t *)SPI(bus).W;
|
|
||||||
for (size_t i = 0; i < count; i ++)
|
|
||||||
{
|
|
||||||
data[i] = word_size == SPI_16BIT
|
|
||||||
? _swap_words(data[i])
|
|
||||||
: _swap_bytes(data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _spi_buf_transfer(uint8_t bus, const void *out_data, void *in_data,
|
|
||||||
size_t len, spi_endianness_t e, spi_word_size_t word_size)
|
|
||||||
{
|
|
||||||
_wait(bus);
|
|
||||||
size_t bytes = len * (uint8_t)word_size;
|
|
||||||
_set_size(bus, bytes);
|
|
||||||
_store_data(bus, out_data, bytes);
|
|
||||||
_spi_buf_prepare(bus, len, e, word_size);
|
|
||||||
_start(bus);
|
|
||||||
_wait(bus);
|
|
||||||
if (in_data)
|
|
||||||
{
|
|
||||||
_spi_buf_prepare(bus, len, e, word_size);
|
|
||||||
memcpy(in_data, (void *)SPI(bus).W, bytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t spi_transfer_8(uint8_t bus, uint8_t data)
|
|
||||||
{
|
|
||||||
uint8_t res;
|
|
||||||
_spi_buf_transfer(bus, &data, &res, 1, spi_get_endianness(bus), SPI_8BIT);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t spi_transfer_16(uint8_t bus, uint16_t data)
|
|
||||||
{
|
|
||||||
uint16_t res;
|
|
||||||
_spi_buf_transfer(bus, &data, &res, 1, spi_get_endianness(bus), SPI_16BIT);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t spi_transfer_32(uint8_t bus, uint32_t data)
|
|
||||||
{
|
|
||||||
uint32_t res;
|
|
||||||
_spi_buf_transfer(bus, &data, &res, 1, spi_get_endianness(bus), SPI_32BIT);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _rearm_extras_bit(uint8_t bus, bool arm)
|
|
||||||
{
|
|
||||||
if (!_minimal_pins[bus]) return;
|
|
||||||
static uint8_t status[2];
|
|
||||||
|
|
||||||
if (arm)
|
|
||||||
{
|
|
||||||
if (status[bus] & 0x01) SPI(bus).USER0 |= (SPI_USER0_ADDR);
|
|
||||||
if (status[bus] & 0x02) SPI(bus).USER0 |= (SPI_USER0_COMMAND);
|
|
||||||
if (status[bus] & 0x04)
|
|
||||||
SPI(bus).USER0 |= (SPI_USER0_DUMMY | SPI_USER0_MISO);
|
|
||||||
status[bus] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (SPI(bus).USER0 & SPI_USER0_ADDR)
|
|
||||||
{
|
|
||||||
SPI(bus).USER0 &= ~(SPI_USER0_ADDR);
|
|
||||||
status[bus] |= 0x01;
|
|
||||||
}
|
|
||||||
if (SPI(bus).USER0 & SPI_USER0_COMMAND)
|
|
||||||
{
|
|
||||||
SPI(bus).USER0 &= ~(SPI_USER0_COMMAND);
|
|
||||||
status[bus] |= 0x02;
|
|
||||||
}
|
|
||||||
if (SPI(bus).USER0 & SPI_USER0_DUMMY)
|
|
||||||
{
|
|
||||||
SPI(bus).USER0 &= ~(SPI_USER0_DUMMY | SPI_USER0_MISO);
|
|
||||||
status[bus] |= 0x04;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t spi_transfer(uint8_t bus, const void *out_data, void *in_data, size_t len, spi_word_size_t word_size)
|
|
||||||
{
|
|
||||||
if (!out_data || !len) return 0;
|
|
||||||
|
|
||||||
spi_endianness_t e = spi_get_endianness(bus);
|
|
||||||
uint8_t buf_size = _SPI_BUF_SIZE / (uint8_t)word_size;
|
|
||||||
|
|
||||||
size_t blocks = len / buf_size;
|
|
||||||
for (size_t i = 0; i < blocks; i++)
|
|
||||||
{
|
|
||||||
size_t offset = i * _SPI_BUF_SIZE;
|
|
||||||
_spi_buf_transfer(bus, (const uint8_t *)out_data + offset,
|
|
||||||
in_data ? (uint8_t *)in_data + offset : NULL, buf_size, e, word_size);
|
|
||||||
_rearm_extras_bit(bus, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t tail = len % buf_size;
|
|
||||||
if (tail)
|
|
||||||
{
|
|
||||||
_spi_buf_transfer(bus, (const uint8_t *)out_data + blocks * _SPI_BUF_SIZE,
|
|
||||||
in_data ? (uint8_t *)in_data + blocks * _SPI_BUF_SIZE : NULL, tail, e, word_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blocks) _rearm_extras_bit(bus, true);
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _spi_buf_read(uint8_t bus, uint8_t b, void *in_data,
|
|
||||||
size_t len, spi_endianness_t e, spi_word_size_t word_size)
|
|
||||||
{
|
|
||||||
_wait(bus);
|
|
||||||
size_t bytes = len * (uint8_t)word_size;
|
|
||||||
_set_size(bus, bytes);
|
|
||||||
uint32_t w = ((uint32_t)b << 24) | ((uint32_t)b << 16) | ((uint32_t)b << 8) | b;
|
|
||||||
for (uint8_t i = 0; i < _SPI_BUF_SIZE / 4; i ++)
|
|
||||||
SPI(bus).W[i] = w;
|
|
||||||
_start(bus);
|
|
||||||
_wait(bus);
|
|
||||||
_spi_buf_prepare(bus, len, e, word_size);
|
|
||||||
memcpy(in_data, (void *)SPI(bus).W, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
void spi_read(uint8_t bus, uint8_t out_byte, void *in_data, size_t len, spi_word_size_t word_size)
|
|
||||||
{
|
|
||||||
spi_endianness_t e = spi_get_endianness(bus);
|
|
||||||
uint8_t buf_size = _SPI_BUF_SIZE / (uint8_t)word_size;
|
|
||||||
|
|
||||||
size_t blocks = len / buf_size;
|
|
||||||
for (size_t i = 0; i < blocks; i++)
|
|
||||||
{
|
|
||||||
size_t offset = i * _SPI_BUF_SIZE;
|
|
||||||
_spi_buf_read(bus, out_byte, (uint8_t *)in_data + offset, buf_size, e, word_size);
|
|
||||||
_rearm_extras_bit(bus, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t tail = len % buf_size;
|
|
||||||
if (tail)
|
|
||||||
_spi_buf_read(bus, out_byte, (uint8_t *)in_data + blocks * _SPI_BUF_SIZE, tail, e, word_size);
|
|
||||||
|
|
||||||
if (blocks) _rearm_extras_bit(bus, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _repeat_send(uint8_t bus, uint32_t *dword, int32_t *repeats,
|
|
||||||
spi_word_size_t size)
|
|
||||||
{
|
|
||||||
uint8_t i = 0;
|
|
||||||
while (*repeats > 0)
|
|
||||||
{
|
|
||||||
uint16_t bytes_to_transfer = __min(*repeats * size, _SPI_BUF_SIZE);
|
|
||||||
_wait(bus);
|
|
||||||
if (i) _rearm_extras_bit(bus, false);
|
|
||||||
_set_size(bus, bytes_to_transfer);
|
|
||||||
for (i = 0; i < (bytes_to_transfer + 3) / 4; i++)
|
|
||||||
SPI(bus).W[i] = *dword; //need test with memcpy !
|
|
||||||
_start(bus);
|
|
||||||
*repeats -= (bytes_to_transfer / size);
|
|
||||||
}
|
|
||||||
_wait(bus);
|
|
||||||
_rearm_extras_bit(bus, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void spi_repeat_send_8(uint8_t bus, uint8_t data, int32_t repeats)
|
|
||||||
{
|
|
||||||
uint32_t dword = data << 24 | data << 16 | data << 8 | data;
|
|
||||||
_repeat_send(bus, &dword, &repeats, SPI_8BIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void spi_repeat_send_16(uint8_t bus, uint16_t data, int32_t repeats)
|
|
||||||
{
|
|
||||||
uint32_t dword = data << 16 | data;
|
|
||||||
_repeat_send(bus, &dword, &repeats, SPI_16BIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void spi_repeat_send_32(uint8_t bus, uint32_t data, int32_t repeats)
|
|
||||||
{
|
|
||||||
_repeat_send(bus, &data, &repeats, SPI_32BIT);
|
|
||||||
}
|
|
144
core/esp_timer.c
144
core/esp_timer.c
|
@ -6,148 +6,30 @@
|
||||||
* BSD Licensed as described in the file LICENSE
|
* BSD Licensed as described in the file LICENSE
|
||||||
*/
|
*/
|
||||||
#include <esp/timer.h>
|
#include <esp/timer.h>
|
||||||
#include <esp/dport_regs.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* Timer divisor number to maximum frequency */
|
/*
|
||||||
#define _FREQ_DIV1 (80*1000*1000)
|
* These are the runtime implementations for functions that are linked in if any of
|
||||||
#define _FREQ_DIV16 (5*1000*1000)
|
* the arguments aren't known at compile time (values are evaluated at
|
||||||
#define _FREQ_DIV256 312500
|
* compile time otherwise.)
|
||||||
|
*/
|
||||||
const static uint32_t IROM _TIMER_FREQS[] = { _FREQ_DIV1, _FREQ_DIV16, _FREQ_DIV256 };
|
uint32_t _timer_freq_to_count_runtime(const timer_frc_t frc, const uint32_t freq, const timer_clkdiv_t div)
|
||||||
|
|
||||||
/* Timer divisor index to divisor value */
|
|
||||||
const static uint32_t IROM _TIMER_DIV_VAL[] = { 1, 16, 256 };
|
|
||||||
|
|
||||||
void timer_set_interrupts(const timer_frc_t frc, bool enable)
|
|
||||||
{
|
{
|
||||||
const uint32_t dp_bit = (frc == FRC1) ? DPORT_INT_ENABLE_FRC1 : DPORT_INT_ENABLE_FRC2;
|
return _timer_freq_to_count_impl(frc, freq, div);
|
||||||
const uint32_t int_mask = BIT((frc == FRC1) ? INUM_TIMER_FRC1 : INUM_TIMER_FRC2);
|
|
||||||
if(enable) {
|
|
||||||
DPORT.INT_ENABLE |= dp_bit;
|
|
||||||
_xt_isr_unmask(int_mask);
|
|
||||||
} else {
|
|
||||||
DPORT.INT_ENABLE &= ~dp_bit;
|
|
||||||
_xt_isr_mask(int_mask);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t timer_freq_to_count(const timer_frc_t frc, const uint32_t freq, const timer_clkdiv_t div)
|
uint32_t _timer_time_to_count_runtime(const timer_frc_t frc, uint32_t us, const timer_clkdiv_t div)
|
||||||
{
|
{
|
||||||
if(div < TIMER_CLKDIV_1 || div > TIMER_CLKDIV_256)
|
return _timer_time_to_count_runtime(frc, us, div);
|
||||||
return 0; /* invalid divider */
|
|
||||||
|
|
||||||
if(freq > _TIMER_FREQS[div])
|
|
||||||
return 0; /* out of range for given divisor */
|
|
||||||
|
|
||||||
uint64_t counts = _TIMER_FREQS[div]/freq;
|
|
||||||
return counts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t timer_time_to_count(const timer_frc_t frc, uint32_t us, const timer_clkdiv_t div)
|
bool _timer_set_frequency_runtime(const timer_frc_t frc, uint32_t freq)
|
||||||
{
|
{
|
||||||
if(div < TIMER_CLKDIV_1 || div > TIMER_CLKDIV_256)
|
return _timer_set_frequency_runtime(frc, freq);
|
||||||
return 0; /* invalid divider */
|
|
||||||
|
|
||||||
const uint32_t TIMER_MAX = timer_max_load(frc);
|
|
||||||
|
|
||||||
if(div != TIMER_CLKDIV_256) /* timer tick in MHz */
|
|
||||||
{
|
|
||||||
/* timer is either 80MHz or 5MHz, so either 80 or 5 MHz counts per us */
|
|
||||||
const uint32_t counts_per_us = ((div == TIMER_CLKDIV_1) ? _FREQ_DIV1 : _FREQ_DIV16)/1000/1000;
|
|
||||||
if(us > TIMER_MAX/counts_per_us)
|
|
||||||
return 0; /* Multiplying us by mhz_per_count will overflow TIMER_MAX */
|
|
||||||
return us*counts_per_us;
|
|
||||||
}
|
|
||||||
else /* /256 divider, 312.5kHz freq so need to scale up */
|
|
||||||
{
|
|
||||||
/* derived from naive floating point equation that we can't use:
|
|
||||||
counts = (us/1000/1000)*_FREQ_DIV256;
|
|
||||||
counts = (us/2000)*(_FREQ_DIV256/500);
|
|
||||||
counts = us*(_FREQ_DIV256/500)/2000;
|
|
||||||
*/
|
|
||||||
const uint32_t scalar = _FREQ_DIV256/500;
|
|
||||||
if(us > 1+UINT32_MAX/scalar)
|
|
||||||
return 0; /* Multiplying us by _FREQ_DIV256/500 will overflow uint32_t */
|
|
||||||
|
|
||||||
uint32_t counts = (us*scalar)/2000;
|
|
||||||
if(counts > TIMER_MAX)
|
|
||||||
return 0; /* counts value too high for timer type */
|
|
||||||
return counts;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int timer_set_frequency(const timer_frc_t frc, uint32_t freq)
|
bool _timer_set_timeout_runtime(const timer_frc_t frc, uint32_t us)
|
||||||
{
|
{
|
||||||
uint32_t counts = 0;
|
return _timer_set_timeout_impl(frc, us);
|
||||||
timer_clkdiv_t div = timer_freq_to_div(freq);
|
|
||||||
|
|
||||||
if(freq == 0) //can't divide by 0
|
|
||||||
{
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
counts = timer_freq_to_count(frc, freq, div);
|
|
||||||
if(counts == 0)
|
|
||||||
{
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
timer_set_divider(frc, div);
|
|
||||||
if(frc == FRC1)
|
|
||||||
{
|
|
||||||
timer_set_load(frc, counts);
|
|
||||||
timer_set_reload(frc, true);
|
|
||||||
}
|
|
||||||
else /* FRC2 */
|
|
||||||
{
|
|
||||||
/* assume that if this overflows it'll wrap, so we'll get desired behaviour */
|
|
||||||
TIMER(1).ALARM = counts + TIMER(1).COUNT;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int _timer_set_timeout_impl(const timer_frc_t frc, uint32_t us)
|
|
||||||
{
|
|
||||||
uint32_t counts = 0;
|
|
||||||
timer_clkdiv_t div = timer_time_to_div(us);
|
|
||||||
|
|
||||||
counts = timer_time_to_count(frc, us, div);
|
|
||||||
if(counts == 0)
|
|
||||||
return -EINVAL; /* can't set frequency */
|
|
||||||
|
|
||||||
timer_set_divider(frc, div);
|
|
||||||
if(frc == FRC1)
|
|
||||||
{
|
|
||||||
timer_set_load(frc, counts);
|
|
||||||
}
|
|
||||||
else /* FRC2 */
|
|
||||||
{
|
|
||||||
TIMER(1).ALARM = counts + TIMER(1).COUNT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int timer_set_timeout(const timer_frc_t frc, uint32_t us)
|
|
||||||
{
|
|
||||||
uint32_t counts = 0;
|
|
||||||
timer_clkdiv_t div = timer_time_to_div(us);
|
|
||||||
|
|
||||||
counts = timer_time_to_count(frc, us, div);
|
|
||||||
if(counts == 0)
|
|
||||||
return -EINVAL; /* can't set frequency */
|
|
||||||
|
|
||||||
timer_set_divider(frc, div);
|
|
||||||
if(frc == FRC1)
|
|
||||||
{
|
|
||||||
timer_set_load(frc, counts);
|
|
||||||
}
|
|
||||||
else /* FRC2 */
|
|
||||||
{
|
|
||||||
TIMER(1).ALARM = counts + TIMER(1).COUNT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,580 +1,256 @@
|
||||||
/* Xtensa Exception (ie interrupt) Vectors & low-level handler code
|
/* Xtensa Exception (ie interrupt) Vectors & low-level handler code
|
||||||
*
|
|
||||||
* Core exception handler code is placed in the .vecbase section, which gets
|
|
||||||
* picked up specially in the linker script and placed at beginning of IRAM.
|
|
||||||
*
|
|
||||||
* The actual VecBase symbol should be the first thing in .vecbase (this is not
|
|
||||||
* strictly important as it gets set by symbol lookup not by hardcoded address,
|
|
||||||
* but having it at 0x40100000 means that the exception vectors have memorable
|
|
||||||
* offsets, which match the default Boot ROM vector offsets. So convenient for
|
|
||||||
* human understanding.
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Original vector contents Copyright (C) 2014-2015 Espressif Systems
|
|
||||||
* Additions Copyright (C) Superhouse Automation Pty Ltd and Angus Gratton
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "led_debug.s"
|
Core exception handler code is placed in the .vecbase section,
|
||||||
|
which gets picked up specially in the linker script and placed
|
||||||
|
at beginning of IRAM.
|
||||||
|
|
||||||
|
The actual VecBase symbol should be the first thing in .vecbase
|
||||||
|
(this is not strictly important as it gets set by symbol lookup not
|
||||||
|
by hardcoded address, but having it at 0x40100000 means that the
|
||||||
|
exception vectors have memorable offsets, which match the default
|
||||||
|
Boot ROM vector offsets. So convenient for human understanding.
|
||||||
|
|
||||||
|
Part of esp-open-rtos
|
||||||
|
Original vector contents Copyright (C) 2014-2015 Espressif Systems
|
||||||
|
Additions Copyright (C) Superhouse Automation Pty Ltd
|
||||||
|
BSD Licensed as described in the file LICENSE
|
||||||
|
*/
|
||||||
|
.text
|
||||||
|
.section .vecbase.text, "x"
|
||||||
|
.align 256
|
||||||
|
.global VecBase
|
||||||
|
.type VecBase, @function /* it's not really a function, but treat it like one */
|
||||||
|
VecBase:
|
||||||
|
/* IMPORTANT: exception vector literals will go here, but we
|
||||||
|
can't have more than 4 otherwise we push DebugExceptionVector past
|
||||||
|
offset 0x10 relative to VecBase. There should be ways to avoid this,
|
||||||
|
and also keep the VecBase offsets easy to read, but this works for now.
|
||||||
|
*/
|
||||||
|
.literal_position
|
||||||
|
.align 16
|
||||||
|
DebugExceptionVector:
|
||||||
|
wsr.excsave2 a0
|
||||||
|
call0 sdk_user_fatal_exception_handler
|
||||||
|
rfi 2
|
||||||
|
.align 16
|
||||||
|
NMIExceptionVector:
|
||||||
|
wsr.excsave3 a0
|
||||||
|
call0 CallNMIExceptionHandler
|
||||||
|
rfi 3 /* CallNMIExceptionHandler should call rfi itself */
|
||||||
|
.align 16
|
||||||
|
KernelExceptionVector:
|
||||||
|
break 1, 0
|
||||||
|
call0 sdk_user_fatal_exception_handler
|
||||||
|
rfe
|
||||||
|
.align 16
|
||||||
|
.L_EmptyVectorEntry:
|
||||||
|
nop
|
||||||
|
.align 16
|
||||||
|
UserExceptionVector:
|
||||||
|
wsr.excsave1 a0
|
||||||
|
call0 CallUserExceptionHandler
|
||||||
|
rfe /* CallUserExceptionHandler should call rfe itself */
|
||||||
|
.align 16
|
||||||
|
.L_EmptyVectorEntry2:
|
||||||
|
nop
|
||||||
|
.align 16
|
||||||
|
DoubleExceptionVector:
|
||||||
|
break 1, 4
|
||||||
|
call0 sdk_user_fatal_exception_handler
|
||||||
|
.align 16
|
||||||
|
.L_UnusedResetVector:
|
||||||
|
/* reset vector slot doesn't get used, as vecbase goes back to mask ROM on reset */
|
||||||
|
nop
|
||||||
|
|
||||||
|
.section .bss
|
||||||
|
NMIHandlerStack: /* stack space for NMI handler */
|
||||||
|
.skip 4*0x100
|
||||||
|
NMIRegisterSaved: /* register space for saving NMI registers */
|
||||||
|
.skip 4*(0x16 + 6)
|
||||||
|
|
||||||
|
/* this symbol is _Pri_3_HandlerAddress in the RTOS SDK, appears totally
|
||||||
|
unused (stays zero at all times) */
|
||||||
|
.global NMIHandlerAddress
|
||||||
|
NMIHandlerAddress:
|
||||||
|
.long 0
|
||||||
|
|
||||||
|
/* Save register relative to a0 */
|
||||||
|
.macro SAVE_REG register, regnum
|
||||||
|
s32i \register, a0, (0x20 + 4 * \regnum)
|
||||||
|
.endm
|
||||||
|
|
||||||
|
/* Load register relative to sp */
|
||||||
|
.macro LOAD_REG register, regnum
|
||||||
|
l32i \register, sp, (0x20 + 4 * \regnum)
|
||||||
|
.endm
|
||||||
|
|
||||||
|
.text
|
||||||
|
.section .vecbase.text
|
||||||
|
.literal_position
|
||||||
|
.align 4
|
||||||
|
.global call_user_start
|
||||||
|
.type call_user_start, @function
|
||||||
|
call_user_start:
|
||||||
|
movi a2, VecBase
|
||||||
|
wsr.vecbase a2
|
||||||
|
call0 sdk_user_start
|
||||||
|
|
||||||
|
.literal_position
|
||||||
|
.align 16
|
||||||
|
.type CallNMIExceptionHandler, @function
|
||||||
|
CallNMIExceptionHandler:
|
||||||
|
movi a0, NMIRegisterSaved
|
||||||
|
SAVE_REG a2, 2
|
||||||
|
movi a2, NMIHandlerAddress
|
||||||
|
l32i a2, a2, 0
|
||||||
|
SAVE_REG sp, 1
|
||||||
|
SAVE_REG a3, 3
|
||||||
|
xsr.excsave3 a2 /* excsave3 is now NMIHandlerAddress, a2 is former a0 */
|
||||||
|
SAVE_REG a4, 4
|
||||||
|
SAVE_REG a2, 0
|
||||||
|
rsr.epc1 a3
|
||||||
|
rsr.exccause a4
|
||||||
|
SAVE_REG a3, -5
|
||||||
|
SAVE_REG a4, -4
|
||||||
|
rsr.excvaddr a3
|
||||||
|
SAVE_REG a3, -3
|
||||||
|
rsr.excsave1 a3
|
||||||
|
SAVE_REG a3, -2
|
||||||
|
SAVE_REG a5, 5
|
||||||
|
SAVE_REG a6, 6
|
||||||
|
SAVE_REG a7, 7
|
||||||
|
SAVE_REG a8, 8
|
||||||
|
SAVE_REG a9, 9
|
||||||
|
SAVE_REG a10, 10
|
||||||
|
SAVE_REG a11, 11
|
||||||
|
SAVE_REG a12, 12
|
||||||
|
SAVE_REG a13, 13
|
||||||
|
SAVE_REG a14, 14
|
||||||
|
SAVE_REG a15, 15
|
||||||
|
movi sp, NMIRegisterSaved /* also top of NMIHandlerStack */
|
||||||
|
movi a0, 0
|
||||||
|
movi a2, 0x23 /* argument for handler */
|
||||||
|
wsr.ps a2
|
||||||
|
rsync
|
||||||
|
rsr.sar a14
|
||||||
|
s32i a14, sp, 0 /* this is also NMIRegisterSaved+0 */
|
||||||
|
call0 sdk_wDev_ProcessFiq
|
||||||
|
l32i a15, sp, 0
|
||||||
|
wsr.sar a15
|
||||||
|
movi a2, 0x33
|
||||||
|
wsr.ps a2
|
||||||
|
rsync
|
||||||
|
LOAD_REG a4, 4
|
||||||
|
LOAD_REG a5, 5
|
||||||
|
LOAD_REG a6, 6
|
||||||
|
LOAD_REG a7, 7
|
||||||
|
LOAD_REG a8, 8
|
||||||
|
LOAD_REG a9, 9
|
||||||
|
LOAD_REG a10, 10
|
||||||
|
LOAD_REG a11, 11
|
||||||
|
LOAD_REG a12, 12
|
||||||
|
LOAD_REG a13, 13
|
||||||
|
LOAD_REG a14, 14
|
||||||
|
LOAD_REG a15, 15
|
||||||
|
LOAD_REG a2, -5
|
||||||
|
LOAD_REG a3, -4
|
||||||
|
wsr.epc1 a2
|
||||||
|
wsr.exccause a3
|
||||||
|
LOAD_REG a2, -3
|
||||||
|
LOAD_REG a3, -2
|
||||||
|
wsr.excvaddr a2
|
||||||
|
wsr.excsave1 a3
|
||||||
|
LOAD_REG a0, 0
|
||||||
|
/* set dport nmi status bit 0 (wDev_ProcessFiq clears & verifies this bit stays cleared,
|
||||||
|
see http://esp8266-re.foogod.com/wiki/WDev_ProcessFiq_%28IoT_RTOS_SDK_0.9.9%29) */
|
||||||
|
movi a2, 0x3ff00000
|
||||||
|
movi a3, 0x1
|
||||||
|
s32i a3, a2, 0
|
||||||
|
LOAD_REG a2, 2
|
||||||
|
LOAD_REG a3, 3
|
||||||
|
LOAD_REG a1, 1
|
||||||
|
rfi 0x3
|
||||||
|
|
||||||
/* Some UserException causes, see table Table 4–64 in ISA reference */
|
/* Some UserException causes, see table Table 4–64 in ISA reference */
|
||||||
|
|
||||||
#define CAUSE_SYSCALL 1
|
#define CAUSE_SYSCALL 1
|
||||||
#define CAUSE_LOADSTORE 3
|
|
||||||
#define CAUSE_LVL1INT 4
|
#define CAUSE_LVL1INT 4
|
||||||
|
|
||||||
.section .bss
|
.type CallUserExceptionHandler, @function
|
||||||
|
CallUserExceptionHandler:
|
||||||
/* Stack space for NMI handler
|
rsr.exccause a0
|
||||||
|
beqi a0, CAUSE_SYSCALL, UserSyscallHandler
|
||||||
NMI handler stack high water mark measured at 0x134 bytes. Any use
|
mov a0, sp
|
||||||
of the NMI timer callback will add stack overhead as well.
|
addi sp, sp, -0x50
|
||||||
|
s32i a0, sp, 0x10
|
||||||
The NMI handler does a basic check for stack overflow
|
rsr.ps a0
|
||||||
*/
|
s32i a0, sp, 0x08
|
||||||
.balign 16
|
rsr.epc1 a0
|
||||||
NMIHandlerStack:
|
s32i a0, sp, 0x04
|
||||||
.skip 0x200
|
rsr.excsave1 a0 /* a0 was saved in UserExceptionVector */
|
||||||
.NMIHandlerStackTop:
|
s32i a0, sp, 0x0c
|
||||||
|
movi a0, _xt_user_exit
|
||||||
.balign 16
|
s32i a0, sp, 0x0
|
||||||
LoadStoreErrorHandlerStack:
|
call0 sdk__xt_int_enter
|
||||||
.word 0 # a0
|
movi a0, 0x23
|
||||||
.word 0 # (unused)
|
wsr.ps a0
|
||||||
.word 0 # a2
|
rsync
|
||||||
.word 0 # a3
|
rsr.exccause a2
|
||||||
.word 0 # a4
|
beqi a2, CAUSE_LVL1INT, UserHandleInterrupt
|
||||||
|
/* Any UserException cause other than level 1 interrupt triggers a panic */
|
||||||
.balign 4
|
UserFailOtherExceptionCause:
|
||||||
.global debug_saved_ctx
|
break 1, 1
|
||||||
debug_saved_ctx:
|
call0 sdk_user_fatal_exception_handler
|
||||||
.word 0 # a0
|
UserHandleInterrupt:
|
||||||
.word 0 # a1
|
rsil a0, 1
|
||||||
.word 0 # a2
|
rsr.intenable a2
|
||||||
.word 0 # a3
|
rsr.interrupt a3
|
||||||
.word 0 # a4
|
movi a4, 0x3fff
|
||||||
|
and a2, a2, a3
|
||||||
/***************************** Exception Vectors *****************************/
|
and a2, a2, a4 /* a2 = 0x3FFF & INTENABLE & INTERRUPT */
|
||||||
|
UserHandleTimer:
|
||||||
.section .vecbase.text, "x"
|
movi a3, 0xffbf
|
||||||
|
and a3, a2, a3 /* a3 = a2 & 0xFFBF, ie remove 0x40 from a2 if set */
|
||||||
/* Note: Exception vectors must be aligned on a 256-byte (0x100) boundary or
|
bnez a3, UserTimerDone /* bits other than 0x40 are set */
|
||||||
* they will not function properly. (This is taken care of in the linker
|
movi a3, 0x40
|
||||||
* script by ensuring .vecbase.text is aligned properly, and putting VecBase
|
sub a12, a2, a3 /* a12 - a2 - 0x40 - I think a12 _must_ be zero here? */
|
||||||
* right at the beginning of .vecbase.text) */
|
call0 sdk__xt_timer_int /* tick timer interrupt */
|
||||||
.org 0
|
mov a2, a12 /* restore a2 from a12, ie zero */
|
||||||
VecBase:
|
beqz a2, UserIntDone
|
||||||
.global VecBase
|
UserTimerDone:
|
||||||
/* IMPORTANT: exception vector literals will go here, but we
|
call0 _xt_isr_handler
|
||||||
* can't have more than 4 otherwise we push DebugExceptionVector past
|
bnez a2, UserHandleTimer
|
||||||
* offset 0x10 relative to VecBase. There should be ways to avoid this,
|
UserIntDone:
|
||||||
* and also keep the VecBase offsets easy to read, but this works for
|
beqz a2, UserIntExit
|
||||||
* now. */
|
break 1, 1 /* non-zero remnant in a2 means fail */
|
||||||
.literal_position
|
call0 sdk_user_fatal_exception_handler
|
||||||
|
UserIntExit:
|
||||||
.org VecBase + 0x10
|
call0 sdk__xt_int_exit /* calls rfi */
|
||||||
DebugExceptionVector:
|
|
||||||
.type DebugExceptionVector, @function
|
/* As far as I can tell, the syscall handler is basically a no-op */
|
||||||
j DebugExceptionHandler
|
UserSyscallHandler:
|
||||||
|
addi sp, sp, -0x10
|
||||||
.org VecBase + 0x20
|
s32i a2, sp, 0x08
|
||||||
NMIExceptionVector:
|
s32i a2, sp, 0x0c
|
||||||
.type NMIExceptionVector, @function
|
rsr.epc1 a2
|
||||||
j NMIExceptionHandler
|
addi a3, a2, 0x3
|
||||||
|
wsr.epc1 a3
|
||||||
.org VecBase + 0x30
|
l32i a2, sp, 0x8
|
||||||
KernelExceptionVector:
|
l32i a3, sp, 0xc
|
||||||
.type KernelExceptionVector, @function
|
addi sp, sp, 0x10
|
||||||
|
movi a0, 0x7f
|
||||||
break 1, 0
|
movnez a2, a0, a2
|
||||||
mov a2, a1
|
rsr.excsave1 a0
|
||||||
movi a3, 0
|
rfe
|
||||||
call0 fatal_exception_handler
|
|
||||||
rfe
|
.global _xt_user_exit
|
||||||
|
.type _xt_user_exit, @function
|
||||||
.org VecBase + 0x50
|
|
||||||
UserExceptionVector:
|
|
||||||
.type UserExceptionVector, @function
|
|
||||||
|
|
||||||
wsr a1, excsave1
|
|
||||||
rsr a1, exccause
|
|
||||||
beqi a1, CAUSE_LOADSTORE, LoadStoreErrorHandler
|
|
||||||
j UserExceptionHandler
|
|
||||||
|
|
||||||
.org VecBase + 0x70
|
|
||||||
DoubleExceptionVector:
|
|
||||||
.type DoubleExceptionVector, @function
|
|
||||||
|
|
||||||
break 1, 4
|
|
||||||
mov a2, a1
|
|
||||||
movi a3, 0
|
|
||||||
call0 fatal_exception_handler
|
|
||||||
|
|
||||||
/* Reset vector at offset 0x80 is unused, as vecbase gets reset to mask ROM
|
|
||||||
* vectors on chip reset. */
|
|
||||||
|
|
||||||
/*************************** LoadStoreError Handler **************************/
|
|
||||||
|
|
||||||
.section .vecbase.text, "x"
|
|
||||||
|
|
||||||
/* Xtensa "Load/Store Exception" handler:
|
|
||||||
* Completes L8/L16 load instructions from Instruction address space, for which
|
|
||||||
* the architecture only supports 32-bit reads.
|
|
||||||
*
|
|
||||||
* Called from UserExceptionVector if EXCCAUSE is LoadStoreErrorCause
|
|
||||||
*
|
|
||||||
* (Fast path (no branches) is for L8UI)
|
|
||||||
*/
|
|
||||||
.literal_position
|
|
||||||
|
|
||||||
.balign 4
|
|
||||||
LoadStoreErrorHandler:
|
|
||||||
.type LoadStoreErrorHandler, @function
|
|
||||||
|
|
||||||
/* Registers are saved in the address corresponding to their register
|
|
||||||
* number times 4. This allows a quick and easy mapping later on when
|
|
||||||
* needing to store the value to a particular register number. */
|
|
||||||
movi sp, LoadStoreErrorHandlerStack
|
|
||||||
s32i a0, sp, 0
|
|
||||||
s32i a2, sp, 0x08
|
|
||||||
s32i a3, sp, 0x0c
|
|
||||||
s32i a4, sp, 0x10
|
|
||||||
rsr a0, sar # Save SAR in a0 to restore later
|
|
||||||
|
|
||||||
/* Examine the opcode which generated the exception */
|
|
||||||
/* Note: Instructions are in this order to avoid pipeline stalls. */
|
|
||||||
rsr a2, epc1
|
|
||||||
movi a3, ~3
|
|
||||||
ssa8l a2 # sar is now correct shift for aligned read
|
|
||||||
and a2, a2, a3 # a2 now 4-byte aligned address of instruction
|
|
||||||
l32i a4, a2, 0
|
|
||||||
l32i a2, a2, 4
|
|
||||||
movi a3, 0x00700F # opcode mask for l8ui/l16si/l16ui
|
|
||||||
src a2, a2, a4 # a2 now instruction that failed
|
|
||||||
and a3, a2, a3 # a3 is masked instruction
|
|
||||||
bnei a3, 0x000002, .LSE_check_l16
|
|
||||||
|
|
||||||
/* Note: At this point, opcode could technically be one of two things:
|
|
||||||
* xx0xx2 (L8UI)
|
|
||||||
* xx8xx2 (Reserved (invalid) opcode)
|
|
||||||
* It is assumed that we'll never get to this point from an illegal
|
|
||||||
* opcode, so we don't bother to check for that case and presume this
|
|
||||||
* is always an L8UI. */
|
|
||||||
|
|
||||||
movi a4, ~3
|
|
||||||
rsr a3, excvaddr # read faulting address
|
|
||||||
and a4, a3, a4 # a4 now word aligned read address
|
|
||||||
|
|
||||||
l32i a4, a4, 0 # perform the actual read
|
|
||||||
ssa8l a3 # sar is now shift to extract a3's byte
|
|
||||||
srl a3, a4 # shift right correct distance
|
|
||||||
extui a4, a3, 0, 8 # mask off bits we need for an l8
|
|
||||||
|
|
||||||
.LSE_post_fetch:
|
|
||||||
/* We jump back here after either the L8UI or the L16*I routines do the
|
|
||||||
* necessary work to read the value from memory.
|
|
||||||
* At this point, a2 holds the faulting instruction and a4 holds the
|
|
||||||
* correctly read value.
|
|
||||||
|
|
||||||
* Restore original SAR value (saved in a0) and update EPC so we'll
|
|
||||||
* return back to the instruction following the one we just emulated */
|
|
||||||
|
|
||||||
/* Note: Instructions are in this order to avoid pipeline stalls */
|
|
||||||
rsr a3, epc1
|
|
||||||
wsr a0, sar
|
|
||||||
addi a3, a3, 0x3
|
|
||||||
wsr a3, epc1
|
|
||||||
|
|
||||||
/* Stupid opcode tricks: The jumptable we use later on needs 16 bytes
|
|
||||||
* per entry (so we can avoid a second jump by just doing a RFE inside
|
|
||||||
* each entry). Unfortunately, however, Xtensa doesn't have an addx16
|
|
||||||
* operation to make that easy for us. Luckily, all of the faulting
|
|
||||||
* opcodes we're processing are guaranteed to have bit 3 be zero, which
|
|
||||||
* means if we just shift the register bits of the opcode down by 3
|
|
||||||
* instead of 4, we will get the register number multiplied by 2. This
|
|
||||||
* combined with an addx8 will give us an effective addx16 without
|
|
||||||
* needing any extra shift operations. */
|
|
||||||
extui a2, a2, 3, 5 # a2 is now destination register 0-15 times 2
|
|
||||||
|
|
||||||
bgei a2, 10, .LSE_assign_reg # a5..a15 use jumptable
|
|
||||||
beqi a2, 2, .LSE_assign_a1 # a1 uses a special routine
|
|
||||||
|
|
||||||
/* We're storing into a0 or a2..a4, which are all saved in our "stack"
|
|
||||||
* area. Calculate the correct address and stick the value in there,
|
|
||||||
* then just do our normal restore and RFE (no jumps required, which
|
|
||||||
* actually makes a0..a4 substantially faster). */
|
|
||||||
addx2 a2, a2, sp
|
|
||||||
s32i a4, a2, 0
|
|
||||||
|
|
||||||
/* Restore all regs and return */
|
|
||||||
l32i a0, sp, 0
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a3, sp, 0x0c
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1 # restore a1 saved by UserExceptionVector
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.LSE_assign_reg:
|
|
||||||
/* At this point, a2 contains the register number times 2, a4 is the
|
|
||||||
* read value. */
|
|
||||||
|
|
||||||
/* Calculate the jumptable address, and restore all regs except a2 and
|
|
||||||
* a4 so we have less to do after jumping. */
|
|
||||||
/* Note: Instructions are in this order to avoid pipeline stalls. */
|
|
||||||
movi a3, .LSE_jumptable_base
|
|
||||||
l32i a0, sp, 0
|
|
||||||
addx8 a2, a2, a3 # a2 is now the address to jump to
|
|
||||||
l32i a3, sp, 0x0c
|
|
||||||
|
|
||||||
jx a2
|
|
||||||
|
|
||||||
.balign 4
|
|
||||||
.LSE_check_l16:
|
|
||||||
/* At this point, a2 contains the opcode, a3 is masked opcode */
|
|
||||||
movi a4, 0x001002 # l16si or l16ui opcode after masking
|
|
||||||
bne a3, a4, .LSE_wrong_opcode
|
|
||||||
|
|
||||||
/* Note: At this point, the opcode could be one of two things:
|
|
||||||
* xx1xx2 (L16UI)
|
|
||||||
* xx9xx2 (L16SI)
|
|
||||||
* Both of these we can handle. */
|
|
||||||
|
|
||||||
movi a4, ~3
|
|
||||||
rsr a3, excvaddr # read faulting address
|
|
||||||
and a4, a3, a4 # a4 now word aligned read address
|
|
||||||
|
|
||||||
l32i a4, a4, 0 # perform the actual read
|
|
||||||
ssa8l a3 # sar is now shift to extract a3's bytes
|
|
||||||
srl a3, a4 # shift right correct distance
|
|
||||||
extui a4, a3, 0, 16 # mask off bits we need for an l16
|
|
||||||
|
|
||||||
bbci a2, 15, .LSE_post_fetch # Not a signed op
|
|
||||||
bbci a4, 15, .LSE_post_fetch # Value does not need sign-extension
|
|
||||||
|
|
||||||
movi a3, 0xFFFF0000
|
|
||||||
or a4, a3, a4 # set 32-bit sign bits
|
|
||||||
j .LSE_post_fetch
|
|
||||||
|
|
||||||
.LSE_wrong_opcode:
|
|
||||||
/* If we got here it's not an opcode we can try to fix, so bomb out.
|
|
||||||
* Restore registers so any dump the fatal exception routine produces
|
|
||||||
* will have correct values */
|
|
||||||
wsr a0, sar
|
|
||||||
l32i a0, sp, 0
|
|
||||||
/*l32i a2, sp, 0x08*/
|
|
||||||
l32i a3, sp, 0x0c
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
mov a2, a1
|
|
||||||
movi a3, 0
|
|
||||||
call0 fatal_exception_handler
|
|
||||||
|
|
||||||
.balign 4
|
|
||||||
.LSE_assign_a1:
|
|
||||||
/* a1 is saved in excsave1, so just update that with the value, */
|
|
||||||
wsr a4, excsave1
|
|
||||||
/* Then restore all regs and return */
|
|
||||||
l32i a0, sp, 0
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a3, sp, 0x0c
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.balign 4
|
|
||||||
.LSE_jumptable:
|
|
||||||
/* The first 5 entries (80 bytes) of this table are unused (registers
|
|
||||||
* a0..a4 are handled separately above). Rather than have a whole bunch
|
|
||||||
* of wasted space, we just pretend that the table starts 80 bytes
|
|
||||||
* earlier in memory. */
|
|
||||||
.set .LSE_jumptable_base, .LSE_jumptable - (16 * 5)
|
|
||||||
|
|
||||||
.org .LSE_jumptable_base + (16 * 5)
|
|
||||||
mov a5, a4
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.org .LSE_jumptable_base + (16 * 6)
|
|
||||||
mov a6, a4
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.org .LSE_jumptable_base + (16 * 7)
|
|
||||||
mov a7, a4
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.org .LSE_jumptable_base + (16 * 8)
|
|
||||||
mov a8, a4
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.org .LSE_jumptable_base + (16 * 9)
|
|
||||||
mov a9, a4
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.org .LSE_jumptable_base + (16 * 10)
|
|
||||||
mov a10, a4
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.org .LSE_jumptable_base + (16 * 11)
|
|
||||||
mov a11, a4
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.org .LSE_jumptable_base + (16 * 12)
|
|
||||||
mov a12, a4
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.org .LSE_jumptable_base + (16 * 13)
|
|
||||||
mov a13, a4
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.org .LSE_jumptable_base + (16 * 14)
|
|
||||||
mov a14, a4
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
.org .LSE_jumptable_base + (16 * 15)
|
|
||||||
mov a15, a4
|
|
||||||
l32i a2, sp, 0x08
|
|
||||||
l32i a4, sp, 0x10
|
|
||||||
rsr a1, excsave1
|
|
||||||
rfe
|
|
||||||
|
|
||||||
/*************************** Debug exception handler *************************/
|
|
||||||
|
|
||||||
.section .vecbase.text, "x"
|
|
||||||
.literal_position
|
|
||||||
.balign 4
|
|
||||||
|
|
||||||
DebugExceptionHandler:
|
|
||||||
wsr a0, excsave2
|
|
||||||
// Save context in case an actual debugger is running
|
|
||||||
movi a0, debug_saved_ctx
|
|
||||||
// Save a1 - a4 as we are going to use them later
|
|
||||||
s32i a1, a0, 0x04
|
|
||||||
s32i a2, a0, 0x08
|
|
||||||
s32i a3, a0, 0x0C
|
|
||||||
s32i a4, a0, 0x10
|
|
||||||
// Save a0
|
|
||||||
rsr a4, excsave2
|
|
||||||
s32i a4, a0, 0x00
|
|
||||||
// Default handler is fatal_exception_handler(uint32_t * sp, bool registers_saved_on_stack)
|
|
||||||
// sp
|
|
||||||
mov a2, a1
|
|
||||||
// registers_saved_on_stack
|
|
||||||
movi a3, 0
|
|
||||||
call0 debug_exception_handler
|
|
||||||
rfi 2
|
|
||||||
|
|
||||||
/****************************** call_user_start ******************************/
|
|
||||||
|
|
||||||
.section .vecbase.text, "x"
|
|
||||||
|
|
||||||
/* This is the first entrypoint called from the ROM after loading the image
|
|
||||||
* into IRAM. It just sets up the VECBASE register to point at our own
|
|
||||||
* exception vectors and then calls sdk_user_start() */
|
|
||||||
|
|
||||||
.literal_position
|
|
||||||
|
|
||||||
.balign 4
|
|
||||||
call_user_start:
|
|
||||||
.global call_user_start
|
|
||||||
.type call_user_start, @function
|
|
||||||
|
|
||||||
movi a2, VecBase
|
|
||||||
wsr a2, vecbase
|
|
||||||
call0 sdk_user_start
|
|
||||||
|
|
||||||
/*************************** NMI Exception Handler ***************************/
|
|
||||||
|
|
||||||
#define NMI_STACK_CANARY 0xABBABABA
|
|
||||||
|
|
||||||
.section .vecbase.text, "x"
|
|
||||||
|
|
||||||
.literal_position
|
|
||||||
.balign 16
|
|
||||||
NMIExceptionHandler:
|
|
||||||
.type NMIExceptionHandler, @function
|
|
||||||
|
|
||||||
wsr sp, excsave3 # excsave3 holds user stack
|
|
||||||
movi sp, .NMIHandlerStackTop - 0x40
|
|
||||||
s32i a0, sp, 0x00
|
|
||||||
s32i a2, sp, 0x04
|
|
||||||
s32i a3, sp, 0x08
|
|
||||||
s32i a4, sp, 0x0c
|
|
||||||
s32i a5, sp, 0x10
|
|
||||||
s32i a6, sp, 0x14
|
|
||||||
s32i a7, sp, 0x18
|
|
||||||
s32i a8, sp, 0x1c
|
|
||||||
s32i a9, sp, 0x20
|
|
||||||
s32i a10, sp, 0x24
|
|
||||||
s32i a11, sp, 0x28
|
|
||||||
rsr a0, epc1
|
|
||||||
s32i a0, sp, 0x2c
|
|
||||||
rsr a0, exccause
|
|
||||||
s32i a0, sp, 0x30
|
|
||||||
rsr a0, excsave1
|
|
||||||
s32i a0, sp, 0x34
|
|
||||||
rsr a0, excvaddr
|
|
||||||
s32i a0, sp, 0x38
|
|
||||||
rsr a0, sar
|
|
||||||
s32i a0, sp, 0x3c
|
|
||||||
movi a0, 0x23 # Override PS for NMI handler
|
|
||||||
wsr a0, ps
|
|
||||||
rsync
|
|
||||||
|
|
||||||
/* mark the stack overflow point before we call the actual NMI handler */
|
|
||||||
movi a0, NMIHandlerStack
|
|
||||||
movi a2, NMI_STACK_CANARY
|
|
||||||
s32i a2, a0, 0x00
|
|
||||||
|
|
||||||
call0 sdk_wDev_ProcessFiq
|
|
||||||
|
|
||||||
/* verify we didn't overflow */
|
|
||||||
movi a0, NMIHandlerStack
|
|
||||||
l32i a3, a0, 0
|
|
||||||
movi a2, NMI_STACK_CANARY
|
|
||||||
bne a3, a2, .NMIFatalStackOverflow
|
|
||||||
|
|
||||||
l32i a0, sp, 0x3c
|
|
||||||
wsr a0, sar
|
|
||||||
l32i a0, sp, 0x38
|
|
||||||
wsr a0, excvaddr
|
|
||||||
l32i a0, sp, 0x34
|
|
||||||
wsr a0, excsave1
|
|
||||||
l32i a0, sp, 0x30
|
|
||||||
wsr a0, exccause
|
|
||||||
l32i a0, sp, 0x2c
|
|
||||||
wsr a0, epc1
|
|
||||||
l32i a11, sp, 0x28
|
|
||||||
l32i a10, sp, 0x24
|
|
||||||
l32i a9, sp, 0x20
|
|
||||||
l32i a8, sp, 0x1c
|
|
||||||
l32i a7, sp, 0x18
|
|
||||||
l32i a6, sp, 0x14
|
|
||||||
l32i a5, sp, 0x10
|
|
||||||
l32i a4, sp, 0x0c
|
|
||||||
l32i a3, sp, 0x08
|
|
||||||
movi a0, 0x33 # Reset PS
|
|
||||||
wsr a0, ps
|
|
||||||
rsync
|
|
||||||
/* set dport nmi status to 1 (wDev_ProcessFiq clears bit 0 and verifies it
|
|
||||||
* stays cleared, see
|
|
||||||
* http://esp8266-re.foogod.com/wiki/WDev_ProcessFiq_%28IoT_RTOS_SDK_0.9.9%29)
|
|
||||||
*/
|
|
||||||
movi a0, 0x3ff00000
|
|
||||||
movi a2, 0x1
|
|
||||||
s32i a2, a0, 0
|
|
||||||
l32i a2, sp, 0x04
|
|
||||||
l32i a0, sp, 0x00
|
|
||||||
movi a1, 0x0
|
|
||||||
xsr a1, excsave3 # Load stack back from excsave3, clear excsave3
|
|
||||||
rfi 3
|
|
||||||
|
|
||||||
.section .rodata
|
|
||||||
|
|
||||||
.NMIStackOverflowErrorMsg:
|
|
||||||
.string "\nFATAL: NMI Stack Overflow\n"
|
|
||||||
|
|
||||||
.section .vecbase.text, "x"
|
|
||||||
|
|
||||||
.NMIFatalStackOverflow:
|
|
||||||
movi a2, .NMIStackOverflowErrorMsg
|
|
||||||
call0 printf
|
|
||||||
.NMIInfiniteLoop:
|
|
||||||
j .NMIInfiniteLoop /* TODO: replace with call to abort() */
|
|
||||||
|
|
||||||
/*********************** General UserException Handler ***********************/
|
|
||||||
|
|
||||||
.section .vecbase.text, "x"
|
|
||||||
|
|
||||||
/* Called by UserExceptionVector if EXCCAUSE is anything other than
|
|
||||||
* LoadStoreCause. */
|
|
||||||
|
|
||||||
.literal_position
|
|
||||||
.balign 4
|
|
||||||
UserExceptionHandler:
|
|
||||||
.type UserExceptionHandler, @function
|
|
||||||
// save a0, a1 to debug_saved_ctx before stack pointer is affected
|
|
||||||
// excsave1 contains a1
|
|
||||||
// a1 was changed earlier
|
|
||||||
movi a1, debug_saved_ctx
|
|
||||||
// store a0
|
|
||||||
s32i a0, a1, 0x00
|
|
||||||
xsr a0, excsave1
|
|
||||||
// store a1
|
|
||||||
s32i a0, a1, 0x04
|
|
||||||
mov sp, a0
|
|
||||||
addi sp, sp, -0x50
|
|
||||||
s32i a0, sp, 0x10
|
|
||||||
rsr a0, ps
|
|
||||||
s32i a0, sp, 0x08
|
|
||||||
rsr a0, epc1
|
|
||||||
s32i a0, sp, 0x04
|
|
||||||
rsr a0, excsave1
|
|
||||||
s32i a0, sp, 0x0c
|
|
||||||
movi a0, _xt_user_exit
|
|
||||||
s32i a0, sp, 0x0
|
|
||||||
call0 sdk__xt_int_enter
|
|
||||||
movi a0, 0x23
|
|
||||||
wsr a0, ps
|
|
||||||
rsync
|
|
||||||
rsr a2, exccause
|
|
||||||
/* Any UserException cause other than a level 1 interrupt is fatal */
|
|
||||||
bnei a2, CAUSE_LVL1INT, .LUserFailOtherExceptionCause
|
|
||||||
.LUserHandleInterrupt:
|
|
||||||
rsil a0, 1
|
|
||||||
rsr a2, intenable
|
|
||||||
rsr a3, interrupt
|
|
||||||
movi a4, 0x3fff
|
|
||||||
and a2, a2, a3
|
|
||||||
and a2, a2, a4 # a2 = 0x3FFF & INTENABLE & INTERRUPT
|
|
||||||
call0 _xt_isr_handler
|
|
||||||
call0 sdk__xt_int_exit # once finished, jumps to _xt_user_exit via stack
|
|
||||||
|
|
||||||
.literal_position
|
|
||||||
.LUserFailOtherExceptionCause:
|
|
||||||
break 1, 1
|
|
||||||
addi a2, a1, 0x50 /* UserExceptionHandler pushes stack down 0x50 */
|
|
||||||
movi a3, 1
|
|
||||||
call0 fatal_exception_handler
|
|
||||||
|
|
||||||
/* _xt_user_exit is pushed onto the stack as part of the user exception handler,
|
|
||||||
restores same set registers which were saved there and returns from exception */
|
|
||||||
_xt_user_exit:
|
_xt_user_exit:
|
||||||
.global _xt_user_exit
|
l32i a0, sp, 0x8
|
||||||
.type _xt_user_exit, @function
|
wsr.ps a0
|
||||||
l32i a0, sp, 0x8
|
l32i a0, sp, 0x4
|
||||||
wsr a0, ps
|
wsr.epc1 a0
|
||||||
l32i a0, sp, 0x4
|
l32i a0, sp, 0xc
|
||||||
wsr a0, epc1
|
l32i sp, sp, 0x10
|
||||||
l32i a0, sp, 0xc
|
rsync
|
||||||
l32i sp, sp, 0x10
|
rfe
|
||||||
rsync
|
|
||||||
rfe
|
|
||||||
|
|
|
@ -37,79 +37,15 @@
|
||||||
#define VAL2FIELD_M(fieldname, value) (((value) & fieldname##_M) << fieldname##_S)
|
#define VAL2FIELD_M(fieldname, value) (((value) & fieldname##_M) << fieldname##_S)
|
||||||
#define SET_FIELD_M(regbits, fieldname, value) (((regbits) & ~FIELD_MASK(fieldname)) | VAL2FIELD_M(fieldname, value))
|
#define SET_FIELD_M(regbits, fieldname, value) (((regbits) & ~FIELD_MASK(fieldname)) | VAL2FIELD_M(fieldname, value))
|
||||||
|
|
||||||
/* Set bits in reg with specified mask.
|
/* Use this macro to store constant values in IROM flash instead
|
||||||
*/
|
of having them loaded into rodata (which resides in DRAM)
|
||||||
#define SET_MASK_BITS(reg, mask) (reg) |= (mask)
|
|
||||||
|
|
||||||
/* Clear bits in reg with specified mask
|
Unlike the ESP8266 SDK you don't need an attribute like this for
|
||||||
*/
|
standard functions. They're stored in flash by default. But
|
||||||
#define CLEAR_MASK_BITS(reg, mask) (reg) &= ~(mask)
|
variables need them.
|
||||||
|
|
||||||
/* Use the IRAM macro to place functions into Instruction RAM (IRAM)
|
Important to note: IROM flash can only be accessed via 32-bit word
|
||||||
instead of flash (aka irom).
|
aligned reads. It's up to the user of this attribute to ensure this.
|
||||||
|
|
||||||
(This is the opposite to the Espressif SDK, where functions default
|
|
||||||
to being placed in IRAM but the ICACHE_FLASH_ATTR attribute will
|
|
||||||
place them in flash.)
|
|
||||||
|
|
||||||
Use the IRAM attribute for functions which are called when the
|
|
||||||
flash may not be available (for example during NMI exceptions), or
|
|
||||||
for functions which are called very frequently and need high
|
|
||||||
performance.
|
|
||||||
|
|
||||||
Usage example:
|
|
||||||
|
|
||||||
void IRAM high_performance_function(void)
|
|
||||||
{
|
|
||||||
// do important thing here
|
|
||||||
}
|
|
||||||
|
|
||||||
Bear in mind IRAM is limited (32KB), compared to up to 1MB of flash.
|
|
||||||
*/
|
|
||||||
#define IRAM __attribute__((section(".iram1.text")))
|
|
||||||
|
|
||||||
/* Use the RAM macro to place constant data (rodata) into RAM (data
|
|
||||||
RAM) instead of the default placement in flash. This is useful for
|
|
||||||
constant data which needs high performance access.
|
|
||||||
|
|
||||||
Usage example:
|
|
||||||
|
|
||||||
const RAM uint8_t constants[] = { 1, 2, 3, 7 };
|
|
||||||
|
|
||||||
When placing string literals in RAM, they need to be declared with
|
|
||||||
the type "const char[]" not "const char *"
|
|
||||||
|
|
||||||
Usage example:
|
|
||||||
|
|
||||||
const RAM char hello_world[] = "Hello World";
|
|
||||||
*/
|
|
||||||
#define RAM __attribute__((section(".data")))
|
|
||||||
|
|
||||||
/* Use the IRAM_DATA macro to place data into Instruction RAM (IRAM)
|
|
||||||
instead of the default of flash (for constant data) or data RAM
|
|
||||||
(for non-constant data).
|
|
||||||
|
|
||||||
This may be useful to free up data RAM. However all data read from
|
|
||||||
any instruction space (either IRAM or Flash) must be 32-bit aligned
|
|
||||||
word reads. Reading unaligned data stored with IRAM_DATA will be
|
|
||||||
slower than reading data stored in RAM. You can't perform unaligned
|
|
||||||
writes to IRAM.
|
|
||||||
*/
|
|
||||||
#define IRAM_DATA __attribute__((section(".iram1.data")))
|
|
||||||
|
|
||||||
/* Use the IROM macro to store constant values in IROM flash. In
|
|
||||||
esp-open-rtos this is already the default location for most constant
|
|
||||||
data (rodata), so you don't need this attribute in 99% of cases.
|
|
||||||
|
|
||||||
The exceptions are to mark data in the core & freertos libraries,
|
|
||||||
where the default for constant data storage is RAM.
|
|
||||||
|
|
||||||
(Unlike the Espressif SDK you don't need to use an attribute like
|
|
||||||
ICACHE_FLASH_ATTR for functions, they go into flash by default.)
|
|
||||||
|
|
||||||
Important to note: IROM flash is accessed via 32-bit word aligned
|
|
||||||
reads. esp-open-rtos does some magic to "fix" unaligned reads, but
|
|
||||||
performance is reduced.
|
|
||||||
*/
|
*/
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#define IROM __attribute__((section(".irom0.literal")))
|
#define IROM __attribute__((section(".irom0.literal")))
|
||||||
|
@ -117,5 +53,8 @@
|
||||||
#define IROM __attribute__((section(".irom0.literal"))) const
|
#define IROM __attribute__((section(".irom0.literal"))) const
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define INLINED inline static __attribute__((always_inline)) __attribute__((unused))
|
||||||
|
|
||||||
|
#define IRAM __attribute__((section(".iram1.text")))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
/* Functions for dumping status/debug output/etc, including fatal
|
|
||||||
* exception handling.
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
*
|
|
||||||
* Copyright (C) 2015-2016 Superhouse Automation Pty Ltd
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#ifndef _DEBUG_DUMPS_H
|
|
||||||
#define _DEBUG_DUMPS_H
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/* Dump stack memory to stdout, starting from stack pointer address sp. */
|
|
||||||
void dump_stack(uint32_t *sp);
|
|
||||||
|
|
||||||
/* Dump heap statistics to stdout */
|
|
||||||
void dump_heapinfo(void);
|
|
||||||
|
|
||||||
/* Called from exception_vectors.S when a fatal exception occurs.
|
|
||||||
|
|
||||||
Probably not useful to be called in other contexts.
|
|
||||||
*/
|
|
||||||
void __attribute__((noreturn)) fatal_exception_handler(uint32_t *sp, bool registers_saved_on_stack);
|
|
||||||
void __attribute__((weak, alias("fatal_exception_handler")))
|
|
||||||
debug_exception_handler(uint32_t *sp, bool registers_saved_on_stack);
|
|
||||||
|
|
||||||
#endif
|
|
33
core/include/esp/cpu.h
Normal file
33
core/include/esp/cpu.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* esp/cpu.h
|
||||||
|
*
|
||||||
|
* Details relating to the ESP8266 Xtensa core.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef _ESP_CPU_H
|
||||||
|
#define _ESP_CPU_H
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/* Interrupt numbers for level 1 exception handler.
|
||||||
|
*
|
||||||
|
* Currently the UserExceptionVector calls down to _xt_isr_handler,
|
||||||
|
* defined in port.c, for at least some of these interrupts. Some are handled
|
||||||
|
* on the SDK side, though.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
INUM_SPI = 2,
|
||||||
|
INUM_GPIO = 4,
|
||||||
|
INUM_UART = 5,
|
||||||
|
INUM_MAX = 6, /* in some places this is documented as timer0 CCOMPARE0 interrupt */
|
||||||
|
INUM_SOFT = 7,
|
||||||
|
INUM_WDT = 8,
|
||||||
|
INUM_TIMER_FRC1 = 9,
|
||||||
|
|
||||||
|
/* FRC2 default handler. Configured by sdk_ets_timer_init, which
|
||||||
|
runs as part of default libmain.a startup code, assigns
|
||||||
|
interrupt handler to sdk_vApplicationTickHook+0x68
|
||||||
|
*/
|
||||||
|
INUM_TIMER_FRC2 = 10,
|
||||||
|
} xt_isr_num_t;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -90,10 +90,6 @@ _Static_assert(sizeof(struct DPORT_REGS) == 0x60, "DPORT_REGS is the wrong size"
|
||||||
|
|
||||||
/* Details for CLOCKGATE_WATCHDOG register */
|
/* Details for CLOCKGATE_WATCHDOG register */
|
||||||
|
|
||||||
// Set and then cleared during sdk_system_restart_in_nmi().
|
|
||||||
// Not sure what this does. May be related to ESPSAR.UNKNOWN_48
|
|
||||||
#define DPORT_CLOCKGATE_WATCHDOG_UNKNOWN_8 BIT(8)
|
|
||||||
|
|
||||||
/* Comment found in pvvx/mp3_decode headers: "use clockgate_watchdog(flg) { if(flg) 0x3FF00018 &= 0x77; else 0x3FF00018 |= 8; }". Not sure what this means or does. */
|
/* Comment found in pvvx/mp3_decode headers: "use clockgate_watchdog(flg) { if(flg) 0x3FF00018 &= 0x77; else 0x3FF00018 |= 8; }". Not sure what this means or does. */
|
||||||
|
|
||||||
#define DPORT_CLOCKGATE_WATCHDOG_DISABLE BIT(3)
|
#define DPORT_CLOCKGATE_WATCHDOG_DISABLE BIT(3)
|
||||||
|
|
|
@ -10,93 +10,77 @@
|
||||||
#define _ESP_GPIO_H
|
#define _ESP_GPIO_H
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "esp/gpio_regs.h"
|
#include "esp/gpio_regs.h"
|
||||||
#include "esp/rtc_regs.h"
|
|
||||||
#include "esp/iomux.h"
|
#include "esp/iomux.h"
|
||||||
#include "esp/interrupts.h"
|
#include "esp/cpu.h"
|
||||||
|
#include "xtensa_interrupts.h"
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
GPIO_INPUT,
|
GPIO_INPUT,
|
||||||
GPIO_OUTPUT, /* "Standard" push-pull output */
|
GPIO_OUTPUT, /* "Standard" push-pull output */
|
||||||
GPIO_OUT_OPEN_DRAIN, /* Open drain output */
|
GPIO_OUT_OPEN_DRAIN, /* Open drain output */
|
||||||
|
GPIO_INPUT_PULLUP,
|
||||||
} gpio_direction_t;
|
} gpio_direction_t;
|
||||||
|
|
||||||
/* Enable GPIO on the specified pin, and set it to input or output mode.
|
/* Enable GPIO on the specified pin, and set it to input/output/ with
|
||||||
|
* pullup as needed
|
||||||
*/
|
*/
|
||||||
void gpio_enable(const uint8_t gpio_num, const gpio_direction_t direction);
|
INLINED void gpio_enable(const uint8_t gpio_num, const gpio_direction_t direction)
|
||||||
|
{
|
||||||
|
uint32_t iomux_flags;
|
||||||
|
|
||||||
/* Enable/disable internal pullup resistor for a particular GPIO
|
switch(direction) {
|
||||||
*
|
case GPIO_INPUT:
|
||||||
* Note: According to Espressif, pullup resistor values are between 30K and
|
iomux_flags = 0;
|
||||||
* 100K ohms (see http://bbs.espressif.com/viewtopic.php?t=1079#p4097)
|
break;
|
||||||
* However, measured values suggest that the actual value is likely to be close
|
case GPIO_OUTPUT:
|
||||||
* to 47K in reality.
|
iomux_flags = IOMUX_PIN_OUTPUT_ENABLE;
|
||||||
*
|
break;
|
||||||
* NOTE: The enabled_during_sleep setting is currently untested (please send
|
case GPIO_OUT_OPEN_DRAIN:
|
||||||
* feedback if you give it a try)
|
iomux_flags = IOMUX_PIN_OUTPUT_ENABLE;
|
||||||
*/
|
break;
|
||||||
void gpio_set_pullup(uint8_t gpio_num, bool enabled, bool enabled_during_sleep);
|
case GPIO_INPUT_PULLUP:
|
||||||
|
iomux_flags = IOMUX_PIN_PULLUP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
iomux_set_gpio_function(gpio_num, iomux_flags);
|
||||||
|
if(direction == GPIO_OUT_OPEN_DRAIN)
|
||||||
|
GPIO.CONF[gpio_num] |= GPIO_CONF_OPEN_DRAIN;
|
||||||
|
else
|
||||||
|
GPIO.CONF[gpio_num] &= ~GPIO_CONF_OPEN_DRAIN;
|
||||||
|
if (iomux_flags & IOMUX_PIN_OUTPUT_ENABLE)
|
||||||
|
GPIO.ENABLE_OUT_SET = BIT(gpio_num);
|
||||||
|
else
|
||||||
|
GPIO.ENABLE_OUT_CLEAR = BIT(gpio_num);
|
||||||
|
}
|
||||||
|
|
||||||
/* Disable GPIO on the specified pin, and set it Hi-Z.
|
/* Disable GPIO on the specified pin, and set it Hi-Z.
|
||||||
*
|
*
|
||||||
* If later muxing this pin to a different function, make sure to set
|
* If later muxing this pin to a different function, make sure to set
|
||||||
* IOMUX_PIN_OUTPUT_ENABLE if necessary to enable the output buffer.
|
* IOMUX_PIN_OUTPUT_ENABLE if necessary to enable the output buffer.
|
||||||
*/
|
*/
|
||||||
static inline void gpio_disable(const uint8_t gpio_num)
|
INLINED void gpio_disable(const uint8_t gpio_num)
|
||||||
{
|
{
|
||||||
GPIO.ENABLE_OUT_CLEAR = BIT(gpio_num);
|
GPIO.ENABLE_OUT_CLEAR = BIT(gpio_num);
|
||||||
*gpio_iomux_reg(gpio_num) &= ~IOMUX_PIN_OUTPUT_ENABLE;
|
*gpio_iomux_reg(gpio_num) &= ~IOMUX_PIN_OUTPUT_ENABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set whether the specified pin continues to drive its output when the ESP8266
|
|
||||||
* goes into sleep mode. Note that this setting is reset to off whenever
|
|
||||||
* gpio_enable is called, so this must be called after calling that function.
|
|
||||||
*
|
|
||||||
* NOTE: This functionality is currently untested (please send feedback if you
|
|
||||||
* give it a try)
|
|
||||||
*/
|
|
||||||
static inline void gpio_set_output_on_sleep(const uint8_t gpio_num, bool enabled)
|
|
||||||
{
|
|
||||||
if (enabled) {
|
|
||||||
IOMUX.PIN[gpio_to_iomux(gpio_num)] |= IOMUX_PIN_OUTPUT_ENABLE_SLEEP;
|
|
||||||
} else {
|
|
||||||
IOMUX.PIN[gpio_to_iomux(gpio_num)] &= ~IOMUX_PIN_OUTPUT_ENABLE_SLEEP;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set output of a pin high or low.
|
/* Set output of a pin high or low.
|
||||||
*
|
*
|
||||||
* Only works if pin has been set to GPIO_OUTPUT or GPIO_OUT_OPEN_DRAIN via
|
* Only works if pin has been set to GPIO_OUTPUT via gpio_enable()
|
||||||
* gpio_enable()
|
|
||||||
*
|
|
||||||
* If the mode is GPIO_OUT_OPEN_DRAIN, setting it low (false) will pull the pin
|
|
||||||
* down to ground, but setting it high (true) will allow it to float. Note
|
|
||||||
* that even in GPIO_OUT_OPEN_DRAIN mode, the input gates are still physically
|
|
||||||
* connected to the pin, and can be damaged if the voltage is not in either the
|
|
||||||
* "low" or "high" range. Make sure there is some sort of pull-up resistor on
|
|
||||||
* the line to avoid floating logic lines!
|
|
||||||
*/
|
*/
|
||||||
static inline void gpio_write(const uint8_t gpio_num, const bool set)
|
INLINED void gpio_write(const uint8_t gpio_num, const bool set)
|
||||||
{
|
{
|
||||||
if (gpio_num == 16) {
|
if(set)
|
||||||
RTC.GPIO_OUT = (RTC.GPIO_OUT & 0xfffffffe) | (set ? 1 : 0);
|
GPIO.OUT_SET = BIT(gpio_num);
|
||||||
} else if (set)
|
|
||||||
GPIO.OUT_SET = BIT(gpio_num) & GPIO_OUT_PIN_MASK;
|
|
||||||
else
|
else
|
||||||
GPIO.OUT_CLEAR = BIT(gpio_num) & GPIO_OUT_PIN_MASK;
|
GPIO.OUT_CLEAR = BIT(gpio_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Toggle output of a pin
|
/* Toggle output of a pin
|
||||||
*
|
*
|
||||||
* Only works if pin has been set to GPIO_OUTPUT or GPIO_OUT_OPEN_DRAIN via
|
* Only works if pin has been set to GPIO_OUTPUT via gpio_enable()
|
||||||
* gpio_enable()
|
|
||||||
*
|
|
||||||
* See notes in gpio_write() about GPIO_OUT_OPEN_DRAIN mode.
|
|
||||||
*/
|
*/
|
||||||
static inline void gpio_toggle(const uint8_t gpio_num)
|
INLINED void gpio_toggle(const uint8_t gpio_num)
|
||||||
{
|
{
|
||||||
/* Why implement like this instead of GPIO_OUT_REG ^= xxx?
|
/* Why implement like this instead of GPIO_OUT_REG ^= xxx?
|
||||||
Concurrency. If an interrupt or higher priority task writes to
|
Concurrency. If an interrupt or higher priority task writes to
|
||||||
|
@ -104,86 +88,41 @@ static inline void gpio_toggle(const uint8_t gpio_num)
|
||||||
get an invalid value. Prevents one task from clobbering another
|
get an invalid value. Prevents one task from clobbering another
|
||||||
task's pins, without needing to disable/enable interrupts.
|
task's pins, without needing to disable/enable interrupts.
|
||||||
*/
|
*/
|
||||||
if (GPIO.OUT & BIT(gpio_num))
|
if(GPIO.OUT & BIT(gpio_num))
|
||||||
GPIO.OUT_CLEAR = BIT(gpio_num) & GPIO_OUT_PIN_MASK;
|
GPIO.OUT_CLEAR = BIT(gpio_num);
|
||||||
else
|
else
|
||||||
GPIO.OUT_SET = BIT(gpio_num) & GPIO_OUT_PIN_MASK;
|
GPIO.OUT_SET = BIT(gpio_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read input value of a GPIO pin.
|
/* Read input value of a GPIO pin.
|
||||||
*
|
*
|
||||||
* If pin is set GPIO_INPUT, this reads the level on the pin.
|
* If pin is set as an input, this reads the value on the pin.
|
||||||
* If pin is set GPIO_OUTPUT, this reads the level at which the pin is
|
* If pin is set as an output, this reads the last value written to the pin.
|
||||||
* currently being driven (i.e. the last value written).
|
|
||||||
* If pin is set GPIO_OUT_OPEN_DRAIN, when the pin is written low, this will
|
|
||||||
* return low (false), when the pin is written high, this will behave like
|
|
||||||
* GPIO_INPUT.
|
|
||||||
*/
|
*/
|
||||||
static inline bool gpio_read(const uint8_t gpio_num)
|
INLINED bool gpio_read(const uint8_t gpio_num)
|
||||||
{
|
{
|
||||||
if (gpio_num == 16)
|
return GPIO.IN & BIT(gpio_num);
|
||||||
return RTC.GPIO_IN & 1;
|
|
||||||
else
|
|
||||||
return GPIO.IN & BIT(gpio_num);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef void (* gpio_interrupt_handler_t)(uint8_t gpio_num);
|
extern void gpio_interrupt_handler(void);
|
||||||
|
|
||||||
/*
|
|
||||||
* You can implement GPIO interrupt handlers in either of two ways:
|
|
||||||
* - Implement handler and use it with the gpio_set_interrupt()
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* void my_intr_handler(uint8_t gpio_num) {
|
|
||||||
* // Do something when GPIO changes
|
|
||||||
* }
|
|
||||||
* ...
|
|
||||||
* gpio_set_interrupt(MY_GPIO_NUM, GPIO_INTTYPE_EDGE_ANY, my_intr_handler);
|
|
||||||
*
|
|
||||||
* OR
|
|
||||||
*
|
|
||||||
* - Implement a single function named gpio_interrupt_handler(). This
|
|
||||||
* will need to manually check GPIO.STATUS and clear any status
|
|
||||||
* bits after handling interrupts. This gives you full control, but
|
|
||||||
* you can't combine it with the first approach.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* void IRAM gpio_interrupt_handler(void *arg) {
|
|
||||||
* // check GPIO.STATUS
|
|
||||||
* // write GPIO.STATUS_CLEAR
|
|
||||||
* // Do something when GPIO changes
|
|
||||||
* }
|
|
||||||
* ...
|
|
||||||
* gpio_set_interrupt(MY_GPIO_NUM, GPIO_INTTYPE_EDGE_ANY, NULL);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Set the interrupt type for a given pin
|
/* Set the interrupt type for a given pin
|
||||||
*
|
*
|
||||||
* If int_type is not GPIO_INTTYPE_NONE, the gpio_interrupt_handler will be
|
* If int_type is not GPIO_INTTYPE_NONE, the gpio_interrupt_handler will be attached and unmasked.
|
||||||
* attached and unmasked.
|
|
||||||
*/
|
*/
|
||||||
void gpio_set_interrupt(const uint8_t gpio_num, const gpio_inttype_t int_type, gpio_interrupt_handler_t handler);
|
INLINED void gpio_set_interrupt(const uint8_t gpio_num, const gpio_inttype_t int_type)
|
||||||
|
{
|
||||||
|
GPIO.CONF[gpio_num] = SET_FIELD(GPIO.CONF[gpio_num], GPIO_CONF_INTTYPE, int_type);
|
||||||
|
if(int_type != GPIO_INTTYPE_NONE) {
|
||||||
|
_xt_isr_attach(INUM_GPIO, gpio_interrupt_handler);
|
||||||
|
_xt_isr_unmask(1<<INUM_GPIO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Return the interrupt type set for a pin */
|
/* Return the interrupt type set for a pin */
|
||||||
static inline gpio_inttype_t gpio_get_interrupt(const uint8_t gpio_num)
|
INLINED gpio_inttype_t gpio_get_interrupt(const uint8_t gpio_num)
|
||||||
{
|
{
|
||||||
return (gpio_inttype_t)FIELD2VAL(GPIO_CONF_INTTYPE, GPIO.CONF[gpio_num]);
|
return (gpio_inttype_t)FIELD2VAL(GPIO_CONF_INTTYPE, GPIO.CONF[gpio_num]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set GPIO I/O Mux function.
|
|
||||||
* The 'func' is an IOMUX_GPIO<n>_FUNC_<function> value, see iomux_regs.h
|
|
||||||
*/
|
|
||||||
inline static void gpio_set_iomux_function(const uint8_t gpio_num, uint32_t func)
|
|
||||||
{
|
|
||||||
uint8_t iomux_num = gpio_to_iomux(gpio_num);
|
|
||||||
uint32_t prev = IOMUX.PIN[iomux_num] & ~IOMUX_PIN_FUNC_MASK;
|
|
||||||
IOMUX.PIN[iomux_num] = func | prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -40,22 +40,6 @@
|
||||||
* be reset by writing to STATUS or STATUS_CLEAR.
|
* be reset by writing to STATUS or STATUS_CLEAR.
|
||||||
*
|
*
|
||||||
* (_SET/_CLEAR function similarly to OUT registers)
|
* (_SET/_CLEAR function similarly to OUT registers)
|
||||||
*
|
|
||||||
* IN:
|
|
||||||
*
|
|
||||||
* Low 16 bits represent GPIO0-15 state (see also above).
|
|
||||||
*
|
|
||||||
* High 16 bits represent "strapping pins" values captured at reset time:
|
|
||||||
* bit 31 - GPIO10 (SD_DATA3)
|
|
||||||
* bit 30 - GPIO9 (SD_DATA2)
|
|
||||||
* bit 29 - GPIO7 (SD_DATA0)
|
|
||||||
* bit 18 - GPIO15 (MTDO)
|
|
||||||
* bit 17 - GPIO0
|
|
||||||
* bit 16 - GPIO2
|
|
||||||
* (In other words, highest 3 and lowest 3 bits of 16-bit half-word are used).
|
|
||||||
* BootROM uses strapping pin values to determine boot mode.
|
|
||||||
*
|
|
||||||
* Source and more information: 0D-ESP8266__Pin_List*.xlsx document
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct GPIO_REGS {
|
struct GPIO_REGS {
|
||||||
|
@ -70,28 +54,13 @@ struct GPIO_REGS {
|
||||||
uint32_t volatile STATUS_SET; // 0x20
|
uint32_t volatile STATUS_SET; // 0x20
|
||||||
uint32_t volatile STATUS_CLEAR; // 0x24
|
uint32_t volatile STATUS_CLEAR; // 0x24
|
||||||
uint32_t volatile CONF[16]; // 0x28 - 0x64
|
uint32_t volatile CONF[16]; // 0x28 - 0x64
|
||||||
uint32_t volatile DSM; // 0x68
|
uint32_t volatile PWM; // 0x68
|
||||||
uint32_t volatile RTC_CALIB; // 0x6c
|
uint32_t volatile RTC_CALIB; // 0x6c
|
||||||
uint32_t volatile RTC_CALIB_RESULT; // 0x70
|
uint32_t volatile RTC_CALIB_RESULT; // 0x70
|
||||||
};
|
};
|
||||||
|
|
||||||
_Static_assert(sizeof(struct GPIO_REGS) == 0x74, "GPIO_REGS is the wrong size");
|
_Static_assert(sizeof(struct GPIO_REGS) == 0x74, "GPIO_REGS is the wrong size");
|
||||||
|
|
||||||
/* Details for additional OUT register fields */
|
|
||||||
|
|
||||||
/* Bottom 16 bits of GPIO.OUT are for GPIOs 0-15, but upper 16 bits
|
|
||||||
are used to configure the input signalling pins for Bluetooth
|
|
||||||
Coexistence config (see esp/phy.h for a wrapper function).
|
|
||||||
*/
|
|
||||||
#define GPIO_OUT_PIN_MASK 0x0000FFFF
|
|
||||||
#define GPIO_OUT_BT_COEXIST_MASK 0x03FF0000
|
|
||||||
#define GPIO_OUT_BT_ACTIVE_ENABLE BIT(24)
|
|
||||||
#define GPIO_OUT_BT_PRIORITY_ENABLE BIT(25)
|
|
||||||
#define GPIO_OUT_BT_ACTIVE_PIN_M 0x0F
|
|
||||||
#define GPIO_OUT_BT_ACTIVE_PIN_S 16
|
|
||||||
#define GPIO_OUT_BT_PRIORITY_PIN_M 0x0F
|
|
||||||
#define GPIO_OUT_BT_PRIORITY_PIN_S 20
|
|
||||||
|
|
||||||
/* Details for CONF[i] registers */
|
/* Details for CONF[i] registers */
|
||||||
|
|
||||||
/* GPIO.CONF[i] control the pin behavior for the corresponding GPIO in/output.
|
/* GPIO.CONF[i] control the pin behavior for the corresponding GPIO in/output.
|
||||||
|
@ -117,9 +86,9 @@ _Static_assert(sizeof(struct GPIO_REGS) == 0x74, "GPIO_REGS is the wrong size");
|
||||||
* GPIO_CONF_OPEN_DRAIN does not appear to work on all pins.
|
* GPIO_CONF_OPEN_DRAIN does not appear to work on all pins.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* GPIO_CONF_SOURCE_DSM (boolean)
|
* GPIO_CONF_SOURCE_PWM (boolean)
|
||||||
* When set, GPIO pin output will be connected to the sigma-delta
|
* When set, GPIO pin output will be connected to the sigma-delta PWM
|
||||||
* generator (controlled by the GPIO.DSM register). When cleared, pin
|
* generator (controlled by the GPIO.PWM register). When cleared, pin
|
||||||
* output will function as a normal GPIO output (controlled by the
|
* output will function as a normal GPIO output (controlled by the
|
||||||
* GPIO.OUT* registers).
|
* GPIO.OUT* registers).
|
||||||
*/
|
*/
|
||||||
|
@ -130,7 +99,7 @@ _Static_assert(sizeof(struct GPIO_REGS) == 0x74, "GPIO_REGS is the wrong size");
|
||||||
#define GPIO_CONF_INTTYPE_M 0x00000007
|
#define GPIO_CONF_INTTYPE_M 0x00000007
|
||||||
#define GPIO_CONF_INTTYPE_S 7
|
#define GPIO_CONF_INTTYPE_S 7
|
||||||
#define GPIO_CONF_OPEN_DRAIN BIT(2)
|
#define GPIO_CONF_OPEN_DRAIN BIT(2)
|
||||||
#define GPIO_CONF_SOURCE_DSM BIT(0)
|
#define GPIO_CONF_SOURCE_PWM BIT(0)
|
||||||
|
|
||||||
/* Valid values for the GPIO_CONF_INTTYPE field */
|
/* Valid values for the GPIO_CONF_INTTYPE field */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -142,13 +111,13 @@ typedef enum {
|
||||||
GPIO_INTTYPE_LEVEL_HIGH = 5,
|
GPIO_INTTYPE_LEVEL_HIGH = 5,
|
||||||
} gpio_inttype_t;
|
} gpio_inttype_t;
|
||||||
|
|
||||||
/* Details for DSM register */
|
/* Details for PWM register */
|
||||||
|
|
||||||
#define GPIO_DSM_ENABLE BIT(16)
|
#define GPIO_PWM_ENABLE BIT(16)
|
||||||
#define GPIO_DSM_PRESCALER_M 0x000000ff
|
#define GPIO_PWM_PRESCALER_M 0x000000ff
|
||||||
#define GPIO_DSM_PRESCALER_S 8
|
#define GPIO_PWM_PRESCALER_S 8
|
||||||
#define GPIO_DSM_TARGET_M 0x000000ff
|
#define GPIO_PWM_TARGET_M 0x000000ff
|
||||||
#define GPIO_DSM_TARGET_S 0
|
#define GPIO_PWM_TARGET_S 0
|
||||||
|
|
||||||
/* Details for RTC_CALIB register */
|
/* Details for RTC_CALIB register */
|
||||||
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
/** esp/hwrand.h
|
|
||||||
*
|
|
||||||
* Hardware Random Number Generator functions.
|
|
||||||
*
|
|
||||||
* For documentation, see http://esp8266-re.foogod.com/wiki/Random_Number_Generator
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (C) 2015 Angus Gratton
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#ifndef _ESP_RNG_H
|
|
||||||
#define _ESP_RNG_H
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Return a random 32-bit number */
|
|
||||||
uint32_t hwrand(void);
|
|
||||||
|
|
||||||
/* Fill a variable size buffer with data from the Hardware RNG */
|
|
||||||
void hwrand_fill(uint8_t *buf, size_t len);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,137 +0,0 @@
|
||||||
/* esp/i2s_regs.h
|
|
||||||
*
|
|
||||||
* ESP8266 I2S register definitions
|
|
||||||
*
|
|
||||||
* Not compatible with ESP SDK register access code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ESP_I2S_REGS_H
|
|
||||||
#define _ESP_I2S_REGS_H
|
|
||||||
|
|
||||||
#include "esp/types.h"
|
|
||||||
#include "common_macros.h"
|
|
||||||
|
|
||||||
#define I2S_BASE 0x60000e00
|
|
||||||
#define I2S (*(struct I2S_REGS *)I2S_BASE)
|
|
||||||
|
|
||||||
struct I2S_REGS {
|
|
||||||
uint32_t volatile TXFIFO; // 0x00
|
|
||||||
uint32_t volatile RXFIFO; // 0x04
|
|
||||||
uint32_t volatile CONF; // 0x08
|
|
||||||
uint32_t volatile INT_RAW; // 0x0c
|
|
||||||
uint32_t volatile INT_STATUS; // 0x10
|
|
||||||
uint32_t volatile INT_ENABLE; // 0x14
|
|
||||||
uint32_t volatile INT_CLEAR; // 0x18
|
|
||||||
uint32_t volatile TIMING; // 0x1c
|
|
||||||
uint32_t volatile FIFO_CONF; // 0x20
|
|
||||||
uint32_t volatile RX_EOF_NUM; // 0x24
|
|
||||||
uint32_t volatile CONF_SINGLE_DATA; // 0x28
|
|
||||||
uint32_t volatile CONF_CHANNELS; // 0x2c
|
|
||||||
};
|
|
||||||
|
|
||||||
_Static_assert(sizeof(struct I2S_REGS) == 0x30, "I2S_REGS is the wrong size");
|
|
||||||
|
|
||||||
/* Details for CONF register */
|
|
||||||
|
|
||||||
#define I2S_CONF_BCK_DIV_M 0x0000003f
|
|
||||||
#define I2S_CONF_BCK_DIV_S 22
|
|
||||||
#define I2S_CONF_CLKM_DIV_M 0x0000003f
|
|
||||||
#define I2S_CONF_CLKM_DIV_S 16
|
|
||||||
#define I2S_CONF_BITS_MOD_M 0x0000000f
|
|
||||||
#define I2S_CONF_BITS_MOD_S 12
|
|
||||||
#define I2S_CONF_RX_MSB_SHIFT BIT(11)
|
|
||||||
#define I2S_CONF_TX_MSB_SHIFT BIT(10)
|
|
||||||
#define I2S_CONF_RX_START BIT(9)
|
|
||||||
#define I2S_CONF_TX_START BIT(8)
|
|
||||||
#define I2S_CONF_MSB_RIGHT BIT(7)
|
|
||||||
#define I2S_CONF_RIGHT_FIRST BIT(6)
|
|
||||||
#define I2S_CONF_RX_SLAVE_MOD BIT(5)
|
|
||||||
#define I2S_CONF_TX_SLAVE_MOD BIT(4)
|
|
||||||
#define I2S_CONF_RX_FIFO_RESET BIT(3)
|
|
||||||
#define I2S_CONF_TX_FIFO_RESET BIT(2)
|
|
||||||
#define I2S_CONF_RX_RESET BIT(1)
|
|
||||||
#define I2S_CONF_TX_RESET BIT(0)
|
|
||||||
#define I2S_CONF_RESET_MASK 0xf
|
|
||||||
|
|
||||||
/* Details for INT_RAW register */
|
|
||||||
|
|
||||||
#define I2S_INT_RAW_TX_REMPTY BIT(5)
|
|
||||||
#define I2S_INT_RAW_TX_WFULL BIT(4)
|
|
||||||
#define I2S_INT_RAW_RX_REMPTY BIT(3)
|
|
||||||
#define I2S_INT_RAW_RX_WFULL BIT(2)
|
|
||||||
#define I2S_INT_RAW_TX_PUT_DATA BIT(1)
|
|
||||||
#define I2S_INT_RAW_RX_TAKE_DATA BIT(0)
|
|
||||||
|
|
||||||
/* Details for INT_STATUS register */
|
|
||||||
|
|
||||||
#define I2S_INT_STATUS_TX_REMPTY BIT(5)
|
|
||||||
#define I2S_INT_STATUS_TX_WFULL BIT(4)
|
|
||||||
#define I2S_INT_STATUS_RX_REMPTY BIT(3)
|
|
||||||
#define I2S_INT_STATUS_RX_WFULL BIT(2)
|
|
||||||
#define I2S_INT_STATUS_TX_PUT_DATA BIT(1)
|
|
||||||
#define I2S_INT_STATUS_RX_TAKE_DATA BIT(0)
|
|
||||||
|
|
||||||
/* Details for INT_ENABLE register */
|
|
||||||
|
|
||||||
#define I2S_INT_ENABLE_TX_REMPTY BIT(5)
|
|
||||||
#define I2S_INT_ENABLE_TX_WFULL BIT(4)
|
|
||||||
#define I2S_INT_ENABLE_RX_REMPTY BIT(3)
|
|
||||||
#define I2S_INT_ENABLE_RX_WFULL BIT(2)
|
|
||||||
#define I2S_INT_ENABLE_TX_PUT_DATA BIT(1)
|
|
||||||
#define I2S_INT_ENABLE_RX_TAKE_DATA BIT(0)
|
|
||||||
|
|
||||||
/* Details for INT_CLEAR register */
|
|
||||||
|
|
||||||
#define I2S_INT_CLEAR_TX_REMPTY BIT(5)
|
|
||||||
#define I2S_INT_CLEAR_TX_WFULL BIT(4)
|
|
||||||
#define I2S_INT_CLEAR_RX_REMPTY BIT(3)
|
|
||||||
#define I2S_INT_CLEAR_RX_WFULL BIT(2)
|
|
||||||
#define I2S_INT_CLEAR_TX_PUT_DATA BIT(1)
|
|
||||||
#define I2S_INT_CLEAR_RX_TAKE_DATA BIT(0)
|
|
||||||
|
|
||||||
/* Details for TIMING register */
|
|
||||||
|
|
||||||
#define I2S_TIMING_TX_BCK_IN_INV BIT(22)
|
|
||||||
#define I2S_TIMING_RX_DSYNC_SW BIT(21)
|
|
||||||
#define I2S_TIMING_TX_DSYNC_SW BIT(20)
|
|
||||||
#define I2S_TIMING_RX_BCK_OUT_DELAY_M 0x00000003
|
|
||||||
#define I2S_TIMING_RX_BCK_OUT_DELAY_S 18
|
|
||||||
#define I2S_TIMING_RX_WS_OUT_DELAY_M 0x00000003
|
|
||||||
#define I2S_TIMING_RX_WS_OUT_DELAY_S 16
|
|
||||||
#define I2S_TIMING_TX_SD_OUT_DELAY_M 0x00000003
|
|
||||||
#define I2S_TIMING_TX_SD_OUT_DELAY_S 14
|
|
||||||
#define I2S_TIMING_TX_WS_OUT_DELAY_M 0x00000003
|
|
||||||
#define I2S_TIMING_TX_WS_OUT_DELAY_S 12
|
|
||||||
#define I2S_TIMING_TX_BCK_OUT_DELAY_M 0x00000003
|
|
||||||
#define I2S_TIMING_TX_BCK_OUT_DELAY_S 10
|
|
||||||
#define I2S_TIMING_RX_SD_IN_DELAY_M 0x00000003
|
|
||||||
#define I2S_TIMING_RX_SD_IN_DELAY_S 8
|
|
||||||
#define I2S_TIMING_RX_WS_IN_DELAY 0x00000003
|
|
||||||
#define I2S_TIMING_RX_WS_IN_DELAY_S 6
|
|
||||||
#define I2S_TIMING_RX_BCK_IN_DELAY_M 0x00000003
|
|
||||||
#define I2S_TIMING_RX_BCK_IN_DELAY_S 4
|
|
||||||
#define I2S_TIMING_TX_WS_IN_DELAY_M 0x00000003
|
|
||||||
#define I2S_TIMING_TX_WS_IN_DELAY_S 2
|
|
||||||
#define I2S_TIMING_TX_BCK_IN_DELAY_M 0x00000003
|
|
||||||
#define I2S_TIMING_TX_BCK_IN_DELAY_S 0
|
|
||||||
|
|
||||||
/* Details for FIFO_CONF register */
|
|
||||||
|
|
||||||
#define I2S_FIFO_CONF_RX_FIFO_MOD_M 0x00000007
|
|
||||||
#define I2S_FIFO_CONF_RX_FIFO_MOD_S 16
|
|
||||||
#define I2S_FIFO_CONF_TX_FIFO_MOD_M 0x00000007
|
|
||||||
#define I2S_FIFO_CONF_TX_FIFO_MOD_S 13
|
|
||||||
#define I2S_FIFO_CONF_DESCRIPTOR_ENABLE BIT(12)
|
|
||||||
#define I2S_FIFO_CONF_TX_DATA_NUM_M 0x0000003f
|
|
||||||
#define I2S_FIFO_CONF_TX_DATA_NUM_S 6
|
|
||||||
#define I2S_FIFO_CONF_RX_DATA_NUM_M 0x0000003f
|
|
||||||
#define I2S_FIFO_CONF_RX_DATA_NUM_S 0
|
|
||||||
|
|
||||||
/* Details for CONF_CHANNEL register */
|
|
||||||
|
|
||||||
#define I2S_CONF_CHANNELS_RX_CHANNEL_MOD_M 0x00000003
|
|
||||||
#define I2S_CONF_CHANNELS_RX_CHANNEL_MOD_S 3
|
|
||||||
#define I2S_CONF_CHANNELS_TX_CHANNEL_MOD_M 0x00000007
|
|
||||||
#define I2S_CONF_CHANNELS_TX_CHANNEL_MOD_S 0
|
|
||||||
|
|
||||||
#endif /* _ESP_I2S_REGS_H */
|
|
|
@ -1,124 +0,0 @@
|
||||||
/* ESP8266 Xtensa interrupt management functions
|
|
||||||
*
|
|
||||||
* Some (w/ sdk_ prefix) are implemented in binary libs, rest are
|
|
||||||
* inlines replacing functions in the binary libraries.
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (C) 2015 Superhouse Automation Pty Ltd
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#ifndef _XTENSA_INTERRUPTS_H
|
|
||||||
#define _XTENSA_INTERRUPTS_H
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <xtruntime.h>
|
|
||||||
#include <xtensa/hal.h>
|
|
||||||
#include <common_macros.h>
|
|
||||||
|
|
||||||
/* Interrupt numbers for level 1 exception handler. */
|
|
||||||
typedef enum {
|
|
||||||
INUM_WDEV_FIQ = 0,
|
|
||||||
INUM_SLC = 1,
|
|
||||||
INUM_SPI = 2,
|
|
||||||
INUM_RTC = 3,
|
|
||||||
INUM_GPIO = 4,
|
|
||||||
INUM_UART = 5,
|
|
||||||
INUM_TICK = 6, /* RTOS timer tick, possibly xtensa CPU CCOMPARE0(?) */
|
|
||||||
INUM_SOFT = 7,
|
|
||||||
INUM_WDT = 8,
|
|
||||||
INUM_TIMER_FRC1 = 9,
|
|
||||||
|
|
||||||
/* FRC2 default handler. Configured by sdk_ets_timer_init, which
|
|
||||||
runs as part of default libmain.a startup code, assigns
|
|
||||||
interrupt handler to sdk_vApplicationTickHook+0x68
|
|
||||||
*/
|
|
||||||
INUM_TIMER_FRC2 = 10,
|
|
||||||
} xt_isr_num_t;
|
|
||||||
|
|
||||||
void sdk__xt_int_exit(void);
|
|
||||||
void _xt_user_exit(void);
|
|
||||||
void sdk__xt_tick_timer_init(void);
|
|
||||||
void sdk__xt_timer_int(void *);
|
|
||||||
void sdk__xt_timer_int1(void);
|
|
||||||
|
|
||||||
/* The normal running level is 0.
|
|
||||||
* The system tick isr, timer frc2_isr, sv_isr etc run at level 1.
|
|
||||||
* Debug exceptions run at level 2?
|
|
||||||
* The wdev nmi runs at level 3.
|
|
||||||
*/
|
|
||||||
static inline uint32_t _xt_get_intlevel(void)
|
|
||||||
{
|
|
||||||
uint32_t level;
|
|
||||||
__asm__ volatile("rsr %0, ps" : "=a"(level));
|
|
||||||
return level & 0xf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* There are conflicting definitions for XCHAL_EXCM_LEVEL. Newlib
|
|
||||||
* defines it to be 1 and xtensa_rtos.h defines it to be 3. Don't want
|
|
||||||
* 3 as that is for the NMI and might want to check that the OS apis
|
|
||||||
* are not entered in level 3. Setting the interrupt level to 3 does
|
|
||||||
* not disable the NMI anyway. So set the level to 2.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef XCHAL_EXCM_LEVEL
|
|
||||||
#undef XCHAL_EXCM_LEVEL
|
|
||||||
#define XCHAL_EXCM_LEVEL 2
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Disable interrupts and return the old ps value, to pass into
|
|
||||||
_xt_restore_interrupts later.
|
|
||||||
|
|
||||||
This is desirable to use in place of
|
|
||||||
portDISABLE_INTERRUPTS/portENABLE_INTERRUPTS for
|
|
||||||
non-FreeRTOS & non-portable code.
|
|
||||||
*/
|
|
||||||
static inline uint32_t _xt_disable_interrupts(void)
|
|
||||||
{
|
|
||||||
uint32_t old_level;
|
|
||||||
__asm__ volatile ("rsil %0, " XTSTR(XCHAL_EXCM_LEVEL) : "=a" (old_level));
|
|
||||||
return old_level;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Restore PS level. Intended to be used with _xt_disable_interrupts */
|
|
||||||
static inline void _xt_restore_interrupts(uint32_t new_ps)
|
|
||||||
{
|
|
||||||
__asm__ volatile ("wsr %0, ps; rsync" :: "a" (new_ps));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint32_t _xt_isr_unmask(uint32_t unmask)
|
|
||||||
{
|
|
||||||
uint32_t old_level = _xt_disable_interrupts();
|
|
||||||
uint32_t intenable;
|
|
||||||
asm volatile ("rsr %0, intenable" : "=a" (intenable));
|
|
||||||
asm volatile ("wsr %0, intenable;" :: "a" (intenable | unmask));
|
|
||||||
_xt_restore_interrupts(old_level);
|
|
||||||
return intenable;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint32_t _xt_isr_mask(uint32_t mask)
|
|
||||||
{
|
|
||||||
uint32_t old_level = _xt_disable_interrupts();
|
|
||||||
uint32_t intenable;
|
|
||||||
asm volatile ("rsr %0, intenable" : "=a" (intenable));
|
|
||||||
asm volatile ("wsr %0, intenable;" :: "a" (intenable & ~mask));
|
|
||||||
_xt_restore_interrupts(old_level);
|
|
||||||
return intenable;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint32_t _xt_read_ints(void)
|
|
||||||
{
|
|
||||||
uint32_t interrupt;
|
|
||||||
asm volatile ("rsr %0, interrupt" : "=a" (interrupt));
|
|
||||||
return interrupt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void _xt_clear_ints(uint32_t mask)
|
|
||||||
{
|
|
||||||
asm volatile ("wsr %0, intclear; esync" :: "a" (mask));
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef void (* _xt_isr)(void *arg);
|
|
||||||
void _xt_isr_attach (uint8_t i, _xt_isr func, void *arg);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -11,10 +11,6 @@
|
||||||
#include "esp/types.h"
|
#include "esp/types.h"
|
||||||
#include "esp/iomux_regs.h"
|
#include "esp/iomux_regs.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a GPIO pin number to an iomux register index.
|
* Convert a GPIO pin number to an iomux register index.
|
||||||
*
|
*
|
||||||
|
@ -22,7 +18,7 @@ extern "C" {
|
||||||
* known at compile time, or return the result from a lookup table if not.
|
* known at compile time, or return the result from a lookup table if not.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uint8_t IRAM gpio_to_iomux(const uint8_t gpio_number);
|
inline static uint8_t gpio_to_iomux(const uint8_t gpio_number);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an iomux register index to a GPIO pin number.
|
* Convert an iomux register index to a GPIO pin number.
|
||||||
|
@ -31,7 +27,7 @@ uint8_t IRAM gpio_to_iomux(const uint8_t gpio_number);
|
||||||
* known at compile time, or return the result from a lookup table if not.
|
* known at compile time, or return the result from a lookup table if not.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uint8_t IRAM iomux_to_gpio(const uint8_t iomux_num);
|
inline static uint8_t iomux_to_gpio(const uint8_t iomux_num);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Directly get the IOMUX register for a particular gpio number
|
* Directly get the IOMUX register for a particular gpio number
|
||||||
|
@ -43,52 +39,29 @@ inline static esp_reg_t gpio_iomux_reg(const uint8_t gpio_number)
|
||||||
return &(IOMUX.PIN[gpio_to_iomux(gpio_number)]);
|
return &(IOMUX.PIN[gpio_to_iomux(gpio_number)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set IOMUX function.
|
|
||||||
*
|
|
||||||
* @param iomux_num Index of IOMUX register. Can be converted from GPIO number
|
|
||||||
* with gpio_to_iomux.
|
|
||||||
* @param iomux_func GPIO function definition IOMUX_GPIOn_FUNC_*
|
|
||||||
*/
|
|
||||||
inline static void iomux_set_function(uint8_t iomux_num, uint32_t iomux_func)
|
|
||||||
{
|
|
||||||
uint32_t prev = IOMUX.PIN[iomux_num] & ~IOMUX_PIN_FUNC_MASK;
|
|
||||||
IOMUX.PIN[iomux_num] = iomux_func | prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static void iomux_set_direction_flags(uint8_t iomux_num, uint32_t dir_flags)
|
|
||||||
{
|
|
||||||
uint32_t mask = IOMUX_PIN_OUTPUT_ENABLE | IOMUX_PIN_OUTPUT_ENABLE_SLEEP;
|
|
||||||
uint32_t prev = IOMUX.PIN[iomux_num] & ~mask;
|
|
||||||
IOMUX.PIN[iomux_num] = dir_flags | prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline static void iomux_set_pullup_flags(uint8_t iomux_num, uint32_t pullup_flags)
|
|
||||||
{
|
|
||||||
uint32_t mask = IOMUX_PIN_PULLUP | IOMUX_PIN_PULLDOWN | IOMUX_PIN_PULLUP_SLEEP | IOMUX_PIN_PULLDOWN_SLEEP;
|
|
||||||
uint32_t prev = IOMUX.PIN[iomux_num] & ~mask;
|
|
||||||
IOMUX.PIN[iomux_num] = pullup_flags | prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a pin to the GPIO function.
|
* Set a pin to the GPIO function.
|
||||||
*
|
*
|
||||||
* This allows you to set pins to GPIO without knowing in advance the
|
* This allows you to set pins to GPIO without knowing in advance the
|
||||||
* exact register masks to use.
|
* exact register masks to use.
|
||||||
*
|
*
|
||||||
* Sets the function and direction, but leaves the pullup configuration the
|
* flags can be any of IOMUX_PIN_OUTPUT_ENABLE, IOMUX_PIN_PULLUP, IOMUX_PIN_PULLDOWN, etc. Any other flags will be cleared.
|
||||||
* same as before.
|
*
|
||||||
|
* Equivalent to a direct register operation if gpio_number is known at compile time.
|
||||||
|
* ie the following are equivalent:
|
||||||
|
*
|
||||||
|
* iomux_set_gpio_function(12, IOMUX_PIN_OUTPUT_ENABLE);
|
||||||
|
* IOMUX_GPIO12 = IOMUX_GPIO12_FUNC_GPIO | IOMUX_PIN_OUTPUT_ENABLE;
|
||||||
*/
|
*/
|
||||||
inline static void iomux_set_gpio_function(uint8_t gpio_number, bool output_enable)
|
inline static void iomux_set_gpio_function(const uint8_t gpio_number, const uint32_t flags)
|
||||||
{
|
{
|
||||||
const uint8_t iomux_num = gpio_to_iomux(gpio_number);
|
const uint8_t reg_idx = gpio_to_iomux(gpio_number);
|
||||||
const uint32_t func = iomux_num > 11 ? IOMUX_FUNC(0) : IOMUX_FUNC(3);
|
const uint32_t func = (reg_idx > 11 ? IOMUX_FUNC(0) : IOMUX_FUNC(3)) | flags;
|
||||||
iomux_set_function(iomux_num, func);
|
IOMUX.PIN[reg_idx] = func | flags;
|
||||||
iomux_set_direction_flags(iomux_num, output_enable ? IOMUX_PIN_OUTPUT_ENABLE : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
/* esp_iomux_private contains implementation parts of the inline functions
|
||||||
}
|
declared above */
|
||||||
#endif
|
#include "esp/iomux_private.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
46
core/include/esp/iomux_private.h
Normal file
46
core/include/esp/iomux_private.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/** esp/iomux_private.h
|
||||||
|
*
|
||||||
|
* Private implementation parts of iomux registers. In headers to
|
||||||
|
* allow compile-time optimisations.
|
||||||
|
*
|
||||||
|
* Part of esp-open-rtos
|
||||||
|
* Copyright (C) 2015 Superhouse Automation Pty Ltd
|
||||||
|
* BSD Licensed as described in the file LICENSE
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Mapping from register index to GPIO and from GPIO index to register
|
||||||
|
number. DO NOT USE THESE IN YOUR CODE, call gpio_to_iomux(xxx) or
|
||||||
|
iomux_to_gpio(xxx) instead.
|
||||||
|
*/
|
||||||
|
#ifndef _IOMUX_PRIVATE
|
||||||
|
#define _IOMUX_PRIVATE
|
||||||
|
|
||||||
|
#include "common_macros.h"
|
||||||
|
|
||||||
|
#define _IOMUX_TO_GPIO { 12, 13, 14, 15, 3, 1, 6, 7, 8, 9, 10, 11, 0, 2, 4, 5 }
|
||||||
|
#define _GPIO_TO_IOMUX { 12, 5, 13, 4, 14, 15, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3 }
|
||||||
|
|
||||||
|
extern const IROM uint32_t GPIO_TO_IOMUX_MAP[];
|
||||||
|
extern const IROM uint32_t IOMUX_TO_GPIO_MAP[];
|
||||||
|
|
||||||
|
INLINED uint8_t gpio_to_iomux(const uint8_t gpio_number)
|
||||||
|
{
|
||||||
|
if(__builtin_constant_p(gpio_number)) {
|
||||||
|
static const uint8_t _regs[] = _GPIO_TO_IOMUX;
|
||||||
|
return _regs[gpio_number];
|
||||||
|
} else {
|
||||||
|
return GPIO_TO_IOMUX_MAP[gpio_number];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED uint8_t iomux_to_gpio(const uint8_t iomux_number)
|
||||||
|
{
|
||||||
|
if(__builtin_constant_p(iomux_number)) {
|
||||||
|
static const uint8_t _regs[] = _IOMUX_TO_GPIO;
|
||||||
|
return _regs[iomux_number];
|
||||||
|
} else {
|
||||||
|
return IOMUX_TO_GPIO_MAP[iomux_number];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -40,13 +40,18 @@ _Static_assert(sizeof(struct IOMUX_REGS) == 0x44, "IOMUX_REGS is the wrong size"
|
||||||
#define IOMUX_PIN_PULLDOWN BIT(6)
|
#define IOMUX_PIN_PULLDOWN BIT(6)
|
||||||
#define IOMUX_PIN_PULLUP BIT(7)
|
#define IOMUX_PIN_PULLUP BIT(7)
|
||||||
#define IOMUX_PIN_FUNC_HIGH_M 0x00000004
|
#define IOMUX_PIN_FUNC_HIGH_M 0x00000004
|
||||||
#define IOMUX_PIN_FUNC_HIGH_S 6
|
#define IOMUX_PIN_FUNC_HIGH_S 8
|
||||||
|
|
||||||
#define IOMUX_PIN_FUNC_MASK 0x00000130
|
#define IOMUX_PIN_FUNC_MASK 0x00001030
|
||||||
|
|
||||||
/* WARNING: Macro evaluates argument twice */
|
/* WARNING: Macro evaluates argument twice */
|
||||||
#define IOMUX_FUNC(val) (VAL2FIELD_M(IOMUX_PIN_FUNC_LOW, val) | VAL2FIELD_M(IOMUX_PIN_FUNC_HIGH, val))
|
#define IOMUX_FUNC(val) (VAL2FIELD_M(IOMUX_PIN_FUNC_LOW, val) | VAL2FIELD_M(IOMUX_PIN_FUNC_HIGH, val))
|
||||||
|
|
||||||
|
/* WARNING: Macro evaluates argument twice */
|
||||||
|
#define IOMUX_FUNC_VALUE(regbits) (FIELD2VAL(IOMUX_PIN_FUNC_LOW, regbits) | FIELD2VAL(IOMUX_PIN_FUNC_HIGH, regbits))
|
||||||
|
|
||||||
|
#define IOMUX_SET_FUNC(regbits, funcval) (((regbits) & ~IOMUX_PIN_FUNC_MASK) | (funcval))
|
||||||
|
|
||||||
#define IOMUX_GPIO0 IOMUX.PIN[12]
|
#define IOMUX_GPIO0 IOMUX.PIN[12]
|
||||||
#define IOMUX_GPIO1 IOMUX.PIN[5]
|
#define IOMUX_GPIO1 IOMUX.PIN[5]
|
||||||
#define IOMUX_GPIO2 IOMUX.PIN[13]
|
#define IOMUX_GPIO2 IOMUX.PIN[13]
|
||||||
|
@ -75,8 +80,8 @@ _Static_assert(sizeof(struct IOMUX_REGS) == 0x44, "IOMUX_REGS is the wrong size"
|
||||||
|
|
||||||
#define IOMUX_GPIO2_FUNC_GPIO IOMUX_FUNC(0)
|
#define IOMUX_GPIO2_FUNC_GPIO IOMUX_FUNC(0)
|
||||||
#define IOMUX_GPIO2_FUNC_I2SO_WS IOMUX_FUNC(1)
|
#define IOMUX_GPIO2_FUNC_I2SO_WS IOMUX_FUNC(1)
|
||||||
#define IOMUX_GPIO2_FUNC_UART1_TXD IOMUX_FUNC(2)
|
#define IOMUX_GPIO2_FUNC_UART1_TXD_BLINK IOMUX_FUNC(2)
|
||||||
#define IOMUX_GPIO2_FUNC_UART0_TXD IOMUX_FUNC(4)
|
#define IOMUX_GPIO2_FUNC_UART0_TXD_BLINK IOMUX_FUNC(4)
|
||||||
|
|
||||||
#define IOMUX_GPIO3_FUNC_UART0_RXD IOMUX_FUNC(0)
|
#define IOMUX_GPIO3_FUNC_UART0_RXD IOMUX_FUNC(0)
|
||||||
#define IOMUX_GPIO3_FUNC_I2SO_DATA IOMUX_FUNC(1)
|
#define IOMUX_GPIO3_FUNC_I2SO_DATA IOMUX_FUNC(1)
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
/** esp/phy.h
|
|
||||||
*
|
|
||||||
* PHY hardware management functions.
|
|
||||||
*
|
|
||||||
* These are not enough to configure the ESP8266 PHY by themselves
|
|
||||||
* (yet), but they provide utilities to modify the configuration set
|
|
||||||
* up via the SDK.
|
|
||||||
*
|
|
||||||
* Functions implemented here deal directly with the hardware, not the
|
|
||||||
* SDK software layers.
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (C) 2016 ChefSteps, Inc
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#ifndef _ESP_PHY_H
|
|
||||||
#define _ESP_PHY_H
|
|
||||||
|
|
||||||
#include <esp/types.h>
|
|
||||||
#include <common_macros.h>
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
BT_COEXIST_NONE,
|
|
||||||
BT_COEXIST_USE_BT_ACTIVE,
|
|
||||||
BT_COEXIST_USE_BT_ACTIVE_PRIORITY,
|
|
||||||
} bt_coexist_mode_t;
|
|
||||||
|
|
||||||
/** Override the Bluetooth Coexistence BT_ACTIVE pin setting
|
|
||||||
taken from the phy_info structure.
|
|
||||||
|
|
||||||
This enables other pins to be used for Bluetooth Coexistence
|
|
||||||
signals (rather than just the two provided for by phy_info). (Note
|
|
||||||
that not that not all pins are confirmed to work, GPIO 0 is
|
|
||||||
confirmed not usable as the SDK configures it as the WLAN_ACTIVE
|
|
||||||
output - even if you change the pin mode the SDK will change it
|
|
||||||
back.)
|
|
||||||
|
|
||||||
To change pins and have coexistence work successfully the BT
|
|
||||||
coexistence feature must be enabled in the phy_info configuration
|
|
||||||
(get_default_phy_info()). You can then modify the initial
|
|
||||||
configuration by calling this function from your own user_init
|
|
||||||
function.
|
|
||||||
|
|
||||||
(Eventually we should be able to support enough PHY registers
|
|
||||||
to enable coexistence without SDK support at all, but not yet.)
|
|
||||||
|
|
||||||
This function will enable bt_active_pin & bt_priority_as GPIO
|
|
||||||
inputs, according to the mode parameter.
|
|
||||||
|
|
||||||
Remember that the default Bluetooth Coexistence pins will be
|
|
||||||
configured as GPIOs by the SDK already, so you may want to
|
|
||||||
reconfigure/re-iomux them after calling this function.
|
|
||||||
*/
|
|
||||||
void bt_coexist_configure(bt_coexist_mode_t mode, uint8_t bt_active_pin, uint8_t bt_priority_pin);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,74 +0,0 @@
|
||||||
/* esp/phy_regs.h
|
|
||||||
*
|
|
||||||
* ESP8266 PHY register definitions
|
|
||||||
*
|
|
||||||
* Not compatible with ESP SDK register access code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ESP_PHY_REGS_H
|
|
||||||
#define _ESP_PHY_REGS_H
|
|
||||||
|
|
||||||
#include "esp/types.h"
|
|
||||||
#include "common_macros.h"
|
|
||||||
|
|
||||||
#define PHY_BASE 0x60000500
|
|
||||||
#define PHY (*(struct PHY_REGS *)(PHY_BASE))
|
|
||||||
|
|
||||||
struct PHY_REGS {
|
|
||||||
// 0x00 — 0x60
|
|
||||||
uint32_t volatile _gap0[24];
|
|
||||||
// TX digital predistortion control
|
|
||||||
// 0x60
|
|
||||||
uint32_t volatile TX_DPD;
|
|
||||||
// 0x64 — 0x7c
|
|
||||||
uint32_t volatile _gap1[6];
|
|
||||||
// IQ imbalance estimation control
|
|
||||||
// 0x7c
|
|
||||||
uint32_t volatile IQ_EST;
|
|
||||||
// Looks like RSSI,
|
|
||||||
// may be per OFDM subcarrier
|
|
||||||
// 0x80
|
|
||||||
uint32_t volatile RX_IQ_0;
|
|
||||||
// 0x84
|
|
||||||
uint32_t volatile RX_IQ_1;
|
|
||||||
// 0x88
|
|
||||||
uint32_t volatile RX_IQ_2;
|
|
||||||
// 0x8c
|
|
||||||
uint32_t volatile RX_IQ_3;
|
|
||||||
// RX gain control
|
|
||||||
// 0x90
|
|
||||||
uint32_t volatile RX_GAIN_CTL;
|
|
||||||
// Whatever pbus is, these registers controls it
|
|
||||||
// 0x94
|
|
||||||
uint32_t volatile PBUS_CTL_0;
|
|
||||||
// 0x98
|
|
||||||
uint32_t volatile PBUS_CTL_1;
|
|
||||||
// 0x9C
|
|
||||||
uint32_t volatile PBUS_CTL_2;
|
|
||||||
// 0xA0
|
|
||||||
uint32_t volatile PBUS_CTL_3;
|
|
||||||
uint32_t volatile _gap2[5];
|
|
||||||
// Looks like baseband synthesizer control regs
|
|
||||||
// 0xB8
|
|
||||||
uint32_t volatile BB_CTL_0;
|
|
||||||
// 0xBC
|
|
||||||
uint32_t volatile BB_CTL_1;
|
|
||||||
// 0xC0
|
|
||||||
uint32_t volatile BB_CTL_2;
|
|
||||||
// 0xC4
|
|
||||||
uint32_t volatile BB_CTL_3;
|
|
||||||
// These registers do exist but I don't know
|
|
||||||
// what they are for.
|
|
||||||
// 0xC8
|
|
||||||
uint32_t volatile UNK_0;
|
|
||||||
uint32_t volatile UNK_1;
|
|
||||||
uint32_t volatile UNK_2;
|
|
||||||
uint32_t volatile UNK_3;
|
|
||||||
uint32_t volatile UNK_4;
|
|
||||||
};
|
|
||||||
|
|
||||||
_Static_assert((uintptr_t) &PHY.TX_DPD == 0x60000560, "RF PHY TX_DPD address");
|
|
||||||
_Static_assert((uintptr_t) &PHY.IQ_EST == 0x6000057C, "RF PHY IQ_EST address");
|
|
||||||
_Static_assert((uintptr_t) &PHY.BB_CTL_3 == 0x600005C4, "RF PHY BB_CTL_3 address");
|
|
||||||
|
|
||||||
#endif /* _ESP_PHY_REGS_H */
|
|
|
@ -16,17 +16,14 @@
|
||||||
#include "common_macros.h"
|
#include "common_macros.h"
|
||||||
#include "esp/types.h"
|
#include "esp/types.h"
|
||||||
|
|
||||||
#include "esp/dport_regs.h"
|
#include "esp/uart_regs.h"
|
||||||
#include "esp/gpio_regs.h"
|
|
||||||
#include "esp/i2s_regs.h"
|
|
||||||
#include "esp/iomux_regs.h"
|
|
||||||
#include "esp/rtc_regs.h"
|
|
||||||
#include "esp/rtcmem_regs.h"
|
|
||||||
#include "esp/slc_regs.h"
|
|
||||||
#include "esp/spi_regs.h"
|
#include "esp/spi_regs.h"
|
||||||
|
#include "esp/iomux_regs.h"
|
||||||
|
#include "esp/gpio_regs.h"
|
||||||
#include "esp/timer_regs.h"
|
#include "esp/timer_regs.h"
|
||||||
#include "esp/wdt_regs.h"
|
#include "esp/wdt_regs.h"
|
||||||
#include "esp/uart_regs.h"
|
#include "esp/rtcmem_regs.h"
|
||||||
|
#include "esp/dport_regs.h"
|
||||||
|
|
||||||
/* Register base addresses
|
/* Register base addresses
|
||||||
|
|
||||||
|
@ -47,7 +44,7 @@
|
||||||
//#define SPI_BASE (MMIO_BASE + 0x0200)
|
//#define SPI_BASE (MMIO_BASE + 0x0200)
|
||||||
//#define GPIO0_BASE (MMIO_BASE + 0x0300)
|
//#define GPIO0_BASE (MMIO_BASE + 0x0300)
|
||||||
//#define TIMER_BASE (MMIO_BASE + 0x0600)
|
//#define TIMER_BASE (MMIO_BASE + 0x0600)
|
||||||
//#define RTC_BASE (MMIO_BASE + 0x0700)
|
#define RTC_BASE (MMIO_BASE + 0x0700)
|
||||||
//#define IOMUX_BASE (MMIO_BASE + 0x0800)
|
//#define IOMUX_BASE (MMIO_BASE + 0x0800)
|
||||||
//#define WDT_BASE (MMIO_BASE + 0x0900)
|
//#define WDT_BASE (MMIO_BASE + 0x0900)
|
||||||
#define I2C_BASE (MMIO_BASE + 0x0d00)
|
#define I2C_BASE (MMIO_BASE + 0x0d00)
|
||||||
|
|
|
@ -6,12 +6,7 @@
|
||||||
#ifndef _ESP_ROM_H
|
#ifndef _ESP_ROM_H
|
||||||
#define _ESP_ROM_H
|
#define _ESP_ROM_H
|
||||||
|
|
||||||
#include "esp/types.h"
|
#include <stdint.h>
|
||||||
#include "flashchip.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void Cache_Read_Disable(void);
|
void Cache_Read_Disable(void);
|
||||||
|
|
||||||
|
@ -23,19 +18,4 @@ void Cache_Read_Disable(void);
|
||||||
*/
|
*/
|
||||||
void Cache_Read_Enable(uint32_t odd_even, uint32_t mb_count, uint32_t no_idea);
|
void Cache_Read_Enable(uint32_t odd_even, uint32_t mb_count, uint32_t no_idea);
|
||||||
|
|
||||||
/* Low-level SPI flash read/write routines */
|
|
||||||
int Enable_QMode(sdk_flashchip_t *chip);
|
|
||||||
int Disable_QMode(sdk_flashchip_t *chip);
|
|
||||||
int SPI_page_program(sdk_flashchip_t *chip, uint32_t dest_addr, uint32_t *src_addr, uint32_t size);
|
|
||||||
int SPI_read_data(sdk_flashchip_t *chip, uint32_t src_addr, uint32_t *dest_addr, uint32_t size);
|
|
||||||
int SPI_write_enable(sdk_flashchip_t *chip);
|
|
||||||
int SPI_sector_erase(sdk_flashchip_t *chip, uint32_t addr);
|
|
||||||
int SPI_read_status(sdk_flashchip_t *chip, uint32_t *status);
|
|
||||||
int SPI_write_status(sdk_flashchip_t *chip, uint32_t status);
|
|
||||||
int Wait_SPI_Idle(sdk_flashchip_t *chip);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _ESP_ROM_H */
|
|
||||||
|
|
|
@ -1,104 +0,0 @@
|
||||||
/* esp/rtc_regs.h
|
|
||||||
*
|
|
||||||
* ESP8266 RTC register definitions
|
|
||||||
*
|
|
||||||
* Not compatible with ESP SDK register access code.
|
|
||||||
*
|
|
||||||
* RTC peripheral remains powered during deep sleep, and RTC clock
|
|
||||||
* is used to wake from deep sleep when RTC.COUNTER == RTC.COUNTER_ALARM.
|
|
||||||
*
|
|
||||||
* "GPIO16" is a special GPIO pin connected to the RTC subsystem,
|
|
||||||
* GPIO16 must be connected to reset to allow wake from deep sleep.
|
|
||||||
*
|
|
||||||
* The contents of scratch registers RTC.SCRATCH[] are preserved
|
|
||||||
* across reset, including wake from sleep (unconfirmed). Contents of
|
|
||||||
* RTCMEM are also preserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ESP_RTC_REGS_H
|
|
||||||
#define _ESP_RTC_REGS_H
|
|
||||||
|
|
||||||
#include "esp/types.h"
|
|
||||||
#include "common_macros.h"
|
|
||||||
|
|
||||||
#define RTC_BASE 0x60000700
|
|
||||||
#define RTC (*(struct RTC_REGS *)(RTC_BASE))
|
|
||||||
|
|
||||||
//FIXME: need to understand/clarify distinction between GPIO_CONF and GPIO_CFG[]
|
|
||||||
// Note: GPIO_CFG[3] is also known as PAD_XPD_DCDC_CONF in eagle_soc.h
|
|
||||||
|
|
||||||
struct RTC_REGS {
|
|
||||||
uint32_t volatile CTRL0; // 0x00
|
|
||||||
uint32_t volatile COUNTER_ALARM; // 0x04
|
|
||||||
uint32_t volatile RESET_REASON0; // 0x08 //FIXME: need better name
|
|
||||||
uint32_t volatile _unknownc; // 0x0c
|
|
||||||
uint32_t volatile _unknown10; // 0x10
|
|
||||||
uint32_t volatile RESET_REASON1; // 0x14 //FIXME: need better name
|
|
||||||
uint32_t volatile RESET_REASON2; // 0x18 //FIXME: need better name
|
|
||||||
uint32_t volatile COUNTER; // 0x1c
|
|
||||||
uint32_t volatile INT_SET; // 0x20
|
|
||||||
uint32_t volatile INT_CLEAR; // 0x24
|
|
||||||
uint32_t volatile INT_ENABLE; // 0x28
|
|
||||||
uint32_t volatile _unknown2c; // 0x2c
|
|
||||||
uint32_t volatile SCRATCH[4]; // 0x30 - 3c
|
|
||||||
uint32_t volatile _unknown40; // 0x40
|
|
||||||
uint32_t volatile _unknown44; // 0x44
|
|
||||||
uint32_t volatile _unknown48; // 0x48
|
|
||||||
uint32_t volatile _unknown4c[7]; // 0x4c - 0x64
|
|
||||||
uint32_t volatile GPIO_OUT; // 0x68
|
|
||||||
uint32_t volatile _unknown6c[2]; // 0x6c - 0x70
|
|
||||||
uint32_t volatile GPIO_ENABLE; // 0x74
|
|
||||||
uint32_t volatile _unknown80[5]; // 0x78 - 0x88
|
|
||||||
uint32_t volatile GPIO_IN; // 0x8c
|
|
||||||
uint32_t volatile GPIO_CONF; // 0x90
|
|
||||||
uint32_t volatile GPIO_CFG[6]; // 0x94 - 0xa8
|
|
||||||
};
|
|
||||||
|
|
||||||
_Static_assert(sizeof(struct RTC_REGS) == 0xac, "RTC_REGS is the wrong size");
|
|
||||||
|
|
||||||
/* Details for CTRL0 register */
|
|
||||||
|
|
||||||
/* Writing this bit causes a software reset but
|
|
||||||
the device then fails in ets_main.c (needs other parameters set?) */
|
|
||||||
#define RTC_CTRL0_BIT31 BIT(31)
|
|
||||||
|
|
||||||
/* Details for RESET_REASONx registers */
|
|
||||||
|
|
||||||
/* The following are used in sdk_rtc_get_reset_reason(). Details are still a
|
|
||||||
* bit sketchy regarding exactly what they mean/do.. */
|
|
||||||
|
|
||||||
#define RTC_RESET_REASON1_CODE_M 0x0000000f
|
|
||||||
#define RTC_RESET_REASON1_CODE_S 0
|
|
||||||
|
|
||||||
#define RTC_RESET_REASON2_CODE_M 0x0000003f
|
|
||||||
#define RTC_RESET_REASON2_CODE_S 8
|
|
||||||
|
|
||||||
/* Writing this bit causes the ESP to go into some kind of unrecoverable boot loop */
|
|
||||||
#define RTC_RESET_REASON0_BIT20 BIT(20)
|
|
||||||
|
|
||||||
/* Both bits 20 & 21 can be set & cleared from software,
|
|
||||||
BIT21 appears to be checked inside sdk_rtc_get_reset_reason() */
|
|
||||||
#define RTC_RESET_REASON0_BIT21 BIT(21)
|
|
||||||
#define RTC_RESET_REASON0_BIT22 BIT(22)
|
|
||||||
|
|
||||||
/* Details for GPIO_CONF register */
|
|
||||||
|
|
||||||
#define RTC_GPIO_CONF_OUT_ENABLE BIT(0)
|
|
||||||
|
|
||||||
/* Details for GPIO_CFG[3] register controlling GPIO16 (possibly others?) */
|
|
||||||
|
|
||||||
#define RTC_GPIO_CFG3_PIN_PULLUP BIT(2)
|
|
||||||
#define RTC_GPIO_CFG3_PIN_PULLDOWN BIT(3)
|
|
||||||
#define RTC_GPIO_CFG3_PIN_PULLUP_SLEEP BIT(4)
|
|
||||||
#define RTC_GPIO_CFG3_PIN_PULLDOWN_SLEEP BIT(5)
|
|
||||||
|
|
||||||
/* The PIN_FUNC values here are probably similar to the
|
|
||||||
values used to set the iomux registers...? */
|
|
||||||
#define RTC_GPIO_CFG3_PIN_FUNC_M 0x00000043
|
|
||||||
#define RTC_GPIO_CFG3_PIN_FUNC_S 0
|
|
||||||
|
|
||||||
/* This should be the function value needed to have GPIO16 be the alarm
|
|
||||||
output from the RTC. FIXME: Needs to be validated. */
|
|
||||||
#define RTC_GPIO_CFG3_PIN_FUNC_RTC_GPIO0 BIT(0)
|
|
||||||
|
|
||||||
#endif /* _ESP_RTC_REGS_H */
|
|
|
@ -1,39 +0,0 @@
|
||||||
/* esp/sar_regs.h
|
|
||||||
*
|
|
||||||
* ESP8266 register definitions for the "sar" region (0x3FF2xxx)
|
|
||||||
*
|
|
||||||
* The 0x60000D00 register region is referred to as "sar" by some old header
|
|
||||||
* files. Apparently referenced both by ROM I2C functions as well as ADC
|
|
||||||
* config/read functions.
|
|
||||||
*
|
|
||||||
* Not compatible with ESP SDK register access code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ESP_SAR_REGS_H
|
|
||||||
#define _ESP_SAR_REGS_H
|
|
||||||
|
|
||||||
#include "esp/types.h"
|
|
||||||
#include "common_macros.h"
|
|
||||||
|
|
||||||
#define SAR_BASE 0x60000d00
|
|
||||||
// Unfortunately,
|
|
||||||
// esp-open-sdk/xtensa-lx106-elf/xtensa-lx106-elf/sysroot/usr/include/xtensa/config/specreg.h
|
|
||||||
// already has a "SAR" macro definition which would conflict with this, so
|
|
||||||
// we'll use "ESPSAR" instead..
|
|
||||||
#define ESPSAR (*(struct SAR_REGS *)(SAR_BASE))
|
|
||||||
|
|
||||||
/* Note: This memory region is not currently well understood. Pretty much all
|
|
||||||
* of the definitions here are from reverse-engineering the Espressif SDK code,
|
|
||||||
* many are just educated guesses, and almost certainly some are misleading or
|
|
||||||
* wrong. If you can improve on any of this, please contribute!
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct SAR_REGS {
|
|
||||||
uint32_t volatile _unknown0[18]; // 0x00 - 0x44
|
|
||||||
uint32_t volatile UNKNOWN_48; // 0x48 : used by sdk_system_restart_in_nmi()
|
|
||||||
} __attribute__ (( packed ));
|
|
||||||
|
|
||||||
_Static_assert(sizeof(struct SAR_REGS) == 0x4c, "SAR_REGS is the wrong size");
|
|
||||||
|
|
||||||
#endif /* _ESP_SAR_REGS_H */
|
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
/* esp/slc_regs.h
|
|
||||||
*
|
|
||||||
* ESP8266 SLC functions
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ESP_SLC_H
|
|
||||||
#define _ESP_SLC_H
|
|
||||||
|
|
||||||
#include "esp/slc_regs.h"
|
|
||||||
|
|
||||||
/* Memory layout for DMA transfer descriptors. */
|
|
||||||
|
|
||||||
struct SLCDescriptor
|
|
||||||
{
|
|
||||||
uint32_t flags;
|
|
||||||
uint32_t buf_ptr;
|
|
||||||
uint32_t next_link_ptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define SLC_DESCRIPTOR_FLAGS_BLOCKSIZE_M 0x00000fff
|
|
||||||
#define SLC_DESCRIPTOR_FLAGS_BLOCKSIZE_S 0
|
|
||||||
#define SLC_DESCRIPTOR_FLAGS_DATA_LENGTH_M 0x00000fff
|
|
||||||
#define SLC_DESCRIPTOR_FLAGS_DATA_LENGTH_S 12
|
|
||||||
#define SLC_DESCRIPTOR_FLAGS_SUB_SOF BIT(29)
|
|
||||||
#define SLC_DESCRIPTOR_FLAGS_EOF BIT(30)
|
|
||||||
#define SLC_DESCRIPTOR_FLAGS_OWNER BIT(31)
|
|
||||||
|
|
||||||
#define SLC_DESCRIPTOR_FLAGS(blocksize,datalen,sub_sof,eof,owner) ( \
|
|
||||||
VAL2FIELD_M(SLC_DESCRIPTOR_FLAGS_BLOCKSIZE,blocksize)| \
|
|
||||||
VAL2FIELD_M(SLC_DESCRIPTOR_FLAGS_DATA_LENGTH,datalen)| \
|
|
||||||
((sub_sof)?SLC_DESCRIPTOR_FLAGS_SUB_SOF:0)| \
|
|
||||||
((eof)?SLC_DESCRIPTOR_FLAGS_EOF:0)| \
|
|
||||||
((owner)?SLC_DESCRIPTOR_FLAGS_OWNER:0) \
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _ESP_SLC_REGS_H */
|
|
|
@ -1,289 +0,0 @@
|
||||||
/* esp/slc_regs.h
|
|
||||||
*
|
|
||||||
* ESP8266 SLC register definitions
|
|
||||||
*
|
|
||||||
* Not compatible with ESP SDK register access code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ESP_SLC_REGS_H
|
|
||||||
#define _ESP_SLC_REGS_H
|
|
||||||
|
|
||||||
#include "esp/types.h"
|
|
||||||
#include "common_macros.h"
|
|
||||||
|
|
||||||
#define SLC_BASE 0x60000b00
|
|
||||||
#define SLC (*(struct SLC_REGS *)SLC_BASE)
|
|
||||||
|
|
||||||
struct SLC_REGS {
|
|
||||||
uint32_t volatile CONF0; // 0x00
|
|
||||||
uint32_t volatile INT_RAW; // 0x04
|
|
||||||
uint32_t volatile INT_STATUS; // 0x08
|
|
||||||
uint32_t volatile INT_ENABLE; // 0x0c
|
|
||||||
uint32_t volatile INT_CLEAR; // 0x10
|
|
||||||
uint32_t volatile RX_STATUS; // 0x14
|
|
||||||
uint32_t volatile RX_FIFO_PUSH; // 0x18
|
|
||||||
uint32_t volatile TX_STATUS; // 0x1c
|
|
||||||
uint32_t volatile TX_FIFO_POP; // 0x20
|
|
||||||
uint32_t volatile RX_LINK; // 0x24
|
|
||||||
uint32_t volatile TX_LINK; // 0x28
|
|
||||||
uint32_t volatile INTVEC_TO_HOST; // 0x2c
|
|
||||||
uint32_t volatile TOKEN0; // 0x30
|
|
||||||
uint32_t volatile TOKEN1; // 0x34
|
|
||||||
uint32_t volatile CONF1; // 0x38
|
|
||||||
uint32_t volatile STATE0; // 0x3c
|
|
||||||
uint32_t volatile STATE1; // 0x40
|
|
||||||
uint32_t volatile BRIDGE_CONF; // 0x44
|
|
||||||
uint32_t volatile RX_EOF_DESCRIPTOR_ADDR; // 0x48
|
|
||||||
uint32_t volatile TX_EOF_DESCRIPTOR_ADDR; // 0x4c
|
|
||||||
uint32_t volatile RX_EOF_BUFFER_DESCRIPTOR_ADDR; // 0x50 - Naming uncertain
|
|
||||||
uint32_t volatile AHB_TEST; // 0x54
|
|
||||||
uint32_t volatile SDIO_STATUS; // 0x58
|
|
||||||
uint32_t volatile RX_DESCRIPTOR_CONF; // 0x5c
|
|
||||||
uint32_t volatile TX_LINK_DESCRIPTOR; // 0x60
|
|
||||||
uint32_t volatile TX_LINK_DESCRIPTOR_BF0; // 0x64
|
|
||||||
uint32_t volatile TX_LINK_DESCRIPTOR_BF1; // 0x68
|
|
||||||
uint32_t volatile RX_LINK_DESCRIPTOR; // 0x6c
|
|
||||||
uint32_t volatile RX_LINK_DESCRIPTOR_BF0; // 0x70
|
|
||||||
uint32_t volatile RX_LINK_DESCRIPTOR_BF1; // 0x74
|
|
||||||
uint32_t volatile DATE; // 0x78
|
|
||||||
uint32_t volatile ID; // 0x7c
|
|
||||||
uint32_t volatile UNKNOWN_80; // 0x80
|
|
||||||
uint32_t volatile UNKNOWN_84; // 0x84
|
|
||||||
uint32_t volatile HOST_INT_RAW; // 0x88
|
|
||||||
uint32_t volatile UNKNOWN_8C; // 0x8c
|
|
||||||
uint32_t volatile UNKNOWN_90; // 0x90
|
|
||||||
uint32_t volatile HOST_CONF_W0; // 0x94
|
|
||||||
uint32_t volatile HOST_CONF_W1; // 0x98
|
|
||||||
uint32_t volatile HOST_INT_STATUS; // 0x9c
|
|
||||||
uint32_t volatile HOST_CONF_W2; // 0xa0
|
|
||||||
uint32_t volatile HOST_CONF_W3; // 0xa4
|
|
||||||
uint32_t volatile HOST_CONF_W4; // 0xa8
|
|
||||||
uint32_t volatile UNKNOWN_AC; // 0xac
|
|
||||||
uint32_t volatile HOST_INT_CLEAR; // 0xb0
|
|
||||||
uint32_t volatile HOST_INT_ENABLE; // 0xb4
|
|
||||||
uint32_t volatile UNKNOWN_B8; // 0xb8
|
|
||||||
uint32_t volatile HOST_CONF_W5; // 0xbc
|
|
||||||
};
|
|
||||||
|
|
||||||
_Static_assert(sizeof(struct SLC_REGS) == 0xc0, "SLC_REGS is the wrong size");
|
|
||||||
|
|
||||||
/* Details for CONF0 register */
|
|
||||||
|
|
||||||
#define SLC_CONF0_MODE_M 0x00000003
|
|
||||||
#define SLC_CONF0_MODE_S 12
|
|
||||||
#define SLC_CONF0_DATA_BURST_ENABLE BIT(9)
|
|
||||||
#define SLC_CONF0_DESCRIPTOR_BURST_ENABLE BIT(8)
|
|
||||||
#define SLC_CONF0_RX_NO_RESTART_CLEAR BIT(7)
|
|
||||||
#define SLC_CONF0_RX_AUTO_WRITE_BACK BIT(6)
|
|
||||||
#define SLC_CONF0_RX_LOOP_TEST BIT(5)
|
|
||||||
#define SLC_CONF0_TX_LOOP_TEST BIT(4)
|
|
||||||
#define SLC_CONF0_AHBM_RESET BIT(3)
|
|
||||||
#define SLC_CONF0_AHBM_FIFO_RESET BIT(2)
|
|
||||||
#define SLC_CONF0_RX_LINK_RESET BIT(1)
|
|
||||||
#define SLC_CONF0_TX_LINK_RESET BIT(0)
|
|
||||||
|
|
||||||
/* Details for INT_RAW register */
|
|
||||||
|
|
||||||
#define SLC_INT_RAW_TX_DSCR_EMPTY BIT(21)
|
|
||||||
#define SLC_INT_RAW_RX_DSCR_ERROR BIT(20)
|
|
||||||
#define SLC_INT_RAW_TX_DSCR_ERROR BIT(19)
|
|
||||||
#define SLC_INT_RAW_TO_HOST BIT(18)
|
|
||||||
#define SLC_INT_RAW_RX_EOF BIT(17)
|
|
||||||
#define SLC_INT_RAW_RX_DONE BIT(16)
|
|
||||||
#define SLC_INT_RAW_TX_EOF BIT(15)
|
|
||||||
#define SLC_INT_RAW_TX_DONE BIT(14)
|
|
||||||
#define SLC_INT_RAW_TOKEN1_1TO0 BIT(13)
|
|
||||||
#define SLC_INT_RAW_TOKEN0_1TO0 BIT(12)
|
|
||||||
#define SLC_INT_RAW_TX_OVERFLOW BIT(11)
|
|
||||||
#define SLC_INT_RAW_RX_UNDEFLOW BIT(10)
|
|
||||||
#define SLC_INT_RAW_TX_START BIT(9)
|
|
||||||
#define SLC_INT_RAW_RX_START BIT(8)
|
|
||||||
#define SLC_INT_RAW_FROM_HOST_BIT7 BIT(7)
|
|
||||||
#define SLC_INT_RAW_FROM_HOST_BIT6 BIT(6)
|
|
||||||
#define SLC_INT_RAW_FROM_HOST_BIT5 BIT(5)
|
|
||||||
#define SLC_INT_RAW_FROM_HOST_BIT4 BIT(4)
|
|
||||||
#define SLC_INT_RAW_FROM_HOST_BIT3 BIT(3)
|
|
||||||
#define SLC_INT_RAW_FROM_HOST_BIT2 BIT(2)
|
|
||||||
#define SLC_INT_RAW_FROM_HOST_BIT1 BIT(1)
|
|
||||||
#define SLC_INT_RAW_FROM_HOST_BIT0 BIT(0)
|
|
||||||
|
|
||||||
/* Details for INT_STATUS register */
|
|
||||||
|
|
||||||
#define SLC_INT_STATUS_TX_DSCR_EMPTY BIT(21)
|
|
||||||
#define SLC_INT_STATUS_RX_DSCR_ERROR BIT(20)
|
|
||||||
#define SLC_INT_STATUS_TX_DSCR_ERROR BIT(19)
|
|
||||||
#define SLC_INT_STATUS_TO_HOST BIT(18)
|
|
||||||
#define SLC_INT_STATUS_RX_EOF BIT(17)
|
|
||||||
#define SLC_INT_STATUS_RX_DONE BIT(16)
|
|
||||||
#define SLC_INT_STATUS_TX_EOF BIT(15)
|
|
||||||
#define SLC_INT_STATUS_TX_DONE BIT(14)
|
|
||||||
#define SLC_INT_STATUS_TOKEN1_1TO0 BIT(13)
|
|
||||||
#define SLC_INT_STATUS_TOKEN0_1TO0 BIT(12)
|
|
||||||
#define SLC_INT_STATUS_TX_OVERFLOW BIT(11)
|
|
||||||
#define SLC_INT_STATUS_RX_UNDEFLOW BIT(10)
|
|
||||||
#define SLC_INT_STATUS_TX_START BIT(9)
|
|
||||||
#define SLC_INT_STATUS_RX_START BIT(8)
|
|
||||||
#define SLC_INT_STATUS_FROM_HOST_BIT7 BIT(7)
|
|
||||||
#define SLC_INT_STATUS_FROM_HOST_BIT6 BIT(6)
|
|
||||||
#define SLC_INT_STATUS_FROM_HOST_BIT5 BIT(5)
|
|
||||||
#define SLC_INT_STATUS_FROM_HOST_BIT4 BIT(4)
|
|
||||||
#define SLC_INT_STATUS_FROM_HOST_BIT3 BIT(3)
|
|
||||||
#define SLC_INT_STATUS_FROM_HOST_BIT2 BIT(2)
|
|
||||||
#define SLC_INT_STATUS_FROM_HOST_BIT1 BIT(1)
|
|
||||||
#define SLC_INT_STATUS_FROM_HOST_BIT0 BIT(0)
|
|
||||||
|
|
||||||
/* Details for INT_ENABLE register */
|
|
||||||
|
|
||||||
#define SLC_INT_ENABLE_TX_DSCR_EMPTY BIT(21)
|
|
||||||
#define SLC_INT_ENABLE_RX_DSCR_ERROR BIT(20)
|
|
||||||
#define SLC_INT_ENABLE_TX_DSCR_ERROR BIT(19)
|
|
||||||
#define SLC_INT_ENABLE_TO_HOST BIT(18)
|
|
||||||
#define SLC_INT_ENABLE_RX_EOF BIT(17)
|
|
||||||
#define SLC_INT_ENABLE_RX_DONE BIT(16)
|
|
||||||
#define SLC_INT_ENABLE_TX_EOF BIT(15)
|
|
||||||
#define SLC_INT_ENABLE_TX_DONE BIT(14)
|
|
||||||
#define SLC_INT_ENABLE_TOKEN1_1TO0 BIT(13)
|
|
||||||
#define SLC_INT_ENABLE_TOKEN0_1TO0 BIT(12)
|
|
||||||
#define SLC_INT_ENABLE_TX_OVERFLOW BIT(11)
|
|
||||||
#define SLC_INT_ENABLE_RX_UNDEFLOW BIT(10)
|
|
||||||
#define SLC_INT_ENABLE_TX_START BIT(9)
|
|
||||||
#define SLC_INT_ENABLE_RX_START BIT(8)
|
|
||||||
#define SLC_INT_ENABLE_FROM_HOST_BIT7 BIT(7)
|
|
||||||
#define SLC_INT_ENABLE_FROM_HOST_BIT6 BIT(6)
|
|
||||||
#define SLC_INT_ENABLE_FROM_HOST_BIT5 BIT(5)
|
|
||||||
#define SLC_INT_ENABLE_FROM_HOST_BIT4 BIT(4)
|
|
||||||
#define SLC_INT_ENABLE_FROM_HOST_BIT3 BIT(3)
|
|
||||||
#define SLC_INT_ENABLE_FROM_HOST_BIT2 BIT(2)
|
|
||||||
#define SLC_INT_ENABLE_FROM_HOST_BIT1 BIT(1)
|
|
||||||
#define SLC_INT_ENABLE_FROM_HOST_BIT0 BIT(0)
|
|
||||||
|
|
||||||
#define SLC_INT_ENABLE_FROM_HOST_BIT_ALL 0xff
|
|
||||||
|
|
||||||
/* Details for INT_CLEAR register */
|
|
||||||
|
|
||||||
#define SLC_INT_CLEAR_TX_DSCR_EMPTY BIT(21)
|
|
||||||
#define SLC_INT_CLEAR_RX_DSCR_ERROR BIT(20)
|
|
||||||
#define SLC_INT_CLEAR_TX_DSCR_ERROR BIT(19)
|
|
||||||
#define SLC_INT_CLEAR_TO_HOST BIT(18)
|
|
||||||
#define SLC_INT_CLEAR_RX_EOF BIT(17)
|
|
||||||
#define SLC_INT_CLEAR_RX_DONE BIT(16)
|
|
||||||
#define SLC_INT_CLEAR_TX_EOF BIT(15)
|
|
||||||
#define SLC_INT_CLEAR_TX_DONE BIT(14)
|
|
||||||
#define SLC_INT_CLEAR_TOKEN1_1TO0 BIT(13)
|
|
||||||
#define SLC_INT_CLEAR_TOKEN0_1TO0 BIT(12)
|
|
||||||
#define SLC_INT_CLEAR_TX_OVERFLOW BIT(11)
|
|
||||||
#define SLC_INT_CLEAR_RX_UNDEFLOW BIT(10)
|
|
||||||
#define SLC_INT_CLEAR_TX_START BIT(9)
|
|
||||||
#define SLC_INT_CLEAR_RX_START BIT(8)
|
|
||||||
#define SLC_INT_CLEAR_FROM_HOST_BIT7 BIT(7)
|
|
||||||
#define SLC_INT_CLEAR_FROM_HOST_BIT6 BIT(6)
|
|
||||||
#define SLC_INT_CLEAR_FROM_HOST_BIT5 BIT(5)
|
|
||||||
#define SLC_INT_CLEAR_FROM_HOST_BIT4 BIT(4)
|
|
||||||
#define SLC_INT_CLEAR_FROM_HOST_BIT3 BIT(3)
|
|
||||||
#define SLC_INT_CLEAR_FROM_HOST_BIT2 BIT(2)
|
|
||||||
#define SLC_INT_CLEAR_FROM_HOST_BIT1 BIT(1)
|
|
||||||
#define SLC_INT_CLEAR_FROM_HOST_BIT0 BIT(0)
|
|
||||||
|
|
||||||
/* Details for RX_STATUS register */
|
|
||||||
|
|
||||||
#define SLC_RX_STATUS_EMPTY BIT(1)
|
|
||||||
#define SLC_RX_STATUS_FULL BIT(0)
|
|
||||||
|
|
||||||
/* Details for RX_FIFO_PUSH register */
|
|
||||||
|
|
||||||
#define SLC_RX_FIFO_PUSH_FLAG BIT(16)
|
|
||||||
#define SLC_RX_FIFO_PUSH_DATA_M 0x000001ff
|
|
||||||
#define SLC_RX_FIFO_PUSH_DATA_S 0
|
|
||||||
|
|
||||||
/* Details for TX_STATUS register */
|
|
||||||
|
|
||||||
#define SLC_TX_STATUS_EMPTY BIT(1)
|
|
||||||
#define SLC_TX_STATUS_FULL BIT(0)
|
|
||||||
|
|
||||||
/* Details for TX_FIFO_POP register */
|
|
||||||
|
|
||||||
#define SLC_TX_FIFO_POP_FLAG BIT(16)
|
|
||||||
#define SLC_TX_FIFO_POP_DATA_M 0x000007ff
|
|
||||||
#define SLC_TX_FIFO_POP_DATA_S 0
|
|
||||||
|
|
||||||
/* Details for RX_LINK register */
|
|
||||||
|
|
||||||
#define SLC_RX_LINK_PARK BIT(31)
|
|
||||||
#define SLC_RX_LINK_RESTART BIT(30)
|
|
||||||
#define SLC_RX_LINK_START BIT(29)
|
|
||||||
#define SLC_RX_LINK_STOP BIT(28)
|
|
||||||
#define SLC_RX_LINK_DESCRIPTOR_ADDR_M 0x000fffff
|
|
||||||
#define SLC_RX_LINK_DESCRIPTOR_ADDR_S 0
|
|
||||||
|
|
||||||
/* Details for TX_LINK register */
|
|
||||||
|
|
||||||
#define SLC_TX_LINK_PARK BIT(31)
|
|
||||||
#define SLC_TX_LINK_RESTART BIT(30)
|
|
||||||
#define SLC_TX_LINK_START BIT(29)
|
|
||||||
#define SLC_TX_LINK_STOP BIT(28)
|
|
||||||
#define SLC_TX_LINK_DESCRIPTOR_ADDR_M 0x000fffff
|
|
||||||
#define SLC_TX_LINK_DESCRIPTOR_ADDR_S 0
|
|
||||||
|
|
||||||
/* Details for INTVEC_TO_HOST register */
|
|
||||||
|
|
||||||
#define SLC_INTVEC_TO_HOST_INTVEC_M 0x000000ff
|
|
||||||
#define SLC_INTVEC_TO_HOST_INTVEC_S 0
|
|
||||||
|
|
||||||
/* Details for TOKEN0 register */
|
|
||||||
|
|
||||||
#define SLC_TOKEN0_M 0x00000fff
|
|
||||||
#define SLC_TOKEN0_S 16
|
|
||||||
#define SLC_TOKEN0_LOCAL_INC_MORE BIT(14)
|
|
||||||
#define SLC_TOKEN0_LOCAL_INC BIT(13)
|
|
||||||
#define SLC_TOKEN0_LOCAL_WRITE BIT(12)
|
|
||||||
#define SLC_TOKEN0_LOCAL_DATA_M 0x00000FFF
|
|
||||||
#define SLC_TOKEN0_LOCAL_DATA_S 0
|
|
||||||
|
|
||||||
/* Details for TOKEN1 register */
|
|
||||||
|
|
||||||
#define SLC_TOKEN1_MASK 0x00000fff
|
|
||||||
#define SLC_TOKEN1_S 16
|
|
||||||
#define SLC_TOKEN1_LOCAL_INC_MORE BIT(14)
|
|
||||||
#define SLC_TOKEN1_LOCAL_INC BIT(13)
|
|
||||||
#define SLC_TOKEN1_LOCAL_WRITE BIT(12)
|
|
||||||
#define SLC_TOKEN1_LOCAL_DATA_M 0x00000fff
|
|
||||||
#define SLC_TOKEN1_LOCAL_DATA_S 0
|
|
||||||
|
|
||||||
/* Details for BRIDGE_CONF register */
|
|
||||||
|
|
||||||
#define SLC_BRIDGE_CONF_TX_PUSH_IDLE_M 0x0000ffff
|
|
||||||
#define SLC_BRIDGE_CONF_TX_PUSH_IDLE_S 16
|
|
||||||
#define SLC_BRIDGE_CONF_TX_DUMMY_MODE BIT(12)
|
|
||||||
#define SLC_BRIDGE_CONF_FIFO_MAP_ENABLE_M 0x0000000f
|
|
||||||
#define SLC_BRIDGE_CONF_FIFO_MAP_ENABLE_S 8
|
|
||||||
#define SLC_BRIDGE_CONF_TX_EOF_ENABLE_M 0x0000003f
|
|
||||||
#define SLC_BRIDGE_CONF_TX_EOF_ENABLE_S 0
|
|
||||||
|
|
||||||
/* Details for AHB_TEST register */
|
|
||||||
|
|
||||||
#define SLC_AHB_TEST_ADDR_M 0x00000003
|
|
||||||
#define SLC_AHB_TEST_ADDR_S 4
|
|
||||||
#define SLC_AHB_TEST_MODE_M 0x00000007
|
|
||||||
#define SLC_AHB_TEST_MODE_S 0
|
|
||||||
|
|
||||||
/* Details for SDIO_STATUS register */
|
|
||||||
|
|
||||||
#define SLC_SDIO_STATUS_BUS_M 0x00000007
|
|
||||||
#define SLC_SDIO_STATUS_BUS_S 12
|
|
||||||
#define SLC_SDIO_STATUS_WAKEUP BIT(8)
|
|
||||||
#define SLC_SDIO_STATUS_FUNC_M 0x0000000f
|
|
||||||
#define SLC_SDIO_STATUS_FUNC_S 4
|
|
||||||
#define SLC_SDIO_STATUS_COMMAND_M 0x00000007
|
|
||||||
#define SLC_SDIO_STATUS_COMMAND_S 0
|
|
||||||
|
|
||||||
/* Details for RX_DESCRIPTOR_CONF register */
|
|
||||||
|
|
||||||
#define SLC_RX_DESCRIPTOR_CONF_RX_FILL_ENABLE BIT(20)
|
|
||||||
#define SLC_RX_DESCRIPTOR_CONF_RX_EOF_MODE BIT(19)
|
|
||||||
#define SLC_RX_DESCRIPTOR_CONF_RX_FILL_MODE BIT(18)
|
|
||||||
#define SLC_RX_DESCRIPTOR_CONF_INFOR_NO_REPLACE BIT(17)
|
|
||||||
#define SLC_RX_DESCRIPTOR_CONF_TOKEN_NO_REPLACE BIT(16)
|
|
||||||
#define SLC_RX_DESCRIPTOR_CONF_POP_IDLE_COUNT_M 0x0000ffff
|
|
||||||
#define SLC_RX_DESCRIPTOR_CONF_POP_IDLE_COUNT_S 0
|
|
||||||
|
|
||||||
#endif /* _ESP_SLC_REGS_H */
|
|
|
@ -1,433 +0,0 @@
|
||||||
/**
|
|
||||||
* \file Hardware SPI master driver
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
*
|
|
||||||
* \copyright Ruslan V. Uss, 2016
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#ifndef _ESP_SPI_H_
|
|
||||||
#define _ESP_SPI_H_
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "esp/spi_regs.h"
|
|
||||||
#include "esp/clocks.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Macro for use with spi_init and spi_set_frequency_div.
|
|
||||||
* SPI frequency = 80000000 / divider / count
|
|
||||||
* dvider must be in 1..8192 and count in 1..64
|
|
||||||
*/
|
|
||||||
#define SPI_GET_FREQ_DIV(divider, count) (((count) << 16) | ((divider) & 0xffff))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Predefinded SPI frequency dividers
|
|
||||||
*/
|
|
||||||
#define SPI_FREQ_DIV_125K SPI_GET_FREQ_DIV(64, 10) ///< 125kHz
|
|
||||||
#define SPI_FREQ_DIV_250K SPI_GET_FREQ_DIV(32, 10) ///< 250kHz
|
|
||||||
#define SPI_FREQ_DIV_500K SPI_GET_FREQ_DIV(16, 10) ///< 500kHz
|
|
||||||
#define SPI_FREQ_DIV_1M SPI_GET_FREQ_DIV(8, 10) ///< 1MHz
|
|
||||||
#define SPI_FREQ_DIV_2M SPI_GET_FREQ_DIV(4, 10) ///< 2MHz
|
|
||||||
#define SPI_FREQ_DIV_4M SPI_GET_FREQ_DIV(2, 10) ///< 4MHz
|
|
||||||
#define SPI_FREQ_DIV_8M SPI_GET_FREQ_DIV(5, 2) ///< 8MHz
|
|
||||||
#define SPI_FREQ_DIV_10M SPI_GET_FREQ_DIV(4, 2) ///< 10MHz
|
|
||||||
#define SPI_FREQ_DIV_20M SPI_GET_FREQ_DIV(2, 2) ///< 20MHz
|
|
||||||
#define SPI_FREQ_DIV_40M SPI_GET_FREQ_DIV(1, 2) ///< 40MHz
|
|
||||||
#define SPI_FREQ_DIV_80M SPI_GET_FREQ_DIV(1, 1) ///< 80MHz
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Possible Data Structure of SPI Transaction
|
|
||||||
*
|
|
||||||
* [COMMAND]+[ADDRESS]+[DataOUT]+[DUMMYBITS]+[DataIN]
|
|
||||||
*
|
|
||||||
* [COMMAND]+[ADDRESS]+[DUMMYBITS]+[DataOUT]
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum _spi_mode_t {
|
|
||||||
SPI_MODE0 = 0, ///< CPOL = 0, CPHA = 0
|
|
||||||
SPI_MODE1, ///< CPOL = 0, CPHA = 1
|
|
||||||
SPI_MODE2, ///< CPOL = 1, CPHA = 0
|
|
||||||
SPI_MODE3 ///< CPOL = 1, CPHA = 1
|
|
||||||
} spi_mode_t;
|
|
||||||
|
|
||||||
typedef enum _spi_endianness_t {
|
|
||||||
SPI_LITTLE_ENDIAN = 0,
|
|
||||||
SPI_BIG_ENDIAN
|
|
||||||
} spi_endianness_t;
|
|
||||||
|
|
||||||
typedef enum _spi_word_size_t {
|
|
||||||
SPI_8BIT = 1, ///< 1 byte
|
|
||||||
SPI_16BIT = 2, ///< 2 bytes
|
|
||||||
SPI_32BIT = 4 ///< 4 bytes
|
|
||||||
} spi_word_size_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SPI bus settings
|
|
||||||
*/
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
spi_mode_t mode; ///< Bus mode
|
|
||||||
uint32_t freq_divider; ///< Bus frequency as a divider. See spi_init()
|
|
||||||
bool msb; ///< MSB first if true
|
|
||||||
spi_endianness_t endianness; ///< Bus byte order
|
|
||||||
bool minimal_pins; ///< Minimal set of pins if true. Spee spi_init()
|
|
||||||
} spi_settings_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Initalize SPI bus
|
|
||||||
* Initalize specified SPI bus and setup appropriate pins:
|
|
||||||
* Bus 0:
|
|
||||||
* - MISO = GPIO 7
|
|
||||||
* - MOSI = GPIO 8
|
|
||||||
* - SCK = GPIO 6
|
|
||||||
* - CS0 = GPIO 11 (if minimal_pins is false)
|
|
||||||
* - HD = GPIO 9 (if minimal_pins is false)
|
|
||||||
* - WP = GPIO 10 (if minimal_pins is false)
|
|
||||||
* Bus 1:
|
|
||||||
* - MISO = GPIO 12
|
|
||||||
* - MOSI = GPIO 13
|
|
||||||
* - SCK = GPIO 14
|
|
||||||
* - CS0 = GPIO 15 (if minimal_pins is false)
|
|
||||||
* Note that system flash memory is on the bus 0!
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param mode Bus mode
|
|
||||||
* \param freq_divider SPI bus frequency divider, use SPI_GET_FREQ_DIV() or predefined value
|
|
||||||
* \param msb Bit order, MSB first if true
|
|
||||||
* \param endianness Byte order
|
|
||||||
* \param minimal_pins If true use the minimal set of pins: MISO, MOSI and SCK.
|
|
||||||
* \return false when error
|
|
||||||
*/
|
|
||||||
bool spi_init(uint8_t bus, spi_mode_t mode, uint32_t freq_divider, bool msb, spi_endianness_t endianness, bool minimal_pins);
|
|
||||||
/**
|
|
||||||
* \brief Initalize SPI bus
|
|
||||||
* spi_init() wrapper.
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* const spi_settings_t my_settings = {
|
|
||||||
* .mode = SPI_MODE0,
|
|
||||||
* .freq_divider = SPI_FREQ_DIV_4M,
|
|
||||||
* .msb = true,
|
|
||||||
* .endianness = SPI_LITTLE_ENDIAN,
|
|
||||||
* .minimal_pins = true
|
|
||||||
* }
|
|
||||||
* ....
|
|
||||||
* spi_settings_t old;
|
|
||||||
* spi_get_settings(1, &old); // save current settings
|
|
||||||
* //spi_init(1, SPI_MODE0, SPI_FREQ_DIV_4M, true, SPI_LITTLE_ENDIAN, true); // use own settings
|
|
||||||
* // or
|
|
||||||
* spi_set_settings(1, &my_settings);
|
|
||||||
* // some work with spi here
|
|
||||||
* ....
|
|
||||||
* spi_set_settings(1, &old); // restore saved settings
|
|
||||||
*
|
|
||||||
* \param s Pointer to the settings structure
|
|
||||||
* \return false when error
|
|
||||||
*/
|
|
||||||
static inline bool spi_set_settings(uint8_t bus, const spi_settings_t *s)
|
|
||||||
{
|
|
||||||
return spi_init(bus, s->mode, s->freq_divider, s->msb, s->endianness, s->minimal_pins);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* \brief Get current settings of the SPI bus
|
|
||||||
* See spi_set_settings().
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param s Pointer to the structure that receives SPI bus settings
|
|
||||||
*/
|
|
||||||
void spi_get_settings(uint8_t bus, spi_settings_t *s);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Set SPI bus mode
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param mode Bus mode
|
|
||||||
*/
|
|
||||||
void spi_set_mode(uint8_t bus, spi_mode_t mode);
|
|
||||||
/**
|
|
||||||
* \brief Get mode of the SPI bus
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \return Bus mode
|
|
||||||
*/
|
|
||||||
spi_mode_t spi_get_mode(uint8_t bus);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Set SPI bus frequency
|
|
||||||
* Examples:
|
|
||||||
*
|
|
||||||
* spi_set_frequency_div(1, SPI_FREQ_DIV_8M); // 8 MHz, predefined value
|
|
||||||
* ...
|
|
||||||
* spi_set_frequency_div(1, SPI_GET_FREQ_DIV(8, 10)); // divider = 8, count = 10,
|
|
||||||
* // frequency = 80000000 Hz / 8 / 10 = 1000000 Hz
|
|
||||||
*
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param divider Predivider of the system bus frequency (80MHz) in the 2 low
|
|
||||||
* bytes and period pulses count in the third byte. Please note that
|
|
||||||
* divider must be be in range 1..8192 and count in range 2..64. Use the
|
|
||||||
* macro SPI_GET_FREQ_DIV(divider, count) to get the correct parameter value.
|
|
||||||
*/
|
|
||||||
void spi_set_frequency_div(uint8_t bus, uint32_t divider);
|
|
||||||
/**
|
|
||||||
* \brief Get SPI bus frequency as a divider
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* uint32_t old_freq = spi_get_frequency_div(1);
|
|
||||||
* spi_set_frequency_div(1, SPI_FREQ_DIV_8M);
|
|
||||||
* ...
|
|
||||||
* spi_set_frequency_div(1, old_freq);
|
|
||||||
*
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \return SPI frequency, as divider.
|
|
||||||
*/
|
|
||||||
inline uint32_t spi_get_frequency_div(uint8_t bus)
|
|
||||||
{
|
|
||||||
return (FIELD2VAL(SPI_CLOCK_DIV_PRE, SPI(bus).CLOCK) + 1) |
|
|
||||||
(FIELD2VAL(SPI_CLOCK_COUNT_NUM, SPI(bus).CLOCK) + 1);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* \brief Get SPI bus frequency in Hz
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \return SPI frequency, Hz
|
|
||||||
*/
|
|
||||||
inline uint32_t spi_get_frequency_hz(uint8_t bus)
|
|
||||||
{
|
|
||||||
return APB_CLK_FREQ /
|
|
||||||
(FIELD2VAL(SPI_CLOCK_DIV_PRE, SPI(bus).CLOCK) + 1) /
|
|
||||||
(FIELD2VAL(SPI_CLOCK_COUNT_NUM, SPI(bus).CLOCK) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Set SPI bus bit order
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param msb Bit order, MSB first if true
|
|
||||||
*/
|
|
||||||
void spi_set_msb(uint8_t bus, bool msb);
|
|
||||||
/**
|
|
||||||
* \brief Get SPI bus bit order
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \return msb Bit order, MSB first if true
|
|
||||||
*/
|
|
||||||
inline bool spi_get_msb(uint8_t bus)
|
|
||||||
{
|
|
||||||
return !(SPI(bus).CTRL0 & (SPI_CTRL0_WR_BIT_ORDER | SPI_CTRL0_RD_BIT_ORDER));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Set SPI bus byte order
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param endianness Byte order
|
|
||||||
*/
|
|
||||||
void spi_set_endianness(uint8_t bus, spi_endianness_t endianness);
|
|
||||||
/**
|
|
||||||
* \brief Get SPI bus byte order
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \return endianness Byte order
|
|
||||||
*/
|
|
||||||
inline spi_endianness_t spi_get_endianness(uint8_t bus)
|
|
||||||
{
|
|
||||||
return SPI(bus).USER0 & (SPI_USER0_WR_BYTE_ORDER | SPI_USER0_RD_BYTE_ORDER)
|
|
||||||
? SPI_BIG_ENDIAN
|
|
||||||
: SPI_LITTLE_ENDIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Transfer 8 bits over SPI
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param data Byte to send
|
|
||||||
* \return Received byte
|
|
||||||
*/
|
|
||||||
uint8_t spi_transfer_8(uint8_t bus, uint8_t data);
|
|
||||||
/**
|
|
||||||
* \brief Transfer 16 bits over SPI
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param data Word to send
|
|
||||||
* \return Received word
|
|
||||||
*/
|
|
||||||
uint16_t spi_transfer_16(uint8_t bus, uint16_t data);
|
|
||||||
/**
|
|
||||||
* \brief Transfer 32 bits over SPI
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param data dword to send
|
|
||||||
* \return Received dword
|
|
||||||
*/
|
|
||||||
uint32_t spi_transfer_32(uint8_t bus, uint32_t data);
|
|
||||||
/**
|
|
||||||
* \brief Transfer buffer of words over SPI
|
|
||||||
* Please note that the buffer size is in words, not in bytes!
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* const uint16_t out_buf[] = { 0xa0b0, 0xa1b1, 0xa2b2, 0xa3b3 };
|
|
||||||
* uint16_t in_buf[sizeof(out_buf)];
|
|
||||||
* spi_init(1, SPI_MODE1, SPI_FREQ_DIV_4M, true, SPI_BIG_ENDIAN, true);
|
|
||||||
* spi_transfer(1, out_buf, in_buf, sizeof(out_buf), SPI_16BIT); // len = 4 words * 2 bytes = 8 bytes
|
|
||||||
*
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param out_data Data to send.
|
|
||||||
* \param in_data Receive buffer. If NULL, received data will be lost.
|
|
||||||
* \param len Buffer size in words
|
|
||||||
* \param word_size Size of the word
|
|
||||||
* \return Transmitted/received words count
|
|
||||||
*/
|
|
||||||
size_t spi_transfer(uint8_t bus, const void *out_data, void *in_data, size_t len, spi_word_size_t word_size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Add permanent command bits when transfert data over SPI
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* spi_set_command(1, 1, 0x01); // Set one command bit to 1
|
|
||||||
* for (uint8_t i = 0; i < x; i++ ) {
|
|
||||||
* spi_transfer_8(1, 0x55); // Send 1 bit command + 8 bits data x times
|
|
||||||
* }
|
|
||||||
* spi_clear_command(1); // Clear command
|
|
||||||
* spi_transfer_8(1, 0x55); // Send 8 bits data
|
|
||||||
*
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param bits Number of bits (max: 16).
|
|
||||||
* \param data Command to send for each transfert.
|
|
||||||
*/
|
|
||||||
static inline void spi_set_command(uint8_t bus, uint8_t bits, uint16_t data)
|
|
||||||
{
|
|
||||||
if (!bits) return;
|
|
||||||
|
|
||||||
SPI(bus).USER0 |= SPI_USER0_COMMAND; //enable COMMAND function in SPI module
|
|
||||||
uint16_t command;
|
|
||||||
// Commands are always sent using little endian byte order
|
|
||||||
if (!spi_get_msb(bus)) {
|
|
||||||
// "data" are natively little endian, with LSB bit order
|
|
||||||
// this makes all bits of the command ready to be sent as-is
|
|
||||||
command = data;
|
|
||||||
} else {
|
|
||||||
// MSB
|
|
||||||
command = data << (16 - bits); //align command data to high bits
|
|
||||||
command = ((command >> 8) & 0xff) | ((command << 8) & 0xff00); //swap byte order
|
|
||||||
}
|
|
||||||
SPI(bus).USER2 = SET_FIELD(SPI(bus).USER2, SPI_USER2_COMMAND_BITLEN, --bits);
|
|
||||||
SPI(bus).USER2 = SET_FIELD(SPI(bus).USER2, SPI_USER2_COMMAND_VALUE, command);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Add permanent address bits when transfert data over SPI
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* spi_set_address(1,8,0x45); // Set one address byte to 0x45
|
|
||||||
* for (uint8_t i = 0 ; i < x ; i++ ) {
|
|
||||||
* spi_transfer_16(1,0xC584); // Send 16 bits address + 16 bits data x times
|
|
||||||
* }
|
|
||||||
* spi_clear_address(1); // Clear command
|
|
||||||
* spi_transfer_16(1,0x55); // Send 16 bits data
|
|
||||||
*
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param bits Number of bits (max: 32).
|
|
||||||
* \param data Address to send for each transfert.
|
|
||||||
*/
|
|
||||||
static inline void spi_set_address(uint8_t bus, uint8_t bits, uint32_t data)
|
|
||||||
{
|
|
||||||
if (!bits) return;
|
|
||||||
|
|
||||||
SPI(bus).USER0 |= SPI_USER0_ADDR; //enable ADDRess function in SPI module
|
|
||||||
// addresses are always sent using big endian byte order
|
|
||||||
if (spi_get_msb(bus)) {
|
|
||||||
SPI(bus).ADDR = data << (32 - bits); //align address data to high bits
|
|
||||||
} else {
|
|
||||||
// swap bytes from native little to command's big endian order
|
|
||||||
// bits in each byte are already arranged properly for LSB
|
|
||||||
SPI(bus).ADDR = (data & 0xff) << 24 | (data & 0xff00) << 8 | ((data >> 8) & 0xff00) | ((data >> 24) & 0xff);
|
|
||||||
}
|
|
||||||
SPI(bus).USER1 = SET_FIELD(SPI(bus).USER1, SPI_USER1_ADDR_BITLEN, --bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Add permanent dummy bits when transfert data over SPI
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* spi_set_dummy_bits(1, 4, false); // Set 4 dummy bit before Dout
|
|
||||||
* for (uint8_t i = 0; i < x; i++ ) {
|
|
||||||
* spi_transfer_16(1, 0xC584); // Send 4 bits dummy + 16 bits Dout x times
|
|
||||||
* }
|
|
||||||
* spi_set_dummy_bits(1, 4, true); // Set 4 dummy bit between Dout and Din
|
|
||||||
* spi_transfer_8(1, 0x55); // Send 8 bits Dout + 4 bits dummy + 8 bits Din
|
|
||||||
*
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param bits Number of bits
|
|
||||||
* \param pos Position of dummy bit, between Dout and Din if true.
|
|
||||||
*/
|
|
||||||
static inline void spi_set_dummy_bits(uint8_t bus, uint8_t bits, bool pos)
|
|
||||||
{
|
|
||||||
if (!bits) return;
|
|
||||||
if (pos)
|
|
||||||
SPI(bus).USER0 |= SPI_USER0_MISO; // Dummy bit will be between Dout and Din data if set
|
|
||||||
SPI(bus).USER0 |= SPI_USER0_DUMMY; //enable dummy bits
|
|
||||||
SPI(bus).USER1 = SET_FIELD(SPI(bus).USER1, SPI_USER1_DUMMY_CYCLELEN, --bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Clear adress Bits
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
*/
|
|
||||||
static inline void spi_clear_address(uint8_t bus)
|
|
||||||
{
|
|
||||||
SPI(bus).USER0 &= ~(SPI_USER0_ADDR);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Clear command Bits
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
*/
|
|
||||||
|
|
||||||
static inline void spi_clear_command(uint8_t bus)
|
|
||||||
{
|
|
||||||
SPI(bus).USER0 &= ~(SPI_USER0_COMMAND);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Clear dummy Bits
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
*/
|
|
||||||
static inline void spi_clear_dummy(uint8_t bus)
|
|
||||||
{
|
|
||||||
SPI(bus).USER0 &= ~(SPI_USER0_DUMMY | SPI_USER0_MISO);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Send many 8 bits template over SPI
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param data Byte template (8 bits)
|
|
||||||
* \param repeats Copy byte number
|
|
||||||
*/
|
|
||||||
void spi_repeat_send_8(uint8_t bus, uint8_t data, int32_t repeats);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Send many 16 bits template over SPI
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param data Word template (16 bits)
|
|
||||||
* \param repeats Copy word number
|
|
||||||
*/
|
|
||||||
void spi_repeat_send_16(uint8_t bus, uint16_t data, int32_t repeats);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Send many 32 bits template over SPI
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param data Dualword template (32 bits)
|
|
||||||
* \param repeats Copy dword number
|
|
||||||
*/
|
|
||||||
void spi_repeat_send_32(uint8_t bus, uint32_t data, int32_t repeats);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Repeatedly send byte over SPI and receive data
|
|
||||||
* \param bus Bus ID: 0 - system, 1 - user
|
|
||||||
* \param out_byte Byte to send
|
|
||||||
* \param in_data Receive buffer
|
|
||||||
* \param len Buffer size in words
|
|
||||||
* \param word_size Size of the word
|
|
||||||
*/
|
|
||||||
void spi_read(uint8_t bus, uint8_t out_byte, void *in_data, size_t len, spi_word_size_t word_size);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* _ESP_SPI_H_ */
|
|
|
@ -46,7 +46,22 @@ struct SPI_REGS {
|
||||||
uint32_t volatile SLAVE1; // 0x34
|
uint32_t volatile SLAVE1; // 0x34
|
||||||
uint32_t volatile SLAVE2; // 0x38
|
uint32_t volatile SLAVE2; // 0x38
|
||||||
uint32_t volatile SLAVE3; // 0x3c
|
uint32_t volatile SLAVE3; // 0x3c
|
||||||
uint32_t volatile W[16]; // 0x40 - 0x7c
|
uint32_t volatile W0; // 0x40
|
||||||
|
uint32_t volatile W1; // 0x44
|
||||||
|
uint32_t volatile W2; // 0x48
|
||||||
|
uint32_t volatile W3; // 0x4c
|
||||||
|
uint32_t volatile W4; // 0x50
|
||||||
|
uint32_t volatile W5; // 0x54
|
||||||
|
uint32_t volatile W6; // 0x58
|
||||||
|
uint32_t volatile W7; // 0x5c
|
||||||
|
uint32_t volatile W8; // 0x60
|
||||||
|
uint32_t volatile W9; // 0x64
|
||||||
|
uint32_t volatile W10; // 0x68
|
||||||
|
uint32_t volatile W11; // 0x6c
|
||||||
|
uint32_t volatile W12; // 0x70
|
||||||
|
uint32_t volatile W13; // 0x74
|
||||||
|
uint32_t volatile W14; // 0x78
|
||||||
|
uint32_t volatile W15; // 0x7c
|
||||||
uint32_t volatile _unused[28]; // 0x80 - 0xec
|
uint32_t volatile _unused[28]; // 0x80 - 0xec
|
||||||
uint32_t volatile EXT0; // 0xf0
|
uint32_t volatile EXT0; // 0xf0
|
||||||
uint32_t volatile EXT1; // 0xf4
|
uint32_t volatile EXT1; // 0xf4
|
||||||
|
@ -58,19 +73,6 @@ _Static_assert(sizeof(struct SPI_REGS) == 0x100, "SPI_REGS is the wrong size");
|
||||||
|
|
||||||
/* Details for CMD register */
|
/* Details for CMD register */
|
||||||
|
|
||||||
#define SPI_CMD_READ BIT(31)
|
|
||||||
#define SPI_CMD_WRITE_ENABLE BIT(30)
|
|
||||||
#define SPI_CMD_WRITE_DISABLE BIT(29)
|
|
||||||
#define SPI_CMD_READ_ID BIT(28)
|
|
||||||
#define SPI_CMD_READ_SR BIT(27)
|
|
||||||
#define SPI_CMD_WRITE_SR BIT(26)
|
|
||||||
#define SPI_CMD_PP BIT(25)
|
|
||||||
#define SPI_CMD_SE BIT(24)
|
|
||||||
#define SPI_CMD_BE BIT(23)
|
|
||||||
#define SPI_CMD_CE BIT(22)
|
|
||||||
#define SPI_CMD_DP BIT(21)
|
|
||||||
#define SPI_CMD_RES BIT(20)
|
|
||||||
#define SPI_CMD_HPM BIT(19)
|
|
||||||
#define SPI_CMD_USR BIT(18)
|
#define SPI_CMD_USR BIT(18)
|
||||||
|
|
||||||
/* Details for CTRL0 register */
|
/* Details for CTRL0 register */
|
||||||
|
@ -150,7 +152,6 @@ _Static_assert(sizeof(struct SPI_REGS) == 0x100, "SPI_REGS is the wrong size");
|
||||||
#define SPI_USER0_CS_SETUP BIT(5)
|
#define SPI_USER0_CS_SETUP BIT(5)
|
||||||
#define SPI_USER0_CS_HOLD BIT(4)
|
#define SPI_USER0_CS_HOLD BIT(4)
|
||||||
#define SPI_USER0_FLASH_MODE BIT(2)
|
#define SPI_USER0_FLASH_MODE BIT(2)
|
||||||
#define SPI_USER0_DUPLEX BIT(0)
|
|
||||||
|
|
||||||
/* Details for USER1 register */
|
/* Details for USER1 register */
|
||||||
|
|
||||||
|
@ -172,7 +173,6 @@ _Static_assert(sizeof(struct SPI_REGS) == 0x100, "SPI_REGS is the wrong size");
|
||||||
|
|
||||||
/* Details for PIN register */
|
/* Details for PIN register */
|
||||||
|
|
||||||
#define SPI_PIN_IDLE_EDGE BIT(29) ///< CPOL
|
|
||||||
#define SPI_PIN_CS2_DISABLE BIT(2)
|
#define SPI_PIN_CS2_DISABLE BIT(2)
|
||||||
#define SPI_PIN_CS1_DISABLE BIT(1)
|
#define SPI_PIN_CS1_DISABLE BIT(1)
|
||||||
#define SPI_PIN_CS0_DISABLE BIT(0)
|
#define SPI_PIN_CS0_DISABLE BIT(0)
|
||||||
|
|
|
@ -10,13 +10,9 @@
|
||||||
#define _ESP_TIMER_H
|
#define _ESP_TIMER_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <errno.h>
|
#include <xtensa_interrupts.h>
|
||||||
#include "esp/timer_regs.h"
|
#include "esp/timer_regs.h"
|
||||||
#include "esp/interrupts.h"
|
#include "esp/cpu.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
FRC1 = 0,
|
FRC1 = 0,
|
||||||
|
@ -24,73 +20,43 @@ typedef enum {
|
||||||
} timer_frc_t;
|
} timer_frc_t;
|
||||||
|
|
||||||
/* Return current count value for timer. */
|
/* Return current count value for timer. */
|
||||||
static inline uint32_t timer_get_count(const timer_frc_t frc)
|
INLINED uint32_t timer_get_count(const timer_frc_t frc);
|
||||||
{
|
|
||||||
return TIMER(frc).COUNT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return current load value for timer. */
|
/* Return current load value for timer. */
|
||||||
static inline uint32_t timer_get_load(const timer_frc_t frc)
|
INLINED uint32_t timer_get_load(const timer_frc_t frc);
|
||||||
{
|
|
||||||
return TIMER(frc).LOAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write load value for timer. */
|
/* Write load value for timer. */
|
||||||
static inline void timer_set_load(const timer_frc_t frc, const uint32_t load)
|
INLINED void timer_set_load(const timer_frc_t frc, const uint32_t load);
|
||||||
{
|
|
||||||
TIMER(frc).LOAD = load;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns maximum load value for timer. */
|
/* Returns maximum load value for timer. */
|
||||||
static inline uint32_t timer_max_load(const timer_frc_t frc)
|
INLINED uint32_t timer_max_load(const timer_frc_t frc);
|
||||||
{
|
|
||||||
return (frc == FRC1) ? TIMER_FRC1_MAX_LOAD : UINT32_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set the timer divider value */
|
/* Set the timer divider value */
|
||||||
static inline void timer_set_divider(const timer_frc_t frc, const timer_clkdiv_t div)
|
INLINED void timer_set_divider(const timer_frc_t frc, const timer_clkdiv_t div);
|
||||||
{
|
|
||||||
if(div < TIMER_CLKDIV_1 || div > TIMER_CLKDIV_256)
|
|
||||||
return;
|
|
||||||
TIMER(frc).CTRL = SET_FIELD(TIMER(frc).CTRL, TIMER_CTRL_CLKDIV, div);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enable or disable timer interrupts
|
/* Enable or disable timer interrupts
|
||||||
|
|
||||||
This both sets the xtensa interrupt mask and writes to the DPORT register
|
This both sets the xtensa interrupt mask and writes to the DPORT register
|
||||||
that allows timer interrupts.
|
that allows timer interrupts.
|
||||||
*/
|
*/
|
||||||
void timer_set_interrupts(const timer_frc_t frc, bool enable);
|
INLINED void timer_set_interrupts(const timer_frc_t frc, bool enable);
|
||||||
|
|
||||||
/* Turn the timer on or off */
|
/* Turn the timer on or off */
|
||||||
static inline void timer_set_run(const timer_frc_t frc, const bool run)
|
INLINED void timer_set_run(const timer_frc_t frc, const bool run);
|
||||||
{
|
|
||||||
if (run)
|
|
||||||
TIMER(frc).CTRL |= TIMER_CTRL_RUN;
|
|
||||||
else
|
|
||||||
TIMER(frc).CTRL &= ~TIMER_CTRL_RUN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the run state of the timer (on or off) */
|
/* Get the run state of the timer (on or off) */
|
||||||
static inline bool timer_get_run(const timer_frc_t frc)
|
INLINED bool timer_get_run(const timer_frc_t frc);
|
||||||
{
|
|
||||||
return TIMER(frc).CTRL & TIMER_CTRL_RUN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set timer auto-reload on or off */
|
/* Set timer auto-reload on or off */
|
||||||
static inline void timer_set_reload(const timer_frc_t frc, const bool reload)
|
INLINED void timer_set_reload(const timer_frc_t frc, const bool reload);
|
||||||
{
|
|
||||||
if (reload)
|
|
||||||
TIMER(frc).CTRL |= TIMER_CTRL_RELOAD;
|
|
||||||
else
|
|
||||||
TIMER(frc).CTRL &= ~TIMER_CTRL_RELOAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the auto-reload state of the timer (on or off) */
|
/* Get the auto-reload state of the timer (on or off) */
|
||||||
static inline bool timer_get_reload(const timer_frc_t frc)
|
INLINED bool timer_get_reload(const timer_frc_t frc);
|
||||||
{
|
|
||||||
return TIMER(frc).CTRL & TIMER_CTRL_RELOAD;
|
/* Return a suitable timer divider for the specified frequency,
|
||||||
}
|
or -1 if none is found.
|
||||||
|
*/
|
||||||
|
INLINED timer_clkdiv_t timer_freq_to_div(uint32_t freq);
|
||||||
|
|
||||||
/* Return the number of timer counts to achieve the specified
|
/* Return the number of timer counts to achieve the specified
|
||||||
* frequency with the specified divisor.
|
* frequency with the specified divisor.
|
||||||
|
@ -99,41 +65,14 @@ static inline bool timer_get_reload(const timer_frc_t frc)
|
||||||
*
|
*
|
||||||
* Returns 0 if the given freq/divisor combo cannot be achieved.
|
* Returns 0 if the given freq/divisor combo cannot be achieved.
|
||||||
*
|
*
|
||||||
|
* Compile-time evaluates if all arguments are available at compile time.
|
||||||
*/
|
*/
|
||||||
uint32_t timer_freq_to_count(const timer_frc_t frc, uint32_t freq, const timer_clkdiv_t div);
|
INLINED uint32_t timer_freq_to_count(const timer_frc_t frc, uint32_t freq, const timer_clkdiv_t div);
|
||||||
|
|
||||||
/* Return a suitable timer divider for the specified frequency,
|
|
||||||
or -1 if none is found.
|
|
||||||
*/
|
|
||||||
static inline timer_clkdiv_t timer_freq_to_div(uint32_t freq)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
try to maintain resolution without risking overflows.
|
|
||||||
these values are a bit arbitrary at the moment! */
|
|
||||||
if(freq > 100*1000)
|
|
||||||
return TIMER_CLKDIV_1;
|
|
||||||
else if(freq > 100)
|
|
||||||
return TIMER_CLKDIV_16;
|
|
||||||
else
|
|
||||||
return TIMER_CLKDIV_256;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return a suitable timer divider for the specified duration in
|
/* Return a suitable timer divider for the specified duration in
|
||||||
microseconds or -1 if none is found.
|
microseconds or -1 if none is found.
|
||||||
*/
|
*/
|
||||||
static inline timer_clkdiv_t timer_time_to_div(uint32_t us)
|
INLINED timer_clkdiv_t timer_time_to_div(uint32_t us);
|
||||||
{
|
|
||||||
/*
|
|
||||||
try to maintain resolution without risking overflows. Similar to
|
|
||||||
timer_freq_to_div, these values are a bit arbitrary at the
|
|
||||||
moment! */
|
|
||||||
if(us < 1000)
|
|
||||||
return TIMER_CLKDIV_1;
|
|
||||||
else if(us < 10*1000)
|
|
||||||
return TIMER_CLKDIV_16;
|
|
||||||
else
|
|
||||||
return TIMER_CLKDIV_256;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return the number of timer counts for the specified timer duration
|
/* Return the number of timer counts for the specified timer duration
|
||||||
* in microseconds, when using the specified divisor.
|
* in microseconds, when using the specified divisor.
|
||||||
|
@ -142,8 +81,9 @@ static inline timer_clkdiv_t timer_time_to_div(uint32_t us)
|
||||||
*
|
*
|
||||||
* Returns 0 if the given time/divisor combo cannot be achieved.
|
* Returns 0 if the given time/divisor combo cannot be achieved.
|
||||||
*
|
*
|
||||||
|
* Compile-time evaluates if all arguments are available at compile time.
|
||||||
*/
|
*/
|
||||||
uint32_t timer_time_to_count(const timer_frc_t frc, uint32_t us, const timer_clkdiv_t div);
|
INLINED uint32_t timer_time_to_count(const timer_frc_t frc, uint32_t us, const timer_clkdiv_t div);
|
||||||
|
|
||||||
/* Set a target timer interrupt frequency in Hz.
|
/* Set a target timer interrupt frequency in Hz.
|
||||||
|
|
||||||
|
@ -160,9 +100,12 @@ uint32_t timer_time_to_count(const timer_frc_t frc, uint32_t us, const timer_clk
|
||||||
Does not start/stop the timer, you have to do this manually via
|
Does not start/stop the timer, you have to do this manually via
|
||||||
timer_set_run.
|
timer_set_run.
|
||||||
|
|
||||||
Returns 0 on success, or -EINVAL if given frequency could not be set.
|
Returns true on success, false if given frequency could not be set.
|
||||||
|
|
||||||
|
Compile-time evaluates to simple register writes if all arguments
|
||||||
|
are available at compile time.
|
||||||
*/
|
*/
|
||||||
int timer_set_frequency(const timer_frc_t frc, uint32_t freq);
|
INLINED bool timer_set_frequency(const timer_frc_t frc, uint32_t freq);
|
||||||
|
|
||||||
/* Sets the timer for a oneshot interrupt in 'us' microseconds.
|
/* Sets the timer for a oneshot interrupt in 'us' microseconds.
|
||||||
|
|
||||||
|
@ -177,12 +120,13 @@ int timer_set_frequency(const timer_frc_t frc, uint32_t freq);
|
||||||
also disable FRC1 in the timer interrupt handler by calling
|
also disable FRC1 in the timer interrupt handler by calling
|
||||||
timer_set_run(TIMER_FRC1, false);
|
timer_set_run(TIMER_FRC1, false);
|
||||||
|
|
||||||
Returns 0 on success, or -EINVAL if the given timeout could not be set.
|
Returns true if the timeout was successfully set.
|
||||||
|
|
||||||
|
Compile-time evaluates to simple register writes if all arguments
|
||||||
|
are available at compile time.
|
||||||
*/
|
*/
|
||||||
int timer_set_timeout(const timer_frc_t frc, uint32_t us);
|
INLINED bool timer_set_timeout(const timer_frc_t frc, uint32_t us);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#include "timer_private.h"
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
260
core/include/esp/timer_private.h
Normal file
260
core/include/esp/timer_private.h
Normal file
|
@ -0,0 +1,260 @@
|
||||||
|
/* Private header parts of the timer API implementation
|
||||||
|
*
|
||||||
|
* Part of esp-open-rtos
|
||||||
|
* Copyright (C) 2015 Superhouse Automation Pty Ltd
|
||||||
|
* BSD Licensed as described in the file LICENSE
|
||||||
|
*/
|
||||||
|
#ifndef _ESP_TIMER_PRIVATE_H
|
||||||
|
#define _ESP_TIMER_PRIVATE_H
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "esp/dport_regs.h"
|
||||||
|
|
||||||
|
/* Timer divisor index to max frequency */
|
||||||
|
#define _FREQ_DIV1 (80*1000*1000)
|
||||||
|
#define _FREQ_DIV16 (5*1000*1000)
|
||||||
|
#define _FREQ_DIV256 312500
|
||||||
|
const static uint32_t IROM _TIMER_FREQS[] = { _FREQ_DIV1, _FREQ_DIV16, _FREQ_DIV256 };
|
||||||
|
|
||||||
|
/* Timer divisor index to divisor value */
|
||||||
|
const static uint32_t IROM _TIMER_DIV_VAL[] = { 1, 16, 256 };
|
||||||
|
|
||||||
|
INLINED uint32_t timer_get_count(const timer_frc_t frc)
|
||||||
|
{
|
||||||
|
return TIMER(frc).COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED uint32_t timer_get_load(const timer_frc_t frc)
|
||||||
|
{
|
||||||
|
return TIMER(frc).LOAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED void timer_set_load(const timer_frc_t frc, const uint32_t load)
|
||||||
|
{
|
||||||
|
TIMER(frc).LOAD = load;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED uint32_t timer_max_load(const timer_frc_t frc)
|
||||||
|
{
|
||||||
|
return (frc == FRC1) ? TIMER_FRC1_MAX_LOAD : UINT32_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED void timer_set_divider(const timer_frc_t frc, const timer_clkdiv_t div)
|
||||||
|
{
|
||||||
|
if(div < TIMER_CLKDIV_1 || div > TIMER_CLKDIV_256)
|
||||||
|
return;
|
||||||
|
TIMER(frc).CTRL = SET_FIELD(TIMER(frc).CTRL, TIMER_CTRL_CLKDIV, div);
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED void timer_set_interrupts(const timer_frc_t frc, bool enable)
|
||||||
|
{
|
||||||
|
const uint32_t dp_bit = (frc == FRC1) ? DPORT_INT_ENABLE_FRC1 : DPORT_INT_ENABLE_FRC2;
|
||||||
|
const uint32_t int_mask = BIT((frc == FRC1) ? INUM_TIMER_FRC1 : INUM_TIMER_FRC2);
|
||||||
|
if(enable) {
|
||||||
|
DPORT.INT_ENABLE |= dp_bit;
|
||||||
|
_xt_isr_unmask(int_mask);
|
||||||
|
} else {
|
||||||
|
DPORT.INT_ENABLE &= ~dp_bit;
|
||||||
|
_xt_isr_mask(int_mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED void timer_set_run(const timer_frc_t frc, const bool run)
|
||||||
|
{
|
||||||
|
if (run)
|
||||||
|
TIMER(frc).CTRL |= TIMER_CTRL_RUN;
|
||||||
|
else
|
||||||
|
TIMER(frc).CTRL &= ~TIMER_CTRL_RUN;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED bool timer_get_run(const timer_frc_t frc)
|
||||||
|
{
|
||||||
|
return TIMER(frc).CTRL & TIMER_CTRL_RUN;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED void timer_set_reload(const timer_frc_t frc, const bool reload)
|
||||||
|
{
|
||||||
|
if (reload)
|
||||||
|
TIMER(frc).CTRL |= TIMER_CTRL_RELOAD;
|
||||||
|
else
|
||||||
|
TIMER(frc).CTRL &= ~TIMER_CTRL_RELOAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED bool timer_get_reload(const timer_frc_t frc)
|
||||||
|
{
|
||||||
|
return TIMER(frc).CTRL & TIMER_CTRL_RELOAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED timer_clkdiv_t timer_freq_to_div(uint32_t freq)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
try to maintain resolution without risking overflows.
|
||||||
|
these values are a bit arbitrary at the moment! */
|
||||||
|
if(freq > 100*1000)
|
||||||
|
return TIMER_CLKDIV_1;
|
||||||
|
else if(freq > 100)
|
||||||
|
return TIMER_CLKDIV_16;
|
||||||
|
else
|
||||||
|
return TIMER_CLKDIV_256;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* timer_timer_to_count implementation - inline if all args are constant, call normally otherwise */
|
||||||
|
|
||||||
|
INLINED uint32_t _timer_freq_to_count_impl(const timer_frc_t frc, const uint32_t freq, const timer_clkdiv_t div)
|
||||||
|
{
|
||||||
|
if(div < TIMER_CLKDIV_1 || div > TIMER_CLKDIV_256)
|
||||||
|
return 0; /* invalid divider */
|
||||||
|
|
||||||
|
if(freq > _TIMER_FREQS[div])
|
||||||
|
return 0; /* out of range for given divisor */
|
||||||
|
|
||||||
|
uint64_t counts = _TIMER_FREQS[div]/freq;
|
||||||
|
return counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t _timer_freq_to_count_runtime(const timer_frc_t frc, const uint32_t freq, const timer_clkdiv_t div);
|
||||||
|
|
||||||
|
INLINED uint32_t timer_freq_to_count(const timer_frc_t frc, const uint32_t freq, const timer_clkdiv_t div)
|
||||||
|
{
|
||||||
|
if(__builtin_constant_p(frc) && __builtin_constant_p(freq) && __builtin_constant_p(div))
|
||||||
|
return _timer_freq_to_count_impl(frc, freq, div);
|
||||||
|
else
|
||||||
|
return _timer_freq_to_count_runtime(frc, freq, div);
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINED timer_clkdiv_t timer_time_to_div(uint32_t us)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
try to maintain resolution without risking overflows. Similar to
|
||||||
|
timer_freq_to_div, these values are a bit arbitrary at the
|
||||||
|
moment! */
|
||||||
|
if(us < 1000)
|
||||||
|
return TIMER_CLKDIV_1;
|
||||||
|
else if(us < 10*1000)
|
||||||
|
return TIMER_CLKDIV_16;
|
||||||
|
else
|
||||||
|
return TIMER_CLKDIV_256;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* timer_timer_to_count implementation - inline if all args are constant, call normally otherwise */
|
||||||
|
|
||||||
|
INLINED uint32_t _timer_time_to_count_impl(const timer_frc_t frc, uint32_t us, const timer_clkdiv_t div)
|
||||||
|
{
|
||||||
|
if(div < TIMER_CLKDIV_1 || div > TIMER_CLKDIV_256)
|
||||||
|
return 0; /* invalid divider */
|
||||||
|
|
||||||
|
const uint32_t TIMER_MAX = timer_max_load(frc);
|
||||||
|
|
||||||
|
if(div != TIMER_CLKDIV_256) /* timer tick in MHz */
|
||||||
|
{
|
||||||
|
/* timer is either 80MHz or 5MHz, so either 80 or 5 MHz counts per us */
|
||||||
|
const uint32_t counts_per_us = ((div == TIMER_CLKDIV_1) ? _FREQ_DIV1 : _FREQ_DIV16)/1000/1000;
|
||||||
|
if(us > TIMER_MAX/counts_per_us)
|
||||||
|
return 0; /* Multiplying us by mhz_per_count will overflow TIMER_MAX */
|
||||||
|
return us*counts_per_us;
|
||||||
|
}
|
||||||
|
else /* /256 divider, 312.5kHz freq so need to scale up */
|
||||||
|
{
|
||||||
|
/* derived from naive floating point equation that we can't use:
|
||||||
|
counts = (us/1000/1000)*_FREQ_DIV256;
|
||||||
|
counts = (us/2000)*(_FREQ_DIV256/500);
|
||||||
|
counts = us*(_FREQ_DIV256/500)/2000;
|
||||||
|
*/
|
||||||
|
const uint32_t scalar = _FREQ_DIV256/500;
|
||||||
|
if(us > 1+UINT32_MAX/scalar)
|
||||||
|
return 0; /* Multiplying us by _FREQ_DIV256/500 will overflow uint32_t */
|
||||||
|
|
||||||
|
uint32_t counts = (us*scalar)/2000;
|
||||||
|
if(counts > TIMER_MAX)
|
||||||
|
return 0; /* counts value too high for timer type */
|
||||||
|
return counts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t _timer_time_to_count_runtime(const timer_frc_t frc, uint32_t us, const timer_clkdiv_t div);
|
||||||
|
|
||||||
|
INLINED uint32_t timer_time_to_count(const timer_frc_t frc, uint32_t us, const timer_clkdiv_t div)
|
||||||
|
{
|
||||||
|
if(__builtin_constant_p(frc) && __builtin_constant_p(us) && __builtin_constant_p(div))
|
||||||
|
return _timer_time_to_count_impl(frc, us, div);
|
||||||
|
else
|
||||||
|
return _timer_time_to_count_runtime(frc, us, div);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* timer_set_frequency implementation - inline if all args are constant, call normally otherwise */
|
||||||
|
|
||||||
|
INLINED bool _timer_set_frequency_impl(const timer_frc_t frc, uint32_t freq)
|
||||||
|
{
|
||||||
|
uint32_t counts = 0;
|
||||||
|
timer_clkdiv_t div = timer_freq_to_div(freq);
|
||||||
|
|
||||||
|
counts = timer_freq_to_count(frc, freq, div);
|
||||||
|
if(counts == 0)
|
||||||
|
{
|
||||||
|
printf("ABORT: No counter for timer %u frequency %u\r\n", frc, freq);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
timer_set_divider(frc, div);
|
||||||
|
if(frc == FRC1)
|
||||||
|
{
|
||||||
|
timer_set_load(frc, counts);
|
||||||
|
timer_set_reload(frc, true);
|
||||||
|
}
|
||||||
|
else /* FRC2 */
|
||||||
|
{
|
||||||
|
/* assume that if this overflows it'll wrap, so we'll get desired behaviour */
|
||||||
|
TIMER(1).ALARM = counts + TIMER(1).COUNT;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _timer_set_frequency_runtime(const timer_frc_t frc, uint32_t freq);
|
||||||
|
|
||||||
|
INLINED bool timer_set_frequency(const timer_frc_t frc, uint32_t freq)
|
||||||
|
{
|
||||||
|
if(__builtin_constant_p(frc) && __builtin_constant_p(freq))
|
||||||
|
return _timer_set_frequency_impl(frc, freq);
|
||||||
|
else
|
||||||
|
return _timer_set_frequency_runtime(frc, freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* timer_set_timeout implementation - inline if all args are constant, call normally otherwise */
|
||||||
|
|
||||||
|
INLINED bool _timer_set_timeout_impl(const timer_frc_t frc, uint32_t us)
|
||||||
|
{
|
||||||
|
uint32_t counts = 0;
|
||||||
|
timer_clkdiv_t div = timer_time_to_div(us);
|
||||||
|
|
||||||
|
counts = timer_time_to_count(frc, us, div);
|
||||||
|
if(counts == 0)
|
||||||
|
return false; /* can't set frequency */
|
||||||
|
|
||||||
|
timer_set_divider(frc, div);
|
||||||
|
if(frc == FRC1)
|
||||||
|
{
|
||||||
|
timer_set_load(frc, counts);
|
||||||
|
}
|
||||||
|
else /* FRC2 */
|
||||||
|
{
|
||||||
|
TIMER(1).ALARM = counts + TIMER(1).COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _timer_set_timeout_runtime(const timer_frc_t frc, uint32_t us);
|
||||||
|
|
||||||
|
INLINED bool timer_set_timeout(const timer_frc_t frc, uint32_t us)
|
||||||
|
{
|
||||||
|
if(__builtin_constant_p(frc) && __builtin_constant_p(us))
|
||||||
|
return _timer_set_timeout_impl(frc, us);
|
||||||
|
else
|
||||||
|
return _timer_set_timeout_runtime(frc, us);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -2,8 +2,6 @@
|
||||||
#define _ESP_TYPES_H
|
#define _ESP_TYPES_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
typedef volatile uint32_t *esp_reg_t;
|
typedef volatile uint32_t *esp_reg_t;
|
||||||
|
|
||||||
|
|
|
@ -1,173 +0,0 @@
|
||||||
/** esp/uart.h
|
|
||||||
*
|
|
||||||
* Utility routines for working with UARTs
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (C) 2015 Superhouse Automation Pty Ltd
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
#ifndef _ESP_UART_H
|
|
||||||
#define _ESP_UART_H
|
|
||||||
|
|
||||||
#include "esp/types.h"
|
|
||||||
#include "esp/uart_regs.h"
|
|
||||||
#include "esp/clocks.h"
|
|
||||||
|
|
||||||
#define UART_FIFO_MAX 127
|
|
||||||
|
|
||||||
/* Wait for at least `min_count` bytes of data to be available in the UART's
|
|
||||||
* receive FIFO
|
|
||||||
*
|
|
||||||
* Returns the number of bytes actually available for reading.
|
|
||||||
*/
|
|
||||||
static inline int uart_rxfifo_wait(int uart_num, int min_count) {
|
|
||||||
int count;
|
|
||||||
do {
|
|
||||||
count = FIELD2VAL(UART_STATUS_RXFIFO_COUNT, UART(uart_num).STATUS);
|
|
||||||
} while (count < min_count);
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait for at least `min_count` bytes of space to be available in the UART's
|
|
||||||
* transmit FIFO
|
|
||||||
*
|
|
||||||
* Returns the number of bytes actually available in the write buffer.
|
|
||||||
*/
|
|
||||||
static inline int uart_txfifo_wait(int uart_num, int min_count) {
|
|
||||||
int count;
|
|
||||||
do {
|
|
||||||
count = UART_FIFO_MAX - FIELD2VAL(UART_STATUS_TXFIFO_COUNT, UART(uart_num).STATUS);
|
|
||||||
} while (count < min_count);
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read a character from the UART. Block until a character is available for
|
|
||||||
* reading.
|
|
||||||
*
|
|
||||||
* Returns the character read.
|
|
||||||
*/
|
|
||||||
static inline int uart_getc(int uart_num) {
|
|
||||||
uart_rxfifo_wait(uart_num, 1);
|
|
||||||
return UART(uart_num).FIFO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read a character from the UART. Does not block.
|
|
||||||
*
|
|
||||||
* Returns the read character on success. If the RX FIFO is currently empty
|
|
||||||
* (nothing to read), returns -1.
|
|
||||||
*/
|
|
||||||
static inline int uart_getc_nowait(int uart_num) {
|
|
||||||
if (FIELD2VAL(UART_STATUS_RXFIFO_COUNT, UART(uart_num).STATUS)) {
|
|
||||||
return UART(uart_num).FIFO;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write a character to the UART. Blocks if necessary until there is space in
|
|
||||||
* the TX FIFO.
|
|
||||||
*/
|
|
||||||
static inline void uart_putc(int uart_num, char c) {
|
|
||||||
uart_txfifo_wait(uart_num, 1);
|
|
||||||
UART(uart_num).FIFO = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write a character to the UART. Does not block.
|
|
||||||
*
|
|
||||||
* Returns 0 on success. If there is no space currently in the TX FIFO,
|
|
||||||
* returns -1.
|
|
||||||
*/
|
|
||||||
static inline int uart_putc_nowait(int uart_num, char c) {
|
|
||||||
if (FIELD2VAL(UART_STATUS_TXFIFO_COUNT, UART(uart_num).STATUS) < UART_FIFO_MAX) {
|
|
||||||
UART(uart_num).FIFO = c;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clear (discard) all pending write data in the TX FIFO */
|
|
||||||
static inline void uart_clear_txfifo(int uart_num) {
|
|
||||||
uint32_t conf = UART(uart_num).CONF0;
|
|
||||||
UART(uart_num).CONF0 = conf | UART_CONF0_TXFIFO_RESET;
|
|
||||||
UART(uart_num).CONF0 = conf & ~UART_CONF0_TXFIFO_RESET;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clear (discard) all pending read data in the RX FIFO */
|
|
||||||
static inline void uart_clear_rxfifo(int uart_num) {
|
|
||||||
uint32_t conf = UART(uart_num).CONF0;
|
|
||||||
UART(uart_num).CONF0 = conf | UART_CONF0_RXFIFO_RESET;
|
|
||||||
UART(uart_num).CONF0 = conf & ~UART_CONF0_RXFIFO_RESET;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait until all pending output in the UART's TX FIFO has been sent out the
|
|
||||||
* serial port. */
|
|
||||||
static inline void uart_flush_txfifo(int uart_num) {
|
|
||||||
while (FIELD2VAL(UART_STATUS_TXFIFO_COUNT, UART(uart_num).STATUS) != 0) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Flush all pending input in the UART's RX FIFO
|
|
||||||
* (this is just another name for uart_clear_rxfifo)
|
|
||||||
*/
|
|
||||||
static inline void uart_flush_rxfifo(int uart_num) {
|
|
||||||
uart_clear_rxfifo(uart_num);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set uart baud rate to the desired value */
|
|
||||||
static inline void uart_set_baud(int uart_num, int bps)
|
|
||||||
{
|
|
||||||
uint32_t divider = APB_CLK_FREQ / bps;
|
|
||||||
UART(uart_num).CLOCK_DIVIDER = divider;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns the current baud rate for the UART */
|
|
||||||
static inline int uart_get_baud(int uart_num)
|
|
||||||
{
|
|
||||||
return APB_CLK_FREQ / FIELD2VAL(UART_CLOCK_DIVIDER_VALUE, UART(uart_num).CLOCK_DIVIDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set uart stop bit count to the desired value */
|
|
||||||
static inline void uart_set_stopbits(int uart_num, UART_StopBits stop_bits) {
|
|
||||||
UART(uart_num).CONF0 = SET_FIELD(UART(uart_num).CONF0, UART_CONF0_STOP_BITS, stop_bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns the current stopbit count for the UART */
|
|
||||||
static inline UART_StopBits uart_get_stopbits(int uart_num) {
|
|
||||||
return (UART_StopBits)(FIELD2VAL(UART_CONF0_STOP_BITS, UART(uart_num).CONF0));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set if uart parity bit should be enabled */
|
|
||||||
static inline void uart_set_parity_enabled(int uart_num, bool enable) {
|
|
||||||
if(enable)
|
|
||||||
UART(uart_num).CONF0 = SET_MASK_BITS(UART(uart_num).CONF0, UART_CONF0_PARITY_ENABLE);
|
|
||||||
else
|
|
||||||
UART(uart_num).CONF0 = CLEAR_MASK_BITS(UART(uart_num).CONF0, UART_CONF0_PARITY_ENABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set uart parity bit type */
|
|
||||||
static inline void uart_set_parity(int uart_num, UART_Parity parity) {
|
|
||||||
if(parity == UART_PARITY_EVEN)
|
|
||||||
UART(uart_num).CONF0 = CLEAR_MASK_BITS(UART(uart_num).CONF0, UART_CONF0_PARITY);
|
|
||||||
else
|
|
||||||
UART(uart_num).CONF0 = SET_MASK_BITS(UART(uart_num).CONF0, UART_CONF0_PARITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns if parity bit is currently enabled for UART uart_num */
|
|
||||||
static inline bool uart_get_parity_enabled(int uart_num) {
|
|
||||||
return ((UART(uart_num).CONF0 & UART_CONF0_PARITY_ENABLE) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns the current parity bit type for UART uart_num (also if parity bit is not enabled) */
|
|
||||||
static inline UART_Parity uart_get_parity(int uart_num) {
|
|
||||||
return (UART_Parity)((UART(uart_num).CONF0 & UART_CONF0_PARITY) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set uart data bits length to the desired value */
|
|
||||||
static inline void uart_set_byte_length(int uart_num, UART_ByteLength byte_length) {
|
|
||||||
UART(uart_num).CONF0 = SET_FIELD(UART(uart_num).CONF0, UART_CONF0_BYTE_LEN, byte_length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns the current data bits length for the UART */
|
|
||||||
static inline UART_ByteLength uart_get_byte_length(int uart_num) {
|
|
||||||
return (UART_ByteLength)(FIELD2VAL(UART_CONF0_BYTE_LEN, UART(uart_num).CONF0));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* _ESP_UART_H */
|
|
|
@ -50,25 +50,6 @@ struct UART_REGS {
|
||||||
|
|
||||||
_Static_assert(sizeof(struct UART_REGS) == 0x80, "UART_REGS is the wrong size");
|
_Static_assert(sizeof(struct UART_REGS) == 0x80, "UART_REGS is the wrong size");
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
UART_STOPBITS_0 = 0b00,
|
|
||||||
UART_STOPBITS_1 = 0b01,
|
|
||||||
UART_STOPBITS_1_5 = 0b10,
|
|
||||||
UART_STOPBITS_2 = 0b11
|
|
||||||
} UART_StopBits;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
UART_PARITY_EVEN = 0b0,
|
|
||||||
UART_PARITY_ODD = 0b1
|
|
||||||
} UART_Parity;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
UART_BYTELENGTH_5 = 0b00,
|
|
||||||
UART_BYTELENGTH_6 = 0b01,
|
|
||||||
UART_BYTELENGTH_7 = 0b10,
|
|
||||||
UART_BYTELENGTH_8 = 0b11,
|
|
||||||
} UART_ByteLength;
|
|
||||||
|
|
||||||
/* Details for FIFO register */
|
/* Details for FIFO register */
|
||||||
|
|
||||||
#define UART_FIFO_DATA_M 0x000000ff
|
#define UART_FIFO_DATA_M 0x000000ff
|
||||||
|
@ -172,7 +153,7 @@ typedef enum {
|
||||||
#define UART_CONF0_BYTE_LEN_M 0x00000003
|
#define UART_CONF0_BYTE_LEN_M 0x00000003
|
||||||
#define UART_CONF0_BYTE_LEN_S 2
|
#define UART_CONF0_BYTE_LEN_S 2
|
||||||
#define UART_CONF0_PARITY_ENABLE BIT(1)
|
#define UART_CONF0_PARITY_ENABLE BIT(1)
|
||||||
#define UART_CONF0_PARITY BIT(0) //where 0 means even
|
#define UART_CONF0_PARITY BIT(0) //FIXME: does this indicate odd or even?
|
||||||
|
|
||||||
/* Details for CONF1 register */
|
/* Details for CONF1 register */
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
*
|
*
|
||||||
* ESP8266 register definitions for the "wdev" region (0x3FF2xxx)
|
* ESP8266 register definitions for the "wdev" region (0x3FF2xxx)
|
||||||
*
|
*
|
||||||
* In the DPORT memory space, alongside DPORT regs. However mostly
|
|
||||||
* concerned with the WiFi hardware interface.
|
|
||||||
*
|
|
||||||
* Not compatible with ESP SDK register access code.
|
* Not compatible with ESP SDK register access code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -24,19 +21,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct WDEV_REGS {
|
struct WDEV_REGS {
|
||||||
uint32_t volatile _unknown0[768]; // 0x0000 - 0x0bfc
|
uint32_t volatile _unknown[768]; // 0x0000 - 0x0bfc
|
||||||
uint32_t volatile SYS_TIME; // 0x0c00
|
uint32_t volatile SYS_TIME; // 0x0c00
|
||||||
uint32_t volatile _unknown1[144]; // 0x0c04 - 0x0e40
|
|
||||||
uint32_t volatile HWRNG; // 0xe44 HW RNG, see http://esp8266-re.foogod.com/wiki/Random_Number_Generator
|
|
||||||
} __attribute__ (( packed ));
|
} __attribute__ (( packed ));
|
||||||
|
|
||||||
_Static_assert(sizeof(struct WDEV_REGS) == 0xe48, "WDEV_REGS is the wrong size");
|
_Static_assert(sizeof(struct WDEV_REGS) == 0xc04, "WDEV_REGS is the wrong size");
|
||||||
|
|
||||||
/* Extra paranoid check about the HWRNG address, as if this becomes
|
|
||||||
wrong there will be no obvious symptoms apart from a lack of
|
|
||||||
entropy.
|
|
||||||
*/
|
|
||||||
_Static_assert(&WDEV.HWRNG == (void*)0x3FF20E44, "HWRNG register is at wrong address");
|
|
||||||
|
|
||||||
#endif /* _ESP_WDEV_REGS_H */
|
#endif /* _ESP_WDEV_REGS_H */
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,7 @@ struct WDT_REGS {
|
||||||
uint32_t volatile CTRL; // 0x00
|
uint32_t volatile CTRL; // 0x00
|
||||||
uint32_t volatile REG1; // 0x04
|
uint32_t volatile REG1; // 0x04
|
||||||
uint32_t volatile REG2; // 0x08
|
uint32_t volatile REG2; // 0x08
|
||||||
// Current value, decrementing
|
uint32_t volatile _unused[2]; // 0x0c - 0x10
|
||||||
uint32_t volatile VAL; // 0x0c
|
|
||||||
uint32_t volatile _unused[1]; // 0x10
|
|
||||||
uint32_t volatile FEED; // 0x14
|
uint32_t volatile FEED; // 0x14
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include "common_macros.h"
|
#include "common_macros.h"
|
||||||
#include "esp/registers.h"
|
#include "esp/registers.h"
|
||||||
#include "esp/interrupts.h"
|
#include "esp/cpu.h"
|
||||||
#include "esp/iomux.h"
|
#include "esp/iomux.h"
|
||||||
#include "esp/gpio.h"
|
#include "esp/gpio.h"
|
||||||
#include "esp/timer.h"
|
#include "esp/timer.h"
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
/* flashchip.h
|
|
||||||
*
|
|
||||||
* sdk_flashchip_t structure used by the SDK and some bootrom routines
|
|
||||||
*
|
|
||||||
* This is in a separate include file because it's referenced by several other
|
|
||||||
* headers which are otherwise independent of each other.
|
|
||||||
*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (C) 2015 Alex Stewart and Angus Gratton
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _FLASHCHIP_H
|
|
||||||
#define _FLASHCHIP_H
|
|
||||||
|
|
||||||
/* SDK/bootrom uses this structure internally to account for flash size.
|
|
||||||
|
|
||||||
chip_size field is initialised during startup from the flash size
|
|
||||||
saved in the image header (on the first 8 bytes of SPI flash).
|
|
||||||
|
|
||||||
Other field are initialised to hardcoded values by the SDK.
|
|
||||||
|
|
||||||
** NOTE: This structure is passed to some bootrom routines and is therefore
|
|
||||||
fixed. Be very careful if you want to change it that you do not break
|
|
||||||
things. **
|
|
||||||
|
|
||||||
Based on RE work by @foogod at
|
|
||||||
http://esp8266-re.foogod.com/wiki/Flashchip_%28IoT_RTOS_SDK_0.9.9%29
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
uint32_t device_id;
|
|
||||||
uint32_t chip_size; /* in bytes */
|
|
||||||
uint32_t block_size; /* in bytes */
|
|
||||||
uint32_t sector_size; /* in bytes */
|
|
||||||
uint32_t page_size; /* in bytes */
|
|
||||||
uint32_t status_mask;
|
|
||||||
} sdk_flashchip_t;
|
|
||||||
|
|
||||||
extern sdk_flashchip_t sdk_flashchip;
|
|
||||||
|
|
||||||
#endif /* _FLASHCHIP_H */
|
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
#include "espressif/esp_wifi.h"
|
#include "espressif/esp_wifi.h"
|
||||||
#include "espressif/spi_flash.h"
|
#include "espressif/spi_flash.h"
|
||||||
#include "espressif/phy_info.h"
|
|
||||||
#include "etstimer.h"
|
|
||||||
#include "lwip/netif.h"
|
#include "lwip/netif.h"
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -14,134 +12,33 @@
|
||||||
// 'info' is declared in app_main.o at .bss+0x4
|
// 'info' is declared in app_main.o at .bss+0x4
|
||||||
|
|
||||||
struct sdk_info_st {
|
struct sdk_info_st {
|
||||||
ip4_addr_t softap_ipaddr; // 0x00
|
uint32_t _unknown0;
|
||||||
ip4_addr_t softap_netmask; // 0x04
|
uint32_t _unknown1;
|
||||||
ip4_addr_t softap_gw; // 0x08
|
uint32_t _unknown2;
|
||||||
ip4_addr_t sta_ipaddr; // 0x0c
|
uint8_t _unknown3[12];
|
||||||
ip4_addr_t sta_netmask; // 0x10
|
uint8_t softap_mac_addr[6];
|
||||||
ip4_addr_t sta_gw; // 0x14
|
uint8_t sta_mac_addr[6];
|
||||||
uint8_t softap_mac_addr[6]; // 0x18
|
|
||||||
uint8_t sta_mac_addr[6]; // 0x1e
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern struct sdk_info_st sdk_info;
|
||||||
|
|
||||||
struct wl_channel {
|
// 'rst_if' is declared in user_interface.o at .bss+0xfc
|
||||||
uint8_t _unknown00;
|
|
||||||
uint8_t _unknown01;
|
struct sdk_rst_if_st {
|
||||||
uint8_t _unknown02;
|
uint32_t version;
|
||||||
uint8_t _unknown03;
|
uint8_t _unknown[28];
|
||||||
uint8_t _unknown04;
|
|
||||||
uint8_t _unknown05;
|
|
||||||
uint8_t num; // eagle_auth_done
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern struct sdk_rst_if_st sdk_rst_if;
|
||||||
|
|
||||||
struct _unknown_softap2 {
|
// 'g_ic' is declared in libnet80211/ieee80211.o at .bss+0x0
|
||||||
uint32_t _unknown00;
|
// See also: http://esp8266-re.foogod.com/wiki/G_ic_(IoT_RTOS_SDK_0.9.9)
|
||||||
uint32_t _unknown04;
|
|
||||||
uint32_t _unknown08;
|
|
||||||
uint32_t _unknown0c;
|
|
||||||
uint32_t _unknown10[8]; // block copied from sdk_g_ic.s._unknown28c
|
|
||||||
uint32_t _unknown30;
|
|
||||||
uint32_t _unknown34;
|
|
||||||
uint32_t *_unknown38;
|
|
||||||
uint8_t *_unknown3c; // string copied from sdk_g_ic.s._unknown2ac
|
|
||||||
uint32_t _unknown40[29];
|
|
||||||
uint32_t _unknownb4; // 300
|
|
||||||
uint32_t _unknownb8[5];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct _unknown_softap1 {
|
|
||||||
uint32_t _unknown00;
|
|
||||||
struct _unknown_softap2 *_unknown04;
|
|
||||||
uint32_t _unknown08[4];
|
|
||||||
uint32_t *_unknown18; // result of sdk_wpa_init, dynamically allocated object.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct _unknown_wpa1 {
|
|
||||||
uint32_t _unknown00; // 1, 2, 3
|
|
||||||
uint32_t _unknown04; // 2
|
|
||||||
uint32_t _unknown08; // 10
|
|
||||||
uint32_t _unknown0c;
|
|
||||||
uint32_t _unknown10;
|
|
||||||
uint32_t _unknown14;
|
|
||||||
uint32_t _unknown18;
|
|
||||||
uint32_t _unknown1c;
|
|
||||||
uint32_t _unknown20; // 10
|
|
||||||
uint32_t _unknown24;
|
|
||||||
uint32_t _unknown28;
|
|
||||||
uint32_t _unknown2c;
|
|
||||||
uint32_t _unknown30;
|
|
||||||
uint32_t _unknown34;
|
|
||||||
uint32_t _unknown38;
|
|
||||||
uint32_t _unknown3c;
|
|
||||||
uint32_t _unknown40; // 2
|
|
||||||
uint32_t _unknown44;
|
|
||||||
uint32_t _unknown48;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct sdk_cnx_node {
|
|
||||||
uint8_t mac_addr[6];
|
|
||||||
uint8_t _unknown07[2];
|
|
||||||
|
|
||||||
uint32_t _unknown08; // eagle_auth_done
|
|
||||||
|
|
||||||
uint32_t _unknown0c[3];
|
|
||||||
|
|
||||||
int8_t _unknown18; // eagle_auth_done
|
|
||||||
int8_t _unknown19;
|
|
||||||
int8_t _unknown1a;
|
|
||||||
int8_t _unknown1b;
|
|
||||||
|
|
||||||
uint32_t _unknown1c[23];
|
|
||||||
|
|
||||||
struct wl_channel *channel; // 0x78 eagle_auth_done
|
|
||||||
|
|
||||||
uint32_t _unknown7c[8];
|
|
||||||
|
|
||||||
uint16_t _unknown9c; // ieee80211_hostap. increases by one one each timer func called.
|
|
||||||
uint16_t _unknown9e;
|
|
||||||
|
|
||||||
uint32_t _unknowna0[17];
|
|
||||||
|
|
||||||
void *_unknowne4;
|
|
||||||
|
|
||||||
uint8_t _unknowne8; //
|
|
||||||
uint8_t _unknowne9; // ppInstallKey
|
|
||||||
int8_t _unknownea;
|
|
||||||
int8_t _unknowneb;
|
|
||||||
|
|
||||||
uint32_t _unknownec[7];
|
|
||||||
|
|
||||||
uint32_t _unknown108; // hostap_handle_timer count
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct sdk_g_ic_netif_info {
|
struct sdk_g_ic_netif_info {
|
||||||
struct netif *netif; // 0x00
|
struct netif *netif;
|
||||||
ETSTimer timer; // 0x04 - 0x20
|
//TODO: rest of this structure is unknown.
|
||||||
uint8_t _unknown20[28]; // 0x20 - 0x3c
|
|
||||||
uint32_t _unknown3c; // 0x3c (referenced by sdk_wifi_station_disconnect)
|
|
||||||
uint8_t _unknown40[6]; // 0x40 - 0x46
|
|
||||||
uint8_t _unknown46[2]; // 0x46 - 0x47
|
|
||||||
uint32_t _unknown48; // 0x48
|
|
||||||
uint8_t _unknown4c; // 0x4c
|
|
||||||
uint8_t _unknown4d[59]; // 0x4d - 0x88
|
|
||||||
struct sdk_cnx_node *_unknown88; // 0x88
|
|
||||||
uint32_t _unknown8c; // 0x8c
|
|
||||||
struct sdk_cnx_node *cnx_nodes[6]; // 0x90 - 0xa8
|
|
||||||
uint8_t _unknowna8[12]; // 0xa8 - 0xb4
|
|
||||||
struct _unknown_softap1 *_unknownb4;
|
|
||||||
uint8_t statusb8; // 0xb8 (arg of sta_status_set)
|
|
||||||
uint8_t statusb9; // 0xb9 (compared to arg of sta_status_set)
|
|
||||||
uint8_t connect_status; // 0xba (result of wifi_station_get_connect_status)
|
|
||||||
uint8_t started; // 0xbb (referenced by sdk_wifi_station_start / sdk_wifi_station_stop)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// This is the portion of g_ic which is not loaded/saved to the flash ROM, and
|
// This is the portion of g_ic which is not loaded/saved to the flash ROM, and
|
||||||
// starts out zeroed on every boot.
|
// starts out zeroed on every boot.
|
||||||
struct sdk_g_ic_volatile_st {
|
struct sdk_g_ic_volatile_st {
|
||||||
|
@ -167,11 +64,9 @@ struct sdk_g_ic_volatile_st {
|
||||||
uint8_t _unknown7e;
|
uint8_t _unknown7e;
|
||||||
uint8_t _unknown7f;
|
uint8_t _unknown7f;
|
||||||
|
|
||||||
uint32_t _unknown80;
|
uint8_t _unknown80[204];
|
||||||
|
|
||||||
uint32_t _unknown84[50]; // wifi_softap_start, channels.
|
void *_unknown14c;
|
||||||
|
|
||||||
void * volatile _unknown14c; // wifi_softap_start, current channel, arg to ieee80211_chan2ieee
|
|
||||||
|
|
||||||
uint8_t _unknown150[20];
|
uint8_t _unknown150[20];
|
||||||
|
|
||||||
|
@ -186,9 +81,10 @@ struct sdk_g_ic_volatile_st {
|
||||||
|
|
||||||
void *_unknown180;
|
void *_unknown180;
|
||||||
void *_unknown184;
|
void *_unknown184;
|
||||||
struct station_info *station_info_head;
|
struct sdk_station_info *station_info_head;
|
||||||
struct station_info *station_info_tail;
|
struct sdk_station_info *station_info_tail;
|
||||||
void *_unknown190[2]; // cnx_sta_leave
|
uint32_t _unknown190;
|
||||||
|
uint32_t _unknown194;
|
||||||
|
|
||||||
uint8_t _unknown198[40];
|
uint8_t _unknown198[40];
|
||||||
|
|
||||||
|
@ -207,10 +103,9 @@ struct sdk_g_ic_volatile_st {
|
||||||
uint8_t _unknown1d5[3];
|
uint8_t _unknown1d5[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct sdk_g_ic_unk0_st {
|
||||||
struct sdk_g_ic_ssid_with_length {
|
uint32_t _unknown1e4;
|
||||||
uint32_t ssid_length; // 0x1e4 sdk_wpa_config_profile
|
uint8_t _unknown1e8[32];
|
||||||
uint8_t ssid[32]; // 0x1e8 Station ssid. Null terminated string.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is the portion of g_ic which is loaded/saved to the flash ROM, and thus
|
// This is the portion of g_ic which is loaded/saved to the flash ROM, and thus
|
||||||
|
@ -223,46 +118,40 @@ struct sdk_g_ic_saved_st {
|
||||||
uint8_t wifi_mode;
|
uint8_t wifi_mode;
|
||||||
uint8_t wifi_led_enable;
|
uint8_t wifi_led_enable;
|
||||||
uint8_t wifi_led_gpio;
|
uint8_t wifi_led_gpio;
|
||||||
uint8_t wifi_led_state; // 0 or 1.
|
uint8_t _unknown1e3;
|
||||||
|
|
||||||
// Current station ap config ssid and length.
|
struct sdk_g_ic_unk0_st _unknown1e4;
|
||||||
struct sdk_g_ic_ssid_with_length sta_ssid; // 0x1e4
|
|
||||||
|
|
||||||
uint8_t _unknown208;
|
uint8_t _unknown208;
|
||||||
uint8_t _unknown209; // sdk_wpa_config_profile
|
uint8_t _unknown209;
|
||||||
uint8_t _unknown20a; // sdk_wpa_config_profile
|
uint8_t _unknown20a;
|
||||||
uint8_t _unknown20b;
|
uint8_t _unknown20b;
|
||||||
uint8_t _unknown20c; // sdk_wpa_config_profile
|
uint8_t _unknown20c;
|
||||||
uint8_t _unknown20d;
|
uint8_t _unknown20d;
|
||||||
uint8_t _unknown20e;
|
uint8_t _unknown20e;
|
||||||
uint8_t sta_password[64]; // 0x20f Null terminated string.
|
uint8_t _unknown20f[64];
|
||||||
uint8_t _unknown24f;
|
uint8_t _unknown24f;
|
||||||
|
|
||||||
uint8_t _unknown250[49];
|
uint8_t _unknown250[49];
|
||||||
|
|
||||||
uint8_t sta_bssid_set; // 0x281 One if bssid is used, otherwise zero.
|
uint8_t _unknown281;
|
||||||
|
|
||||||
uint8_t sta_bssid[6]; // 0x282
|
uint8_t _unknown282[6];
|
||||||
|
|
||||||
uint16_t _unknown288;
|
uint32_t _unknown288;
|
||||||
uint16_t _unknown28a;
|
|
||||||
uint8_t _unknown28c;
|
uint8_t _unknown28c;
|
||||||
|
|
||||||
uint8_t _unknown28d[21];
|
uint8_t _unknown28d[31];
|
||||||
|
|
||||||
uint8_t _unknown2a0; // used in dhcp_bind_check wpa_main.o
|
uint8_t _unknown2ac[64];
|
||||||
|
|
||||||
uint8_t _unknown2a1[9];
|
|
||||||
|
|
||||||
char _unknown2ac[64]; // string.
|
|
||||||
uint8_t _unknonwn2ec;
|
uint8_t _unknonwn2ec;
|
||||||
|
|
||||||
uint8_t _unknown2ed[32];
|
uint8_t _unknown2ed[32];
|
||||||
|
|
||||||
uint8_t _unknown30d; // result of ieee80211_chan2ieee
|
uint8_t _unknown30d;
|
||||||
uint8_t _unknown30e;
|
uint8_t _unknown30e;
|
||||||
uint8_t _unknown30f;
|
uint8_t _unknown30f;
|
||||||
uint8_t _unknown310; // count of entries in the softap cnx_node array, less two.
|
uint8_t _unknown310;
|
||||||
|
|
||||||
uint8_t _unknown311[3];
|
uint8_t _unknown311[3];
|
||||||
|
|
||||||
|
@ -296,20 +185,7 @@ struct sdk_g_ic_st {
|
||||||
struct sdk_g_ic_saved_st s; // 0x1d8 - 0x548
|
struct sdk_g_ic_saved_st s; // 0x1d8 - 0x548
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern struct sdk_g_ic_st sdk_g_ic;
|
||||||
|
|
||||||
struct esf_buf {
|
|
||||||
struct pbuf *pbuf1; // 0x00
|
|
||||||
struct pbuf *pbuf2; // 0x04
|
|
||||||
uint32_t *_unknown8_; // 0x08
|
|
||||||
uint32_t *_unknownc_; // 0x0c
|
|
||||||
uint8_t *frame; // 0x10 IEEE-802.11 payload data?
|
|
||||||
uint16_t _unknown14_; // 0x14
|
|
||||||
uint16_t length; // 0x16
|
|
||||||
uint32_t *_unknown18_; // 0x18
|
|
||||||
struct esf_buf *next; // 0x1c Free list.
|
|
||||||
void *extra; // 0x20
|
|
||||||
};
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// The above structures all refer to data regions outside our control, and a
|
// The above structures all refer to data regions outside our control, and a
|
||||||
|
@ -320,60 +196,37 @@ struct esf_buf {
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
_Static_assert(sizeof(struct sdk_info_st) == 0x24, "info_st is the wrong size!");
|
_Static_assert(sizeof(struct sdk_info_st) == 0x24, "info_st is the wrong size!");
|
||||||
_Static_assert(offsetof(struct sdk_info_st, sta_mac_addr) == 0x1e, "bad struct");
|
_Static_assert(sizeof(struct sdk_rst_if_st) == 0x20, "sdk_rst_if_st is the wrong size!");
|
||||||
|
|
||||||
_Static_assert(offsetof(struct wl_channel, num) == 0x06, "bad struct");
|
|
||||||
|
|
||||||
_Static_assert(sizeof(struct _unknown_softap2) == 0xcc, "_unknown_softap2 is the wrong size!");
|
|
||||||
_Static_assert(offsetof(struct _unknown_softap2, _unknownb8) == 0xb8, "bad struct");
|
|
||||||
|
|
||||||
_Static_assert(sizeof(struct _unknown_softap1) == 0x1c, "_unknown_softap1 is the wrong size!");
|
|
||||||
_Static_assert(offsetof(struct _unknown_softap1, _unknown18) == 0x18, "bad struct");
|
|
||||||
|
|
||||||
_Static_assert(sizeof(struct _unknown_wpa1) == 0x4c, "_unknown_wpa1 is the wrong size!");
|
|
||||||
_Static_assert(offsetof(struct _unknown_wpa1, _unknown48) == 0x48, "bad struct");
|
|
||||||
|
|
||||||
_Static_assert(offsetof(struct sdk_cnx_node, channel) == 0x78, "bad struct");
|
|
||||||
_Static_assert(offsetof(struct sdk_cnx_node, _unknown108) == 0x108, "bad struct");
|
|
||||||
|
|
||||||
_Static_assert(offsetof(struct sdk_g_ic_netif_info, started) == 0xbb, "bad struct");
|
|
||||||
|
|
||||||
_Static_assert(sizeof(struct sdk_g_ic_volatile_st) == 0x1d8, "sdk_g_ic_volatile_st is the wrong size!");
|
_Static_assert(sizeof(struct sdk_g_ic_volatile_st) == 0x1d8, "sdk_g_ic_volatile_st is the wrong size!");
|
||||||
_Static_assert(offsetof(struct sdk_g_ic_volatile_st, _unknown1d5) == 0x1d5, "bad struct");
|
|
||||||
|
|
||||||
_Static_assert(sizeof(struct sdk_g_ic_saved_st) == 0x370, "sdk_g_ic_saved_st is the wrong size!");
|
_Static_assert(sizeof(struct sdk_g_ic_saved_st) == 0x370, "sdk_g_ic_saved_st is the wrong size!");
|
||||||
_Static_assert(offsetof(struct sdk_g_ic_saved_st, sta_ssid) == 0x1e4 - 0x1d8, "bad struct");
|
|
||||||
_Static_assert(offsetof(struct sdk_g_ic_saved_st, _unknown546) == 0x546 - 0x1d8, "bad struct");
|
|
||||||
|
|
||||||
_Static_assert(sizeof(struct sdk_g_ic_st) == 0x548, "sdk_g_ic_st is the wrong size!");
|
_Static_assert(sizeof(struct sdk_g_ic_st) == 0x548, "sdk_g_ic_st is the wrong size!");
|
||||||
|
|
||||||
_Static_assert(sizeof(struct esf_buf) == 0x24, "struct esf_buf: wrong size");
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
_Static_assert(offsetof(struct esf_buf, extra) == 0x20, "bad struct");
|
// Function Prototypes //
|
||||||
_Static_assert(offsetof(struct esf_buf, length) == 0x16, "bad struct");
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// The SDK access some slots in lwip structures.
|
sdk_SpiFlashOpResult sdk_SPIRead(uint32_t src_addr, uint32_t *des_addr, uint32_t size);
|
||||||
|
sdk_SpiFlashOpResult sdk_SPIWrite(uint32_t des_addr, uint32_t *src_addr, uint32_t size);
|
||||||
// The netif->state is initialized in netif_add within lwip with a struct
|
void sdk_cnx_attach(struct sdk_g_ic_st *);
|
||||||
// sdk_g_ic_netif_info, see sdk_wifi_station_start and sdk_wifi_softap_start.
|
void sdk_ets_timer_init(void);
|
||||||
// There is a known sdk read of the netif->state in ieee80211_output.o
|
void sdk_ieee80211_ifattach(struct sdk_g_ic_st *, uint8_t *);
|
||||||
// ieee80211_output_pbuf and perhaps elsewhere. The value is just passed through
|
void sdk_ieee80211_phy_init(enum sdk_phy_mode);
|
||||||
// lwip and and not used by lwip so just ensure this slot is at the expected
|
void sdk_lmacInit(void);
|
||||||
// offset.
|
void sdk_phy_disable_agc(void);
|
||||||
_Static_assert(offsetof(struct netif, state) == 4, "netif->state offset wrong!");
|
void sdk_phy_enable_agc(void);
|
||||||
|
void sdk_pm_attach(void);
|
||||||
// Some sdk uses of netif->hwaddr have been converted to source code, but many
|
void sdk_pp_attach(void);
|
||||||
// remain, but the content of this slot should not change in future versions of
|
void sdk_pp_soft_wdt_init(void);
|
||||||
// lwip, so just ensure it is at the expected offset. Note the sdk binary
|
int sdk_register_chipv6_phy(uint8_t *);
|
||||||
// libraries have been patched to move this offset from 41 to 42 to keep it
|
void sdk_sleep_reset_analog_rtcreg_8266(void);
|
||||||
// 16-bit aligned to keep lwip v2 happy.
|
uint32_t sdk_system_get_checksum(uint8_t *, uint32_t);
|
||||||
_Static_assert(offsetof(struct netif, hwaddr) == 8, "netif->hwaddr offset wrong!");
|
void sdk_system_restart_in_nmi(void);
|
||||||
|
void sdk_wDevEnableRx(void);
|
||||||
_Static_assert(offsetof(struct pbuf, esf_buf) == 16, "pbuf->esf_buf offset wrong!");
|
void sdk_wDev_Initialize(void);
|
||||||
|
void sdk_wifi_mode_set(uint8_t);
|
||||||
|
void sdk_wifi_softap_cacl_mac(uint8_t *, uint8_t *);
|
||||||
/// Misc.
|
void sdk_wifi_softap_set_default_ssid(void);
|
||||||
|
void sdk_wifi_softap_start(void);
|
||||||
err_t ethernetif_init(struct netif *netif);
|
void sdk_wifi_station_start(void);
|
||||||
void ethernetif_input(struct netif *netif, struct pbuf *p);
|
|
||||||
|
|
||||||
#endif /* _INTERNAL_SDK_STRUCTURES_H */
|
#endif /* _INTERNAL_SDK_STRUCTURES_H */
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
/**
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016 sheinz (https://github.com/sheinz)
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#ifndef __SPIFLASH_H__
|
|
||||||
#define __SPIFLASH_H__
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "common_macros.h"
|
|
||||||
|
|
||||||
#define SPI_FLASH_SECTOR_SIZE 4096
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read data from SPI flash.
|
|
||||||
*
|
|
||||||
* @param addr Address to read from. Can be not aligned.
|
|
||||||
* @param buf Buffer to read to. Doesn't have to be aligned.
|
|
||||||
* @param size Size of data to read. Buffer size must be >= than data size.
|
|
||||||
*
|
|
||||||
* @return true if success, otherwise false
|
|
||||||
*/
|
|
||||||
bool IRAM spiflash_read(uint32_t addr, uint8_t *buf, uint32_t size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write data to SPI flash.
|
|
||||||
*
|
|
||||||
* @param addr Address to write to. Can be not aligned.
|
|
||||||
* @param buf Buffer of data to write to flash. Doesn't have to be aligned.
|
|
||||||
* @param size Size of data to write. Buffer size must be >= than data size.
|
|
||||||
*
|
|
||||||
* @return true if success, otherwise false
|
|
||||||
*/
|
|
||||||
bool IRAM spiflash_write(uint32_t addr, uint8_t *buf, uint32_t size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Erase a sector.
|
|
||||||
*
|
|
||||||
* @param addr Address of sector to erase. Must be sector aligned.
|
|
||||||
*
|
|
||||||
* @return true if success, otherwise false
|
|
||||||
*/
|
|
||||||
bool IRAM spiflash_erase_sector(uint32_t addr);
|
|
||||||
|
|
||||||
#endif // __SPIFLASH_H__
|
|
|
@ -1,45 +0,0 @@
|
||||||
/*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (C) 2016 Oto Petrik <oto.petrik@gmail.com>
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _STDOUT_REDIRECT_H_
|
|
||||||
#define _STDOUT_REDIRECT_H_
|
|
||||||
|
|
||||||
#include <sys/reent.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef ssize_t _WriteFunction(struct _reent *r, int fd, const void *ptr, size_t len);
|
|
||||||
|
|
||||||
/** Set implementation of write syscall for stdout.
|
|
||||||
*
|
|
||||||
* Use this function to redirect stdout for further processing (save to file, send over network).
|
|
||||||
* It may be good idea to save result of `get_write_stdout()` beforehand and call
|
|
||||||
* it at the end of the supplied function.
|
|
||||||
*
|
|
||||||
* NOTE: use NULL to reset to default implementation.
|
|
||||||
*
|
|
||||||
* @param[in] f New code to handle stdout output
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void set_write_stdout(_WriteFunction *f);
|
|
||||||
|
|
||||||
/** Get current implementation of write syscall for stdout.
|
|
||||||
*
|
|
||||||
* Save returned value before calling `set_write_stdout`, it allows for chaining
|
|
||||||
* multiple independent handlers.
|
|
||||||
*
|
|
||||||
* @returns current stdout handler
|
|
||||||
*/
|
|
||||||
_WriteFunction *get_write_stdout();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* _STDOUT_REDIRECT_H_ */
|
|
|
@ -1,467 +0,0 @@
|
||||||
/*
|
|
||||||
* Part of esp-open-rtos
|
|
||||||
* Copyright (C) 2016 Alex Stewart
|
|
||||||
* BSD Licensed as described in the file LICENSE
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _SYSPARAM_H_
|
|
||||||
#define _SYSPARAM_H_
|
|
||||||
|
|
||||||
#include <esp/types.h>
|
|
||||||
|
|
||||||
#ifndef DEFAULT_SYSPARAM_SECTORS
|
|
||||||
#define DEFAULT_SYSPARAM_SECTORS 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** @file sysparam.h
|
|
||||||
*
|
|
||||||
* Read/write "system parameters" to persistent flash.
|
|
||||||
*
|
|
||||||
* System parameters are stored as key/value pairs. Keys are string values
|
|
||||||
* between 1 and 65535 characters long. Values can be any data up to 65535
|
|
||||||
* bytes in length (but are most commonly also text strings). Up to 126 key/
|
|
||||||
* value pairs can be stored at a time.
|
|
||||||
*
|
|
||||||
* Keys and values are stored in flash using a progressive list structure
|
|
||||||
* which allows space-efficient storage and minimizes flash erase cycles,
|
|
||||||
* improving write speed and increasing the lifespan of the flash memory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** Status codes returned by all sysparam functions
|
|
||||||
*
|
|
||||||
* Error codes (`SYSPARAM_ERR_*`) all have values less than zero, and can be
|
|
||||||
* returned by any function. Values greater than zero are non-error status
|
|
||||||
* codes which may be returned by some functions to indicate various results.
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
SYSPARAM_OK = 0, ///< Success
|
|
||||||
SYSPARAM_NOTFOUND = 1, ///< Entry not found matching criteria
|
|
||||||
SYSPARAM_PARSEFAILED = 2, ///< Unable to parse retrieved value
|
|
||||||
SYSPARAM_ERR_NOINIT = -1, ///< sysparam_init() must be called first
|
|
||||||
SYSPARAM_ERR_BADVALUE = -2, ///< One or more arguments were invalid
|
|
||||||
SYSPARAM_ERR_FULL = -3, ///< No space left in sysparam area (or too many keys in use)
|
|
||||||
SYSPARAM_ERR_IO = -4, ///< I/O error reading/writing flash
|
|
||||||
SYSPARAM_ERR_CORRUPT = -5, ///< Sysparam region has bad/corrupted data
|
|
||||||
SYSPARAM_ERR_NOMEM = -6, ///< Unable to allocate memory
|
|
||||||
} sysparam_status_t;
|
|
||||||
|
|
||||||
/** Structure used by sysparam_iter_next() to keep track of its current state
|
|
||||||
* and return its results. This should be initialized by calling
|
|
||||||
* sysparam_iter_start() and cleaned up afterward by calling
|
|
||||||
* sysparam_iter_end().
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
char *key;
|
|
||||||
uint8_t *value;
|
|
||||||
size_t key_len;
|
|
||||||
size_t value_len;
|
|
||||||
bool binary;
|
|
||||||
size_t bufsize;
|
|
||||||
struct sysparam_context *ctx;
|
|
||||||
} sysparam_iter_t;
|
|
||||||
|
|
||||||
/** Initialize sysparam and set up the current area of flash to use.
|
|
||||||
*
|
|
||||||
* This must be called (and return successfully) before any other sysparam
|
|
||||||
* routines (except sysparam_create_area()) are called.
|
|
||||||
*
|
|
||||||
* This should normally be taken care of automatically on boot by the OS
|
|
||||||
* startup routines. It may be necessary to call it specially, however, if
|
|
||||||
* the normal initialization failed, or after calling sysparam_create_area()
|
|
||||||
* to reformat the current area.
|
|
||||||
*
|
|
||||||
* This routine will start at `base_addr` and scan all sectors up to
|
|
||||||
* `top_addr` looking for a valid sysparam area. If `top_addr` is zero (or
|
|
||||||
* equal to `base_addr`, then only the sector at `base_addr` will be checked.
|
|
||||||
*
|
|
||||||
* @param[in] base_addr The flash address to start looking for the start of
|
|
||||||
* the (already present) sysparam area
|
|
||||||
* @param[in] top_addr The flash address to stop looking for the sysparam
|
|
||||||
* area
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Initialization successful.
|
|
||||||
* @retval ::SYSPARAM_NOTFOUND The specified address does not appear to
|
|
||||||
* contain a sysparam area. It may be
|
|
||||||
* necessary to call sysparam_create_area() to
|
|
||||||
* create one first.
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_init(uint32_t base_addr, uint32_t top_addr);
|
|
||||||
|
|
||||||
/** Create a new sysparam area in flash at the specified address.
|
|
||||||
*
|
|
||||||
* By default, this routine will scan the specified area to make sure it
|
|
||||||
* appears to be empty (i.e. all 0xFF bytes) before setting it up as a new
|
|
||||||
* sysparam area. If there appears to be other data already present, it will
|
|
||||||
* not overwrite it. Setting `force` to `true` will cause it to clobber any
|
|
||||||
* existing data instead.
|
|
||||||
*
|
|
||||||
* @param[in] base_addr The flash address at which it should start
|
|
||||||
* (must be a multiple of the sector size)
|
|
||||||
* @param[in] num_sectors The number of flash sectors to use for the sysparam
|
|
||||||
* area. This should be an even number >= 2. Note
|
|
||||||
* that the actual amount of useable parameter space
|
|
||||||
* will be roughly half this amount.
|
|
||||||
* @param[in] force Proceed even if the space does not appear to be empty
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Area (re)created successfully.
|
|
||||||
* @retval ::SYSPARAM_NOTFOUND `force` was not specified, and the area at
|
|
||||||
* `base_addr` appears to have other data. No
|
|
||||||
* action taken.
|
|
||||||
* @retval ::SYSPARAM_ERR_BADVALUE The `num_sectors` value was not even (or
|
|
||||||
* was zero)
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*
|
|
||||||
* Note: This routine can create a sysparam area in another location than the
|
|
||||||
* one currently being used, but does not change which area is currently used
|
|
||||||
* (you will need to call sysparam_init() again if you want to do that). If
|
|
||||||
* you reformat the area currently being used, you will also need to call
|
|
||||||
* sysparam_init() again afterward before you will be able to continue using
|
|
||||||
* it.
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_create_area(uint32_t base_addr, uint16_t num_sectors, bool force);
|
|
||||||
|
|
||||||
/** Get the start address and size of the currently active sysparam area
|
|
||||||
*
|
|
||||||
* Fills in `base_addr` and `num_sectors` with the location and size of the
|
|
||||||
* currently active sysparam area. The returned values correspond to the
|
|
||||||
* arguments passed to the sysparam_create_area() call when the area was
|
|
||||||
* originally created.
|
|
||||||
*
|
|
||||||
* @param[out] base_addr The flash address at which the sysparam area starts
|
|
||||||
* @param[out] num_sectors The number of flash sectors used by the sysparam
|
|
||||||
* area
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Completed successfully
|
|
||||||
* @retval ::SYSPARAM_ERR_NOINIT No current sysparam area is active
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_get_info(uint32_t *base_addr, uint32_t *num_sectors);
|
|
||||||
|
|
||||||
/** Compact the sysparam area.
|
|
||||||
*
|
|
||||||
* This also flattens the log.
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Completed successfully
|
|
||||||
* @retval ::SYSPARAM_ERR_NOINIT No current sysparam area is active
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_compact();
|
|
||||||
|
|
||||||
/** Get the value associated with a key
|
|
||||||
*
|
|
||||||
* This is the core "get value" function. It will retrieve the value for the
|
|
||||||
* specified key in a freshly malloc()'d buffer and return it. Raw values can
|
|
||||||
* contain any data (including zero bytes), so the `actual_length` parameter
|
|
||||||
* should be used to determine the length of the data in the buffer.
|
|
||||||
*
|
|
||||||
* It is up to the caller to free() the returned buffer when done using it.
|
|
||||||
*
|
|
||||||
* Note: If the status result is anything other than ::SYSPARAM_OK, the value
|
|
||||||
* in `destptr` is not changed. This means it is possible to set a default
|
|
||||||
* value before calling this function which will be left as-is if a sysparam
|
|
||||||
* value could not be successfully read.
|
|
||||||
*
|
|
||||||
* @param[in] key Key name (zero-terminated string)
|
|
||||||
* @param[out] destptr Pointer to a location to hold the address of the
|
|
||||||
* returned data buffer
|
|
||||||
* @param[out] actual_length Pointer to a location to hold the length of the
|
|
||||||
* returned data buffer (may be NULL)
|
|
||||||
* @param[out] is_binary Pointer to a bool to hold whether the returned
|
|
||||||
* value is "binary" or not (may be NULL)
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Value successfully retrieved.
|
|
||||||
* @retval ::SYSPARAM_NOTFOUND Key/value not found. No buffer returned.
|
|
||||||
* @retval ::SYSPARAM_ERR_NOINIT sysparam_init() must be called first
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_get_data(const char *key, uint8_t **destptr, size_t *actual_length, bool *is_binary);
|
|
||||||
|
|
||||||
/** Get the value associated with a key (static value buffer)
|
|
||||||
*
|
|
||||||
* This performs the same function as sysparam_get_data() but without
|
|
||||||
* allocating memory for the result value. It can thus be used before the heap
|
|
||||||
* has been configured or in other cases where using the heap would be a
|
|
||||||
* problem (i.e. in an OOM handler, etc). It requires that the caller pass in
|
|
||||||
* a suitably sized buffer for the value to be read (if the supplied buffer is
|
|
||||||
* not large enough, the returned value will be truncated and the full required
|
|
||||||
* length will be returned in `actual_length`).
|
|
||||||
*
|
|
||||||
* @param[in] key Key name (zero-terminated string)
|
|
||||||
* @param[in] dest Pointer to a buffer to hold the returned value.
|
|
||||||
* @param[in] dest_size Length of the supplied buffer in bytes.
|
|
||||||
* @param[out] actual_length Pointer to a location to hold the actual length
|
|
||||||
* of the data which was associated with the key
|
|
||||||
* (may be NULL).
|
|
||||||
* @param[out] is_binary Pointer to a bool to hold whether the returned
|
|
||||||
* value is "binary" or not (may be NULL)
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Value successfully retrieved
|
|
||||||
* @retval ::SYSPARAM_NOTFOUND Key/value not found
|
|
||||||
* @retval ::SYSPARAM_ERR_NOINIT sysparam_init() must be called first
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM The supplied buffer is too small
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_get_data_static(const char *key, uint8_t *dest, size_t dest_size, size_t *actual_length, bool *is_binary);
|
|
||||||
|
|
||||||
/** Get the string value associated with a key
|
|
||||||
*
|
|
||||||
* This routine can be used if you know that the value in a key will (or at
|
|
||||||
* least should) be a string. It will return a zero-terminated char buffer
|
|
||||||
* containing the value retrieved.
|
|
||||||
*
|
|
||||||
* It is up to the caller to free() the returned buffer when done using it.
|
|
||||||
*
|
|
||||||
* Note: If the status result is anything other than ::SYSPARAM_OK, the value
|
|
||||||
* in `destptr` is not changed. This means it is possible to set a default
|
|
||||||
* value before calling this function which will be left as-is if a sysparam
|
|
||||||
* value could not be successfully read.
|
|
||||||
*
|
|
||||||
* @param[in] key Key name (zero-terminated string)
|
|
||||||
* @param[out] destptr Pointer to a location to hold the address of the
|
|
||||||
* returned data buffer
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Value successfully retrieved.
|
|
||||||
* @retval ::SYSPARAM_NOTFOUND Key/value not found.
|
|
||||||
* @retval ::SYSPARAM_PARSEFAILED The retrieved value was a binary value
|
|
||||||
* @retval ::SYSPARAM_ERR_NOINIT sysparam_init() must be called first
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_get_string(const char *key, char **destptr);
|
|
||||||
|
|
||||||
/** Get the int32_t value associated with a key
|
|
||||||
*
|
|
||||||
* This routine can be used if you know that the value in a key will (or at
|
|
||||||
* least should) be an int32_t value. This is done without allocating any
|
|
||||||
* memory.
|
|
||||||
*
|
|
||||||
* Note: If the status result is anything other than ::SYSPARAM_OK, the value
|
|
||||||
* in `result` is not changed. This means it is possible to set a default
|
|
||||||
* value before calling this function which will be left as-is if a sysparam
|
|
||||||
* value could not be successfully read.
|
|
||||||
*
|
|
||||||
* @param[in] key Key name (zero-terminated string)
|
|
||||||
* @param[out] result Pointer to a location to hold returned integer value
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Value successfully retrieved.
|
|
||||||
* @retval ::SYSPARAM_NOTFOUND Key/value not found.
|
|
||||||
* @retval ::SYSPARAM_PARSEFAILED The retrieved value could not be parsed as
|
|
||||||
* an integer.
|
|
||||||
* @retval ::SYSPARAM_ERR_NOINIT sysparam_init() must be called first
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_get_int32(const char *key, int32_t *result);
|
|
||||||
|
|
||||||
/** Get the int8_t value associated with a key
|
|
||||||
*
|
|
||||||
* This routine can be used if you know that the value in a key will (or at
|
|
||||||
* least should) be a uint8_t binary value. This is done without allocating any
|
|
||||||
* memory.
|
|
||||||
*
|
|
||||||
* Note: If the status result is anything other than ::SYSPARAM_OK, the value
|
|
||||||
* in `result` is not changed. This means it is possible to set a default
|
|
||||||
* value before calling this function which will be left as-is if a sysparam
|
|
||||||
* value could not be successfully read.
|
|
||||||
*
|
|
||||||
* @param[in] key Key name (zero-terminated string)
|
|
||||||
* @param[out] result Pointer to a location to hold returned boolean value
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Value successfully retrieved.
|
|
||||||
* @retval ::SYSPARAM_NOTFOUND Key/value not found.
|
|
||||||
* @retval ::SYSPARAM_PARSEFAILED The retrieved value could not be parsed as a
|
|
||||||
* boolean setting.
|
|
||||||
* @retval ::SYSPARAM_ERR_NOINIT sysparam_init() must be called first
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_get_int8(const char *key, int8_t *result);
|
|
||||||
|
|
||||||
/** Get the boolean value associated with a key
|
|
||||||
*
|
|
||||||
* This routine can be used if you know that the value in a key will (or at
|
|
||||||
* least should) be a boolean setting. It will read the specified value as a
|
|
||||||
* text string and attempt to parse it as a boolean value.
|
|
||||||
*
|
|
||||||
* It will recognize the following (case-insensitive) strings:
|
|
||||||
* * True: "yes", "y", "true", "t", "1"
|
|
||||||
* * False: "no", "n", "false", "f", "0"
|
|
||||||
*
|
|
||||||
* Note: If the status result is anything other than ::SYSPARAM_OK, the value
|
|
||||||
* in `result` is not changed. This means it is possible to set a default
|
|
||||||
* value before calling this function which will be left as-is if a sysparam
|
|
||||||
* value could not be successfully read.
|
|
||||||
*
|
|
||||||
* @param[in] key Key name (zero-terminated string)
|
|
||||||
* @param[out] result Pointer to a location to hold returned boolean value
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Value successfully retrieved.
|
|
||||||
* @retval ::SYSPARAM_NOTFOUND Key/value not found.
|
|
||||||
* @retval ::SYSPARAM_PARSEFAILED The retrieved value could not be parsed as a
|
|
||||||
* boolean setting.
|
|
||||||
* @retval ::SYSPARAM_ERR_NOINIT sysparam_init() must be called first
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_get_bool(const char *key, bool *result);
|
|
||||||
|
|
||||||
/** Set the value associated with a key
|
|
||||||
*
|
|
||||||
* The supplied value can be any data, up to 255 bytes in length. If `value`
|
|
||||||
* is NULL or `value_len` is 0, this is treated as a request to delete any
|
|
||||||
* current entry matching `key`. This is done without allocating any memory.
|
|
||||||
*
|
|
||||||
* If `binary` is true, the data will be considered binary (unprintable) data,
|
|
||||||
* and this will be annotated in the saved entry. This does not affect the
|
|
||||||
* saving or loading process in any way, but may be used by some applications
|
|
||||||
* to (for example) print binary data differently than text entries when
|
|
||||||
* printing parameter values.
|
|
||||||
*
|
|
||||||
* @param[in] key Key name (zero-terminated string)
|
|
||||||
* @param[in] value Pointer to a buffer containing the value data
|
|
||||||
* @param[in] value_len Length of the data in the buffer
|
|
||||||
* @param[in] binary Whether the data should be considered "binary"
|
|
||||||
* (unprintable) data
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Value successfully set.
|
|
||||||
* @retval ::SYSPARAM_ERR_NOINIT sysparam_init() must be called first
|
|
||||||
* @retval ::SYSPARAM_ERR_BADVALUE Either an empty key was provided or
|
|
||||||
* value_len is too large
|
|
||||||
* @retval ::SYSPARAM_ERR_FULL No space left in sysparam area
|
|
||||||
* (or too many keys in use)
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_set_data(const char *key, const uint8_t *value, size_t value_len, bool binary);
|
|
||||||
|
|
||||||
/** Set a key's value from a string
|
|
||||||
*
|
|
||||||
* Performs the same function as sysparam_set_data(), but accepts a
|
|
||||||
* zero-terminated string value instead.
|
|
||||||
*
|
|
||||||
* @param[in] key Key name (zero-terminated string)
|
|
||||||
* @param[in] value Value to set (zero-terminated string)
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Value successfully set.
|
|
||||||
* @retval ::SYSPARAM_ERR_BADVALUE Either an empty key was provided or the
|
|
||||||
* length of `value` is too large
|
|
||||||
* @retval ::SYSPARAM_ERR_FULL No space left in sysparam area
|
|
||||||
* (or too many keys in use)
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_set_string(const char *key, const char *value);
|
|
||||||
|
|
||||||
/** Set a key's value as a number
|
|
||||||
*
|
|
||||||
* Write an int32_t binary value to the specified key. This does the inverse of
|
|
||||||
* the sysparam_get_int32() function. This is done without allocating any
|
|
||||||
* memory.
|
|
||||||
*
|
|
||||||
* @param[in] key Key name (zero-terminated string)
|
|
||||||
* @param[in] value Value to set
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Value successfully set.
|
|
||||||
* @retval ::SYSPARAM_ERR_BADVALUE An empty key was provided.
|
|
||||||
* @retval ::SYSPARAM_ERR_FULL No space left in sysparam area
|
|
||||||
* (or too many keys in use)
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_set_int32(const char *key, int32_t value);
|
|
||||||
|
|
||||||
/** Set a key's value as a number
|
|
||||||
*
|
|
||||||
* Write an int8_t binary value to the specified key. This does the inverse of
|
|
||||||
* the sysparam_get_int8() function. This is done without allocating any
|
|
||||||
* memory.
|
|
||||||
*
|
|
||||||
* @param[in] key Key name (zero-terminated string)
|
|
||||||
* @param[in] value Value to set
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Value successfully set.
|
|
||||||
* @retval ::SYSPARAM_ERR_BADVALUE An empty key was provided.
|
|
||||||
* @retval ::SYSPARAM_ERR_FULL No space left in sysparam area
|
|
||||||
* (or too many keys in use)
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_set_int8(const char *key, int8_t value);
|
|
||||||
|
|
||||||
/** Set a key's value as a boolean (yes/no) string
|
|
||||||
*
|
|
||||||
* Converts a bool value to a corresponding text string and writes it to the
|
|
||||||
* specified key. This does the inverse of the sysparam_get_bool()
|
|
||||||
* function.
|
|
||||||
*
|
|
||||||
* @param[in] key Key name (zero-terminated string)
|
|
||||||
* @param[in] value Value to set
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Value successfully set.
|
|
||||||
* @retval ::SYSPARAM_ERR_BADVALUE An empty key was provided.
|
|
||||||
* @retval ::SYSPARAM_ERR_FULL No space left in sysparam area
|
|
||||||
* (or too many keys in use)
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_set_bool(const char *key, bool value);
|
|
||||||
|
|
||||||
/** Begin iterating through all key/value pairs
|
|
||||||
*
|
|
||||||
* This function initializes a sysparam_iter_t structure to prepare it for
|
|
||||||
* iterating through the list of key/value pairs using sysparam_iter_next().
|
|
||||||
* This does not fetch any items (the first successive call to
|
|
||||||
* sysparam_iter_next() will return the first key/value in the list).
|
|
||||||
*
|
|
||||||
* NOTE: When done, you must call sysparam_iter_end() to free the resources
|
|
||||||
* associated with `iter`, or you will leak memory.
|
|
||||||
*
|
|
||||||
* @param[in] iter A pointer to a sysparam_iter_t structure to initialize
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Initialization successful
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_iter_start(sysparam_iter_t *iter);
|
|
||||||
|
|
||||||
/** Fetch the next key/value pair
|
|
||||||
*
|
|
||||||
* This will retrieve the next key and value from the sysparam area, placing
|
|
||||||
* them in `iter->key`, and `iter->value` (and updating `iter->key_len` and
|
|
||||||
* `iter->value_len`).
|
|
||||||
*
|
|
||||||
* NOTE: `iter->key` and `iter->value` are static buffers local to the `iter`
|
|
||||||
* structure, and will be overwritten with the next call to
|
|
||||||
* sysparam_iter_next() using the same `iter`. They should *not* be free()d
|
|
||||||
* after use.
|
|
||||||
*
|
|
||||||
* @param[in] iter The iterator structure to update
|
|
||||||
*
|
|
||||||
* @retval ::SYSPARAM_OK Next key/value retrieved
|
|
||||||
* @retval ::SYSPARAM_ERR_NOMEM Unable to allocate memory
|
|
||||||
* @retval ::SYSPARAM_ERR_CORRUPT Sysparam region has bad/corrupted data
|
|
||||||
* @retval ::SYSPARAM_ERR_IO I/O error reading/writing flash
|
|
||||||
*/
|
|
||||||
sysparam_status_t sysparam_iter_next(sysparam_iter_t *iter);
|
|
||||||
|
|
||||||
/** Finish iterating through keys/values
|
|
||||||
*
|
|
||||||
* Cleans up and releases resources allocated by sysparam_iter_start() /
|
|
||||||
* sysparam_iter_next().
|
|
||||||
*/
|
|
||||||
void sysparam_iter_end(sysparam_iter_t *iter);
|
|
||||||
|
|
||||||
#endif /* _SYSPARAM_H_ */
|
|
|
@ -1,9 +0,0 @@
|
||||||
/* Allows the user to set their own exception handler. */
|
|
||||||
|
|
||||||
#ifndef _USER_EXCEPTION_H
|
|
||||||
#define _USER_EXCEPTION_H
|
|
||||||
|
|
||||||
void set_user_exception_handler(void (*fn)(void));
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -11,20 +11,6 @@
|
||||||
#ifndef _XTENSA_OPS_H
|
#ifndef _XTENSA_OPS_H
|
||||||
#define _XTENSA_OPS_H
|
#define _XTENSA_OPS_H
|
||||||
|
|
||||||
/* Read stack pointer to variable.
|
|
||||||
*
|
|
||||||
* Note that the compiler will push a stack frame (minimum 16 bytes)
|
|
||||||
* in the prelude of a C function that calls any other functions.
|
|
||||||
*/
|
|
||||||
#define SP(var) asm volatile ("mov %0, a1" : "=r" (var))
|
|
||||||
|
|
||||||
/* Read the function return address to a variable.
|
|
||||||
*
|
|
||||||
* Depends on the containing function being simple enough that a0 is
|
|
||||||
* being used as a working register.
|
|
||||||
*/
|
|
||||||
#define RETADDR(var) asm volatile ("mov %0, a0" : "=r" (var))
|
|
||||||
|
|
||||||
// GCC macros for reading, writing, and exchanging Xtensa processor special
|
// GCC macros for reading, writing, and exchanging Xtensa processor special
|
||||||
// registers:
|
// registers:
|
||||||
|
|
||||||
|
@ -32,11 +18,4 @@
|
||||||
#define WSR(var, reg) asm volatile ("wsr %0, " #reg : : "r" (var));
|
#define WSR(var, reg) asm volatile ("wsr %0, " #reg : : "r" (var));
|
||||||
#define XSR(var, reg) asm volatile ("xsr %0, " #reg : "+r" (var));
|
#define XSR(var, reg) asm volatile ("xsr %0, " #reg : "+r" (var));
|
||||||
|
|
||||||
// GCC macros for performing associated "*sync" opcodes
|
|
||||||
|
|
||||||
#define ISYNC() asm volatile ( "isync" )
|
|
||||||
#define RSYNC() asm volatile ( "rsync" )
|
|
||||||
#define ESYNC() asm volatile ( "esync" )
|
|
||||||
#define DSYNC() asm volatile ( "dsync" )
|
|
||||||
|
|
||||||
#endif /* _XTENSA_OPS_H */
|
#endif /* _XTENSA_OPS_H */
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
*
|
*
|
||||||
* To have this work from initial reset, without needing an iomux call
|
* To have this work from initial reset, without needing an iomux call
|
||||||
* first, choose a pin where iomux defaults to GPIO (ie 0,2,4,5)
|
* first, choose a pin where iomux defaults to GPIO (ie 0,2,4,5)
|
||||||
*
|
|
||||||
* Current sets on=LOW, as the GPIO2 pin is active low
|
|
||||||
*/
|
*/
|
||||||
LED_GPIO=2
|
LED_GPIO=2
|
||||||
GPIO_DIR_SET = 0x6000030c
|
GPIO_DIR_SET = 0x6000030c
|
||||||
|
@ -21,11 +19,11 @@ GPIO_OUT_CLEAR = 0x60000308
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
// Turn LED on. rega, regb will be clobbered
|
// Turn LED on. rega, regb will be clobbered
|
||||||
.macro led_off rega, regb
|
.macro led_on rega, regb
|
||||||
led_op \rega, \regb, GPIO_OUT_SET
|
led_op \rega, \regb, GPIO_OUT_SET
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
// Turn LED on. rega, regb will be clobbered
|
// Turn LED off. rega, regb will be clobbered
|
||||||
.macro led_on rega, regb
|
.macro led_off rega, regb
|
||||||
led_op \rega, \regb, GPIO_OUT_CLEAR
|
led_op \rega, \regb, GPIO_OUT_CLEAR
|
||||||
.endm
|
.endm
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue