Merge branch 'master' of https://github.com/littlevgl/lv_micropython
This commit is contained in:
commit
0a86dd1f23
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -7,6 +7,7 @@
|
|||||||
*.bat text eol=crlf
|
*.bat text eol=crlf
|
||||||
|
|
||||||
# These are binary so should never be modified by git.
|
# These are binary so should never be modified by git.
|
||||||
|
*.a binary
|
||||||
*.png binary
|
*.png binary
|
||||||
*.jpg binary
|
*.jpg binary
|
||||||
*.dxf binary
|
*.dxf binary
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,6 +19,7 @@
|
|||||||
# VIM Swap Files
|
# VIM Swap Files
|
||||||
######################
|
######################
|
||||||
*.swp
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
# VIM Session Files
|
# VIM Session Files
|
||||||
######################
|
######################
|
||||||
@ -27,6 +28,7 @@ Session.vim
|
|||||||
# CTags files
|
# CTags files
|
||||||
######################
|
######################
|
||||||
tags
|
tags
|
||||||
|
TAGS
|
||||||
|
|
||||||
# Build directory
|
# Build directory
|
||||||
######################
|
######################
|
||||||
|
|||||||
28
.travis.yml
28
.travis.yml
@ -1,4 +1,5 @@
|
|||||||
# global options
|
# global options
|
||||||
|
dist: xenial
|
||||||
language:
|
language:
|
||||||
- c
|
- c
|
||||||
compiler:
|
compiler:
|
||||||
@ -23,14 +24,16 @@ jobs:
|
|||||||
env: NAME="stm32 port build"
|
env: NAME="stm32 port build"
|
||||||
install:
|
install:
|
||||||
# need newer gcc version for Cortex-M7 support
|
# need newer gcc version for Cortex-M7 support
|
||||||
- sudo add-apt-repository -y ppa:terry.guo/gcc-arm-embedded
|
- sudo add-apt-repository -y ppa:team-gcc-arm-embedded/ppa
|
||||||
- sudo apt-get update -qq || true
|
- sudo apt-get update -qq || true
|
||||||
- sudo apt-get install --allow-unauthenticated gcc-arm-none-eabi
|
- sudo apt-get install gcc-arm-embedded
|
||||||
|
- sudo apt-get install libnewlib-arm-none-eabi
|
||||||
- arm-none-eabi-gcc --version
|
- arm-none-eabi-gcc --version
|
||||||
script:
|
script:
|
||||||
- make ${MAKEOPTS} -C mpy-cross
|
- make ${MAKEOPTS} -C mpy-cross
|
||||||
- make ${MAKEOPTS} -C ports/stm32
|
- make ${MAKEOPTS} -C ports/stm32
|
||||||
- make ${MAKEOPTS} -C ports/stm32 BOARD=PYBV11 MICROPY_PY_WIZNET5K=5200 MICROPY_PY_CC3K=1
|
- make ${MAKEOPTS} -C ports/stm32 BOARD=PYBV11 MICROPY_PY_WIZNET5K=5200 MICROPY_PY_CC3K=1
|
||||||
|
- make ${MAKEOPTS} -C ports/stm32 BOARD=PYBD_SF2
|
||||||
- make ${MAKEOPTS} -C ports/stm32 BOARD=STM32F769DISC
|
- make ${MAKEOPTS} -C ports/stm32 BOARD=STM32F769DISC
|
||||||
- make ${MAKEOPTS} -C ports/stm32 BOARD=STM32L476DISC
|
- make ${MAKEOPTS} -C ports/stm32 BOARD=STM32L476DISC
|
||||||
|
|
||||||
@ -38,12 +41,11 @@ jobs:
|
|||||||
- stage: test
|
- stage: test
|
||||||
env: NAME="qemu-arm port build and tests"
|
env: NAME="qemu-arm port build and tests"
|
||||||
install:
|
install:
|
||||||
# need newer gcc version for nano.specs
|
- sudo apt-get install gcc-arm-none-eabi
|
||||||
- sudo add-apt-repository -y ppa:terry.guo/gcc-arm-embedded
|
- sudo apt-get install libnewlib-arm-none-eabi
|
||||||
- sudo apt-get update -qq || true
|
|
||||||
- sudo apt-get install --allow-unauthenticated gcc-arm-none-eabi
|
|
||||||
- sudo apt-get install qemu-system
|
- sudo apt-get install qemu-system
|
||||||
- arm-none-eabi-gcc --version
|
- arm-none-eabi-gcc --version
|
||||||
|
- qemu-system-arm --version
|
||||||
script:
|
script:
|
||||||
- make ${MAKEOPTS} -C mpy-cross
|
- make ${MAKEOPTS} -C mpy-cross
|
||||||
- make ${MAKEOPTS} -C ports/qemu-arm -f Makefile.test test
|
- make ${MAKEOPTS} -C ports/qemu-arm -f Makefile.test test
|
||||||
@ -54,8 +56,6 @@ jobs:
|
|||||||
- stage: test
|
- stage: test
|
||||||
env: NAME="unix coverage build and tests"
|
env: NAME="unix coverage build and tests"
|
||||||
install:
|
install:
|
||||||
# a specific urllib3 version is needed for requests and cpp-coveralls to work together
|
|
||||||
- sudo pip install -Iv urllib3==1.22
|
|
||||||
- sudo pip install cpp-coveralls
|
- sudo pip install cpp-coveralls
|
||||||
- gcc --version
|
- gcc --version
|
||||||
- python3 --version
|
- python3 --version
|
||||||
@ -67,7 +67,8 @@ jobs:
|
|||||||
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests)
|
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests)
|
||||||
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -d thread)
|
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -d thread)
|
||||||
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests --emit native)
|
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests --emit native)
|
||||||
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests --via-mpy -d basics float)
|
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests --via-mpy -d basics float micropython)
|
||||||
|
- (cd tests && MICROPY_CPYTHON3=python3 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests --via-mpy --emit native -d basics float micropython)
|
||||||
# test when input script comes from stdin
|
# test when input script comes from stdin
|
||||||
- cat tests/basics/0prelim.py | ports/unix/micropython_coverage | grep -q 'abc'
|
- cat tests/basics/0prelim.py | ports/unix/micropython_coverage | grep -q 'abc'
|
||||||
# run coveralls coverage analysis (try to, even if some builds/tests failed)
|
# run coveralls coverage analysis (try to, even if some builds/tests failed)
|
||||||
@ -117,10 +118,8 @@ jobs:
|
|||||||
- stage: test
|
- stage: test
|
||||||
env: NAME="nrf port build"
|
env: NAME="nrf port build"
|
||||||
install:
|
install:
|
||||||
# need newer gcc version to support variables in linker script
|
- sudo apt-get install gcc-arm-none-eabi
|
||||||
- sudo add-apt-repository -y ppa:team-gcc-arm-embedded/ppa
|
- sudo apt-get install libnewlib-arm-none-eabi
|
||||||
- sudo apt-get update -qq || true
|
|
||||||
- sudo apt-get install gcc-arm-embedded
|
|
||||||
- arm-none-eabi-gcc --version
|
- arm-none-eabi-gcc --version
|
||||||
script:
|
script:
|
||||||
- make ${MAKEOPTS} -C ports/nrf
|
- make ${MAKEOPTS} -C ports/nrf
|
||||||
@ -130,6 +129,7 @@ jobs:
|
|||||||
env: NAME="bare-arm and minimal ports build"
|
env: NAME="bare-arm and minimal ports build"
|
||||||
install:
|
install:
|
||||||
- sudo apt-get install gcc-arm-none-eabi
|
- sudo apt-get install gcc-arm-none-eabi
|
||||||
|
- sudo apt-get install libnewlib-arm-none-eabi
|
||||||
- arm-none-eabi-gcc --version
|
- arm-none-eabi-gcc --version
|
||||||
script:
|
script:
|
||||||
- make ${MAKEOPTS} -C ports/bare-arm
|
- make ${MAKEOPTS} -C ports/bare-arm
|
||||||
@ -145,6 +145,7 @@ jobs:
|
|||||||
env: NAME="cc3200 port build"
|
env: NAME="cc3200 port build"
|
||||||
install:
|
install:
|
||||||
- sudo apt-get install gcc-arm-none-eabi
|
- sudo apt-get install gcc-arm-none-eabi
|
||||||
|
- sudo apt-get install libnewlib-arm-none-eabi
|
||||||
script:
|
script:
|
||||||
- make ${MAKEOPTS} -C ports/cc3200 BTARGET=application BTYPE=release
|
- make ${MAKEOPTS} -C ports/cc3200 BTARGET=application BTYPE=release
|
||||||
- make ${MAKEOPTS} -C ports/cc3200 BTARGET=bootloader BTYPE=release
|
- make ${MAKEOPTS} -C ports/cc3200 BTARGET=bootloader BTYPE=release
|
||||||
@ -154,5 +155,6 @@ jobs:
|
|||||||
env: NAME="teensy port build"
|
env: NAME="teensy port build"
|
||||||
install:
|
install:
|
||||||
- sudo apt-get install gcc-arm-none-eabi
|
- sudo apt-get install gcc-arm-none-eabi
|
||||||
|
- sudo apt-get install libnewlib-arm-none-eabi
|
||||||
script:
|
script:
|
||||||
- make ${MAKEOPTS} -C ports/teensy
|
- make ${MAKEOPTS} -C ports/teensy
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013, 2014 Damien P. George
|
Copyright (c) 2013-2019 Damien P. George
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -74,7 +74,7 @@ copyright = '2014-2019, Damien P. George, Paul Sokolovsky, and contributors'
|
|||||||
#
|
#
|
||||||
# We don't follow "The short X.Y version" vs "The full version, including alpha/beta/rc tags"
|
# We don't follow "The short X.Y version" vs "The full version, including alpha/beta/rc tags"
|
||||||
# breakdown, so use the same version identifier for both to avoid confusion.
|
# breakdown, so use the same version identifier for both to avoid confusion.
|
||||||
version = release = '1.10'
|
version = release = '1.11'
|
||||||
|
|
||||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||||
# for a list of supported languages.
|
# for a list of supported languages.
|
||||||
|
|||||||
174
docs/develop/cmodules.rst
Normal file
174
docs/develop/cmodules.rst
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
MicroPython external C modules
|
||||||
|
==============================
|
||||||
|
|
||||||
|
When developing modules for use with MicroPython you may find you run into
|
||||||
|
limitations with the Python environment, often due to an inability to access
|
||||||
|
certain hardware resources or Python speed limitations.
|
||||||
|
|
||||||
|
If your limitations can't be resolved with suggestions in :ref:`speed_python`,
|
||||||
|
writing some or all of your module in C is a viable option.
|
||||||
|
|
||||||
|
If your module is designed to access or work with commonly available
|
||||||
|
hardware or libraries please consider implementing it inside the MicroPython
|
||||||
|
source tree alongside similar modules and submitting it as a pull request.
|
||||||
|
If however you're targeting obscure or proprietary systems it may make
|
||||||
|
more sense to keep this external to the main MicroPython repository.
|
||||||
|
|
||||||
|
This chapter describes how to compile such external modules into the
|
||||||
|
MicroPython executable or firmware image.
|
||||||
|
|
||||||
|
|
||||||
|
Structure of an external C module
|
||||||
|
---------------------------------
|
||||||
|
|
||||||
|
A MicroPython user C module is a directory with the following files:
|
||||||
|
|
||||||
|
* ``*.c`` and/or ``*.h`` source code files for your module.
|
||||||
|
|
||||||
|
These will typically include the low level functionality being implemented and
|
||||||
|
the MicroPython binding functions to expose the functions and module(s).
|
||||||
|
|
||||||
|
Currently the best reference for writing these functions/modules is
|
||||||
|
to find similar modules within the MicroPython tree and use them as examples.
|
||||||
|
|
||||||
|
* ``micropython.mk`` contains the Makefile fragment for this module.
|
||||||
|
|
||||||
|
``$(USERMOD_DIR)`` is available in ``micropython.mk`` as the path to your
|
||||||
|
module directory. As it's redefined for each c module, is should be expanded
|
||||||
|
in your ``micropython.mk`` to a local make variable,
|
||||||
|
eg ``EXAMPLE_MOD_DIR := $(USERMOD_DIR)``
|
||||||
|
|
||||||
|
Your ``micropython.mk`` must add your modules C files relative to your
|
||||||
|
expanded copy of ``$(USERMOD_DIR)`` to ``SRC_USERMOD``, eg
|
||||||
|
``SRC_USERMOD += $(EXAMPLE_MOD_DIR)/example.c``
|
||||||
|
|
||||||
|
If you have custom ``CFLAGS`` settings or include folders to define, these
|
||||||
|
should be added to ``CFLAGS_USERMOD``.
|
||||||
|
|
||||||
|
See below for full usage example.
|
||||||
|
|
||||||
|
|
||||||
|
Basic Example
|
||||||
|
-------------
|
||||||
|
|
||||||
|
This simple module named ``example`` provides a single function
|
||||||
|
``example.add_ints(a, b)`` which adds the two integer args together and returns
|
||||||
|
the result.
|
||||||
|
|
||||||
|
Directory::
|
||||||
|
|
||||||
|
example/
|
||||||
|
├── example.c
|
||||||
|
└── micropython.mk
|
||||||
|
|
||||||
|
|
||||||
|
``example.c``
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
// Include required definitions first.
|
||||||
|
#include "py/obj.h"
|
||||||
|
#include "py/runtime.h"
|
||||||
|
#include "py/builtin.h"
|
||||||
|
|
||||||
|
// This is the function which will be called from Python as example.add_ints(a, b).
|
||||||
|
STATIC mp_obj_t example_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) {
|
||||||
|
// Extract the ints from the micropython input objects
|
||||||
|
int a = mp_obj_get_int(a_obj);
|
||||||
|
int b = mp_obj_get_int(b_obj);
|
||||||
|
|
||||||
|
// Calculate the addition and convert to MicroPython object.
|
||||||
|
return mp_obj_new_int(a + b);
|
||||||
|
}
|
||||||
|
// Define a Python reference to the function above
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(example_add_ints_obj, example_add_ints);
|
||||||
|
|
||||||
|
// Define all properties of the example module.
|
||||||
|
// Table entries are key/value pairs of the attribute name (a string)
|
||||||
|
// and the MicroPython object reference.
|
||||||
|
// All identifiers and strings are written as MP_QSTR_xxx and will be
|
||||||
|
// optimized to word-sized integers by the build system (interned strings).
|
||||||
|
STATIC const mp_rom_map_elem_t example_module_globals_table[] = {
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_add_ints), MP_ROM_PTR(&example_add_ints_obj) },
|
||||||
|
};
|
||||||
|
STATIC MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table);
|
||||||
|
|
||||||
|
// Define module object.
|
||||||
|
const mp_obj_module_t example_user_cmodule = {
|
||||||
|
.base = { &mp_type_module },
|
||||||
|
.globals = (mp_obj_dict_t*)&example_module_globals,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Register the module to make it available in Python
|
||||||
|
MP_REGISTER_MODULE(MP_QSTR_example, example_user_cmodule, MODULE_EXAMPLE_ENABLED);
|
||||||
|
|
||||||
|
|
||||||
|
``micropython.mk``
|
||||||
|
|
||||||
|
.. code-block:: make
|
||||||
|
|
||||||
|
EXAMPLE_MOD_DIR := $(USERMOD_DIR)
|
||||||
|
|
||||||
|
# Add all C files to SRC_USERMOD.
|
||||||
|
SRC_USERMOD += $(EXAMPLE_MOD_DIR)/example.c
|
||||||
|
|
||||||
|
# We can add our module folder to include paths if needed
|
||||||
|
# This is not actually needed in this example.
|
||||||
|
CFLAGS_USERMOD += -I$(EXAMPLE_MOD_DIR)
|
||||||
|
|
||||||
|
Finally you will need to define ``MODULE_EXAMPLE_ENABLED`` to 1. This
|
||||||
|
can be done by adding ``CFLAGS_EXTRA=-DMODULE_EXAMPLE_ENABLED=1`` to
|
||||||
|
the ``make`` command, or editing ``mpconfigport.h`` or
|
||||||
|
``mpconfigboard.h`` to add
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
#define MODULE_EXAMPLE_ENABLED (1)
|
||||||
|
|
||||||
|
Note that the exact method depends on the port as they have different
|
||||||
|
structures. If not done correctly it will compile but importing will
|
||||||
|
fail to find the module.
|
||||||
|
|
||||||
|
|
||||||
|
Compiling the cmodule into MicroPython
|
||||||
|
--------------------------------------
|
||||||
|
|
||||||
|
To build such a module, compile MicroPython (see `getting started
|
||||||
|
<https://github.com/micropython/micropython/wiki/Getting-Started>`_) with an
|
||||||
|
extra ``make`` flag named ``USER_C_MODULES`` set to the directory containing
|
||||||
|
all modules you want included (not to the module itself). For example:
|
||||||
|
|
||||||
|
|
||||||
|
Directory::
|
||||||
|
|
||||||
|
my_project/
|
||||||
|
├── modules/
|
||||||
|
│ └──example/
|
||||||
|
│ ├──example.c
|
||||||
|
│ └──micropython.mk
|
||||||
|
└── micropython/
|
||||||
|
├──ports/
|
||||||
|
... ├──stm32/
|
||||||
|
...
|
||||||
|
|
||||||
|
Building for stm32 port:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
cd my_project/micropython/ports/stm32
|
||||||
|
make USER_C_MODULES=../../../modules CFLAGS_EXTRA=-DMODULE_EXAMPLE_ENABLED=1 all
|
||||||
|
|
||||||
|
|
||||||
|
Module usage in MicroPython
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
Once built into your copy of MicroPython, the module implemented
|
||||||
|
in ``example.c`` above can now be accessed in Python just
|
||||||
|
like any other builtin module, eg
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
import example
|
||||||
|
print(example.add_ints(1, 3))
|
||||||
|
# should display 4
|
||||||
12
docs/develop/index.rst
Normal file
12
docs/develop/index.rst
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Developing and building MicroPython
|
||||||
|
===================================
|
||||||
|
|
||||||
|
This chapter describes some options for extending MicroPython in C. Note
|
||||||
|
that it doesn't aim to be a complete guide for developing with MicroPython.
|
||||||
|
See the `getting started guide
|
||||||
|
<https://github.com/micropython/micropython/wiki/Getting-Started>`_ for further information.
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 1
|
||||||
|
|
||||||
|
cmodules.rst
|
||||||
@ -128,6 +128,8 @@ with timer ID of -1::
|
|||||||
|
|
||||||
The period is in milliseconds.
|
The period is in milliseconds.
|
||||||
|
|
||||||
|
.. _Pins_and_GPIO:
|
||||||
|
|
||||||
Pins and GPIO
|
Pins and GPIO
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
@ -161,6 +163,9 @@ Notes:
|
|||||||
|
|
||||||
* Pins 34-39 are input only, and also do not have internal pull-up resistors
|
* Pins 34-39 are input only, and also do not have internal pull-up resistors
|
||||||
|
|
||||||
|
* The pull value of some pins can be set to ``Pin.PULL_HOLD`` to reduce power
|
||||||
|
consumption during deepsleep.
|
||||||
|
|
||||||
PWM (pulse width modulation)
|
PWM (pulse width modulation)
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
@ -271,8 +276,13 @@ class::
|
|||||||
Hardware SPI bus
|
Hardware SPI bus
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
There are two hardware SPI channels that allow faster (up to 80Mhz)
|
There are two hardware SPI channels that allow faster transmission
|
||||||
transmission rates, but are only supported on a subset of pins.
|
rates (up to 80Mhz). These may be used on any IO pins that support the
|
||||||
|
required direction and are otherwise unused (see :ref:`Pins_and_GPIO`)
|
||||||
|
but if they are not configured to their default pins then they need to
|
||||||
|
pass through an extra layer of GPIO multiplexing, which can impact
|
||||||
|
their reliability at high speeds. Hardware SPI channels are limited
|
||||||
|
to 40MHz when used on pins other than the default ones listed below.
|
||||||
|
|
||||||
===== =========== ============
|
===== =========== ============
|
||||||
\ HSPI (id=1) VSPI (id=2)
|
\ HSPI (id=1) VSPI (id=2)
|
||||||
@ -337,6 +347,15 @@ Notes:
|
|||||||
* Calling ``deepsleep()`` without an argument will put the device to sleep
|
* Calling ``deepsleep()`` without an argument will put the device to sleep
|
||||||
indefinitely
|
indefinitely
|
||||||
* A software reset does not change the reset cause
|
* A software reset does not change the reset cause
|
||||||
|
* There may be some leakage current flowing through enabled internal pullups.
|
||||||
|
To further reduce power consumption it is possible to disable the internal pullups::
|
||||||
|
|
||||||
|
p1 = Pin(4, Pin.IN, Pin.PULL_HOLD)
|
||||||
|
|
||||||
|
After leaving deepsleep it may be necessary to un-hold the pin explicitly (e.g. if
|
||||||
|
it is an output pin) via::
|
||||||
|
|
||||||
|
p1 = Pin(4, Pin.OUT, None)
|
||||||
|
|
||||||
OneWire driver
|
OneWire driver
|
||||||
--------------
|
--------------
|
||||||
@ -421,7 +440,7 @@ Note that TouchPads can be used to wake an ESP32 from sleep::
|
|||||||
t = TouchPad(Pin(14))
|
t = TouchPad(Pin(14))
|
||||||
t.config(500) # configure the threshold at which the pin is considered touched
|
t.config(500) # configure the threshold at which the pin is considered touched
|
||||||
esp32.wake_on_touch(True)
|
esp32.wake_on_touch(True)
|
||||||
machine.sleep() # put the MCU to sleep until a touchpad is touched
|
machine.lightsleep() # put the MCU to sleep until a touchpad is touched
|
||||||
|
|
||||||
For more details on touchpads refer to `Espressif Touch Sensor
|
For more details on touchpads refer to `Espressif Touch Sensor
|
||||||
<https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/touch_pad.html>`_.
|
<https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/touch_pad.html>`_.
|
||||||
|
|||||||
91
docs/esp8266/tutorial/apa102.rst
Normal file
91
docs/esp8266/tutorial/apa102.rst
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
Controlling APA102 LEDs
|
||||||
|
=======================
|
||||||
|
|
||||||
|
APA102 LEDs, also known as DotStar LEDs, are individually addressable
|
||||||
|
full-colour RGB LEDs, generally in a string formation. They differ from
|
||||||
|
NeoPixels in that they require two pins to control - both a Clock and Data pin.
|
||||||
|
They can operate at a much higher data and PWM frequencies than NeoPixels and
|
||||||
|
are more suitable for persistence-of-vision effects.
|
||||||
|
|
||||||
|
To create an APA102 object do the following::
|
||||||
|
|
||||||
|
>>> import machine, apa102
|
||||||
|
>>> strip = apa102.APA102(machine.Pin(5), machine.Pin(4), 60)
|
||||||
|
|
||||||
|
This configures an 60 pixel APA102 strip with clock on GPIO5 and data on GPIO4.
|
||||||
|
You can adjust the pin numbers and the number of pixels to suit your needs.
|
||||||
|
|
||||||
|
The RGB colour data, as well as a brightness level, is sent to the APA102 in a
|
||||||
|
certain order. Usually this is ``(Red, Green, Blue, Brightness)``.
|
||||||
|
If you are using one of the newer APA102C LEDs the green and blue are swapped,
|
||||||
|
so the order is ``(Red, Blue, Green, Brightness)``.
|
||||||
|
The APA102 has more of a square lens while the APA102C has more of a round one.
|
||||||
|
If you are using a APA102C strip and would prefer to provide colours in RGB
|
||||||
|
order instead of RBG, you can customise the tuple colour order like so::
|
||||||
|
|
||||||
|
>>> strip.ORDER = (0, 2, 1, 3)
|
||||||
|
|
||||||
|
To set the colour of pixels use::
|
||||||
|
|
||||||
|
>>> strip[0] = (255, 255, 255, 31) # set to white, full brightness
|
||||||
|
>>> strip[1] = (255, 0, 0, 31) # set to red, full brightness
|
||||||
|
>>> strip[2] = (0, 255, 0, 15) # set to green, half brightness
|
||||||
|
>>> strip[3] = (0, 0, 255, 7) # set to blue, quarter brightness
|
||||||
|
|
||||||
|
Use the ``write()`` method to output the colours to the LEDs::
|
||||||
|
|
||||||
|
>>> strip.write()
|
||||||
|
|
||||||
|
Demonstration::
|
||||||
|
|
||||||
|
import time
|
||||||
|
import machine, apa102
|
||||||
|
|
||||||
|
# 1M strip with 60 LEDs
|
||||||
|
strip = apa102.APA102(machine.Pin(5), machine.Pin(4), 60)
|
||||||
|
|
||||||
|
brightness = 1 # 0 is off, 1 is dim, 31 is max
|
||||||
|
|
||||||
|
# Helper for converting 0-255 offset to a colour tuple
|
||||||
|
def wheel(offset, brightness):
|
||||||
|
# The colours are a transition r - g - b - back to r
|
||||||
|
offset = 255 - offset
|
||||||
|
if offset < 85:
|
||||||
|
return (255 - offset * 3, 0, offset * 3, brightness)
|
||||||
|
if offset < 170:
|
||||||
|
offset -= 85
|
||||||
|
return (0, offset * 3, 255 - offset * 3, brightness)
|
||||||
|
offset -= 170
|
||||||
|
return (offset * 3, 255 - offset * 3, 0, brightness)
|
||||||
|
|
||||||
|
# Demo 1: RGB RGB RGB
|
||||||
|
red = 0xff0000
|
||||||
|
green = red >> 8
|
||||||
|
blue = red >> 16
|
||||||
|
for i in range(strip.n):
|
||||||
|
colour = red >> (i % 3) * 8
|
||||||
|
strip[i] = ((colour & red) >> 16, (colour & green) >> 8, (colour & blue), brightness)
|
||||||
|
strip.write()
|
||||||
|
|
||||||
|
# Demo 2: Show all colours of the rainbow
|
||||||
|
for i in range(strip.n):
|
||||||
|
strip[i] = wheel((i * 256 // strip.n) % 255, brightness)
|
||||||
|
strip.write()
|
||||||
|
|
||||||
|
# Demo 3: Fade all pixels together through rainbow colours, offset each pixel
|
||||||
|
for r in range(5):
|
||||||
|
for n in range(256):
|
||||||
|
for i in range(strip.n):
|
||||||
|
strip[i] = wheel(((i * 256 // strip.n) + n) & 255, brightness)
|
||||||
|
strip.write()
|
||||||
|
time.sleep_ms(25)
|
||||||
|
|
||||||
|
# Demo 4: Same colour, different brightness levels
|
||||||
|
for b in range(31,-1,-1):
|
||||||
|
strip[0] = (255, 153, 0, b)
|
||||||
|
strip.write()
|
||||||
|
time.sleep_ms(250)
|
||||||
|
|
||||||
|
# End: Turn off all the LEDs
|
||||||
|
strip.fill((0, 0, 0, 0))
|
||||||
|
strip.write()
|
||||||
@ -29,5 +29,6 @@ to `<https://www.python.org>`__.
|
|||||||
powerctrl.rst
|
powerctrl.rst
|
||||||
onewire.rst
|
onewire.rst
|
||||||
neopixel.rst
|
neopixel.rst
|
||||||
|
apa102.rst
|
||||||
dht.rst
|
dht.rst
|
||||||
nextsteps.rst
|
nextsteps.rst
|
||||||
|
|||||||
@ -6,6 +6,7 @@ MicroPython documentation and references
|
|||||||
library/index.rst
|
library/index.rst
|
||||||
reference/index.rst
|
reference/index.rst
|
||||||
genrst/index.rst
|
genrst/index.rst
|
||||||
|
develop/index.rst
|
||||||
license.rst
|
license.rst
|
||||||
pyboard/quickref.rst
|
pyboard/quickref.rst
|
||||||
esp8266/quickref.rst
|
esp8266/quickref.rst
|
||||||
|
|||||||
@ -131,6 +131,20 @@ operations that target a given slave device.
|
|||||||
generated at the end of the transfer, even if a NACK is received.
|
generated at the end of the transfer, even if a NACK is received.
|
||||||
The function returns the number of ACKs that were received.
|
The function returns the number of ACKs that were received.
|
||||||
|
|
||||||
|
.. method:: I2C.writevto(addr, vector, stop=True)
|
||||||
|
|
||||||
|
Write the bytes contained in *vector* to the slave specified by *addr*.
|
||||||
|
*vector* should be a tuple or list of objects with the buffer protocol.
|
||||||
|
The *addr* is sent once and then the bytes from each object in *vector*
|
||||||
|
are written out sequentially. The objects in *vector* may be zero bytes
|
||||||
|
in length in which case they don't contribute to the output.
|
||||||
|
|
||||||
|
If a NACK is received following the write of a byte from one of the
|
||||||
|
objects in *vector* then the remaining bytes, and any remaining objects,
|
||||||
|
are not sent. If *stop* is true then a STOP condition is generated at
|
||||||
|
the end of the transfer, even if a NACK is received. The function
|
||||||
|
returns the number of ACKs that were received.
|
||||||
|
|
||||||
Memory operations
|
Memory operations
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
|||||||
@ -235,6 +235,7 @@ not all constants are available on all ports.
|
|||||||
|
|
||||||
.. data:: Pin.PULL_UP
|
.. data:: Pin.PULL_UP
|
||||||
Pin.PULL_DOWN
|
Pin.PULL_DOWN
|
||||||
|
Pin.PULL_HOLD
|
||||||
|
|
||||||
Selects whether there is a pull up/down resistor. Use the value
|
Selects whether there is a pull up/down resistor. Use the value
|
||||||
``None`` for no pull.
|
``None`` for no pull.
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
.. currentmodule:: machine
|
.. currentmodule:: machine
|
||||||
.. _machine.SD:
|
.. _machine.SD:
|
||||||
|
|
||||||
class SD -- secure digital memory card
|
class SD -- secure digital memory card (cc3200 port only)
|
||||||
======================================
|
=========================================================
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
|
|||||||
122
docs/library/machine.SDCard.rst
Normal file
122
docs/library/machine.SDCard.rst
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
.. currentmodule:: machine
|
||||||
|
.. _machine.SDCard:
|
||||||
|
|
||||||
|
class SDCard -- secure digital memory card
|
||||||
|
==========================================
|
||||||
|
|
||||||
|
SD cards are one of the most common small form factor removable storage media.
|
||||||
|
SD cards come in a variety of sizes and phsyical form factors. MMC cards are
|
||||||
|
similar removable storage devices while eMMC devices are electically similar
|
||||||
|
storage devices designed to be embedded into other systems. All three form
|
||||||
|
share a common protocol for communication with their host system and high-level
|
||||||
|
support looks the same for them all. As such in MicroPython they are implemented
|
||||||
|
in a single class called :class:`machine.SDCard` .
|
||||||
|
|
||||||
|
Both SD and MMC interfaces support being accessed with a variety of bus widths.
|
||||||
|
When being accessed with a 1-bit wide interface they can be accessed using the
|
||||||
|
SPI protocol. Different MicroPython hardware platforms support different widths
|
||||||
|
and pin configurations but for most platforms there is a standard configuation
|
||||||
|
for any given hardware. In general constructing an `SDCard`` object with without
|
||||||
|
passing any parameters will initialise the interface to the default card slot
|
||||||
|
for the current hardware. The arguments listed below represent the common
|
||||||
|
arguments that might need to be set in order to use either a non-stanard slot
|
||||||
|
or a non-standard pin assignment. The exact subset of arguments suported will
|
||||||
|
vary from platform to platform.
|
||||||
|
|
||||||
|
.. class:: SDCard(slot=1, width=1, cd=None, wp=None, sck=None, miso=None, mosi=None, cs=None)
|
||||||
|
|
||||||
|
This class provides access to SD or MMC storage cards using either
|
||||||
|
a dedicated SD/MMC interface hardware or through an SPI channel.
|
||||||
|
The class implements the block protocol defined by :class:`uos.AbstractBlockDev`.
|
||||||
|
This allows the mounting of an SD card to be as simple as::
|
||||||
|
|
||||||
|
uos.mount(machine.SDCard(), "/sd")
|
||||||
|
|
||||||
|
The constrcutor takes the following paramters:
|
||||||
|
|
||||||
|
- *slot* selects which of the available interfaces to use. Leaving this
|
||||||
|
unset will select the default interface.
|
||||||
|
|
||||||
|
- *width* selects the bus width for the SD/MMC interface.
|
||||||
|
|
||||||
|
- *cd* can be used to specify a card-detect pin.
|
||||||
|
|
||||||
|
- *wp* can be used to specify a write-protect pin.
|
||||||
|
|
||||||
|
- *sck* can be used to specify an SPI clock pin.
|
||||||
|
|
||||||
|
- *miso* can be used to specify an SPI miso pin.
|
||||||
|
|
||||||
|
- *mosi* can be used to specify an SPI mosi pin.
|
||||||
|
|
||||||
|
- *cs* can be used to specify an SPI chip select pin.
|
||||||
|
|
||||||
|
Implementation-specific details
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
Different implementations of the ``SDCard`` class on different hardware support
|
||||||
|
varying subsets of the options above.
|
||||||
|
|
||||||
|
PyBoard
|
||||||
|
```````
|
||||||
|
|
||||||
|
The standard PyBoard has just one slot. No arguments are necessary or supported.
|
||||||
|
|
||||||
|
ESP32
|
||||||
|
`````
|
||||||
|
|
||||||
|
The ESP32 provides two channels of SD/MMC hardware and also supports
|
||||||
|
access to SD Cards through either of the two SPI ports that are
|
||||||
|
generally available to the user. As a result the *slot* argument can
|
||||||
|
take a value between 0 and 3, inclusive. Slots 0 and 1 use the
|
||||||
|
built-in SD/MMC hardware while slots 2 and 3 use the SPI ports. Slot 0
|
||||||
|
supports 1, 4 or 8-bit wide access while slot 1 supports 1 or 4-bit
|
||||||
|
access; the SPI slots only support 1-bit access.
|
||||||
|
|
||||||
|
.. note:: Slot 0 is used to communicate with on-board flash memory
|
||||||
|
on most ESP32 modules and so will be unavailable to the
|
||||||
|
user.
|
||||||
|
|
||||||
|
.. note:: Most ESP32 modules that provide an SD card slot using the
|
||||||
|
dedicated hardware only wire up 1 data pin, so the default
|
||||||
|
value for *width* is 1.
|
||||||
|
|
||||||
|
The pins used by the dedicated SD/MMC hardware are fixed. The pins
|
||||||
|
used by the SPI hardware can be reassigned.
|
||||||
|
|
||||||
|
.. note:: If any of the SPI signals are remapped then all of the SPI
|
||||||
|
signals will pass through a GPIO multiplexer unit which
|
||||||
|
can limit the performance of high frequency signals. Since
|
||||||
|
the normal operating speed for SD cards is 40MHz this can
|
||||||
|
cause problems on some cards.
|
||||||
|
|
||||||
|
The default (and preferred) pin assignment are as follows:
|
||||||
|
|
||||||
|
====== ====== ====== ====== ======
|
||||||
|
Slot 0 1 2 3
|
||||||
|
------ ------ ------ ------ ------
|
||||||
|
Signal Pin Pin Pin Pin
|
||||||
|
====== ====== ====== ====== ======
|
||||||
|
sck 6 14 18 14
|
||||||
|
cmd 11 15
|
||||||
|
cs 5 15
|
||||||
|
miso 19 12
|
||||||
|
mosi 23 13
|
||||||
|
D0 7 2
|
||||||
|
D1 8 4
|
||||||
|
D2 9 12
|
||||||
|
D3 10 13
|
||||||
|
D4 16
|
||||||
|
D5 17
|
||||||
|
D6 5
|
||||||
|
D7 18
|
||||||
|
====== ====== ====== ====== ======
|
||||||
|
|
||||||
|
cc3200
|
||||||
|
``````
|
||||||
|
|
||||||
|
You can set the pins used for SPI access by passing a tuple as the
|
||||||
|
*pins* argument.
|
||||||
|
|
||||||
|
*Note:* The current cc3200 SD card implementation names the this class
|
||||||
|
:class:`machine.SD` rather than :class:`machine.SDCard` .
|
||||||
@ -63,16 +63,31 @@ Power related functions
|
|||||||
|
|
||||||
.. function:: sleep()
|
.. function:: sleep()
|
||||||
|
|
||||||
Stops the CPU and disables all peripherals except for WLAN. Execution is resumed from
|
.. note:: This function is deprecated, use `lightsleep()` instead with no arguments.
|
||||||
the point where the sleep was requested. For wake up to actually happen, wake sources
|
|
||||||
should be configured first.
|
|
||||||
|
|
||||||
.. function:: deepsleep()
|
.. function:: lightsleep([time_ms])
|
||||||
|
deepsleep([time_ms])
|
||||||
|
|
||||||
Stops the CPU and all peripherals (including networking interfaces, if any). Execution
|
Stops execution in an attempt to enter a low power state.
|
||||||
is resumed from the main script, just as with a reset. The reset cause can be checked
|
|
||||||
to know that we are coming from `machine.DEEPSLEEP`. For wake up to actually happen,
|
If *time_ms* is specified then this will be the maximum time in milliseconds that
|
||||||
wake sources should be configured first, like `Pin` change or `RTC` timeout.
|
the sleep will last for. Otherwise the sleep can last indefinitely.
|
||||||
|
|
||||||
|
With or without a timout, execution may resume at any time if there are events
|
||||||
|
that require processing. Such events, or wake sources, should be configured before
|
||||||
|
sleeping, like `Pin` change or `RTC` timeout.
|
||||||
|
|
||||||
|
The precise behaviour and power-saving capabilities of lightsleep and deepsleep is
|
||||||
|
highly dependent on the underlying hardware, but the general properties are:
|
||||||
|
|
||||||
|
* A lightsleep has full RAM and state retention. Upon wake execution is resumed
|
||||||
|
from the point where the sleep was requested, with all subsystems operational.
|
||||||
|
|
||||||
|
* A deepsleep may not retain RAM or any other state of the system (for example
|
||||||
|
peripherals or network interfaces). Upon wake execution is resumed from the main
|
||||||
|
script, similar to a hard or power-on reset. The `reset_cause()` function will
|
||||||
|
return `machine.DEEPSLEEP` and this can be used to distinguish a deepsleep wake
|
||||||
|
from other resets.
|
||||||
|
|
||||||
.. function:: wake_reason()
|
.. function:: wake_reason()
|
||||||
|
|
||||||
@ -153,3 +168,4 @@ Classes
|
|||||||
machine.Timer.rst
|
machine.Timer.rst
|
||||||
machine.WDT.rst
|
machine.WDT.rst
|
||||||
machine.SD.rst
|
machine.SD.rst
|
||||||
|
machine.SDCard.rst
|
||||||
|
|||||||
@ -69,7 +69,7 @@ Constructors
|
|||||||
Methods
|
Methods
|
||||||
-------
|
-------
|
||||||
|
|
||||||
.. method:: UART.init(baudrate, bits=8, parity=None, stop=1, \*, timeout=1000, flow=0, timeout_char=0, read_buf_len=64)
|
.. method:: UART.init(baudrate, bits=8, parity=None, stop=1, \*, timeout=0, flow=0, timeout_char=0, read_buf_len=64)
|
||||||
|
|
||||||
Initialise the UART bus with the given parameters:
|
Initialise the UART bus with the given parameters:
|
||||||
|
|
||||||
|
|||||||
@ -22,9 +22,11 @@ Classes
|
|||||||
* *mode* is:
|
* *mode* is:
|
||||||
|
|
||||||
* ``1`` (or ``ucryptolib.MODE_ECB`` if it exists) for Electronic Code Book (ECB).
|
* ``1`` (or ``ucryptolib.MODE_ECB`` if it exists) for Electronic Code Book (ECB).
|
||||||
* ``2`` (or ``ucryptolib.MODE_CBC`` if it exists) for Cipher Block Chaining (CBC)
|
* ``2`` (or ``ucryptolib.MODE_CBC`` if it exists) for Cipher Block Chaining (CBC).
|
||||||
|
* ``6`` (or ``ucryptolib.MODE_CTR`` if it exists) for Counter mode (CTR).
|
||||||
|
|
||||||
* *IV* is an initialization vector for CBC mode.
|
* *IV* is an initialization vector for CBC mode.
|
||||||
|
* For Counter mode, *IV* is the initial value for the counter.
|
||||||
|
|
||||||
.. method:: encrypt(in_buf, [out_buf])
|
.. method:: encrypt(in_buf, [out_buf])
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,8 @@ Terminal redirection and duplication
|
|||||||
.. function:: dupterm(stream_object, index=0)
|
.. function:: dupterm(stream_object, index=0)
|
||||||
|
|
||||||
Duplicate or switch the MicroPython terminal (the REPL) on the given `stream`-like
|
Duplicate or switch the MicroPython terminal (the REPL) on the given `stream`-like
|
||||||
object. The *stream_object* argument must implement the ``readinto()`` and
|
object. The *stream_object* argument must be a native stream object, or derive
|
||||||
|
from ``uio.IOBase`` and implement the ``readinto()`` and
|
||||||
``write()`` methods. The stream should be in non-blocking mode and
|
``write()`` methods. The stream should be in non-blocking mode and
|
||||||
``readinto()`` should return ``None`` if there is no data available for reading.
|
``readinto()`` should return ``None`` if there is no data available for reading.
|
||||||
|
|
||||||
|
|||||||
@ -175,7 +175,7 @@ Match objects
|
|||||||
Match objects as returned by `match()` and `search()` methods, and passed
|
Match objects as returned by `match()` and `search()` methods, and passed
|
||||||
to the replacement function in `sub()`.
|
to the replacement function in `sub()`.
|
||||||
|
|
||||||
.. method:: match.group([index])
|
.. method:: match.group(index)
|
||||||
|
|
||||||
Return matching (sub)string. *index* is 0 for entire match,
|
Return matching (sub)string. *index* is 0 for entire match,
|
||||||
1 and above for each capturing group. Only numeric groups are supported.
|
1 and above for each capturing group. Only numeric groups are supported.
|
||||||
|
|||||||
@ -3,9 +3,12 @@ The pyboard hardware
|
|||||||
|
|
||||||
For the pyboard:
|
For the pyboard:
|
||||||
|
|
||||||
* `PYBv1.0 schematics and layout <http://micropython.org/resources/PYBv10b.pdf>`_ (2.4MiB PDF)
|
* v1.1
|
||||||
* `PYBv1.0 metric dimensions <http://micropython.org/resources/PYBv10b-metric-dimensions.pdf>`_ (360KiB PDF)
|
* `PYBv1.1 schematics and layout <https://micropython.org/resources/PYBv11.pdf>`_ (2.9MiB PDF)
|
||||||
* `PYBv1.0 imperial dimensions <http://micropython.org/resources/PYBv10b-imperial-dimensions.pdf>`_ (360KiB PDF)
|
* v1.0
|
||||||
|
* `PYBv1.0 schematics and layout <http://micropython.org/resources/PYBv10b.pdf>`_ (2.4MiB PDF)
|
||||||
|
* `PYBv1.0 metric dimensions <http://micropython.org/resources/PYBv10b-metric-dimensions.pdf>`_ (360KiB PDF)
|
||||||
|
* `PYBv1.0 imperial dimensions <http://micropython.org/resources/PYBv10b-imperial-dimensions.pdf>`_ (360KiB PDF)
|
||||||
|
|
||||||
For the official skin modules:
|
For the official skin modules:
|
||||||
|
|
||||||
|
|||||||
@ -3,22 +3,22 @@
|
|||||||
Quick reference for the pyboard
|
Quick reference for the pyboard
|
||||||
===============================
|
===============================
|
||||||
|
|
||||||
The below pinout is for PYBv1.0. You can also view pinouts for
|
The below pinout is for PYBv1.1. You can also view pinouts for
|
||||||
other versions of the pyboard:
|
other versions of the pyboard:
|
||||||
`PYBv1.1 <http://micropython.org/resources/pybv11-pinout.jpg>`__
|
`PYBv1.0 <http://micropython.org/resources/pybv10-pinout.jpg>`__
|
||||||
or `PYBLITEv1.0-AC <http://micropython.org/resources/pyblitev10ac-pinout.jpg>`__
|
or `PYBLITEv1.0-AC <http://micropython.org/resources/pyblitev10ac-pinout.jpg>`__
|
||||||
or `PYBLITEv1.0 <http://micropython.org/resources/pyblitev10-pinout.jpg>`__.
|
or `PYBLITEv1.0 <http://micropython.org/resources/pyblitev10-pinout.jpg>`__.
|
||||||
|
|
||||||
.. only:: not latex
|
.. only:: not latex
|
||||||
|
|
||||||
.. image:: http://micropython.org/resources/pybv10-pinout.jpg
|
.. image:: http://micropython.org/resources/pybv11-pinout.jpg
|
||||||
:alt: PYBv1.0 pinout
|
:alt: PYBv1.1 pinout
|
||||||
:width: 700px
|
:width: 700px
|
||||||
|
|
||||||
.. only:: latex
|
.. only:: latex
|
||||||
|
|
||||||
.. image:: http://micropython.org/resources/pybv10-pinout-800px.jpg
|
.. image:: http://micropython.org/resources/pybv11-pinout-800px.jpg
|
||||||
:alt: PYBv1.0 pinout
|
:alt: PYBv1.1 pinout
|
||||||
|
|
||||||
Below is a quick reference for the pyboard. If it is your first time working with
|
Below is a quick reference for the pyboard. If it is your first time working with
|
||||||
this board please consider reading the following sections first:
|
this board please consider reading the following sections first:
|
||||||
@ -199,16 +199,25 @@ See :ref:`pyb.SPI <pyb.SPI>`. ::
|
|||||||
I2C bus
|
I2C bus
|
||||||
-------
|
-------
|
||||||
|
|
||||||
See :ref:`pyb.I2C <pyb.I2C>`. ::
|
Hardware I2C is available on the X and Y halves of the pyboard via ``I2C('X')``
|
||||||
|
and ``I2C('Y')``. Alternatively pass in the integer identifier of the peripheral,
|
||||||
|
eg ``I2C(1)``. Software I2C is also available by explicitly specifying the
|
||||||
|
``scl`` and ``sda`` pins instead of the bus name. For more details see
|
||||||
|
:ref:`machine.I2C <machine.I2C>`. ::
|
||||||
|
|
||||||
from pyb import I2C
|
from machine import I2C
|
||||||
|
|
||||||
i2c = I2C(1, I2C.MASTER, baudrate=100000)
|
i2c = I2C('X', freq=400000) # create hardware I2c object
|
||||||
i2c.scan() # returns list of slave addresses
|
i2c = I2C(scl='X1', sda='X2', freq=100000) # create software I2C object
|
||||||
i2c.send('hello', 0x42) # send 5 bytes to slave with address 0x42
|
|
||||||
i2c.recv(5, 0x42) # receive 5 bytes from slave
|
i2c.scan() # returns list of slave addresses
|
||||||
i2c.mem_read(2, 0x42, 0x10) # read 2 bytes from slave 0x42, slave memory 0x10
|
i2c.writeto(0x42, 'hello') # write 5 bytes to slave with address 0x42
|
||||||
i2c.mem_write('xy', 0x42, 0x10) # write 2 bytes to slave 0x42, slave memory 0x10
|
i2c.readfrom(0x42, 5) # read 5 bytes from slave
|
||||||
|
|
||||||
|
i2c.readfrom_mem(0x42, 0x10, 2) # read 2 bytes from slave 0x42, slave memory 0x10
|
||||||
|
i2c.writeto_mem(0x42, 0x10, 'xy') # write 2 bytes to slave 0x42, slave memory 0x10
|
||||||
|
|
||||||
|
Note: for legacy I2C support see :ref:`pyb.I2C <pyb.I2C>`.
|
||||||
|
|
||||||
CAN bus (controller area network)
|
CAN bus (controller area network)
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
|||||||
@ -96,8 +96,8 @@ If something goes wrong, you can reset the board in two ways. The first is to pr
|
|||||||
at the MicroPython prompt, which performs a soft reset. You will see a message something like ::
|
at the MicroPython prompt, which performs a soft reset. You will see a message something like ::
|
||||||
|
|
||||||
>>>
|
>>>
|
||||||
PYB: sync filesystems
|
MPY: sync filesystems
|
||||||
PYB: soft reboot
|
MPY: soft reboot
|
||||||
Micro Python v1.0 on 2014-05-03; PYBv1.0 with STM32F405RG
|
Micro Python v1.0 on 2014-05-03; PYBv1.0 with STM32F405RG
|
||||||
Type "help()" for more information.
|
Type "help()" for more information.
|
||||||
>>>
|
>>>
|
||||||
|
|||||||
@ -174,8 +174,8 @@ variables no longer exist:
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
PYB: sync filesystems
|
MPY: sync filesystems
|
||||||
PYB: soft reboot
|
MPY: soft reboot
|
||||||
MicroPython v1.5-51-g6f70283-dirty on 2015-10-30; PYBv1.0 with STM32F405RG
|
MicroPython v1.5-51-g6f70283-dirty on 2015-10-30; PYBv1.0 with STM32F405RG
|
||||||
Type "help()" for more information.
|
Type "help()" for more information.
|
||||||
>>> dir()
|
>>> dir()
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
.. _speed_python:
|
||||||
|
|
||||||
Maximising MicroPython Speed
|
Maximising MicroPython Speed
|
||||||
============================
|
============================
|
||||||
|
|
||||||
|
|||||||
@ -178,7 +178,7 @@ Details on sleep modes
|
|||||||
* ``machine.idle()``: Power consumption: ~12mA (in WLAN STA mode). Wake sources:
|
* ``machine.idle()``: Power consumption: ~12mA (in WLAN STA mode). Wake sources:
|
||||||
any hardware interrupt (including systick with period of 1ms), no special
|
any hardware interrupt (including systick with period of 1ms), no special
|
||||||
configuration required.
|
configuration required.
|
||||||
* ``machine.sleep()``: 950uA (in WLAN STA mode). Wake sources are ``Pin``, ``RTC``
|
* ``machine.lightsleep()``: 950uA (in WLAN STA mode). Wake sources are ``Pin``, ``RTC``
|
||||||
and ``WLAN``
|
and ``WLAN``
|
||||||
* ``machine.deepsleep()``: ~350uA. Wake sources are ``Pin`` and ``RTC``.
|
* ``machine.deepsleep()``: ~350uA. Wake sources are ``Pin`` and ``RTC``.
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ See the :mod:`machine` module::
|
|||||||
machine.unique_id() # return the 6-byte unique id of the board (the WiPy's MAC address)
|
machine.unique_id() # return the 6-byte unique id of the board (the WiPy's MAC address)
|
||||||
|
|
||||||
machine.idle() # average current decreases to (~12mA), any interrupts wake it up
|
machine.idle() # average current decreases to (~12mA), any interrupts wake it up
|
||||||
machine.sleep() # everything except for WLAN is powered down (~950uA avg. current)
|
machine.lightsleep() # everything except for WLAN is powered down (~950uA avg. current)
|
||||||
# wakes from Pin, RTC or WLAN
|
# wakes from Pin, RTC or WLAN
|
||||||
machine.deepsleep() # deepest sleep mode, MCU starts from reset. Wakes from Pin and RTC.
|
machine.deepsleep() # deepest sleep mode, MCU starts from reset. Wakes from Pin and RTC.
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ See :ref:`machine.RTC <machine.RTC>` ::
|
|||||||
rtc_i = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.SLEEP)
|
rtc_i = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.SLEEP)
|
||||||
|
|
||||||
# go into suspended mode waiting for the RTC alarm to expire and wake us up
|
# go into suspended mode waiting for the RTC alarm to expire and wake us up
|
||||||
machine.sleep()
|
machine.lightsleep()
|
||||||
|
|
||||||
SD card
|
SD card
|
||||||
-------
|
-------
|
||||||
@ -199,7 +199,7 @@ See :ref:`network.WLAN <network.WLAN>` and :mod:`machine`. ::
|
|||||||
# enable wake on WLAN
|
# enable wake on WLAN
|
||||||
wlan.irq(trigger=WLAN.ANY_EVENT, wake=machine.SLEEP)
|
wlan.irq(trigger=WLAN.ANY_EVENT, wake=machine.SLEEP)
|
||||||
# go to sleep
|
# go to sleep
|
||||||
machine.sleep()
|
machine.lightsleep()
|
||||||
# now, connect to the FTP or the Telnet server and the WiPy will wake-up
|
# now, connect to the FTP or the Telnet server and the WiPy will wake-up
|
||||||
|
|
||||||
Telnet and FTP server
|
Telnet and FTP server
|
||||||
|
|||||||
@ -120,7 +120,7 @@ If something goes wrong, you can reset the board in two ways. The first is to pr
|
|||||||
at the MicroPython prompt, which performs a soft reset. You will see a message something like::
|
at the MicroPython prompt, which performs a soft reset. You will see a message something like::
|
||||||
|
|
||||||
>>>
|
>>>
|
||||||
PYB: soft reboot
|
MPY: soft reboot
|
||||||
MicroPython v1.4.6-146-g1d8b5e5 on 2015-10-21; WiPy with CC3200
|
MicroPython v1.4.6-146-g1d8b5e5 on 2015-10-21; WiPy with CC3200
|
||||||
Type "help()" for more information.
|
Type "help()" for more information.
|
||||||
>>>
|
>>>
|
||||||
|
|||||||
17
drivers/cyw43/README.md
Normal file
17
drivers/cyw43/README.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
CYW43xx WiFi SoC driver
|
||||||
|
=======================
|
||||||
|
|
||||||
|
This is a driver for the CYW43xx WiFi SoC.
|
||||||
|
|
||||||
|
There are four layers to the driver:
|
||||||
|
|
||||||
|
1. SDIO bus interface, provided by the host device/system.
|
||||||
|
|
||||||
|
2. Low-level CYW43xx interface, managing the bus, control messages, Ethernet
|
||||||
|
frames and asynchronous events. Includes download of SoC firmware. The
|
||||||
|
header file `cyw43_ll.h` defines the interface to this layer.
|
||||||
|
|
||||||
|
3. Mid-level CYW43xx control, to control and set WiFi parameters and manage
|
||||||
|
events. See `cyw43_ctrl.c`.
|
||||||
|
|
||||||
|
4. TCP/IP bindings to lwIP. See `cyw43_lwip.c`.
|
||||||
135
drivers/cyw43/cyw43.h
Normal file
135
drivers/cyw43/cyw43.h
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018-2019 Damien P. George
|
||||||
|
*
|
||||||
|
* 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 MICROPY_INCLUDED_STM32_CYW43_H
|
||||||
|
#define MICROPY_INCLUDED_STM32_CYW43_H
|
||||||
|
|
||||||
|
#include "lwip/netif.h"
|
||||||
|
#include "lwip/dhcp.h"
|
||||||
|
#include "lib/netutils/dhcpserver.h"
|
||||||
|
#include "drivers/cyw43/cyw43_ll.h"
|
||||||
|
|
||||||
|
// For trace_flags
|
||||||
|
#define CYW43_TRACE_ASYNC_EV (0x0001)
|
||||||
|
#define CYW43_TRACE_ETH_TX (0x0002)
|
||||||
|
#define CYW43_TRACE_ETH_RX (0x0004)
|
||||||
|
#define CYW43_TRACE_ETH_FULL (0x0008)
|
||||||
|
#define CYW43_TRACE_MAC (0x0010)
|
||||||
|
|
||||||
|
// Return value of cyw43_wifi_link_status
|
||||||
|
#define CYW43_LINK_DOWN (0)
|
||||||
|
#define CYW43_LINK_JOIN (1)
|
||||||
|
#define CYW43_LINK_NOIP (2)
|
||||||
|
#define CYW43_LINK_UP (3)
|
||||||
|
#define CYW43_LINK_FAIL (-1)
|
||||||
|
#define CYW43_LINK_NONET (-2)
|
||||||
|
#define CYW43_LINK_BADAUTH (-3)
|
||||||
|
|
||||||
|
typedef struct _cyw43_t {
|
||||||
|
cyw43_ll_t cyw43_ll;
|
||||||
|
|
||||||
|
uint8_t itf_state;
|
||||||
|
uint32_t trace_flags;
|
||||||
|
|
||||||
|
// State for async events
|
||||||
|
volatile uint32_t wifi_scan_state;
|
||||||
|
uint32_t wifi_join_state;
|
||||||
|
void *wifi_scan_env;
|
||||||
|
int (*wifi_scan_cb)(void*, const cyw43_ev_scan_result_t*);
|
||||||
|
|
||||||
|
// Pending things to do
|
||||||
|
bool pend_disassoc;
|
||||||
|
bool pend_rejoin;
|
||||||
|
bool pend_rejoin_wpa;
|
||||||
|
|
||||||
|
// AP settings
|
||||||
|
uint8_t ap_channel;
|
||||||
|
uint8_t ap_auth;
|
||||||
|
uint8_t ap_ssid_len;
|
||||||
|
uint8_t ap_key_len;
|
||||||
|
uint8_t ap_ssid[32];
|
||||||
|
uint8_t ap_key[64];
|
||||||
|
|
||||||
|
// lwIP data
|
||||||
|
struct netif netif[2];
|
||||||
|
struct dhcp dhcp_client;
|
||||||
|
dhcp_server_t dhcp_server;
|
||||||
|
} cyw43_t;
|
||||||
|
|
||||||
|
extern cyw43_t cyw43_state;
|
||||||
|
extern void (*cyw43_poll)(void);
|
||||||
|
extern uint32_t cyw43_sleep;
|
||||||
|
|
||||||
|
void cyw43_init(cyw43_t *self);
|
||||||
|
void cyw43_deinit(cyw43_t *self);
|
||||||
|
|
||||||
|
int cyw43_ioctl(cyw43_t *self, uint32_t cmd, size_t len, uint8_t *buf, uint32_t iface);
|
||||||
|
int cyw43_send_ethernet(cyw43_t *self, int itf, size_t len, const void *buf, bool is_pbuf);
|
||||||
|
|
||||||
|
int cyw43_wifi_pm(cyw43_t *self, uint32_t pm);
|
||||||
|
int cyw43_wifi_link_status(cyw43_t *self, int itf);
|
||||||
|
void cyw43_wifi_set_up(cyw43_t *self, int itf, bool up);
|
||||||
|
int cyw43_wifi_get_mac(cyw43_t *self, int itf, uint8_t mac[6]);
|
||||||
|
int cyw43_wifi_scan(cyw43_t *self, cyw43_wifi_scan_options_t *opts, void *env, int (*result_cb)(void*, const cyw43_ev_scan_result_t*));
|
||||||
|
|
||||||
|
static inline bool cyw43_wifi_scan_active(cyw43_t *self) {
|
||||||
|
return self->wifi_scan_state == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cyw43_wifi_join(cyw43_t *self, size_t ssid_len, const uint8_t *ssid, size_t key_len, const uint8_t *key, uint32_t auth_type, const uint8_t *bssid, uint32_t channel);
|
||||||
|
int cyw43_wifi_leave(cyw43_t *self, int itf);
|
||||||
|
|
||||||
|
static inline void cyw43_wifi_ap_get_ssid(cyw43_t *self, size_t *len, const uint8_t **buf) {
|
||||||
|
*len = self->ap_ssid_len;
|
||||||
|
*buf = self->ap_ssid;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void cyw43_wifi_ap_set_channel(cyw43_t *self, uint32_t channel) {
|
||||||
|
self->ap_channel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void cyw43_wifi_ap_set_ssid(cyw43_t *self, size_t len, const uint8_t *buf) {
|
||||||
|
self->ap_ssid_len = MIN(len, sizeof(self->ap_ssid));
|
||||||
|
memcpy(self->ap_ssid, buf, self->ap_ssid_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void cyw43_wifi_ap_set_password(cyw43_t *self, size_t len, const uint8_t *buf) {
|
||||||
|
self->ap_key_len = MIN(len, sizeof(self->ap_key));
|
||||||
|
memcpy(self->ap_key, buf, self->ap_key_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void cyw43_wifi_ap_set_auth(cyw43_t *self, uint32_t auth) {
|
||||||
|
self->ap_auth = auth;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cyw43_wifi_ap_get_stas(cyw43_t *self, int *num_stas, uint8_t *macs);
|
||||||
|
|
||||||
|
void cyw43_tcpip_init(cyw43_t *self, int itf);
|
||||||
|
void cyw43_tcpip_deinit(cyw43_t *self, int itf);
|
||||||
|
void cyw43_tcpip_set_link_up(cyw43_t *self, int itf);
|
||||||
|
void cyw43_tcpip_set_link_down(cyw43_t *self, int itf);
|
||||||
|
int cyw43_tcpip_link_status(cyw43_t *self, int itf);
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_STM32_CYW43_H
|
||||||
588
drivers/cyw43/cyw43_ctrl.c
Normal file
588
drivers/cyw43/cyw43_ctrl.c
Normal file
@ -0,0 +1,588 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018-2019 Damien P. George
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "py/mphal.h"
|
||||||
|
#include "drivers/cyw43/cyw43.h"
|
||||||
|
#include "pendsv.h"
|
||||||
|
#include "sdio.h"
|
||||||
|
|
||||||
|
#define CYW_ENTER MICROPY_PY_LWIP_ENTER
|
||||||
|
#define CYW_EXIT MICROPY_PY_LWIP_EXIT
|
||||||
|
|
||||||
|
#ifdef pyb_pin_WL_HOST_WAKE
|
||||||
|
#define USE_SDIOIT (0)
|
||||||
|
#else
|
||||||
|
#define USE_SDIOIT (1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CYW43_SLEEP_MAX (50)
|
||||||
|
|
||||||
|
#define WIFI_JOIN_STATE_ACTIVE (0x0001)
|
||||||
|
#define WIFI_JOIN_STATE_FAIL (0x0002)
|
||||||
|
#define WIFI_JOIN_STATE_NONET (0x0003)
|
||||||
|
#define WIFI_JOIN_STATE_BADAUTH (0x0004)
|
||||||
|
#define WIFI_JOIN_STATE_AUTH (0x0200)
|
||||||
|
#define WIFI_JOIN_STATE_LINK (0x0400)
|
||||||
|
#define WIFI_JOIN_STATE_KEYED (0x0800)
|
||||||
|
#define WIFI_JOIN_STATE_ALL (0x0e01)
|
||||||
|
|
||||||
|
cyw43_t cyw43_state;
|
||||||
|
void (*cyw43_poll)(void);
|
||||||
|
uint32_t cyw43_sleep;
|
||||||
|
|
||||||
|
STATIC void cyw43_poll_func(void);
|
||||||
|
STATIC void cyw43_wifi_ap_init(cyw43_t *self);
|
||||||
|
STATIC void cyw43_wifi_ap_set_up(cyw43_t *self, bool up);
|
||||||
|
|
||||||
|
static inline uint32_t cyw43_get_be16(const uint8_t *buf) {
|
||||||
|
return buf[0] << 8 | buf[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t cyw43_get_be32(const uint8_t *buf) {
|
||||||
|
return buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void cyw43_delay_ms(uint32_t ms) {
|
||||||
|
mp_hal_delay_ms(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
// Initialisation and polling
|
||||||
|
|
||||||
|
void cyw43_init(cyw43_t *self) {
|
||||||
|
#ifdef pyb_pin_WL_HOST_WAKE
|
||||||
|
mp_hal_pin_config(pyb_pin_WL_HOST_WAKE, MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_NONE, 0);
|
||||||
|
#endif
|
||||||
|
mp_hal_pin_config(pyb_pin_WL_REG_ON, MP_HAL_PIN_MODE_OUTPUT, MP_HAL_PIN_PULL_NONE, 0);
|
||||||
|
mp_hal_pin_low(pyb_pin_WL_REG_ON);
|
||||||
|
#ifdef pyb_pin_WL_RFSW_VDD
|
||||||
|
mp_hal_pin_config(pyb_pin_WL_RFSW_VDD, MP_HAL_PIN_MODE_OUTPUT, MP_HAL_PIN_PULL_NONE, 0); // RF-switch power
|
||||||
|
mp_hal_pin_low(pyb_pin_WL_RFSW_VDD);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cyw43_ll_init(&self->cyw43_ll, self);
|
||||||
|
|
||||||
|
self->itf_state = 0;
|
||||||
|
self->wifi_scan_state = 0;
|
||||||
|
self->wifi_join_state = 0;
|
||||||
|
self->pend_disassoc = false;
|
||||||
|
self->pend_rejoin= false;
|
||||||
|
self->pend_rejoin_wpa = false;
|
||||||
|
self->ap_channel = 3;
|
||||||
|
self->ap_ssid_len = 0;
|
||||||
|
self->ap_key_len = 0;
|
||||||
|
|
||||||
|
cyw43_poll = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cyw43_deinit(cyw43_t *self) {
|
||||||
|
CYW_ENTER
|
||||||
|
|
||||||
|
cyw43_ll_bus_sleep(&self->cyw43_ll, true);
|
||||||
|
cyw43_delay_ms(2);
|
||||||
|
cyw43_tcpip_deinit(self, 0);
|
||||||
|
cyw43_tcpip_deinit(self, 1);
|
||||||
|
|
||||||
|
self->itf_state = 0;
|
||||||
|
|
||||||
|
// Disable async polling
|
||||||
|
SDMMC1->MASK &= ~SDMMC_MASK_SDIOITIE;
|
||||||
|
cyw43_poll = NULL;
|
||||||
|
|
||||||
|
#ifdef pyb_pin_WL_RFSW_VDD
|
||||||
|
// Turn the RF-switch off
|
||||||
|
mp_hal_pin_low(pyb_pin_WL_RFSW_VDD);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Power down the WL chip and the SDIO bus
|
||||||
|
mp_hal_pin_low(pyb_pin_WL_REG_ON);
|
||||||
|
sdio_deinit();
|
||||||
|
|
||||||
|
CYW_EXIT
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC int cyw43_ensure_up(cyw43_t *self) {
|
||||||
|
if (cyw43_poll != NULL) {
|
||||||
|
cyw43_ll_bus_sleep(&self->cyw43_ll, false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CYW_ENTER
|
||||||
|
|
||||||
|
// Disable the netif if it was previously up
|
||||||
|
cyw43_tcpip_deinit(self, CYW43_ITF_STA);
|
||||||
|
cyw43_tcpip_deinit(self, CYW43_ITF_AP);
|
||||||
|
self->itf_state = 0;
|
||||||
|
|
||||||
|
// Reset and power up the WL chip
|
||||||
|
mp_hal_pin_low(pyb_pin_WL_REG_ON);
|
||||||
|
cyw43_delay_ms(20);
|
||||||
|
mp_hal_pin_high(pyb_pin_WL_REG_ON);
|
||||||
|
cyw43_delay_ms(50);
|
||||||
|
|
||||||
|
// Initialise SDIO bus
|
||||||
|
// IRQ priority only needs to be higher than CYW_ENTER/EXIT protection (PENDSV)
|
||||||
|
sdio_init(NVIC_EncodePriority(NVIC_PRIORITYGROUP_4, 14, 0));
|
||||||
|
|
||||||
|
// Initialise the low-level driver
|
||||||
|
uint8_t mac[6];
|
||||||
|
mp_hal_get_mac(MP_HAL_MAC_WLAN0, mac);
|
||||||
|
int ret = cyw43_ll_bus_init(&self->cyw43_ll, mac);
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
CYW_EXIT
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable async events from low-level driver
|
||||||
|
cyw43_sleep = CYW43_SLEEP_MAX;
|
||||||
|
cyw43_poll = cyw43_poll_func;
|
||||||
|
#if USE_SDIOIT
|
||||||
|
SDMMC1->MASK |= SDMMC_MASK_SDIOITIE;
|
||||||
|
#else
|
||||||
|
extern void extint_set(const pin_obj_t *pin, uint32_t mode);
|
||||||
|
extint_set(pyb_pin_WL_HOST_WAKE, GPIO_MODE_IT_FALLING);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CYW_EXIT
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function must always be executed at the level where CYW_ENTER is effectively active
|
||||||
|
STATIC void cyw43_poll_func(void) {
|
||||||
|
if (cyw43_poll == NULL) {
|
||||||
|
// Poll scheduled during deinit, just ignore it
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cyw43_t *self = &cyw43_state;
|
||||||
|
cyw43_ll_process_packets(&self->cyw43_ll);
|
||||||
|
|
||||||
|
if (self->pend_disassoc) {
|
||||||
|
self->pend_disassoc = false;
|
||||||
|
cyw43_ll_ioctl(&self->cyw43_ll, CYW43_IOCTL_SET_DISASSOC, 0, NULL, CYW43_ITF_STA);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->pend_rejoin_wpa) {
|
||||||
|
self->pend_rejoin_wpa = false;
|
||||||
|
cyw43_ll_wifi_set_wpa_auth(&self->cyw43_ll);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->pend_rejoin) {
|
||||||
|
self->pend_rejoin = false;
|
||||||
|
cyw43_ll_wifi_rejoin(&self->cyw43_ll);
|
||||||
|
self->wifi_join_state = WIFI_JOIN_STATE_ACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cyw43_sleep == 0) {
|
||||||
|
cyw43_ll_bus_sleep(&self->cyw43_ll, true);
|
||||||
|
#if !USE_SDIOIT
|
||||||
|
sdio_deinit(); // save power while WLAN bus sleeps
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if USE_SDIOIT
|
||||||
|
SDMMC1->MASK |= SDMMC_MASK_SDIOITIE;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
// Callback interface to low-level driver
|
||||||
|
|
||||||
|
int cyw43_cb_read_host_interrupt_pin(void *cb_data) {
|
||||||
|
#ifdef pyb_pin_WL_HOST_WAKE
|
||||||
|
return mp_hal_pin_read(pyb_pin_WL_HOST_WAKE);
|
||||||
|
#else
|
||||||
|
return mp_hal_pin_read(pyb_pin_WL_SDIO_1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void cyw43_cb_ensure_awake(void *cb_data) {
|
||||||
|
cyw43_sleep = CYW43_SLEEP_MAX;
|
||||||
|
#if !USE_SDIOIT
|
||||||
|
if (__HAL_RCC_SDMMC1_IS_CLK_DISABLED()) {
|
||||||
|
__HAL_RCC_SDMMC1_CLK_ENABLE(); // enable SDIO peripheral
|
||||||
|
sdio_enable_high_speed_4bit();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC const char *cyw43_async_event_name_table[89] = {
|
||||||
|
[0 ... 88] = NULL,
|
||||||
|
[CYW43_EV_SET_SSID] = "SET_SSID",
|
||||||
|
[CYW43_EV_JOIN] = "JOIN",
|
||||||
|
[CYW43_EV_AUTH] = "AUTH",
|
||||||
|
[CYW43_EV_DEAUTH_IND] = "DEAUTH_IND",
|
||||||
|
[CYW43_EV_ASSOC] = "ASSOC",
|
||||||
|
[CYW43_EV_DISASSOC] = "DISASSOC",
|
||||||
|
[CYW43_EV_DISASSOC_IND] = "DISASSOC_IND",
|
||||||
|
[CYW43_EV_LINK] = "LINK",
|
||||||
|
[CYW43_EV_PSK_SUP] = "PSK_SUP",
|
||||||
|
[CYW43_EV_ESCAN_RESULT] = "ESCAN_RESULT",
|
||||||
|
[CYW43_EV_CSA_COMPLETE_IND] = "CSA_COMPLETE_IND",
|
||||||
|
[CYW43_EV_ASSOC_REQ_IE] = "ASSOC_REQ_IE",
|
||||||
|
[CYW43_EV_ASSOC_RESP_IE] = "ASSOC_RESP_IE",
|
||||||
|
};
|
||||||
|
|
||||||
|
STATIC void cyw43_dump_async_event(const cyw43_async_event_t *ev) {
|
||||||
|
printf("[% 8d] ASYNC(%04x,",
|
||||||
|
mp_hal_ticks_ms(),
|
||||||
|
(unsigned int)ev->flags
|
||||||
|
);
|
||||||
|
if (ev->event_type < MP_ARRAY_SIZE(cyw43_async_event_name_table)
|
||||||
|
&& cyw43_async_event_name_table[ev->event_type] != NULL) {
|
||||||
|
printf("%s", cyw43_async_event_name_table[ev->event_type]);
|
||||||
|
} else {
|
||||||
|
printf("%u", (unsigned int)ev->event_type);
|
||||||
|
}
|
||||||
|
printf(",%u,%u,%u)\n",
|
||||||
|
(unsigned int)ev->status,
|
||||||
|
(unsigned int)ev->reason,
|
||||||
|
(unsigned int)ev->interface
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cyw43_cb_process_async_event(void *cb_data, const cyw43_async_event_t *ev) {
|
||||||
|
cyw43_t *self = cb_data;
|
||||||
|
|
||||||
|
if (self->trace_flags & CYW43_TRACE_ASYNC_EV) {
|
||||||
|
cyw43_dump_async_event(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ev->event_type == CYW43_EV_ESCAN_RESULT && self->wifi_scan_state == 1) {
|
||||||
|
// Escan result event
|
||||||
|
if (ev->status == 8) {
|
||||||
|
// Partial result
|
||||||
|
int ret = self->wifi_scan_cb(self->wifi_scan_env, &ev->u.scan_result);
|
||||||
|
if (ret != 0) {
|
||||||
|
// TODO need to abort scan, or just ignore any more results
|
||||||
|
}
|
||||||
|
} else if (ev->status == 0) {
|
||||||
|
// Scan complete
|
||||||
|
self->wifi_scan_state = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (ev->event_type == CYW43_EV_DISASSOC) {
|
||||||
|
cyw43_tcpip_set_link_down(self, CYW43_ITF_STA);
|
||||||
|
self->wifi_join_state = 0x0000;
|
||||||
|
|
||||||
|
/*
|
||||||
|
} else if (ev->event_type == CYW43_EV_DISASSOC_IND) {
|
||||||
|
if (ev->interface == CYW43_ITF_AP) {
|
||||||
|
// Station disassociated with our AP, let DHCP server know so it can free the IP address
|
||||||
|
dhcp_server_disassoc(&self->dhcp_server, buf + 24);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// WiFi join events
|
||||||
|
} else if (ev->event_type == CYW43_EV_PRUNE) {
|
||||||
|
if (ev->status == 0 && ev->reason == 8) {
|
||||||
|
// RSN mismatch, retry join with WPA auth
|
||||||
|
self->pend_rejoin = true;
|
||||||
|
self->pend_rejoin_wpa = true;
|
||||||
|
pendsv_schedule_dispatch(PENDSV_DISPATCH_CYW43, cyw43_poll_func);
|
||||||
|
}
|
||||||
|
} else if (ev->event_type == CYW43_EV_SET_SSID) {
|
||||||
|
if (ev->status == 0) {
|
||||||
|
// Success setting SSID
|
||||||
|
} else if (ev->status == 3 && ev->reason == 0) {
|
||||||
|
self->wifi_join_state = WIFI_JOIN_STATE_NONET;
|
||||||
|
// No matching SSID found (could be out of range, or down)
|
||||||
|
} else {
|
||||||
|
// Other failure setting SSID
|
||||||
|
self->wifi_join_state = WIFI_JOIN_STATE_FAIL;
|
||||||
|
}
|
||||||
|
} else if (ev->event_type == CYW43_EV_AUTH) {
|
||||||
|
if (ev->status == 0) {
|
||||||
|
self->wifi_join_state |= WIFI_JOIN_STATE_AUTH;
|
||||||
|
} else if (ev->status == 6) {
|
||||||
|
// Unsolicited auth packet, ignore it
|
||||||
|
} else {
|
||||||
|
// Cannot authenticate
|
||||||
|
self->wifi_join_state = WIFI_JOIN_STATE_BADAUTH;
|
||||||
|
}
|
||||||
|
} else if (ev->event_type == CYW43_EV_DEAUTH_IND) {
|
||||||
|
if (ev->status == 0 && ev->reason == 2) {
|
||||||
|
// Deauth, probably because password was wrong; disassociate
|
||||||
|
self->pend_disassoc = true;
|
||||||
|
pendsv_schedule_dispatch(PENDSV_DISPATCH_CYW43, cyw43_poll_func);
|
||||||
|
}
|
||||||
|
} else if (ev->event_type == CYW43_EV_LINK) {
|
||||||
|
if (ev->status == 0) {
|
||||||
|
if (ev->flags & 1) {
|
||||||
|
// Link is up
|
||||||
|
if (ev->interface == CYW43_ITF_STA) {
|
||||||
|
self->wifi_join_state |= WIFI_JOIN_STATE_LINK;
|
||||||
|
} else {
|
||||||
|
cyw43_tcpip_set_link_up(self, ev->interface);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Link is down
|
||||||
|
cyw43_tcpip_set_link_down(self, ev->interface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (ev->event_type == CYW43_EV_PSK_SUP) {
|
||||||
|
if (ev->status == 6) { // WLC_SUP_KEYED
|
||||||
|
self->wifi_join_state |= WIFI_JOIN_STATE_KEYED;
|
||||||
|
} else if ((ev->status == 4 || ev->status == 8 || ev->status == 11) && ev->reason == 15) {
|
||||||
|
// Timeout waiting for key exchange M1/M3/G1
|
||||||
|
// Probably at edge of the cell, retry
|
||||||
|
self->pend_rejoin = true;
|
||||||
|
pendsv_schedule_dispatch(PENDSV_DISPATCH_CYW43, cyw43_poll_func);
|
||||||
|
} else {
|
||||||
|
// PSK_SUP failure
|
||||||
|
self->wifi_join_state = WIFI_JOIN_STATE_BADAUTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->wifi_join_state == WIFI_JOIN_STATE_ALL) {
|
||||||
|
// STA connected
|
||||||
|
self->wifi_join_state = WIFI_JOIN_STATE_ACTIVE;
|
||||||
|
cyw43_tcpip_set_link_up(self, CYW43_ITF_STA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
// Ioctl and Ethernet interface
|
||||||
|
|
||||||
|
int cyw43_ioctl(cyw43_t *self, uint32_t cmd, size_t len, uint8_t *buf, uint32_t iface) {
|
||||||
|
int ret = cyw43_ensure_up(self);
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
CYW_ENTER
|
||||||
|
ret = cyw43_ll_ioctl(&self->cyw43_ll, cmd, len, buf, iface);
|
||||||
|
CYW_EXIT
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cyw43_send_ethernet(cyw43_t *self, int itf, size_t len, const void *buf, bool is_pbuf) {
|
||||||
|
int ret = cyw43_ensure_up(self);
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
CYW_ENTER
|
||||||
|
ret = cyw43_ll_send_ethernet(&self->cyw43_ll, itf, len, buf, is_pbuf);
|
||||||
|
CYW_EXIT
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
// WiFi control
|
||||||
|
|
||||||
|
STATIC int cyw43_wifi_on(cyw43_t *self, uint32_t country) {
|
||||||
|
int ret = cyw43_ensure_up(self);
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef pyb_pin_WL_RFSW_VDD
|
||||||
|
// Turn the RF-switch on
|
||||||
|
mp_hal_pin_high(pyb_pin_WL_RFSW_VDD);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
CYW_ENTER
|
||||||
|
ret = cyw43_ll_wifi_on(&self->cyw43_ll, country);
|
||||||
|
CYW_EXIT
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cyw43_wifi_pm(cyw43_t *self, uint32_t pm_in) {
|
||||||
|
int ret = cyw43_ensure_up(self);
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pm_in: 0x00adbrrm
|
||||||
|
uint32_t pm = pm_in & 0xf;
|
||||||
|
uint32_t pm_sleep_ret = (pm_in >> 4) & 0xff;
|
||||||
|
uint32_t li_bcn = (pm_in >> 12) & 0xf;
|
||||||
|
uint32_t li_dtim = (pm_in >> 16) & 0xf;
|
||||||
|
uint32_t li_assoc = (pm_in >> 20) & 0xf;
|
||||||
|
|
||||||
|
CYW_ENTER
|
||||||
|
ret = cyw43_ll_wifi_pm(&self->cyw43_ll, pm, pm_sleep_ret, li_bcn, li_dtim, li_assoc);
|
||||||
|
CYW_EXIT
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cyw43_wifi_get_mac(cyw43_t *self, int itf, uint8_t mac[6]) {
|
||||||
|
mp_hal_get_mac(MP_HAL_MAC_WLAN0, &mac[0]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MAKE_COUNTRY(a, b, rev) ((a) | (b) << 8 | (rev) << 16)
|
||||||
|
|
||||||
|
void cyw43_wifi_set_up(cyw43_t *self, int itf, bool up) {
|
||||||
|
if (up) {
|
||||||
|
if (self->itf_state == 0) {
|
||||||
|
uint32_t country;
|
||||||
|
extern char pyb_country_code[2];
|
||||||
|
if (pyb_country_code[0] == '\0' || pyb_country_code[1] == '\0') {
|
||||||
|
country = MAKE_COUNTRY('X', 'X', 17); // default to world-wide (passive ch 12-14)
|
||||||
|
} else {
|
||||||
|
country = MAKE_COUNTRY(pyb_country_code[0], pyb_country_code[1], 0);
|
||||||
|
}
|
||||||
|
cyw43_wifi_on(self, country);
|
||||||
|
cyw43_wifi_pm(self, 10 << 20 | 1 << 16 | 1 << 12 | 20 << 4 | 2);
|
||||||
|
}
|
||||||
|
if (itf == CYW43_ITF_AP) {
|
||||||
|
cyw43_wifi_ap_init(self);
|
||||||
|
cyw43_wifi_ap_set_up(self, true);
|
||||||
|
}
|
||||||
|
if ((self->itf_state & (1 << itf)) == 0) {
|
||||||
|
CYW_ENTER
|
||||||
|
cyw43_tcpip_deinit(self, itf);
|
||||||
|
cyw43_tcpip_init(self, itf);
|
||||||
|
self->itf_state |= 1 << itf;
|
||||||
|
CYW_EXIT
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (itf == CYW43_ITF_AP) {
|
||||||
|
cyw43_wifi_ap_set_up(self, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int cyw43_wifi_scan(cyw43_t *self, cyw43_wifi_scan_options_t *opts, void *env, int (*result_cb)(void*, const cyw43_ev_scan_result_t*)) {
|
||||||
|
if (self->itf_state == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cyw43_ensure_up(self);
|
||||||
|
|
||||||
|
CYW_ENTER
|
||||||
|
|
||||||
|
// Set state and callback data
|
||||||
|
self->wifi_scan_state = 1;
|
||||||
|
self->wifi_scan_env = env;
|
||||||
|
self->wifi_scan_cb = result_cb;
|
||||||
|
|
||||||
|
// Start the scan
|
||||||
|
int ret = cyw43_ll_wifi_scan(&self->cyw43_ll, opts);
|
||||||
|
|
||||||
|
CYW_EXIT
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cyw43_wifi_link_status(cyw43_t *self, int itf) {
|
||||||
|
if (itf == CYW43_ITF_STA) {
|
||||||
|
int s = self->wifi_join_state & 0xf;
|
||||||
|
if (s == WIFI_JOIN_STATE_ACTIVE) {
|
||||||
|
return CYW43_LINK_JOIN;
|
||||||
|
} else if (s == WIFI_JOIN_STATE_FAIL) {
|
||||||
|
return CYW43_LINK_FAIL;
|
||||||
|
} else if (s == WIFI_JOIN_STATE_NONET) {
|
||||||
|
return CYW43_LINK_NONET;
|
||||||
|
} else if (s == WIFI_JOIN_STATE_BADAUTH) {
|
||||||
|
return CYW43_LINK_BADAUTH;
|
||||||
|
} else {
|
||||||
|
return CYW43_LINK_DOWN;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return CYW43_LINK_DOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
// WiFi STA
|
||||||
|
|
||||||
|
int cyw43_wifi_join(cyw43_t *self, size_t ssid_len, const uint8_t *ssid, size_t key_len, const uint8_t *key, uint32_t auth_type, const uint8_t *bssid, uint32_t channel) {
|
||||||
|
int ret = cyw43_ensure_up(self);
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
CYW_ENTER
|
||||||
|
|
||||||
|
ret = cyw43_ll_wifi_join(&self->cyw43_ll, ssid_len, ssid, key_len, key, auth_type, bssid, channel);
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
|
// Wait for responses: EV_AUTH, EV_LINK, EV_SET_SSID, EV_PSK_SUP
|
||||||
|
// Will get EV_DEAUTH_IND if password is invalid
|
||||||
|
self->wifi_join_state = WIFI_JOIN_STATE_ACTIVE;
|
||||||
|
|
||||||
|
if (auth_type == 0) {
|
||||||
|
// For open security we don't need EV_PSK_SUP, so set that flag indicator now
|
||||||
|
self->wifi_join_state |= WIFI_JOIN_STATE_KEYED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CYW_EXIT
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cyw43_wifi_leave(cyw43_t *self, int itf) {
|
||||||
|
// Disassociate with SSID
|
||||||
|
return cyw43_ioctl(self, CYW43_IOCTL_SET_DISASSOC, 0, NULL, itf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
// WiFi AP
|
||||||
|
|
||||||
|
STATIC void cyw43_wifi_ap_init(cyw43_t *self) {
|
||||||
|
int ret = cyw43_ensure_up(self);
|
||||||
|
if (ret) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CYW_ENTER
|
||||||
|
cyw43_ll_wifi_ap_init(&self->cyw43_ll, self->ap_ssid_len, self->ap_ssid, self->ap_auth, self->ap_key_len, self->ap_key, self->ap_channel);
|
||||||
|
CYW_EXIT
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC void cyw43_wifi_ap_set_up(cyw43_t *self, bool up) {
|
||||||
|
int ret = cyw43_ensure_up(self);
|
||||||
|
if (ret) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CYW_ENTER
|
||||||
|
cyw43_ll_wifi_ap_set_up(&self->cyw43_ll, up);
|
||||||
|
CYW_EXIT
|
||||||
|
}
|
||||||
|
|
||||||
|
void cyw43_wifi_ap_get_stas(cyw43_t *self, int *num_stas, uint8_t *macs) {
|
||||||
|
int ret = cyw43_ensure_up(self);
|
||||||
|
if (ret) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CYW_ENTER
|
||||||
|
cyw43_ll_wifi_ap_get_stas(&self->cyw43_ll, num_stas, macs);
|
||||||
|
CYW_EXIT
|
||||||
|
}
|
||||||
135
drivers/cyw43/cyw43_ll.h
Normal file
135
drivers/cyw43/cyw43_ll.h
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018-2019 Damien P. George
|
||||||
|
*
|
||||||
|
* 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 MICROPY_INCLUDED_STM32_CYW43_LL_H
|
||||||
|
#define MICROPY_INCLUDED_STM32_CYW43_LL_H
|
||||||
|
|
||||||
|
// IOCTL commands
|
||||||
|
#define CYW43_IOCTL_GET_SSID (0x32)
|
||||||
|
#define CYW43_IOCTL_GET_CHANNEL (0x3a)
|
||||||
|
#define CYW43_IOCTL_SET_DISASSOC (0x69)
|
||||||
|
#define CYW43_IOCTL_GET_ANTDIV (0x7e)
|
||||||
|
#define CYW43_IOCTL_SET_ANTDIV (0x81)
|
||||||
|
#define CYW43_IOCTL_SET_MONITOR (0xd9)
|
||||||
|
#define CYW43_IOCTL_GET_VAR (0x20c)
|
||||||
|
#define CYW43_IOCTL_SET_VAR (0x20f)
|
||||||
|
|
||||||
|
// Async events, event_type field
|
||||||
|
#define CYW43_EV_SET_SSID (0)
|
||||||
|
#define CYW43_EV_JOIN (1)
|
||||||
|
#define CYW43_EV_AUTH (3)
|
||||||
|
#define CYW43_EV_DEAUTH_IND (6)
|
||||||
|
#define CYW43_EV_ASSOC (7)
|
||||||
|
#define CYW43_EV_DISASSOC (11)
|
||||||
|
#define CYW43_EV_DISASSOC_IND (12)
|
||||||
|
#define CYW43_EV_LINK (16)
|
||||||
|
#define CYW43_EV_PRUNE (23)
|
||||||
|
#define CYW43_EV_PSK_SUP (46)
|
||||||
|
#define CYW43_EV_ESCAN_RESULT (69)
|
||||||
|
#define CYW43_EV_CSA_COMPLETE_IND (80)
|
||||||
|
#define CYW43_EV_ASSOC_REQ_IE (87)
|
||||||
|
#define CYW43_EV_ASSOC_RESP_IE (88)
|
||||||
|
|
||||||
|
enum {
|
||||||
|
CYW43_ITF_STA,
|
||||||
|
CYW43_ITF_AP,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct _cyw43_ev_scan_result_t {
|
||||||
|
uint32_t _0[5];
|
||||||
|
uint8_t bssid[6];
|
||||||
|
uint16_t _1[2];
|
||||||
|
uint8_t ssid_len;
|
||||||
|
uint8_t ssid[32];
|
||||||
|
uint32_t _2[5];
|
||||||
|
uint16_t channel;
|
||||||
|
uint16_t _3;
|
||||||
|
uint8_t auth_mode;
|
||||||
|
int16_t rssi;
|
||||||
|
} cyw43_ev_scan_result_t;
|
||||||
|
|
||||||
|
typedef struct _cyw43_async_event_t {
|
||||||
|
uint16_t _0;
|
||||||
|
uint16_t flags;
|
||||||
|
uint32_t event_type;
|
||||||
|
uint32_t status;
|
||||||
|
uint32_t reason;
|
||||||
|
uint8_t _1[30];
|
||||||
|
uint8_t interface;
|
||||||
|
uint8_t _2;
|
||||||
|
union {
|
||||||
|
cyw43_ev_scan_result_t scan_result;
|
||||||
|
} u;
|
||||||
|
} cyw43_async_event_t;
|
||||||
|
|
||||||
|
typedef struct _cyw43_wifi_scan_options_t {
|
||||||
|
uint32_t version;
|
||||||
|
uint16_t action;
|
||||||
|
uint16_t _;
|
||||||
|
uint32_t ssid_len; // 0 to select all
|
||||||
|
uint8_t ssid[32];
|
||||||
|
uint8_t bssid[6];
|
||||||
|
int8_t bss_type; // fill with 0xff to select all
|
||||||
|
int8_t scan_type; // 0=active, 1=passive
|
||||||
|
int32_t nprobes;
|
||||||
|
int32_t active_time;
|
||||||
|
int32_t passive_time;
|
||||||
|
int32_t home_time;
|
||||||
|
int32_t channel_num;
|
||||||
|
uint16_t channel_list[1];
|
||||||
|
} cyw43_wifi_scan_options_t;
|
||||||
|
|
||||||
|
typedef struct _cyw43_ll_t {
|
||||||
|
uint32_t opaque[528];
|
||||||
|
} cyw43_ll_t;
|
||||||
|
|
||||||
|
void cyw43_ll_init(cyw43_ll_t *self, void *cb_data);
|
||||||
|
void cyw43_ll_deinit(cyw43_ll_t *self);
|
||||||
|
|
||||||
|
int cyw43_ll_bus_init(cyw43_ll_t *self, const uint8_t *mac);
|
||||||
|
void cyw43_ll_bus_sleep(cyw43_ll_t *self, bool can_sleep);
|
||||||
|
void cyw43_ll_process_packets(cyw43_ll_t *self);
|
||||||
|
int cyw43_ll_ioctl(cyw43_ll_t *self, uint32_t cmd, size_t len, uint8_t *buf, uint32_t iface);
|
||||||
|
int cyw43_ll_send_ethernet(cyw43_ll_t *self, int itf, size_t len, const void *buf, bool is_pbuf);
|
||||||
|
|
||||||
|
int cyw43_ll_wifi_on(cyw43_ll_t *self, uint32_t country);
|
||||||
|
int cyw43_ll_wifi_pm(cyw43_ll_t *self, uint32_t pm, uint32_t pm_sleep_ret, uint32_t li_bcn, uint32_t li_dtim, uint32_t li_assoc);
|
||||||
|
int cyw43_ll_wifi_scan(cyw43_ll_t *self, cyw43_wifi_scan_options_t *opts);
|
||||||
|
|
||||||
|
int cyw43_ll_wifi_join(cyw43_ll_t *self, size_t ssid_len, const uint8_t *ssid, size_t key_len, const uint8_t *key, uint32_t auth_type, const uint8_t *bssid, uint32_t channel);
|
||||||
|
void cyw43_ll_wifi_set_wpa_auth(cyw43_ll_t *self);
|
||||||
|
void cyw43_ll_wifi_rejoin(cyw43_ll_t *self);
|
||||||
|
|
||||||
|
int cyw43_ll_wifi_ap_init(cyw43_ll_t *self, size_t ssid_len, const uint8_t *ssid, uint32_t auth, size_t key_len, const uint8_t *key, uint32_t channel);
|
||||||
|
int cyw43_ll_wifi_ap_set_up(cyw43_ll_t *self, bool up);
|
||||||
|
int cyw43_ll_wifi_ap_get_stas(cyw43_ll_t *self, int *num_stas, uint8_t *macs);
|
||||||
|
|
||||||
|
// Callbacks to be provided by mid-level interface
|
||||||
|
int cyw43_cb_read_host_interrupt_pin(void *cb_data);
|
||||||
|
void cyw43_cb_ensure_awake(void *cb_data);
|
||||||
|
void cyw43_cb_process_async_event(void *cb_data, const cyw43_async_event_t *ev);
|
||||||
|
void cyw43_cb_process_ethernet(void *cb_data, int itf, size_t len, const uint8_t *buf);
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_STM32_CYW43_LL_H
|
||||||
197
drivers/cyw43/cyw43_lwip.c
Normal file
197
drivers/cyw43/cyw43_lwip.c
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018-2019 Damien P. George
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "py/mphal.h"
|
||||||
|
#include "lib/netutils/netutils.h"
|
||||||
|
#include "lwip/etharp.h"
|
||||||
|
#include "lwip/dns.h"
|
||||||
|
#include "lwip/apps/mdns.h"
|
||||||
|
#include "drivers/cyw43/cyw43.h"
|
||||||
|
|
||||||
|
STATIC void cyw43_ethernet_trace(cyw43_t *self, struct netif *netif, size_t len, const void *data, unsigned int flags) {
|
||||||
|
bool is_tx = flags & NETUTILS_TRACE_IS_TX;
|
||||||
|
if ((is_tx && (self->trace_flags & CYW43_TRACE_ETH_TX))
|
||||||
|
|| (!is_tx && (self->trace_flags & CYW43_TRACE_ETH_RX))) {
|
||||||
|
const uint8_t *buf;
|
||||||
|
if (len == (size_t)-1) {
|
||||||
|
// data is a pbuf
|
||||||
|
const struct pbuf *pbuf = data;
|
||||||
|
buf = pbuf->payload;
|
||||||
|
len = pbuf->len; // restricted to print only the first chunk of the pbuf
|
||||||
|
} else {
|
||||||
|
// data is actual data buffer
|
||||||
|
buf = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->trace_flags & CYW43_TRACE_MAC) {
|
||||||
|
printf("[% 8d] ETH%cX itf=%c%c len=%u", mp_hal_ticks_ms(), is_tx ? 'T' : 'R', netif->name[0], netif->name[1], len);
|
||||||
|
printf(" MAC type=%d subtype=%d data=", buf[0] >> 2 & 3, buf[0] >> 4);
|
||||||
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
printf(" %02x", buf[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->trace_flags & CYW43_TRACE_ETH_FULL) {
|
||||||
|
flags |= NETUTILS_TRACE_PAYLOAD;
|
||||||
|
}
|
||||||
|
netutils_ethernet_trace(MP_PYTHON_PRINTER, len, buf, flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC err_t cyw43_netif_output(struct netif *netif, struct pbuf *p) {
|
||||||
|
cyw43_t *self = netif->state;
|
||||||
|
if (self->trace_flags != 0) {
|
||||||
|
cyw43_ethernet_trace(self, netif, (size_t)-1, p, NETUTILS_TRACE_IS_TX | NETUTILS_TRACE_NEWLINE);
|
||||||
|
}
|
||||||
|
int itf = netif->name[1] - '0';
|
||||||
|
int ret = cyw43_send_ethernet(self, itf, p->tot_len, (void*)p, true);
|
||||||
|
if (ret) {
|
||||||
|
printf("[CYW43] send_ethernet failed: %d\n", ret);
|
||||||
|
return ERR_IF;
|
||||||
|
}
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC err_t cyw43_netif_init(struct netif *netif) {
|
||||||
|
netif->linkoutput = cyw43_netif_output;
|
||||||
|
netif->output = etharp_output;
|
||||||
|
netif->mtu = 1500;
|
||||||
|
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
|
||||||
|
cyw43_wifi_get_mac(netif->state, netif->name[1] - '0', netif->hwaddr);
|
||||||
|
netif->hwaddr_len = sizeof(netif->hwaddr);
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cyw43_tcpip_init(cyw43_t *self, int itf) {
|
||||||
|
ip_addr_t ipconfig[4];
|
||||||
|
#if LWIP_IPV6
|
||||||
|
#define IP(x) ((x).u_addr.ip4)
|
||||||
|
#else
|
||||||
|
#define IP(x) (x)
|
||||||
|
#endif
|
||||||
|
if (itf == 0) {
|
||||||
|
// need to zero out to get isconnected() working
|
||||||
|
IP4_ADDR(&IP(ipconfig[0]), 0, 0, 0, 0);
|
||||||
|
IP4_ADDR(&IP(ipconfig[2]), 192, 168, 0, 1);
|
||||||
|
} else {
|
||||||
|
IP4_ADDR(&IP(ipconfig[0]), 192, 168, 4, 1);
|
||||||
|
IP4_ADDR(&IP(ipconfig[2]), 192, 168, 4, 1);
|
||||||
|
}
|
||||||
|
IP4_ADDR(&IP(ipconfig[1]), 255, 255, 255, 0);
|
||||||
|
IP4_ADDR(&IP(ipconfig[3]), 8, 8, 8, 8);
|
||||||
|
#undef IP
|
||||||
|
|
||||||
|
struct netif *n = &self->netif[itf];
|
||||||
|
n->name[0] = 'w';
|
||||||
|
n->name[1] = '0' + itf;
|
||||||
|
#if LWIP_IPV6
|
||||||
|
netif_add(n, &ipconfig[0].u_addr.ip4, &ipconfig[1].u_addr.ip4, &ipconfig[2].u_addr.ip4, self, cyw43_netif_init, ethernet_input);
|
||||||
|
#else
|
||||||
|
netif_add(n, &ipconfig[0], &ipconfig[1], &ipconfig[2], self, cyw43_netif_init, netif_input);
|
||||||
|
#endif
|
||||||
|
netif_set_hostname(n, "PYBD");
|
||||||
|
netif_set_default(n);
|
||||||
|
netif_set_up(n);
|
||||||
|
|
||||||
|
if (itf == CYW43_ITF_STA) {
|
||||||
|
dns_setserver(0, &ipconfig[3]);
|
||||||
|
dhcp_set_struct(n, &self->dhcp_client);
|
||||||
|
dhcp_start(n);
|
||||||
|
} else {
|
||||||
|
dhcp_server_init(&self->dhcp_server, &ipconfig[0], &ipconfig[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if LWIP_MDNS_RESPONDER
|
||||||
|
// TODO better to call after IP address is set
|
||||||
|
char mdns_hostname[9];
|
||||||
|
memcpy(&mdns_hostname[0], "PYBD", 4);
|
||||||
|
mp_hal_get_mac_ascii(MP_HAL_MAC_WLAN0, 8, 4, &mdns_hostname[4]);
|
||||||
|
mdns_hostname[8] = '\0';
|
||||||
|
mdns_resp_add_netif(n, mdns_hostname, 60);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void cyw43_tcpip_deinit(cyw43_t *self, int itf) {
|
||||||
|
struct netif *n = &self->netif[itf];
|
||||||
|
if (itf == CYW43_ITF_STA) {
|
||||||
|
dhcp_stop(n);
|
||||||
|
} else {
|
||||||
|
dhcp_server_deinit(&self->dhcp_server);
|
||||||
|
}
|
||||||
|
#if LWIP_MDNS_RESPONDER
|
||||||
|
mdns_resp_remove_netif(n);
|
||||||
|
#endif
|
||||||
|
for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) {
|
||||||
|
if (netif == n) {
|
||||||
|
netif_remove(netif);
|
||||||
|
netif->ip_addr.addr = 0;
|
||||||
|
netif->flags = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cyw43_cb_process_ethernet(void *cb_data, int itf, size_t len, const uint8_t *buf) {
|
||||||
|
cyw43_t *self = cb_data;
|
||||||
|
struct netif *netif = &self->netif[itf];
|
||||||
|
if (self->trace_flags) {
|
||||||
|
cyw43_ethernet_trace(self, netif, len, buf, NETUTILS_TRACE_NEWLINE);
|
||||||
|
}
|
||||||
|
if (netif->flags & NETIF_FLAG_LINK_UP) {
|
||||||
|
struct pbuf *p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
|
||||||
|
if (p != NULL) {
|
||||||
|
pbuf_take(p, buf, len);
|
||||||
|
if (netif->input(p, netif) != ERR_OK) {
|
||||||
|
pbuf_free(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cyw43_tcpip_set_link_up(cyw43_t *self, int itf) {
|
||||||
|
netif_set_link_up(&self->netif[itf]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cyw43_tcpip_set_link_down(cyw43_t *self, int itf) {
|
||||||
|
netif_set_link_down(&self->netif[itf]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int cyw43_tcpip_link_status(cyw43_t *self, int itf) {
|
||||||
|
struct netif *netif = &self->netif[itf];
|
||||||
|
if ((netif->flags & (NETIF_FLAG_UP | NETIF_FLAG_LINK_UP))
|
||||||
|
== (NETIF_FLAG_UP | NETIF_FLAG_LINK_UP)) {
|
||||||
|
if (netif->ip_addr.addr != 0) {
|
||||||
|
return CYW43_LINK_UP;
|
||||||
|
} else {
|
||||||
|
return CYW43_LINK_NOIP;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return cyw43_wifi_link_status(self, itf);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
drivers/cyw43/libcyw43.a
Normal file
BIN
drivers/cyw43/libcyw43.a
Normal file
Binary file not shown.
@ -96,6 +96,7 @@ class SSD1306_I2C(SSD1306):
|
|||||||
self.i2c = i2c
|
self.i2c = i2c
|
||||||
self.addr = addr
|
self.addr = addr
|
||||||
self.temp = bytearray(2)
|
self.temp = bytearray(2)
|
||||||
|
self.write_list = [b'\x40', None] # Co=0, D/C#=1
|
||||||
super().__init__(width, height, external_vcc)
|
super().__init__(width, height, external_vcc)
|
||||||
|
|
||||||
def write_cmd(self, cmd):
|
def write_cmd(self, cmd):
|
||||||
@ -104,12 +105,8 @@ class SSD1306_I2C(SSD1306):
|
|||||||
self.i2c.writeto(self.addr, self.temp)
|
self.i2c.writeto(self.addr, self.temp)
|
||||||
|
|
||||||
def write_data(self, buf):
|
def write_data(self, buf):
|
||||||
self.temp[0] = self.addr << 1
|
self.write_list[1] = buf
|
||||||
self.temp[1] = 0x40 # Co=0, D/C#=1
|
self.i2c.writevto(self.addr, self.write_list)
|
||||||
self.i2c.start()
|
|
||||||
self.i2c.write(self.temp)
|
|
||||||
self.i2c.write(buf)
|
|
||||||
self.i2c.stop()
|
|
||||||
|
|
||||||
|
|
||||||
class SSD1306_SPI(SSD1306):
|
class SSD1306_SPI(SSD1306):
|
||||||
|
|||||||
@ -128,19 +128,14 @@ STATIC void mp_spiflash_write_cmd_addr(mp_spiflash_t *self, uint8_t cmd, uint32_
|
|||||||
|
|
||||||
STATIC int mp_spiflash_wait_sr(mp_spiflash_t *self, uint8_t mask, uint8_t val, uint32_t timeout) {
|
STATIC int mp_spiflash_wait_sr(mp_spiflash_t *self, uint8_t mask, uint8_t val, uint32_t timeout) {
|
||||||
uint8_t sr;
|
uint8_t sr;
|
||||||
for (; timeout; --timeout) {
|
do {
|
||||||
sr = mp_spiflash_read_cmd(self, CMD_RDSR, 1);
|
sr = mp_spiflash_read_cmd(self, CMD_RDSR, 1);
|
||||||
if ((sr & mask) == val) {
|
if ((sr & mask) == val) {
|
||||||
break;
|
return 0; // success
|
||||||
}
|
}
|
||||||
}
|
} while (timeout--);
|
||||||
if ((sr & mask) == val) {
|
|
||||||
return 0; // success
|
return -MP_ETIMEDOUT;
|
||||||
} else if (timeout == 0) {
|
|
||||||
return -MP_ETIMEDOUT;
|
|
||||||
} else {
|
|
||||||
return -MP_EIO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int mp_spiflash_wait_wel1(mp_spiflash_t *self) {
|
STATIC int mp_spiflash_wait_wel1(mp_spiflash_t *self) {
|
||||||
|
|||||||
193
extmod/extmod.mk
Normal file
193
extmod/extmod.mk
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
# This makefile fragment provides rules to build 3rd-party components for extmod modules
|
||||||
|
|
||||||
|
# this sets the config file for FatFs
|
||||||
|
CFLAGS_MOD += -DFFCONF_H=\"lib/oofatfs/ffconf.h\"
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# ussl
|
||||||
|
|
||||||
|
ifeq ($(MICROPY_PY_USSL),1)
|
||||||
|
CFLAGS_MOD += -DMICROPY_PY_USSL=1
|
||||||
|
ifeq ($(MICROPY_SSL_AXTLS),1)
|
||||||
|
CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I$(TOP)/lib/axtls/ssl -I$(TOP)/lib/axtls/crypto -I$(TOP)/extmod/axtls-include
|
||||||
|
AXTLS_DIR = lib/axtls
|
||||||
|
$(BUILD)/$(AXTLS_DIR)/%.o: CFLAGS += -Wno-all -Wno-unused-parameter -Wno-uninitialized -Wno-sign-compare -Wno-old-style-definition $(AXTLS_DEFS_EXTRA)
|
||||||
|
SRC_MOD += $(addprefix $(AXTLS_DIR)/,\
|
||||||
|
ssl/asn1.c \
|
||||||
|
ssl/loader.c \
|
||||||
|
ssl/tls1.c \
|
||||||
|
ssl/tls1_svr.c \
|
||||||
|
ssl/tls1_clnt.c \
|
||||||
|
ssl/x509.c \
|
||||||
|
crypto/aes.c \
|
||||||
|
crypto/bigint.c \
|
||||||
|
crypto/crypto_misc.c \
|
||||||
|
crypto/hmac.c \
|
||||||
|
crypto/md5.c \
|
||||||
|
crypto/rsa.c \
|
||||||
|
crypto/sha1.c \
|
||||||
|
)
|
||||||
|
else ifeq ($(MICROPY_SSL_MBEDTLS),1)
|
||||||
|
MBEDTLS_DIR = lib/mbedtls
|
||||||
|
CFLAGS_MOD += -DMICROPY_SSL_MBEDTLS=1 -I$(TOP)/$(MBEDTLS_DIR)/include
|
||||||
|
SRC_MOD += $(addprefix $(MBEDTLS_DIR)/library/,\
|
||||||
|
aes.c \
|
||||||
|
aesni.c \
|
||||||
|
arc4.c \
|
||||||
|
asn1parse.c \
|
||||||
|
asn1write.c \
|
||||||
|
base64.c \
|
||||||
|
bignum.c \
|
||||||
|
blowfish.c \
|
||||||
|
camellia.c \
|
||||||
|
ccm.c \
|
||||||
|
certs.c \
|
||||||
|
chacha20.c \
|
||||||
|
chachapoly.c \
|
||||||
|
cipher.c \
|
||||||
|
cipher_wrap.c \
|
||||||
|
cmac.c \
|
||||||
|
ctr_drbg.c \
|
||||||
|
debug.c \
|
||||||
|
des.c \
|
||||||
|
dhm.c \
|
||||||
|
ecdh.c \
|
||||||
|
ecdsa.c \
|
||||||
|
ecjpake.c \
|
||||||
|
ecp.c \
|
||||||
|
ecp_curves.c \
|
||||||
|
entropy.c \
|
||||||
|
entropy_poll.c \
|
||||||
|
error.c \
|
||||||
|
gcm.c \
|
||||||
|
havege.c \
|
||||||
|
hmac_drbg.c \
|
||||||
|
md2.c \
|
||||||
|
md4.c \
|
||||||
|
md5.c \
|
||||||
|
md.c \
|
||||||
|
md_wrap.c \
|
||||||
|
oid.c \
|
||||||
|
padlock.c \
|
||||||
|
pem.c \
|
||||||
|
pk.c \
|
||||||
|
pkcs11.c \
|
||||||
|
pkcs12.c \
|
||||||
|
pkcs5.c \
|
||||||
|
pkparse.c \
|
||||||
|
pk_wrap.c \
|
||||||
|
pkwrite.c \
|
||||||
|
platform.c \
|
||||||
|
platform_util.c \
|
||||||
|
poly1305.c \
|
||||||
|
ripemd160.c \
|
||||||
|
rsa.c \
|
||||||
|
rsa_internal.c \
|
||||||
|
sha1.c \
|
||||||
|
sha256.c \
|
||||||
|
sha512.c \
|
||||||
|
ssl_cache.c \
|
||||||
|
ssl_ciphersuites.c \
|
||||||
|
ssl_cli.c \
|
||||||
|
ssl_cookie.c \
|
||||||
|
ssl_srv.c \
|
||||||
|
ssl_ticket.c \
|
||||||
|
ssl_tls.c \
|
||||||
|
timing.c \
|
||||||
|
x509.c \
|
||||||
|
x509_create.c \
|
||||||
|
x509_crl.c \
|
||||||
|
x509_crt.c \
|
||||||
|
x509_csr.c \
|
||||||
|
x509write_crt.c \
|
||||||
|
x509write_csr.c \
|
||||||
|
xtea.c \
|
||||||
|
)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# lwip
|
||||||
|
|
||||||
|
ifeq ($(MICROPY_PY_LWIP),1)
|
||||||
|
# A port should add an include path where lwipopts.h can be found (eg extmod/lwip-include)
|
||||||
|
LWIP_DIR = lib/lwip/src
|
||||||
|
INC += -I$(TOP)/$(LWIP_DIR)/include
|
||||||
|
CFLAGS_MOD += -DMICROPY_PY_LWIP=1
|
||||||
|
$(BUILD)/$(LWIP_DIR)/core/ipv4/dhcp.o: CFLAGS_MOD += -Wno-address
|
||||||
|
SRC_MOD += extmod/modlwip.c lib/netutils/netutils.c
|
||||||
|
SRC_MOD += $(addprefix $(LWIP_DIR)/,\
|
||||||
|
apps/mdns/mdns.c \
|
||||||
|
core/def.c \
|
||||||
|
core/dns.c \
|
||||||
|
core/inet_chksum.c \
|
||||||
|
core/init.c \
|
||||||
|
core/ip.c \
|
||||||
|
core/mem.c \
|
||||||
|
core/memp.c \
|
||||||
|
core/netif.c \
|
||||||
|
core/pbuf.c \
|
||||||
|
core/raw.c \
|
||||||
|
core/stats.c \
|
||||||
|
core/sys.c \
|
||||||
|
core/tcp.c \
|
||||||
|
core/tcp_in.c \
|
||||||
|
core/tcp_out.c \
|
||||||
|
core/timeouts.c \
|
||||||
|
core/udp.c \
|
||||||
|
core/ipv4/autoip.c \
|
||||||
|
core/ipv4/dhcp.c \
|
||||||
|
core/ipv4/etharp.c \
|
||||||
|
core/ipv4/icmp.c \
|
||||||
|
core/ipv4/igmp.c \
|
||||||
|
core/ipv4/ip4_addr.c \
|
||||||
|
core/ipv4/ip4.c \
|
||||||
|
core/ipv4/ip4_frag.c \
|
||||||
|
core/ipv6/dhcp6.c \
|
||||||
|
core/ipv6/ethip6.c \
|
||||||
|
core/ipv6/icmp6.c \
|
||||||
|
core/ipv6/inet6.c \
|
||||||
|
core/ipv6/ip6_addr.c \
|
||||||
|
core/ipv6/ip6.c \
|
||||||
|
core/ipv6/ip6_frag.c \
|
||||||
|
core/ipv6/mld6.c \
|
||||||
|
core/ipv6/nd6.c \
|
||||||
|
netif/ethernet.c \
|
||||||
|
)
|
||||||
|
ifeq ($(MICROPY_PY_LWIP_SLIP),1)
|
||||||
|
CFLAGS_MOD += -DMICROPY_PY_LWIP_SLIP=1
|
||||||
|
SRC_MOD += $(LWIP_DIR)/netif/slipif.c
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# btree
|
||||||
|
|
||||||
|
ifeq ($(MICROPY_PY_BTREE),1)
|
||||||
|
BTREE_DIR = lib/berkeley-db-1.xx
|
||||||
|
BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ "-Dvirt_fd_t=void*" $(BTREE_DEFS_EXTRA)
|
||||||
|
INC += -I$(TOP)/$(BTREE_DIR)/PORT/include
|
||||||
|
SRC_MOD += extmod/modbtree.c
|
||||||
|
SRC_MOD += $(addprefix $(BTREE_DIR)/,\
|
||||||
|
btree/bt_close.c \
|
||||||
|
btree/bt_conv.c \
|
||||||
|
btree/bt_debug.c \
|
||||||
|
btree/bt_delete.c \
|
||||||
|
btree/bt_get.c \
|
||||||
|
btree/bt_open.c \
|
||||||
|
btree/bt_overflow.c \
|
||||||
|
btree/bt_page.c \
|
||||||
|
btree/bt_put.c \
|
||||||
|
btree/bt_search.c \
|
||||||
|
btree/bt_seq.c \
|
||||||
|
btree/bt_split.c \
|
||||||
|
btree/bt_utils.c \
|
||||||
|
mpool/mpool.c \
|
||||||
|
)
|
||||||
|
CFLAGS_MOD += -DMICROPY_PY_BTREE=1
|
||||||
|
# we need to suppress certain warnings to get berkeley-db to compile cleanly
|
||||||
|
# and we have separate BTREE_DEFS so the definitions don't interfere with other source code
|
||||||
|
$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter $(BTREE_DEFS)
|
||||||
|
$(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS)
|
||||||
|
endif
|
||||||
|
|
||||||
@ -180,9 +180,9 @@ STATIC int mp_hal_i2c_read_byte(machine_i2c_obj_t *self, uint8_t *val, int nack)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return value:
|
// return value:
|
||||||
// >=0 - number of acks received
|
// >=0 - success; for read it's 0, for write it's number of acks received
|
||||||
// <0 - error, with errno being the negative of the return value
|
// <0 - error, with errno being the negative of the return value
|
||||||
int mp_machine_soft_i2c_writeto(mp_obj_base_t *self_in, uint16_t addr, const uint8_t *src, size_t len, bool stop) {
|
int mp_machine_soft_i2c_transfer(mp_obj_base_t *self_in, uint16_t addr, size_t n, mp_machine_i2c_buf_t *bufs, unsigned int flags) {
|
||||||
machine_i2c_obj_t *self = (machine_i2c_obj_t*)self_in;
|
machine_i2c_obj_t *self = (machine_i2c_obj_t*)self_in;
|
||||||
|
|
||||||
// start the I2C transaction
|
// start the I2C transaction
|
||||||
@ -192,7 +192,7 @@ int mp_machine_soft_i2c_writeto(mp_obj_base_t *self_in, uint16_t addr, const uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write the slave address
|
// write the slave address
|
||||||
ret = mp_hal_i2c_write_byte(self, addr << 1);
|
ret = mp_hal_i2c_write_byte(self, (addr << 1) | (flags & MP_MACHINE_I2C_FLAG_READ));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
} else if (ret != 0) {
|
} else if (ret != 0) {
|
||||||
@ -201,69 +201,102 @@ int mp_machine_soft_i2c_writeto(mp_obj_base_t *self_in, uint16_t addr, const uin
|
|||||||
return -MP_ENODEV;
|
return -MP_ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the buffer to the I2C memory
|
int transfer_ret = 0;
|
||||||
int num_acks = 0;
|
for (; n--; ++bufs) {
|
||||||
while (len--) {
|
size_t len = bufs->len;
|
||||||
ret = mp_hal_i2c_write_byte(self, *src++);
|
uint8_t *buf = bufs->buf;
|
||||||
if (ret < 0) {
|
if (flags & MP_MACHINE_I2C_FLAG_READ) {
|
||||||
return ret;
|
// read bytes from the slave into the given buffer(s)
|
||||||
} else if (ret != 0) {
|
while (len--) {
|
||||||
// nack received, stop sending
|
ret = mp_hal_i2c_read_byte(self, buf++, (n | len) == 0);
|
||||||
break;
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// write bytes from the given buffer(s) to the slave
|
||||||
|
while (len--) {
|
||||||
|
ret = mp_hal_i2c_write_byte(self, *buf++);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
} else if (ret != 0) {
|
||||||
|
// nack received, stop sending
|
||||||
|
n = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++transfer_ret; // count the number of acks
|
||||||
|
}
|
||||||
}
|
}
|
||||||
++num_acks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish the I2C transaction
|
// finish the I2C transaction
|
||||||
if (stop) {
|
if (flags & MP_MACHINE_I2C_FLAG_STOP) {
|
||||||
ret = mp_hal_i2c_stop(self);
|
ret = mp_hal_i2c_stop(self);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return num_acks;
|
return transfer_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return value:
|
/******************************************************************************/
|
||||||
// 0 - success
|
// Generic helper functions
|
||||||
// <0 - error, with errno being the negative of the return value
|
|
||||||
int mp_machine_soft_i2c_readfrom(mp_obj_base_t *self_in, uint16_t addr, uint8_t *dest, size_t len, bool stop) {
|
|
||||||
machine_i2c_obj_t *self = (machine_i2c_obj_t*)self_in;
|
|
||||||
|
|
||||||
// start the I2C transaction
|
// For use by ports that require a single buffer of data for a read/write transfer
|
||||||
int ret = mp_hal_i2c_start(self);
|
int mp_machine_i2c_transfer_adaptor(mp_obj_base_t *self, uint16_t addr, size_t n, mp_machine_i2c_buf_t *bufs, unsigned int flags) {
|
||||||
if (ret != 0) {
|
size_t len;
|
||||||
return ret;
|
uint8_t *buf;
|
||||||
}
|
if (n == 1) {
|
||||||
|
// Use given single buffer
|
||||||
// write the slave address
|
len = bufs[0].len;
|
||||||
ret = mp_hal_i2c_write_byte(self, (addr << 1) | 1);
|
buf = bufs[0].buf;
|
||||||
if (ret < 0) {
|
} else {
|
||||||
return ret;
|
// Combine buffers into a single one
|
||||||
} else if (ret != 0) {
|
len = 0;
|
||||||
// nack received, release the bus cleanly
|
for (size_t i = 0; i < n; ++i) {
|
||||||
mp_hal_i2c_stop(self);
|
len += bufs[i].len;
|
||||||
return -MP_ENODEV;
|
}
|
||||||
}
|
buf = m_new(uint8_t, len);
|
||||||
|
if (!(flags & MP_MACHINE_I2C_FLAG_READ)) {
|
||||||
// read the bytes from the slave
|
len = 0;
|
||||||
while (len--) {
|
for (size_t i = 0; i < n; ++i) {
|
||||||
ret = mp_hal_i2c_read_byte(self, dest++, len == 0);
|
memcpy(buf + len, bufs[i].buf, bufs[i].len);
|
||||||
if (ret != 0) {
|
len += bufs[i].len;
|
||||||
return ret;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish the I2C transaction
|
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||||
if (stop) {
|
int ret = i2c_p->transfer_single(self, addr, len, buf, flags);
|
||||||
ret = mp_hal_i2c_stop(self);
|
|
||||||
if (ret != 0) {
|
if (n > 1) {
|
||||||
return ret;
|
if (flags & MP_MACHINE_I2C_FLAG_READ) {
|
||||||
|
// Copy data from single buffer to individual ones
|
||||||
|
len = 0;
|
||||||
|
for (size_t i = 0; i < n; ++i) {
|
||||||
|
memcpy(bufs[i].buf, buf + len, bufs[i].len);
|
||||||
|
len += bufs[i].len;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
m_del(uint8_t, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; // success
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC int mp_machine_i2c_readfrom(mp_obj_base_t *self, uint16_t addr, uint8_t *dest, size_t len, bool stop) {
|
||||||
|
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||||
|
mp_machine_i2c_buf_t buf = {.len = len, .buf = dest};
|
||||||
|
unsigned int flags = MP_MACHINE_I2C_FLAG_READ | (stop ? MP_MACHINE_I2C_FLAG_STOP : 0);
|
||||||
|
return i2c_p->transfer(self, addr, 1, &buf, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC int mp_machine_i2c_writeto(mp_obj_base_t *self, uint16_t addr, const uint8_t *src, size_t len, bool stop) {
|
||||||
|
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||||
|
mp_machine_i2c_buf_t buf = {.len = len, .buf = (uint8_t*)src};
|
||||||
|
unsigned int flags = stop ? MP_MACHINE_I2C_FLAG_STOP : 0;
|
||||||
|
return i2c_p->transfer(self, addr, 1, &buf, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -318,11 +351,10 @@ MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_init_obj, 1, machine_i2c_obj_init);
|
|||||||
|
|
||||||
STATIC mp_obj_t machine_i2c_scan(mp_obj_t self_in) {
|
STATIC mp_obj_t machine_i2c_scan(mp_obj_t self_in) {
|
||||||
mp_obj_base_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_base_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
|
||||||
mp_obj_t list = mp_obj_new_list(0, NULL);
|
mp_obj_t list = mp_obj_new_list(0, NULL);
|
||||||
// 7-bit addresses 0b0000xxx and 0b1111xxx are reserved
|
// 7-bit addresses 0b0000xxx and 0b1111xxx are reserved
|
||||||
for (int addr = 0x08; addr < 0x78; ++addr) {
|
for (int addr = 0x08; addr < 0x78; ++addr) {
|
||||||
int ret = i2c_p->writeto(self, addr, NULL, 0, true);
|
int ret = mp_machine_i2c_writeto(self, addr, NULL, 0, true);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
mp_obj_list_append(list, MP_OBJ_NEW_SMALL_INT(addr));
|
mp_obj_list_append(list, MP_OBJ_NEW_SMALL_INT(addr));
|
||||||
}
|
}
|
||||||
@ -407,12 +439,11 @@ MP_DEFINE_CONST_FUN_OBJ_2(machine_i2c_write_obj, machine_i2c_write);
|
|||||||
|
|
||||||
STATIC mp_obj_t machine_i2c_readfrom(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t machine_i2c_readfrom(size_t n_args, const mp_obj_t *args) {
|
||||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
||||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
|
||||||
mp_int_t addr = mp_obj_get_int(args[1]);
|
mp_int_t addr = mp_obj_get_int(args[1]);
|
||||||
vstr_t vstr;
|
vstr_t vstr;
|
||||||
vstr_init_len(&vstr, mp_obj_get_int(args[2]));
|
vstr_init_len(&vstr, mp_obj_get_int(args[2]));
|
||||||
bool stop = (n_args == 3) ? true : mp_obj_is_true(args[3]);
|
bool stop = (n_args == 3) ? true : mp_obj_is_true(args[3]);
|
||||||
int ret = i2c_p->readfrom(self, addr, (uint8_t*)vstr.buf, vstr.len, stop);
|
int ret = mp_machine_i2c_readfrom(self, addr, (uint8_t*)vstr.buf, vstr.len, stop);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
mp_raise_OSError(-ret);
|
mp_raise_OSError(-ret);
|
||||||
}
|
}
|
||||||
@ -422,12 +453,11 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readfrom_obj, 3, 4, machine_i2c_
|
|||||||
|
|
||||||
STATIC mp_obj_t machine_i2c_readfrom_into(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t machine_i2c_readfrom_into(size_t n_args, const mp_obj_t *args) {
|
||||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
||||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
|
||||||
mp_int_t addr = mp_obj_get_int(args[1]);
|
mp_int_t addr = mp_obj_get_int(args[1]);
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE);
|
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_WRITE);
|
||||||
bool stop = (n_args == 3) ? true : mp_obj_is_true(args[3]);
|
bool stop = (n_args == 3) ? true : mp_obj_is_true(args[3]);
|
||||||
int ret = i2c_p->readfrom(self, addr, bufinfo.buf, bufinfo.len, stop);
|
int ret = mp_machine_i2c_readfrom(self, addr, bufinfo.buf, bufinfo.len, stop);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
mp_raise_OSError(-ret);
|
mp_raise_OSError(-ret);
|
||||||
}
|
}
|
||||||
@ -437,12 +467,11 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_readfrom_into_obj, 3, 4, machine
|
|||||||
|
|
||||||
STATIC mp_obj_t machine_i2c_writeto(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t machine_i2c_writeto(size_t n_args, const mp_obj_t *args) {
|
||||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
||||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
|
||||||
mp_int_t addr = mp_obj_get_int(args[1]);
|
mp_int_t addr = mp_obj_get_int(args[1]);
|
||||||
mp_buffer_info_t bufinfo;
|
mp_buffer_info_t bufinfo;
|
||||||
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[2], &bufinfo, MP_BUFFER_READ);
|
||||||
bool stop = (n_args == 3) ? true : mp_obj_is_true(args[3]);
|
bool stop = (n_args == 3) ? true : mp_obj_is_true(args[3]);
|
||||||
int ret = i2c_p->writeto(self, addr, bufinfo.buf, bufinfo.len, stop);
|
int ret = mp_machine_i2c_writeto(self, addr, bufinfo.buf, bufinfo.len, stop);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
mp_raise_OSError(-ret);
|
mp_raise_OSError(-ret);
|
||||||
}
|
}
|
||||||
@ -451,53 +480,87 @@ STATIC mp_obj_t machine_i2c_writeto(size_t n_args, const mp_obj_t *args) {
|
|||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_writeto_obj, 3, 4, machine_i2c_writeto);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_writeto_obj, 3, 4, machine_i2c_writeto);
|
||||||
|
|
||||||
|
STATIC mp_obj_t machine_i2c_writevto(size_t n_args, const mp_obj_t *args) {
|
||||||
|
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
||||||
|
mp_int_t addr = mp_obj_get_int(args[1]);
|
||||||
|
|
||||||
|
// Get the list of data buffer(s) to write
|
||||||
|
size_t nitems;
|
||||||
|
const mp_obj_t *items;
|
||||||
|
mp_obj_get_array(args[2], &nitems, (mp_obj_t**)&items);
|
||||||
|
|
||||||
|
// Get the stop argument
|
||||||
|
bool stop = (n_args == 3) ? true : mp_obj_is_true(args[3]);
|
||||||
|
|
||||||
|
// Extract all buffer data, skipping zero-length buffers
|
||||||
|
size_t alloc = nitems == 0 ? 1 : nitems;
|
||||||
|
size_t nbufs = 0;
|
||||||
|
mp_machine_i2c_buf_t *bufs = mp_local_alloc(alloc * sizeof(mp_machine_i2c_buf_t));
|
||||||
|
for (; nitems--; ++items) {
|
||||||
|
mp_buffer_info_t bufinfo;
|
||||||
|
mp_get_buffer_raise(*items, &bufinfo, MP_BUFFER_READ);
|
||||||
|
if (bufinfo.len > 0) {
|
||||||
|
bufs[nbufs].len = bufinfo.len;
|
||||||
|
bufs[nbufs++].buf = bufinfo.buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure there is at least one buffer, empty if needed
|
||||||
|
if (nbufs == 0) {
|
||||||
|
bufs[0].len = 0;
|
||||||
|
bufs[0].buf = NULL;
|
||||||
|
nbufs = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do the I2C transfer
|
||||||
|
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||||
|
int ret = i2c_p->transfer(self, addr, nbufs, bufs, stop ? MP_MACHINE_I2C_FLAG_STOP : 0);
|
||||||
|
mp_local_free(bufs);
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
mp_raise_OSError(-ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return number of acks received
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(ret);
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_writevto_obj, 3, 4, machine_i2c_writevto);
|
||||||
|
|
||||||
STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, uint8_t *buf, size_t len) {
|
STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, uint8_t *buf, size_t len) {
|
||||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
|
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
|
||||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
|
||||||
uint8_t memaddr_buf[4];
|
uint8_t memaddr_buf[4];
|
||||||
size_t memaddr_len = 0;
|
size_t memaddr_len = 0;
|
||||||
for (int16_t i = addrsize - 8; i >= 0; i -= 8) {
|
for (int16_t i = addrsize - 8; i >= 0; i -= 8) {
|
||||||
memaddr_buf[memaddr_len++] = memaddr >> i;
|
memaddr_buf[memaddr_len++] = memaddr >> i;
|
||||||
}
|
}
|
||||||
int ret = i2c_p->writeto(self, addr, memaddr_buf, memaddr_len, false);
|
int ret = mp_machine_i2c_writeto(self, addr, memaddr_buf, memaddr_len, false);
|
||||||
if (ret != memaddr_len) {
|
if (ret != memaddr_len) {
|
||||||
// must generate STOP
|
// must generate STOP
|
||||||
i2c_p->writeto(self, addr, NULL, 0, true);
|
mp_machine_i2c_writeto(self, addr, NULL, 0, true);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return i2c_p->readfrom(self, addr, buf, len, true);
|
return mp_machine_i2c_readfrom(self, addr, buf, len, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_MEMADDR_SIZE (4)
|
|
||||||
#define BUF_STACK_SIZE (12)
|
|
||||||
|
|
||||||
STATIC int write_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, const uint8_t *buf, size_t len) {
|
STATIC int write_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t addrsize, const uint8_t *buf, size_t len) {
|
||||||
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
|
mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
|
||||||
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
|
||||||
|
|
||||||
// need some memory to create the buffer to send; try to use stack if possible
|
// Create buffer with memory address
|
||||||
uint8_t buf2_stack[MAX_MEMADDR_SIZE + BUF_STACK_SIZE];
|
|
||||||
uint8_t *buf2;
|
|
||||||
size_t buf2_alloc = 0;
|
|
||||||
if (len <= BUF_STACK_SIZE) {
|
|
||||||
buf2 = buf2_stack;
|
|
||||||
} else {
|
|
||||||
buf2_alloc = MAX_MEMADDR_SIZE + len;
|
|
||||||
buf2 = m_new(uint8_t, buf2_alloc);
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the buffer to send
|
|
||||||
size_t memaddr_len = 0;
|
size_t memaddr_len = 0;
|
||||||
|
uint8_t memaddr_buf[4];
|
||||||
for (int16_t i = addrsize - 8; i >= 0; i -= 8) {
|
for (int16_t i = addrsize - 8; i >= 0; i -= 8) {
|
||||||
buf2[memaddr_len++] = memaddr >> i;
|
memaddr_buf[memaddr_len++] = memaddr >> i;
|
||||||
}
|
}
|
||||||
memcpy(buf2 + memaddr_len, buf, len);
|
|
||||||
|
|
||||||
int ret = i2c_p->writeto(self, addr, buf2, memaddr_len + len, true);
|
// Create partial write buffers
|
||||||
if (buf2_alloc != 0) {
|
mp_machine_i2c_buf_t bufs[2] = {
|
||||||
m_del(uint8_t, buf2, buf2_alloc);
|
{.len = memaddr_len, .buf = memaddr_buf},
|
||||||
}
|
{.len = len, .buf = (uint8_t*)buf},
|
||||||
return ret;
|
};
|
||||||
|
|
||||||
|
// Do I2C transfer
|
||||||
|
mp_machine_i2c_p_t *i2c_p = (mp_machine_i2c_p_t*)self->type->protocol;
|
||||||
|
return i2c_p->transfer(self, addr, 2, bufs, MP_MACHINE_I2C_FLAG_STOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC const mp_arg_t machine_i2c_mem_allowed_args[] = {
|
STATIC const mp_arg_t machine_i2c_mem_allowed_args[] = {
|
||||||
@ -584,6 +647,7 @@ STATIC const mp_rom_map_elem_t machine_i2c_locals_dict_table[] = {
|
|||||||
{ MP_ROM_QSTR(MP_QSTR_readfrom), MP_ROM_PTR(&machine_i2c_readfrom_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_readfrom), MP_ROM_PTR(&machine_i2c_readfrom_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_readfrom_into), MP_ROM_PTR(&machine_i2c_readfrom_into_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_readfrom_into), MP_ROM_PTR(&machine_i2c_readfrom_into_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_writeto), MP_ROM_PTR(&machine_i2c_writeto_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_writeto), MP_ROM_PTR(&machine_i2c_writeto_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_writevto), MP_ROM_PTR(&machine_i2c_writevto_obj) },
|
||||||
|
|
||||||
// memory operations
|
// memory operations
|
||||||
{ MP_ROM_QSTR(MP_QSTR_readfrom_mem), MP_ROM_PTR(&machine_i2c_readfrom_mem_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_readfrom_mem), MP_ROM_PTR(&machine_i2c_readfrom_mem_obj) },
|
||||||
@ -625,8 +689,7 @@ STATIC const mp_machine_i2c_p_t mp_machine_soft_i2c_p = {
|
|||||||
.stop = (int(*)(mp_obj_base_t*))mp_hal_i2c_stop,
|
.stop = (int(*)(mp_obj_base_t*))mp_hal_i2c_stop,
|
||||||
.read = mp_machine_soft_i2c_read,
|
.read = mp_machine_soft_i2c_read,
|
||||||
.write = mp_machine_soft_i2c_write,
|
.write = mp_machine_soft_i2c_write,
|
||||||
.readfrom = mp_machine_soft_i2c_readfrom,
|
.transfer = mp_machine_soft_i2c_transfer,
|
||||||
.writeto = mp_machine_soft_i2c_writeto,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const mp_obj_type_t machine_i2c_type = {
|
const mp_obj_type_t machine_i2c_type = {
|
||||||
|
|||||||
@ -28,15 +28,24 @@
|
|||||||
|
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
|
|
||||||
|
#define MP_MACHINE_I2C_FLAG_READ (0x01) // if not set then it's a write
|
||||||
|
#define MP_MACHINE_I2C_FLAG_STOP (0x02)
|
||||||
|
|
||||||
|
typedef struct _mp_machine_i2c_buf_t {
|
||||||
|
size_t len;
|
||||||
|
uint8_t *buf;
|
||||||
|
} mp_machine_i2c_buf_t;
|
||||||
|
|
||||||
// I2C protocol
|
// I2C protocol
|
||||||
// the first 4 methods can be NULL, meaning operation is not supported
|
// the first 4 methods can be NULL, meaning operation is not supported
|
||||||
|
// transfer_single only needs to be set if transfer=mp_machine_i2c_transfer_adaptor
|
||||||
typedef struct _mp_machine_i2c_p_t {
|
typedef struct _mp_machine_i2c_p_t {
|
||||||
int (*start)(mp_obj_base_t *obj);
|
int (*start)(mp_obj_base_t *obj);
|
||||||
int (*stop)(mp_obj_base_t *obj);
|
int (*stop)(mp_obj_base_t *obj);
|
||||||
int (*read)(mp_obj_base_t *obj, uint8_t *dest, size_t len, bool nack);
|
int (*read)(mp_obj_base_t *obj, uint8_t *dest, size_t len, bool nack);
|
||||||
int (*write)(mp_obj_base_t *obj, const uint8_t *src, size_t len);
|
int (*write)(mp_obj_base_t *obj, const uint8_t *src, size_t len);
|
||||||
int (*readfrom)(mp_obj_base_t *obj, uint16_t addr, uint8_t *dest, size_t len, bool stop);
|
int (*transfer)(mp_obj_base_t *obj, uint16_t addr, size_t n, mp_machine_i2c_buf_t *bufs, unsigned int flags);
|
||||||
int (*writeto)(mp_obj_base_t *obj, uint16_t addr, const uint8_t *src, size_t len, bool stop);
|
int (*transfer_single)(mp_obj_base_t *obj, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags);
|
||||||
} mp_machine_i2c_p_t;
|
} mp_machine_i2c_p_t;
|
||||||
|
|
||||||
typedef struct _mp_machine_soft_i2c_obj_t {
|
typedef struct _mp_machine_soft_i2c_obj_t {
|
||||||
@ -50,7 +59,7 @@ typedef struct _mp_machine_soft_i2c_obj_t {
|
|||||||
extern const mp_obj_type_t machine_i2c_type;
|
extern const mp_obj_type_t machine_i2c_type;
|
||||||
extern const mp_obj_dict_t mp_machine_soft_i2c_locals_dict;
|
extern const mp_obj_dict_t mp_machine_soft_i2c_locals_dict;
|
||||||
|
|
||||||
int mp_machine_soft_i2c_readfrom(mp_obj_base_t *self_in, uint16_t addr, uint8_t *dest, size_t len, bool stop);
|
int mp_machine_i2c_transfer_adaptor(mp_obj_base_t *self, uint16_t addr, size_t n, mp_machine_i2c_buf_t *bufs, unsigned int flags);
|
||||||
int mp_machine_soft_i2c_writeto(mp_obj_base_t *self_in, uint16_t addr, const uint8_t *src, size_t len, bool stop);
|
int mp_machine_soft_i2c_transfer(mp_obj_base_t *self, uint16_t addr, size_t n, mp_machine_i2c_buf_t *bufs, unsigned int flags);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H
|
#endif // MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H
|
||||||
|
|||||||
@ -43,13 +43,13 @@ typedef struct _machine_signal_t {
|
|||||||
} machine_signal_t;
|
} machine_signal_t;
|
||||||
|
|
||||||
STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||||
mp_obj_t pin = args[0];
|
mp_obj_t pin;
|
||||||
bool invert = false;
|
bool invert = false;
|
||||||
|
|
||||||
#if defined(MICROPY_PY_MACHINE_PIN_MAKE_NEW)
|
#if defined(MICROPY_PY_MACHINE_PIN_MAKE_NEW)
|
||||||
mp_pin_p_t *pin_p = NULL;
|
mp_pin_p_t *pin_p = NULL;
|
||||||
|
|
||||||
if (MP_OBJ_IS_OBJ(pin)) {
|
if (n_args > 0 && mp_obj_is_obj(args[0])) {
|
||||||
mp_obj_base_t *pin_base = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
mp_obj_base_t *pin_base = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
|
||||||
pin_p = (mp_pin_p_t*)pin_base->type->protocol;
|
pin_p = (mp_pin_p_t*)pin_base->type->protocol;
|
||||||
}
|
}
|
||||||
@ -96,6 +96,7 @@ STATIC mp_obj_t signal_make_new(const mp_obj_type_t *type, size_t n_args, size_t
|
|||||||
// Otherwise there should be 1 or 2 args
|
// Otherwise there should be 1 or 2 args
|
||||||
{
|
{
|
||||||
if (n_args == 1) {
|
if (n_args == 1) {
|
||||||
|
pin = args[0];
|
||||||
if (n_kw == 0) {
|
if (n_kw == 0) {
|
||||||
} else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) {
|
} else if (n_kw == 1 && args[1] == MP_OBJ_NEW_QSTR(MP_QSTR_invert)) {
|
||||||
invert = mp_obj_is_true(args[2]);
|
invert = mp_obj_is_true(args[2]);
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj);
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj);
|
||||||
|
|
||||||
#if MICROPY_PY_OS_DUPTERM
|
#if MICROPY_PY_OS_DUPTERM
|
||||||
|
bool mp_uos_dupterm_is_builtin_stream(mp_const_obj_t stream);
|
||||||
int mp_uos_dupterm_rx_chr(void);
|
int mp_uos_dupterm_rx_chr(void);
|
||||||
void mp_uos_dupterm_tx_strn(const char *str, size_t len);
|
void mp_uos_dupterm_tx_strn(const char *str, size_t len);
|
||||||
void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc);
|
void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc);
|
||||||
|
|||||||
271
extmod/modlwip.c
271
extmod/modlwip.c
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013, 2014 Damien P. George
|
* Copyright (c) 2013-2019 Damien P. George
|
||||||
* Copyright (c) 2015 Galen Hazelwood
|
* Copyright (c) 2015 Galen Hazelwood
|
||||||
* Copyright (c) 2015-2017 Paul Sokolovsky
|
* Copyright (c) 2015-2017 Paul Sokolovsky
|
||||||
*
|
*
|
||||||
@ -57,6 +57,10 @@
|
|||||||
#define DEBUG_printf(...) (void)0
|
#define DEBUG_printf(...) (void)0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Timeout between closing a TCP socket and doing a tcp_abort on that
|
||||||
|
// socket, if the connection isn't closed cleanly in that time.
|
||||||
|
#define MICROPY_PY_LWIP_TCP_CLOSE_TIMEOUT_MS (10000)
|
||||||
|
|
||||||
// All socket options should be globally distinct,
|
// All socket options should be globally distinct,
|
||||||
// because we ignore option levels for efficiency.
|
// because we ignore option levels for efficiency.
|
||||||
#define IP_ADD_MEMBERSHIP 0x400
|
#define IP_ADD_MEMBERSHIP 0x400
|
||||||
@ -69,6 +73,13 @@
|
|||||||
#define ip_reset_option(pcb, opt) ((pcb)->so_options &= ~(opt))
|
#define ip_reset_option(pcb, opt) ((pcb)->so_options &= ~(opt))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// A port can define these hooks to provide concurrency protection
|
||||||
|
#ifndef MICROPY_PY_LWIP_ENTER
|
||||||
|
#define MICROPY_PY_LWIP_ENTER
|
||||||
|
#define MICROPY_PY_LWIP_REENTER
|
||||||
|
#define MICROPY_PY_LWIP_EXIT
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MICROPY_PY_LWIP_SLIP
|
#ifdef MICROPY_PY_LWIP_SLIP
|
||||||
#include "netif/slipif.h"
|
#include "netif/slipif.h"
|
||||||
#include "lwip/sio.h"
|
#include "lwip/sio.h"
|
||||||
@ -308,6 +319,38 @@ static inline void poll_sockets(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATIC struct tcp_pcb *volatile *lwip_socket_incoming_array(lwip_socket_obj_t *socket) {
|
||||||
|
if (socket->incoming.connection.alloc == 0) {
|
||||||
|
return &socket->incoming.connection.tcp.item;
|
||||||
|
} else {
|
||||||
|
return &socket->incoming.connection.tcp.array[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC void lwip_socket_free_incoming(lwip_socket_obj_t *socket) {
|
||||||
|
bool socket_is_listener =
|
||||||
|
socket->type == MOD_NETWORK_SOCK_STREAM
|
||||||
|
&& socket->pcb.tcp->state == LISTEN;
|
||||||
|
|
||||||
|
if (!socket_is_listener) {
|
||||||
|
if (socket->incoming.pbuf != NULL) {
|
||||||
|
pbuf_free(socket->incoming.pbuf);
|
||||||
|
socket->incoming.pbuf = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uint8_t alloc = socket->incoming.connection.alloc;
|
||||||
|
struct tcp_pcb *volatile *tcp_array = lwip_socket_incoming_array(socket);
|
||||||
|
for (uint8_t i = 0; i < alloc; ++i) {
|
||||||
|
// Deregister callback and abort
|
||||||
|
if (tcp_array[i] != NULL) {
|
||||||
|
tcp_poll(tcp_array[i], NULL, 0);
|
||||||
|
tcp_abort(tcp_array[i]);
|
||||||
|
tcp_array[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
// Callback functions for the lwIP raw API.
|
// Callback functions for the lwIP raw API.
|
||||||
|
|
||||||
@ -341,6 +384,8 @@ STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
|||||||
STATIC void _lwip_tcp_error(void *arg, err_t err) {
|
STATIC void _lwip_tcp_error(void *arg, err_t err) {
|
||||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
||||||
|
|
||||||
|
// Free any incoming buffers or connections that are stored
|
||||||
|
lwip_socket_free_incoming(socket);
|
||||||
// Pass the error code back via the connection variable.
|
// Pass the error code back via the connection variable.
|
||||||
socket->state = err;
|
socket->state = err;
|
||||||
// If we got here, the lwIP stack either has deallocated or will deallocate the pcb.
|
// If we got here, the lwIP stack either has deallocated or will deallocate the pcb.
|
||||||
@ -355,6 +400,43 @@ STATIC err_t _lwip_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err) {
|
|||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle errors (eg connection aborted) on TCP PCBs that have been put on the
|
||||||
|
// accept queue but are not yet actually accepted.
|
||||||
|
STATIC void _lwip_tcp_err_unaccepted(void *arg, err_t err) {
|
||||||
|
struct tcp_pcb *pcb = (struct tcp_pcb*)arg;
|
||||||
|
|
||||||
|
// The ->connected entry is repurposed to store the parent socket; this is safe
|
||||||
|
// because it's only ever used by lwIP if tcp_connect is called on the TCP PCB.
|
||||||
|
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)pcb->connected;
|
||||||
|
|
||||||
|
// Array is not volatile because thiss callback is executed within the lwIP context
|
||||||
|
uint8_t alloc = socket->incoming.connection.alloc;
|
||||||
|
struct tcp_pcb **tcp_array = (struct tcp_pcb**)lwip_socket_incoming_array(socket);
|
||||||
|
|
||||||
|
// Search for PCB on the accept queue of the parent socket
|
||||||
|
struct tcp_pcb **shift_down = NULL;
|
||||||
|
uint8_t i = socket->incoming.connection.iget;
|
||||||
|
do {
|
||||||
|
if (shift_down == NULL) {
|
||||||
|
if (tcp_array[i] == pcb) {
|
||||||
|
shift_down = &tcp_array[i];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*shift_down = tcp_array[i];
|
||||||
|
shift_down = &tcp_array[i];
|
||||||
|
}
|
||||||
|
if (++i >= alloc) {
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
} while (i != socket->incoming.connection.iput);
|
||||||
|
|
||||||
|
// PCB found in queue, remove it
|
||||||
|
if (shift_down != NULL) {
|
||||||
|
*shift_down = NULL;
|
||||||
|
socket->incoming.connection.iput = shift_down - tcp_array;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// By default, a child socket of listen socket is created with recv
|
// By default, a child socket of listen socket is created with recv
|
||||||
// handler which discards incoming pbuf's. We don't want to do that,
|
// handler which discards incoming pbuf's. We don't want to do that,
|
||||||
// so set this handler which requests lwIP to keep pbuf's and deliver
|
// so set this handler which requests lwIP to keep pbuf's and deliver
|
||||||
@ -369,7 +451,8 @@ STATIC err_t _lwip_tcp_recv_unaccepted(void *arg, struct tcp_pcb *pcb, struct pb
|
|||||||
// from accept callback itself.
|
// from accept callback itself.
|
||||||
STATIC err_t _lwip_tcp_accept_finished(void *arg, struct tcp_pcb *pcb)
|
STATIC err_t _lwip_tcp_accept_finished(void *arg, struct tcp_pcb *pcb)
|
||||||
{
|
{
|
||||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
// The ->connected entry of the pcb holds the listening socket of the accept
|
||||||
|
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)pcb->connected;
|
||||||
tcp_poll(pcb, NULL, 0);
|
tcp_poll(pcb, NULL, 0);
|
||||||
exec_user_callback(socket);
|
exec_user_callback(socket);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
@ -377,19 +460,19 @@ STATIC err_t _lwip_tcp_accept_finished(void *arg, struct tcp_pcb *pcb)
|
|||||||
|
|
||||||
// Callback for incoming tcp connections.
|
// Callback for incoming tcp connections.
|
||||||
STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {
|
STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {
|
||||||
|
// err can be ERR_MEM to notify us that there was no memory for an incoming connection
|
||||||
|
if (err != ERR_OK) {
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
|
||||||
tcp_recv(newpcb, _lwip_tcp_recv_unaccepted);
|
tcp_recv(newpcb, _lwip_tcp_recv_unaccepted);
|
||||||
|
|
||||||
// Search for an empty slot to store the new connection
|
// Search for an empty slot to store the new connection
|
||||||
struct tcp_pcb *volatile *tcp_array;
|
struct tcp_pcb *volatile *slot = &lwip_socket_incoming_array(socket)[socket->incoming.connection.iput];
|
||||||
if (socket->incoming.connection.alloc == 0) {
|
if (*slot == NULL) {
|
||||||
tcp_array = &socket->incoming.connection.tcp.item;
|
|
||||||
} else {
|
|
||||||
tcp_array = socket->incoming.connection.tcp.array;
|
|
||||||
}
|
|
||||||
if (tcp_array[socket->incoming.connection.iput] == NULL) {
|
|
||||||
// Have an empty slot to store waiting connection
|
// Have an empty slot to store waiting connection
|
||||||
tcp_array[socket->incoming.connection.iput] = newpcb;
|
*slot = newpcb;
|
||||||
if (++socket->incoming.connection.iput >= socket->incoming.connection.alloc) {
|
if (++socket->incoming.connection.iput >= socket->incoming.connection.alloc) {
|
||||||
socket->incoming.connection.iput = 0;
|
socket->incoming.connection.iput = 0;
|
||||||
}
|
}
|
||||||
@ -399,6 +482,15 @@ STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {
|
|||||||
// is idle.
|
// is idle.
|
||||||
tcp_poll(newpcb, _lwip_tcp_accept_finished, 1);
|
tcp_poll(newpcb, _lwip_tcp_accept_finished, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the error callback to handle the case of a dropped connection before we
|
||||||
|
// have a chance to take it off the accept queue.
|
||||||
|
// The ->connected entry is repurposed to store the parent socket; this is safe
|
||||||
|
// because it's only ever used by lwIP if tcp_connect is called on the TCP PCB.
|
||||||
|
newpcb->connected = (void*)socket;
|
||||||
|
tcp_arg(newpcb, newpcb);
|
||||||
|
tcp_err(newpcb, _lwip_tcp_err_unaccepted);
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,9 +536,12 @@ STATIC mp_uint_t lwip_udp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui
|
|||||||
len = 0xffff;
|
len = 0xffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_ENTER
|
||||||
|
|
||||||
// FIXME: maybe PBUF_ROM?
|
// FIXME: maybe PBUF_ROM?
|
||||||
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
|
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
*_errno = MP_ENOMEM;
|
*_errno = MP_ENOMEM;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -464,6 +559,8 @@ STATIC mp_uint_t lwip_udp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui
|
|||||||
|
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
|
||||||
// udp_sendto can return 1 on occasion for ESP8266 port. It's not known why
|
// udp_sendto can return 1 on occasion for ESP8266 port. It's not known why
|
||||||
// but it seems that the send actually goes through without error in this case.
|
// but it seems that the send actually goes through without error in this case.
|
||||||
// So we treat such cases as a success until further investigation.
|
// So we treat such cases as a success until further investigation.
|
||||||
@ -502,10 +599,14 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
|
|||||||
|
|
||||||
struct pbuf *p = socket->incoming.pbuf;
|
struct pbuf *p = socket->incoming.pbuf;
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_ENTER
|
||||||
|
|
||||||
u16_t result = pbuf_copy_partial(p, buf, ((p->tot_len > len) ? len : p->tot_len), 0);
|
u16_t result = pbuf_copy_partial(p, buf, ((p->tot_len > len) ? len : p->tot_len), 0);
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
socket->incoming.pbuf = NULL;
|
socket->incoming.pbuf = NULL;
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
|
||||||
return (mp_uint_t) result;
|
return (mp_uint_t) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,17 +618,29 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
|
|||||||
} \
|
} \
|
||||||
assert(socket->pcb.tcp);
|
assert(socket->pcb.tcp);
|
||||||
|
|
||||||
|
// Version of above for use when lock is held
|
||||||
|
#define STREAM_ERROR_CHECK_WITH_LOCK(socket) \
|
||||||
|
if (socket->state < 0) { \
|
||||||
|
*_errno = error_lookup_table[-socket->state]; \
|
||||||
|
MICROPY_PY_LWIP_EXIT \
|
||||||
|
return MP_STREAM_ERROR; \
|
||||||
|
} \
|
||||||
|
assert(socket->pcb.tcp);
|
||||||
|
|
||||||
|
|
||||||
// Helper function for send/sendto to handle TCP packets
|
// Helper function for send/sendto to handle TCP packets
|
||||||
STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) {
|
STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) {
|
||||||
// Check for any pending errors
|
// Check for any pending errors
|
||||||
STREAM_ERROR_CHECK(socket);
|
STREAM_ERROR_CHECK(socket);
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_ENTER
|
||||||
|
|
||||||
u16_t available = tcp_sndbuf(socket->pcb.tcp);
|
u16_t available = tcp_sndbuf(socket->pcb.tcp);
|
||||||
|
|
||||||
if (available == 0) {
|
if (available == 0) {
|
||||||
// Non-blocking socket
|
// Non-blocking socket
|
||||||
if (socket->timeout == 0) {
|
if (socket->timeout == 0) {
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
*_errno = MP_EAGAIN;
|
*_errno = MP_EAGAIN;
|
||||||
return MP_STREAM_ERROR;
|
return MP_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
@ -540,15 +653,17 @@ STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui
|
|||||||
// reset) by error callback.
|
// reset) by error callback.
|
||||||
// Avoid sending too small packets, so wait until at least 16 bytes available
|
// Avoid sending too small packets, so wait until at least 16 bytes available
|
||||||
while (socket->state >= STATE_CONNECTED && (available = tcp_sndbuf(socket->pcb.tcp)) < 16) {
|
while (socket->state >= STATE_CONNECTED && (available = tcp_sndbuf(socket->pcb.tcp)) < 16) {
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
if (socket->timeout != -1 && mp_hal_ticks_ms() - start > socket->timeout) {
|
if (socket->timeout != -1 && mp_hal_ticks_ms() - start > socket->timeout) {
|
||||||
*_errno = MP_ETIMEDOUT;
|
*_errno = MP_ETIMEDOUT;
|
||||||
return MP_STREAM_ERROR;
|
return MP_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
poll_sockets();
|
poll_sockets();
|
||||||
|
MICROPY_PY_LWIP_REENTER
|
||||||
}
|
}
|
||||||
|
|
||||||
// While we waited, something could happen
|
// While we waited, something could happen
|
||||||
STREAM_ERROR_CHECK(socket);
|
STREAM_ERROR_CHECK_WITH_LOCK(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
u16_t write_len = MIN(available, len);
|
u16_t write_len = MIN(available, len);
|
||||||
@ -560,6 +675,8 @@ STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui
|
|||||||
err = tcp_output(socket->pcb.tcp);
|
err = tcp_output(socket->pcb.tcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
*_errno = error_lookup_table[-err];
|
*_errno = error_lookup_table[-err];
|
||||||
return MP_STREAM_ERROR;
|
return MP_STREAM_ERROR;
|
||||||
@ -605,6 +722,8 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_ENTER
|
||||||
|
|
||||||
assert(socket->pcb.tcp != NULL);
|
assert(socket->pcb.tcp != NULL);
|
||||||
|
|
||||||
struct pbuf *p = socket->incoming.pbuf;
|
struct pbuf *p = socket->incoming.pbuf;
|
||||||
@ -630,6 +749,8 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
|
|||||||
}
|
}
|
||||||
tcp_recved(socket->pcb.tcp, len);
|
tcp_recved(socket->pcb.tcp, len);
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -769,47 +890,58 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_listen_obj, lwip_socket_listen);
|
|||||||
STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
|
STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
|
||||||
lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in);
|
lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
||||||
if (socket->pcb.tcp == NULL) {
|
|
||||||
mp_raise_OSError(MP_EBADF);
|
|
||||||
}
|
|
||||||
if (socket->type != MOD_NETWORK_SOCK_STREAM) {
|
if (socket->type != MOD_NETWORK_SOCK_STREAM) {
|
||||||
mp_raise_OSError(MP_EOPNOTSUPP);
|
mp_raise_OSError(MP_EOPNOTSUPP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create new socket object, do it here because we must not raise an out-of-memory
|
||||||
|
// exception when the LWIP concurrency lock is held
|
||||||
|
lwip_socket_obj_t *socket2 = m_new_obj_with_finaliser(lwip_socket_obj_t);
|
||||||
|
socket2->base.type = &lwip_socket_type;
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_ENTER
|
||||||
|
|
||||||
|
if (socket->pcb.tcp == NULL) {
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
m_del_obj(lwip_socket_obj_t, socket2);
|
||||||
|
mp_raise_OSError(MP_EBADF);
|
||||||
|
}
|
||||||
|
|
||||||
// I need to do this because "tcp_accepted", later, is a macro.
|
// I need to do this because "tcp_accepted", later, is a macro.
|
||||||
struct tcp_pcb *listener = socket->pcb.tcp;
|
struct tcp_pcb *listener = socket->pcb.tcp;
|
||||||
if (listener->state != LISTEN) {
|
if (listener->state != LISTEN) {
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
m_del_obj(lwip_socket_obj_t, socket2);
|
||||||
mp_raise_OSError(MP_EINVAL);
|
mp_raise_OSError(MP_EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// accept incoming connection
|
// accept incoming connection
|
||||||
struct tcp_pcb *volatile *incoming_connection;
|
struct tcp_pcb *volatile *incoming_connection = &lwip_socket_incoming_array(socket)[socket->incoming.connection.iget];
|
||||||
if (socket->incoming.connection.alloc == 0) {
|
|
||||||
incoming_connection = &socket->incoming.connection.tcp.item;
|
|
||||||
} else {
|
|
||||||
incoming_connection = &socket->incoming.connection.tcp.array[socket->incoming.connection.iget];
|
|
||||||
}
|
|
||||||
if (*incoming_connection == NULL) {
|
if (*incoming_connection == NULL) {
|
||||||
if (socket->timeout == 0) {
|
if (socket->timeout == 0) {
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
m_del_obj(lwip_socket_obj_t, socket2);
|
||||||
mp_raise_OSError(MP_EAGAIN);
|
mp_raise_OSError(MP_EAGAIN);
|
||||||
} else if (socket->timeout != -1) {
|
} else if (socket->timeout != -1) {
|
||||||
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
mp_uint_t retries = socket->timeout / 100;
|
||||||
|
while (*incoming_connection == NULL) {
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
if (retries-- == 0) {
|
||||||
|
m_del_obj(lwip_socket_obj_t, socket2);
|
||||||
|
mp_raise_OSError(MP_ETIMEDOUT);
|
||||||
|
}
|
||||||
mp_hal_delay_ms(100);
|
mp_hal_delay_ms(100);
|
||||||
if (*incoming_connection != NULL) break;
|
MICROPY_PY_LWIP_REENTER
|
||||||
}
|
|
||||||
if (*incoming_connection == NULL) {
|
|
||||||
mp_raise_OSError(MP_ETIMEDOUT);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (*incoming_connection == NULL) {
|
while (*incoming_connection == NULL) {
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
poll_sockets();
|
poll_sockets();
|
||||||
|
MICROPY_PY_LWIP_REENTER
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create new socket object
|
|
||||||
lwip_socket_obj_t *socket2 = m_new_obj_with_finaliser(lwip_socket_obj_t);
|
|
||||||
socket2->base.type = &lwip_socket_type;
|
|
||||||
|
|
||||||
// We get a new pcb handle...
|
// We get a new pcb handle...
|
||||||
socket2->pcb.tcp = *incoming_connection;
|
socket2->pcb.tcp = *incoming_connection;
|
||||||
if (++socket->incoming.connection.iget >= socket->incoming.connection.alloc) {
|
if (++socket->incoming.connection.iget >= socket->incoming.connection.alloc) {
|
||||||
@ -831,6 +963,8 @@ STATIC mp_obj_t lwip_socket_accept(mp_obj_t self_in) {
|
|||||||
|
|
||||||
tcp_accepted(listener);
|
tcp_accepted(listener);
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
|
||||||
// make the return value
|
// make the return value
|
||||||
uint8_t ip[NETUTILS_IPV4ADDR_BUFSIZE];
|
uint8_t ip[NETUTILS_IPV4ADDR_BUFSIZE];
|
||||||
memcpy(ip, &(socket2->pcb.tcp->remote_ip), sizeof(ip));
|
memcpy(ip, &(socket2->pcb.tcp->remote_ip), sizeof(ip));
|
||||||
@ -867,16 +1001,21 @@ STATIC mp_obj_t lwip_socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
|
|||||||
mp_raise_OSError(MP_EALREADY);
|
mp_raise_OSError(MP_EALREADY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register our receive callback.
|
// Register our receive callback.
|
||||||
|
MICROPY_PY_LWIP_ENTER
|
||||||
tcp_recv(socket->pcb.tcp, _lwip_tcp_recv);
|
tcp_recv(socket->pcb.tcp, _lwip_tcp_recv);
|
||||||
socket->state = STATE_CONNECTING;
|
socket->state = STATE_CONNECTING;
|
||||||
err = tcp_connect(socket->pcb.tcp, &dest, port, _lwip_tcp_connected);
|
err = tcp_connect(socket->pcb.tcp, &dest, port, _lwip_tcp_connected);
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
socket->state = STATE_NEW;
|
socket->state = STATE_NEW;
|
||||||
mp_raise_OSError(error_lookup_table[-err]);
|
mp_raise_OSError(error_lookup_table[-err]);
|
||||||
}
|
}
|
||||||
socket->peer_port = (mp_uint_t)port;
|
socket->peer_port = (mp_uint_t)port;
|
||||||
memcpy(socket->peer, &dest, sizeof(socket->peer));
|
memcpy(socket->peer, &dest, sizeof(socket->peer));
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
|
||||||
// And now we wait...
|
// And now we wait...
|
||||||
if (socket->timeout != -1) {
|
if (socket->timeout != -1) {
|
||||||
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
for (mp_uint_t retries = socket->timeout / 100; retries--;) {
|
||||||
@ -1207,10 +1346,19 @@ STATIC mp_uint_t lwip_socket_write(mp_obj_t self_in, const void *buf, mp_uint_t
|
|||||||
return MP_STREAM_ERROR;
|
return MP_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATIC err_t _lwip_tcp_close_poll(void *arg, struct tcp_pcb *pcb) {
|
||||||
|
// Connection has not been cleanly closed so just abort it to free up memory
|
||||||
|
tcp_poll(pcb, NULL, 0);
|
||||||
|
tcp_abort(pcb);
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
||||||
lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in);
|
lwip_socket_obj_t *socket = MP_OBJ_TO_PTR(self_in);
|
||||||
mp_uint_t ret;
|
mp_uint_t ret;
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_ENTER
|
||||||
|
|
||||||
if (request == MP_STREAM_POLL) {
|
if (request == MP_STREAM_POLL) {
|
||||||
uintptr_t flags = arg;
|
uintptr_t flags = arg;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -1218,10 +1366,8 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
|
|||||||
if (flags & MP_STREAM_POLL_RD) {
|
if (flags & MP_STREAM_POLL_RD) {
|
||||||
if (socket->state == STATE_LISTENING) {
|
if (socket->state == STATE_LISTENING) {
|
||||||
// Listening TCP socket may have one or multiple connections waiting
|
// Listening TCP socket may have one or multiple connections waiting
|
||||||
if ((socket->incoming.connection.alloc == 0
|
if (lwip_socket_incoming_array(socket)[socket->incoming.connection.iget] != NULL) {
|
||||||
&& socket->incoming.connection.tcp.item != NULL)
|
ret |= MP_STREAM_POLL_RD;
|
||||||
|| socket->incoming.connection.tcp.array[socket->incoming.connection.iget] != NULL) {
|
|
||||||
ret |= MP_STREAM_POLL_RD;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise there is just one slot for incoming data
|
// Otherwise there is just one slot for incoming data
|
||||||
@ -1231,9 +1377,15 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: pcb.tcp==NULL if state<0, and in this case we can't call tcp_sndbuf
|
if (flags & MP_STREAM_POLL_WR) {
|
||||||
if (flags & MP_STREAM_POLL_WR && socket->pcb.tcp != NULL && tcp_sndbuf(socket->pcb.tcp) > 0) {
|
if (socket->type == MOD_NETWORK_SOCK_DGRAM && socket->pcb.udp != NULL) {
|
||||||
ret |= MP_STREAM_POLL_WR;
|
// UDP socket is writable
|
||||||
|
ret |= MP_STREAM_POLL_WR;
|
||||||
|
} else if (socket->pcb.tcp != NULL && tcp_sndbuf(socket->pcb.tcp) > 0) {
|
||||||
|
// TCP socket is writable
|
||||||
|
// Note: pcb.tcp==NULL if state<0, and in this case we can't call tcp_sndbuf
|
||||||
|
ret |= MP_STREAM_POLL_WR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socket->state == STATE_NEW) {
|
if (socket->state == STATE_NEW) {
|
||||||
@ -1254,19 +1406,26 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (request == MP_STREAM_CLOSE) {
|
} else if (request == MP_STREAM_CLOSE) {
|
||||||
bool socket_is_listener = false;
|
|
||||||
|
|
||||||
if (socket->pcb.tcp == NULL) {
|
if (socket->pcb.tcp == NULL) {
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deregister callback (pcb.tcp is set to NULL below so must deregister now)
|
// Deregister callback (pcb.tcp is set to NULL below so must deregister now)
|
||||||
|
tcp_arg(socket->pcb.tcp, NULL);
|
||||||
|
tcp_err(socket->pcb.tcp, NULL);
|
||||||
tcp_recv(socket->pcb.tcp, NULL);
|
tcp_recv(socket->pcb.tcp, NULL);
|
||||||
|
|
||||||
|
// Free any incoming buffers or connections that are stored
|
||||||
|
lwip_socket_free_incoming(socket);
|
||||||
|
|
||||||
switch (socket->type) {
|
switch (socket->type) {
|
||||||
case MOD_NETWORK_SOCK_STREAM: {
|
case MOD_NETWORK_SOCK_STREAM: {
|
||||||
if (socket->pcb.tcp->state == LISTEN) {
|
if (socket->pcb.tcp->state != LISTEN) {
|
||||||
socket_is_listener = true;
|
// Schedule a callback to abort the connection if it's not cleanly closed after
|
||||||
|
// the given timeout. The callback must be set before calling tcp_close since
|
||||||
|
// the latter may free the pcb; if it doesn't then the callback will be active.
|
||||||
|
tcp_poll(socket->pcb.tcp, _lwip_tcp_close_poll, MICROPY_PY_LWIP_TCP_CLOSE_TIMEOUT_MS / 500);
|
||||||
}
|
}
|
||||||
if (tcp_close(socket->pcb.tcp) != ERR_OK) {
|
if (tcp_close(socket->pcb.tcp) != ERR_OK) {
|
||||||
DEBUG_printf("lwip_close: had to call tcp_abort()\n");
|
DEBUG_printf("lwip_close: had to call tcp_abort()\n");
|
||||||
@ -1277,30 +1436,9 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
|
|||||||
case MOD_NETWORK_SOCK_DGRAM: udp_remove(socket->pcb.udp); break;
|
case MOD_NETWORK_SOCK_DGRAM: udp_remove(socket->pcb.udp); break;
|
||||||
//case MOD_NETWORK_SOCK_RAW: raw_remove(socket->pcb.raw); break;
|
//case MOD_NETWORK_SOCK_RAW: raw_remove(socket->pcb.raw); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket->pcb.tcp = NULL;
|
socket->pcb.tcp = NULL;
|
||||||
socket->state = _ERR_BADF;
|
socket->state = _ERR_BADF;
|
||||||
if (!socket_is_listener) {
|
|
||||||
if (socket->incoming.pbuf != NULL) {
|
|
||||||
pbuf_free(socket->incoming.pbuf);
|
|
||||||
socket->incoming.pbuf = NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
uint8_t alloc = socket->incoming.connection.alloc;
|
|
||||||
struct tcp_pcb *volatile *tcp_array;
|
|
||||||
if (alloc == 0) {
|
|
||||||
tcp_array = &socket->incoming.connection.tcp.item;
|
|
||||||
} else {
|
|
||||||
tcp_array = socket->incoming.connection.tcp.array;
|
|
||||||
}
|
|
||||||
for (uint8_t i = 0; i < alloc; ++i) {
|
|
||||||
// Deregister callback and abort
|
|
||||||
if (tcp_array[i] != NULL) {
|
|
||||||
tcp_poll(tcp_array[i], NULL, 0);
|
|
||||||
tcp_abort(tcp_array[i]);
|
|
||||||
tcp_array[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -1308,6 +1446,8 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
|
|||||||
ret = MP_STREAM_ERROR;
|
ret = MP_STREAM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1448,14 +1588,17 @@ STATIC mp_obj_t lwip_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
|||||||
&& (type == 0 || type == MOD_NETWORK_SOCK_STREAM)
|
&& (type == 0 || type == MOD_NETWORK_SOCK_STREAM)
|
||||||
&& proto == 0
|
&& proto == 0
|
||||||
&& flags == 0)) {
|
&& flags == 0)) {
|
||||||
mp_warning("unsupported getaddrinfo constraints");
|
mp_warning(MP_WARN_CAT(RuntimeWarning), "unsupported getaddrinfo constraints");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getaddrinfo_state_t state;
|
getaddrinfo_state_t state;
|
||||||
state.status = 0;
|
state.status = 0;
|
||||||
|
|
||||||
|
MICROPY_PY_LWIP_ENTER
|
||||||
err_t ret = dns_gethostbyname(host, (ip_addr_t*)&state.ipaddr, lwip_getaddrinfo_cb, &state);
|
err_t ret = dns_gethostbyname(host, (ip_addr_t*)&state.ipaddr, lwip_getaddrinfo_cb, &state);
|
||||||
|
MICROPY_PY_LWIP_EXIT
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case ERR_OK:
|
case ERR_OK:
|
||||||
// cached
|
// cached
|
||||||
@ -1494,7 +1637,7 @@ STATIC mp_obj_t lwip_print_pcbs() {
|
|||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(lwip_print_pcbs_obj, lwip_print_pcbs);
|
MP_DEFINE_CONST_FUN_OBJ_0(lwip_print_pcbs_obj, lwip_print_pcbs);
|
||||||
|
|
||||||
#ifdef MICROPY_PY_LWIP
|
#if MICROPY_PY_LWIP
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = {
|
STATIC const mp_rom_map_elem_t mp_module_lwip_globals_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_lwip) },
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_lwip) },
|
||||||
|
|||||||
@ -41,10 +41,17 @@
|
|||||||
|
|
||||||
// values follow PEP 272
|
// values follow PEP 272
|
||||||
enum {
|
enum {
|
||||||
UCRYPTOLIB_MODE_MIN = 0,
|
UCRYPTOLIB_MODE_ECB = 1,
|
||||||
UCRYPTOLIB_MODE_ECB,
|
UCRYPTOLIB_MODE_CBC = 2,
|
||||||
UCRYPTOLIB_MODE_CBC,
|
UCRYPTOLIB_MODE_CTR = 6,
|
||||||
UCRYPTOLIB_MODE_MAX,
|
};
|
||||||
|
|
||||||
|
struct ctr_params {
|
||||||
|
// counter is the IV of the AES context.
|
||||||
|
|
||||||
|
size_t offset; // in encrypted_counter
|
||||||
|
// encrypted counter
|
||||||
|
uint8_t encrypted_counter[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
#if MICROPY_SSL_AXTLS
|
#if MICROPY_SSL_AXTLS
|
||||||
@ -82,6 +89,19 @@ typedef struct _mp_obj_aes_t {
|
|||||||
uint8_t key_type: 2;
|
uint8_t key_type: 2;
|
||||||
} mp_obj_aes_t;
|
} mp_obj_aes_t;
|
||||||
|
|
||||||
|
STATIC inline bool is_ctr_mode(int block_mode) {
|
||||||
|
#if MICROPY_PY_UCRYPTOLIB_CTR
|
||||||
|
return block_mode == UCRYPTOLIB_MODE_CTR;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC inline struct ctr_params *ctr_params_from_aes(mp_obj_aes_t *o) {
|
||||||
|
// ctr_params follows aes object struct
|
||||||
|
return (struct ctr_params*)&o[1];
|
||||||
|
}
|
||||||
|
|
||||||
#if MICROPY_SSL_AXTLS
|
#if MICROPY_SSL_AXTLS
|
||||||
STATIC void aes_initial_set_key_impl(AES_CTX_IMPL *ctx, const uint8_t *key, size_t keysize, const uint8_t iv[16]) {
|
STATIC void aes_initial_set_key_impl(AES_CTX_IMPL *ctx, const uint8_t *key, size_t keysize, const uint8_t iv[16]) {
|
||||||
assert(16 == keysize || 32 == keysize);
|
assert(16 == keysize || 32 == keysize);
|
||||||
@ -119,6 +139,33 @@ STATIC void aes_process_cbc_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *
|
|||||||
AES_cbc_decrypt(ctx, in, out, in_len);
|
AES_cbc_decrypt(ctx, in, out, in_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MICROPY_PY_UCRYPTOLIB_CTR
|
||||||
|
// axTLS doesn't have CTR support out of the box. This implements the counter part using the ECB primitive.
|
||||||
|
STATIC void aes_process_ctr_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, struct ctr_params *ctr_params) {
|
||||||
|
size_t n = ctr_params->offset;
|
||||||
|
uint8_t *const counter = ctx->iv;
|
||||||
|
|
||||||
|
while (in_len--) {
|
||||||
|
if (n == 0) {
|
||||||
|
aes_process_ecb_impl(ctx, counter, ctr_params->encrypted_counter, true);
|
||||||
|
|
||||||
|
// increment the 128-bit counter
|
||||||
|
for (int i = 15; i >= 0; --i) {
|
||||||
|
if (++counter[i] != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*out++ = *in++ ^ ctr_params->encrypted_counter[n];
|
||||||
|
n = (n + 1) & 0xf;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctr_params->offset = n;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MICROPY_SSL_MBEDTLS
|
#if MICROPY_SSL_MBEDTLS
|
||||||
@ -155,20 +202,38 @@ STATIC void aes_process_ecb_impl(AES_CTX_IMPL *ctx, const uint8_t in[16], uint8_
|
|||||||
STATIC void aes_process_cbc_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, bool encrypt) {
|
STATIC void aes_process_cbc_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, bool encrypt) {
|
||||||
mbedtls_aes_crypt_cbc(&ctx->u.mbedtls_ctx, encrypt ? MBEDTLS_AES_ENCRYPT : MBEDTLS_AES_DECRYPT, in_len, ctx->iv, in, out);
|
mbedtls_aes_crypt_cbc(&ctx->u.mbedtls_ctx, encrypt ? MBEDTLS_AES_ENCRYPT : MBEDTLS_AES_DECRYPT, in_len, ctx->iv, in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MICROPY_PY_UCRYPTOLIB_CTR
|
||||||
|
STATIC void aes_process_ctr_impl(AES_CTX_IMPL *ctx, const uint8_t *in, uint8_t *out, size_t in_len, struct ctr_params *ctr_params) {
|
||||||
|
mbedtls_aes_crypt_ctr(&ctx->u.mbedtls_ctx, in_len, &ctr_params->offset, ctx->iv, ctr_params->encrypted_counter, in, out);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||||
mp_arg_check_num(n_args, n_kw, 2, 3, false);
|
mp_arg_check_num(n_args, n_kw, 2, 3, false);
|
||||||
mp_obj_aes_t *o = m_new_obj(mp_obj_aes_t);
|
|
||||||
|
const mp_int_t block_mode = mp_obj_get_int(args[1]);
|
||||||
|
|
||||||
|
switch (block_mode) {
|
||||||
|
case UCRYPTOLIB_MODE_ECB:
|
||||||
|
case UCRYPTOLIB_MODE_CBC:
|
||||||
|
#if MICROPY_PY_UCRYPTOLIB_CTR
|
||||||
|
case UCRYPTOLIB_MODE_CTR:
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
mp_raise_ValueError("mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_obj_aes_t *o = m_new_obj_var(mp_obj_aes_t, struct ctr_params, !!is_ctr_mode(block_mode));
|
||||||
o->base.type = type;
|
o->base.type = type;
|
||||||
|
|
||||||
o->block_mode = mp_obj_get_int(args[1]);
|
o->block_mode = block_mode;
|
||||||
o->key_type = AES_KEYTYPE_NONE;
|
o->key_type = AES_KEYTYPE_NONE;
|
||||||
|
|
||||||
if (o->block_mode <= UCRYPTOLIB_MODE_MIN || o->block_mode >= UCRYPTOLIB_MODE_MAX) {
|
|
||||||
mp_raise_ValueError("mode");
|
|
||||||
}
|
|
||||||
|
|
||||||
mp_buffer_info_t keyinfo;
|
mp_buffer_info_t keyinfo;
|
||||||
mp_get_buffer_raise(args[0], &keyinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(args[0], &keyinfo, MP_BUFFER_READ);
|
||||||
if (32 != keyinfo.len && 16 != keyinfo.len) {
|
if (32 != keyinfo.len && 16 != keyinfo.len) {
|
||||||
@ -183,10 +248,14 @@ STATIC mp_obj_t ucryptolib_aes_make_new(const mp_obj_type_t *type, size_t n_args
|
|||||||
if (16 != ivinfo.len) {
|
if (16 != ivinfo.len) {
|
||||||
mp_raise_ValueError("IV");
|
mp_raise_ValueError("IV");
|
||||||
}
|
}
|
||||||
} else if (o->block_mode == UCRYPTOLIB_MODE_CBC) {
|
} else if (o->block_mode == UCRYPTOLIB_MODE_CBC || is_ctr_mode(o->block_mode)) {
|
||||||
mp_raise_ValueError("IV");
|
mp_raise_ValueError("IV");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_ctr_mode(block_mode)) {
|
||||||
|
ctr_params_from_aes(o)->offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
aes_initial_set_key_impl(&o->ctx, keyinfo.buf, keyinfo.len, ivinfo.buf);
|
aes_initial_set_key_impl(&o->ctx, keyinfo.buf, keyinfo.len, ivinfo.buf);
|
||||||
|
|
||||||
return MP_OBJ_FROM_PTR(o);
|
return MP_OBJ_FROM_PTR(o);
|
||||||
@ -204,7 +273,7 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) {
|
|||||||
mp_buffer_info_t in_bufinfo;
|
mp_buffer_info_t in_bufinfo;
|
||||||
mp_get_buffer_raise(in_buf, &in_bufinfo, MP_BUFFER_READ);
|
mp_get_buffer_raise(in_buf, &in_bufinfo, MP_BUFFER_READ);
|
||||||
|
|
||||||
if (in_bufinfo.len % 16 != 0) {
|
if (!is_ctr_mode(self->block_mode) && in_bufinfo.len % 16 != 0) {
|
||||||
mp_raise_ValueError("blksize % 16");
|
mp_raise_ValueError("blksize % 16");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +293,9 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (AES_KEYTYPE_NONE == self->key_type) {
|
if (AES_KEYTYPE_NONE == self->key_type) {
|
||||||
aes_final_set_key_impl(&self->ctx, encrypt);
|
// always set key for encryption if CTR mode.
|
||||||
|
const bool encrypt_mode = encrypt || is_ctr_mode(self->block_mode);
|
||||||
|
aes_final_set_key_impl(&self->ctx, encrypt_mode);
|
||||||
self->key_type = encrypt ? AES_KEYTYPE_ENC : AES_KEYTYPE_DEC;
|
self->key_type = encrypt ? AES_KEYTYPE_ENC : AES_KEYTYPE_DEC;
|
||||||
} else {
|
} else {
|
||||||
if ((encrypt && self->key_type == AES_KEYTYPE_DEC) ||
|
if ((encrypt && self->key_type == AES_KEYTYPE_DEC) ||
|
||||||
@ -234,14 +305,26 @@ STATIC mp_obj_t aes_process(size_t n_args, const mp_obj_t *args, bool encrypt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->block_mode == UCRYPTOLIB_MODE_ECB) {
|
switch (self->block_mode) {
|
||||||
uint8_t *in = in_bufinfo.buf, *out = out_buf_ptr;
|
case UCRYPTOLIB_MODE_ECB: {
|
||||||
uint8_t *top = in + in_bufinfo.len;
|
uint8_t *in = in_bufinfo.buf, *out = out_buf_ptr;
|
||||||
for (; in < top; in += 16, out += 16) {
|
uint8_t *top = in + in_bufinfo.len;
|
||||||
aes_process_ecb_impl(&self->ctx, in, out, encrypt);
|
for (; in < top; in += 16, out += 16) {
|
||||||
|
aes_process_ecb_impl(&self->ctx, in, out, encrypt);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
aes_process_cbc_impl(&self->ctx, in_bufinfo.buf, out_buf_ptr, in_bufinfo.len, encrypt);
|
case UCRYPTOLIB_MODE_CBC:
|
||||||
|
aes_process_cbc_impl(&self->ctx, in_bufinfo.buf, out_buf_ptr, in_bufinfo.len, encrypt);
|
||||||
|
break;
|
||||||
|
|
||||||
|
#if MICROPY_PY_UCRYPTOLIB_CTR
|
||||||
|
case UCRYPTOLIB_MODE_CTR:
|
||||||
|
aes_process_ctr_impl(&self->ctx, in_bufinfo.buf, out_buf_ptr, in_bufinfo.len,
|
||||||
|
ctr_params_from_aes(self));
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_buf != MP_OBJ_NULL) {
|
if (out_buf != MP_OBJ_NULL) {
|
||||||
@ -279,6 +362,9 @@ STATIC const mp_rom_map_elem_t mp_module_ucryptolib_globals_table[] = {
|
|||||||
#if MICROPY_PY_UCRYPTOLIB_CONSTS
|
#if MICROPY_PY_UCRYPTOLIB_CONSTS
|
||||||
{ MP_ROM_QSTR(MP_QSTR_MODE_ECB), MP_ROM_INT(UCRYPTOLIB_MODE_ECB) },
|
{ MP_ROM_QSTR(MP_QSTR_MODE_ECB), MP_ROM_INT(UCRYPTOLIB_MODE_ECB) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_MODE_CBC), MP_ROM_INT(UCRYPTOLIB_MODE_CBC) },
|
{ MP_ROM_QSTR(MP_QSTR_MODE_CBC), MP_ROM_INT(UCRYPTOLIB_MODE_CBC) },
|
||||||
|
#if MICROPY_PY_UCRYPTOLIB_CTR
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_MODE_CTR), MP_ROM_INT(UCRYPTOLIB_MODE_CTR) },
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -137,13 +137,13 @@ STATIC void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_p
|
|||||||
(void)kind;
|
(void)kind;
|
||||||
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
const char *typen = "unk";
|
const char *typen = "unk";
|
||||||
if (MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)
|
if (mp_obj_is_type(self->desc, &mp_type_dict)
|
||||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||||
|| MP_OBJ_IS_TYPE(self->desc, &mp_type_ordereddict)
|
|| mp_obj_is_type(self->desc, &mp_type_ordereddict)
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
typen = "STRUCT";
|
typen = "STRUCT";
|
||||||
} else if (MP_OBJ_IS_TYPE(self->desc, &mp_type_tuple)) {
|
} else if (mp_obj_is_type(self->desc, &mp_type_tuple)) {
|
||||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc);
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc);
|
||||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
||||||
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
||||||
@ -210,14 +210,14 @@ STATIC mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, int layout_type, mp_
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size) {
|
STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size) {
|
||||||
if (!MP_OBJ_IS_TYPE(desc_in, &mp_type_dict)
|
if (!mp_obj_is_type(desc_in, &mp_type_dict)
|
||||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||||
&& !MP_OBJ_IS_TYPE(desc_in, &mp_type_ordereddict)
|
&& !mp_obj_is_type(desc_in, &mp_type_ordereddict)
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
if (MP_OBJ_IS_TYPE(desc_in, &mp_type_tuple)) {
|
if (mp_obj_is_type(desc_in, &mp_type_tuple)) {
|
||||||
return uctypes_struct_agg_size((mp_obj_tuple_t*)MP_OBJ_TO_PTR(desc_in), layout_type, max_field_size);
|
return uctypes_struct_agg_size((mp_obj_tuple_t*)MP_OBJ_TO_PTR(desc_in), layout_type, max_field_size);
|
||||||
} else if (MP_OBJ_IS_SMALL_INT(desc_in)) {
|
} else if (mp_obj_is_small_int(desc_in)) {
|
||||||
// We allow sizeof on both type definitions and structures/structure fields,
|
// We allow sizeof on both type definitions and structures/structure fields,
|
||||||
// but scalar structure field is lowered into native Python int, so all
|
// but scalar structure field is lowered into native Python int, so all
|
||||||
// type info is lost. So, we cannot say if it's scalar type description,
|
// type info is lost. So, we cannot say if it's scalar type description,
|
||||||
@ -231,9 +231,9 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_
|
|||||||
mp_uint_t total_size = 0;
|
mp_uint_t total_size = 0;
|
||||||
|
|
||||||
for (mp_uint_t i = 0; i < d->map.alloc; i++) {
|
for (mp_uint_t i = 0; i < d->map.alloc; i++) {
|
||||||
if (MP_MAP_SLOT_IS_FILLED(&d->map, i)) {
|
if (mp_map_slot_is_filled(&d->map, i)) {
|
||||||
mp_obj_t v = d->map.table[i].value;
|
mp_obj_t v = d->map.table[i].value;
|
||||||
if (MP_OBJ_IS_SMALL_INT(v)) {
|
if (mp_obj_is_small_int(v)) {
|
||||||
mp_uint_t offset = MP_OBJ_SMALL_INT_VALUE(v);
|
mp_uint_t offset = MP_OBJ_SMALL_INT_VALUE(v);
|
||||||
mp_uint_t val_type = GET_TYPE(offset, VAL_TYPE_BITS);
|
mp_uint_t val_type = GET_TYPE(offset, VAL_TYPE_BITS);
|
||||||
offset &= VALUE_MASK(VAL_TYPE_BITS);
|
offset &= VALUE_MASK(VAL_TYPE_BITS);
|
||||||
@ -248,7 +248,7 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_
|
|||||||
total_size = offset + s;
|
total_size = offset + s;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!MP_OBJ_IS_TYPE(v, &mp_type_tuple)) {
|
if (!mp_obj_is_type(v, &mp_type_tuple)) {
|
||||||
syntax_error();
|
syntax_error();
|
||||||
}
|
}
|
||||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(v);
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(v);
|
||||||
@ -272,13 +272,13 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_
|
|||||||
STATIC mp_obj_t uctypes_struct_sizeof(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t uctypes_struct_sizeof(size_t n_args, const mp_obj_t *args) {
|
||||||
mp_obj_t obj_in = args[0];
|
mp_obj_t obj_in = args[0];
|
||||||
mp_uint_t max_field_size = 0;
|
mp_uint_t max_field_size = 0;
|
||||||
if (MP_OBJ_IS_TYPE(obj_in, &mp_type_bytearray)) {
|
if (mp_obj_is_type(obj_in, &mp_type_bytearray)) {
|
||||||
return mp_obj_len(obj_in);
|
return mp_obj_len(obj_in);
|
||||||
}
|
}
|
||||||
int layout_type = LAYOUT_NATIVE;
|
int layout_type = LAYOUT_NATIVE;
|
||||||
// We can apply sizeof either to structure definition (a dict)
|
// We can apply sizeof either to structure definition (a dict)
|
||||||
// or to instantiated structure
|
// or to instantiated structure
|
||||||
if (MP_OBJ_IS_TYPE(obj_in, &uctypes_struct_type)) {
|
if (mp_obj_is_type(obj_in, &uctypes_struct_type)) {
|
||||||
if (n_args != 1) {
|
if (n_args != 1) {
|
||||||
mp_raise_TypeError(NULL);
|
mp_raise_TypeError(NULL);
|
||||||
}
|
}
|
||||||
@ -406,16 +406,16 @@ STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) {
|
|||||||
STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set_val) {
|
STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set_val) {
|
||||||
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
|
||||||
if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)
|
if (!mp_obj_is_type(self->desc, &mp_type_dict)
|
||||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||||
&& !MP_OBJ_IS_TYPE(self->desc, &mp_type_ordereddict)
|
&& !mp_obj_is_type(self->desc, &mp_type_ordereddict)
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
mp_raise_TypeError("struct: no fields");
|
mp_raise_TypeError("struct: no fields");
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr));
|
mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr));
|
||||||
if (MP_OBJ_IS_SMALL_INT(deref)) {
|
if (mp_obj_is_small_int(deref)) {
|
||||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(deref);
|
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(deref);
|
||||||
mp_uint_t val_type = GET_TYPE(offset, VAL_TYPE_BITS);
|
mp_uint_t val_type = GET_TYPE(offset, VAL_TYPE_BITS);
|
||||||
offset &= VALUE_MASK(VAL_TYPE_BITS);
|
offset &= VALUE_MASK(VAL_TYPE_BITS);
|
||||||
@ -476,7 +476,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
|
|||||||
return MP_OBJ_NULL;
|
return MP_OBJ_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MP_OBJ_IS_TYPE(deref, &mp_type_tuple)) {
|
if (!mp_obj_is_type(deref, &mp_type_tuple)) {
|
||||||
syntax_error();
|
syntax_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,7 +543,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
|
|||||||
return MP_OBJ_NULL; // op not supported
|
return MP_OBJ_NULL; // op not supported
|
||||||
} else {
|
} else {
|
||||||
// load / store
|
// load / store
|
||||||
if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_tuple)) {
|
if (!mp_obj_is_type(self->desc, &mp_type_tuple)) {
|
||||||
mp_raise_TypeError("struct: cannot index");
|
mp_raise_TypeError("struct: cannot index");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,7 +594,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
|
|||||||
|
|
||||||
} else if (agg_type == PTR) {
|
} else if (agg_type == PTR) {
|
||||||
byte *p = *(void**)self->addr;
|
byte *p = *(void**)self->addr;
|
||||||
if (MP_OBJ_IS_SMALL_INT(t->items[1])) {
|
if (mp_obj_is_small_int(t->items[1])) {
|
||||||
uint val_type = GET_TYPE(MP_OBJ_SMALL_INT_VALUE(t->items[1]), VAL_TYPE_BITS);
|
uint val_type = GET_TYPE(MP_OBJ_SMALL_INT_VALUE(t->items[1]), VAL_TYPE_BITS);
|
||||||
return get_aligned(val_type, p, index);
|
return get_aligned(val_type, p, index);
|
||||||
} else {
|
} else {
|
||||||
@ -618,7 +618,7 @@ STATIC mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
|||||||
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case MP_UNARY_OP_INT:
|
case MP_UNARY_OP_INT:
|
||||||
if (MP_OBJ_IS_TYPE(self->desc, &mp_type_tuple)) {
|
if (mp_obj_is_type(self->desc, &mp_type_tuple)) {
|
||||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc);
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc);
|
||||||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
||||||
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
||||||
|
|||||||
@ -104,6 +104,8 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#include "crypto-algorithms/sha256.c"
|
||||||
|
|
||||||
STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||||
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX));
|
mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX));
|
||||||
@ -344,8 +346,4 @@ const mp_obj_module_t mp_module_uhashlib = {
|
|||||||
.globals = (mp_obj_dict_t*)&mp_module_uhashlib_globals,
|
.globals = (mp_obj_dict_t*)&mp_module_uhashlib_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#if MICROPY_PY_UHASHLIB_SHA256
|
|
||||||
#include "crypto-algorithms/sha256.c"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif //MICROPY_PY_UHASHLIB
|
#endif //MICROPY_PY_UHASHLIB
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
// the algorithm here is modelled on CPython's heapq.py
|
// the algorithm here is modelled on CPython's heapq.py
|
||||||
|
|
||||||
STATIC mp_obj_list_t *get_heap(mp_obj_t heap_in) {
|
STATIC mp_obj_list_t *get_heap(mp_obj_t heap_in) {
|
||||||
if (!MP_OBJ_IS_TYPE(heap_in, &mp_type_list)) {
|
if (!mp_obj_is_type(heap_in, &mp_type_list)) {
|
||||||
mp_raise_TypeError("heap must be a list");
|
mp_raise_TypeError("heap must be a list");
|
||||||
}
|
}
|
||||||
return MP_OBJ_TO_PTR(heap_in);
|
return MP_OBJ_TO_PTR(heap_in);
|
||||||
|
|||||||
@ -185,7 +185,7 @@ STATIC mp_obj_t mod_ujson_load(mp_obj_t stream_obj) {
|
|||||||
cur = S_CUR(s);
|
cur = S_CUR(s);
|
||||||
if (cur == '.' || cur == 'E' || cur == 'e') {
|
if (cur == '.' || cur == 'E' || cur == 'e') {
|
||||||
flt = true;
|
flt = true;
|
||||||
} else if (cur == '-' || unichar_isdigit(cur)) {
|
} else if (cur == '+' || cur == '-' || unichar_isdigit(cur)) {
|
||||||
// pass
|
// pass
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -200,8 +200,19 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_urandom_uniform_obj, mod_urandom_uniform);
|
|||||||
|
|
||||||
#endif // MICROPY_PY_URANDOM_EXTRA_FUNCS
|
#endif // MICROPY_PY_URANDOM_EXTRA_FUNCS
|
||||||
|
|
||||||
|
#ifdef MICROPY_PY_URANDOM_SEED_INIT_FUNC
|
||||||
|
STATIC mp_obj_t mod_urandom___init__() {
|
||||||
|
mod_urandom_seed(MP_OBJ_NEW_SMALL_INT(MICROPY_PY_URANDOM_SEED_INIT_FUNC));
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_urandom___init___obj, mod_urandom___init__);
|
||||||
|
#endif
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t mp_module_urandom_globals_table[] = {
|
STATIC const mp_rom_map_elem_t mp_module_urandom_globals_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_urandom) },
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_urandom) },
|
||||||
|
#ifdef MICROPY_PY_URANDOM_SEED_INIT_FUNC
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&mod_urandom___init___obj) },
|
||||||
|
#endif
|
||||||
{ MP_ROM_QSTR(MP_QSTR_getrandbits), MP_ROM_PTR(&mod_urandom_getrandbits_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_getrandbits), MP_ROM_PTR(&mod_urandom_getrandbits_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_urandom_seed_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_urandom_seed_obj) },
|
||||||
#if MICROPY_PY_URANDOM_EXTRA_FUNCS
|
#if MICROPY_PY_URANDOM_EXTRA_FUNCS
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014 Damien P. George
|
* Copyright (c) 2014 Damien P. George
|
||||||
|
* Copyright (c) 2015-2017 Paul Sokolovsky
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -77,7 +78,7 @@ STATIC void poll_map_add(mp_map_t *poll_map, const mp_obj_t *obj, mp_uint_t obj_
|
|||||||
STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, size_t *rwx_num) {
|
STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, size_t *rwx_num) {
|
||||||
mp_uint_t n_ready = 0;
|
mp_uint_t n_ready = 0;
|
||||||
for (mp_uint_t i = 0; i < poll_map->alloc; ++i) {
|
for (mp_uint_t i = 0; i < poll_map->alloc; ++i) {
|
||||||
if (!MP_MAP_SLOT_IS_FILLED(poll_map, i)) {
|
if (!mp_map_slot_is_filled(poll_map, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, size_t *rwx_num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// \function select(rlist, wlist, xlist[, timeout])
|
/// \function select(rlist, wlist, xlist[, timeout])
|
||||||
STATIC mp_obj_t select_select(uint n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) {
|
||||||
// get array data from tuple/list arguments
|
// get array data from tuple/list arguments
|
||||||
size_t rwx_len[3];
|
size_t rwx_len[3];
|
||||||
mp_obj_t *r_array, *w_array, *x_array;
|
mp_obj_t *r_array, *w_array, *x_array;
|
||||||
@ -155,7 +156,7 @@ STATIC mp_obj_t select_select(uint n_args, const mp_obj_t *args) {
|
|||||||
list_array[2] = mp_obj_new_list(rwx_len[2], NULL);
|
list_array[2] = mp_obj_new_list(rwx_len[2], NULL);
|
||||||
rwx_len[0] = rwx_len[1] = rwx_len[2] = 0;
|
rwx_len[0] = rwx_len[1] = rwx_len[2] = 0;
|
||||||
for (mp_uint_t i = 0; i < poll_map.alloc; ++i) {
|
for (mp_uint_t i = 0; i < poll_map.alloc; ++i) {
|
||||||
if (!MP_MAP_SLOT_IS_FILLED(&poll_map, i)) {
|
if (!mp_map_slot_is_filled(&poll_map, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
poll_obj_t *poll_obj = MP_OBJ_TO_PTR(poll_map.table[i].value);
|
poll_obj_t *poll_obj = MP_OBJ_TO_PTR(poll_map.table[i].value);
|
||||||
@ -190,7 +191,7 @@ typedef struct _mp_obj_poll_t {
|
|||||||
} mp_obj_poll_t;
|
} mp_obj_poll_t;
|
||||||
|
|
||||||
/// \method register(obj[, eventmask])
|
/// \method register(obj[, eventmask])
|
||||||
STATIC mp_obj_t poll_register(uint n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t poll_register(size_t n_args, const mp_obj_t *args) {
|
||||||
mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]);
|
mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||||
mp_uint_t flags;
|
mp_uint_t flags;
|
||||||
if (n_args == 3) {
|
if (n_args == 3) {
|
||||||
@ -266,7 +267,7 @@ STATIC mp_obj_t poll_poll(size_t n_args, const mp_obj_t *args) {
|
|||||||
mp_obj_list_t *ret_list = MP_OBJ_TO_PTR(mp_obj_new_list(n_ready, NULL));
|
mp_obj_list_t *ret_list = MP_OBJ_TO_PTR(mp_obj_new_list(n_ready, NULL));
|
||||||
n_ready = 0;
|
n_ready = 0;
|
||||||
for (mp_uint_t i = 0; i < self->poll_map.alloc; ++i) {
|
for (mp_uint_t i = 0; i < self->poll_map.alloc; ++i) {
|
||||||
if (!MP_MAP_SLOT_IS_FILLED(&self->poll_map, i)) {
|
if (!mp_map_slot_is_filled(&self->poll_map, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
poll_obj_t *poll_obj = MP_OBJ_TO_PTR(self->poll_map.table[i].value);
|
poll_obj_t *poll_obj = MP_OBJ_TO_PTR(self->poll_map.table[i].value);
|
||||||
@ -309,7 +310,7 @@ STATIC mp_obj_t poll_iternext(mp_obj_t self_in) {
|
|||||||
|
|
||||||
for (mp_uint_t i = self->iter_idx; i < self->poll_map.alloc; ++i) {
|
for (mp_uint_t i = self->iter_idx; i < self->poll_map.alloc; ++i) {
|
||||||
self->iter_idx++;
|
self->iter_idx++;
|
||||||
if (!MP_MAP_SLOT_IS_FILLED(&self->poll_map, i)) {
|
if (!mp_map_slot_is_filled(&self->poll_map, i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
poll_obj_t *poll_obj = MP_OBJ_TO_PTR(self->poll_map.table[i].value);
|
poll_obj_t *poll_obj = MP_OBJ_TO_PTR(self->poll_map.table[i].value);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015-2017 Paul Sokolovsky
|
* Copyright (c) 2015-2019 Paul Sokolovsky
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -41,6 +41,7 @@ typedef struct _mp_obj_ssl_socket_t {
|
|||||||
SSL *ssl_sock;
|
SSL *ssl_sock;
|
||||||
byte *buf;
|
byte *buf;
|
||||||
uint32_t bytes_left;
|
uint32_t bytes_left;
|
||||||
|
bool blocking;
|
||||||
} mp_obj_ssl_socket_t;
|
} mp_obj_ssl_socket_t;
|
||||||
|
|
||||||
struct ssl_args {
|
struct ssl_args {
|
||||||
@ -48,6 +49,7 @@ struct ssl_args {
|
|||||||
mp_arg_val_t cert;
|
mp_arg_val_t cert;
|
||||||
mp_arg_val_t server_side;
|
mp_arg_val_t server_side;
|
||||||
mp_arg_val_t server_hostname;
|
mp_arg_val_t server_hostname;
|
||||||
|
mp_arg_val_t do_handshake;
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC const mp_obj_type_t ussl_socket_type;
|
STATIC const mp_obj_type_t ussl_socket_type;
|
||||||
@ -62,8 +64,12 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
|||||||
o->buf = NULL;
|
o->buf = NULL;
|
||||||
o->bytes_left = 0;
|
o->bytes_left = 0;
|
||||||
o->sock = sock;
|
o->sock = sock;
|
||||||
|
o->blocking = true;
|
||||||
|
|
||||||
uint32_t options = SSL_SERVER_VERIFY_LATER;
|
uint32_t options = SSL_SERVER_VERIFY_LATER;
|
||||||
|
if (!args->do_handshake.u_bool) {
|
||||||
|
options |= SSL_CONNECT_IN_PARTS;
|
||||||
|
}
|
||||||
if (args->key.u_obj != mp_const_none) {
|
if (args->key.u_obj != mp_const_none) {
|
||||||
options |= SSL_NO_DEFAULT_KEY;
|
options |= SSL_NO_DEFAULT_KEY;
|
||||||
}
|
}
|
||||||
@ -97,17 +103,14 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
|||||||
|
|
||||||
o->ssl_sock = ssl_client_new(o->ssl_ctx, (long)sock, NULL, 0, ext);
|
o->ssl_sock = ssl_client_new(o->ssl_ctx, (long)sock, NULL, 0, ext);
|
||||||
|
|
||||||
int res = ssl_handshake_status(o->ssl_sock);
|
if (args->do_handshake.u_bool) {
|
||||||
// Pointer to SSL_EXTENSIONS as being passed to ssl_client_new()
|
int res = ssl_handshake_status(o->ssl_sock);
|
||||||
// is saved in ssl_sock->extensions.
|
|
||||||
// As of axTLS 2.1.3, extensions aren't used beyond the initial
|
|
||||||
// handshake, and that's pretty much how it's expected to be. So
|
|
||||||
// we allocate them on stack and reset the pointer after handshake.
|
|
||||||
|
|
||||||
if (res != SSL_OK) {
|
if (res != SSL_OK) {
|
||||||
printf("ssl_handshake_status: %d\n", res);
|
printf("ssl_handshake_status: %d\n", res);
|
||||||
ssl_display_error(res);
|
ssl_display_error(res);
|
||||||
mp_raise_OSError(MP_EIO);
|
mp_raise_OSError(MP_EIO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -133,8 +136,18 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc
|
|||||||
mp_int_t r = ssl_read(o->ssl_sock, &o->buf);
|
mp_int_t r = ssl_read(o->ssl_sock, &o->buf);
|
||||||
if (r == SSL_OK) {
|
if (r == SSL_OK) {
|
||||||
// SSL_OK from ssl_read() means "everything is ok, but there's
|
// SSL_OK from ssl_read() means "everything is ok, but there's
|
||||||
// no user data yet". So, we just keep reading.
|
// no user data yet". It may happen e.g. if handshake is not
|
||||||
continue;
|
// finished yet. The best way we can treat it is by returning
|
||||||
|
// EAGAIN. This may be a bit unexpected in blocking mode, but
|
||||||
|
// default is to perform complete handshake in constructor, so
|
||||||
|
// this should not happen in blocking mode. On the other hand,
|
||||||
|
// in nonblocking mode EAGAIN (comparing to the alternative of
|
||||||
|
// looping) is really preferrable.
|
||||||
|
if (o->blocking) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
goto eagain;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
if (r == SSL_CLOSE_NOTIFY || r == SSL_ERROR_CONN_LOST) {
|
if (r == SSL_CLOSE_NOTIFY || r == SSL_ERROR_CONN_LOST) {
|
||||||
@ -142,6 +155,7 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (r == SSL_EAGAIN) {
|
if (r == SSL_EAGAIN) {
|
||||||
|
eagain:
|
||||||
r = MP_EAGAIN;
|
r = MP_EAGAIN;
|
||||||
}
|
}
|
||||||
*errcode = r;
|
*errcode = r;
|
||||||
@ -187,12 +201,14 @@ STATIC mp_uint_t socket_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
|
STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
|
||||||
// Currently supports only blocking mode
|
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(self_in);
|
||||||
(void)self_in;
|
mp_obj_t sock = o->sock;
|
||||||
if (!mp_obj_is_true(flag_in)) {
|
mp_obj_t dest[3];
|
||||||
mp_raise_NotImplementedError(NULL);
|
mp_load_method(sock, MP_QSTR_setblocking, dest);
|
||||||
}
|
dest[2] = flag_in;
|
||||||
return mp_const_none;
|
mp_obj_t res = mp_call_method_n_kw(1, 0, dest);
|
||||||
|
o->blocking = mp_obj_is_true(flag_in);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_setblocking_obj, socket_setblocking);
|
||||||
|
|
||||||
@ -234,6 +250,7 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_
|
|||||||
{ MP_QSTR_cert, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
|
{ MP_QSTR_cert, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
|
||||||
{ MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
{ MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
||||||
{ MP_QSTR_server_hostname, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
|
{ MP_QSTR_server_hostname, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
|
||||||
|
{ MP_QSTR_do_handshake, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Check that sock implements stream protocol
|
// TODO: Check that sock implements stream protocol
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 Linaro Ltd.
|
* Copyright (c) 2016 Linaro Ltd.
|
||||||
|
* Copyright (c) 2019 Paul Sokolovsky
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -36,7 +37,6 @@
|
|||||||
|
|
||||||
// mbedtls_time_t
|
// mbedtls_time_t
|
||||||
#include "mbedtls/platform.h"
|
#include "mbedtls/platform.h"
|
||||||
#include "mbedtls/net.h"
|
|
||||||
#include "mbedtls/ssl.h"
|
#include "mbedtls/ssl.h"
|
||||||
#include "mbedtls/x509_crt.h"
|
#include "mbedtls/x509_crt.h"
|
||||||
#include "mbedtls/pk.h"
|
#include "mbedtls/pk.h"
|
||||||
@ -61,6 +61,7 @@ struct ssl_args {
|
|||||||
mp_arg_val_t cert;
|
mp_arg_val_t cert;
|
||||||
mp_arg_val_t server_side;
|
mp_arg_val_t server_side;
|
||||||
mp_arg_val_t server_hostname;
|
mp_arg_val_t server_hostname;
|
||||||
|
mp_arg_val_t do_handshake;
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC const mp_obj_type_t ussl_socket_type;
|
STATIC const mp_obj_type_t ussl_socket_type;
|
||||||
@ -185,10 +186,12 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
|||||||
assert(ret == 0);
|
assert(ret == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((ret = mbedtls_ssl_handshake(&o->ssl)) != 0) {
|
if (args->do_handshake.u_bool) {
|
||||||
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
|
while ((ret = mbedtls_ssl_handshake(&o->ssl)) != 0) {
|
||||||
printf("mbedtls_ssl_handshake error: -%x\n", -ret);
|
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
|
||||||
goto cleanup;
|
printf("mbedtls_ssl_handshake error: -%x\n", -ret);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,6 +242,11 @@ STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc
|
|||||||
}
|
}
|
||||||
if (ret == MBEDTLS_ERR_SSL_WANT_READ) {
|
if (ret == MBEDTLS_ERR_SSL_WANT_READ) {
|
||||||
ret = MP_EWOULDBLOCK;
|
ret = MP_EWOULDBLOCK;
|
||||||
|
} else if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
|
||||||
|
// If handshake is not finished, read attempt may end up in protocol
|
||||||
|
// wanting to write next handshake message. The same may happen with
|
||||||
|
// renegotation.
|
||||||
|
ret = MP_EWOULDBLOCK;
|
||||||
}
|
}
|
||||||
*errcode = ret;
|
*errcode = ret;
|
||||||
return MP_STREAM_ERROR;
|
return MP_STREAM_ERROR;
|
||||||
@ -253,6 +261,11 @@ STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in
|
|||||||
}
|
}
|
||||||
if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
|
if (ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
|
||||||
ret = MP_EWOULDBLOCK;
|
ret = MP_EWOULDBLOCK;
|
||||||
|
} else if (ret == MBEDTLS_ERR_SSL_WANT_READ) {
|
||||||
|
// If handshake is not finished, write attempt may end up in protocol
|
||||||
|
// wanting to read next handshake message. The same may happen with
|
||||||
|
// renegotation.
|
||||||
|
ret = MP_EWOULDBLOCK;
|
||||||
}
|
}
|
||||||
*errcode = ret;
|
*errcode = ret;
|
||||||
return MP_STREAM_ERROR;
|
return MP_STREAM_ERROR;
|
||||||
@ -321,7 +334,8 @@ STATIC mp_obj_t mod_ssl_wrap_socket(size_t n_args, const mp_obj_t *pos_args, mp_
|
|||||||
{ MP_QSTR_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
{ MP_QSTR_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||||
{ MP_QSTR_cert, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
{ MP_QSTR_cert, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
||||||
{ MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
{ MP_QSTR_server_side, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
||||||
{ MP_QSTR_server_hostname, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
{ MP_QSTR_server_hostname, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
|
||||||
|
{ MP_QSTR_do_handshake, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Check that sock implements stream protocol
|
// TODO: Check that sock implements stream protocol
|
||||||
|
|||||||
@ -145,7 +145,7 @@ STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
|
|||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "empty heap"));
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "empty heap"));
|
||||||
}
|
}
|
||||||
mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref);
|
mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref);
|
||||||
if (!MP_OBJ_IS_TYPE(list_ref, &mp_type_list) || ret->len < 3) {
|
if (!mp_obj_is_type(list_ref, &mp_type_list) || ret->len < 3) {
|
||||||
mp_raise_TypeError(NULL);
|
mp_raise_TypeError(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,9 +30,9 @@
|
|||||||
|
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "py/stream.h"
|
#include "py/stream.h"
|
||||||
#include "extmod/modwebsocket.h"
|
#include "extmod/moduwebsocket.h"
|
||||||
|
|
||||||
#if MICROPY_PY_WEBSOCKET
|
#if MICROPY_PY_UWEBSOCKET
|
||||||
|
|
||||||
enum { FRAME_HEADER, FRAME_OPT, PAYLOAD, CONTROL };
|
enum { FRAME_HEADER, FRAME_OPT, PAYLOAD, CONTROL };
|
||||||
|
|
||||||
@ -299,16 +299,16 @@ STATIC const mp_obj_type_t websocket_type = {
|
|||||||
.locals_dict = (void*)&websocket_locals_dict,
|
.locals_dict = (void*)&websocket_locals_dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC const mp_rom_map_elem_t websocket_module_globals_table[] = {
|
STATIC const mp_rom_map_elem_t uwebsocket_module_globals_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_websocket) },
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uwebsocket) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&websocket_type) },
|
{ MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&websocket_type) },
|
||||||
};
|
};
|
||||||
|
|
||||||
STATIC MP_DEFINE_CONST_DICT(websocket_module_globals, websocket_module_globals_table);
|
STATIC MP_DEFINE_CONST_DICT(uwebsocket_module_globals, uwebsocket_module_globals_table);
|
||||||
|
|
||||||
const mp_obj_module_t mp_module_websocket = {
|
const mp_obj_module_t mp_module_uwebsocket = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t*)&websocket_module_globals,
|
.globals = (mp_obj_dict_t*)&uwebsocket_module_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MICROPY_PY_WEBSOCKET
|
#endif // MICROPY_PY_UWEBSOCKET
|
||||||
10
extmod/moduwebsocket.h
Normal file
10
extmod/moduwebsocket.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H
|
||||||
|
#define MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H
|
||||||
|
|
||||||
|
#define FRAME_OPCODE_MASK 0x0f
|
||||||
|
enum {
|
||||||
|
FRAME_CONT, FRAME_TXT, FRAME_BIN,
|
||||||
|
FRAME_CLOSE = 0x8, FRAME_PING, FRAME_PONG
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H
|
||||||
@ -48,7 +48,7 @@ typedef struct _mp_obj_decompio_t {
|
|||||||
bool eof;
|
bool eof;
|
||||||
} mp_obj_decompio_t;
|
} mp_obj_decompio_t;
|
||||||
|
|
||||||
STATIC unsigned char read_src_stream(TINF_DATA *data) {
|
STATIC int read_src_stream(TINF_DATA *data) {
|
||||||
byte *p = (void*)data;
|
byte *p = (void*)data;
|
||||||
p -= offsetof(mp_obj_decompio_t, decomp);
|
p -= offsetof(mp_obj_decompio_t, decomp);
|
||||||
mp_obj_decompio_t *self = (mp_obj_decompio_t*)p;
|
mp_obj_decompio_t *self = (mp_obj_decompio_t*)p;
|
||||||
@ -110,7 +110,7 @@ STATIC mp_uint_t decompio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er
|
|||||||
}
|
}
|
||||||
|
|
||||||
o->decomp.dest = buf;
|
o->decomp.dest = buf;
|
||||||
o->decomp.destSize = size;
|
o->decomp.dest_limit = (byte*)buf + size;
|
||||||
int st = uzlib_uncompress_chksum(&o->decomp);
|
int st = uzlib_uncompress_chksum(&o->decomp);
|
||||||
if (st == TINF_DONE) {
|
if (st == TINF_DONE) {
|
||||||
o->eof = true;
|
o->eof = true;
|
||||||
@ -155,9 +155,10 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
|||||||
byte *dest_buf = m_new(byte, dest_buf_size);
|
byte *dest_buf = m_new(byte, dest_buf_size);
|
||||||
|
|
||||||
decomp->dest = dest_buf;
|
decomp->dest = dest_buf;
|
||||||
decomp->destSize = dest_buf_size;
|
decomp->dest_limit = dest_buf + dest_buf_size;
|
||||||
DEBUG_printf("uzlib: Initial out buffer: " UINT_FMT " bytes\n", decomp->destSize);
|
DEBUG_printf("uzlib: Initial out buffer: " UINT_FMT " bytes\n", dest_buf_size);
|
||||||
decomp->source = bufinfo.buf;
|
decomp->source = bufinfo.buf;
|
||||||
|
decomp->source_limit = (byte*)bufinfo.buf + bufinfo.len;
|
||||||
|
|
||||||
int st;
|
int st;
|
||||||
bool is_zlib = true;
|
bool is_zlib = true;
|
||||||
@ -185,7 +186,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
|||||||
dest_buf = m_renew(byte, dest_buf, dest_buf_size, dest_buf_size + 256);
|
dest_buf = m_renew(byte, dest_buf, dest_buf_size, dest_buf_size + 256);
|
||||||
dest_buf_size += 256;
|
dest_buf_size += 256;
|
||||||
decomp->dest = dest_buf + offset;
|
decomp->dest = dest_buf + offset;
|
||||||
decomp->destSize = 256;
|
decomp->dest_limit = decomp->dest + 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t final_sz = decomp->dest - dest_buf;
|
mp_uint_t final_sz = decomp->dest - dest_buf;
|
||||||
|
|||||||
@ -34,7 +34,7 @@
|
|||||||
#ifdef MICROPY_PY_WEBREPL_DELAY
|
#ifdef MICROPY_PY_WEBREPL_DELAY
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
#endif
|
#endif
|
||||||
#include "extmod/modwebsocket.h"
|
#include "extmod/moduwebsocket.h"
|
||||||
|
|
||||||
#if MICROPY_PY_WEBREPL
|
#if MICROPY_PY_WEBREPL
|
||||||
|
|
||||||
@ -108,6 +108,15 @@ STATIC mp_obj_t webrepl_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATIC void check_file_op_finished(mp_obj_webrepl_t *self) {
|
||||||
|
if (self->data_to_recv == 0) {
|
||||||
|
mp_stream_close(self->cur_file);
|
||||||
|
self->hdr_to_recv = sizeof(struct webrepl_file);
|
||||||
|
DEBUG_printf("webrepl: Finished file operation %d\n", self->hdr.type);
|
||||||
|
write_webrepl_resp(self->sock, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
STATIC int write_file_chunk(mp_obj_webrepl_t *self) {
|
STATIC int write_file_chunk(mp_obj_webrepl_t *self) {
|
||||||
const mp_stream_p_t *file_stream = mp_get_stream(self->cur_file);
|
const mp_stream_p_t *file_stream = mp_get_stream(self->cur_file);
|
||||||
byte readbuf[2 + 256];
|
byte readbuf[2 + 256];
|
||||||
@ -160,6 +169,7 @@ STATIC void handle_op(mp_obj_webrepl_t *self) {
|
|||||||
|
|
||||||
if (self->hdr.type == PUT_FILE) {
|
if (self->hdr.type == PUT_FILE) {
|
||||||
self->data_to_recv = self->hdr.size;
|
self->data_to_recv = self->hdr.size;
|
||||||
|
check_file_op_finished(self);
|
||||||
} else if (self->hdr.type == GET_FILE) {
|
} else if (self->hdr.type == GET_FILE) {
|
||||||
self->data_to_recv = 1;
|
self->data_to_recv = 1;
|
||||||
}
|
}
|
||||||
@ -266,12 +276,7 @@ STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->data_to_recv == 0) {
|
check_file_op_finished(self);
|
||||||
mp_stream_close(self->cur_file);
|
|
||||||
self->hdr_to_recv = sizeof(struct webrepl_file);
|
|
||||||
DEBUG_printf("webrepl: Finished file operation %d\n", self->hdr.type);
|
|
||||||
write_webrepl_resp(self->sock, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef MICROPY_PY_WEBREPL_DELAY
|
#ifdef MICROPY_PY_WEBREPL_DELAY
|
||||||
// Some platforms may have broken drivers and easily gets
|
// Some platforms may have broken drivers and easily gets
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
#ifndef MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H
|
|
||||||
#define MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H
|
|
||||||
|
|
||||||
#define FRAME_OPCODE_MASK 0x0f
|
|
||||||
enum {
|
|
||||||
FRAME_CONT, FRAME_TXT, FRAME_BIN,
|
|
||||||
FRAME_CLOSE = 0x8, FRAME_PING, FRAME_PONG
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H
|
|
||||||
460
extmod/network_cyw43.c
Normal file
460
extmod/network_cyw43.c
Normal file
@ -0,0 +1,460 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018-2019 Damien P. George
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "py/runtime.h"
|
||||||
|
#include "py/objstr.h"
|
||||||
|
#include "py/mphal.h"
|
||||||
|
|
||||||
|
#if MICROPY_PY_NETWORK_CYW43
|
||||||
|
|
||||||
|
#include "lwip/netif.h"
|
||||||
|
#include "drivers/cyw43/cyw43.h"
|
||||||
|
#include "extmod/network_cyw43.h"
|
||||||
|
#include "modnetwork.h"
|
||||||
|
|
||||||
|
typedef struct _network_cyw43_obj_t {
|
||||||
|
mp_obj_base_t base;
|
||||||
|
cyw43_t *cyw;
|
||||||
|
int itf;
|
||||||
|
} network_cyw43_obj_t;
|
||||||
|
|
||||||
|
STATIC const network_cyw43_obj_t network_cyw43_wl0 = { { &mp_network_cyw43_type }, &cyw43_state, 0 };
|
||||||
|
STATIC const network_cyw43_obj_t network_cyw43_wl1 = { { &mp_network_cyw43_type }, &cyw43_state, 1 };
|
||||||
|
|
||||||
|
STATIC void network_cyw43_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
struct netif *netif = &self->cyw->netif[self->itf];
|
||||||
|
int status = cyw43_tcpip_link_status(self->cyw, self->itf);
|
||||||
|
const char *status_str;
|
||||||
|
if (status == CYW43_LINK_DOWN) {
|
||||||
|
status_str = "down";
|
||||||
|
} else if (status == CYW43_LINK_JOIN || status == CYW43_LINK_NOIP) {
|
||||||
|
status_str = "join";
|
||||||
|
} else if (status == CYW43_LINK_UP) {
|
||||||
|
status_str = "up";
|
||||||
|
} else if (status == CYW43_LINK_NONET) {
|
||||||
|
status_str = "nonet";
|
||||||
|
} else if (status == CYW43_LINK_BADAUTH) {
|
||||||
|
status_str = "badauth";
|
||||||
|
} else {
|
||||||
|
status_str = "fail";
|
||||||
|
}
|
||||||
|
mp_printf(print, "<CYW43 %s %s %u.%u.%u.%u>",
|
||||||
|
self->itf == 0 ? "STA" : "AP",
|
||||||
|
status_str,
|
||||||
|
netif->ip_addr.addr & 0xff,
|
||||||
|
netif->ip_addr.addr >> 8 & 0xff,
|
||||||
|
netif->ip_addr.addr >> 16 & 0xff,
|
||||||
|
netif->ip_addr.addr >> 24
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||||
|
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||||
|
if (n_args == 0 || mp_obj_get_int(args[0]) == 0) {
|
||||||
|
return MP_OBJ_FROM_PTR(&network_cyw43_wl0);
|
||||||
|
} else {
|
||||||
|
return MP_OBJ_FROM_PTR(&network_cyw43_wl1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_send_ethernet(mp_obj_t self_in, mp_obj_t buf_in) {
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
mp_buffer_info_t buf;
|
||||||
|
mp_get_buffer_raise(buf_in, &buf, MP_BUFFER_READ);
|
||||||
|
int ret = cyw43_send_ethernet(self->cyw, self->itf, buf.len, buf.buf, false);
|
||||||
|
if (ret) {
|
||||||
|
mp_raise_OSError(-ret);
|
||||||
|
}
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(network_cyw43_send_ethernet_obj, network_cyw43_send_ethernet);
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t buf_in) {
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
mp_buffer_info_t buf;
|
||||||
|
mp_get_buffer_raise(buf_in, &buf, MP_BUFFER_READ | MP_BUFFER_WRITE);
|
||||||
|
cyw43_ioctl(self->cyw, mp_obj_get_int(cmd_in), buf.len, buf.buf, self->itf);
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_3(network_cyw43_ioctl_obj, network_cyw43_ioctl);
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
// network API
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_deinit(mp_obj_t self_in) {
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
cyw43_deinit(self->cyw);
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_deinit_obj, network_cyw43_deinit);
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_active(size_t n_args, const mp_obj_t *args) {
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||||
|
if (n_args == 1) {
|
||||||
|
return mp_obj_new_bool(cyw43_tcpip_link_status(self->cyw, self->itf));
|
||||||
|
} else {
|
||||||
|
cyw43_wifi_set_up(self->cyw, self->itf, mp_obj_is_true(args[1]));
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_cyw43_active_obj, 1, 2, network_cyw43_active);
|
||||||
|
|
||||||
|
STATIC int network_cyw43_scan_cb(void *env, const cyw43_ev_scan_result_t *res) {
|
||||||
|
mp_obj_t list = MP_OBJ_FROM_PTR(env);
|
||||||
|
|
||||||
|
// Search for existing BSSID to remove duplicates
|
||||||
|
bool found = false;
|
||||||
|
size_t len;
|
||||||
|
mp_obj_t *items;
|
||||||
|
mp_obj_get_array(list, &len, &items);
|
||||||
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(items[i]);
|
||||||
|
if (memcmp(res->bssid, ((mp_obj_str_t*)MP_OBJ_TO_PTR(t->items[1]))->data, sizeof(res->bssid)) == 0) {
|
||||||
|
if (res->rssi > MP_OBJ_SMALL_INT_VALUE(t->items[3])) {
|
||||||
|
t->items[3] = MP_OBJ_NEW_SMALL_INT(res->rssi);
|
||||||
|
}
|
||||||
|
t->items[5] = MP_OBJ_NEW_SMALL_INT(MP_OBJ_SMALL_INT_VALUE(t->items[5]) + 1);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to list of results if wanted
|
||||||
|
if (!found) {
|
||||||
|
mp_obj_t tuple[6] = {
|
||||||
|
mp_obj_new_bytes(res->ssid, res->ssid_len),
|
||||||
|
mp_obj_new_bytes(res->bssid, sizeof(res->bssid)),
|
||||||
|
MP_OBJ_NEW_SMALL_INT(res->channel),
|
||||||
|
MP_OBJ_NEW_SMALL_INT(res->rssi),
|
||||||
|
MP_OBJ_NEW_SMALL_INT(res->auth_mode),
|
||||||
|
//mp_const_false, // hidden
|
||||||
|
MP_OBJ_NEW_SMALL_INT(1), // N
|
||||||
|
};
|
||||||
|
mp_obj_list_append(list, mp_obj_new_tuple(6, tuple));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0; // continue scan
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
|
enum { ARG_passive, ARG_essid, ARG_bssid };
|
||||||
|
static const mp_arg_t allowed_args[] = {
|
||||||
|
{ MP_QSTR_passive, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
||||||
|
{ MP_QSTR_essid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
|
||||||
|
{ MP_QSTR_bssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
|
||||||
|
};
|
||||||
|
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||||
|
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||||
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||||
|
|
||||||
|
cyw43_wifi_scan_options_t opts;
|
||||||
|
opts.scan_type = args[ARG_passive].u_bool ? 1 : 0;
|
||||||
|
if (args[ARG_essid].u_obj == mp_const_none) {
|
||||||
|
opts.ssid_len = 0;
|
||||||
|
} else {
|
||||||
|
mp_buffer_info_t ssid;
|
||||||
|
mp_get_buffer_raise(args[ARG_essid].u_obj, &ssid, MP_BUFFER_READ);
|
||||||
|
opts.ssid_len = MIN(ssid.len, sizeof(opts.ssid));
|
||||||
|
memcpy(opts.ssid, ssid.buf, opts.ssid_len);
|
||||||
|
}
|
||||||
|
if (args[ARG_bssid].u_obj == mp_const_none) {
|
||||||
|
memset(opts.bssid, 0xff, sizeof(opts.bssid));
|
||||||
|
} else {
|
||||||
|
mp_buffer_info_t bssid;
|
||||||
|
mp_get_buffer_raise(args[ARG_bssid].u_obj, &bssid, MP_BUFFER_READ);
|
||||||
|
memcpy(opts.bssid, bssid.buf, sizeof(opts.bssid));
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_obj_t res = mp_obj_new_list(0, NULL);
|
||||||
|
int scan_res = cyw43_wifi_scan(self->cyw, &opts, MP_OBJ_TO_PTR(res), network_cyw43_scan_cb);
|
||||||
|
|
||||||
|
if (scan_res < 0) {
|
||||||
|
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "STA must be active"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for scan to finish, with a 10s timeout
|
||||||
|
uint32_t start = mp_hal_ticks_ms();
|
||||||
|
while (cyw43_wifi_scan_active(self->cyw) && mp_hal_ticks_ms() - start < 10000) {
|
||||||
|
MICROPY_EVENT_POLL_HOOK
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_scan_obj, 1, network_cyw43_scan);
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
|
enum { ARG_essid, ARG_key, ARG_auth, ARG_bssid, ARG_channel };
|
||||||
|
static const mp_arg_t allowed_args[] = {
|
||||||
|
{ MP_QSTR_essid, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
|
||||||
|
{ MP_QSTR_key, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
|
||||||
|
{ MP_QSTR_auth, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
||||||
|
{ MP_QSTR_bssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
|
||||||
|
{ MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} },
|
||||||
|
};
|
||||||
|
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
|
||||||
|
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||||
|
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||||
|
|
||||||
|
mp_buffer_info_t ssid;
|
||||||
|
mp_get_buffer_raise(args[ARG_essid].u_obj, &ssid, MP_BUFFER_READ);
|
||||||
|
mp_buffer_info_t key;
|
||||||
|
key.buf = NULL;
|
||||||
|
if (args[ARG_key].u_obj != mp_const_none) {
|
||||||
|
mp_get_buffer_raise(args[ARG_key].u_obj, &key, MP_BUFFER_READ);
|
||||||
|
}
|
||||||
|
mp_buffer_info_t bssid;
|
||||||
|
bssid.buf = NULL;
|
||||||
|
if (args[ARG_bssid].u_obj != mp_const_none) {
|
||||||
|
mp_get_buffer_raise(args[ARG_bssid].u_obj, &bssid, MP_BUFFER_READ);
|
||||||
|
if (bssid.len != 6) {
|
||||||
|
mp_raise_ValueError(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int ret = cyw43_wifi_join(self->cyw, ssid.len, ssid.buf, key.len, key.buf, args[ARG_auth].u_int, bssid.buf, args[ARG_channel].u_int);
|
||||||
|
if (ret != 0) {
|
||||||
|
mp_raise_OSError(ret);
|
||||||
|
}
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_connect_obj, 1, network_cyw43_connect);
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_disconnect(mp_obj_t self_in) {
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
cyw43_wifi_leave(self->cyw, self->itf);
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_disconnect_obj, network_cyw43_disconnect);
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_isconnected(mp_obj_t self_in) {
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
|
return mp_obj_new_bool(cyw43_tcpip_link_status(self->cyw, self->itf) == 3);
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_isconnected_obj, network_cyw43_isconnected);
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_ifconfig(size_t n_args, const mp_obj_t *args) {
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||||
|
return mod_network_nic_ifconfig(&self->cyw->netif[self->itf], n_args - 1, args + 1);
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_cyw43_ifconfig_obj, 1, 2, network_cyw43_ifconfig);
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_status(size_t n_args, const mp_obj_t *args) {
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||||
|
(void)self;
|
||||||
|
|
||||||
|
if (n_args == 1) {
|
||||||
|
// no arguments: return link status
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(cyw43_tcpip_link_status(self->cyw, self->itf));
|
||||||
|
}
|
||||||
|
|
||||||
|
// one argument: return status based on query parameter
|
||||||
|
switch (mp_obj_str_get_qstr(args[1])) {
|
||||||
|
case MP_QSTR_stations: {
|
||||||
|
// return list of connected stations
|
||||||
|
if (self->itf != CYW43_ITF_AP) {
|
||||||
|
mp_raise_ValueError("AP required");
|
||||||
|
}
|
||||||
|
int num_stas;
|
||||||
|
uint8_t macs[32 * 6];
|
||||||
|
cyw43_wifi_ap_get_stas(self->cyw, &num_stas, macs);
|
||||||
|
mp_obj_t list = mp_obj_new_list(num_stas, NULL);
|
||||||
|
for (int i = 0; i < num_stas; ++i) {
|
||||||
|
mp_obj_t tuple[1] = {
|
||||||
|
mp_obj_new_bytes(&macs[i * 6], 6),
|
||||||
|
};
|
||||||
|
((mp_obj_list_t*)MP_OBJ_TO_PTR(list))->items[i] = mp_obj_new_tuple(1, tuple);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_raise_ValueError("unknown status param");
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_cyw43_status_obj, 1, 2, network_cyw43_status);
|
||||||
|
|
||||||
|
static inline uint32_t nw_get_le32(const uint8_t *buf) {
|
||||||
|
return buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void nw_put_le32(uint8_t *buf, uint32_t x) {
|
||||||
|
buf[0] = x;
|
||||||
|
buf[1] = x >> 8;
|
||||||
|
buf[2] = x >> 16;
|
||||||
|
buf[3] = x >> 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATIC mp_obj_t network_cyw43_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||||
|
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||||
|
|
||||||
|
if (kwargs->used == 0) {
|
||||||
|
// Get config value
|
||||||
|
if (n_args != 2) {
|
||||||
|
mp_raise_TypeError("must query one param");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (mp_obj_str_get_qstr(args[1])) {
|
||||||
|
case MP_QSTR_antenna: {
|
||||||
|
uint8_t buf[4];
|
||||||
|
cyw43_ioctl(self->cyw, CYW43_IOCTL_GET_ANTDIV, 4, buf, self->itf);
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(nw_get_le32(buf));
|
||||||
|
}
|
||||||
|
case MP_QSTR_channel: {
|
||||||
|
uint8_t buf[4];
|
||||||
|
cyw43_ioctl(self->cyw, CYW43_IOCTL_GET_CHANNEL, 4, buf, self->itf);
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(nw_get_le32(buf));
|
||||||
|
}
|
||||||
|
case MP_QSTR_essid: {
|
||||||
|
if (self->itf == CYW43_ITF_STA) {
|
||||||
|
uint8_t buf[36];
|
||||||
|
cyw43_ioctl(self->cyw, CYW43_IOCTL_GET_SSID, 36, buf, self->itf);
|
||||||
|
return mp_obj_new_str((const char*)buf + 4, nw_get_le32(buf));
|
||||||
|
} else {
|
||||||
|
size_t len;
|
||||||
|
const uint8_t *buf;
|
||||||
|
cyw43_wifi_ap_get_ssid(self->cyw, &len, &buf);
|
||||||
|
return mp_obj_new_str((const char*)buf, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case MP_QSTR_mac: {
|
||||||
|
uint8_t buf[6];
|
||||||
|
cyw43_wifi_get_mac(self->cyw, self->itf, buf);
|
||||||
|
return mp_obj_new_bytes(buf, 6);
|
||||||
|
}
|
||||||
|
case MP_QSTR_txpower: {
|
||||||
|
uint8_t buf[13];
|
||||||
|
memcpy(buf, "qtxpower\x00\x00\x00\x00\x00", 13);
|
||||||
|
cyw43_ioctl(self->cyw, CYW43_IOCTL_GET_VAR, 13, buf, self->itf);
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(nw_get_le32(buf) / 4);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
mp_raise_ValueError("unknown config param");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Set config value(s)
|
||||||
|
if (n_args != 1) {
|
||||||
|
mp_raise_TypeError("can't specify pos and kw args");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < kwargs->alloc; ++i) {
|
||||||
|
if (MP_MAP_SLOT_IS_FILLED(kwargs, i)) {
|
||||||
|
mp_map_elem_t *e = &kwargs->table[i];
|
||||||
|
switch (mp_obj_str_get_qstr(e->key)) {
|
||||||
|
case MP_QSTR_antenna: {
|
||||||
|
uint8_t buf[4];
|
||||||
|
nw_put_le32(buf, mp_obj_get_int(e->value));
|
||||||
|
cyw43_ioctl(self->cyw, CYW43_IOCTL_SET_ANTDIV, 4, buf, self->itf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MP_QSTR_channel: {
|
||||||
|
cyw43_wifi_ap_set_channel(self->cyw, mp_obj_get_int(e->value));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MP_QSTR_essid: {
|
||||||
|
size_t len;
|
||||||
|
const char *str = mp_obj_str_get_data(e->value, &len);
|
||||||
|
cyw43_wifi_ap_set_ssid(self->cyw, len, (const uint8_t*)str);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MP_QSTR_monitor: {
|
||||||
|
mp_int_t value = mp_obj_get_int(e->value);
|
||||||
|
uint8_t buf[9 + 4];
|
||||||
|
memcpy(buf, "allmulti\x00", 9);
|
||||||
|
nw_put_le32(buf + 9, value);
|
||||||
|
cyw43_ioctl(self->cyw, CYW43_IOCTL_SET_VAR, 9 + 4, buf, self->itf);
|
||||||
|
nw_put_le32(buf, value);
|
||||||
|
cyw43_ioctl(self->cyw, CYW43_IOCTL_SET_MONITOR, 4, buf, self->itf);
|
||||||
|
if (value) {
|
||||||
|
self->cyw->trace_flags |= CYW43_TRACE_MAC;
|
||||||
|
} else {
|
||||||
|
self->cyw->trace_flags &= ~CYW43_TRACE_MAC;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MP_QSTR_password: {
|
||||||
|
size_t len;
|
||||||
|
const char *str = mp_obj_str_get_data(e->value, &len);
|
||||||
|
cyw43_wifi_ap_set_password(self->cyw, len, (const uint8_t*)str);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MP_QSTR_pm: {
|
||||||
|
cyw43_wifi_pm(self->cyw, mp_obj_get_int(e->value));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MP_QSTR_trace: {
|
||||||
|
self->cyw->trace_flags = mp_obj_get_int(e->value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MP_QSTR_txpower: {
|
||||||
|
mp_int_t dbm = mp_obj_get_int(e->value);
|
||||||
|
uint8_t buf[9 + 4];
|
||||||
|
memcpy(buf, "qtxpower\x00", 9);
|
||||||
|
nw_put_le32(buf + 9, dbm * 4);
|
||||||
|
cyw43_ioctl(self->cyw, CYW43_IOCTL_SET_VAR, 9 + 4, buf, self->itf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
mp_raise_ValueError("unknown config param");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(network_cyw43_config_obj, 1, network_cyw43_config);
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
// class bindings
|
||||||
|
|
||||||
|
STATIC const mp_rom_map_elem_t network_cyw43_locals_dict_table[] = {
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_send_ethernet), MP_ROM_PTR(&network_cyw43_send_ethernet_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&network_cyw43_ioctl_obj) },
|
||||||
|
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&network_cyw43_deinit_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&network_cyw43_active_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&network_cyw43_scan_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&network_cyw43_connect_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&network_cyw43_disconnect_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_isconnected), MP_ROM_PTR(&network_cyw43_isconnected_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_ifconfig), MP_ROM_PTR(&network_cyw43_ifconfig_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_status), MP_ROM_PTR(&network_cyw43_status_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_config), MP_ROM_PTR(&network_cyw43_config_obj) },
|
||||||
|
};
|
||||||
|
STATIC MP_DEFINE_CONST_DICT(network_cyw43_locals_dict, network_cyw43_locals_dict_table);
|
||||||
|
|
||||||
|
const mp_obj_type_t mp_network_cyw43_type = {
|
||||||
|
{ &mp_type_type },
|
||||||
|
.name = MP_QSTR_CYW43,
|
||||||
|
.print = network_cyw43_print,
|
||||||
|
.make_new = network_cyw43_make_new,
|
||||||
|
.locals_dict = (mp_obj_dict_t*)&network_cyw43_locals_dict,
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MICROPY_PY_NETWORK_CYW43
|
||||||
31
extmod/network_cyw43.h
Normal file
31
extmod/network_cyw43.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2019 Damien P. George
|
||||||
|
*
|
||||||
|
* 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 MICROPY_INCLUDED_EXTMOD_NETWORK_CYW43_H
|
||||||
|
#define MICROPY_INCLUDED_EXTMOD_NETWORK_CYW43_H
|
||||||
|
|
||||||
|
extern const mp_obj_type_t mp_network_cyw43_type;
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_EXTMOD_NETWORK_CYW43_H
|
||||||
@ -32,6 +32,7 @@
|
|||||||
#include "py/objtuple.h"
|
#include "py/objtuple.h"
|
||||||
#include "py/objarray.h"
|
#include "py/objarray.h"
|
||||||
#include "py/stream.h"
|
#include "py/stream.h"
|
||||||
|
#include "extmod/misc.h"
|
||||||
#include "lib/utils/interrupt_char.h"
|
#include "lib/utils/interrupt_char.h"
|
||||||
|
|
||||||
#if MICROPY_PY_OS_DUPTERM
|
#if MICROPY_PY_OS_DUPTERM
|
||||||
@ -58,6 +59,20 @@ int mp_uos_dupterm_rx_chr(void) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM
|
||||||
|
if (mp_uos_dupterm_is_builtin_stream(MP_STATE_VM(dupterm_objs[idx]))) {
|
||||||
|
byte buf[1];
|
||||||
|
int errcode = 0;
|
||||||
|
const mp_stream_p_t *stream_p = mp_get_stream(MP_STATE_VM(dupterm_objs[idx]));
|
||||||
|
mp_uint_t out_sz = stream_p->read(MP_STATE_VM(dupterm_objs[idx]), buf, 1, &errcode);
|
||||||
|
if (errcode == 0 && out_sz != 0) {
|
||||||
|
return buf[0];
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
nlr_buf_t nlr;
|
nlr_buf_t nlr;
|
||||||
if (nlr_push(&nlr) == 0) {
|
if (nlr_push(&nlr) == 0) {
|
||||||
byte buf[1];
|
byte buf[1];
|
||||||
@ -98,6 +113,16 @@ void mp_uos_dupterm_tx_strn(const char *str, size_t len) {
|
|||||||
if (MP_STATE_VM(dupterm_objs[idx]) == MP_OBJ_NULL) {
|
if (MP_STATE_VM(dupterm_objs[idx]) == MP_OBJ_NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MICROPY_PY_UOS_DUPTERM_BUILTIN_STREAM
|
||||||
|
if (mp_uos_dupterm_is_builtin_stream(MP_STATE_VM(dupterm_objs[idx]))) {
|
||||||
|
int errcode = 0;
|
||||||
|
const mp_stream_p_t *stream_p = mp_get_stream(MP_STATE_VM(dupterm_objs[idx]));
|
||||||
|
stream_p->write(MP_STATE_VM(dupterm_objs[idx]), str, len, &errcode);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
nlr_buf_t nlr;
|
nlr_buf_t nlr;
|
||||||
if (nlr_push(&nlr) == 0) {
|
if (nlr_push(&nlr) == 0) {
|
||||||
mp_stream_write(MP_STATE_VM(dupterm_objs[idx]), str, len, MP_STREAM_RW_WRITE);
|
mp_stream_write(MP_STATE_VM(dupterm_objs[idx]), str, len, MP_STREAM_RW_WRITE);
|
||||||
|
|||||||
45
extmod/uzlib/defl_static.h
Normal file
45
extmod/uzlib/defl_static.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) uzlib authors
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express
|
||||||
|
* or implied warranty. In no event will the authors be
|
||||||
|
* held liable for any damages arising from the use of
|
||||||
|
* this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software
|
||||||
|
* for any purpose, including commercial applications,
|
||||||
|
* and to alter it and redistribute it freely, subject to
|
||||||
|
* the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be
|
||||||
|
* misrepresented; you must not claim that you
|
||||||
|
* wrote the original software. If you use this
|
||||||
|
* software in a product, an acknowledgment in
|
||||||
|
* the product documentation would be appreciated
|
||||||
|
* but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked
|
||||||
|
* as such, and must not be misrepresented as
|
||||||
|
* being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from
|
||||||
|
* any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This files contains type declaration and prototypes for defl_static.c.
|
||||||
|
They may be altered/distinct from the originals used in PuTTY source
|
||||||
|
code. */
|
||||||
|
|
||||||
|
struct Outbuf {
|
||||||
|
unsigned char *outbuf;
|
||||||
|
int outlen, outsize;
|
||||||
|
unsigned long outbits;
|
||||||
|
int noutbits;
|
||||||
|
int comp_disabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
void outbits(struct Outbuf *out, unsigned long bits, int nbits);
|
||||||
|
void zlib_start_block(struct Outbuf *ctx);
|
||||||
|
void zlib_finish_block(struct Outbuf *ctx);
|
||||||
|
void zlib_literal(struct Outbuf *ectx, unsigned char c);
|
||||||
|
void zlib_match(struct Outbuf *ectx, int distance, int len);
|
||||||
@ -1,117 +1,3 @@
|
|||||||
/*
|
/* Compatibility header for the original tinf lib/older versions of uzlib.
|
||||||
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
Note: may be removed in the future, please migrate to uzlib.h. */
|
||||||
*
|
#include "uzlib.h"
|
||||||
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
|
||||||
* All Rights Reserved
|
|
||||||
* http://www.ibsensoftware.com/
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014-2016 by Paul Sokolovsky
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TINF_H_INCLUDED
|
|
||||||
#define TINF_H_INCLUDED
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/* calling convention */
|
|
||||||
#ifndef TINFCC
|
|
||||||
#ifdef __WATCOMC__
|
|
||||||
#define TINFCC __cdecl
|
|
||||||
#else
|
|
||||||
#define TINFCC
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ok status, more data produced */
|
|
||||||
#define TINF_OK 0
|
|
||||||
/* end of compressed stream reached */
|
|
||||||
#define TINF_DONE 1
|
|
||||||
#define TINF_DATA_ERROR (-3)
|
|
||||||
#define TINF_CHKSUM_ERROR (-4)
|
|
||||||
#define TINF_DICT_ERROR (-5)
|
|
||||||
|
|
||||||
/* checksum types */
|
|
||||||
#define TINF_CHKSUM_NONE 0
|
|
||||||
#define TINF_CHKSUM_ADLER 1
|
|
||||||
#define TINF_CHKSUM_CRC 2
|
|
||||||
|
|
||||||
/* data structures */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
unsigned short table[16]; /* table of code length counts */
|
|
||||||
unsigned short trans[288]; /* code -> symbol translation table */
|
|
||||||
} TINF_TREE;
|
|
||||||
|
|
||||||
struct TINF_DATA;
|
|
||||||
typedef struct TINF_DATA {
|
|
||||||
const unsigned char *source;
|
|
||||||
/* If source above is NULL, this function will be used to read
|
|
||||||
next byte from source stream */
|
|
||||||
unsigned char (*readSource)(struct TINF_DATA *data);
|
|
||||||
|
|
||||||
unsigned int tag;
|
|
||||||
unsigned int bitcount;
|
|
||||||
|
|
||||||
/* Buffer start */
|
|
||||||
unsigned char *destStart;
|
|
||||||
/* Buffer total size */
|
|
||||||
unsigned int destSize;
|
|
||||||
/* Current pointer in buffer */
|
|
||||||
unsigned char *dest;
|
|
||||||
/* Remaining bytes in buffer */
|
|
||||||
unsigned int destRemaining;
|
|
||||||
|
|
||||||
/* Accumulating checksum */
|
|
||||||
unsigned int checksum;
|
|
||||||
char checksum_type;
|
|
||||||
|
|
||||||
int btype;
|
|
||||||
int bfinal;
|
|
||||||
unsigned int curlen;
|
|
||||||
int lzOff;
|
|
||||||
unsigned char *dict_ring;
|
|
||||||
unsigned int dict_size;
|
|
||||||
unsigned int dict_idx;
|
|
||||||
|
|
||||||
TINF_TREE ltree; /* dynamic length/symbol tree */
|
|
||||||
TINF_TREE dtree; /* dynamic distance tree */
|
|
||||||
} TINF_DATA;
|
|
||||||
|
|
||||||
#define TINF_PUT(d, c) \
|
|
||||||
{ \
|
|
||||||
*d->dest++ = c; \
|
|
||||||
if (d->dict_ring) { d->dict_ring[d->dict_idx++] = c; if (d->dict_idx == d->dict_size) d->dict_idx = 0; } \
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char TINFCC uzlib_get_byte(TINF_DATA *d);
|
|
||||||
|
|
||||||
/* Decompression API */
|
|
||||||
|
|
||||||
void TINFCC uzlib_init(void);
|
|
||||||
void TINFCC uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen);
|
|
||||||
int TINFCC uzlib_uncompress(TINF_DATA *d);
|
|
||||||
int TINFCC uzlib_uncompress_chksum(TINF_DATA *d);
|
|
||||||
|
|
||||||
int TINFCC uzlib_zlib_parse_header(TINF_DATA *d);
|
|
||||||
int TINFCC uzlib_gzip_parse_header(TINF_DATA *d);
|
|
||||||
|
|
||||||
/* Compression API */
|
|
||||||
|
|
||||||
void TINFCC uzlib_compress(void *data, const uint8_t *src, unsigned slen);
|
|
||||||
|
|
||||||
/* Checksum API */
|
|
||||||
|
|
||||||
/* prev_sum is previous value for incremental computation, 1 initially */
|
|
||||||
uint32_t TINFCC uzlib_adler32(const void *data, unsigned int length, uint32_t prev_sum);
|
|
||||||
/* crc is previous value for incremental computation, 0xffffffff initially */
|
|
||||||
uint32_t TINFCC uzlib_crc32(const void *data, unsigned int length, uint32_t crc);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
} /* extern "C" */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* TINF_H_INCLUDED */
|
|
||||||
|
|||||||
9
extmod/uzlib/tinf_compat.h
Normal file
9
extmod/uzlib/tinf_compat.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/* This header contains compatibility defines for the original tinf API
|
||||||
|
and uzlib 2.x and below API. These defines are deprecated and going
|
||||||
|
to be removed in the future, so applications should migrate to new
|
||||||
|
uzlib API. */
|
||||||
|
#define TINF_DATA struct uzlib_uncomp
|
||||||
|
|
||||||
|
#define destSize dest_size
|
||||||
|
#define destStart dest_start
|
||||||
|
#define readSource source_read_cb
|
||||||
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* tinfgzip - tiny gzip decompressor
|
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
*
|
*
|
||||||
* http://www.ibsensoftware.com/
|
* http://www.ibsensoftware.com/
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014-2016 by Paul Sokolovsky
|
* Copyright (c) 2014-2018 by Paul Sokolovsky
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express
|
* This software is provided 'as-is', without any express
|
||||||
* or implied warranty. In no event will the authors be
|
* or implied warranty. In no event will the authors be
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* tinflate - tiny inflate
|
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
* http://www.ibsensoftware.com/
|
* http://www.ibsensoftware.com/
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014-2016 by Paul Sokolovsky
|
* Copyright (c) 2014-2018 by Paul Sokolovsky
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express
|
* This software is provided 'as-is', without any express
|
||||||
* or implied warranty. In no event will the authors be
|
* or implied warranty. In no event will the authors be
|
||||||
@ -35,6 +35,15 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "tinf.h"
|
#include "tinf.h"
|
||||||
|
|
||||||
|
#define UZLIB_DUMP_ARRAY(heading, arr, size) \
|
||||||
|
{ \
|
||||||
|
printf("%s", heading); \
|
||||||
|
for (int i = 0; i < size; ++i) { \
|
||||||
|
printf(" %d", (arr)[i]); \
|
||||||
|
} \
|
||||||
|
printf("\n"); \
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t tinf_get_le_uint32(TINF_DATA *d);
|
uint32_t tinf_get_le_uint32(TINF_DATA *d);
|
||||||
uint32_t tinf_get_be_uint32(TINF_DATA *d);
|
uint32_t tinf_get_be_uint32(TINF_DATA *d);
|
||||||
|
|
||||||
@ -149,6 +158,13 @@ static void tinf_build_tree(TINF_TREE *t, const unsigned char *lengths, unsigned
|
|||||||
/* scan symbol lengths, and sum code length counts */
|
/* scan symbol lengths, and sum code length counts */
|
||||||
for (i = 0; i < num; ++i) t->table[lengths[i]]++;
|
for (i = 0; i < num; ++i) t->table[lengths[i]]++;
|
||||||
|
|
||||||
|
#if UZLIB_CONF_DEBUG_LOG >= 2
|
||||||
|
UZLIB_DUMP_ARRAY("codelen counts:", t->table, TINF_ARRAY_SIZE(t->table));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* In the lengths array, 0 means unused code. So, t->table[0] now contains
|
||||||
|
number of unused codes. But table's purpose is to contain # of codes of
|
||||||
|
particular length, and there're 0 codes of length 0. */
|
||||||
t->table[0] = 0;
|
t->table[0] = 0;
|
||||||
|
|
||||||
/* compute offset table for distribution sort */
|
/* compute offset table for distribution sort */
|
||||||
@ -158,6 +174,10 @@ static void tinf_build_tree(TINF_TREE *t, const unsigned char *lengths, unsigned
|
|||||||
sum += t->table[i];
|
sum += t->table[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if UZLIB_CONF_DEBUG_LOG >= 2
|
||||||
|
UZLIB_DUMP_ARRAY("codelen offsets:", offs, TINF_ARRAY_SIZE(offs));
|
||||||
|
#endif
|
||||||
|
|
||||||
/* create code->symbol translation table (symbols sorted by code) */
|
/* create code->symbol translation table (symbols sorted by code) */
|
||||||
for (i = 0; i < num; ++i)
|
for (i = 0; i < num; ++i)
|
||||||
{
|
{
|
||||||
@ -171,10 +191,28 @@ static void tinf_build_tree(TINF_TREE *t, const unsigned char *lengths, unsigned
|
|||||||
|
|
||||||
unsigned char uzlib_get_byte(TINF_DATA *d)
|
unsigned char uzlib_get_byte(TINF_DATA *d)
|
||||||
{
|
{
|
||||||
if (d->source) {
|
/* If end of source buffer is not reached, return next byte from source
|
||||||
|
buffer. */
|
||||||
|
if (d->source < d->source_limit) {
|
||||||
return *d->source++;
|
return *d->source++;
|
||||||
}
|
}
|
||||||
return d->readSource(d);
|
|
||||||
|
/* Otherwise if there's callback and we haven't seen EOF yet, try to
|
||||||
|
read next byte using it. (Note: the callback can also update ->source
|
||||||
|
and ->source_limit). */
|
||||||
|
if (d->readSource && !d->eof) {
|
||||||
|
int val = d->readSource(d);
|
||||||
|
if (val >= 0) {
|
||||||
|
return (unsigned char)val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, we hit EOF (either from ->readSource() or from exhaustion
|
||||||
|
of the buffer), and it will be "sticky", i.e. further calls to this
|
||||||
|
function will end up here too. */
|
||||||
|
d->eof = true;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t tinf_get_le_uint32(TINF_DATA *d)
|
uint32_t tinf_get_le_uint32(TINF_DATA *d)
|
||||||
@ -182,7 +220,7 @@ uint32_t tinf_get_le_uint32(TINF_DATA *d)
|
|||||||
uint32_t val = 0;
|
uint32_t val = 0;
|
||||||
int i;
|
int i;
|
||||||
for (i = 4; i--;) {
|
for (i = 4; i--;) {
|
||||||
val = val >> 8 | uzlib_get_byte(d) << 24;
|
val = val >> 8 | ((uint32_t)uzlib_get_byte(d)) << 24;
|
||||||
}
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@ -245,21 +283,31 @@ static int tinf_decode_symbol(TINF_DATA *d, TINF_TREE *t)
|
|||||||
|
|
||||||
cur = 2*cur + tinf_getbit(d);
|
cur = 2*cur + tinf_getbit(d);
|
||||||
|
|
||||||
++len;
|
if (++len == TINF_ARRAY_SIZE(t->table)) {
|
||||||
|
return TINF_DATA_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
sum += t->table[len];
|
sum += t->table[len];
|
||||||
cur -= t->table[len];
|
cur -= t->table[len];
|
||||||
|
|
||||||
} while (cur >= 0);
|
} while (cur >= 0);
|
||||||
|
|
||||||
return t->trans[sum + cur];
|
sum += cur;
|
||||||
|
#if UZLIB_CONF_PARANOID_CHECKS
|
||||||
|
if (sum < 0 || sum >= TINF_ARRAY_SIZE(t->trans)) {
|
||||||
|
return TINF_DATA_ERROR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return t->trans[sum];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* given a data stream, decode dynamic trees from it */
|
/* given a data stream, decode dynamic trees from it */
|
||||||
static void tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt)
|
static int tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt)
|
||||||
{
|
{
|
||||||
|
/* code lengths for 288 literal/len symbols and 32 dist symbols */
|
||||||
unsigned char lengths[288+32];
|
unsigned char lengths[288+32];
|
||||||
unsigned int hlit, hdist, hclen;
|
unsigned int hlit, hdist, hclen, hlimit;
|
||||||
unsigned int i, num, length;
|
unsigned int i, num, length;
|
||||||
|
|
||||||
/* get 5 bits HLIT (257-286) */
|
/* get 5 bits HLIT (257-286) */
|
||||||
@ -286,53 +334,75 @@ static void tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt)
|
|||||||
tinf_build_tree(lt, lengths, 19);
|
tinf_build_tree(lt, lengths, 19);
|
||||||
|
|
||||||
/* decode code lengths for the dynamic trees */
|
/* decode code lengths for the dynamic trees */
|
||||||
for (num = 0; num < hlit + hdist; )
|
hlimit = hlit + hdist;
|
||||||
|
for (num = 0; num < hlimit; )
|
||||||
{
|
{
|
||||||
int sym = tinf_decode_symbol(d, lt);
|
int sym = tinf_decode_symbol(d, lt);
|
||||||
|
unsigned char fill_value = 0;
|
||||||
|
int lbits, lbase = 3;
|
||||||
|
|
||||||
|
/* error decoding */
|
||||||
|
if (sym < 0) return sym;
|
||||||
|
|
||||||
switch (sym)
|
switch (sym)
|
||||||
{
|
{
|
||||||
case 16:
|
case 16:
|
||||||
/* copy previous code length 3-6 times (read 2 bits) */
|
/* copy previous code length 3-6 times (read 2 bits) */
|
||||||
{
|
if (num == 0) return TINF_DATA_ERROR;
|
||||||
unsigned char prev = lengths[num - 1];
|
fill_value = lengths[num - 1];
|
||||||
for (length = tinf_read_bits(d, 2, 3); length; --length)
|
lbits = 2;
|
||||||
{
|
|
||||||
lengths[num++] = prev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 17:
|
case 17:
|
||||||
/* repeat code length 0 for 3-10 times (read 3 bits) */
|
/* repeat code length 0 for 3-10 times (read 3 bits) */
|
||||||
for (length = tinf_read_bits(d, 3, 3); length; --length)
|
lbits = 3;
|
||||||
{
|
|
||||||
lengths[num++] = 0;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
/* repeat code length 0 for 11-138 times (read 7 bits) */
|
/* repeat code length 0 for 11-138 times (read 7 bits) */
|
||||||
for (length = tinf_read_bits(d, 7, 11); length; --length)
|
lbits = 7;
|
||||||
{
|
lbase = 11;
|
||||||
lengths[num++] = 0;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* values 0-15 represent the actual code lengths */
|
/* values 0-15 represent the actual code lengths */
|
||||||
lengths[num++] = sym;
|
lengths[num++] = sym;
|
||||||
break;
|
/* continue the for loop */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* special code length 16-18 are handled here */
|
||||||
|
length = tinf_read_bits(d, lbits, lbase);
|
||||||
|
if (num + length > hlimit) return TINF_DATA_ERROR;
|
||||||
|
for (; length; --length)
|
||||||
|
{
|
||||||
|
lengths[num++] = fill_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if UZLIB_CONF_DEBUG_LOG >= 2
|
||||||
|
printf("lit code lengths (%d):", hlit);
|
||||||
|
UZLIB_DUMP_ARRAY("", lengths, hlit);
|
||||||
|
printf("dist code lengths (%d):", hdist);
|
||||||
|
UZLIB_DUMP_ARRAY("", lengths + hlit, hdist);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if UZLIB_CONF_PARANOID_CHECKS
|
||||||
|
/* Check that there's "end of block" symbol */
|
||||||
|
if (lengths[256] == 0) {
|
||||||
|
return TINF_DATA_ERROR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* build dynamic trees */
|
/* build dynamic trees */
|
||||||
tinf_build_tree(lt, lengths, hlit);
|
tinf_build_tree(lt, lengths, hlit);
|
||||||
tinf_build_tree(dt, lengths + hlit, hdist);
|
tinf_build_tree(dt, lengths + hlit, hdist);
|
||||||
|
|
||||||
|
return TINF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------- *
|
/* ----------------------------- *
|
||||||
* -- block inflate functions -- *
|
* -- block inflate functions -- *
|
||||||
* ----------------------------- */
|
* ----------------------------- */
|
||||||
|
|
||||||
/* given a stream and two trees, inflate a block of data */
|
/* given a stream and two trees, inflate next byte of output */
|
||||||
static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt)
|
static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt)
|
||||||
{
|
{
|
||||||
if (d->curlen == 0) {
|
if (d->curlen == 0) {
|
||||||
@ -341,6 +411,10 @@ static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt)
|
|||||||
int sym = tinf_decode_symbol(d, lt);
|
int sym = tinf_decode_symbol(d, lt);
|
||||||
//printf("huff sym: %02x\n", sym);
|
//printf("huff sym: %02x\n", sym);
|
||||||
|
|
||||||
|
if (d->eof) {
|
||||||
|
return TINF_DATA_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* literal byte */
|
/* literal byte */
|
||||||
if (sym < 256) {
|
if (sym < 256) {
|
||||||
TINF_PUT(d, sym);
|
TINF_PUT(d, sym);
|
||||||
@ -354,21 +428,45 @@ static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt)
|
|||||||
|
|
||||||
/* substring from sliding dictionary */
|
/* substring from sliding dictionary */
|
||||||
sym -= 257;
|
sym -= 257;
|
||||||
|
if (sym >= 29) {
|
||||||
|
return TINF_DATA_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* possibly get more bits from length code */
|
/* possibly get more bits from length code */
|
||||||
d->curlen = tinf_read_bits(d, length_bits[sym], length_base[sym]);
|
d->curlen = tinf_read_bits(d, length_bits[sym], length_base[sym]);
|
||||||
|
|
||||||
dist = tinf_decode_symbol(d, dt);
|
dist = tinf_decode_symbol(d, dt);
|
||||||
|
if (dist >= 30) {
|
||||||
|
return TINF_DATA_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
/* possibly get more bits from distance code */
|
/* possibly get more bits from distance code */
|
||||||
offs = tinf_read_bits(d, dist_bits[dist], dist_base[dist]);
|
offs = tinf_read_bits(d, dist_bits[dist], dist_base[dist]);
|
||||||
|
|
||||||
|
/* calculate and validate actual LZ offset to use */
|
||||||
if (d->dict_ring) {
|
if (d->dict_ring) {
|
||||||
if (offs > d->dict_size) {
|
if (offs > d->dict_size) {
|
||||||
return TINF_DICT_ERROR;
|
return TINF_DICT_ERROR;
|
||||||
}
|
}
|
||||||
|
/* Note: unlike full-dest-in-memory case below, we don't
|
||||||
|
try to catch offset which points to not yet filled
|
||||||
|
part of the dictionary here. Doing so would require
|
||||||
|
keeping another variable to track "filled in" size
|
||||||
|
of the dictionary. Appearance of such an offset cannot
|
||||||
|
lead to accessing memory outside of the dictionary
|
||||||
|
buffer, and clients which don't want to leak unrelated
|
||||||
|
information, should explicitly initialize dictionary
|
||||||
|
buffer passed to uzlib. */
|
||||||
|
|
||||||
d->lzOff = d->dict_idx - offs;
|
d->lzOff = d->dict_idx - offs;
|
||||||
if (d->lzOff < 0) {
|
if (d->lzOff < 0) {
|
||||||
d->lzOff += d->dict_size;
|
d->lzOff += d->dict_size;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
/* catch trying to point before the start of dest buffer */
|
||||||
|
if (offs > d->dest - d->destStart) {
|
||||||
|
return TINF_DATA_ERROR;
|
||||||
|
}
|
||||||
d->lzOff = -offs;
|
d->lzOff = -offs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,7 +485,7 @@ static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt)
|
|||||||
return TINF_OK;
|
return TINF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* inflate an uncompressed block of data */
|
/* inflate next byte from uncompressed block of data */
|
||||||
static int tinf_inflate_uncompressed_block(TINF_DATA *d)
|
static int tinf_inflate_uncompressed_block(TINF_DATA *d)
|
||||||
{
|
{
|
||||||
if (d->curlen == 0) {
|
if (d->curlen == 0) {
|
||||||
@ -440,6 +538,7 @@ void uzlib_init(void)
|
|||||||
/* initialize decompression structure */
|
/* initialize decompression structure */
|
||||||
void uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen)
|
void uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen)
|
||||||
{
|
{
|
||||||
|
d->eof = 0;
|
||||||
d->bitcount = 0;
|
d->bitcount = 0;
|
||||||
d->bfinal = 0;
|
d->bfinal = 0;
|
||||||
d->btype = -1;
|
d->btype = -1;
|
||||||
@ -449,7 +548,7 @@ void uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen)
|
|||||||
d->curlen = 0;
|
d->curlen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* inflate next byte of compressed stream */
|
/* inflate next output bytes from compressed stream */
|
||||||
int uzlib_uncompress(TINF_DATA *d)
|
int uzlib_uncompress(TINF_DATA *d)
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
@ -463,14 +562,19 @@ next_blk:
|
|||||||
/* read block type (2 bits) */
|
/* read block type (2 bits) */
|
||||||
d->btype = tinf_read_bits(d, 2, 0);
|
d->btype = tinf_read_bits(d, 2, 0);
|
||||||
|
|
||||||
//printf("Started new block: type=%d final=%d\n", d->btype, d->bfinal);
|
#if UZLIB_CONF_DEBUG_LOG >= 1
|
||||||
|
printf("Started new block: type=%d final=%d\n", d->btype, d->bfinal);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (d->btype == 1) {
|
if (d->btype == 1) {
|
||||||
/* build fixed huffman trees */
|
/* build fixed huffman trees */
|
||||||
tinf_build_fixed_trees(&d->ltree, &d->dtree);
|
tinf_build_fixed_trees(&d->ltree, &d->dtree);
|
||||||
} else if (d->btype == 2) {
|
} else if (d->btype == 2) {
|
||||||
/* decode trees from stream */
|
/* decode trees from stream */
|
||||||
tinf_decode_trees(d, &d->ltree, &d->dtree);
|
res = tinf_decode_trees(d, &d->ltree, &d->dtree);
|
||||||
|
if (res != TINF_OK) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,7 +587,7 @@ next_blk:
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
/* decompress block with fixed/dyanamic huffman trees */
|
/* decompress block with fixed/dynamic huffman trees */
|
||||||
/* trees were decoded previously, so it's the same routine for both */
|
/* trees were decoded previously, so it's the same routine for both */
|
||||||
res = tinf_inflate_block_data(d, &d->ltree, &d->dtree);
|
res = tinf_inflate_block_data(d, &d->ltree, &d->dtree);
|
||||||
break;
|
break;
|
||||||
@ -501,11 +605,13 @@ next_blk:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (--d->destSize);
|
} while (d->dest < d->dest_limit);
|
||||||
|
|
||||||
return TINF_OK;
|
return TINF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* inflate next output bytes from compressed stream, updating
|
||||||
|
checksum, and at the end of stream, verify it */
|
||||||
int uzlib_uncompress_chksum(TINF_DATA *d)
|
int uzlib_uncompress_chksum(TINF_DATA *d)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* tinfzlib - tiny zlib decompressor
|
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
*
|
*
|
||||||
* http://www.ibsensoftware.com/
|
* http://www.ibsensoftware.com/
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014-2016 by Paul Sokolovsky
|
* Copyright (c) 2014-2018 by Paul Sokolovsky
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express
|
* This software is provided 'as-is', without any express
|
||||||
* or implied warranty. In no event will the authors be
|
* or implied warranty. In no event will the authors be
|
||||||
|
|||||||
169
extmod/uzlib/uzlib.h
Normal file
169
extmod/uzlib/uzlib.h
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||||
|
* All Rights Reserved
|
||||||
|
* http://www.ibsensoftware.com/
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014-2018 by Paul Sokolovsky
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express
|
||||||
|
* or implied warranty. In no event will the authors be
|
||||||
|
* held liable for any damages arising from the use of
|
||||||
|
* this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software
|
||||||
|
* for any purpose, including commercial applications,
|
||||||
|
* and to alter it and redistribute it freely, subject to
|
||||||
|
* the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be
|
||||||
|
* misrepresented; you must not claim that you
|
||||||
|
* wrote the original software. If you use this
|
||||||
|
* software in a product, an acknowledgment in
|
||||||
|
* the product documentation would be appreciated
|
||||||
|
* but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked
|
||||||
|
* as such, and must not be misrepresented as
|
||||||
|
* being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from
|
||||||
|
* any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UZLIB_H_INCLUDED
|
||||||
|
#define UZLIB_H_INCLUDED
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "defl_static.h"
|
||||||
|
|
||||||
|
#include "uzlib_conf.h"
|
||||||
|
#if UZLIB_CONF_DEBUG_LOG
|
||||||
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* calling convention */
|
||||||
|
#ifndef TINFCC
|
||||||
|
#ifdef __WATCOMC__
|
||||||
|
#define TINFCC __cdecl
|
||||||
|
#else
|
||||||
|
#define TINFCC
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ok status, more data produced */
|
||||||
|
#define TINF_OK 0
|
||||||
|
/* end of compressed stream reached */
|
||||||
|
#define TINF_DONE 1
|
||||||
|
#define TINF_DATA_ERROR (-3)
|
||||||
|
#define TINF_CHKSUM_ERROR (-4)
|
||||||
|
#define TINF_DICT_ERROR (-5)
|
||||||
|
|
||||||
|
/* checksum types */
|
||||||
|
#define TINF_CHKSUM_NONE 0
|
||||||
|
#define TINF_CHKSUM_ADLER 1
|
||||||
|
#define TINF_CHKSUM_CRC 2
|
||||||
|
|
||||||
|
/* helper macros */
|
||||||
|
#define TINF_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr)))
|
||||||
|
|
||||||
|
/* data structures */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned short table[16]; /* table of code length counts */
|
||||||
|
unsigned short trans[288]; /* code -> symbol translation table */
|
||||||
|
} TINF_TREE;
|
||||||
|
|
||||||
|
struct uzlib_uncomp {
|
||||||
|
/* Pointer to the next byte in the input buffer */
|
||||||
|
const unsigned char *source;
|
||||||
|
/* Pointer to the next byte past the input buffer (source_limit = source + len) */
|
||||||
|
const unsigned char *source_limit;
|
||||||
|
/* If source_limit == NULL, or source >= source_limit, this function
|
||||||
|
will be used to read next byte from source stream. The function may
|
||||||
|
also return -1 in case of EOF (or irrecoverable error). Note that
|
||||||
|
besides returning the next byte, it may also update source and
|
||||||
|
source_limit fields, thus allowing for buffered operation. */
|
||||||
|
int (*source_read_cb)(struct uzlib_uncomp *uncomp);
|
||||||
|
|
||||||
|
unsigned int tag;
|
||||||
|
unsigned int bitcount;
|
||||||
|
|
||||||
|
/* Destination (output) buffer start */
|
||||||
|
unsigned char *dest_start;
|
||||||
|
/* Current pointer in dest buffer */
|
||||||
|
unsigned char *dest;
|
||||||
|
/* Pointer past the end of the dest buffer, similar to source_limit */
|
||||||
|
unsigned char *dest_limit;
|
||||||
|
|
||||||
|
/* Accumulating checksum */
|
||||||
|
unsigned int checksum;
|
||||||
|
char checksum_type;
|
||||||
|
bool eof;
|
||||||
|
|
||||||
|
int btype;
|
||||||
|
int bfinal;
|
||||||
|
unsigned int curlen;
|
||||||
|
int lzOff;
|
||||||
|
unsigned char *dict_ring;
|
||||||
|
unsigned int dict_size;
|
||||||
|
unsigned int dict_idx;
|
||||||
|
|
||||||
|
TINF_TREE ltree; /* dynamic length/symbol tree */
|
||||||
|
TINF_TREE dtree; /* dynamic distance tree */
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "tinf_compat.h"
|
||||||
|
|
||||||
|
#define TINF_PUT(d, c) \
|
||||||
|
{ \
|
||||||
|
*d->dest++ = c; \
|
||||||
|
if (d->dict_ring) { d->dict_ring[d->dict_idx++] = c; if (d->dict_idx == d->dict_size) d->dict_idx = 0; } \
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char TINFCC uzlib_get_byte(TINF_DATA *d);
|
||||||
|
|
||||||
|
/* Decompression API */
|
||||||
|
|
||||||
|
void TINFCC uzlib_init(void);
|
||||||
|
void TINFCC uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen);
|
||||||
|
int TINFCC uzlib_uncompress(TINF_DATA *d);
|
||||||
|
int TINFCC uzlib_uncompress_chksum(TINF_DATA *d);
|
||||||
|
|
||||||
|
int TINFCC uzlib_zlib_parse_header(TINF_DATA *d);
|
||||||
|
int TINFCC uzlib_gzip_parse_header(TINF_DATA *d);
|
||||||
|
|
||||||
|
/* Compression API */
|
||||||
|
|
||||||
|
typedef const uint8_t *uzlib_hash_entry_t;
|
||||||
|
|
||||||
|
struct uzlib_comp {
|
||||||
|
struct Outbuf out;
|
||||||
|
|
||||||
|
uzlib_hash_entry_t *hash_table;
|
||||||
|
unsigned int hash_bits;
|
||||||
|
unsigned int dict_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
void TINFCC uzlib_compress(struct uzlib_comp *c, const uint8_t *src, unsigned slen);
|
||||||
|
|
||||||
|
/* Checksum API */
|
||||||
|
|
||||||
|
/* prev_sum is previous value for incremental computation, 1 initially */
|
||||||
|
uint32_t TINFCC uzlib_adler32(const void *data, unsigned int length, uint32_t prev_sum);
|
||||||
|
/* crc is previous value for incremental computation, 0xffffffff initially */
|
||||||
|
uint32_t TINFCC uzlib_crc32(const void *data, unsigned int length, uint32_t crc);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* UZLIB_H_INCLUDED */
|
||||||
22
extmod/uzlib/uzlib_conf.h
Normal file
22
extmod/uzlib/uzlib_conf.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014-2018 by Paul Sokolovsky
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UZLIB_CONF_H_INCLUDED
|
||||||
|
#define UZLIB_CONF_H_INCLUDED
|
||||||
|
|
||||||
|
#ifndef UZLIB_CONF_DEBUG_LOG
|
||||||
|
/* Debug logging level 0, 1, 2, etc. */
|
||||||
|
#define UZLIB_CONF_DEBUG_LOG 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UZLIB_CONF_PARANOID_CHECKS
|
||||||
|
/* Perform extra checks on the input stream, even if they aren't proven
|
||||||
|
to be strictly required (== lack of them wasn't proven to lead to
|
||||||
|
crashes). */
|
||||||
|
#define UZLIB_CONF_PARANOID_CHECKS 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* UZLIB_CONF_H_INCLUDED */
|
||||||
@ -227,7 +227,7 @@ mp_obj_t mp_vfs_umount(mp_obj_t mnt_in) {
|
|||||||
mp_vfs_mount_t *vfs = NULL;
|
mp_vfs_mount_t *vfs = NULL;
|
||||||
size_t mnt_len;
|
size_t mnt_len;
|
||||||
const char *mnt_str = NULL;
|
const char *mnt_str = NULL;
|
||||||
if (MP_OBJ_IS_STR(mnt_in)) {
|
if (mp_obj_is_str(mnt_in)) {
|
||||||
mnt_str = mp_obj_str_get_data(mnt_in, &mnt_len);
|
mnt_str = mp_obj_str_get_data(mnt_in, &mnt_len);
|
||||||
}
|
}
|
||||||
for (mp_vfs_mount_t **vfsp = &MP_STATE_VM(vfs_mount_table); *vfsp != NULL; vfsp = &(*vfsp)->next) {
|
for (mp_vfs_mount_t **vfsp = &MP_STATE_VM(vfs_mount_table); *vfsp != NULL; vfsp = &(*vfsp)->next) {
|
||||||
@ -270,7 +270,7 @@ mp_obj_t mp_vfs_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
|||||||
|
|
||||||
#if MICROPY_VFS_POSIX
|
#if MICROPY_VFS_POSIX
|
||||||
// If the file is an integer then delegate straight to the POSIX handler
|
// If the file is an integer then delegate straight to the POSIX handler
|
||||||
if (MP_OBJ_IS_SMALL_INT(args[ARG_file].u_obj)) {
|
if (mp_obj_is_small_int(args[ARG_file].u_obj)) {
|
||||||
return mp_vfs_posix_file_open(&mp_type_textio, args[ARG_file].u_obj, args[ARG_mode].u_obj);
|
return mp_vfs_posix_file_open(&mp_type_textio, args[ARG_file].u_obj, args[ARG_mode].u_obj);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -39,8 +39,8 @@
|
|||||||
#include "extmod/vfs_fat.h"
|
#include "extmod/vfs_fat.h"
|
||||||
#include "lib/timeutils/timeutils.h"
|
#include "lib/timeutils/timeutils.h"
|
||||||
|
|
||||||
#if _MAX_SS == _MIN_SS
|
#if FF_MAX_SS == FF_MIN_SS
|
||||||
#define SECSIZE(fs) (_MIN_SS)
|
#define SECSIZE(fs) (FF_MIN_SS)
|
||||||
#else
|
#else
|
||||||
#define SECSIZE(fs) ((fs)->ssize)
|
#define SECSIZE(fs) ((fs)->ssize)
|
||||||
#endif
|
#endif
|
||||||
@ -111,8 +111,11 @@ STATIC mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) {
|
|||||||
fs_user_mount_t *vfs = MP_OBJ_TO_PTR(fat_vfs_make_new(&mp_fat_vfs_type, 1, 0, &bdev_in));
|
fs_user_mount_t *vfs = MP_OBJ_TO_PTR(fat_vfs_make_new(&mp_fat_vfs_type, 1, 0, &bdev_in));
|
||||||
|
|
||||||
// make the filesystem
|
// make the filesystem
|
||||||
uint8_t working_buf[_MAX_SS];
|
uint8_t working_buf[FF_MAX_SS];
|
||||||
FRESULT res = f_mkfs(&vfs->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf));
|
FRESULT res = f_mkfs(&vfs->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf));
|
||||||
|
if (res == FR_MKFS_ABORTED) { // Probably doesn't support FAT16
|
||||||
|
res = f_mkfs(&vfs->fatfs, FM_FAT32, 0, working_buf, sizeof(working_buf));
|
||||||
|
}
|
||||||
if (res != FR_OK) {
|
if (res != FR_OK) {
|
||||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||||
}
|
}
|
||||||
@ -363,7 +366,7 @@ STATIC mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) {
|
|||||||
t->items[6] = MP_OBJ_NEW_SMALL_INT(0); // f_ffree
|
t->items[6] = MP_OBJ_NEW_SMALL_INT(0); // f_ffree
|
||||||
t->items[7] = MP_OBJ_NEW_SMALL_INT(0); // f_favail
|
t->items[7] = MP_OBJ_NEW_SMALL_INT(0); // f_favail
|
||||||
t->items[8] = MP_OBJ_NEW_SMALL_INT(0); // f_flags
|
t->items[8] = MP_OBJ_NEW_SMALL_INT(0); // f_flags
|
||||||
t->items[9] = MP_OBJ_NEW_SMALL_INT(_MAX_LFN); // f_namemax
|
t->items[9] = MP_OBJ_NEW_SMALL_INT(FF_MAX_LFN); // f_namemax
|
||||||
|
|
||||||
return MP_OBJ_FROM_PTR(t);
|
return MP_OBJ_FROM_PTR(t);
|
||||||
}
|
}
|
||||||
@ -383,7 +386,7 @@ STATIC mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs
|
|||||||
// check if we need to make the filesystem
|
// check if we need to make the filesystem
|
||||||
FRESULT res = (self->flags & FSUSER_NO_FILESYSTEM) ? FR_NO_FILESYSTEM : FR_OK;
|
FRESULT res = (self->flags & FSUSER_NO_FILESYSTEM) ? FR_NO_FILESYSTEM : FR_OK;
|
||||||
if (res == FR_NO_FILESYSTEM && mp_obj_is_true(mkfs)) {
|
if (res == FR_NO_FILESYSTEM && mp_obj_is_true(mkfs)) {
|
||||||
uint8_t working_buf[_MAX_SS];
|
uint8_t working_buf[FF_MAX_SS];
|
||||||
res = f_mkfs(&self->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf));
|
res = f_mkfs(&self->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf));
|
||||||
}
|
}
|
||||||
if (res != FR_OK) {
|
if (res != FR_OK) {
|
||||||
|
|||||||
@ -42,8 +42,8 @@
|
|||||||
#include "lib/oofatfs/diskio.h"
|
#include "lib/oofatfs/diskio.h"
|
||||||
#include "extmod/vfs_fat.h"
|
#include "extmod/vfs_fat.h"
|
||||||
|
|
||||||
#if _MAX_SS == _MIN_SS
|
#if FF_MAX_SS == FF_MIN_SS
|
||||||
#define SECSIZE(fs) (_MIN_SS)
|
#define SECSIZE(fs) (FF_MIN_SS)
|
||||||
#else
|
#else
|
||||||
#define SECSIZE(fs) ((fs)->ssize)
|
#define SECSIZE(fs) ((fs)->ssize)
|
||||||
#endif
|
#endif
|
||||||
@ -194,7 +194,7 @@ DRESULT disk_ioctl (
|
|||||||
} else {
|
} else {
|
||||||
*((WORD*)buff) = mp_obj_get_int(ret);
|
*((WORD*)buff) = mp_obj_get_int(ret);
|
||||||
}
|
}
|
||||||
#if _MAX_SS != _MIN_SS
|
#if FF_MAX_SS != FF_MIN_SS
|
||||||
// need to store ssize because we use it in disk_read/disk_write
|
// need to store ssize because we use it in disk_read/disk_write
|
||||||
vfs->fatfs.ssize = *((WORD*)buff);
|
vfs->fatfs.ssize = *((WORD*)buff);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -130,7 +130,7 @@ STATIC mp_obj_t vfs_posix_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode
|
|||||||
&& (strchr(mode, 'w') != NULL || strchr(mode, 'a') != NULL || strchr(mode, '+') != NULL)) {
|
&& (strchr(mode, 'w') != NULL || strchr(mode, 'a') != NULL || strchr(mode, '+') != NULL)) {
|
||||||
mp_raise_OSError(MP_EROFS);
|
mp_raise_OSError(MP_EROFS);
|
||||||
}
|
}
|
||||||
if (!MP_OBJ_IS_SMALL_INT(path_in)) {
|
if (!mp_obj_is_small_int(path_in)) {
|
||||||
path_in = vfs_posix_get_path_obj(self, path_in);
|
path_in = vfs_posix_get_path_obj(self, path_in);
|
||||||
}
|
}
|
||||||
return mp_vfs_posix_file_open(&mp_type_textio, path_in, mode_in);
|
return mp_vfs_posix_file_open(&mp_type_textio, path_in, mode_in);
|
||||||
|
|||||||
@ -94,7 +94,7 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_
|
|||||||
|
|
||||||
mp_obj_t fid = file_in;
|
mp_obj_t fid = file_in;
|
||||||
|
|
||||||
if (MP_OBJ_IS_SMALL_INT(fid)) {
|
if (mp_obj_is_small_int(fid)) {
|
||||||
o->fd = MP_OBJ_SMALL_INT_VALUE(fid);
|
o->fd = MP_OBJ_SMALL_INT_VALUE(fid);
|
||||||
return MP_OBJ_FROM_PTR(o);
|
return MP_OBJ_FROM_PTR(o);
|
||||||
}
|
}
|
||||||
|
|||||||
12
index.html
Normal file
12
index.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<!-- HTML meta refresh URL redirection -->
|
||||||
|
<meta http-equiv="refresh"
|
||||||
|
content="0; url=/ports/javascript/lvgl.html">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>The page has moved to:
|
||||||
|
<a href="/ports/javascript/lvgl.html">this page</a></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -1,43 +1,108 @@
|
|||||||
/**************************************************************************//**
|
/**************************************************************************//**
|
||||||
* @file cmsis_armcc.h
|
* @file cmsis_armcc.h
|
||||||
* @brief CMSIS Cortex-M Core Function/Instruction Header File
|
* @brief CMSIS compiler ARMCC (Arm Compiler 5) header file
|
||||||
* @version V4.30
|
* @version V5.0.5
|
||||||
* @date 20. October 2015
|
* @date 14. December 2018
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
/*
|
||||||
|
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
|
||||||
All rights reserved.
|
*
|
||||||
Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
modification, are permitted provided that the following conditions are met:
|
*
|
||||||
- Redistributions of source code must retain the above copyright
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
notice, this list of conditions and the following disclaimer.
|
* not use this file except in compliance with the License.
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
* You may obtain a copy of the License at
|
||||||
notice, this list of conditions and the following disclaimer in the
|
*
|
||||||
documentation and/or other materials provided with the distribution.
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
- Neither the name of ARM nor the names of its contributors may be used
|
*
|
||||||
to endorse or promote products derived from this software without
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
specific prior written permission.
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
*
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* See the License for the specific language governing permissions and
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* limitations under the License.
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
*/
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
|
||||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef __CMSIS_ARMCC_H
|
#ifndef __CMSIS_ARMCC_H
|
||||||
#define __CMSIS_ARMCC_H
|
#define __CMSIS_ARMCC_H
|
||||||
|
|
||||||
|
|
||||||
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677)
|
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677)
|
||||||
#error "Please use ARM Compiler Toolchain V4.0.677 or later!"
|
#error "Please use Arm Compiler Toolchain V4.0.677 or later!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CMSIS compiler control architecture macros */
|
||||||
|
#if ((defined (__TARGET_ARCH_6_M ) && (__TARGET_ARCH_6_M == 1)) || \
|
||||||
|
(defined (__TARGET_ARCH_6S_M ) && (__TARGET_ARCH_6S_M == 1)) )
|
||||||
|
#define __ARM_ARCH_6M__ 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1))
|
||||||
|
#define __ARM_ARCH_7M__ 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1))
|
||||||
|
#define __ARM_ARCH_7EM__ 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* __ARM_ARCH_8M_BASE__ not applicable */
|
||||||
|
/* __ARM_ARCH_8M_MAIN__ not applicable */
|
||||||
|
|
||||||
|
/* CMSIS compiler control DSP macros */
|
||||||
|
#if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
|
||||||
|
#define __ARM_FEATURE_DSP 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* CMSIS compiler specific defines */
|
||||||
|
#ifndef __ASM
|
||||||
|
#define __ASM __asm
|
||||||
|
#endif
|
||||||
|
#ifndef __INLINE
|
||||||
|
#define __INLINE __inline
|
||||||
|
#endif
|
||||||
|
#ifndef __STATIC_INLINE
|
||||||
|
#define __STATIC_INLINE static __inline
|
||||||
|
#endif
|
||||||
|
#ifndef __STATIC_FORCEINLINE
|
||||||
|
#define __STATIC_FORCEINLINE static __forceinline
|
||||||
|
#endif
|
||||||
|
#ifndef __NO_RETURN
|
||||||
|
#define __NO_RETURN __declspec(noreturn)
|
||||||
|
#endif
|
||||||
|
#ifndef __USED
|
||||||
|
#define __USED __attribute__((used))
|
||||||
|
#endif
|
||||||
|
#ifndef __WEAK
|
||||||
|
#define __WEAK __attribute__((weak))
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED
|
||||||
|
#define __PACKED __attribute__((packed))
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED_STRUCT
|
||||||
|
#define __PACKED_STRUCT __packed struct
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED_UNION
|
||||||
|
#define __PACKED_UNION __packed union
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32 /* deprecated */
|
||||||
|
#define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x)))
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT16_WRITE
|
||||||
|
#define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val))
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT16_READ
|
||||||
|
#define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr)))
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32_WRITE
|
||||||
|
#define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val))
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32_READ
|
||||||
|
#define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr)))
|
||||||
|
#endif
|
||||||
|
#ifndef __ALIGNED
|
||||||
|
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||||
|
#endif
|
||||||
|
#ifndef __RESTRICT
|
||||||
|
#define __RESTRICT __restrict
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ########################### Core Function Access ########################### */
|
/* ########################### Core Function Access ########################### */
|
||||||
@ -46,7 +111,19 @@
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Enable IRQ Interrupts
|
||||||
|
\details Enables IRQ interrupts by clearing the I-bit in the CPSR.
|
||||||
|
Can only be executed in Privileged modes.
|
||||||
|
*/
|
||||||
/* intrinsic void __enable_irq(); */
|
/* intrinsic void __enable_irq(); */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Disable IRQ Interrupts
|
||||||
|
\details Disables IRQ interrupts by setting the I-bit in the CPSR.
|
||||||
|
Can only be executed in Privileged modes.
|
||||||
|
*/
|
||||||
/* intrinsic void __disable_irq(); */
|
/* intrinsic void __disable_irq(); */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -181,7 +258,8 @@ __STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
|
#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||||
|
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Enable FIQ
|
\brief Enable FIQ
|
||||||
@ -256,14 +334,13 @@ __STATIC_INLINE uint32_t __get_FAULTMASK(void)
|
|||||||
__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
|
__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
|
||||||
{
|
{
|
||||||
register uint32_t __regFaultMask __ASM("faultmask");
|
register uint32_t __regFaultMask __ASM("faultmask");
|
||||||
__regFaultMask = (faultMask & (uint32_t)1);
|
__regFaultMask = (faultMask & (uint32_t)1U);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */
|
#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||||
|
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
|
||||||
|
|
||||||
|
|
||||||
#if (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get FPSCR
|
\brief Get FPSCR
|
||||||
\details Returns the current value of the Floating Point Status/Control register.
|
\details Returns the current value of the Floating Point Status/Control register.
|
||||||
@ -271,7 +348,8 @@ __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
|
|||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t __get_FPSCR(void)
|
__STATIC_INLINE uint32_t __get_FPSCR(void)
|
||||||
{
|
{
|
||||||
#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
|
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||||
|
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
|
||||||
register uint32_t __regfpscr __ASM("fpscr");
|
register uint32_t __regfpscr __ASM("fpscr");
|
||||||
return(__regfpscr);
|
return(__regfpscr);
|
||||||
#else
|
#else
|
||||||
@ -287,15 +365,15 @@ __STATIC_INLINE uint32_t __get_FPSCR(void)
|
|||||||
*/
|
*/
|
||||||
__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
|
__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
|
||||||
{
|
{
|
||||||
#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
|
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||||
|
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
|
||||||
register uint32_t __regfpscr __ASM("fpscr");
|
register uint32_t __regfpscr __ASM("fpscr");
|
||||||
__regfpscr = (fpscr);
|
__regfpscr = (fpscr);
|
||||||
|
#else
|
||||||
|
(void)fpscr;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*@} end of CMSIS_Core_RegAccFunctions */
|
/*@} end of CMSIS_Core_RegAccFunctions */
|
||||||
|
|
||||||
@ -369,9 +447,10 @@ __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
|
|||||||
__schedule_barrier();\
|
__schedule_barrier();\
|
||||||
} while (0U)
|
} while (0U)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Reverse byte order (32 bit)
|
\brief Reverse byte order (32 bit)
|
||||||
\details Reverses the byte order in integer value.
|
\details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
|
||||||
\param [in] value Value to reverse
|
\param [in] value Value to reverse
|
||||||
\return Reversed value
|
\return Reversed value
|
||||||
*/
|
*/
|
||||||
@ -380,7 +459,7 @@ __STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Reverse byte order (16 bit)
|
\brief Reverse byte order (16 bit)
|
||||||
\details Reverses the byte order in two unsigned short values.
|
\details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
|
||||||
\param [in] value Value to reverse
|
\param [in] value Value to reverse
|
||||||
\return Reversed value
|
\return Reversed value
|
||||||
*/
|
*/
|
||||||
@ -392,14 +471,15 @@ __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(u
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Reverse byte order in signed short value
|
\brief Reverse byte order (16 bit)
|
||||||
\details Reverses the byte order in a signed short value with sign extension to integer.
|
\details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
|
||||||
\param [in] value Value to reverse
|
\param [in] value Value to reverse
|
||||||
\return Reversed value
|
\return Reversed value
|
||||||
*/
|
*/
|
||||||
#ifndef __NO_EMBEDDED_ASM
|
#ifndef __NO_EMBEDDED_ASM
|
||||||
__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)
|
__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value)
|
||||||
{
|
{
|
||||||
revsh r0, r0
|
revsh r0, r0
|
||||||
bx lr
|
bx lr
|
||||||
@ -410,8 +490,8 @@ __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(in
|
|||||||
/**
|
/**
|
||||||
\brief Rotate Right in unsigned value (32 bit)
|
\brief Rotate Right in unsigned value (32 bit)
|
||||||
\details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
|
\details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
|
||||||
\param [in] value Value to rotate
|
\param [in] op1 Value to rotate
|
||||||
\param [in] value Number of Bits to rotate
|
\param [in] op2 Number of Bits to rotate
|
||||||
\return Rotated value
|
\return Rotated value
|
||||||
*/
|
*/
|
||||||
#define __ROR __ror
|
#define __ROR __ror
|
||||||
@ -433,23 +513,24 @@ __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(in
|
|||||||
\param [in] value Value to reverse
|
\param [in] value Value to reverse
|
||||||
\return Reversed value
|
\return Reversed value
|
||||||
*/
|
*/
|
||||||
#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
|
#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||||
|
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
|
||||||
#define __RBIT __rbit
|
#define __RBIT __rbit
|
||||||
#else
|
#else
|
||||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
|
__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
|
||||||
{
|
{
|
||||||
uint32_t result;
|
uint32_t result;
|
||||||
int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */
|
uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
|
||||||
|
|
||||||
result = value; /* r will be reversed bits of v; first get LSB of v */
|
result = value; /* r will be reversed bits of v; first get LSB of v */
|
||||||
for (value >>= 1U; value; value >>= 1U)
|
for (value >>= 1U; value != 0U; value >>= 1U)
|
||||||
{
|
{
|
||||||
result <<= 1U;
|
result <<= 1U;
|
||||||
result |= value & 1U;
|
result |= value & 1U;
|
||||||
s--;
|
s--;
|
||||||
}
|
}
|
||||||
result <<= s; /* shift when v's highest bits are zero */
|
result <<= s; /* shift when v's highest bits are zero */
|
||||||
return(result);
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -463,7 +544,8 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
|
|||||||
#define __CLZ __clz
|
#define __CLZ __clz
|
||||||
|
|
||||||
|
|
||||||
#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)
|
#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||||
|
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief LDR Exclusive (8 bit)
|
\brief LDR Exclusive (8 bit)
|
||||||
@ -645,7 +727,60 @@ __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint3
|
|||||||
*/
|
*/
|
||||||
#define __STRT(value, ptr) __strt(value, ptr)
|
#define __STRT(value, ptr) __strt(value, ptr)
|
||||||
|
|
||||||
#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */
|
#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||||
|
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Signed Saturate
|
||||||
|
\details Saturates a signed value.
|
||||||
|
\param [in] value Value to be saturated
|
||||||
|
\param [in] sat Bit position to saturate to (1..32)
|
||||||
|
\return Saturated value
|
||||||
|
*/
|
||||||
|
__attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
|
||||||
|
{
|
||||||
|
if ((sat >= 1U) && (sat <= 32U))
|
||||||
|
{
|
||||||
|
const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
|
||||||
|
const int32_t min = -1 - max ;
|
||||||
|
if (val > max)
|
||||||
|
{
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
else if (val < min)
|
||||||
|
{
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Unsigned Saturate
|
||||||
|
\details Saturates an unsigned value.
|
||||||
|
\param [in] value Value to be saturated
|
||||||
|
\param [in] sat Bit position to saturate to (0..31)
|
||||||
|
\return Saturated value
|
||||||
|
*/
|
||||||
|
__attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
|
||||||
|
{
|
||||||
|
if (sat <= 31U)
|
||||||
|
{
|
||||||
|
const uint32_t max = ((1U << sat) - 1U);
|
||||||
|
if (val > (int32_t)max)
|
||||||
|
{
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
else if (val < 0)
|
||||||
|
{
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (uint32_t)val;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||||
|
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
|
||||||
|
|
||||||
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
|
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
|
||||||
|
|
||||||
@ -656,7 +791,7 @@ __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint3
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (__CORTEX_M >= 0x04U) /* only for Cortex-M4 and above */
|
#if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
|
||||||
|
|
||||||
#define __SADD8 __sadd8
|
#define __SADD8 __sadd8
|
||||||
#define __QADD8 __qadd8
|
#define __QADD8 __qadd8
|
||||||
@ -727,7 +862,7 @@ __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint3
|
|||||||
#define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
|
#define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
|
||||||
((int64_t)(ARG3) << 32U) ) >> 32U))
|
((int64_t)(ARG3) << 32U) ) >> 32U))
|
||||||
|
|
||||||
#endif /* (__CORTEX_M >= 0x04) */
|
#endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
|
||||||
/*@} end of group CMSIS_SIMD_intrinsics */
|
/*@} end of group CMSIS_SIMD_intrinsics */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1420
lib/cmsis/inc/cmsis_armclang.h
Normal file
1420
lib/cmsis/inc/cmsis_armclang.h
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
271
lib/cmsis/inc/cmsis_compiler.h
Normal file
271
lib/cmsis/inc/cmsis_compiler.h
Normal file
@ -0,0 +1,271 @@
|
|||||||
|
/**************************************************************************//**
|
||||||
|
* @file cmsis_compiler.h
|
||||||
|
* @brief CMSIS compiler generic header file
|
||||||
|
* @version V5.1.0
|
||||||
|
* @date 09. October 2018
|
||||||
|
******************************************************************************/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CMSIS_COMPILER_H
|
||||||
|
#define __CMSIS_COMPILER_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Arm Compiler 4/5
|
||||||
|
*/
|
||||||
|
#if defined ( __CC_ARM )
|
||||||
|
#include "cmsis_armcc.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Arm Compiler 6.6 LTM (armclang)
|
||||||
|
*/
|
||||||
|
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100)
|
||||||
|
#include "cmsis_armclang_ltm.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Arm Compiler above 6.10.1 (armclang)
|
||||||
|
*/
|
||||||
|
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
|
||||||
|
#include "cmsis_armclang.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GNU Compiler
|
||||||
|
*/
|
||||||
|
#elif defined ( __GNUC__ )
|
||||||
|
#include "cmsis_gcc.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IAR Compiler
|
||||||
|
*/
|
||||||
|
#elif defined ( __ICCARM__ )
|
||||||
|
#include <cmsis_iccarm.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TI Arm Compiler
|
||||||
|
*/
|
||||||
|
#elif defined ( __TI_ARM__ )
|
||||||
|
#include <cmsis_ccs.h>
|
||||||
|
|
||||||
|
#ifndef __ASM
|
||||||
|
#define __ASM __asm
|
||||||
|
#endif
|
||||||
|
#ifndef __INLINE
|
||||||
|
#define __INLINE inline
|
||||||
|
#endif
|
||||||
|
#ifndef __STATIC_INLINE
|
||||||
|
#define __STATIC_INLINE static inline
|
||||||
|
#endif
|
||||||
|
#ifndef __STATIC_FORCEINLINE
|
||||||
|
#define __STATIC_FORCEINLINE __STATIC_INLINE
|
||||||
|
#endif
|
||||||
|
#ifndef __NO_RETURN
|
||||||
|
#define __NO_RETURN __attribute__((noreturn))
|
||||||
|
#endif
|
||||||
|
#ifndef __USED
|
||||||
|
#define __USED __attribute__((used))
|
||||||
|
#endif
|
||||||
|
#ifndef __WEAK
|
||||||
|
#define __WEAK __attribute__((weak))
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED
|
||||||
|
#define __PACKED __attribute__((packed))
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED_STRUCT
|
||||||
|
#define __PACKED_STRUCT struct __attribute__((packed))
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED_UNION
|
||||||
|
#define __PACKED_UNION union __attribute__((packed))
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32 /* deprecated */
|
||||||
|
struct __attribute__((packed)) T_UINT32 { uint32_t v; };
|
||||||
|
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT16_WRITE
|
||||||
|
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
|
||||||
|
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT16_READ
|
||||||
|
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
|
||||||
|
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32_WRITE
|
||||||
|
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
|
||||||
|
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32_READ
|
||||||
|
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
|
||||||
|
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
|
||||||
|
#endif
|
||||||
|
#ifndef __ALIGNED
|
||||||
|
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||||
|
#endif
|
||||||
|
#ifndef __RESTRICT
|
||||||
|
#define __RESTRICT __restrict
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TASKING Compiler
|
||||||
|
*/
|
||||||
|
#elif defined ( __TASKING__ )
|
||||||
|
/*
|
||||||
|
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||||
|
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
||||||
|
* Including the CMSIS ones.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ASM
|
||||||
|
#define __ASM __asm
|
||||||
|
#endif
|
||||||
|
#ifndef __INLINE
|
||||||
|
#define __INLINE inline
|
||||||
|
#endif
|
||||||
|
#ifndef __STATIC_INLINE
|
||||||
|
#define __STATIC_INLINE static inline
|
||||||
|
#endif
|
||||||
|
#ifndef __STATIC_FORCEINLINE
|
||||||
|
#define __STATIC_FORCEINLINE __STATIC_INLINE
|
||||||
|
#endif
|
||||||
|
#ifndef __NO_RETURN
|
||||||
|
#define __NO_RETURN __attribute__((noreturn))
|
||||||
|
#endif
|
||||||
|
#ifndef __USED
|
||||||
|
#define __USED __attribute__((used))
|
||||||
|
#endif
|
||||||
|
#ifndef __WEAK
|
||||||
|
#define __WEAK __attribute__((weak))
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED
|
||||||
|
#define __PACKED __packed__
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED_STRUCT
|
||||||
|
#define __PACKED_STRUCT struct __packed__
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED_UNION
|
||||||
|
#define __PACKED_UNION union __packed__
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32 /* deprecated */
|
||||||
|
struct __packed__ T_UINT32 { uint32_t v; };
|
||||||
|
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT16_WRITE
|
||||||
|
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
|
||||||
|
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT16_READ
|
||||||
|
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
|
||||||
|
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32_WRITE
|
||||||
|
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
|
||||||
|
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32_READ
|
||||||
|
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
|
||||||
|
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
|
||||||
|
#endif
|
||||||
|
#ifndef __ALIGNED
|
||||||
|
#define __ALIGNED(x) __align(x)
|
||||||
|
#endif
|
||||||
|
#ifndef __RESTRICT
|
||||||
|
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
|
||||||
|
#define __RESTRICT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* COSMIC Compiler
|
||||||
|
*/
|
||||||
|
#elif defined ( __CSMC__ )
|
||||||
|
#include <cmsis_csm.h>
|
||||||
|
|
||||||
|
#ifndef __ASM
|
||||||
|
#define __ASM _asm
|
||||||
|
#endif
|
||||||
|
#ifndef __INLINE
|
||||||
|
#define __INLINE inline
|
||||||
|
#endif
|
||||||
|
#ifndef __STATIC_INLINE
|
||||||
|
#define __STATIC_INLINE static inline
|
||||||
|
#endif
|
||||||
|
#ifndef __STATIC_FORCEINLINE
|
||||||
|
#define __STATIC_FORCEINLINE __STATIC_INLINE
|
||||||
|
#endif
|
||||||
|
#ifndef __NO_RETURN
|
||||||
|
// NO RETURN is automatically detected hence no warning here
|
||||||
|
#define __NO_RETURN
|
||||||
|
#endif
|
||||||
|
#ifndef __USED
|
||||||
|
#warning No compiler specific solution for __USED. __USED is ignored.
|
||||||
|
#define __USED
|
||||||
|
#endif
|
||||||
|
#ifndef __WEAK
|
||||||
|
#define __WEAK __weak
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED
|
||||||
|
#define __PACKED @packed
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED_STRUCT
|
||||||
|
#define __PACKED_STRUCT @packed struct
|
||||||
|
#endif
|
||||||
|
#ifndef __PACKED_UNION
|
||||||
|
#define __PACKED_UNION @packed union
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32 /* deprecated */
|
||||||
|
@packed struct T_UINT32 { uint32_t v; };
|
||||||
|
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT16_WRITE
|
||||||
|
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
|
||||||
|
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT16_READ
|
||||||
|
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
|
||||||
|
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32_WRITE
|
||||||
|
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
|
||||||
|
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
|
||||||
|
#endif
|
||||||
|
#ifndef __UNALIGNED_UINT32_READ
|
||||||
|
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
|
||||||
|
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
|
||||||
|
#endif
|
||||||
|
#ifndef __ALIGNED
|
||||||
|
#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
|
||||||
|
#define __ALIGNED(x)
|
||||||
|
#endif
|
||||||
|
#ifndef __RESTRICT
|
||||||
|
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
|
||||||
|
#define __RESTRICT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error Unknown compiler.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __CMSIS_COMPILER_H */
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
940
lib/cmsis/inc/cmsis_iccarm.h
Normal file
940
lib/cmsis/inc/cmsis_iccarm.h
Normal file
@ -0,0 +1,940 @@
|
|||||||
|
/**************************************************************************//**
|
||||||
|
* @file cmsis_iccarm.h
|
||||||
|
* @brief CMSIS compiler ICCARM (IAR Compiler for Arm) header file
|
||||||
|
* @version V5.0.8
|
||||||
|
* @date 04. September 2018
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2017-2018 IAR Systems
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License")
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __CMSIS_ICCARM_H__
|
||||||
|
#define __CMSIS_ICCARM_H__
|
||||||
|
|
||||||
|
#ifndef __ICCARM__
|
||||||
|
#error This file should only be compiled by ICCARM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#pragma system_include
|
||||||
|
|
||||||
|
#define __IAR_FT _Pragma("inline=forced") __intrinsic
|
||||||
|
|
||||||
|
#if (__VER__ >= 8000000)
|
||||||
|
#define __ICCARM_V8 1
|
||||||
|
#else
|
||||||
|
#define __ICCARM_V8 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __ALIGNED
|
||||||
|
#if __ICCARM_V8
|
||||||
|
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||||
|
#elif (__VER__ >= 7080000)
|
||||||
|
/* Needs IAR language extensions */
|
||||||
|
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||||
|
#else
|
||||||
|
#warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
|
||||||
|
#define __ALIGNED(x)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Define compiler macros for CPU architecture, used in CMSIS 5.
|
||||||
|
*/
|
||||||
|
#if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ || __ARM_ARCH_8M_BASE__ || __ARM_ARCH_8M_MAIN__
|
||||||
|
/* Macros already defined */
|
||||||
|
#else
|
||||||
|
#if defined(__ARM8M_MAINLINE__) || defined(__ARM8EM_MAINLINE__)
|
||||||
|
#define __ARM_ARCH_8M_MAIN__ 1
|
||||||
|
#elif defined(__ARM8M_BASELINE__)
|
||||||
|
#define __ARM_ARCH_8M_BASE__ 1
|
||||||
|
#elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M'
|
||||||
|
#if __ARM_ARCH == 6
|
||||||
|
#define __ARM_ARCH_6M__ 1
|
||||||
|
#elif __ARM_ARCH == 7
|
||||||
|
#if __ARM_FEATURE_DSP
|
||||||
|
#define __ARM_ARCH_7EM__ 1
|
||||||
|
#else
|
||||||
|
#define __ARM_ARCH_7M__ 1
|
||||||
|
#endif
|
||||||
|
#endif /* __ARM_ARCH */
|
||||||
|
#endif /* __ARM_ARCH_PROFILE == 'M' */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Alternativ core deduction for older ICCARM's */
|
||||||
|
#if !defined(__ARM_ARCH_6M__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) && \
|
||||||
|
!defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__)
|
||||||
|
#if defined(__ARM6M__) && (__CORE__ == __ARM6M__)
|
||||||
|
#define __ARM_ARCH_6M__ 1
|
||||||
|
#elif defined(__ARM7M__) && (__CORE__ == __ARM7M__)
|
||||||
|
#define __ARM_ARCH_7M__ 1
|
||||||
|
#elif defined(__ARM7EM__) && (__CORE__ == __ARM7EM__)
|
||||||
|
#define __ARM_ARCH_7EM__ 1
|
||||||
|
#elif defined(__ARM8M_BASELINE__) && (__CORE == __ARM8M_BASELINE__)
|
||||||
|
#define __ARM_ARCH_8M_BASE__ 1
|
||||||
|
#elif defined(__ARM8M_MAINLINE__) && (__CORE == __ARM8M_MAINLINE__)
|
||||||
|
#define __ARM_ARCH_8M_MAIN__ 1
|
||||||
|
#elif defined(__ARM8EM_MAINLINE__) && (__CORE == __ARM8EM_MAINLINE__)
|
||||||
|
#define __ARM_ARCH_8M_MAIN__ 1
|
||||||
|
#else
|
||||||
|
#error "Unknown target."
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__ARM_ARCH_6M__) && __ARM_ARCH_6M__==1
|
||||||
|
#define __IAR_M0_FAMILY 1
|
||||||
|
#elif defined(__ARM_ARCH_8M_BASE__) && __ARM_ARCH_8M_BASE__==1
|
||||||
|
#define __IAR_M0_FAMILY 1
|
||||||
|
#else
|
||||||
|
#define __IAR_M0_FAMILY 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __ASM
|
||||||
|
#define __ASM __asm
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __INLINE
|
||||||
|
#define __INLINE inline
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __NO_RETURN
|
||||||
|
#if __ICCARM_V8
|
||||||
|
#define __NO_RETURN __attribute__((__noreturn__))
|
||||||
|
#else
|
||||||
|
#define __NO_RETURN _Pragma("object_attribute=__noreturn")
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __PACKED
|
||||||
|
#if __ICCARM_V8
|
||||||
|
#define __PACKED __attribute__((packed, aligned(1)))
|
||||||
|
#else
|
||||||
|
/* Needs IAR language extensions */
|
||||||
|
#define __PACKED __packed
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __PACKED_STRUCT
|
||||||
|
#if __ICCARM_V8
|
||||||
|
#define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
|
||||||
|
#else
|
||||||
|
/* Needs IAR language extensions */
|
||||||
|
#define __PACKED_STRUCT __packed struct
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __PACKED_UNION
|
||||||
|
#if __ICCARM_V8
|
||||||
|
#define __PACKED_UNION union __attribute__((packed, aligned(1)))
|
||||||
|
#else
|
||||||
|
/* Needs IAR language extensions */
|
||||||
|
#define __PACKED_UNION __packed union
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __RESTRICT
|
||||||
|
#if __ICCARM_V8
|
||||||
|
#define __RESTRICT __restrict
|
||||||
|
#else
|
||||||
|
/* Needs IAR language extensions */
|
||||||
|
#define __RESTRICT restrict
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __STATIC_INLINE
|
||||||
|
#define __STATIC_INLINE static inline
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __FORCEINLINE
|
||||||
|
#define __FORCEINLINE _Pragma("inline=forced")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __STATIC_FORCEINLINE
|
||||||
|
#define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __UNALIGNED_UINT16_READ
|
||||||
|
#pragma language=save
|
||||||
|
#pragma language=extended
|
||||||
|
__IAR_FT uint16_t __iar_uint16_read(void const *ptr)
|
||||||
|
{
|
||||||
|
return *(__packed uint16_t*)(ptr);
|
||||||
|
}
|
||||||
|
#pragma language=restore
|
||||||
|
#define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __UNALIGNED_UINT16_WRITE
|
||||||
|
#pragma language=save
|
||||||
|
#pragma language=extended
|
||||||
|
__IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
|
||||||
|
{
|
||||||
|
*(__packed uint16_t*)(ptr) = val;;
|
||||||
|
}
|
||||||
|
#pragma language=restore
|
||||||
|
#define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __UNALIGNED_UINT32_READ
|
||||||
|
#pragma language=save
|
||||||
|
#pragma language=extended
|
||||||
|
__IAR_FT uint32_t __iar_uint32_read(void const *ptr)
|
||||||
|
{
|
||||||
|
return *(__packed uint32_t*)(ptr);
|
||||||
|
}
|
||||||
|
#pragma language=restore
|
||||||
|
#define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __UNALIGNED_UINT32_WRITE
|
||||||
|
#pragma language=save
|
||||||
|
#pragma language=extended
|
||||||
|
__IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
|
||||||
|
{
|
||||||
|
*(__packed uint32_t*)(ptr) = val;;
|
||||||
|
}
|
||||||
|
#pragma language=restore
|
||||||
|
#define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __UNALIGNED_UINT32 /* deprecated */
|
||||||
|
#pragma language=save
|
||||||
|
#pragma language=extended
|
||||||
|
__packed struct __iar_u32 { uint32_t v; };
|
||||||
|
#pragma language=restore
|
||||||
|
#define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __USED
|
||||||
|
#if __ICCARM_V8
|
||||||
|
#define __USED __attribute__((used))
|
||||||
|
#else
|
||||||
|
#define __USED _Pragma("__root")
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __WEAK
|
||||||
|
#if __ICCARM_V8
|
||||||
|
#define __WEAK __attribute__((weak))
|
||||||
|
#else
|
||||||
|
#define __WEAK _Pragma("__weak")
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __ICCARM_INTRINSICS_VERSION__
|
||||||
|
#define __ICCARM_INTRINSICS_VERSION__ 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __ICCARM_INTRINSICS_VERSION__ == 2
|
||||||
|
|
||||||
|
#if defined(__CLZ)
|
||||||
|
#undef __CLZ
|
||||||
|
#endif
|
||||||
|
#if defined(__REVSH)
|
||||||
|
#undef __REVSH
|
||||||
|
#endif
|
||||||
|
#if defined(__RBIT)
|
||||||
|
#undef __RBIT
|
||||||
|
#endif
|
||||||
|
#if defined(__SSAT)
|
||||||
|
#undef __SSAT
|
||||||
|
#endif
|
||||||
|
#if defined(__USAT)
|
||||||
|
#undef __USAT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "iccarm_builtin.h"
|
||||||
|
|
||||||
|
#define __disable_fault_irq __iar_builtin_disable_fiq
|
||||||
|
#define __disable_irq __iar_builtin_disable_interrupt
|
||||||
|
#define __enable_fault_irq __iar_builtin_enable_fiq
|
||||||
|
#define __enable_irq __iar_builtin_enable_interrupt
|
||||||
|
#define __arm_rsr __iar_builtin_rsr
|
||||||
|
#define __arm_wsr __iar_builtin_wsr
|
||||||
|
|
||||||
|
|
||||||
|
#define __get_APSR() (__arm_rsr("APSR"))
|
||||||
|
#define __get_BASEPRI() (__arm_rsr("BASEPRI"))
|
||||||
|
#define __get_CONTROL() (__arm_rsr("CONTROL"))
|
||||||
|
#define __get_FAULTMASK() (__arm_rsr("FAULTMASK"))
|
||||||
|
|
||||||
|
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||||
|
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
|
||||||
|
#define __get_FPSCR() (__arm_rsr("FPSCR"))
|
||||||
|
#define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", (VALUE)))
|
||||||
|
#else
|
||||||
|
#define __get_FPSCR() ( 0 )
|
||||||
|
#define __set_FPSCR(VALUE) ((void)VALUE)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __get_IPSR() (__arm_rsr("IPSR"))
|
||||||
|
#define __get_MSP() (__arm_rsr("MSP"))
|
||||||
|
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
|
||||||
|
(!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
|
||||||
|
// without main extensions, the non-secure MSPLIM is RAZ/WI
|
||||||
|
#define __get_MSPLIM() (0U)
|
||||||
|
#else
|
||||||
|
#define __get_MSPLIM() (__arm_rsr("MSPLIM"))
|
||||||
|
#endif
|
||||||
|
#define __get_PRIMASK() (__arm_rsr("PRIMASK"))
|
||||||
|
#define __get_PSP() (__arm_rsr("PSP"))
|
||||||
|
|
||||||
|
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
|
||||||
|
(!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
|
||||||
|
// without main extensions, the non-secure PSPLIM is RAZ/WI
|
||||||
|
#define __get_PSPLIM() (0U)
|
||||||
|
#else
|
||||||
|
#define __get_PSPLIM() (__arm_rsr("PSPLIM"))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __get_xPSR() (__arm_rsr("xPSR"))
|
||||||
|
|
||||||
|
#define __set_BASEPRI(VALUE) (__arm_wsr("BASEPRI", (VALUE)))
|
||||||
|
#define __set_BASEPRI_MAX(VALUE) (__arm_wsr("BASEPRI_MAX", (VALUE)))
|
||||||
|
#define __set_CONTROL(VALUE) (__arm_wsr("CONTROL", (VALUE)))
|
||||||
|
#define __set_FAULTMASK(VALUE) (__arm_wsr("FAULTMASK", (VALUE)))
|
||||||
|
#define __set_MSP(VALUE) (__arm_wsr("MSP", (VALUE)))
|
||||||
|
|
||||||
|
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
|
||||||
|
(!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
|
||||||
|
// without main extensions, the non-secure MSPLIM is RAZ/WI
|
||||||
|
#define __set_MSPLIM(VALUE) ((void)(VALUE))
|
||||||
|
#else
|
||||||
|
#define __set_MSPLIM(VALUE) (__arm_wsr("MSPLIM", (VALUE)))
|
||||||
|
#endif
|
||||||
|
#define __set_PRIMASK(VALUE) (__arm_wsr("PRIMASK", (VALUE)))
|
||||||
|
#define __set_PSP(VALUE) (__arm_wsr("PSP", (VALUE)))
|
||||||
|
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
|
||||||
|
(!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
|
||||||
|
// without main extensions, the non-secure PSPLIM is RAZ/WI
|
||||||
|
#define __set_PSPLIM(VALUE) ((void)(VALUE))
|
||||||
|
#else
|
||||||
|
#define __set_PSPLIM(VALUE) (__arm_wsr("PSPLIM", (VALUE)))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __TZ_get_CONTROL_NS() (__arm_rsr("CONTROL_NS"))
|
||||||
|
#define __TZ_set_CONTROL_NS(VALUE) (__arm_wsr("CONTROL_NS", (VALUE)))
|
||||||
|
#define __TZ_get_PSP_NS() (__arm_rsr("PSP_NS"))
|
||||||
|
#define __TZ_set_PSP_NS(VALUE) (__arm_wsr("PSP_NS", (VALUE)))
|
||||||
|
#define __TZ_get_MSP_NS() (__arm_rsr("MSP_NS"))
|
||||||
|
#define __TZ_set_MSP_NS(VALUE) (__arm_wsr("MSP_NS", (VALUE)))
|
||||||
|
#define __TZ_get_SP_NS() (__arm_rsr("SP_NS"))
|
||||||
|
#define __TZ_set_SP_NS(VALUE) (__arm_wsr("SP_NS", (VALUE)))
|
||||||
|
#define __TZ_get_PRIMASK_NS() (__arm_rsr("PRIMASK_NS"))
|
||||||
|
#define __TZ_set_PRIMASK_NS(VALUE) (__arm_wsr("PRIMASK_NS", (VALUE)))
|
||||||
|
#define __TZ_get_BASEPRI_NS() (__arm_rsr("BASEPRI_NS"))
|
||||||
|
#define __TZ_set_BASEPRI_NS(VALUE) (__arm_wsr("BASEPRI_NS", (VALUE)))
|
||||||
|
#define __TZ_get_FAULTMASK_NS() (__arm_rsr("FAULTMASK_NS"))
|
||||||
|
#define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE)))
|
||||||
|
|
||||||
|
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
|
||||||
|
(!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
|
||||||
|
// without main extensions, the non-secure PSPLIM is RAZ/WI
|
||||||
|
#define __TZ_get_PSPLIM_NS() (0U)
|
||||||
|
#define __TZ_set_PSPLIM_NS(VALUE) ((void)(VALUE))
|
||||||
|
#else
|
||||||
|
#define __TZ_get_PSPLIM_NS() (__arm_rsr("PSPLIM_NS"))
|
||||||
|
#define __TZ_set_PSPLIM_NS(VALUE) (__arm_wsr("PSPLIM_NS", (VALUE)))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __TZ_get_MSPLIM_NS() (__arm_rsr("MSPLIM_NS"))
|
||||||
|
#define __TZ_set_MSPLIM_NS(VALUE) (__arm_wsr("MSPLIM_NS", (VALUE)))
|
||||||
|
|
||||||
|
#define __NOP __iar_builtin_no_operation
|
||||||
|
|
||||||
|
#define __CLZ __iar_builtin_CLZ
|
||||||
|
#define __CLREX __iar_builtin_CLREX
|
||||||
|
|
||||||
|
#define __DMB __iar_builtin_DMB
|
||||||
|
#define __DSB __iar_builtin_DSB
|
||||||
|
#define __ISB __iar_builtin_ISB
|
||||||
|
|
||||||
|
#define __LDREXB __iar_builtin_LDREXB
|
||||||
|
#define __LDREXH __iar_builtin_LDREXH
|
||||||
|
#define __LDREXW __iar_builtin_LDREX
|
||||||
|
|
||||||
|
#define __RBIT __iar_builtin_RBIT
|
||||||
|
#define __REV __iar_builtin_REV
|
||||||
|
#define __REV16 __iar_builtin_REV16
|
||||||
|
|
||||||
|
__IAR_FT int16_t __REVSH(int16_t val)
|
||||||
|
{
|
||||||
|
return (int16_t) __iar_builtin_REVSH(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define __ROR __iar_builtin_ROR
|
||||||
|
#define __RRX __iar_builtin_RRX
|
||||||
|
|
||||||
|
#define __SEV __iar_builtin_SEV
|
||||||
|
|
||||||
|
#if !__IAR_M0_FAMILY
|
||||||
|
#define __SSAT __iar_builtin_SSAT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __STREXB __iar_builtin_STREXB
|
||||||
|
#define __STREXH __iar_builtin_STREXH
|
||||||
|
#define __STREXW __iar_builtin_STREX
|
||||||
|
|
||||||
|
#if !__IAR_M0_FAMILY
|
||||||
|
#define __USAT __iar_builtin_USAT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __WFE __iar_builtin_WFE
|
||||||
|
#define __WFI __iar_builtin_WFI
|
||||||
|
|
||||||
|
#if __ARM_MEDIA__
|
||||||
|
#define __SADD8 __iar_builtin_SADD8
|
||||||
|
#define __QADD8 __iar_builtin_QADD8
|
||||||
|
#define __SHADD8 __iar_builtin_SHADD8
|
||||||
|
#define __UADD8 __iar_builtin_UADD8
|
||||||
|
#define __UQADD8 __iar_builtin_UQADD8
|
||||||
|
#define __UHADD8 __iar_builtin_UHADD8
|
||||||
|
#define __SSUB8 __iar_builtin_SSUB8
|
||||||
|
#define __QSUB8 __iar_builtin_QSUB8
|
||||||
|
#define __SHSUB8 __iar_builtin_SHSUB8
|
||||||
|
#define __USUB8 __iar_builtin_USUB8
|
||||||
|
#define __UQSUB8 __iar_builtin_UQSUB8
|
||||||
|
#define __UHSUB8 __iar_builtin_UHSUB8
|
||||||
|
#define __SADD16 __iar_builtin_SADD16
|
||||||
|
#define __QADD16 __iar_builtin_QADD16
|
||||||
|
#define __SHADD16 __iar_builtin_SHADD16
|
||||||
|
#define __UADD16 __iar_builtin_UADD16
|
||||||
|
#define __UQADD16 __iar_builtin_UQADD16
|
||||||
|
#define __UHADD16 __iar_builtin_UHADD16
|
||||||
|
#define __SSUB16 __iar_builtin_SSUB16
|
||||||
|
#define __QSUB16 __iar_builtin_QSUB16
|
||||||
|
#define __SHSUB16 __iar_builtin_SHSUB16
|
||||||
|
#define __USUB16 __iar_builtin_USUB16
|
||||||
|
#define __UQSUB16 __iar_builtin_UQSUB16
|
||||||
|
#define __UHSUB16 __iar_builtin_UHSUB16
|
||||||
|
#define __SASX __iar_builtin_SASX
|
||||||
|
#define __QASX __iar_builtin_QASX
|
||||||
|
#define __SHASX __iar_builtin_SHASX
|
||||||
|
#define __UASX __iar_builtin_UASX
|
||||||
|
#define __UQASX __iar_builtin_UQASX
|
||||||
|
#define __UHASX __iar_builtin_UHASX
|
||||||
|
#define __SSAX __iar_builtin_SSAX
|
||||||
|
#define __QSAX __iar_builtin_QSAX
|
||||||
|
#define __SHSAX __iar_builtin_SHSAX
|
||||||
|
#define __USAX __iar_builtin_USAX
|
||||||
|
#define __UQSAX __iar_builtin_UQSAX
|
||||||
|
#define __UHSAX __iar_builtin_UHSAX
|
||||||
|
#define __USAD8 __iar_builtin_USAD8
|
||||||
|
#define __USADA8 __iar_builtin_USADA8
|
||||||
|
#define __SSAT16 __iar_builtin_SSAT16
|
||||||
|
#define __USAT16 __iar_builtin_USAT16
|
||||||
|
#define __UXTB16 __iar_builtin_UXTB16
|
||||||
|
#define __UXTAB16 __iar_builtin_UXTAB16
|
||||||
|
#define __SXTB16 __iar_builtin_SXTB16
|
||||||
|
#define __SXTAB16 __iar_builtin_SXTAB16
|
||||||
|
#define __SMUAD __iar_builtin_SMUAD
|
||||||
|
#define __SMUADX __iar_builtin_SMUADX
|
||||||
|
#define __SMMLA __iar_builtin_SMMLA
|
||||||
|
#define __SMLAD __iar_builtin_SMLAD
|
||||||
|
#define __SMLADX __iar_builtin_SMLADX
|
||||||
|
#define __SMLALD __iar_builtin_SMLALD
|
||||||
|
#define __SMLALDX __iar_builtin_SMLALDX
|
||||||
|
#define __SMUSD __iar_builtin_SMUSD
|
||||||
|
#define __SMUSDX __iar_builtin_SMUSDX
|
||||||
|
#define __SMLSD __iar_builtin_SMLSD
|
||||||
|
#define __SMLSDX __iar_builtin_SMLSDX
|
||||||
|
#define __SMLSLD __iar_builtin_SMLSLD
|
||||||
|
#define __SMLSLDX __iar_builtin_SMLSLDX
|
||||||
|
#define __SEL __iar_builtin_SEL
|
||||||
|
#define __QADD __iar_builtin_QADD
|
||||||
|
#define __QSUB __iar_builtin_QSUB
|
||||||
|
#define __PKHBT __iar_builtin_PKHBT
|
||||||
|
#define __PKHTB __iar_builtin_PKHTB
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
|
||||||
|
|
||||||
|
#if __IAR_M0_FAMILY
|
||||||
|
/* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
|
||||||
|
#define __CLZ __cmsis_iar_clz_not_active
|
||||||
|
#define __SSAT __cmsis_iar_ssat_not_active
|
||||||
|
#define __USAT __cmsis_iar_usat_not_active
|
||||||
|
#define __RBIT __cmsis_iar_rbit_not_active
|
||||||
|
#define __get_APSR __cmsis_iar_get_APSR_not_active
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||||
|
(defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
|
||||||
|
#define __get_FPSCR __cmsis_iar_get_FPSR_not_active
|
||||||
|
#define __set_FPSCR __cmsis_iar_set_FPSR_not_active
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __INTRINSICS_INCLUDED
|
||||||
|
#error intrinsics.h is already included previously!
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <intrinsics.h>
|
||||||
|
|
||||||
|
#if __IAR_M0_FAMILY
|
||||||
|
/* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
|
||||||
|
#undef __CLZ
|
||||||
|
#undef __SSAT
|
||||||
|
#undef __USAT
|
||||||
|
#undef __RBIT
|
||||||
|
#undef __get_APSR
|
||||||
|
|
||||||
|
__STATIC_INLINE uint8_t __CLZ(uint32_t data)
|
||||||
|
{
|
||||||
|
if (data == 0U) { return 32U; }
|
||||||
|
|
||||||
|
uint32_t count = 0U;
|
||||||
|
uint32_t mask = 0x80000000U;
|
||||||
|
|
||||||
|
while ((data & mask) == 0U)
|
||||||
|
{
|
||||||
|
count += 1U;
|
||||||
|
mask = mask >> 1U;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
__STATIC_INLINE uint32_t __RBIT(uint32_t v)
|
||||||
|
{
|
||||||
|
uint8_t sc = 31U;
|
||||||
|
uint32_t r = v;
|
||||||
|
for (v >>= 1U; v; v >>= 1U)
|
||||||
|
{
|
||||||
|
r <<= 1U;
|
||||||
|
r |= v & 1U;
|
||||||
|
sc--;
|
||||||
|
}
|
||||||
|
return (r << sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
__STATIC_INLINE uint32_t __get_APSR(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__asm("MRS %0,APSR" : "=r" (res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||||
|
(defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
|
||||||
|
#undef __get_FPSCR
|
||||||
|
#undef __set_FPSCR
|
||||||
|
#define __get_FPSCR() (0)
|
||||||
|
#define __set_FPSCR(VALUE) ((void)VALUE)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#pragma diag_suppress=Pe940
|
||||||
|
#pragma diag_suppress=Pe177
|
||||||
|
|
||||||
|
#define __enable_irq __enable_interrupt
|
||||||
|
#define __disable_irq __disable_interrupt
|
||||||
|
#define __NOP __no_operation
|
||||||
|
|
||||||
|
#define __get_xPSR __get_PSR
|
||||||
|
|
||||||
|
#if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0)
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
|
||||||
|
{
|
||||||
|
return __LDREX((unsigned long *)ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
|
||||||
|
{
|
||||||
|
return __STREX(value, (unsigned long *)ptr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
|
||||||
|
#if (__CORTEX_M >= 0x03)
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __RRX(uint32_t value)
|
||||||
|
{
|
||||||
|
uint32_t result;
|
||||||
|
__ASM("RRX %0, %1" : "=r"(result) : "r" (value) : "cc");
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __set_BASEPRI_MAX(uint32_t value)
|
||||||
|
{
|
||||||
|
__asm volatile("MSR BASEPRI_MAX,%0"::"r" (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define __enable_fault_irq __enable_fiq
|
||||||
|
#define __disable_fault_irq __disable_fiq
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* (__CORTEX_M >= 0x03) */
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
|
||||||
|
{
|
||||||
|
return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
|
||||||
|
(defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __get_MSPLIM(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
|
||||||
|
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
|
||||||
|
// without main extensions, the non-secure MSPLIM is RAZ/WI
|
||||||
|
res = 0U;
|
||||||
|
#else
|
||||||
|
__asm volatile("MRS %0,MSPLIM" : "=r" (res));
|
||||||
|
#endif
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __set_MSPLIM(uint32_t value)
|
||||||
|
{
|
||||||
|
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
|
||||||
|
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
|
||||||
|
// without main extensions, the non-secure MSPLIM is RAZ/WI
|
||||||
|
(void)value;
|
||||||
|
#else
|
||||||
|
__asm volatile("MSR MSPLIM,%0" :: "r" (value));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __get_PSPLIM(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
|
||||||
|
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
|
||||||
|
// without main extensions, the non-secure PSPLIM is RAZ/WI
|
||||||
|
res = 0U;
|
||||||
|
#else
|
||||||
|
__asm volatile("MRS %0,PSPLIM" : "=r" (res));
|
||||||
|
#endif
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __set_PSPLIM(uint32_t value)
|
||||||
|
{
|
||||||
|
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
|
||||||
|
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
|
||||||
|
// without main extensions, the non-secure PSPLIM is RAZ/WI
|
||||||
|
(void)value;
|
||||||
|
#else
|
||||||
|
__asm volatile("MSR PSPLIM,%0" :: "r" (value));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __TZ_get_CONTROL_NS(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__asm volatile("MRS %0,CONTROL_NS" : "=r" (res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __TZ_set_CONTROL_NS(uint32_t value)
|
||||||
|
{
|
||||||
|
__asm volatile("MSR CONTROL_NS,%0" :: "r" (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __TZ_get_PSP_NS(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__asm volatile("MRS %0,PSP_NS" : "=r" (res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __TZ_set_PSP_NS(uint32_t value)
|
||||||
|
{
|
||||||
|
__asm volatile("MSR PSP_NS,%0" :: "r" (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __TZ_get_MSP_NS(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__asm volatile("MRS %0,MSP_NS" : "=r" (res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __TZ_set_MSP_NS(uint32_t value)
|
||||||
|
{
|
||||||
|
__asm volatile("MSR MSP_NS,%0" :: "r" (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __TZ_get_SP_NS(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__asm volatile("MRS %0,SP_NS" : "=r" (res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
__IAR_FT void __TZ_set_SP_NS(uint32_t value)
|
||||||
|
{
|
||||||
|
__asm volatile("MSR SP_NS,%0" :: "r" (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __TZ_get_PRIMASK_NS(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__asm volatile("MRS %0,PRIMASK_NS" : "=r" (res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __TZ_set_PRIMASK_NS(uint32_t value)
|
||||||
|
{
|
||||||
|
__asm volatile("MSR PRIMASK_NS,%0" :: "r" (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __TZ_get_BASEPRI_NS(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__asm volatile("MRS %0,BASEPRI_NS" : "=r" (res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __TZ_set_BASEPRI_NS(uint32_t value)
|
||||||
|
{
|
||||||
|
__asm volatile("MSR BASEPRI_NS,%0" :: "r" (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __TZ_get_FAULTMASK_NS(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__asm volatile("MRS %0,FAULTMASK_NS" : "=r" (res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __TZ_set_FAULTMASK_NS(uint32_t value)
|
||||||
|
{
|
||||||
|
__asm volatile("MSR FAULTMASK_NS,%0" :: "r" (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __TZ_get_PSPLIM_NS(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
|
||||||
|
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
|
||||||
|
// without main extensions, the non-secure PSPLIM is RAZ/WI
|
||||||
|
res = 0U;
|
||||||
|
#else
|
||||||
|
__asm volatile("MRS %0,PSPLIM_NS" : "=r" (res));
|
||||||
|
#endif
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __TZ_set_PSPLIM_NS(uint32_t value)
|
||||||
|
{
|
||||||
|
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
|
||||||
|
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
|
||||||
|
// without main extensions, the non-secure PSPLIM is RAZ/WI
|
||||||
|
(void)value;
|
||||||
|
#else
|
||||||
|
__asm volatile("MSR PSPLIM_NS,%0" :: "r" (value));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __TZ_get_MSPLIM_NS(void)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__asm volatile("MRS %0,MSPLIM_NS" : "=r" (res));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __TZ_set_MSPLIM_NS(uint32_t value)
|
||||||
|
{
|
||||||
|
__asm volatile("MSR MSPLIM_NS,%0" :: "r" (value));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
|
||||||
|
|
||||||
|
#endif /* __ICCARM_INTRINSICS_VERSION__ == 2 */
|
||||||
|
|
||||||
|
#define __BKPT(value) __asm volatile ("BKPT %0" : : "i"(value))
|
||||||
|
|
||||||
|
#if __IAR_M0_FAMILY
|
||||||
|
__STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
|
||||||
|
{
|
||||||
|
if ((sat >= 1U) && (sat <= 32U))
|
||||||
|
{
|
||||||
|
const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
|
||||||
|
const int32_t min = -1 - max ;
|
||||||
|
if (val > max)
|
||||||
|
{
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
else if (val < min)
|
||||||
|
{
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
__STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
|
||||||
|
{
|
||||||
|
if (sat <= 31U)
|
||||||
|
{
|
||||||
|
const uint32_t max = ((1U << sat) - 1U);
|
||||||
|
if (val > (int32_t)max)
|
||||||
|
{
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
else if (val < 0)
|
||||||
|
{
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (uint32_t)val;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (__CORTEX_M >= 0x03) /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
|
||||||
|
|
||||||
|
__IAR_FT uint8_t __LDRBT(volatile uint8_t *addr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
|
||||||
|
return ((uint8_t)res);
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint16_t __LDRHT(volatile uint16_t *addr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
|
||||||
|
return ((uint16_t)res);
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __LDRT(volatile uint32_t *addr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr)
|
||||||
|
{
|
||||||
|
__ASM("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr)
|
||||||
|
{
|
||||||
|
__ASM("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr)
|
||||||
|
{
|
||||||
|
__ASM("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* (__CORTEX_M >= 0x03) */
|
||||||
|
|
||||||
|
#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
|
||||||
|
(defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
|
||||||
|
|
||||||
|
|
||||||
|
__IAR_FT uint8_t __LDAB(volatile uint8_t *ptr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
|
||||||
|
return ((uint8_t)res);
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint16_t __LDAH(volatile uint16_t *ptr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
|
||||||
|
return ((uint16_t)res);
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __LDA(volatile uint32_t *ptr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr)
|
||||||
|
{
|
||||||
|
__ASM volatile ("STLB %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr)
|
||||||
|
{
|
||||||
|
__ASM volatile ("STLH %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr)
|
||||||
|
{
|
||||||
|
__ASM volatile ("STL %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
|
||||||
|
return ((uint8_t)res);
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
|
||||||
|
return ((uint16_t)res);
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
__IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
|
||||||
|
{
|
||||||
|
uint32_t res;
|
||||||
|
__ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
|
||||||
|
|
||||||
|
#undef __IAR_FT
|
||||||
|
#undef __IAR_M0_FAMILY
|
||||||
|
#undef __ICCARM_V8
|
||||||
|
|
||||||
|
#pragma diag_default=Pe940
|
||||||
|
#pragma diag_default=Pe177
|
||||||
|
|
||||||
|
#endif /* __CMSIS_ICCARM_H__ */
|
||||||
39
lib/cmsis/inc/cmsis_version.h
Normal file
39
lib/cmsis/inc/cmsis_version.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/**************************************************************************//**
|
||||||
|
* @file cmsis_version.h
|
||||||
|
* @brief CMSIS Core(M) Version definitions
|
||||||
|
* @version V5.0.2
|
||||||
|
* @date 19. April 2017
|
||||||
|
******************************************************************************/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2017 ARM Limited. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ )
|
||||||
|
#pragma system_include /* treat file as system include file for MISRA check */
|
||||||
|
#elif defined (__clang__)
|
||||||
|
#pragma clang system_header /* treat file as system include file */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __CMSIS_VERSION_H
|
||||||
|
#define __CMSIS_VERSION_H
|
||||||
|
|
||||||
|
/* CMSIS Version definitions */
|
||||||
|
#define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */
|
||||||
|
#define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */
|
||||||
|
#define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \
|
||||||
|
__CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */
|
||||||
|
#endif
|
||||||
2967
lib/cmsis/inc/core_armv81mml.h
Normal file
2967
lib/cmsis/inc/core_armv81mml.h
Normal file
File diff suppressed because it is too large
Load Diff
1918
lib/cmsis/inc/core_armv8mbl.h
Normal file
1918
lib/cmsis/inc/core_armv8mbl.h
Normal file
File diff suppressed because it is too large
Load Diff
2832
lib/cmsis/inc/core_armv8mml.h
Normal file
2832
lib/cmsis/inc/core_armv8mml.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,40 +1,30 @@
|
|||||||
/**************************************************************************//**
|
/**************************************************************************//**
|
||||||
* @file core_cm0.h
|
* @file core_cm0.h
|
||||||
* @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File
|
* @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File
|
||||||
* @version V4.30
|
* @version V5.0.6
|
||||||
* @date 20. October 2015
|
* @date 13. March 2019
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
/*
|
||||||
|
* Copyright (c) 2009-2019 Arm Limited. All rights reserved.
|
||||||
All rights reserved.
|
*
|
||||||
Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
modification, are permitted provided that the following conditions are met:
|
*
|
||||||
- Redistributions of source code must retain the above copyright
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
notice, this list of conditions and the following disclaimer.
|
* not use this file except in compliance with the License.
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
* You may obtain a copy of the License at
|
||||||
notice, this list of conditions and the following disclaimer in the
|
*
|
||||||
documentation and/or other materials provided with the distribution.
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
- Neither the name of ARM nor the names of its contributors may be used
|
*
|
||||||
to endorse or promote products derived from this software without
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
specific prior written permission.
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
*
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* See the License for the specific language governing permissions and
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* limitations under the License.
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
*/
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND 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.
|
|
||||||
---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __ICCARM__ )
|
#if defined ( __ICCARM__ )
|
||||||
#pragma system_include /* treat file as system include file for MISRA check */
|
#pragma system_include /* treat file as system include file for MISRA check */
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__clang__)
|
||||||
#pragma clang system_header /* treat file as system include file */
|
#pragma clang system_header /* treat file as system include file */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -70,53 +60,15 @@
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "cmsis_version.h"
|
||||||
|
|
||||||
/* CMSIS CM0 definitions */
|
/* CMSIS CM0 definitions */
|
||||||
#define __CM0_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */
|
#define __CM0_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
|
||||||
#define __CM0_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */
|
#define __CM0_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
|
||||||
#define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16U) | \
|
#define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16U) | \
|
||||||
__CM0_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
|
__CM0_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
|
||||||
|
|
||||||
#define __CORTEX_M (0x00U) /*!< Cortex-M Core */
|
#define __CORTEX_M (0U) /*!< Cortex-M Core */
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __CC_ARM )
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined ( __GNUC__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for GNU Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __ICCARM__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for IAR Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TASKING__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __CSMC__ )
|
|
||||||
#define __packed
|
|
||||||
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error Unknown compiler
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** __FPU_USED indicates whether an FPU is used or not.
|
/** __FPU_USED indicates whether an FPU is used or not.
|
||||||
This core does not support an FPU at all
|
This core does not support an FPU at all
|
||||||
@ -128,8 +80,8 @@
|
|||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||||
#if defined __ARM_PCS_VFP
|
#if defined __ARM_FP
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -143,7 +95,7 @@
|
|||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
#elif defined ( __TI_ARM__ )
|
||||||
#if defined __TI_VFP_SUPPORT__
|
#if defined __TI_VFP_SUPPORT__
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
@ -160,8 +112,8 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "core_cmInstr.h" /* Core Instruction Access */
|
#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
|
||||||
#include "core_cmFunc.h" /* Core Function Access */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@ -364,7 +316,7 @@ typedef struct
|
|||||||
__IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
__IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
||||||
uint32_t RESERVED0[31U];
|
uint32_t RESERVED0[31U];
|
||||||
__IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
__IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
||||||
uint32_t RSERVED1[31U];
|
uint32_t RESERVED1[31U];
|
||||||
__IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
__IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
||||||
uint32_t RESERVED2[31U];
|
uint32_t RESERVED2[31U];
|
||||||
__IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
__IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
||||||
@ -555,18 +507,18 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
\brief Mask and shift a bit field value for use in a register bit range.
|
\brief Mask and shift a bit field value for use in a register bit range.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of the bit field.
|
\param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted value.
|
\return Masked and shifted value.
|
||||||
*/
|
*/
|
||||||
#define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk)
|
#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Mask and shift a register value to extract a bit filed value.
|
\brief Mask and shift a register value to extract a bit filed value.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of register.
|
\param[in] value Value of register. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted bit field value.
|
\return Masked and shifted bit field value.
|
||||||
*/
|
*/
|
||||||
#define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos)
|
#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
|
||||||
|
|
||||||
/*@} end of group CMSIS_core_bitfield */
|
/*@} end of group CMSIS_core_bitfield */
|
||||||
|
|
||||||
@ -578,7 +530,7 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Memory mapping of Cortex-M0 Hardware */
|
/* Memory mapping of Core Hardware */
|
||||||
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
||||||
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
|
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
|
||||||
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
|
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
|
||||||
@ -614,87 +566,177 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Interrupt Priorities are WORD accessible only under ARMv6M */
|
#ifdef CMSIS_NVIC_VIRTUAL
|
||||||
|
#ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
|
||||||
|
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
|
||||||
|
#define NVIC_EnableIRQ __NVIC_EnableIRQ
|
||||||
|
#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
|
||||||
|
#define NVIC_DisableIRQ __NVIC_DisableIRQ
|
||||||
|
#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
|
||||||
|
#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
|
||||||
|
#define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
|
||||||
|
/*#define NVIC_GetActive __NVIC_GetActive not available for Cortex-M0 */
|
||||||
|
#define NVIC_SetPriority __NVIC_SetPriority
|
||||||
|
#define NVIC_GetPriority __NVIC_GetPriority
|
||||||
|
#define NVIC_SystemReset __NVIC_SystemReset
|
||||||
|
#endif /* CMSIS_NVIC_VIRTUAL */
|
||||||
|
|
||||||
|
#ifdef CMSIS_VECTAB_VIRTUAL
|
||||||
|
#ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetVector __NVIC_SetVector
|
||||||
|
#define NVIC_GetVector __NVIC_GetVector
|
||||||
|
#endif /* (CMSIS_VECTAB_VIRTUAL) */
|
||||||
|
|
||||||
|
#define NVIC_USER_IRQ_OFFSET 16
|
||||||
|
|
||||||
|
|
||||||
|
/* The following EXC_RETURN values are saved the LR on exception entry */
|
||||||
|
#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
|
||||||
|
|
||||||
|
|
||||||
|
/* Interrupt Priorities are WORD accessible only under Armv6-M */
|
||||||
/* The following MACROS handle generation of the register offset and byte masks */
|
/* The following MACROS handle generation of the register offset and byte masks */
|
||||||
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
|
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
|
||||||
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
|
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
|
||||||
#define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
|
#define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
|
||||||
|
|
||||||
|
#define __NVIC_SetPriorityGrouping(X) (void)(X)
|
||||||
|
#define __NVIC_GetPriorityGrouping() (0U)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Enable External Interrupt
|
\brief Enable Interrupt
|
||||||
\details Enables a device-specific interrupt in the NVIC interrupt controller.
|
\details Enables a device specific interrupt in the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Disable External Interrupt
|
\brief Get Interrupt Enable status
|
||||||
\details Disables a device-specific interrupt in the NVIC interrupt controller.
|
\details Returns a device specific interrupt enable status from the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\return 0 Interrupt is not enabled.
|
||||||
|
\return 1 Interrupt is enabled.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Disable Interrupt
|
||||||
|
\details Disables a device specific interrupt in the NVIC interrupt controller.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Pending Interrupt
|
\brief Get Pending Interrupt
|
||||||
\details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt.
|
\details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
\return 0 Interrupt status is not pending.
|
\return 0 Interrupt status is not pending.
|
||||||
\return 1 Interrupt status is pending.
|
\return 1 Interrupt status is pending.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Pending Interrupt
|
\brief Set Pending Interrupt
|
||||||
\details Sets the pending bit of an external interrupt.
|
\details Sets the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn Interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Clear Pending Interrupt
|
\brief Clear Pending Interrupt
|
||||||
\details Clears the pending bit of an external interrupt.
|
\details Clears the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Interrupt Priority
|
\brief Set Interrupt Priority
|
||||||
\details Sets the priority of an interrupt.
|
\details Sets the priority of a device specific interrupt or a processor exception.
|
||||||
\note The priority cannot be set for every core interrupt.
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\param [in] priority Priority to set.
|
\param [in] priority Priority to set.
|
||||||
|
\note The priority cannot be set for every processor exception.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
||||||
{
|
{
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
{
|
||||||
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||||
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||||
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -702,24 +744,108 @@ __STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Interrupt Priority
|
\brief Get Interrupt Priority
|
||||||
\details Reads the priority of an interrupt.
|
\details Reads the priority of a device specific interrupt or a processor exception.
|
||||||
The interrupt number can be positive to specify an external (device specific) interrupt,
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
or negative to specify an internal (core) interrupt.
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\return Interrupt Priority.
|
\return Interrupt Priority.
|
||||||
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
|
||||||
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Encode Priority
|
||||||
|
\details Encodes the priority for an interrupt with the given priority group,
|
||||||
|
preemptive priority value, and subpriority value.
|
||||||
|
In case of a conflict between priority grouping and available
|
||||||
|
priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
|
||||||
|
\param [in] PriorityGroup Used priority group.
|
||||||
|
\param [in] PreemptPriority Preemptive priority value (starting from 0).
|
||||||
|
\param [in] SubPriority Subpriority value (starting from 0).
|
||||||
|
\return Encoded priority. Value can be used in the function \ref NVIC_SetPriority().
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
|
||||||
|
{
|
||||||
|
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
||||||
|
uint32_t PreemptPriorityBits;
|
||||||
|
uint32_t SubPriorityBits;
|
||||||
|
|
||||||
|
PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
|
||||||
|
SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
|
||||||
|
|
||||||
|
return (
|
||||||
|
((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) |
|
||||||
|
((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Decode Priority
|
||||||
|
\details Decodes an interrupt priority value with a given priority group to
|
||||||
|
preemptive priority value and subpriority value.
|
||||||
|
In case of a conflict between priority grouping and available
|
||||||
|
priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.
|
||||||
|
\param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority().
|
||||||
|
\param [in] PriorityGroup Used priority group.
|
||||||
|
\param [out] pPreemptPriority Preemptive priority value (starting from 0).
|
||||||
|
\param [out] pSubPriority Subpriority value (starting from 0).
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority)
|
||||||
|
{
|
||||||
|
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
||||||
|
uint32_t PreemptPriorityBits;
|
||||||
|
uint32_t SubPriorityBits;
|
||||||
|
|
||||||
|
PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
|
||||||
|
SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
|
||||||
|
|
||||||
|
*pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL);
|
||||||
|
*pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Set Interrupt Vector
|
||||||
|
\details Sets an interrupt vector in SRAM based interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
Address 0 must be mapped to SRAM.
|
||||||
|
\param [in] IRQn Interrupt number
|
||||||
|
\param [in] vector Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
|
||||||
|
{
|
||||||
|
uint32_t vectors = 0x0U;
|
||||||
|
(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Get Interrupt Vector
|
||||||
|
\details Reads an interrupt vector from interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
\param [in] IRQn Interrupt number.
|
||||||
|
\return Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
uint32_t vectors = 0x0U;
|
||||||
|
return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -727,7 +853,7 @@ __STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
|||||||
\brief System Reset
|
\brief System Reset
|
||||||
\details Initiates a system reset request to reset the MCU.
|
\details Initiates a system reset request to reset the MCU.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SystemReset(void)
|
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
|
||||||
{
|
{
|
||||||
__DSB(); /* Ensure all outstanding memory accesses included
|
__DSB(); /* Ensure all outstanding memory accesses included
|
||||||
buffered write are completed before reset */
|
buffered write are completed before reset */
|
||||||
@ -744,6 +870,31 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
/*@} end of CMSIS_Core_NVICFunctions */
|
/*@} end of CMSIS_Core_NVICFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
/* ########################## FPU functions #################################### */
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_Core_FunctionInterface
|
||||||
|
\defgroup CMSIS_Core_FpuFunctions FPU Functions
|
||||||
|
\brief Function that provides FPU type.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief get FPU type
|
||||||
|
\details returns the FPU type
|
||||||
|
\returns
|
||||||
|
- \b 0: No FPU
|
||||||
|
- \b 1: Single precision FPU
|
||||||
|
- \b 2: Double + Single precision FPU
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t SCB_GetFPUType(void)
|
||||||
|
{
|
||||||
|
return 0U; /* No FPU */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*@} end of CMSIS_Core_FpuFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ################################## SysTick function ############################################ */
|
/* ################################## SysTick function ############################################ */
|
||||||
/**
|
/**
|
||||||
@ -753,7 +904,7 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (__Vendor_SysTickConfig == 0U)
|
#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief System Tick Configuration
|
\brief System Tick Configuration
|
||||||
|
|||||||
@ -1,40 +1,30 @@
|
|||||||
/**************************************************************************//**
|
/**************************************************************************//**
|
||||||
* @file core_cm0plus.h
|
* @file core_cm0plus.h
|
||||||
* @brief CMSIS Cortex-M0+ Core Peripheral Access Layer Header File
|
* @brief CMSIS Cortex-M0+ Core Peripheral Access Layer Header File
|
||||||
* @version V4.30
|
* @version V5.0.7
|
||||||
* @date 20. October 2015
|
* @date 13. March 2019
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
/*
|
||||||
|
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
|
||||||
All rights reserved.
|
*
|
||||||
Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
modification, are permitted provided that the following conditions are met:
|
*
|
||||||
- Redistributions of source code must retain the above copyright
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
notice, this list of conditions and the following disclaimer.
|
* not use this file except in compliance with the License.
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
* You may obtain a copy of the License at
|
||||||
notice, this list of conditions and the following disclaimer in the
|
*
|
||||||
documentation and/or other materials provided with the distribution.
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
- Neither the name of ARM nor the names of its contributors may be used
|
*
|
||||||
to endorse or promote products derived from this software without
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
specific prior written permission.
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
*
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* See the License for the specific language governing permissions and
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* limitations under the License.
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
*/
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND 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.
|
|
||||||
---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __ICCARM__ )
|
#if defined ( __ICCARM__ )
|
||||||
#pragma system_include /* treat file as system include file for MISRA check */
|
#pragma system_include /* treat file as system include file for MISRA check */
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__clang__)
|
||||||
#pragma clang system_header /* treat file as system include file */
|
#pragma clang system_header /* treat file as system include file */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -70,53 +60,15 @@
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "cmsis_version.h"
|
||||||
|
|
||||||
/* CMSIS CM0+ definitions */
|
/* CMSIS CM0+ definitions */
|
||||||
#define __CM0PLUS_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */
|
#define __CM0PLUS_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
|
||||||
#define __CM0PLUS_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */
|
#define __CM0PLUS_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
|
||||||
#define __CM0PLUS_CMSIS_VERSION ((__CM0PLUS_CMSIS_VERSION_MAIN << 16U) | \
|
#define __CM0PLUS_CMSIS_VERSION ((__CM0PLUS_CMSIS_VERSION_MAIN << 16U) | \
|
||||||
__CM0PLUS_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
|
__CM0PLUS_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
|
||||||
|
|
||||||
#define __CORTEX_M (0x00U) /*!< Cortex-M Core */
|
#define __CORTEX_M (0U) /*!< Cortex-M Core */
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __CC_ARM )
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined ( __GNUC__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for GNU Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __ICCARM__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for IAR Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TASKING__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __CSMC__ )
|
|
||||||
#define __packed
|
|
||||||
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error Unknown compiler
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** __FPU_USED indicates whether an FPU is used or not.
|
/** __FPU_USED indicates whether an FPU is used or not.
|
||||||
This core does not support an FPU at all
|
This core does not support an FPU at all
|
||||||
@ -128,8 +80,8 @@
|
|||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||||
#if defined __ARM_PCS_VFP
|
#if defined __ARM_FP
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -143,7 +95,7 @@
|
|||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
#elif defined ( __TI_ARM__ )
|
||||||
#if defined __TI_VFP_SUPPORT__
|
#if defined __TI_VFP_SUPPORT__
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
@ -160,8 +112,8 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "core_cmInstr.h" /* Core Instruction Access */
|
#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
|
||||||
#include "core_cmFunc.h" /* Core Function Access */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@ -378,7 +330,7 @@ typedef struct
|
|||||||
__IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
__IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
||||||
uint32_t RESERVED0[31U];
|
uint32_t RESERVED0[31U];
|
||||||
__IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
__IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
||||||
uint32_t RSERVED1[31U];
|
uint32_t RESERVED1[31U];
|
||||||
__IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
__IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
||||||
uint32_t RESERVED2[31U];
|
uint32_t RESERVED2[31U];
|
||||||
__IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
__IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
||||||
@ -404,7 +356,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
__IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
|
__IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
|
||||||
__IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
|
__IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
|
||||||
#if (__VTOR_PRESENT == 1U)
|
#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
|
||||||
__IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
|
__IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */
|
||||||
#else
|
#else
|
||||||
uint32_t RESERVED0;
|
uint32_t RESERVED0;
|
||||||
@ -461,7 +413,7 @@ typedef struct
|
|||||||
#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */
|
#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */
|
||||||
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
|
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
|
||||||
|
|
||||||
#if (__VTOR_PRESENT == 1U)
|
#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
|
||||||
/* SCB Interrupt Control State Register Definitions */
|
/* SCB Interrupt Control State Register Definitions */
|
||||||
#define SCB_VTOR_TBLOFF_Pos 8U /*!< SCB VTOR: TBLOFF Position */
|
#define SCB_VTOR_TBLOFF_Pos 8U /*!< SCB VTOR: TBLOFF Position */
|
||||||
#define SCB_VTOR_TBLOFF_Msk (0xFFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
|
#define SCB_VTOR_TBLOFF_Msk (0xFFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */
|
||||||
@ -558,7 +510,7 @@ typedef struct
|
|||||||
|
|
||||||
/*@} end of group CMSIS_SysTick */
|
/*@} end of group CMSIS_SysTick */
|
||||||
|
|
||||||
#if (__MPU_PRESENT == 1U)
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
/**
|
/**
|
||||||
\ingroup CMSIS_core_register
|
\ingroup CMSIS_core_register
|
||||||
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
||||||
@ -578,6 +530,8 @@ typedef struct
|
|||||||
__IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
|
__IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */
|
||||||
} MPU_Type;
|
} MPU_Type;
|
||||||
|
|
||||||
|
#define MPU_TYPE_RALIASES 1U
|
||||||
|
|
||||||
/* MPU Type Register Definitions */
|
/* MPU Type Register Definitions */
|
||||||
#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */
|
#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */
|
||||||
#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
|
#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
|
||||||
@ -667,18 +621,18 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
\brief Mask and shift a bit field value for use in a register bit range.
|
\brief Mask and shift a bit field value for use in a register bit range.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of the bit field.
|
\param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted value.
|
\return Masked and shifted value.
|
||||||
*/
|
*/
|
||||||
#define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk)
|
#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Mask and shift a register value to extract a bit filed value.
|
\brief Mask and shift a register value to extract a bit filed value.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of register.
|
\param[in] value Value of register. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted bit field value.
|
\return Masked and shifted bit field value.
|
||||||
*/
|
*/
|
||||||
#define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos)
|
#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
|
||||||
|
|
||||||
/*@} end of group CMSIS_core_bitfield */
|
/*@} end of group CMSIS_core_bitfield */
|
||||||
|
|
||||||
@ -690,7 +644,7 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Memory mapping of Cortex-M0+ Hardware */
|
/* Memory mapping of Core Hardware */
|
||||||
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
||||||
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
|
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
|
||||||
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
|
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
|
||||||
@ -700,7 +654,7 @@ typedef struct
|
|||||||
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
|
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
|
||||||
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
|
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
|
||||||
|
|
||||||
#if (__MPU_PRESENT == 1U)
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
||||||
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
||||||
#endif
|
#endif
|
||||||
@ -730,87 +684,177 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Interrupt Priorities are WORD accessible only under ARMv6M */
|
#ifdef CMSIS_NVIC_VIRTUAL
|
||||||
|
#ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
|
||||||
|
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
|
||||||
|
#define NVIC_EnableIRQ __NVIC_EnableIRQ
|
||||||
|
#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
|
||||||
|
#define NVIC_DisableIRQ __NVIC_DisableIRQ
|
||||||
|
#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
|
||||||
|
#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
|
||||||
|
#define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
|
||||||
|
/*#define NVIC_GetActive __NVIC_GetActive not available for Cortex-M0+ */
|
||||||
|
#define NVIC_SetPriority __NVIC_SetPriority
|
||||||
|
#define NVIC_GetPriority __NVIC_GetPriority
|
||||||
|
#define NVIC_SystemReset __NVIC_SystemReset
|
||||||
|
#endif /* CMSIS_NVIC_VIRTUAL */
|
||||||
|
|
||||||
|
#ifdef CMSIS_VECTAB_VIRTUAL
|
||||||
|
#ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetVector __NVIC_SetVector
|
||||||
|
#define NVIC_GetVector __NVIC_GetVector
|
||||||
|
#endif /* (CMSIS_VECTAB_VIRTUAL) */
|
||||||
|
|
||||||
|
#define NVIC_USER_IRQ_OFFSET 16
|
||||||
|
|
||||||
|
|
||||||
|
/* The following EXC_RETURN values are saved the LR on exception entry */
|
||||||
|
#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
|
||||||
|
|
||||||
|
|
||||||
|
/* Interrupt Priorities are WORD accessible only under Armv6-M */
|
||||||
/* The following MACROS handle generation of the register offset and byte masks */
|
/* The following MACROS handle generation of the register offset and byte masks */
|
||||||
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
|
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
|
||||||
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
|
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
|
||||||
#define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
|
#define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
|
||||||
|
|
||||||
|
#define __NVIC_SetPriorityGrouping(X) (void)(X)
|
||||||
|
#define __NVIC_GetPriorityGrouping() (0U)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Enable External Interrupt
|
\brief Enable Interrupt
|
||||||
\details Enables a device-specific interrupt in the NVIC interrupt controller.
|
\details Enables a device specific interrupt in the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Disable External Interrupt
|
\brief Get Interrupt Enable status
|
||||||
\details Disables a device-specific interrupt in the NVIC interrupt controller.
|
\details Returns a device specific interrupt enable status from the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\return 0 Interrupt is not enabled.
|
||||||
|
\return 1 Interrupt is enabled.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Disable Interrupt
|
||||||
|
\details Disables a device specific interrupt in the NVIC interrupt controller.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Pending Interrupt
|
\brief Get Pending Interrupt
|
||||||
\details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt.
|
\details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
\return 0 Interrupt status is not pending.
|
\return 0 Interrupt status is not pending.
|
||||||
\return 1 Interrupt status is pending.
|
\return 1 Interrupt status is pending.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Pending Interrupt
|
\brief Set Pending Interrupt
|
||||||
\details Sets the pending bit of an external interrupt.
|
\details Sets the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn Interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Clear Pending Interrupt
|
\brief Clear Pending Interrupt
|
||||||
\details Clears the pending bit of an external interrupt.
|
\details Clears the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Interrupt Priority
|
\brief Set Interrupt Priority
|
||||||
\details Sets the priority of an interrupt.
|
\details Sets the priority of a device specific interrupt or a processor exception.
|
||||||
\note The priority cannot be set for every core interrupt.
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\param [in] priority Priority to set.
|
\param [in] priority Priority to set.
|
||||||
|
\note The priority cannot be set for every processor exception.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
||||||
{
|
{
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
{
|
||||||
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||||
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||||
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -818,24 +862,116 @@ __STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Interrupt Priority
|
\brief Get Interrupt Priority
|
||||||
\details Reads the priority of an interrupt.
|
\details Reads the priority of a device specific interrupt or a processor exception.
|
||||||
The interrupt number can be positive to specify an external (device specific) interrupt,
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
or negative to specify an internal (core) interrupt.
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\return Interrupt Priority.
|
\return Interrupt Priority.
|
||||||
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
|
||||||
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Encode Priority
|
||||||
|
\details Encodes the priority for an interrupt with the given priority group,
|
||||||
|
preemptive priority value, and subpriority value.
|
||||||
|
In case of a conflict between priority grouping and available
|
||||||
|
priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
|
||||||
|
\param [in] PriorityGroup Used priority group.
|
||||||
|
\param [in] PreemptPriority Preemptive priority value (starting from 0).
|
||||||
|
\param [in] SubPriority Subpriority value (starting from 0).
|
||||||
|
\return Encoded priority. Value can be used in the function \ref NVIC_SetPriority().
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
|
||||||
|
{
|
||||||
|
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
||||||
|
uint32_t PreemptPriorityBits;
|
||||||
|
uint32_t SubPriorityBits;
|
||||||
|
|
||||||
|
PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
|
||||||
|
SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
|
||||||
|
|
||||||
|
return (
|
||||||
|
((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) |
|
||||||
|
((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Decode Priority
|
||||||
|
\details Decodes an interrupt priority value with a given priority group to
|
||||||
|
preemptive priority value and subpriority value.
|
||||||
|
In case of a conflict between priority grouping and available
|
||||||
|
priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.
|
||||||
|
\param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority().
|
||||||
|
\param [in] PriorityGroup Used priority group.
|
||||||
|
\param [out] pPreemptPriority Preemptive priority value (starting from 0).
|
||||||
|
\param [out] pSubPriority Subpriority value (starting from 0).
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority)
|
||||||
|
{
|
||||||
|
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
||||||
|
uint32_t PreemptPriorityBits;
|
||||||
|
uint32_t SubPriorityBits;
|
||||||
|
|
||||||
|
PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
|
||||||
|
SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
|
||||||
|
|
||||||
|
*pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL);
|
||||||
|
*pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Set Interrupt Vector
|
||||||
|
\details Sets an interrupt vector in SRAM based interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
VTOR must been relocated to SRAM before.
|
||||||
|
If VTOR is not present address 0 must be mapped to SRAM.
|
||||||
|
\param [in] IRQn Interrupt number
|
||||||
|
\param [in] vector Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
|
||||||
|
{
|
||||||
|
#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
|
||||||
|
uint32_t vectors = SCB->VTOR;
|
||||||
|
#else
|
||||||
|
uint32_t vectors = 0x0U;
|
||||||
|
#endif
|
||||||
|
(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Get Interrupt Vector
|
||||||
|
\details Reads an interrupt vector from interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
\param [in] IRQn Interrupt number.
|
||||||
|
\return Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
#if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U)
|
||||||
|
uint32_t vectors = SCB->VTOR;
|
||||||
|
#else
|
||||||
|
uint32_t vectors = 0x0U;
|
||||||
|
#endif
|
||||||
|
return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -843,7 +979,7 @@ __STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
|||||||
\brief System Reset
|
\brief System Reset
|
||||||
\details Initiates a system reset request to reset the MCU.
|
\details Initiates a system reset request to reset the MCU.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SystemReset(void)
|
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
|
||||||
{
|
{
|
||||||
__DSB(); /* Ensure all outstanding memory accesses included
|
__DSB(); /* Ensure all outstanding memory accesses included
|
||||||
buffered write are completed before reset */
|
buffered write are completed before reset */
|
||||||
@ -859,6 +995,38 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
|
|
||||||
/*@} end of CMSIS_Core_NVICFunctions */
|
/*@} end of CMSIS_Core_NVICFunctions */
|
||||||
|
|
||||||
|
/* ########################## MPU functions #################################### */
|
||||||
|
|
||||||
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
|
|
||||||
|
#include "mpu_armv7.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ########################## FPU functions #################################### */
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_Core_FunctionInterface
|
||||||
|
\defgroup CMSIS_Core_FpuFunctions FPU Functions
|
||||||
|
\brief Function that provides FPU type.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief get FPU type
|
||||||
|
\details returns the FPU type
|
||||||
|
\returns
|
||||||
|
- \b 0: No FPU
|
||||||
|
- \b 1: Single precision FPU
|
||||||
|
- \b 2: Double + Single precision FPU
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t SCB_GetFPUType(void)
|
||||||
|
{
|
||||||
|
return 0U; /* No FPU */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*@} end of CMSIS_Core_FpuFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ################################## SysTick function ############################################ */
|
/* ################################## SysTick function ############################################ */
|
||||||
@ -869,7 +1037,7 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (__Vendor_SysTickConfig == 0U)
|
#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief System Tick Configuration
|
\brief System Tick Configuration
|
||||||
|
|||||||
976
lib/cmsis/inc/core_cm1.h
Normal file
976
lib/cmsis/inc/core_cm1.h
Normal file
@ -0,0 +1,976 @@
|
|||||||
|
/**************************************************************************//**
|
||||||
|
* @file core_cm1.h
|
||||||
|
* @brief CMSIS Cortex-M1 Core Peripheral Access Layer Header File
|
||||||
|
* @version V1.0.1
|
||||||
|
* @date 12. November 2018
|
||||||
|
******************************************************************************/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ )
|
||||||
|
#pragma system_include /* treat file as system include file for MISRA check */
|
||||||
|
#elif defined (__clang__)
|
||||||
|
#pragma clang system_header /* treat file as system include file */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __CORE_CM1_H_GENERIC
|
||||||
|
#define __CORE_CM1_H_GENERIC
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
\page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
|
||||||
|
CMSIS violates the following MISRA-C:2004 rules:
|
||||||
|
|
||||||
|
\li Required Rule 8.5, object/function definition in header file.<br>
|
||||||
|
Function definitions in header files are used to allow 'inlining'.
|
||||||
|
|
||||||
|
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
|
||||||
|
Unions are used for effective representation of core registers.
|
||||||
|
|
||||||
|
\li Advisory Rule 19.7, Function-like macro defined.<br>
|
||||||
|
Function-like macros are used to allow more efficient code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* CMSIS definitions
|
||||||
|
******************************************************************************/
|
||||||
|
/**
|
||||||
|
\ingroup Cortex_M1
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cmsis_version.h"
|
||||||
|
|
||||||
|
/* CMSIS CM1 definitions */
|
||||||
|
#define __CM1_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
|
||||||
|
#define __CM1_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
|
||||||
|
#define __CM1_CMSIS_VERSION ((__CM1_CMSIS_VERSION_MAIN << 16U) | \
|
||||||
|
__CM1_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
|
||||||
|
|
||||||
|
#define __CORTEX_M (1U) /*!< Cortex-M Core */
|
||||||
|
|
||||||
|
/** __FPU_USED indicates whether an FPU is used or not.
|
||||||
|
This core does not support an FPU at all
|
||||||
|
*/
|
||||||
|
#define __FPU_USED 0U
|
||||||
|
|
||||||
|
#if defined ( __CC_ARM )
|
||||||
|
#if defined __TARGET_FPU_VFP
|
||||||
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||||
|
#if defined __ARM_FP
|
||||||
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined ( __GNUC__ )
|
||||||
|
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
|
||||||
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined ( __ICCARM__ )
|
||||||
|
#if defined __ARMVFP__
|
||||||
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined ( __TI_ARM__ )
|
||||||
|
#if defined __TI_VFP_SUPPORT__
|
||||||
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined ( __TASKING__ )
|
||||||
|
#if defined __FPU_VFP__
|
||||||
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined ( __CSMC__ )
|
||||||
|
#if ( __CSMC__ & 0x400U)
|
||||||
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __CORE_CM1_H_GENERIC */
|
||||||
|
|
||||||
|
#ifndef __CMSIS_GENERIC
|
||||||
|
|
||||||
|
#ifndef __CORE_CM1_H_DEPENDANT
|
||||||
|
#define __CORE_CM1_H_DEPENDANT
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* check device defines and use defaults */
|
||||||
|
#if defined __CHECK_DEVICE_DEFINES
|
||||||
|
#ifndef __CM1_REV
|
||||||
|
#define __CM1_REV 0x0100U
|
||||||
|
#warning "__CM1_REV not defined in device header file; using default!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __NVIC_PRIO_BITS
|
||||||
|
#define __NVIC_PRIO_BITS 2U
|
||||||
|
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __Vendor_SysTickConfig
|
||||||
|
#define __Vendor_SysTickConfig 0U
|
||||||
|
#warning "__Vendor_SysTickConfig not defined in device header file; using default!"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* IO definitions (access restrictions to peripheral registers) */
|
||||||
|
/**
|
||||||
|
\defgroup CMSIS_glob_defs CMSIS Global Defines
|
||||||
|
|
||||||
|
<strong>IO Type Qualifiers</strong> are used
|
||||||
|
\li to specify the access to peripheral variables.
|
||||||
|
\li for automatic generation of peripheral register debug information.
|
||||||
|
*/
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define __I volatile /*!< Defines 'read only' permissions */
|
||||||
|
#else
|
||||||
|
#define __I volatile const /*!< Defines 'read only' permissions */
|
||||||
|
#endif
|
||||||
|
#define __O volatile /*!< Defines 'write only' permissions */
|
||||||
|
#define __IO volatile /*!< Defines 'read / write' permissions */
|
||||||
|
|
||||||
|
/* following defines should be used for structure members */
|
||||||
|
#define __IM volatile const /*! Defines 'read only' structure member permissions */
|
||||||
|
#define __OM volatile /*! Defines 'write only' structure member permissions */
|
||||||
|
#define __IOM volatile /*! Defines 'read / write' structure member permissions */
|
||||||
|
|
||||||
|
/*@} end of group Cortex_M1 */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Register Abstraction
|
||||||
|
Core Register contain:
|
||||||
|
- Core Register
|
||||||
|
- Core NVIC Register
|
||||||
|
- Core SCB Register
|
||||||
|
- Core SysTick Register
|
||||||
|
******************************************************************************/
|
||||||
|
/**
|
||||||
|
\defgroup CMSIS_core_register Defines and Type Definitions
|
||||||
|
\brief Type definitions and defines for Cortex-M processor based devices.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_core_register
|
||||||
|
\defgroup CMSIS_CORE Status and Control Registers
|
||||||
|
\brief Core Register type definitions.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Union type to access the Application Program Status Register (APSR).
|
||||||
|
*/
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */
|
||||||
|
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
||||||
|
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
||||||
|
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
|
||||||
|
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
|
||||||
|
} b; /*!< Structure used for bit access */
|
||||||
|
uint32_t w; /*!< Type used for word access */
|
||||||
|
} APSR_Type;
|
||||||
|
|
||||||
|
/* APSR Register Definitions */
|
||||||
|
#define APSR_N_Pos 31U /*!< APSR: N Position */
|
||||||
|
#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
|
||||||
|
|
||||||
|
#define APSR_Z_Pos 30U /*!< APSR: Z Position */
|
||||||
|
#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
|
||||||
|
|
||||||
|
#define APSR_C_Pos 29U /*!< APSR: C Position */
|
||||||
|
#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
|
||||||
|
|
||||||
|
#define APSR_V_Pos 28U /*!< APSR: V Position */
|
||||||
|
#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Union type to access the Interrupt Program Status Register (IPSR).
|
||||||
|
*/
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
||||||
|
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
|
||||||
|
} b; /*!< Structure used for bit access */
|
||||||
|
uint32_t w; /*!< Type used for word access */
|
||||||
|
} IPSR_Type;
|
||||||
|
|
||||||
|
/* IPSR Register Definitions */
|
||||||
|
#define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */
|
||||||
|
#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Union type to access the Special-Purpose Program Status Registers (xPSR).
|
||||||
|
*/
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
||||||
|
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
|
||||||
|
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
|
||||||
|
uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */
|
||||||
|
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
||||||
|
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
||||||
|
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
|
||||||
|
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
|
||||||
|
} b; /*!< Structure used for bit access */
|
||||||
|
uint32_t w; /*!< Type used for word access */
|
||||||
|
} xPSR_Type;
|
||||||
|
|
||||||
|
/* xPSR Register Definitions */
|
||||||
|
#define xPSR_N_Pos 31U /*!< xPSR: N Position */
|
||||||
|
#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
|
||||||
|
|
||||||
|
#define xPSR_Z_Pos 30U /*!< xPSR: Z Position */
|
||||||
|
#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
|
||||||
|
|
||||||
|
#define xPSR_C_Pos 29U /*!< xPSR: C Position */
|
||||||
|
#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
|
||||||
|
|
||||||
|
#define xPSR_V_Pos 28U /*!< xPSR: V Position */
|
||||||
|
#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
|
||||||
|
|
||||||
|
#define xPSR_T_Pos 24U /*!< xPSR: T Position */
|
||||||
|
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
|
||||||
|
|
||||||
|
#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
|
||||||
|
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Union type to access the Control Registers (CONTROL).
|
||||||
|
*/
|
||||||
|
typedef union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint32_t _reserved0:1; /*!< bit: 0 Reserved */
|
||||||
|
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
|
||||||
|
uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */
|
||||||
|
} b; /*!< Structure used for bit access */
|
||||||
|
uint32_t w; /*!< Type used for word access */
|
||||||
|
} CONTROL_Type;
|
||||||
|
|
||||||
|
/* CONTROL Register Definitions */
|
||||||
|
#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */
|
||||||
|
#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
|
||||||
|
|
||||||
|
/*@} end of group CMSIS_CORE */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_core_register
|
||||||
|
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
|
||||||
|
\brief Type definitions for the NVIC Registers
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
__IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
||||||
|
uint32_t RESERVED0[31U];
|
||||||
|
__IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
||||||
|
uint32_t RSERVED1[31U];
|
||||||
|
__IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
||||||
|
uint32_t RESERVED2[31U];
|
||||||
|
__IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
||||||
|
uint32_t RESERVED3[31U];
|
||||||
|
uint32_t RESERVED4[64U];
|
||||||
|
__IOM uint32_t IP[8U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
|
||||||
|
} NVIC_Type;
|
||||||
|
|
||||||
|
/*@} end of group CMSIS_NVIC */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_core_register
|
||||||
|
\defgroup CMSIS_SCB System Control Block (SCB)
|
||||||
|
\brief Type definitions for the System Control Block Registers
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Structure type to access the System Control Block (SCB).
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
__IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
|
||||||
|
__IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
|
||||||
|
uint32_t RESERVED0;
|
||||||
|
__IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
|
||||||
|
__IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
|
||||||
|
__IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
|
||||||
|
uint32_t RESERVED1;
|
||||||
|
__IOM uint32_t SHP[2U]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
|
||||||
|
__IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
|
||||||
|
} SCB_Type;
|
||||||
|
|
||||||
|
/* SCB CPUID Register Definitions */
|
||||||
|
#define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */
|
||||||
|
#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
|
||||||
|
|
||||||
|
#define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */
|
||||||
|
#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
|
||||||
|
|
||||||
|
#define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */
|
||||||
|
#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
|
||||||
|
|
||||||
|
#define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */
|
||||||
|
#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
|
||||||
|
|
||||||
|
#define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */
|
||||||
|
#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
|
||||||
|
|
||||||
|
/* SCB Interrupt Control State Register Definitions */
|
||||||
|
#define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */
|
||||||
|
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
|
||||||
|
|
||||||
|
#define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */
|
||||||
|
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
|
||||||
|
|
||||||
|
#define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */
|
||||||
|
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
|
||||||
|
|
||||||
|
#define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */
|
||||||
|
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
|
||||||
|
|
||||||
|
#define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */
|
||||||
|
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
|
||||||
|
|
||||||
|
#define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */
|
||||||
|
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
|
||||||
|
|
||||||
|
#define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */
|
||||||
|
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
|
||||||
|
|
||||||
|
#define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */
|
||||||
|
#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
|
||||||
|
|
||||||
|
#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */
|
||||||
|
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
|
||||||
|
|
||||||
|
/* SCB Application Interrupt and Reset Control Register Definitions */
|
||||||
|
#define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */
|
||||||
|
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
|
||||||
|
|
||||||
|
#define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */
|
||||||
|
#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
|
||||||
|
|
||||||
|
#define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */
|
||||||
|
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
|
||||||
|
|
||||||
|
#define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */
|
||||||
|
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
|
||||||
|
|
||||||
|
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */
|
||||||
|
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
|
||||||
|
|
||||||
|
/* SCB System Control Register Definitions */
|
||||||
|
#define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */
|
||||||
|
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
|
||||||
|
|
||||||
|
#define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */
|
||||||
|
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
|
||||||
|
|
||||||
|
#define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */
|
||||||
|
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
|
||||||
|
|
||||||
|
/* SCB Configuration Control Register Definitions */
|
||||||
|
#define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */
|
||||||
|
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
|
||||||
|
|
||||||
|
#define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */
|
||||||
|
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
|
||||||
|
|
||||||
|
/* SCB System Handler Control and State Register Definitions */
|
||||||
|
#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */
|
||||||
|
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
|
||||||
|
|
||||||
|
/*@} end of group CMSIS_SCB */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_core_register
|
||||||
|
\defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB)
|
||||||
|
\brief Type definitions for the System Control and ID Register not in the SCB
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Structure type to access the System Control and ID Register not in the SCB.
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t RESERVED0[2U];
|
||||||
|
__IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */
|
||||||
|
} SCnSCB_Type;
|
||||||
|
|
||||||
|
/* Auxiliary Control Register Definitions */
|
||||||
|
#define SCnSCB_ACTLR_ITCMUAEN_Pos 4U /*!< ACTLR: Instruction TCM Upper Alias Enable Position */
|
||||||
|
#define SCnSCB_ACTLR_ITCMUAEN_Msk (1UL << SCnSCB_ACTLR_ITCMUAEN_Pos) /*!< ACTLR: Instruction TCM Upper Alias Enable Mask */
|
||||||
|
|
||||||
|
#define SCnSCB_ACTLR_ITCMLAEN_Pos 3U /*!< ACTLR: Instruction TCM Lower Alias Enable Position */
|
||||||
|
#define SCnSCB_ACTLR_ITCMLAEN_Msk (1UL << SCnSCB_ACTLR_ITCMLAEN_Pos) /*!< ACTLR: Instruction TCM Lower Alias Enable Mask */
|
||||||
|
|
||||||
|
/*@} end of group CMSIS_SCnotSCB */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_core_register
|
||||||
|
\defgroup CMSIS_SysTick System Tick Timer (SysTick)
|
||||||
|
\brief Type definitions for the System Timer Registers.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Structure type to access the System Timer (SysTick).
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
__IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
|
||||||
|
__IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
|
||||||
|
__IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
|
||||||
|
__IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
|
||||||
|
} SysTick_Type;
|
||||||
|
|
||||||
|
/* SysTick Control / Status Register Definitions */
|
||||||
|
#define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */
|
||||||
|
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
|
||||||
|
|
||||||
|
#define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */
|
||||||
|
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
|
||||||
|
|
||||||
|
#define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */
|
||||||
|
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
|
||||||
|
|
||||||
|
#define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */
|
||||||
|
#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */
|
||||||
|
|
||||||
|
/* SysTick Reload Register Definitions */
|
||||||
|
#define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */
|
||||||
|
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */
|
||||||
|
|
||||||
|
/* SysTick Current Register Definitions */
|
||||||
|
#define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */
|
||||||
|
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */
|
||||||
|
|
||||||
|
/* SysTick Calibration Register Definitions */
|
||||||
|
#define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */
|
||||||
|
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
|
||||||
|
|
||||||
|
#define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */
|
||||||
|
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
|
||||||
|
|
||||||
|
#define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */
|
||||||
|
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */
|
||||||
|
|
||||||
|
/*@} end of group CMSIS_SysTick */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_core_register
|
||||||
|
\defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
|
||||||
|
\brief Cortex-M1 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor.
|
||||||
|
Therefore they are not covered by the Cortex-M1 header file.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
/*@} end of group CMSIS_CoreDebug */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_core_register
|
||||||
|
\defgroup CMSIS_core_bitfield Core register bit field macros
|
||||||
|
\brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Mask and shift a bit field value for use in a register bit range.
|
||||||
|
\param[in] field Name of the register bit field.
|
||||||
|
\param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
|
||||||
|
\return Masked and shifted value.
|
||||||
|
*/
|
||||||
|
#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Mask and shift a register value to extract a bit filed value.
|
||||||
|
\param[in] field Name of the register bit field.
|
||||||
|
\param[in] value Value of register. This parameter is interpreted as an uint32_t type.
|
||||||
|
\return Masked and shifted bit field value.
|
||||||
|
*/
|
||||||
|
#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
|
||||||
|
|
||||||
|
/*@} end of group CMSIS_core_bitfield */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_core_register
|
||||||
|
\defgroup CMSIS_core_base Core Definitions
|
||||||
|
\brief Definitions for base addresses, unions, and structures.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Memory mapping of Core Hardware */
|
||||||
|
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
||||||
|
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
|
||||||
|
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
|
||||||
|
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
|
||||||
|
|
||||||
|
#define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */
|
||||||
|
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
|
||||||
|
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
|
||||||
|
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
|
||||||
|
|
||||||
|
|
||||||
|
/*@} */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Hardware Abstraction Layer
|
||||||
|
Core Function Interface contains:
|
||||||
|
- Core NVIC Functions
|
||||||
|
- Core SysTick Functions
|
||||||
|
- Core Register Access Functions
|
||||||
|
******************************************************************************/
|
||||||
|
/**
|
||||||
|
\defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ########################## NVIC functions #################################### */
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_Core_FunctionInterface
|
||||||
|
\defgroup CMSIS_Core_NVICFunctions NVIC Functions
|
||||||
|
\brief Functions that manage interrupts and exceptions via the NVIC.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef CMSIS_NVIC_VIRTUAL
|
||||||
|
#ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
|
||||||
|
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
|
||||||
|
#define NVIC_EnableIRQ __NVIC_EnableIRQ
|
||||||
|
#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
|
||||||
|
#define NVIC_DisableIRQ __NVIC_DisableIRQ
|
||||||
|
#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
|
||||||
|
#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
|
||||||
|
#define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
|
||||||
|
/*#define NVIC_GetActive __NVIC_GetActive not available for Cortex-M1 */
|
||||||
|
#define NVIC_SetPriority __NVIC_SetPriority
|
||||||
|
#define NVIC_GetPriority __NVIC_GetPriority
|
||||||
|
#define NVIC_SystemReset __NVIC_SystemReset
|
||||||
|
#endif /* CMSIS_NVIC_VIRTUAL */
|
||||||
|
|
||||||
|
#ifdef CMSIS_VECTAB_VIRTUAL
|
||||||
|
#ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetVector __NVIC_SetVector
|
||||||
|
#define NVIC_GetVector __NVIC_GetVector
|
||||||
|
#endif /* (CMSIS_VECTAB_VIRTUAL) */
|
||||||
|
|
||||||
|
#define NVIC_USER_IRQ_OFFSET 16
|
||||||
|
|
||||||
|
|
||||||
|
/* The following EXC_RETURN values are saved the LR on exception entry */
|
||||||
|
#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
|
||||||
|
|
||||||
|
|
||||||
|
/* Interrupt Priorities are WORD accessible only under Armv6-M */
|
||||||
|
/* The following MACROS handle generation of the register offset and byte masks */
|
||||||
|
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
|
||||||
|
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
|
||||||
|
#define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
|
||||||
|
|
||||||
|
#define __NVIC_SetPriorityGrouping(X) (void)(X)
|
||||||
|
#define __NVIC_GetPriorityGrouping() (0U)
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Enable Interrupt
|
||||||
|
\details Enables a device specific interrupt in the NVIC interrupt controller.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Get Interrupt Enable status
|
||||||
|
\details Returns a device specific interrupt enable status from the NVIC interrupt controller.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\return 0 Interrupt is not enabled.
|
||||||
|
\return 1 Interrupt is enabled.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Disable Interrupt
|
||||||
|
\details Disables a device specific interrupt in the NVIC interrupt controller.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Get Pending Interrupt
|
||||||
|
\details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\return 0 Interrupt status is not pending.
|
||||||
|
\return 1 Interrupt status is pending.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Set Pending Interrupt
|
||||||
|
\details Sets the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Clear Pending Interrupt
|
||||||
|
\details Clears the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Set Interrupt Priority
|
||||||
|
\details Sets the priority of a device specific interrupt or a processor exception.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
\param [in] IRQn Interrupt number.
|
||||||
|
\param [in] priority Priority to set.
|
||||||
|
\note The priority cannot be set for every processor exception.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||||
|
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||||
|
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Get Interrupt Priority
|
||||||
|
\details Reads the priority of a device specific interrupt or a processor exception.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
\param [in] IRQn Interrupt number.
|
||||||
|
\return Interrupt Priority.
|
||||||
|
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Encode Priority
|
||||||
|
\details Encodes the priority for an interrupt with the given priority group,
|
||||||
|
preemptive priority value, and subpriority value.
|
||||||
|
In case of a conflict between priority grouping and available
|
||||||
|
priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
|
||||||
|
\param [in] PriorityGroup Used priority group.
|
||||||
|
\param [in] PreemptPriority Preemptive priority value (starting from 0).
|
||||||
|
\param [in] SubPriority Subpriority value (starting from 0).
|
||||||
|
\return Encoded priority. Value can be used in the function \ref NVIC_SetPriority().
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
|
||||||
|
{
|
||||||
|
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
||||||
|
uint32_t PreemptPriorityBits;
|
||||||
|
uint32_t SubPriorityBits;
|
||||||
|
|
||||||
|
PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
|
||||||
|
SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
|
||||||
|
|
||||||
|
return (
|
||||||
|
((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) |
|
||||||
|
((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL)))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Decode Priority
|
||||||
|
\details Decodes an interrupt priority value with a given priority group to
|
||||||
|
preemptive priority value and subpriority value.
|
||||||
|
In case of a conflict between priority grouping and available
|
||||||
|
priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.
|
||||||
|
\param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority().
|
||||||
|
\param [in] PriorityGroup Used priority group.
|
||||||
|
\param [out] pPreemptPriority Preemptive priority value (starting from 0).
|
||||||
|
\param [out] pSubPriority Subpriority value (starting from 0).
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority)
|
||||||
|
{
|
||||||
|
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
||||||
|
uint32_t PreemptPriorityBits;
|
||||||
|
uint32_t SubPriorityBits;
|
||||||
|
|
||||||
|
PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
|
||||||
|
SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
|
||||||
|
|
||||||
|
*pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL);
|
||||||
|
*pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Set Interrupt Vector
|
||||||
|
\details Sets an interrupt vector in SRAM based interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
Address 0 must be mapped to SRAM.
|
||||||
|
\param [in] IRQn Interrupt number
|
||||||
|
\param [in] vector Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
|
||||||
|
{
|
||||||
|
uint32_t *vectors = (uint32_t *)0x0U;
|
||||||
|
vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Get Interrupt Vector
|
||||||
|
\details Reads an interrupt vector from interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
\param [in] IRQn Interrupt number.
|
||||||
|
\return Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
uint32_t *vectors = (uint32_t *)0x0U;
|
||||||
|
return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief System Reset
|
||||||
|
\details Initiates a system reset request to reset the MCU.
|
||||||
|
*/
|
||||||
|
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
|
||||||
|
{
|
||||||
|
__DSB(); /* Ensure all outstanding memory accesses included
|
||||||
|
buffered write are completed before reset */
|
||||||
|
SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
|
||||||
|
SCB_AIRCR_SYSRESETREQ_Msk);
|
||||||
|
__DSB(); /* Ensure completion of memory access */
|
||||||
|
|
||||||
|
for(;;) /* wait until reset */
|
||||||
|
{
|
||||||
|
__NOP();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@} end of CMSIS_Core_NVICFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
/* ########################## FPU functions #################################### */
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_Core_FunctionInterface
|
||||||
|
\defgroup CMSIS_Core_FpuFunctions FPU Functions
|
||||||
|
\brief Function that provides FPU type.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief get FPU type
|
||||||
|
\details returns the FPU type
|
||||||
|
\returns
|
||||||
|
- \b 0: No FPU
|
||||||
|
- \b 1: Single precision FPU
|
||||||
|
- \b 2: Double + Single precision FPU
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t SCB_GetFPUType(void)
|
||||||
|
{
|
||||||
|
return 0U; /* No FPU */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*@} end of CMSIS_Core_FpuFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ################################## SysTick function ############################################ */
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_Core_FunctionInterface
|
||||||
|
\defgroup CMSIS_Core_SysTickFunctions SysTick Functions
|
||||||
|
\brief Functions that configure the System.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief System Tick Configuration
|
||||||
|
\details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
|
||||||
|
Counter is in free running mode to generate periodic interrupts.
|
||||||
|
\param [in] ticks Number of ticks between two interrupts.
|
||||||
|
\return 0 Function succeeded.
|
||||||
|
\return 1 Function failed.
|
||||||
|
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
|
||||||
|
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
|
||||||
|
must contain a vendor-specific implementation of this function.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
|
||||||
|
{
|
||||||
|
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
|
||||||
|
{
|
||||||
|
return (1UL); /* Reload value impossible */
|
||||||
|
}
|
||||||
|
|
||||||
|
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
|
||||||
|
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
|
||||||
|
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||||
|
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||||
|
SysTick_CTRL_TICKINT_Msk |
|
||||||
|
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
|
||||||
|
return (0UL); /* Function successful */
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*@} end of CMSIS_Core_SysTickFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __CORE_CM1_H_DEPENDANT */
|
||||||
|
|
||||||
|
#endif /* __CMSIS_GENERIC */
|
||||||
1993
lib/cmsis/inc/core_cm23.h
Normal file
1993
lib/cmsis/inc/core_cm23.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,40 +1,30 @@
|
|||||||
/**************************************************************************//**
|
/**************************************************************************//**
|
||||||
* @file core_cm3.h
|
* @file core_cm3.h
|
||||||
* @brief CMSIS Cortex-M3 Core Peripheral Access Layer Header File
|
* @brief CMSIS Cortex-M3 Core Peripheral Access Layer Header File
|
||||||
* @version V4.30
|
* @version V5.1.0
|
||||||
* @date 20. October 2015
|
* @date 13. March 2019
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
/*
|
||||||
|
* Copyright (c) 2009-2019 Arm Limited. All rights reserved.
|
||||||
All rights reserved.
|
*
|
||||||
Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
modification, are permitted provided that the following conditions are met:
|
*
|
||||||
- Redistributions of source code must retain the above copyright
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
notice, this list of conditions and the following disclaimer.
|
* not use this file except in compliance with the License.
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
* You may obtain a copy of the License at
|
||||||
notice, this list of conditions and the following disclaimer in the
|
*
|
||||||
documentation and/or other materials provided with the distribution.
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
- Neither the name of ARM nor the names of its contributors may be used
|
*
|
||||||
to endorse or promote products derived from this software without
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
specific prior written permission.
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
*
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* See the License for the specific language governing permissions and
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* limitations under the License.
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
*/
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND 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.
|
|
||||||
---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __ICCARM__ )
|
#if defined ( __ICCARM__ )
|
||||||
#pragma system_include /* treat file as system include file for MISRA check */
|
#pragma system_include /* treat file as system include file for MISRA check */
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__clang__)
|
||||||
#pragma clang system_header /* treat file as system include file */
|
#pragma clang system_header /* treat file as system include file */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -70,53 +60,15 @@
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "cmsis_version.h"
|
||||||
|
|
||||||
/* CMSIS CM3 definitions */
|
/* CMSIS CM3 definitions */
|
||||||
#define __CM3_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */
|
#define __CM3_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
|
||||||
#define __CM3_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */
|
#define __CM3_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
|
||||||
#define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16U) | \
|
#define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16U) | \
|
||||||
__CM3_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
|
__CM3_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
|
||||||
|
|
||||||
#define __CORTEX_M (0x03U) /*!< Cortex-M Core */
|
#define __CORTEX_M (3U) /*!< Cortex-M Core */
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __CC_ARM )
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined ( __GNUC__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for GNU Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __ICCARM__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for IAR Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TASKING__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __CSMC__ )
|
|
||||||
#define __packed
|
|
||||||
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error Unknown compiler
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** __FPU_USED indicates whether an FPU is used or not.
|
/** __FPU_USED indicates whether an FPU is used or not.
|
||||||
This core does not support an FPU at all
|
This core does not support an FPU at all
|
||||||
@ -128,8 +80,8 @@
|
|||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||||
#if defined __ARM_PCS_VFP
|
#if defined __ARM_FP
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -143,7 +95,7 @@
|
|||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
#elif defined ( __TI_ARM__ )
|
||||||
#if defined __TI_VFP_SUPPORT__
|
#if defined __TI_VFP_SUPPORT__
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
@ -160,8 +112,8 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "core_cmInstr.h" /* Core Instruction Access */
|
#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
|
||||||
#include "core_cmFunc.h" /* Core Function Access */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@ -191,7 +143,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __NVIC_PRIO_BITS
|
#ifndef __NVIC_PRIO_BITS
|
||||||
#define __NVIC_PRIO_BITS 4U
|
#define __NVIC_PRIO_BITS 3U
|
||||||
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
|
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -308,9 +260,11 @@ typedef union
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
||||||
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
|
uint32_t _reserved0:1; /*!< bit: 9 Reserved */
|
||||||
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
|
uint32_t ICI_IT_1:6; /*!< bit: 10..15 ICI/IT part 1 */
|
||||||
uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
|
uint32_t _reserved1:8; /*!< bit: 16..23 Reserved */
|
||||||
|
uint32_t T:1; /*!< bit: 24 Thumb bit */
|
||||||
|
uint32_t ICI_IT_2:2; /*!< bit: 25..26 ICI/IT part 2 */
|
||||||
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
|
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
|
||||||
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
||||||
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
||||||
@ -336,12 +290,15 @@ typedef union
|
|||||||
#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */
|
#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */
|
||||||
#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */
|
#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */
|
||||||
|
|
||||||
#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */
|
#define xPSR_ICI_IT_2_Pos 25U /*!< xPSR: ICI/IT part 2 Position */
|
||||||
#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT Mask */
|
#define xPSR_ICI_IT_2_Msk (3UL << xPSR_ICI_IT_2_Pos) /*!< xPSR: ICI/IT part 2 Mask */
|
||||||
|
|
||||||
#define xPSR_T_Pos 24U /*!< xPSR: T Position */
|
#define xPSR_T_Pos 24U /*!< xPSR: T Position */
|
||||||
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
|
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
|
||||||
|
|
||||||
|
#define xPSR_ICI_IT_1_Pos 10U /*!< xPSR: ICI/IT part 1 Position */
|
||||||
|
#define xPSR_ICI_IT_1_Msk (0x3FUL << xPSR_ICI_IT_1_Pos) /*!< xPSR: ICI/IT part 1 Mask */
|
||||||
|
|
||||||
#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
|
#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
|
||||||
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
|
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
|
||||||
|
|
||||||
@ -385,7 +342,7 @@ typedef struct
|
|||||||
__IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
__IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
||||||
uint32_t RESERVED0[24U];
|
uint32_t RESERVED0[24U];
|
||||||
__IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
__IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
||||||
uint32_t RSERVED1[24U];
|
uint32_t RESERVED1[24U];
|
||||||
__IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
__IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
||||||
uint32_t RESERVED2[24U];
|
uint32_t RESERVED2[24U];
|
||||||
__IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
__IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
||||||
@ -487,7 +444,7 @@ typedef struct
|
|||||||
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
|
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
|
||||||
|
|
||||||
/* SCB Vector Table Offset Register Definitions */
|
/* SCB Vector Table Offset Register Definitions */
|
||||||
#if (__CM3_REV < 0x0201U) /* core r2p1 */
|
#if defined (__CM3_REV) && (__CM3_REV < 0x0201U) /* core r2p1 */
|
||||||
#define SCB_VTOR_TBLBASE_Pos 29U /*!< SCB VTOR: TBLBASE Position */
|
#define SCB_VTOR_TBLBASE_Pos 29U /*!< SCB VTOR: TBLBASE Position */
|
||||||
#define SCB_VTOR_TBLBASE_Msk (1UL << SCB_VTOR_TBLBASE_Pos) /*!< SCB VTOR: TBLBASE Mask */
|
#define SCB_VTOR_TBLBASE_Msk (1UL << SCB_VTOR_TBLBASE_Pos) /*!< SCB VTOR: TBLBASE Mask */
|
||||||
|
|
||||||
@ -602,6 +559,60 @@ typedef struct
|
|||||||
#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */
|
#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */
|
||||||
#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
|
#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
|
||||||
|
|
||||||
|
/* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */
|
||||||
|
#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */
|
||||||
|
#define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */
|
||||||
|
#define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */
|
||||||
|
#define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */
|
||||||
|
#define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */
|
||||||
|
#define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */
|
||||||
|
|
||||||
|
/* BusFault Status Register (part of SCB Configurable Fault Status Register) */
|
||||||
|
#define SCB_CFSR_BFARVALID_Pos (SCB_CFSR_BUSFAULTSR_Pos + 7U) /*!< SCB CFSR (BFSR): BFARVALID Position */
|
||||||
|
#define SCB_CFSR_BFARVALID_Msk (1UL << SCB_CFSR_BFARVALID_Pos) /*!< SCB CFSR (BFSR): BFARVALID Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_STKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 4U) /*!< SCB CFSR (BFSR): STKERR Position */
|
||||||
|
#define SCB_CFSR_STKERR_Msk (1UL << SCB_CFSR_STKERR_Pos) /*!< SCB CFSR (BFSR): STKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_UNSTKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 3U) /*!< SCB CFSR (BFSR): UNSTKERR Position */
|
||||||
|
#define SCB_CFSR_UNSTKERR_Msk (1UL << SCB_CFSR_UNSTKERR_Pos) /*!< SCB CFSR (BFSR): UNSTKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_IMPRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 2U) /*!< SCB CFSR (BFSR): IMPRECISERR Position */
|
||||||
|
#define SCB_CFSR_IMPRECISERR_Msk (1UL << SCB_CFSR_IMPRECISERR_Pos) /*!< SCB CFSR (BFSR): IMPRECISERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_PRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 1U) /*!< SCB CFSR (BFSR): PRECISERR Position */
|
||||||
|
#define SCB_CFSR_PRECISERR_Msk (1UL << SCB_CFSR_PRECISERR_Pos) /*!< SCB CFSR (BFSR): PRECISERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_IBUSERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 0U) /*!< SCB CFSR (BFSR): IBUSERR Position */
|
||||||
|
#define SCB_CFSR_IBUSERR_Msk (1UL << SCB_CFSR_IBUSERR_Pos) /*!< SCB CFSR (BFSR): IBUSERR Mask */
|
||||||
|
|
||||||
|
/* UsageFault Status Register (part of SCB Configurable Fault Status Register) */
|
||||||
|
#define SCB_CFSR_DIVBYZERO_Pos (SCB_CFSR_USGFAULTSR_Pos + 9U) /*!< SCB CFSR (UFSR): DIVBYZERO Position */
|
||||||
|
#define SCB_CFSR_DIVBYZERO_Msk (1UL << SCB_CFSR_DIVBYZERO_Pos) /*!< SCB CFSR (UFSR): DIVBYZERO Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_UNALIGNED_Pos (SCB_CFSR_USGFAULTSR_Pos + 8U) /*!< SCB CFSR (UFSR): UNALIGNED Position */
|
||||||
|
#define SCB_CFSR_UNALIGNED_Msk (1UL << SCB_CFSR_UNALIGNED_Pos) /*!< SCB CFSR (UFSR): UNALIGNED Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_NOCP_Pos (SCB_CFSR_USGFAULTSR_Pos + 3U) /*!< SCB CFSR (UFSR): NOCP Position */
|
||||||
|
#define SCB_CFSR_NOCP_Msk (1UL << SCB_CFSR_NOCP_Pos) /*!< SCB CFSR (UFSR): NOCP Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_INVPC_Pos (SCB_CFSR_USGFAULTSR_Pos + 2U) /*!< SCB CFSR (UFSR): INVPC Position */
|
||||||
|
#define SCB_CFSR_INVPC_Msk (1UL << SCB_CFSR_INVPC_Pos) /*!< SCB CFSR (UFSR): INVPC Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_INVSTATE_Pos (SCB_CFSR_USGFAULTSR_Pos + 1U) /*!< SCB CFSR (UFSR): INVSTATE Position */
|
||||||
|
#define SCB_CFSR_INVSTATE_Msk (1UL << SCB_CFSR_INVSTATE_Pos) /*!< SCB CFSR (UFSR): INVSTATE Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_UNDEFINSTR_Pos (SCB_CFSR_USGFAULTSR_Pos + 0U) /*!< SCB CFSR (UFSR): UNDEFINSTR Position */
|
||||||
|
#define SCB_CFSR_UNDEFINSTR_Msk (1UL << SCB_CFSR_UNDEFINSTR_Pos) /*!< SCB CFSR (UFSR): UNDEFINSTR Mask */
|
||||||
|
|
||||||
/* SCB Hard Fault Status Register Definitions */
|
/* SCB Hard Fault Status Register Definitions */
|
||||||
#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */
|
#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */
|
||||||
#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
|
#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
|
||||||
@ -645,7 +656,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
uint32_t RESERVED0[1U];
|
uint32_t RESERVED0[1U];
|
||||||
__IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */
|
__IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */
|
||||||
#if ((defined __CM3_REV) && (__CM3_REV >= 0x200U))
|
#if defined (__CM3_REV) && (__CM3_REV >= 0x200U)
|
||||||
__IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */
|
__IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */
|
||||||
#else
|
#else
|
||||||
uint32_t RESERVED1[1U];
|
uint32_t RESERVED1[1U];
|
||||||
@ -657,6 +668,12 @@ typedef struct
|
|||||||
#define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */
|
#define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */
|
||||||
|
|
||||||
/* Auxiliary Control Register Definitions */
|
/* Auxiliary Control Register Definitions */
|
||||||
|
#if defined (__CM3_REV) && (__CM3_REV >= 0x200U)
|
||||||
|
#define SCnSCB_ACTLR_DISOOFP_Pos 9U /*!< ACTLR: DISOOFP Position */
|
||||||
|
#define SCnSCB_ACTLR_DISOOFP_Msk (1UL << SCnSCB_ACTLR_DISOOFP_Pos) /*!< ACTLR: DISOOFP Mask */
|
||||||
|
|
||||||
|
#define SCnSCB_ACTLR_DISFPCA_Pos 8U /*!< ACTLR: DISFPCA Position */
|
||||||
|
#define SCnSCB_ACTLR_DISFPCA_Msk (1UL << SCnSCB_ACTLR_DISFPCA_Pos) /*!< ACTLR: DISFPCA Mask */
|
||||||
|
|
||||||
#define SCnSCB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */
|
#define SCnSCB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */
|
||||||
#define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */
|
#define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */
|
||||||
@ -666,6 +683,7 @@ typedef struct
|
|||||||
|
|
||||||
#define SCnSCB_ACTLR_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */
|
#define SCnSCB_ACTLR_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */
|
||||||
#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT Mask */
|
#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT Mask */
|
||||||
|
#endif
|
||||||
|
|
||||||
/*@} end of group CMSIS_SCnotSCB */
|
/*@} end of group CMSIS_SCnotSCB */
|
||||||
|
|
||||||
@ -746,10 +764,7 @@ typedef struct
|
|||||||
__IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */
|
__IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */
|
||||||
uint32_t RESERVED2[15U];
|
uint32_t RESERVED2[15U];
|
||||||
__IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */
|
__IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */
|
||||||
uint32_t RESERVED3[29U];
|
uint32_t RESERVED3[32U];
|
||||||
__OM uint32_t IWR; /*!< Offset: 0xEF8 ( /W) ITM Integration Write Register */
|
|
||||||
__IM uint32_t IRR; /*!< Offset: 0xEFC (R/ ) ITM Integration Read Register */
|
|
||||||
__IOM uint32_t IMCR; /*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register */
|
|
||||||
uint32_t RESERVED4[43U];
|
uint32_t RESERVED4[43U];
|
||||||
__OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */
|
__OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */
|
||||||
__IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */
|
__IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */
|
||||||
@ -770,7 +785,7 @@ typedef struct
|
|||||||
|
|
||||||
/* ITM Trace Privilege Register Definitions */
|
/* ITM Trace Privilege Register Definitions */
|
||||||
#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */
|
#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */
|
||||||
#define ITM_TPR_PRIVMASK_Msk (0xFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */
|
#define ITM_TPR_PRIVMASK_Msk (0xFFFFFFFFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */
|
||||||
|
|
||||||
/* ITM Trace Control Register Definitions */
|
/* ITM Trace Control Register Definitions */
|
||||||
#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */
|
#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */
|
||||||
@ -800,18 +815,6 @@ typedef struct
|
|||||||
#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */
|
#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */
|
||||||
#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */
|
#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */
|
||||||
|
|
||||||
/* ITM Integration Write Register Definitions */
|
|
||||||
#define ITM_IWR_ATVALIDM_Pos 0U /*!< ITM IWR: ATVALIDM Position */
|
|
||||||
#define ITM_IWR_ATVALIDM_Msk (1UL /*<< ITM_IWR_ATVALIDM_Pos*/) /*!< ITM IWR: ATVALIDM Mask */
|
|
||||||
|
|
||||||
/* ITM Integration Read Register Definitions */
|
|
||||||
#define ITM_IRR_ATREADYM_Pos 0U /*!< ITM IRR: ATREADYM Position */
|
|
||||||
#define ITM_IRR_ATREADYM_Msk (1UL /*<< ITM_IRR_ATREADYM_Pos*/) /*!< ITM IRR: ATREADYM Mask */
|
|
||||||
|
|
||||||
/* ITM Integration Mode Control Register Definitions */
|
|
||||||
#define ITM_IMCR_INTEGRATION_Pos 0U /*!< ITM IMCR: INTEGRATION Position */
|
|
||||||
#define ITM_IMCR_INTEGRATION_Msk (1UL /*<< ITM_IMCR_INTEGRATION_Pos*/) /*!< ITM IMCR: INTEGRATION Mask */
|
|
||||||
|
|
||||||
/* ITM Lock Status Register Definitions */
|
/* ITM Lock Status Register Definitions */
|
||||||
#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */
|
#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */
|
||||||
#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */
|
#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */
|
||||||
@ -984,7 +987,7 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
__IOM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */
|
__IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */
|
||||||
__IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */
|
__IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */
|
||||||
uint32_t RESERVED0[2U];
|
uint32_t RESERVED0[2U];
|
||||||
__IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */
|
__IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */
|
||||||
@ -995,7 +998,7 @@ typedef struct
|
|||||||
__IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */
|
__IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */
|
||||||
__IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */
|
__IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */
|
||||||
uint32_t RESERVED3[759U];
|
uint32_t RESERVED3[759U];
|
||||||
__IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER */
|
__IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER Register */
|
||||||
__IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */
|
__IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */
|
||||||
__IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */
|
__IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */
|
||||||
uint32_t RESERVED4[1U];
|
uint32_t RESERVED4[1U];
|
||||||
@ -1044,13 +1047,13 @@ typedef struct
|
|||||||
|
|
||||||
/* TPI Integration ETM Data Register Definitions (FIFO0) */
|
/* TPI Integration ETM Data Register Definitions (FIFO0) */
|
||||||
#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */
|
#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */
|
||||||
#define TPI_FIFO0_ITM_ATVALID_Msk (0x3UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */
|
#define TPI_FIFO0_ITM_ATVALID_Msk (0x1UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */
|
||||||
|
|
||||||
#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */
|
#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */
|
||||||
#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */
|
#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */
|
||||||
|
|
||||||
#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */
|
#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */
|
||||||
#define TPI_FIFO0_ETM_ATVALID_Msk (0x3UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */
|
#define TPI_FIFO0_ETM_ATVALID_Msk (0x1UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */
|
||||||
|
|
||||||
#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */
|
#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */
|
||||||
#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */
|
#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */
|
||||||
@ -1065,18 +1068,21 @@ typedef struct
|
|||||||
#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */
|
#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */
|
||||||
|
|
||||||
/* TPI ITATBCTR2 Register Definitions */
|
/* TPI ITATBCTR2 Register Definitions */
|
||||||
#define TPI_ITATBCTR2_ATREADY_Pos 0U /*!< TPI ITATBCTR2: ATREADY Position */
|
#define TPI_ITATBCTR2_ATREADY2_Pos 0U /*!< TPI ITATBCTR2: ATREADY2 Position */
|
||||||
#define TPI_ITATBCTR2_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY_Pos*/) /*!< TPI ITATBCTR2: ATREADY Mask */
|
#define TPI_ITATBCTR2_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY2_Pos*/) /*!< TPI ITATBCTR2: ATREADY2 Mask */
|
||||||
|
|
||||||
|
#define TPI_ITATBCTR2_ATREADY1_Pos 0U /*!< TPI ITATBCTR2: ATREADY1 Position */
|
||||||
|
#define TPI_ITATBCTR2_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY1_Pos*/) /*!< TPI ITATBCTR2: ATREADY1 Mask */
|
||||||
|
|
||||||
/* TPI Integration ITM Data Register Definitions (FIFO1) */
|
/* TPI Integration ITM Data Register Definitions (FIFO1) */
|
||||||
#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */
|
#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */
|
||||||
#define TPI_FIFO1_ITM_ATVALID_Msk (0x3UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */
|
#define TPI_FIFO1_ITM_ATVALID_Msk (0x1UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */
|
||||||
|
|
||||||
#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */
|
#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */
|
||||||
#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */
|
#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */
|
||||||
|
|
||||||
#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */
|
#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */
|
||||||
#define TPI_FIFO1_ETM_ATVALID_Msk (0x3UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */
|
#define TPI_FIFO1_ETM_ATVALID_Msk (0x1UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */
|
||||||
|
|
||||||
#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */
|
#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */
|
||||||
#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */
|
#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */
|
||||||
@ -1091,12 +1097,15 @@ typedef struct
|
|||||||
#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */
|
#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */
|
||||||
|
|
||||||
/* TPI ITATBCTR0 Register Definitions */
|
/* TPI ITATBCTR0 Register Definitions */
|
||||||
#define TPI_ITATBCTR0_ATREADY_Pos 0U /*!< TPI ITATBCTR0: ATREADY Position */
|
#define TPI_ITATBCTR0_ATREADY2_Pos 0U /*!< TPI ITATBCTR0: ATREADY2 Position */
|
||||||
#define TPI_ITATBCTR0_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY_Pos*/) /*!< TPI ITATBCTR0: ATREADY Mask */
|
#define TPI_ITATBCTR0_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY2_Pos*/) /*!< TPI ITATBCTR0: ATREADY2 Mask */
|
||||||
|
|
||||||
|
#define TPI_ITATBCTR0_ATREADY1_Pos 0U /*!< TPI ITATBCTR0: ATREADY1 Position */
|
||||||
|
#define TPI_ITATBCTR0_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY1_Pos*/) /*!< TPI ITATBCTR0: ATREADY1 Mask */
|
||||||
|
|
||||||
/* TPI Integration Mode Control Register Definitions */
|
/* TPI Integration Mode Control Register Definitions */
|
||||||
#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */
|
#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */
|
||||||
#define TPI_ITCTRL_Mode_Msk (0x1UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */
|
#define TPI_ITCTRL_Mode_Msk (0x3UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */
|
||||||
|
|
||||||
/* TPI DEVID Register Definitions */
|
/* TPI DEVID Register Definitions */
|
||||||
#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */
|
#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */
|
||||||
@ -1118,16 +1127,16 @@ typedef struct
|
|||||||
#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */
|
#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */
|
||||||
|
|
||||||
/* TPI DEVTYPE Register Definitions */
|
/* TPI DEVTYPE Register Definitions */
|
||||||
#define TPI_DEVTYPE_MajorType_Pos 4U /*!< TPI DEVTYPE: MajorType Position */
|
#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */
|
||||||
#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */
|
|
||||||
|
|
||||||
#define TPI_DEVTYPE_SubType_Pos 0U /*!< TPI DEVTYPE: SubType Position */
|
|
||||||
#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */
|
#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */
|
||||||
|
|
||||||
|
#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */
|
||||||
|
#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */
|
||||||
|
|
||||||
/*@}*/ /* end of group CMSIS_TPI */
|
/*@}*/ /* end of group CMSIS_TPI */
|
||||||
|
|
||||||
|
|
||||||
#if (__MPU_PRESENT == 1U)
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
/**
|
/**
|
||||||
\ingroup CMSIS_core_register
|
\ingroup CMSIS_core_register
|
||||||
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
||||||
@ -1153,6 +1162,8 @@ typedef struct
|
|||||||
__IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */
|
__IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */
|
||||||
} MPU_Type;
|
} MPU_Type;
|
||||||
|
|
||||||
|
#define MPU_TYPE_RALIASES 4U
|
||||||
|
|
||||||
/* MPU Type Register Definitions */
|
/* MPU Type Register Definitions */
|
||||||
#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */
|
#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */
|
||||||
#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
|
#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
|
||||||
@ -1337,18 +1348,18 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
\brief Mask and shift a bit field value for use in a register bit range.
|
\brief Mask and shift a bit field value for use in a register bit range.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of the bit field.
|
\param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted value.
|
\return Masked and shifted value.
|
||||||
*/
|
*/
|
||||||
#define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk)
|
#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Mask and shift a register value to extract a bit filed value.
|
\brief Mask and shift a register value to extract a bit filed value.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of register.
|
\param[in] value Value of register. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted bit field value.
|
\return Masked and shifted bit field value.
|
||||||
*/
|
*/
|
||||||
#define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos)
|
#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
|
||||||
|
|
||||||
/*@} end of group CMSIS_core_bitfield */
|
/*@} end of group CMSIS_core_bitfield */
|
||||||
|
|
||||||
@ -1360,7 +1371,7 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Memory mapping of Cortex-M3 Hardware */
|
/* Memory mapping of Core Hardware */
|
||||||
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
||||||
#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
|
#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
|
||||||
#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
|
#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
|
||||||
@ -1379,7 +1390,7 @@ typedef struct
|
|||||||
#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */
|
#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */
|
||||||
#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
|
#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
|
||||||
|
|
||||||
#if (__MPU_PRESENT == 1U)
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
||||||
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
||||||
#endif
|
#endif
|
||||||
@ -1410,6 +1421,45 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef CMSIS_NVIC_VIRTUAL
|
||||||
|
#ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
|
||||||
|
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
|
||||||
|
#define NVIC_EnableIRQ __NVIC_EnableIRQ
|
||||||
|
#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
|
||||||
|
#define NVIC_DisableIRQ __NVIC_DisableIRQ
|
||||||
|
#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
|
||||||
|
#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
|
||||||
|
#define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
|
||||||
|
#define NVIC_GetActive __NVIC_GetActive
|
||||||
|
#define NVIC_SetPriority __NVIC_SetPriority
|
||||||
|
#define NVIC_GetPriority __NVIC_GetPriority
|
||||||
|
#define NVIC_SystemReset __NVIC_SystemReset
|
||||||
|
#endif /* CMSIS_NVIC_VIRTUAL */
|
||||||
|
|
||||||
|
#ifdef CMSIS_VECTAB_VIRTUAL
|
||||||
|
#ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetVector __NVIC_SetVector
|
||||||
|
#define NVIC_GetVector __NVIC_GetVector
|
||||||
|
#endif /* (CMSIS_VECTAB_VIRTUAL) */
|
||||||
|
|
||||||
|
#define NVIC_USER_IRQ_OFFSET 16
|
||||||
|
|
||||||
|
|
||||||
|
/* The following EXC_RETURN values are saved the LR on exception entry */
|
||||||
|
#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Priority Grouping
|
\brief Set Priority Grouping
|
||||||
\details Sets the priority grouping field using the required unlock sequence.
|
\details Sets the priority grouping field using the required unlock sequence.
|
||||||
@ -1419,7 +1469,7 @@ typedef struct
|
|||||||
priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
|
priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
|
||||||
\param [in] PriorityGroup Priority grouping field.
|
\param [in] PriorityGroup Priority grouping field.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
||||||
{
|
{
|
||||||
uint32_t reg_value;
|
uint32_t reg_value;
|
||||||
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
||||||
@ -1428,7 +1478,7 @@ __STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
|||||||
reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */
|
reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */
|
||||||
reg_value = (reg_value |
|
reg_value = (reg_value |
|
||||||
((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
|
((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
|
||||||
(PriorityGroupTmp << 8U) ); /* Insert write key and priorty group */
|
(PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */
|
||||||
SCB->AIRCR = reg_value;
|
SCB->AIRCR = reg_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1438,121 +1488,178 @@ __STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
|||||||
\details Reads the priority grouping field from the NVIC Interrupt Controller.
|
\details Reads the priority grouping field from the NVIC Interrupt Controller.
|
||||||
\return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field).
|
\return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field).
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void)
|
__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void)
|
||||||
{
|
{
|
||||||
return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos));
|
return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Enable External Interrupt
|
\brief Enable Interrupt
|
||||||
\details Enables a device-specific interrupt in the NVIC interrupt controller.
|
\details Enables a device specific interrupt in the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Disable External Interrupt
|
\brief Get Interrupt Enable status
|
||||||
\details Disables a device-specific interrupt in the NVIC interrupt controller.
|
\details Returns a device specific interrupt enable status from the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\return 0 Interrupt is not enabled.
|
||||||
|
\return 1 Interrupt is enabled.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Disable Interrupt
|
||||||
|
\details Disables a device specific interrupt in the NVIC interrupt controller.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Pending Interrupt
|
\brief Get Pending Interrupt
|
||||||
\details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt.
|
\details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
\return 0 Interrupt status is not pending.
|
\return 0 Interrupt status is not pending.
|
||||||
\return 1 Interrupt status is pending.
|
\return 1 Interrupt status is pending.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Pending Interrupt
|
\brief Set Pending Interrupt
|
||||||
\details Sets the pending bit of an external interrupt.
|
\details Sets the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn Interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Clear Pending Interrupt
|
\brief Clear Pending Interrupt
|
||||||
\details Clears the pending bit of an external interrupt.
|
\details Clears the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Active Interrupt
|
\brief Get Active Interrupt
|
||||||
\details Reads the active register in NVIC and returns the active bit.
|
\details Reads the active register in the NVIC and returns the active bit for the device specific interrupt.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
\return 0 Interrupt status is not active.
|
\return 0 Interrupt status is not active.
|
||||||
\return 1 Interrupt status is active.
|
\return 1 Interrupt status is active.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->IABR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Interrupt Priority
|
\brief Set Interrupt Priority
|
||||||
\details Sets the priority of an interrupt.
|
\details Sets the priority of a device specific interrupt or a processor exception.
|
||||||
\note The priority cannot be set for every core interrupt.
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\param [in] priority Priority to set.
|
\param [in] priority Priority to set.
|
||||||
|
\note The priority cannot be set for every processor exception.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
||||||
{
|
{
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
{
|
||||||
SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NVIC->IP[((uint32_t)(int32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Interrupt Priority
|
\brief Get Interrupt Priority
|
||||||
\details Reads the priority of an interrupt.
|
\details Reads the priority of a device specific interrupt or a processor exception.
|
||||||
The interrupt number can be positive to specify an external (device specific) interrupt,
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
or negative to specify an internal (core) interrupt.
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\return Interrupt Priority.
|
\return Interrupt Priority.
|
||||||
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
{
|
||||||
return(((uint32_t)SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS)));
|
return(((uint32_t)NVIC->IP[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return(((uint32_t)NVIC->IP[((uint32_t)(int32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS)));
|
return(((uint32_t)SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1609,11 +1716,42 @@ __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGr
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Set Interrupt Vector
|
||||||
|
\details Sets an interrupt vector in SRAM based interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
VTOR must been relocated to SRAM before.
|
||||||
|
\param [in] IRQn Interrupt number
|
||||||
|
\param [in] vector Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
|
||||||
|
{
|
||||||
|
uint32_t vectors = (uint32_t )SCB->VTOR;
|
||||||
|
(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Get Interrupt Vector
|
||||||
|
\details Reads an interrupt vector from interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
\param [in] IRQn Interrupt number.
|
||||||
|
\return Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
uint32_t vectors = (uint32_t )SCB->VTOR;
|
||||||
|
return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief System Reset
|
\brief System Reset
|
||||||
\details Initiates a system reset request to reset the MCU.
|
\details Initiates a system reset request to reset the MCU.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SystemReset(void)
|
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
|
||||||
{
|
{
|
||||||
__DSB(); /* Ensure all outstanding memory accesses included
|
__DSB(); /* Ensure all outstanding memory accesses included
|
||||||
buffered write are completed before reset */
|
buffered write are completed before reset */
|
||||||
@ -1630,6 +1768,39 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
|
|
||||||
/*@} end of CMSIS_Core_NVICFunctions */
|
/*@} end of CMSIS_Core_NVICFunctions */
|
||||||
|
|
||||||
|
/* ########################## MPU functions #################################### */
|
||||||
|
|
||||||
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
|
|
||||||
|
#include "mpu_armv7.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ########################## FPU functions #################################### */
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_Core_FunctionInterface
|
||||||
|
\defgroup CMSIS_Core_FpuFunctions FPU Functions
|
||||||
|
\brief Function that provides FPU type.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief get FPU type
|
||||||
|
\details returns the FPU type
|
||||||
|
\returns
|
||||||
|
- \b 0: No FPU
|
||||||
|
- \b 1: Single precision FPU
|
||||||
|
- \b 2: Double + Single precision FPU
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t SCB_GetFPUType(void)
|
||||||
|
{
|
||||||
|
return 0U; /* No FPU */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*@} end of CMSIS_Core_FpuFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ################################## SysTick function ############################################ */
|
/* ################################## SysTick function ############################################ */
|
||||||
@ -1640,7 +1811,7 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (__Vendor_SysTickConfig == 0U)
|
#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief System Tick Configuration
|
\brief System Tick Configuration
|
||||||
@ -1683,8 +1854,8 @@ __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */
|
extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */
|
||||||
#define ITM_RXBUFFER_EMPTY 0x5AA55AA5U /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */
|
#define ITM_RXBUFFER_EMPTY ((int32_t)0x5AA55AA5U) /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
2907
lib/cmsis/inc/core_cm33.h
Normal file
2907
lib/cmsis/inc/core_cm33.h
Normal file
File diff suppressed because it is too large
Load Diff
2907
lib/cmsis/inc/core_cm35p.h
Normal file
2907
lib/cmsis/inc/core_cm35p.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,40 +1,30 @@
|
|||||||
/**************************************************************************//**
|
/**************************************************************************//**
|
||||||
* @file core_cm4.h
|
* @file core_cm4.h
|
||||||
* @brief CMSIS Cortex-M4 Core Peripheral Access Layer Header File
|
* @brief CMSIS Cortex-M4 Core Peripheral Access Layer Header File
|
||||||
* @version V4.30
|
* @version V5.1.0
|
||||||
* @date 20. October 2015
|
* @date 13. March 2019
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
/*
|
||||||
|
* Copyright (c) 2009-2019 Arm Limited. All rights reserved.
|
||||||
All rights reserved.
|
*
|
||||||
Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
modification, are permitted provided that the following conditions are met:
|
*
|
||||||
- Redistributions of source code must retain the above copyright
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
notice, this list of conditions and the following disclaimer.
|
* not use this file except in compliance with the License.
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
* You may obtain a copy of the License at
|
||||||
notice, this list of conditions and the following disclaimer in the
|
*
|
||||||
documentation and/or other materials provided with the distribution.
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
- Neither the name of ARM nor the names of its contributors may be used
|
*
|
||||||
to endorse or promote products derived from this software without
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
specific prior written permission.
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
*
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* See the License for the specific language governing permissions and
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* limitations under the License.
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
*/
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND 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.
|
|
||||||
---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __ICCARM__ )
|
#if defined ( __ICCARM__ )
|
||||||
#pragma system_include /* treat file as system include file for MISRA check */
|
#pragma system_include /* treat file as system include file for MISRA check */
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__clang__)
|
||||||
#pragma clang system_header /* treat file as system include file */
|
#pragma clang system_header /* treat file as system include file */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -70,60 +60,22 @@
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* CMSIS CM4 definitions */
|
#include "cmsis_version.h"
|
||||||
#define __CM4_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */
|
|
||||||
#define __CM4_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */
|
/* CMSIS CM4 definitions */
|
||||||
|
#define __CM4_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
|
||||||
|
#define __CM4_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
|
||||||
#define __CM4_CMSIS_VERSION ((__CM4_CMSIS_VERSION_MAIN << 16U) | \
|
#define __CM4_CMSIS_VERSION ((__CM4_CMSIS_VERSION_MAIN << 16U) | \
|
||||||
__CM4_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
|
__CM4_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
|
||||||
|
|
||||||
#define __CORTEX_M (0x04U) /*!< Cortex-M Core */
|
#define __CORTEX_M (4U) /*!< Cortex-M Core */
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __CC_ARM )
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined ( __GNUC__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for GNU Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __ICCARM__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for IAR Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TASKING__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __CSMC__ )
|
|
||||||
#define __packed
|
|
||||||
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error Unknown compiler
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** __FPU_USED indicates whether an FPU is used or not.
|
/** __FPU_USED indicates whether an FPU is used or not.
|
||||||
For this, __FPU_PRESENT has to be checked prior to making use of FPU specific registers and functions.
|
For this, __FPU_PRESENT has to be checked prior to making use of FPU specific registers and functions.
|
||||||
*/
|
*/
|
||||||
#if defined ( __CC_ARM )
|
#if defined ( __CC_ARM )
|
||||||
#if defined __TARGET_FPU_VFP
|
#if defined __TARGET_FPU_VFP
|
||||||
#if (__FPU_PRESENT == 1U)
|
#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
|
||||||
#define __FPU_USED 1U
|
#define __FPU_USED 1U
|
||||||
#else
|
#else
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
@ -133,9 +85,9 @@
|
|||||||
#define __FPU_USED 0U
|
#define __FPU_USED 0U
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||||
#if defined __ARM_PCS_VFP
|
#if defined __ARM_FP
|
||||||
#if (__FPU_PRESENT == 1)
|
#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
|
||||||
#define __FPU_USED 1U
|
#define __FPU_USED 1U
|
||||||
#else
|
#else
|
||||||
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
@ -147,7 +99,7 @@
|
|||||||
|
|
||||||
#elif defined ( __GNUC__ )
|
#elif defined ( __GNUC__ )
|
||||||
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
|
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
|
||||||
#if (__FPU_PRESENT == 1U)
|
#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
|
||||||
#define __FPU_USED 1U
|
#define __FPU_USED 1U
|
||||||
#else
|
#else
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
@ -159,7 +111,7 @@
|
|||||||
|
|
||||||
#elif defined ( __ICCARM__ )
|
#elif defined ( __ICCARM__ )
|
||||||
#if defined __ARMVFP__
|
#if defined __ARMVFP__
|
||||||
#if (__FPU_PRESENT == 1U)
|
#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
|
||||||
#define __FPU_USED 1U
|
#define __FPU_USED 1U
|
||||||
#else
|
#else
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
@ -169,9 +121,9 @@
|
|||||||
#define __FPU_USED 0U
|
#define __FPU_USED 0U
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
#elif defined ( __TI_ARM__ )
|
||||||
#if defined __TI_VFP_SUPPORT__
|
#if defined __TI_VFP_SUPPORT__
|
||||||
#if (__FPU_PRESENT == 1U)
|
#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
|
||||||
#define __FPU_USED 1U
|
#define __FPU_USED 1U
|
||||||
#else
|
#else
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
@ -183,7 +135,7 @@
|
|||||||
|
|
||||||
#elif defined ( __TASKING__ )
|
#elif defined ( __TASKING__ )
|
||||||
#if defined __FPU_VFP__
|
#if defined __FPU_VFP__
|
||||||
#if (__FPU_PRESENT == 1U)
|
#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
|
||||||
#define __FPU_USED 1U
|
#define __FPU_USED 1U
|
||||||
#else
|
#else
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
@ -195,7 +147,7 @@
|
|||||||
|
|
||||||
#elif defined ( __CSMC__ )
|
#elif defined ( __CSMC__ )
|
||||||
#if ( __CSMC__ & 0x400U)
|
#if ( __CSMC__ & 0x400U)
|
||||||
#if (__FPU_PRESENT == 1U)
|
#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)
|
||||||
#define __FPU_USED 1U
|
#define __FPU_USED 1U
|
||||||
#else
|
#else
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
@ -207,9 +159,8 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "core_cmInstr.h" /* Core Instruction Access */
|
#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
|
||||||
#include "core_cmFunc.h" /* Core Function Access */
|
|
||||||
#include "core_cmSimd.h" /* Compiler specific SIMD Intrinsics */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@ -244,7 +195,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __NVIC_PRIO_BITS
|
#ifndef __NVIC_PRIO_BITS
|
||||||
#define __NVIC_PRIO_BITS 4U
|
#define __NVIC_PRIO_BITS 3U
|
||||||
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
|
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -367,11 +318,12 @@ typedef union
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
||||||
uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */
|
uint32_t _reserved0:1; /*!< bit: 9 Reserved */
|
||||||
|
uint32_t ICI_IT_1:6; /*!< bit: 10..15 ICI/IT part 1 */
|
||||||
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
|
uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */
|
||||||
uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
|
uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */
|
||||||
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
|
uint32_t T:1; /*!< bit: 24 Thumb bit */
|
||||||
uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
|
uint32_t ICI_IT_2:2; /*!< bit: 25..26 ICI/IT part 2 */
|
||||||
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
|
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
|
||||||
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
||||||
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
||||||
@ -397,8 +349,8 @@ typedef union
|
|||||||
#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */
|
#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */
|
||||||
#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */
|
#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */
|
||||||
|
|
||||||
#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */
|
#define xPSR_ICI_IT_2_Pos 25U /*!< xPSR: ICI/IT part 2 Position */
|
||||||
#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT Mask */
|
#define xPSR_ICI_IT_2_Msk (3UL << xPSR_ICI_IT_2_Pos) /*!< xPSR: ICI/IT part 2 Mask */
|
||||||
|
|
||||||
#define xPSR_T_Pos 24U /*!< xPSR: T Position */
|
#define xPSR_T_Pos 24U /*!< xPSR: T Position */
|
||||||
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
|
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
|
||||||
@ -406,6 +358,9 @@ typedef union
|
|||||||
#define xPSR_GE_Pos 16U /*!< xPSR: GE Position */
|
#define xPSR_GE_Pos 16U /*!< xPSR: GE Position */
|
||||||
#define xPSR_GE_Msk (0xFUL << xPSR_GE_Pos) /*!< xPSR: GE Mask */
|
#define xPSR_GE_Msk (0xFUL << xPSR_GE_Pos) /*!< xPSR: GE Mask */
|
||||||
|
|
||||||
|
#define xPSR_ICI_IT_1_Pos 10U /*!< xPSR: ICI/IT part 1 Position */
|
||||||
|
#define xPSR_ICI_IT_1_Msk (0x3FUL << xPSR_ICI_IT_1_Pos) /*!< xPSR: ICI/IT part 1 Mask */
|
||||||
|
|
||||||
#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
|
#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
|
||||||
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
|
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
|
||||||
|
|
||||||
@ -453,7 +408,7 @@ typedef struct
|
|||||||
__IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
__IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
|
||||||
uint32_t RESERVED0[24U];
|
uint32_t RESERVED0[24U];
|
||||||
__IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
__IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
|
||||||
uint32_t RSERVED1[24U];
|
uint32_t RESERVED1[24U];
|
||||||
__IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
__IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
|
||||||
uint32_t RESERVED2[24U];
|
uint32_t RESERVED2[24U];
|
||||||
__IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
__IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
|
||||||
@ -662,6 +617,66 @@ typedef struct
|
|||||||
#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */
|
#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */
|
||||||
#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
|
#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
|
||||||
|
|
||||||
|
/* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */
|
||||||
|
#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */
|
||||||
|
#define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_MLSPERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 5U) /*!< SCB CFSR (MMFSR): MLSPERR Position */
|
||||||
|
#define SCB_CFSR_MLSPERR_Msk (1UL << SCB_CFSR_MLSPERR_Pos) /*!< SCB CFSR (MMFSR): MLSPERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */
|
||||||
|
#define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */
|
||||||
|
#define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */
|
||||||
|
#define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */
|
||||||
|
#define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */
|
||||||
|
|
||||||
|
/* BusFault Status Register (part of SCB Configurable Fault Status Register) */
|
||||||
|
#define SCB_CFSR_BFARVALID_Pos (SCB_CFSR_BUSFAULTSR_Pos + 7U) /*!< SCB CFSR (BFSR): BFARVALID Position */
|
||||||
|
#define SCB_CFSR_BFARVALID_Msk (1UL << SCB_CFSR_BFARVALID_Pos) /*!< SCB CFSR (BFSR): BFARVALID Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_LSPERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 5U) /*!< SCB CFSR (BFSR): LSPERR Position */
|
||||||
|
#define SCB_CFSR_LSPERR_Msk (1UL << SCB_CFSR_LSPERR_Pos) /*!< SCB CFSR (BFSR): LSPERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_STKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 4U) /*!< SCB CFSR (BFSR): STKERR Position */
|
||||||
|
#define SCB_CFSR_STKERR_Msk (1UL << SCB_CFSR_STKERR_Pos) /*!< SCB CFSR (BFSR): STKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_UNSTKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 3U) /*!< SCB CFSR (BFSR): UNSTKERR Position */
|
||||||
|
#define SCB_CFSR_UNSTKERR_Msk (1UL << SCB_CFSR_UNSTKERR_Pos) /*!< SCB CFSR (BFSR): UNSTKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_IMPRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 2U) /*!< SCB CFSR (BFSR): IMPRECISERR Position */
|
||||||
|
#define SCB_CFSR_IMPRECISERR_Msk (1UL << SCB_CFSR_IMPRECISERR_Pos) /*!< SCB CFSR (BFSR): IMPRECISERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_PRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 1U) /*!< SCB CFSR (BFSR): PRECISERR Position */
|
||||||
|
#define SCB_CFSR_PRECISERR_Msk (1UL << SCB_CFSR_PRECISERR_Pos) /*!< SCB CFSR (BFSR): PRECISERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_IBUSERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 0U) /*!< SCB CFSR (BFSR): IBUSERR Position */
|
||||||
|
#define SCB_CFSR_IBUSERR_Msk (1UL << SCB_CFSR_IBUSERR_Pos) /*!< SCB CFSR (BFSR): IBUSERR Mask */
|
||||||
|
|
||||||
|
/* UsageFault Status Register (part of SCB Configurable Fault Status Register) */
|
||||||
|
#define SCB_CFSR_DIVBYZERO_Pos (SCB_CFSR_USGFAULTSR_Pos + 9U) /*!< SCB CFSR (UFSR): DIVBYZERO Position */
|
||||||
|
#define SCB_CFSR_DIVBYZERO_Msk (1UL << SCB_CFSR_DIVBYZERO_Pos) /*!< SCB CFSR (UFSR): DIVBYZERO Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_UNALIGNED_Pos (SCB_CFSR_USGFAULTSR_Pos + 8U) /*!< SCB CFSR (UFSR): UNALIGNED Position */
|
||||||
|
#define SCB_CFSR_UNALIGNED_Msk (1UL << SCB_CFSR_UNALIGNED_Pos) /*!< SCB CFSR (UFSR): UNALIGNED Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_NOCP_Pos (SCB_CFSR_USGFAULTSR_Pos + 3U) /*!< SCB CFSR (UFSR): NOCP Position */
|
||||||
|
#define SCB_CFSR_NOCP_Msk (1UL << SCB_CFSR_NOCP_Pos) /*!< SCB CFSR (UFSR): NOCP Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_INVPC_Pos (SCB_CFSR_USGFAULTSR_Pos + 2U) /*!< SCB CFSR (UFSR): INVPC Position */
|
||||||
|
#define SCB_CFSR_INVPC_Msk (1UL << SCB_CFSR_INVPC_Pos) /*!< SCB CFSR (UFSR): INVPC Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_INVSTATE_Pos (SCB_CFSR_USGFAULTSR_Pos + 1U) /*!< SCB CFSR (UFSR): INVSTATE Position */
|
||||||
|
#define SCB_CFSR_INVSTATE_Msk (1UL << SCB_CFSR_INVSTATE_Pos) /*!< SCB CFSR (UFSR): INVSTATE Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_UNDEFINSTR_Pos (SCB_CFSR_USGFAULTSR_Pos + 0U) /*!< SCB CFSR (UFSR): UNDEFINSTR Position */
|
||||||
|
#define SCB_CFSR_UNDEFINSTR_Msk (1UL << SCB_CFSR_UNDEFINSTR_Pos) /*!< SCB CFSR (UFSR): UNDEFINSTR Mask */
|
||||||
|
|
||||||
/* SCB Hard Fault Status Register Definitions */
|
/* SCB Hard Fault Status Register Definitions */
|
||||||
#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */
|
#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */
|
||||||
#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
|
#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
|
||||||
@ -807,10 +822,7 @@ typedef struct
|
|||||||
__IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */
|
__IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */
|
||||||
uint32_t RESERVED2[15U];
|
uint32_t RESERVED2[15U];
|
||||||
__IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */
|
__IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */
|
||||||
uint32_t RESERVED3[29U];
|
uint32_t RESERVED3[32U];
|
||||||
__OM uint32_t IWR; /*!< Offset: 0xEF8 ( /W) ITM Integration Write Register */
|
|
||||||
__IM uint32_t IRR; /*!< Offset: 0xEFC (R/ ) ITM Integration Read Register */
|
|
||||||
__IOM uint32_t IMCR; /*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register */
|
|
||||||
uint32_t RESERVED4[43U];
|
uint32_t RESERVED4[43U];
|
||||||
__OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */
|
__OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */
|
||||||
__IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */
|
__IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */
|
||||||
@ -831,7 +843,7 @@ typedef struct
|
|||||||
|
|
||||||
/* ITM Trace Privilege Register Definitions */
|
/* ITM Trace Privilege Register Definitions */
|
||||||
#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */
|
#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */
|
||||||
#define ITM_TPR_PRIVMASK_Msk (0xFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */
|
#define ITM_TPR_PRIVMASK_Msk (0xFFFFFFFFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */
|
||||||
|
|
||||||
/* ITM Trace Control Register Definitions */
|
/* ITM Trace Control Register Definitions */
|
||||||
#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */
|
#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */
|
||||||
@ -861,18 +873,6 @@ typedef struct
|
|||||||
#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */
|
#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */
|
||||||
#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */
|
#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */
|
||||||
|
|
||||||
/* ITM Integration Write Register Definitions */
|
|
||||||
#define ITM_IWR_ATVALIDM_Pos 0U /*!< ITM IWR: ATVALIDM Position */
|
|
||||||
#define ITM_IWR_ATVALIDM_Msk (1UL /*<< ITM_IWR_ATVALIDM_Pos*/) /*!< ITM IWR: ATVALIDM Mask */
|
|
||||||
|
|
||||||
/* ITM Integration Read Register Definitions */
|
|
||||||
#define ITM_IRR_ATREADYM_Pos 0U /*!< ITM IRR: ATREADYM Position */
|
|
||||||
#define ITM_IRR_ATREADYM_Msk (1UL /*<< ITM_IRR_ATREADYM_Pos*/) /*!< ITM IRR: ATREADYM Mask */
|
|
||||||
|
|
||||||
/* ITM Integration Mode Control Register Definitions */
|
|
||||||
#define ITM_IMCR_INTEGRATION_Pos 0U /*!< ITM IMCR: INTEGRATION Position */
|
|
||||||
#define ITM_IMCR_INTEGRATION_Msk (1UL /*<< ITM_IMCR_INTEGRATION_Pos*/) /*!< ITM IMCR: INTEGRATION Mask */
|
|
||||||
|
|
||||||
/* ITM Lock Status Register Definitions */
|
/* ITM Lock Status Register Definitions */
|
||||||
#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */
|
#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */
|
||||||
#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */
|
#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */
|
||||||
@ -1045,7 +1045,7 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
__IOM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */
|
__IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */
|
||||||
__IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */
|
__IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */
|
||||||
uint32_t RESERVED0[2U];
|
uint32_t RESERVED0[2U];
|
||||||
__IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */
|
__IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */
|
||||||
@ -1056,7 +1056,7 @@ typedef struct
|
|||||||
__IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */
|
__IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */
|
||||||
__IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */
|
__IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */
|
||||||
uint32_t RESERVED3[759U];
|
uint32_t RESERVED3[759U];
|
||||||
__IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER */
|
__IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER Register */
|
||||||
__IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */
|
__IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */
|
||||||
__IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */
|
__IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */
|
||||||
uint32_t RESERVED4[1U];
|
uint32_t RESERVED4[1U];
|
||||||
@ -1105,13 +1105,13 @@ typedef struct
|
|||||||
|
|
||||||
/* TPI Integration ETM Data Register Definitions (FIFO0) */
|
/* TPI Integration ETM Data Register Definitions (FIFO0) */
|
||||||
#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */
|
#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */
|
||||||
#define TPI_FIFO0_ITM_ATVALID_Msk (0x3UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */
|
#define TPI_FIFO0_ITM_ATVALID_Msk (0x1UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */
|
||||||
|
|
||||||
#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */
|
#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */
|
||||||
#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */
|
#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */
|
||||||
|
|
||||||
#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */
|
#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */
|
||||||
#define TPI_FIFO0_ETM_ATVALID_Msk (0x3UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */
|
#define TPI_FIFO0_ETM_ATVALID_Msk (0x1UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */
|
||||||
|
|
||||||
#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */
|
#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */
|
||||||
#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */
|
#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */
|
||||||
@ -1126,18 +1126,21 @@ typedef struct
|
|||||||
#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */
|
#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */
|
||||||
|
|
||||||
/* TPI ITATBCTR2 Register Definitions */
|
/* TPI ITATBCTR2 Register Definitions */
|
||||||
#define TPI_ITATBCTR2_ATREADY_Pos 0U /*!< TPI ITATBCTR2: ATREADY Position */
|
#define TPI_ITATBCTR2_ATREADY2_Pos 0U /*!< TPI ITATBCTR2: ATREADY2 Position */
|
||||||
#define TPI_ITATBCTR2_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY_Pos*/) /*!< TPI ITATBCTR2: ATREADY Mask */
|
#define TPI_ITATBCTR2_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY2_Pos*/) /*!< TPI ITATBCTR2: ATREADY2 Mask */
|
||||||
|
|
||||||
|
#define TPI_ITATBCTR2_ATREADY1_Pos 0U /*!< TPI ITATBCTR2: ATREADY1 Position */
|
||||||
|
#define TPI_ITATBCTR2_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY1_Pos*/) /*!< TPI ITATBCTR2: ATREADY1 Mask */
|
||||||
|
|
||||||
/* TPI Integration ITM Data Register Definitions (FIFO1) */
|
/* TPI Integration ITM Data Register Definitions (FIFO1) */
|
||||||
#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */
|
#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */
|
||||||
#define TPI_FIFO1_ITM_ATVALID_Msk (0x3UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */
|
#define TPI_FIFO1_ITM_ATVALID_Msk (0x1UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */
|
||||||
|
|
||||||
#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */
|
#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */
|
||||||
#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */
|
#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */
|
||||||
|
|
||||||
#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */
|
#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */
|
||||||
#define TPI_FIFO1_ETM_ATVALID_Msk (0x3UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */
|
#define TPI_FIFO1_ETM_ATVALID_Msk (0x1UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */
|
||||||
|
|
||||||
#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */
|
#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */
|
||||||
#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */
|
#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */
|
||||||
@ -1152,12 +1155,15 @@ typedef struct
|
|||||||
#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */
|
#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */
|
||||||
|
|
||||||
/* TPI ITATBCTR0 Register Definitions */
|
/* TPI ITATBCTR0 Register Definitions */
|
||||||
#define TPI_ITATBCTR0_ATREADY_Pos 0U /*!< TPI ITATBCTR0: ATREADY Position */
|
#define TPI_ITATBCTR0_ATREADY2_Pos 0U /*!< TPI ITATBCTR0: ATREADY2 Position */
|
||||||
#define TPI_ITATBCTR0_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY_Pos*/) /*!< TPI ITATBCTR0: ATREADY Mask */
|
#define TPI_ITATBCTR0_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY2_Pos*/) /*!< TPI ITATBCTR0: ATREADY2 Mask */
|
||||||
|
|
||||||
|
#define TPI_ITATBCTR0_ATREADY1_Pos 0U /*!< TPI ITATBCTR0: ATREADY1 Position */
|
||||||
|
#define TPI_ITATBCTR0_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY1_Pos*/) /*!< TPI ITATBCTR0: ATREADY1 Mask */
|
||||||
|
|
||||||
/* TPI Integration Mode Control Register Definitions */
|
/* TPI Integration Mode Control Register Definitions */
|
||||||
#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */
|
#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */
|
||||||
#define TPI_ITCTRL_Mode_Msk (0x1UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */
|
#define TPI_ITCTRL_Mode_Msk (0x3UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */
|
||||||
|
|
||||||
/* TPI DEVID Register Definitions */
|
/* TPI DEVID Register Definitions */
|
||||||
#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */
|
#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */
|
||||||
@ -1179,16 +1185,16 @@ typedef struct
|
|||||||
#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */
|
#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */
|
||||||
|
|
||||||
/* TPI DEVTYPE Register Definitions */
|
/* TPI DEVTYPE Register Definitions */
|
||||||
#define TPI_DEVTYPE_MajorType_Pos 4U /*!< TPI DEVTYPE: MajorType Position */
|
#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */
|
||||||
#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */
|
|
||||||
|
|
||||||
#define TPI_DEVTYPE_SubType_Pos 0U /*!< TPI DEVTYPE: SubType Position */
|
|
||||||
#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */
|
#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */
|
||||||
|
|
||||||
|
#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */
|
||||||
|
#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */
|
||||||
|
|
||||||
/*@}*/ /* end of group CMSIS_TPI */
|
/*@}*/ /* end of group CMSIS_TPI */
|
||||||
|
|
||||||
|
|
||||||
#if (__MPU_PRESENT == 1U)
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
/**
|
/**
|
||||||
\ingroup CMSIS_core_register
|
\ingroup CMSIS_core_register
|
||||||
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
||||||
@ -1214,6 +1220,8 @@ typedef struct
|
|||||||
__IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */
|
__IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */
|
||||||
} MPU_Type;
|
} MPU_Type;
|
||||||
|
|
||||||
|
#define MPU_TYPE_RALIASES 4U
|
||||||
|
|
||||||
/* MPU Type Register Definitions */
|
/* MPU Type Register Definitions */
|
||||||
#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */
|
#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */
|
||||||
#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
|
#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */
|
||||||
@ -1280,10 +1288,9 @@ typedef struct
|
|||||||
#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */
|
#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */
|
||||||
|
|
||||||
/*@} end of group CMSIS_MPU */
|
/*@} end of group CMSIS_MPU */
|
||||||
#endif
|
#endif /* defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) */
|
||||||
|
|
||||||
|
|
||||||
#if (__FPU_PRESENT == 1U)
|
|
||||||
/**
|
/**
|
||||||
\ingroup CMSIS_core_register
|
\ingroup CMSIS_core_register
|
||||||
\defgroup CMSIS_FPU Floating Point Unit (FPU)
|
\defgroup CMSIS_FPU Floating Point Unit (FPU)
|
||||||
@ -1302,6 +1309,7 @@ typedef struct
|
|||||||
__IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */
|
__IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */
|
||||||
__IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */
|
__IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */
|
||||||
__IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */
|
__IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */
|
||||||
|
__IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and FP Feature Register 2 */
|
||||||
} FPU_Type;
|
} FPU_Type;
|
||||||
|
|
||||||
/* Floating-Point Context Control Register Definitions */
|
/* Floating-Point Context Control Register Definitions */
|
||||||
@ -1387,8 +1395,12 @@ typedef struct
|
|||||||
#define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */
|
#define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */
|
||||||
#define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */
|
#define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */
|
||||||
|
|
||||||
|
/* Media and FP Feature Register 2 Definitions */
|
||||||
|
|
||||||
|
#define FPU_MVFR2_VFP_Misc_Pos 4U /*!< MVFR2: VFP Misc bits Position */
|
||||||
|
#define FPU_MVFR2_VFP_Misc_Msk (0xFUL << FPU_MVFR2_VFP_Misc_Pos) /*!< MVFR2: VFP Misc bits Mask */
|
||||||
|
|
||||||
/*@} end of group CMSIS_FPU */
|
/*@} end of group CMSIS_FPU */
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1506,18 +1518,18 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
\brief Mask and shift a bit field value for use in a register bit range.
|
\brief Mask and shift a bit field value for use in a register bit range.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of the bit field.
|
\param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted value.
|
\return Masked and shifted value.
|
||||||
*/
|
*/
|
||||||
#define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk)
|
#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Mask and shift a register value to extract a bit filed value.
|
\brief Mask and shift a register value to extract a bit filed value.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of register.
|
\param[in] value Value of register. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted bit field value.
|
\return Masked and shifted bit field value.
|
||||||
*/
|
*/
|
||||||
#define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos)
|
#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
|
||||||
|
|
||||||
/*@} end of group CMSIS_core_bitfield */
|
/*@} end of group CMSIS_core_bitfield */
|
||||||
|
|
||||||
@ -1529,7 +1541,7 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Memory mapping of Cortex-M4 Hardware */
|
/* Memory mapping of Core Hardware */
|
||||||
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
||||||
#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
|
#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
|
||||||
#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
|
#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
|
||||||
@ -1548,15 +1560,13 @@ typedef struct
|
|||||||
#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */
|
#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */
|
||||||
#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
|
#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
|
||||||
|
|
||||||
#if (__MPU_PRESENT == 1U)
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
||||||
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (__FPU_PRESENT == 1U)
|
#define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */
|
||||||
#define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */
|
#define FPU ((FPU_Type *) FPU_BASE ) /*!< Floating Point Unit */
|
||||||
#define FPU ((FPU_Type *) FPU_BASE ) /*!< Floating Point Unit */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*@} */
|
/*@} */
|
||||||
|
|
||||||
@ -1584,6 +1594,48 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef CMSIS_NVIC_VIRTUAL
|
||||||
|
#ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
|
||||||
|
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
|
||||||
|
#define NVIC_EnableIRQ __NVIC_EnableIRQ
|
||||||
|
#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
|
||||||
|
#define NVIC_DisableIRQ __NVIC_DisableIRQ
|
||||||
|
#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
|
||||||
|
#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
|
||||||
|
#define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
|
||||||
|
#define NVIC_GetActive __NVIC_GetActive
|
||||||
|
#define NVIC_SetPriority __NVIC_SetPriority
|
||||||
|
#define NVIC_GetPriority __NVIC_GetPriority
|
||||||
|
#define NVIC_SystemReset __NVIC_SystemReset
|
||||||
|
#endif /* CMSIS_NVIC_VIRTUAL */
|
||||||
|
|
||||||
|
#ifdef CMSIS_VECTAB_VIRTUAL
|
||||||
|
#ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetVector __NVIC_SetVector
|
||||||
|
#define NVIC_GetVector __NVIC_GetVector
|
||||||
|
#endif /* (CMSIS_VECTAB_VIRTUAL) */
|
||||||
|
|
||||||
|
#define NVIC_USER_IRQ_OFFSET 16
|
||||||
|
|
||||||
|
|
||||||
|
/* The following EXC_RETURN values are saved the LR on exception entry */
|
||||||
|
#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
|
||||||
|
#define EXC_RETURN_HANDLER_FPU (0xFFFFFFE1UL) /* return to Handler mode, uses MSP after return, restore floating-point state */
|
||||||
|
#define EXC_RETURN_THREAD_MSP_FPU (0xFFFFFFE9UL) /* return to Thread mode, uses MSP after return, restore floating-point state */
|
||||||
|
#define EXC_RETURN_THREAD_PSP_FPU (0xFFFFFFEDUL) /* return to Thread mode, uses PSP after return, restore floating-point state */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Priority Grouping
|
\brief Set Priority Grouping
|
||||||
\details Sets the priority grouping field using the required unlock sequence.
|
\details Sets the priority grouping field using the required unlock sequence.
|
||||||
@ -1593,7 +1645,7 @@ typedef struct
|
|||||||
priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
|
priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
|
||||||
\param [in] PriorityGroup Priority grouping field.
|
\param [in] PriorityGroup Priority grouping field.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
||||||
{
|
{
|
||||||
uint32_t reg_value;
|
uint32_t reg_value;
|
||||||
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
||||||
@ -1602,7 +1654,7 @@ __STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
|||||||
reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */
|
reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */
|
||||||
reg_value = (reg_value |
|
reg_value = (reg_value |
|
||||||
((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
|
((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
|
||||||
(PriorityGroupTmp << 8U) ); /* Insert write key and priorty group */
|
(PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */
|
||||||
SCB->AIRCR = reg_value;
|
SCB->AIRCR = reg_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1612,121 +1664,178 @@ __STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
|||||||
\details Reads the priority grouping field from the NVIC Interrupt Controller.
|
\details Reads the priority grouping field from the NVIC Interrupt Controller.
|
||||||
\return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field).
|
\return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field).
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void)
|
__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void)
|
||||||
{
|
{
|
||||||
return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos));
|
return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Enable External Interrupt
|
\brief Enable Interrupt
|
||||||
\details Enables a device-specific interrupt in the NVIC interrupt controller.
|
\details Enables a device specific interrupt in the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Disable External Interrupt
|
\brief Get Interrupt Enable status
|
||||||
\details Disables a device-specific interrupt in the NVIC interrupt controller.
|
\details Returns a device specific interrupt enable status from the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\return 0 Interrupt is not enabled.
|
||||||
|
\return 1 Interrupt is enabled.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Disable Interrupt
|
||||||
|
\details Disables a device specific interrupt in the NVIC interrupt controller.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Pending Interrupt
|
\brief Get Pending Interrupt
|
||||||
\details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt.
|
\details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
\return 0 Interrupt status is not pending.
|
\return 0 Interrupt status is not pending.
|
||||||
\return 1 Interrupt status is pending.
|
\return 1 Interrupt status is pending.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Pending Interrupt
|
\brief Set Pending Interrupt
|
||||||
\details Sets the pending bit of an external interrupt.
|
\details Sets the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn Interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Clear Pending Interrupt
|
\brief Clear Pending Interrupt
|
||||||
\details Clears the pending bit of an external interrupt.
|
\details Clears the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Active Interrupt
|
\brief Get Active Interrupt
|
||||||
\details Reads the active register in NVIC and returns the active bit.
|
\details Reads the active register in the NVIC and returns the active bit for the device specific interrupt.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
\return 0 Interrupt status is not active.
|
\return 0 Interrupt status is not active.
|
||||||
\return 1 Interrupt status is active.
|
\return 1 Interrupt status is active.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->IABR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Interrupt Priority
|
\brief Set Interrupt Priority
|
||||||
\details Sets the priority of an interrupt.
|
\details Sets the priority of a device specific interrupt or a processor exception.
|
||||||
\note The priority cannot be set for every core interrupt.
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\param [in] priority Priority to set.
|
\param [in] priority Priority to set.
|
||||||
|
\note The priority cannot be set for every processor exception.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
||||||
{
|
{
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
{
|
||||||
SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NVIC->IP[((uint32_t)(int32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Interrupt Priority
|
\brief Get Interrupt Priority
|
||||||
\details Reads the priority of an interrupt.
|
\details Reads the priority of a device specific interrupt or a processor exception.
|
||||||
The interrupt number can be positive to specify an external (device specific) interrupt,
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
or negative to specify an internal (core) interrupt.
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\return Interrupt Priority.
|
\return Interrupt Priority.
|
||||||
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
{
|
||||||
return(((uint32_t)SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS)));
|
return(((uint32_t)NVIC->IP[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return(((uint32_t)NVIC->IP[((uint32_t)(int32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS)));
|
return(((uint32_t)SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1783,11 +1892,42 @@ __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGr
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Set Interrupt Vector
|
||||||
|
\details Sets an interrupt vector in SRAM based interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
VTOR must been relocated to SRAM before.
|
||||||
|
\param [in] IRQn Interrupt number
|
||||||
|
\param [in] vector Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
|
||||||
|
{
|
||||||
|
uint32_t vectors = (uint32_t )SCB->VTOR;
|
||||||
|
(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Get Interrupt Vector
|
||||||
|
\details Reads an interrupt vector from interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
\param [in] IRQn Interrupt number.
|
||||||
|
\return Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
uint32_t vectors = (uint32_t )SCB->VTOR;
|
||||||
|
return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief System Reset
|
\brief System Reset
|
||||||
\details Initiates a system reset request to reset the MCU.
|
\details Initiates a system reset request to reset the MCU.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SystemReset(void)
|
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
|
||||||
{
|
{
|
||||||
__DSB(); /* Ensure all outstanding memory accesses included
|
__DSB(); /* Ensure all outstanding memory accesses included
|
||||||
buffered write are completed before reset */
|
buffered write are completed before reset */
|
||||||
@ -1805,6 +1945,50 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
/*@} end of CMSIS_Core_NVICFunctions */
|
/*@} end of CMSIS_Core_NVICFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
/* ########################## MPU functions #################################### */
|
||||||
|
|
||||||
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
|
|
||||||
|
#include "mpu_armv7.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* ########################## FPU functions #################################### */
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_Core_FunctionInterface
|
||||||
|
\defgroup CMSIS_Core_FpuFunctions FPU Functions
|
||||||
|
\brief Function that provides FPU type.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief get FPU type
|
||||||
|
\details returns the FPU type
|
||||||
|
\returns
|
||||||
|
- \b 0: No FPU
|
||||||
|
- \b 1: Single precision FPU
|
||||||
|
- \b 2: Double + Single precision FPU
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t SCB_GetFPUType(void)
|
||||||
|
{
|
||||||
|
uint32_t mvfr0;
|
||||||
|
|
||||||
|
mvfr0 = FPU->MVFR0;
|
||||||
|
if ((mvfr0 & (FPU_MVFR0_Single_precision_Msk | FPU_MVFR0_Double_precision_Msk)) == 0x020U)
|
||||||
|
{
|
||||||
|
return 1U; /* Single precision FPU */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0U; /* No FPU */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*@} end of CMSIS_Core_FpuFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ################################## SysTick function ############################################ */
|
/* ################################## SysTick function ############################################ */
|
||||||
/**
|
/**
|
||||||
@ -1814,7 +1998,7 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (__Vendor_SysTickConfig == 0U)
|
#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief System Tick Configuration
|
\brief System Tick Configuration
|
||||||
@ -1857,8 +2041,8 @@ __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */
|
extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */
|
||||||
#define ITM_RXBUFFER_EMPTY 0x5AA55AA5U /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */
|
#define ITM_RXBUFFER_EMPTY ((int32_t)0x5AA55AA5U) /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -1,87 +0,0 @@
|
|||||||
/**************************************************************************//**
|
|
||||||
* @file core_cmFunc.h
|
|
||||||
* @brief CMSIS Cortex-M Core Function Access Header File
|
|
||||||
* @version V4.30
|
|
||||||
* @date 20. October 2015
|
|
||||||
******************************************************************************/
|
|
||||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
|
||||||
|
|
||||||
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 ARM 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 COPYRIGHT HOLDERS AND 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.
|
|
||||||
---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __ICCARM__ )
|
|
||||||
#pragma system_include /* treat file as system include file for MISRA check */
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#pragma clang system_header /* treat file as system include file */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef __CORE_CMFUNC_H
|
|
||||||
#define __CORE_CMFUNC_H
|
|
||||||
|
|
||||||
|
|
||||||
/* ########################### Core Function Access ########################### */
|
|
||||||
/** \ingroup CMSIS_Core_FunctionInterface
|
|
||||||
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*------------------ RealView Compiler -----------------*/
|
|
||||||
#if defined ( __CC_ARM )
|
|
||||||
#include "cmsis_armcc.h"
|
|
||||||
|
|
||||||
/*------------------ ARM Compiler V6 -------------------*/
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#include "cmsis_armcc_V6.h"
|
|
||||||
|
|
||||||
/*------------------ GNU Compiler ----------------------*/
|
|
||||||
#elif defined ( __GNUC__ )
|
|
||||||
#include "cmsis_gcc.h"
|
|
||||||
|
|
||||||
/*------------------ ICC Compiler ----------------------*/
|
|
||||||
#elif defined ( __ICCARM__ )
|
|
||||||
#include <cmsis_iar.h>
|
|
||||||
|
|
||||||
/*------------------ TI CCS Compiler -------------------*/
|
|
||||||
#elif defined ( __TMS470__ )
|
|
||||||
#include <cmsis_ccs.h>
|
|
||||||
|
|
||||||
/*------------------ TASKING Compiler ------------------*/
|
|
||||||
#elif defined ( __TASKING__ )
|
|
||||||
/*
|
|
||||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
|
||||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
|
||||||
* Including the CMSIS ones.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*------------------ COSMIC Compiler -------------------*/
|
|
||||||
#elif defined ( __CSMC__ )
|
|
||||||
#include <cmsis_csm.h>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*@} end of CMSIS_Core_RegAccFunctions */
|
|
||||||
|
|
||||||
#endif /* __CORE_CMFUNC_H */
|
|
||||||
@ -1,87 +0,0 @@
|
|||||||
/**************************************************************************//**
|
|
||||||
* @file core_cmInstr.h
|
|
||||||
* @brief CMSIS Cortex-M Core Instruction Access Header File
|
|
||||||
* @version V4.30
|
|
||||||
* @date 20. October 2015
|
|
||||||
******************************************************************************/
|
|
||||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
|
||||||
|
|
||||||
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 ARM 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 COPYRIGHT HOLDERS AND 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.
|
|
||||||
---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __ICCARM__ )
|
|
||||||
#pragma system_include /* treat file as system include file for MISRA check */
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#pragma clang system_header /* treat file as system include file */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef __CORE_CMINSTR_H
|
|
||||||
#define __CORE_CMINSTR_H
|
|
||||||
|
|
||||||
|
|
||||||
/* ########################## Core Instruction Access ######################### */
|
|
||||||
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
|
|
||||||
Access to dedicated instructions
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*------------------ RealView Compiler -----------------*/
|
|
||||||
#if defined ( __CC_ARM )
|
|
||||||
#include "cmsis_armcc.h"
|
|
||||||
|
|
||||||
/*------------------ ARM Compiler V6 -------------------*/
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#include "cmsis_armcc_V6.h"
|
|
||||||
|
|
||||||
/*------------------ GNU Compiler ----------------------*/
|
|
||||||
#elif defined ( __GNUC__ )
|
|
||||||
#include "cmsis_gcc.h"
|
|
||||||
|
|
||||||
/*------------------ ICC Compiler ----------------------*/
|
|
||||||
#elif defined ( __ICCARM__ )
|
|
||||||
#include <cmsis_iar.h>
|
|
||||||
|
|
||||||
/*------------------ TI CCS Compiler -------------------*/
|
|
||||||
#elif defined ( __TMS470__ )
|
|
||||||
#include <cmsis_ccs.h>
|
|
||||||
|
|
||||||
/*------------------ TASKING Compiler ------------------*/
|
|
||||||
#elif defined ( __TASKING__ )
|
|
||||||
/*
|
|
||||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
|
||||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
|
||||||
* Including the CMSIS ones.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*------------------ COSMIC Compiler -------------------*/
|
|
||||||
#elif defined ( __CSMC__ )
|
|
||||||
#include <cmsis_csm.h>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
|
|
||||||
|
|
||||||
#endif /* __CORE_CMINSTR_H */
|
|
||||||
@ -1,96 +0,0 @@
|
|||||||
/**************************************************************************//**
|
|
||||||
* @file core_cmSimd.h
|
|
||||||
* @brief CMSIS Cortex-M SIMD Header File
|
|
||||||
* @version V4.30
|
|
||||||
* @date 20. October 2015
|
|
||||||
******************************************************************************/
|
|
||||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
|
||||||
|
|
||||||
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 ARM 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 COPYRIGHT HOLDERS AND 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.
|
|
||||||
---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __ICCARM__ )
|
|
||||||
#pragma system_include /* treat file as system include file for MISRA check */
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#pragma clang system_header /* treat file as system include file */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef __CORE_CMSIMD_H
|
|
||||||
#define __CORE_CMSIMD_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* ################### Compiler specific Intrinsics ########################### */
|
|
||||||
/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
|
|
||||||
Access to dedicated SIMD instructions
|
|
||||||
@{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*------------------ RealView Compiler -----------------*/
|
|
||||||
#if defined ( __CC_ARM )
|
|
||||||
#include "cmsis_armcc.h"
|
|
||||||
|
|
||||||
/*------------------ ARM Compiler V6 -------------------*/
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#include "cmsis_armcc_V6.h"
|
|
||||||
|
|
||||||
/*------------------ GNU Compiler ----------------------*/
|
|
||||||
#elif defined ( __GNUC__ )
|
|
||||||
#include "cmsis_gcc.h"
|
|
||||||
|
|
||||||
/*------------------ ICC Compiler ----------------------*/
|
|
||||||
#elif defined ( __ICCARM__ )
|
|
||||||
#include <cmsis_iar.h>
|
|
||||||
|
|
||||||
/*------------------ TI CCS Compiler -------------------*/
|
|
||||||
#elif defined ( __TMS470__ )
|
|
||||||
#include <cmsis_ccs.h>
|
|
||||||
|
|
||||||
/*------------------ TASKING Compiler ------------------*/
|
|
||||||
#elif defined ( __TASKING__ )
|
|
||||||
/*
|
|
||||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
|
||||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
|
||||||
* Including the CMSIS ones.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*------------------ COSMIC Compiler -------------------*/
|
|
||||||
#elif defined ( __CSMC__ )
|
|
||||||
#include <cmsis_csm.h>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*@} end of group CMSIS_SIMD_intrinsics */
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __CORE_CMSIMD_H */
|
|
||||||
@ -1,40 +1,30 @@
|
|||||||
/**************************************************************************//**
|
/**************************************************************************//**
|
||||||
* @file core_sc000.h
|
* @file core_sc000.h
|
||||||
* @brief CMSIS SC000 Core Peripheral Access Layer Header File
|
* @brief CMSIS SC000 Core Peripheral Access Layer Header File
|
||||||
* @version V4.30
|
* @version V5.0.6
|
||||||
* @date 20. October 2015
|
* @date 12. November 2018
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
/*
|
||||||
|
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
|
||||||
All rights reserved.
|
*
|
||||||
Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
modification, are permitted provided that the following conditions are met:
|
*
|
||||||
- Redistributions of source code must retain the above copyright
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
notice, this list of conditions and the following disclaimer.
|
* not use this file except in compliance with the License.
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
* You may obtain a copy of the License at
|
||||||
notice, this list of conditions and the following disclaimer in the
|
*
|
||||||
documentation and/or other materials provided with the distribution.
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
- Neither the name of ARM nor the names of its contributors may be used
|
*
|
||||||
to endorse or promote products derived from this software without
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
specific prior written permission.
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
*
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* See the License for the specific language governing permissions and
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* limitations under the License.
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
*/
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND 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.
|
|
||||||
---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __ICCARM__ )
|
#if defined ( __ICCARM__ )
|
||||||
#pragma system_include /* treat file as system include file for MISRA check */
|
#pragma system_include /* treat file as system include file for MISRA check */
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__clang__)
|
||||||
#pragma clang system_header /* treat file as system include file */
|
#pragma clang system_header /* treat file as system include file */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -70,53 +60,15 @@
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "cmsis_version.h"
|
||||||
|
|
||||||
/* CMSIS SC000 definitions */
|
/* CMSIS SC000 definitions */
|
||||||
#define __SC000_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */
|
#define __SC000_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
|
||||||
#define __SC000_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */
|
#define __SC000_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
|
||||||
#define __SC000_CMSIS_VERSION ((__SC000_CMSIS_VERSION_MAIN << 16U) | \
|
#define __SC000_CMSIS_VERSION ((__SC000_CMSIS_VERSION_MAIN << 16U) | \
|
||||||
__SC000_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
|
__SC000_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
|
||||||
|
|
||||||
#define __CORTEX_SC (000U) /*!< Cortex secure core */
|
#define __CORTEX_SC (000U) /*!< Cortex secure core */
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __CC_ARM )
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined ( __GNUC__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for GNU Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __ICCARM__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for IAR Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TASKING__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __CSMC__ )
|
|
||||||
#define __packed
|
|
||||||
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error Unknown compiler
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** __FPU_USED indicates whether an FPU is used or not.
|
/** __FPU_USED indicates whether an FPU is used or not.
|
||||||
This core does not support an FPU at all
|
This core does not support an FPU at all
|
||||||
@ -128,8 +80,8 @@
|
|||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||||
#if defined __ARM_PCS_VFP
|
#if defined __ARM_FP
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -143,7 +95,7 @@
|
|||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
#elif defined ( __TI_ARM__ )
|
||||||
#if defined __TI_VFP_SUPPORT__
|
#if defined __TI_VFP_SUPPORT__
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
@ -160,8 +112,8 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "core_cmInstr.h" /* Core Instruction Access */
|
#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
|
||||||
#include "core_cmFunc.h" /* Core Function Access */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@ -569,7 +521,7 @@ typedef struct
|
|||||||
|
|
||||||
/*@} end of group CMSIS_SysTick */
|
/*@} end of group CMSIS_SysTick */
|
||||||
|
|
||||||
#if (__MPU_PRESENT == 1U)
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
/**
|
/**
|
||||||
\ingroup CMSIS_core_register
|
\ingroup CMSIS_core_register
|
||||||
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
||||||
@ -678,18 +630,18 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
\brief Mask and shift a bit field value for use in a register bit range.
|
\brief Mask and shift a bit field value for use in a register bit range.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of the bit field.
|
\param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted value.
|
\return Masked and shifted value.
|
||||||
*/
|
*/
|
||||||
#define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk)
|
#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Mask and shift a register value to extract a bit filed value.
|
\brief Mask and shift a register value to extract a bit filed value.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of register.
|
\param[in] value Value of register. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted bit field value.
|
\return Masked and shifted bit field value.
|
||||||
*/
|
*/
|
||||||
#define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos)
|
#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
|
||||||
|
|
||||||
/*@} end of group CMSIS_core_bitfield */
|
/*@} end of group CMSIS_core_bitfield */
|
||||||
|
|
||||||
@ -701,7 +653,7 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Memory mapping of SC000 Hardware */
|
/* Memory mapping of Core Hardware */
|
||||||
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
||||||
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
|
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
|
||||||
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
|
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
|
||||||
@ -712,7 +664,7 @@ typedef struct
|
|||||||
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
|
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
|
||||||
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
|
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
|
||||||
|
|
||||||
#if (__MPU_PRESENT == 1U)
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
||||||
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
||||||
#endif
|
#endif
|
||||||
@ -742,7 +694,46 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Interrupt Priorities are WORD accessible only under ARMv6M */
|
#ifdef CMSIS_NVIC_VIRTUAL
|
||||||
|
#ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
/*#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping not available for SC000 */
|
||||||
|
/*#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping not available for SC000 */
|
||||||
|
#define NVIC_EnableIRQ __NVIC_EnableIRQ
|
||||||
|
#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
|
||||||
|
#define NVIC_DisableIRQ __NVIC_DisableIRQ
|
||||||
|
#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
|
||||||
|
#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
|
||||||
|
#define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
|
||||||
|
/*#define NVIC_GetActive __NVIC_GetActive not available for SC000 */
|
||||||
|
#define NVIC_SetPriority __NVIC_SetPriority
|
||||||
|
#define NVIC_GetPriority __NVIC_GetPriority
|
||||||
|
#define NVIC_SystemReset __NVIC_SystemReset
|
||||||
|
#endif /* CMSIS_NVIC_VIRTUAL */
|
||||||
|
|
||||||
|
#ifdef CMSIS_VECTAB_VIRTUAL
|
||||||
|
#ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetVector __NVIC_SetVector
|
||||||
|
#define NVIC_GetVector __NVIC_GetVector
|
||||||
|
#endif /* (CMSIS_VECTAB_VIRTUAL) */
|
||||||
|
|
||||||
|
#define NVIC_USER_IRQ_OFFSET 16
|
||||||
|
|
||||||
|
|
||||||
|
/* The following EXC_RETURN values are saved the LR on exception entry */
|
||||||
|
#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
|
||||||
|
|
||||||
|
|
||||||
|
/* Interrupt Priorities are WORD accessible only under Armv6-M */
|
||||||
/* The following MACROS handle generation of the register offset and byte masks */
|
/* The following MACROS handle generation of the register offset and byte masks */
|
||||||
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
|
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
|
||||||
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
|
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
|
||||||
@ -750,79 +741,128 @@ typedef struct
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Enable External Interrupt
|
\brief Enable Interrupt
|
||||||
\details Enables a device-specific interrupt in the NVIC interrupt controller.
|
\details Enables a device specific interrupt in the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Disable External Interrupt
|
\brief Get Interrupt Enable status
|
||||||
\details Disables a device-specific interrupt in the NVIC interrupt controller.
|
\details Returns a device specific interrupt enable status from the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\return 0 Interrupt is not enabled.
|
||||||
|
\return 1 Interrupt is enabled.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Disable Interrupt
|
||||||
|
\details Disables a device specific interrupt in the NVIC interrupt controller.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Pending Interrupt
|
\brief Get Pending Interrupt
|
||||||
\details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt.
|
\details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
\return 0 Interrupt status is not pending.
|
\return 0 Interrupt status is not pending.
|
||||||
\return 1 Interrupt status is pending.
|
\return 1 Interrupt status is pending.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Pending Interrupt
|
\brief Set Pending Interrupt
|
||||||
\details Sets the pending bit of an external interrupt.
|
\details Sets the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn Interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Clear Pending Interrupt
|
\brief Clear Pending Interrupt
|
||||||
\details Clears the pending bit of an external interrupt.
|
\details Clears the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Interrupt Priority
|
\brief Set Interrupt Priority
|
||||||
\details Sets the priority of an interrupt.
|
\details Sets the priority of a device specific interrupt or a processor exception.
|
||||||
\note The priority cannot be set for every core interrupt.
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\param [in] priority Priority to set.
|
\param [in] priority Priority to set.
|
||||||
|
\note The priority cannot be set for every processor exception.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
||||||
{
|
{
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
{
|
||||||
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||||
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
|
||||||
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -830,24 +870,55 @@ __STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Interrupt Priority
|
\brief Get Interrupt Priority
|
||||||
\details Reads the priority of an interrupt.
|
\details Reads the priority of a device specific interrupt or a processor exception.
|
||||||
The interrupt number can be positive to specify an external (device specific) interrupt,
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
or negative to specify an internal (core) interrupt.
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\return Interrupt Priority.
|
\return Interrupt Priority.
|
||||||
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
|
||||||
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Set Interrupt Vector
|
||||||
|
\details Sets an interrupt vector in SRAM based interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
VTOR must been relocated to SRAM before.
|
||||||
|
\param [in] IRQn Interrupt number
|
||||||
|
\param [in] vector Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
|
||||||
|
{
|
||||||
|
uint32_t *vectors = (uint32_t *)SCB->VTOR;
|
||||||
|
vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Get Interrupt Vector
|
||||||
|
\details Reads an interrupt vector from interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
\param [in] IRQn Interrupt number.
|
||||||
|
\return Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
uint32_t *vectors = (uint32_t *)SCB->VTOR;
|
||||||
|
return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -855,7 +926,7 @@ __STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
|||||||
\brief System Reset
|
\brief System Reset
|
||||||
\details Initiates a system reset request to reset the MCU.
|
\details Initiates a system reset request to reset the MCU.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SystemReset(void)
|
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
|
||||||
{
|
{
|
||||||
__DSB(); /* Ensure all outstanding memory accesses included
|
__DSB(); /* Ensure all outstanding memory accesses included
|
||||||
buffered write are completed before reset */
|
buffered write are completed before reset */
|
||||||
@ -872,6 +943,31 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
/*@} end of CMSIS_Core_NVICFunctions */
|
/*@} end of CMSIS_Core_NVICFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
/* ########################## FPU functions #################################### */
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_Core_FunctionInterface
|
||||||
|
\defgroup CMSIS_Core_FpuFunctions FPU Functions
|
||||||
|
\brief Function that provides FPU type.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief get FPU type
|
||||||
|
\details returns the FPU type
|
||||||
|
\returns
|
||||||
|
- \b 0: No FPU
|
||||||
|
- \b 1: Single precision FPU
|
||||||
|
- \b 2: Double + Single precision FPU
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t SCB_GetFPUType(void)
|
||||||
|
{
|
||||||
|
return 0U; /* No FPU */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*@} end of CMSIS_Core_FpuFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ################################## SysTick function ############################################ */
|
/* ################################## SysTick function ############################################ */
|
||||||
/**
|
/**
|
||||||
@ -881,7 +977,7 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (__Vendor_SysTickConfig == 0U)
|
#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief System Tick Configuration
|
\brief System Tick Configuration
|
||||||
|
|||||||
@ -1,40 +1,30 @@
|
|||||||
/**************************************************************************//**
|
/**************************************************************************//**
|
||||||
* @file core_sc300.h
|
* @file core_sc300.h
|
||||||
* @brief CMSIS SC300 Core Peripheral Access Layer Header File
|
* @brief CMSIS SC300 Core Peripheral Access Layer Header File
|
||||||
* @version V4.30
|
* @version V5.0.7
|
||||||
* @date 20. October 2015
|
* @date 12. November 2018
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
/* Copyright (c) 2009 - 2015 ARM LIMITED
|
/*
|
||||||
|
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
|
||||||
All rights reserved.
|
*
|
||||||
Redistribution and use in source and binary forms, with or without
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
modification, are permitted provided that the following conditions are met:
|
*
|
||||||
- Redistributions of source code must retain the above copyright
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
notice, this list of conditions and the following disclaimer.
|
* not use this file except in compliance with the License.
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
* You may obtain a copy of the License at
|
||||||
notice, this list of conditions and the following disclaimer in the
|
*
|
||||||
documentation and/or other materials provided with the distribution.
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
- Neither the name of ARM nor the names of its contributors may be used
|
*
|
||||||
to endorse or promote products derived from this software without
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
specific prior written permission.
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
*
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* See the License for the specific language governing permissions and
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* limitations under the License.
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
*/
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND 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.
|
|
||||||
---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __ICCARM__ )
|
#if defined ( __ICCARM__ )
|
||||||
#pragma system_include /* treat file as system include file for MISRA check */
|
#pragma system_include /* treat file as system include file for MISRA check */
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__clang__)
|
||||||
#pragma clang system_header /* treat file as system include file */
|
#pragma clang system_header /* treat file as system include file */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -70,53 +60,15 @@
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "cmsis_version.h"
|
||||||
|
|
||||||
/* CMSIS SC300 definitions */
|
/* CMSIS SC300 definitions */
|
||||||
#define __SC300_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */
|
#define __SC300_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
|
||||||
#define __SC300_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */
|
#define __SC300_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
|
||||||
#define __SC300_CMSIS_VERSION ((__SC300_CMSIS_VERSION_MAIN << 16U) | \
|
#define __SC300_CMSIS_VERSION ((__SC300_CMSIS_VERSION_MAIN << 16U) | \
|
||||||
__SC300_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */
|
__SC300_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
|
||||||
|
|
||||||
#define __CORTEX_SC (300U) /*!< Cortex secure core */
|
#define __CORTEX_SC (300U) /*!< Cortex secure core */
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __CC_ARM )
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
|
||||||
#define __ASM __asm /*!< asm keyword for ARM Compiler */
|
|
||||||
#define __INLINE __inline /*!< inline keyword for ARM Compiler */
|
|
||||||
#define __STATIC_INLINE static __inline
|
|
||||||
|
|
||||||
#elif defined ( __GNUC__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for GNU Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __ICCARM__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for IAR Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TI CCS Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __TASKING__ )
|
|
||||||
#define __ASM __asm /*!< asm keyword for TASKING Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#elif defined ( __CSMC__ )
|
|
||||||
#define __packed
|
|
||||||
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
|
|
||||||
#define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */
|
|
||||||
#define __STATIC_INLINE static inline
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error Unknown compiler
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** __FPU_USED indicates whether an FPU is used or not.
|
/** __FPU_USED indicates whether an FPU is used or not.
|
||||||
This core does not support an FPU at all
|
This core does not support an FPU at all
|
||||||
@ -128,8 +80,8 @@
|
|||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||||
#if defined __ARM_PCS_VFP
|
#if defined __ARM_FP
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -143,7 +95,7 @@
|
|||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined ( __TMS470__ )
|
#elif defined ( __TI_ARM__ )
|
||||||
#if defined __TI_VFP_SUPPORT__
|
#if defined __TI_VFP_SUPPORT__
|
||||||
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
|
||||||
#endif
|
#endif
|
||||||
@ -160,8 +112,8 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "core_cmInstr.h" /* Core Instruction Access */
|
#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
|
||||||
#include "core_cmFunc.h" /* Core Function Access */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
@ -191,7 +143,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __NVIC_PRIO_BITS
|
#ifndef __NVIC_PRIO_BITS
|
||||||
#define __NVIC_PRIO_BITS 4U
|
#define __NVIC_PRIO_BITS 3U
|
||||||
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
|
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -308,9 +260,11 @@ typedef union
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
|
||||||
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
|
uint32_t _reserved0:1; /*!< bit: 9 Reserved */
|
||||||
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
|
uint32_t ICI_IT_1:6; /*!< bit: 10..15 ICI/IT part 1 */
|
||||||
uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */
|
uint32_t _reserved1:8; /*!< bit: 16..23 Reserved */
|
||||||
|
uint32_t T:1; /*!< bit: 24 Thumb bit */
|
||||||
|
uint32_t ICI_IT_2:2; /*!< bit: 25..26 ICI/IT part 2 */
|
||||||
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
|
uint32_t Q:1; /*!< bit: 27 Saturation condition flag */
|
||||||
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
|
||||||
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
|
||||||
@ -336,12 +290,15 @@ typedef union
|
|||||||
#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */
|
#define xPSR_Q_Pos 27U /*!< xPSR: Q Position */
|
||||||
#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */
|
#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */
|
||||||
|
|
||||||
#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */
|
#define xPSR_ICI_IT_2_Pos 25U /*!< xPSR: ICI/IT part 2 Position */
|
||||||
#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT Mask */
|
#define xPSR_ICI_IT_2_Msk (3UL << xPSR_ICI_IT_2_Pos) /*!< xPSR: ICI/IT part 2 Mask */
|
||||||
|
|
||||||
#define xPSR_T_Pos 24U /*!< xPSR: T Position */
|
#define xPSR_T_Pos 24U /*!< xPSR: T Position */
|
||||||
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
|
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
|
||||||
|
|
||||||
|
#define xPSR_ICI_IT_1_Pos 10U /*!< xPSR: ICI/IT part 1 Position */
|
||||||
|
#define xPSR_ICI_IT_1_Msk (0x3FUL << xPSR_ICI_IT_1_Pos) /*!< xPSR: ICI/IT part 1 Mask */
|
||||||
|
|
||||||
#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
|
#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
|
||||||
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
|
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
|
||||||
|
|
||||||
@ -599,6 +556,60 @@ typedef struct
|
|||||||
#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */
|
#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */
|
||||||
#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
|
#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */
|
||||||
|
|
||||||
|
/* MemManage Fault Status Register (part of SCB Configurable Fault Status Register) */
|
||||||
|
#define SCB_CFSR_MMARVALID_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 7U) /*!< SCB CFSR (MMFSR): MMARVALID Position */
|
||||||
|
#define SCB_CFSR_MMARVALID_Msk (1UL << SCB_CFSR_MMARVALID_Pos) /*!< SCB CFSR (MMFSR): MMARVALID Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_MSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 4U) /*!< SCB CFSR (MMFSR): MSTKERR Position */
|
||||||
|
#define SCB_CFSR_MSTKERR_Msk (1UL << SCB_CFSR_MSTKERR_Pos) /*!< SCB CFSR (MMFSR): MSTKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_MUNSTKERR_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 3U) /*!< SCB CFSR (MMFSR): MUNSTKERR Position */
|
||||||
|
#define SCB_CFSR_MUNSTKERR_Msk (1UL << SCB_CFSR_MUNSTKERR_Pos) /*!< SCB CFSR (MMFSR): MUNSTKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_DACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 1U) /*!< SCB CFSR (MMFSR): DACCVIOL Position */
|
||||||
|
#define SCB_CFSR_DACCVIOL_Msk (1UL << SCB_CFSR_DACCVIOL_Pos) /*!< SCB CFSR (MMFSR): DACCVIOL Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_IACCVIOL_Pos (SCB_SHCSR_MEMFAULTACT_Pos + 0U) /*!< SCB CFSR (MMFSR): IACCVIOL Position */
|
||||||
|
#define SCB_CFSR_IACCVIOL_Msk (1UL /*<< SCB_CFSR_IACCVIOL_Pos*/) /*!< SCB CFSR (MMFSR): IACCVIOL Mask */
|
||||||
|
|
||||||
|
/* BusFault Status Register (part of SCB Configurable Fault Status Register) */
|
||||||
|
#define SCB_CFSR_BFARVALID_Pos (SCB_CFSR_BUSFAULTSR_Pos + 7U) /*!< SCB CFSR (BFSR): BFARVALID Position */
|
||||||
|
#define SCB_CFSR_BFARVALID_Msk (1UL << SCB_CFSR_BFARVALID_Pos) /*!< SCB CFSR (BFSR): BFARVALID Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_STKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 4U) /*!< SCB CFSR (BFSR): STKERR Position */
|
||||||
|
#define SCB_CFSR_STKERR_Msk (1UL << SCB_CFSR_STKERR_Pos) /*!< SCB CFSR (BFSR): STKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_UNSTKERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 3U) /*!< SCB CFSR (BFSR): UNSTKERR Position */
|
||||||
|
#define SCB_CFSR_UNSTKERR_Msk (1UL << SCB_CFSR_UNSTKERR_Pos) /*!< SCB CFSR (BFSR): UNSTKERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_IMPRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 2U) /*!< SCB CFSR (BFSR): IMPRECISERR Position */
|
||||||
|
#define SCB_CFSR_IMPRECISERR_Msk (1UL << SCB_CFSR_IMPRECISERR_Pos) /*!< SCB CFSR (BFSR): IMPRECISERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_PRECISERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 1U) /*!< SCB CFSR (BFSR): PRECISERR Position */
|
||||||
|
#define SCB_CFSR_PRECISERR_Msk (1UL << SCB_CFSR_PRECISERR_Pos) /*!< SCB CFSR (BFSR): PRECISERR Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_IBUSERR_Pos (SCB_CFSR_BUSFAULTSR_Pos + 0U) /*!< SCB CFSR (BFSR): IBUSERR Position */
|
||||||
|
#define SCB_CFSR_IBUSERR_Msk (1UL << SCB_CFSR_IBUSERR_Pos) /*!< SCB CFSR (BFSR): IBUSERR Mask */
|
||||||
|
|
||||||
|
/* UsageFault Status Register (part of SCB Configurable Fault Status Register) */
|
||||||
|
#define SCB_CFSR_DIVBYZERO_Pos (SCB_CFSR_USGFAULTSR_Pos + 9U) /*!< SCB CFSR (UFSR): DIVBYZERO Position */
|
||||||
|
#define SCB_CFSR_DIVBYZERO_Msk (1UL << SCB_CFSR_DIVBYZERO_Pos) /*!< SCB CFSR (UFSR): DIVBYZERO Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_UNALIGNED_Pos (SCB_CFSR_USGFAULTSR_Pos + 8U) /*!< SCB CFSR (UFSR): UNALIGNED Position */
|
||||||
|
#define SCB_CFSR_UNALIGNED_Msk (1UL << SCB_CFSR_UNALIGNED_Pos) /*!< SCB CFSR (UFSR): UNALIGNED Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_NOCP_Pos (SCB_CFSR_USGFAULTSR_Pos + 3U) /*!< SCB CFSR (UFSR): NOCP Position */
|
||||||
|
#define SCB_CFSR_NOCP_Msk (1UL << SCB_CFSR_NOCP_Pos) /*!< SCB CFSR (UFSR): NOCP Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_INVPC_Pos (SCB_CFSR_USGFAULTSR_Pos + 2U) /*!< SCB CFSR (UFSR): INVPC Position */
|
||||||
|
#define SCB_CFSR_INVPC_Msk (1UL << SCB_CFSR_INVPC_Pos) /*!< SCB CFSR (UFSR): INVPC Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_INVSTATE_Pos (SCB_CFSR_USGFAULTSR_Pos + 1U) /*!< SCB CFSR (UFSR): INVSTATE Position */
|
||||||
|
#define SCB_CFSR_INVSTATE_Msk (1UL << SCB_CFSR_INVSTATE_Pos) /*!< SCB CFSR (UFSR): INVSTATE Mask */
|
||||||
|
|
||||||
|
#define SCB_CFSR_UNDEFINSTR_Pos (SCB_CFSR_USGFAULTSR_Pos + 0U) /*!< SCB CFSR (UFSR): UNDEFINSTR Position */
|
||||||
|
#define SCB_CFSR_UNDEFINSTR_Msk (1UL << SCB_CFSR_UNDEFINSTR_Pos) /*!< SCB CFSR (UFSR): UNDEFINSTR Mask */
|
||||||
|
|
||||||
/* SCB Hard Fault Status Register Definitions */
|
/* SCB Hard Fault Status Register Definitions */
|
||||||
#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */
|
#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */
|
||||||
#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
|
#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */
|
||||||
@ -966,7 +977,7 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
__IOM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */
|
__IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */
|
||||||
__IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */
|
__IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */
|
||||||
uint32_t RESERVED0[2U];
|
uint32_t RESERVED0[2U];
|
||||||
__IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */
|
__IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */
|
||||||
@ -977,7 +988,7 @@ typedef struct
|
|||||||
__IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */
|
__IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */
|
||||||
__IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */
|
__IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */
|
||||||
uint32_t RESERVED3[759U];
|
uint32_t RESERVED3[759U];
|
||||||
__IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER */
|
__IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER Register */
|
||||||
__IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */
|
__IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */
|
||||||
__IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */
|
__IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */
|
||||||
uint32_t RESERVED4[1U];
|
uint32_t RESERVED4[1U];
|
||||||
@ -1047,8 +1058,11 @@ typedef struct
|
|||||||
#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */
|
#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */
|
||||||
|
|
||||||
/* TPI ITATBCTR2 Register Definitions */
|
/* TPI ITATBCTR2 Register Definitions */
|
||||||
#define TPI_ITATBCTR2_ATREADY_Pos 0U /*!< TPI ITATBCTR2: ATREADY Position */
|
#define TPI_ITATBCTR2_ATREADY2_Pos 0U /*!< TPI ITATBCTR2: ATREADY2 Position */
|
||||||
#define TPI_ITATBCTR2_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY_Pos*/) /*!< TPI ITATBCTR2: ATREADY Mask */
|
#define TPI_ITATBCTR2_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY2_Pos*/) /*!< TPI ITATBCTR2: ATREADY2 Mask */
|
||||||
|
|
||||||
|
#define TPI_ITATBCTR2_ATREADY1_Pos 0U /*!< TPI ITATBCTR2: ATREADY1 Position */
|
||||||
|
#define TPI_ITATBCTR2_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY1_Pos*/) /*!< TPI ITATBCTR2: ATREADY1 Mask */
|
||||||
|
|
||||||
/* TPI Integration ITM Data Register Definitions (FIFO1) */
|
/* TPI Integration ITM Data Register Definitions (FIFO1) */
|
||||||
#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */
|
#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */
|
||||||
@ -1073,12 +1087,15 @@ typedef struct
|
|||||||
#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */
|
#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */
|
||||||
|
|
||||||
/* TPI ITATBCTR0 Register Definitions */
|
/* TPI ITATBCTR0 Register Definitions */
|
||||||
#define TPI_ITATBCTR0_ATREADY_Pos 0U /*!< TPI ITATBCTR0: ATREADY Position */
|
#define TPI_ITATBCTR0_ATREADY2_Pos 0U /*!< TPI ITATBCTR0: ATREADY2 Position */
|
||||||
#define TPI_ITATBCTR0_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY_Pos*/) /*!< TPI ITATBCTR0: ATREADY Mask */
|
#define TPI_ITATBCTR0_ATREADY2_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY2_Pos*/) /*!< TPI ITATBCTR0: ATREADY2 Mask */
|
||||||
|
|
||||||
|
#define TPI_ITATBCTR0_ATREADY1_Pos 0U /*!< TPI ITATBCTR0: ATREADY1 Position */
|
||||||
|
#define TPI_ITATBCTR0_ATREADY1_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY1_Pos*/) /*!< TPI ITATBCTR0: ATREADY1 Mask */
|
||||||
|
|
||||||
/* TPI Integration Mode Control Register Definitions */
|
/* TPI Integration Mode Control Register Definitions */
|
||||||
#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */
|
#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */
|
||||||
#define TPI_ITCTRL_Mode_Msk (0x1UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */
|
#define TPI_ITCTRL_Mode_Msk (0x3UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */
|
||||||
|
|
||||||
/* TPI DEVID Register Definitions */
|
/* TPI DEVID Register Definitions */
|
||||||
#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */
|
#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */
|
||||||
@ -1100,16 +1117,16 @@ typedef struct
|
|||||||
#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */
|
#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */
|
||||||
|
|
||||||
/* TPI DEVTYPE Register Definitions */
|
/* TPI DEVTYPE Register Definitions */
|
||||||
#define TPI_DEVTYPE_MajorType_Pos 4U /*!< TPI DEVTYPE: MajorType Position */
|
#define TPI_DEVTYPE_SubType_Pos 4U /*!< TPI DEVTYPE: SubType Position */
|
||||||
#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */
|
|
||||||
|
|
||||||
#define TPI_DEVTYPE_SubType_Pos 0U /*!< TPI DEVTYPE: SubType Position */
|
|
||||||
#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */
|
#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */
|
||||||
|
|
||||||
|
#define TPI_DEVTYPE_MajorType_Pos 0U /*!< TPI DEVTYPE: MajorType Position */
|
||||||
|
#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */
|
||||||
|
|
||||||
/*@}*/ /* end of group CMSIS_TPI */
|
/*@}*/ /* end of group CMSIS_TPI */
|
||||||
|
|
||||||
|
|
||||||
#if (__MPU_PRESENT == 1U)
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
/**
|
/**
|
||||||
\ingroup CMSIS_core_register
|
\ingroup CMSIS_core_register
|
||||||
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
\defgroup CMSIS_MPU Memory Protection Unit (MPU)
|
||||||
@ -1319,18 +1336,18 @@ typedef struct
|
|||||||
/**
|
/**
|
||||||
\brief Mask and shift a bit field value for use in a register bit range.
|
\brief Mask and shift a bit field value for use in a register bit range.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of the bit field.
|
\param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted value.
|
\return Masked and shifted value.
|
||||||
*/
|
*/
|
||||||
#define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk)
|
#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Mask and shift a register value to extract a bit filed value.
|
\brief Mask and shift a register value to extract a bit filed value.
|
||||||
\param[in] field Name of the register bit field.
|
\param[in] field Name of the register bit field.
|
||||||
\param[in] value Value of register.
|
\param[in] value Value of register. This parameter is interpreted as an uint32_t type.
|
||||||
\return Masked and shifted bit field value.
|
\return Masked and shifted bit field value.
|
||||||
*/
|
*/
|
||||||
#define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos)
|
#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
|
||||||
|
|
||||||
/*@} end of group CMSIS_core_bitfield */
|
/*@} end of group CMSIS_core_bitfield */
|
||||||
|
|
||||||
@ -1342,7 +1359,7 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Memory mapping of Cortex-M3 Hardware */
|
/* Memory mapping of Core Hardware */
|
||||||
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
|
||||||
#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
|
#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */
|
||||||
#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
|
#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
|
||||||
@ -1361,7 +1378,7 @@ typedef struct
|
|||||||
#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */
|
#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */
|
||||||
#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
|
#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
|
||||||
|
|
||||||
#if (__MPU_PRESENT == 1U)
|
#if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U)
|
||||||
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */
|
||||||
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */
|
||||||
#endif
|
#endif
|
||||||
@ -1392,6 +1409,46 @@ typedef struct
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef CMSIS_NVIC_VIRTUAL
|
||||||
|
#ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_NVIC_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
|
||||||
|
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
|
||||||
|
#define NVIC_EnableIRQ __NVIC_EnableIRQ
|
||||||
|
#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
|
||||||
|
#define NVIC_DisableIRQ __NVIC_DisableIRQ
|
||||||
|
#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
|
||||||
|
#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
|
||||||
|
#define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
|
||||||
|
#define NVIC_GetActive __NVIC_GetActive
|
||||||
|
#define NVIC_SetPriority __NVIC_SetPriority
|
||||||
|
#define NVIC_GetPriority __NVIC_GetPriority
|
||||||
|
#define NVIC_SystemReset __NVIC_SystemReset
|
||||||
|
#endif /* CMSIS_NVIC_VIRTUAL */
|
||||||
|
|
||||||
|
#ifdef CMSIS_VECTAB_VIRTUAL
|
||||||
|
#ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
|
||||||
|
#endif
|
||||||
|
#include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
|
||||||
|
#else
|
||||||
|
#define NVIC_SetVector __NVIC_SetVector
|
||||||
|
#define NVIC_GetVector __NVIC_GetVector
|
||||||
|
#endif /* (CMSIS_VECTAB_VIRTUAL) */
|
||||||
|
|
||||||
|
#define NVIC_USER_IRQ_OFFSET 16
|
||||||
|
|
||||||
|
|
||||||
|
/* The following EXC_RETURN values are saved the LR on exception entry */
|
||||||
|
#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
|
||||||
|
#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Priority Grouping
|
\brief Set Priority Grouping
|
||||||
\details Sets the priority grouping field using the required unlock sequence.
|
\details Sets the priority grouping field using the required unlock sequence.
|
||||||
@ -1401,7 +1458,7 @@ typedef struct
|
|||||||
priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
|
priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
|
||||||
\param [in] PriorityGroup Priority grouping field.
|
\param [in] PriorityGroup Priority grouping field.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
||||||
{
|
{
|
||||||
uint32_t reg_value;
|
uint32_t reg_value;
|
||||||
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
|
||||||
@ -1420,121 +1477,178 @@ __STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
|||||||
\details Reads the priority grouping field from the NVIC Interrupt Controller.
|
\details Reads the priority grouping field from the NVIC Interrupt Controller.
|
||||||
\return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field).
|
\return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field).
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void)
|
__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void)
|
||||||
{
|
{
|
||||||
return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos));
|
return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Enable External Interrupt
|
\brief Enable Interrupt
|
||||||
\details Enables a device-specific interrupt in the NVIC interrupt controller.
|
\details Enables a device specific interrupt in the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Disable External Interrupt
|
\brief Get Interrupt Enable status
|
||||||
\details Disables a device-specific interrupt in the NVIC interrupt controller.
|
\details Returns a device specific interrupt enable status from the NVIC interrupt controller.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\return 0 Interrupt is not enabled.
|
||||||
|
\return 1 Interrupt is enabled.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Disable Interrupt
|
||||||
|
\details Disables a device specific interrupt in the NVIC interrupt controller.
|
||||||
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Pending Interrupt
|
\brief Get Pending Interrupt
|
||||||
\details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt.
|
\details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
\return 0 Interrupt status is not pending.
|
\return 0 Interrupt status is not pending.
|
||||||
\return 1 Interrupt status is pending.
|
\return 1 Interrupt status is pending.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Pending Interrupt
|
\brief Set Pending Interrupt
|
||||||
\details Sets the pending bit of an external interrupt.
|
\details Sets the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn Interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Clear Pending Interrupt
|
\brief Clear Pending Interrupt
|
||||||
\details Clears the pending bit of an external interrupt.
|
\details Clears the pending bit of a device specific interrupt in the NVIC pending register.
|
||||||
\param [in] IRQn External interrupt number. Value cannot be negative.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
NVIC->ICPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Active Interrupt
|
\brief Get Active Interrupt
|
||||||
\details Reads the active register in NVIC and returns the active bit.
|
\details Reads the active register in the NVIC and returns the active bit for the device specific interrupt.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Device specific interrupt number.
|
||||||
\return 0 Interrupt status is not active.
|
\return 0 Interrupt status is not active.
|
||||||
\return 1 Interrupt status is active.
|
\return 1 Interrupt status is active.
|
||||||
|
\note IRQn must not be negative.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
return((uint32_t)(((NVIC->IABR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
if ((int32_t)(IRQn) >= 0)
|
||||||
|
{
|
||||||
|
return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return(0U);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Set Interrupt Priority
|
\brief Set Interrupt Priority
|
||||||
\details Sets the priority of an interrupt.
|
\details Sets the priority of a device specific interrupt or a processor exception.
|
||||||
\note The priority cannot be set for every core interrupt.
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\param [in] priority Priority to set.
|
\param [in] priority Priority to set.
|
||||||
|
\note The priority cannot be set for every processor exception.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
||||||
{
|
{
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
{
|
||||||
SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NVIC->IP[((uint32_t)(int32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Get Interrupt Priority
|
\brief Get Interrupt Priority
|
||||||
\details Reads the priority of an interrupt.
|
\details Reads the priority of a device specific interrupt or a processor exception.
|
||||||
The interrupt number can be positive to specify an external (device specific) interrupt,
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
or negative to specify an internal (core) interrupt.
|
or negative to specify a processor exception.
|
||||||
\param [in] IRQn Interrupt number.
|
\param [in] IRQn Interrupt number.
|
||||||
\return Interrupt Priority.
|
\return Interrupt Priority.
|
||||||
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
Value is aligned automatically to the implemented priority bits of the microcontroller.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((int32_t)(IRQn) < 0)
|
if ((int32_t)(IRQn) >= 0)
|
||||||
{
|
{
|
||||||
return(((uint32_t)SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS)));
|
return(((uint32_t)NVIC->IP[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return(((uint32_t)NVIC->IP[((uint32_t)(int32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS)));
|
return(((uint32_t)SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1591,11 +1705,42 @@ __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGr
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Set Interrupt Vector
|
||||||
|
\details Sets an interrupt vector in SRAM based interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
VTOR must been relocated to SRAM before.
|
||||||
|
\param [in] IRQn Interrupt number
|
||||||
|
\param [in] vector Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
|
||||||
|
{
|
||||||
|
uint32_t *vectors = (uint32_t *)SCB->VTOR;
|
||||||
|
vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief Get Interrupt Vector
|
||||||
|
\details Reads an interrupt vector from interrupt vector table.
|
||||||
|
The interrupt number can be positive to specify a device specific interrupt,
|
||||||
|
or negative to specify a processor exception.
|
||||||
|
\param [in] IRQn Interrupt number.
|
||||||
|
\return Address of interrupt handler function
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
|
||||||
|
{
|
||||||
|
uint32_t *vectors = (uint32_t *)SCB->VTOR;
|
||||||
|
return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief System Reset
|
\brief System Reset
|
||||||
\details Initiates a system reset request to reset the MCU.
|
\details Initiates a system reset request to reset the MCU.
|
||||||
*/
|
*/
|
||||||
__STATIC_INLINE void NVIC_SystemReset(void)
|
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
|
||||||
{
|
{
|
||||||
__DSB(); /* Ensure all outstanding memory accesses included
|
__DSB(); /* Ensure all outstanding memory accesses included
|
||||||
buffered write are completed before reset */
|
buffered write are completed before reset */
|
||||||
@ -1613,6 +1758,31 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
/*@} end of CMSIS_Core_NVICFunctions */
|
/*@} end of CMSIS_Core_NVICFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
/* ########################## FPU functions #################################### */
|
||||||
|
/**
|
||||||
|
\ingroup CMSIS_Core_FunctionInterface
|
||||||
|
\defgroup CMSIS_Core_FpuFunctions FPU Functions
|
||||||
|
\brief Function that provides FPU type.
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief get FPU type
|
||||||
|
\details returns the FPU type
|
||||||
|
\returns
|
||||||
|
- \b 0: No FPU
|
||||||
|
- \b 1: Single precision FPU
|
||||||
|
- \b 2: Double + Single precision FPU
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE uint32_t SCB_GetFPUType(void)
|
||||||
|
{
|
||||||
|
return 0U; /* No FPU */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*@} end of CMSIS_Core_FpuFunctions */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ################################## SysTick function ############################################ */
|
/* ################################## SysTick function ############################################ */
|
||||||
/**
|
/**
|
||||||
@ -1622,7 +1792,7 @@ __STATIC_INLINE void NVIC_SystemReset(void)
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if (__Vendor_SysTickConfig == 0U)
|
#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief System Tick Configuration
|
\brief System Tick Configuration
|
||||||
@ -1665,8 +1835,8 @@ __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
|
|||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */
|
extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */
|
||||||
#define ITM_RXBUFFER_EMPTY 0x5AA55AA5U /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */
|
#define ITM_RXBUFFER_EMPTY ((int32_t)0x5AA55AA5U) /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
272
lib/cmsis/inc/mpu_armv7.h
Normal file
272
lib/cmsis/inc/mpu_armv7.h
Normal file
@ -0,0 +1,272 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* @file mpu_armv7.h
|
||||||
|
* @brief CMSIS MPU API for Armv7-M MPU
|
||||||
|
* @version V5.1.0
|
||||||
|
* @date 08. March 2019
|
||||||
|
******************************************************************************/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017-2019 Arm Limited. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ )
|
||||||
|
#pragma system_include /* treat file as system include file for MISRA check */
|
||||||
|
#elif defined (__clang__)
|
||||||
|
#pragma clang system_header /* treat file as system include file */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ARM_MPU_ARMV7_H
|
||||||
|
#define ARM_MPU_ARMV7_H
|
||||||
|
|
||||||
|
#define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) ///!< MPU Region Size 32 Bytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) ///!< MPU Region Size 64 Bytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) ///!< MPU Region Size 128 Bytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) ///!< MPU Region Size 256 Bytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) ///!< MPU Region Size 512 Bytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) ///!< MPU Region Size 1 KByte
|
||||||
|
#define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) ///!< MPU Region Size 2 KBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) ///!< MPU Region Size 4 KBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) ///!< MPU Region Size 8 KBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) ///!< MPU Region Size 16 KBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) ///!< MPU Region Size 32 KBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) ///!< MPU Region Size 64 KBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) ///!< MPU Region Size 128 KBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) ///!< MPU Region Size 256 KBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) ///!< MPU Region Size 512 KBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) ///!< MPU Region Size 1 MByte
|
||||||
|
#define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) ///!< MPU Region Size 2 MBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) ///!< MPU Region Size 4 MBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) ///!< MPU Region Size 8 MBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) ///!< MPU Region Size 16 MBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) ///!< MPU Region Size 32 MBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) ///!< MPU Region Size 64 MBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) ///!< MPU Region Size 128 MBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) ///!< MPU Region Size 256 MBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) ///!< MPU Region Size 512 MBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) ///!< MPU Region Size 1 GByte
|
||||||
|
#define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) ///!< MPU Region Size 2 GBytes
|
||||||
|
#define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) ///!< MPU Region Size 4 GBytes
|
||||||
|
|
||||||
|
#define ARM_MPU_AP_NONE 0U ///!< MPU Access Permission no access
|
||||||
|
#define ARM_MPU_AP_PRIV 1U ///!< MPU Access Permission privileged access only
|
||||||
|
#define ARM_MPU_AP_URO 2U ///!< MPU Access Permission unprivileged access read-only
|
||||||
|
#define ARM_MPU_AP_FULL 3U ///!< MPU Access Permission full access
|
||||||
|
#define ARM_MPU_AP_PRO 5U ///!< MPU Access Permission privileged access read-only
|
||||||
|
#define ARM_MPU_AP_RO 6U ///!< MPU Access Permission read-only access
|
||||||
|
|
||||||
|
/** MPU Region Base Address Register Value
|
||||||
|
*
|
||||||
|
* \param Region The region to be configured, number 0 to 15.
|
||||||
|
* \param BaseAddress The base address for the region.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_RBAR(Region, BaseAddress) \
|
||||||
|
(((BaseAddress) & MPU_RBAR_ADDR_Msk) | \
|
||||||
|
((Region) & MPU_RBAR_REGION_Msk) | \
|
||||||
|
(MPU_RBAR_VALID_Msk))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MPU Memory Access Attributes
|
||||||
|
*
|
||||||
|
* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
|
||||||
|
* \param IsShareable Region is shareable between multiple bus masters.
|
||||||
|
* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
|
||||||
|
* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable) \
|
||||||
|
((((TypeExtField) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \
|
||||||
|
(((IsShareable) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \
|
||||||
|
(((IsCacheable) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \
|
||||||
|
(((IsBufferable) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MPU Region Attribute and Size Register Value
|
||||||
|
*
|
||||||
|
* \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
|
||||||
|
* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
|
||||||
|
* \param AccessAttributes Memory access attribution, see \ref ARM_MPU_ACCESS_.
|
||||||
|
* \param SubRegionDisable Sub-region disable field.
|
||||||
|
* \param Size Region size of the region to be configured, for example 4K, 8K.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_RASR_EX(DisableExec, AccessPermission, AccessAttributes, SubRegionDisable, Size) \
|
||||||
|
((((DisableExec) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \
|
||||||
|
(((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \
|
||||||
|
(((AccessAttributes) & (MPU_RASR_TEX_Msk | MPU_RASR_S_Msk | MPU_RASR_C_Msk | MPU_RASR_B_Msk))) | \
|
||||||
|
(((SubRegionDisable) << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \
|
||||||
|
(((Size) << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \
|
||||||
|
(((MPU_RASR_ENABLE_Msk))))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MPU Region Attribute and Size Register Value
|
||||||
|
*
|
||||||
|
* \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
|
||||||
|
* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
|
||||||
|
* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
|
||||||
|
* \param IsShareable Region is shareable between multiple bus masters.
|
||||||
|
* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
|
||||||
|
* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
|
||||||
|
* \param SubRegionDisable Sub-region disable field.
|
||||||
|
* \param Size Region size of the region to be configured, for example 4K, 8K.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \
|
||||||
|
ARM_MPU_RASR_EX(DisableExec, AccessPermission, ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable), SubRegionDisable, Size)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MPU Memory Access Attribute for strongly ordered memory.
|
||||||
|
* - TEX: 000b
|
||||||
|
* - Shareable
|
||||||
|
* - Non-cacheable
|
||||||
|
* - Non-bufferable
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_ACCESS_ORDERED ARM_MPU_ACCESS_(0U, 1U, 0U, 0U)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MPU Memory Access Attribute for device memory.
|
||||||
|
* - TEX: 000b (if shareable) or 010b (if non-shareable)
|
||||||
|
* - Shareable or non-shareable
|
||||||
|
* - Non-cacheable
|
||||||
|
* - Bufferable (if shareable) or non-bufferable (if non-shareable)
|
||||||
|
*
|
||||||
|
* \param IsShareable Configures the device memory as shareable or non-shareable.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_ACCESS_DEVICE(IsShareable) ((IsShareable) ? ARM_MPU_ACCESS_(0U, 1U, 0U, 1U) : ARM_MPU_ACCESS_(2U, 0U, 0U, 0U))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MPU Memory Access Attribute for normal memory.
|
||||||
|
* - TEX: 1BBb (reflecting outer cacheability rules)
|
||||||
|
* - Shareable or non-shareable
|
||||||
|
* - Cacheable or non-cacheable (reflecting inner cacheability rules)
|
||||||
|
* - Bufferable or non-bufferable (reflecting inner cacheability rules)
|
||||||
|
*
|
||||||
|
* \param OuterCp Configures the outer cache policy.
|
||||||
|
* \param InnerCp Configures the inner cache policy.
|
||||||
|
* \param IsShareable Configures the memory as shareable or non-shareable.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) & 2U), ((InnerCp) & 1U))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MPU Memory Access Attribute non-cacheable policy.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_CACHEP_NOCACHE 0U
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MPU Memory Access Attribute write-back, write and read allocate policy.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_CACHEP_WB_WRA 1U
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MPU Memory Access Attribute write-through, no write allocate policy.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_CACHEP_WT_NWA 2U
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MPU Memory Access Attribute write-back, no write allocate policy.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_CACHEP_WB_NWA 3U
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Struct for a single MPU Region
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint32_t RBAR; //!< The region base address register value (RBAR)
|
||||||
|
uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR
|
||||||
|
} ARM_MPU_Region_t;
|
||||||
|
|
||||||
|
/** Enable the MPU.
|
||||||
|
* \param MPU_Control Default access permissions for unconfigured regions.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
|
||||||
|
{
|
||||||
|
MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
|
||||||
|
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
|
||||||
|
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
|
||||||
|
#endif
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Disable the MPU.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_Disable(void)
|
||||||
|
{
|
||||||
|
__DMB();
|
||||||
|
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
|
||||||
|
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
|
||||||
|
#endif
|
||||||
|
MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Clear and disable the given MPU region.
|
||||||
|
* \param rnr Region number to be cleared.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
|
||||||
|
{
|
||||||
|
MPU->RNR = rnr;
|
||||||
|
MPU->RASR = 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Configure an MPU region.
|
||||||
|
* \param rbar Value for RBAR register.
|
||||||
|
* \param rsar Value for RSAR register.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr)
|
||||||
|
{
|
||||||
|
MPU->RBAR = rbar;
|
||||||
|
MPU->RASR = rasr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Configure the given MPU region.
|
||||||
|
* \param rnr Region number to be configured.
|
||||||
|
* \param rbar Value for RBAR register.
|
||||||
|
* \param rsar Value for RSAR register.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr)
|
||||||
|
{
|
||||||
|
MPU->RNR = rnr;
|
||||||
|
MPU->RBAR = rbar;
|
||||||
|
MPU->RASR = rasr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Memcopy with strictly ordered memory access, e.g. for register targets.
|
||||||
|
* \param dst Destination data is copied to.
|
||||||
|
* \param src Source data is copied from.
|
||||||
|
* \param len Amount of data words to be copied.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
for (i = 0U; i < len; ++i)
|
||||||
|
{
|
||||||
|
dst[i] = src[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Load the given number of MPU regions from a table.
|
||||||
|
* \param table Pointer to the MPU configuration table.
|
||||||
|
* \param cnt Amount of regions to be configured.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt)
|
||||||
|
{
|
||||||
|
const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U;
|
||||||
|
while (cnt > MPU_TYPE_RALIASES) {
|
||||||
|
ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize);
|
||||||
|
table += MPU_TYPE_RALIASES;
|
||||||
|
cnt -= MPU_TYPE_RALIASES;
|
||||||
|
}
|
||||||
|
ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
346
lib/cmsis/inc/mpu_armv8.h
Normal file
346
lib/cmsis/inc/mpu_armv8.h
Normal file
@ -0,0 +1,346 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* @file mpu_armv8.h
|
||||||
|
* @brief CMSIS MPU API for Armv8-M and Armv8.1-M MPU
|
||||||
|
* @version V5.1.0
|
||||||
|
* @date 08. March 2019
|
||||||
|
******************************************************************************/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017-2019 Arm Limited. All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ )
|
||||||
|
#pragma system_include /* treat file as system include file for MISRA check */
|
||||||
|
#elif defined (__clang__)
|
||||||
|
#pragma clang system_header /* treat file as system include file */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ARM_MPU_ARMV8_H
|
||||||
|
#define ARM_MPU_ARMV8_H
|
||||||
|
|
||||||
|
/** \brief Attribute for device memory (outer only) */
|
||||||
|
#define ARM_MPU_ATTR_DEVICE ( 0U )
|
||||||
|
|
||||||
|
/** \brief Attribute for non-cacheable, normal memory */
|
||||||
|
#define ARM_MPU_ATTR_NON_CACHEABLE ( 4U )
|
||||||
|
|
||||||
|
/** \brief Attribute for normal memory (outer and inner)
|
||||||
|
* \param NT Non-Transient: Set to 1 for non-transient data.
|
||||||
|
* \param WB Write-Back: Set to 1 to use write-back update policy.
|
||||||
|
* \param RA Read Allocation: Set to 1 to use cache allocation on read miss.
|
||||||
|
* \param WA Write Allocation: Set to 1 to use cache allocation on write miss.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA) \
|
||||||
|
(((NT & 1U) << 3U) | ((WB & 1U) << 2U) | ((RA & 1U) << 1U) | (WA & 1U))
|
||||||
|
|
||||||
|
/** \brief Device memory type non Gathering, non Re-ordering, non Early Write Acknowledgement */
|
||||||
|
#define ARM_MPU_ATTR_DEVICE_nGnRnE (0U)
|
||||||
|
|
||||||
|
/** \brief Device memory type non Gathering, non Re-ordering, Early Write Acknowledgement */
|
||||||
|
#define ARM_MPU_ATTR_DEVICE_nGnRE (1U)
|
||||||
|
|
||||||
|
/** \brief Device memory type non Gathering, Re-ordering, Early Write Acknowledgement */
|
||||||
|
#define ARM_MPU_ATTR_DEVICE_nGRE (2U)
|
||||||
|
|
||||||
|
/** \brief Device memory type Gathering, Re-ordering, Early Write Acknowledgement */
|
||||||
|
#define ARM_MPU_ATTR_DEVICE_GRE (3U)
|
||||||
|
|
||||||
|
/** \brief Memory Attribute
|
||||||
|
* \param O Outer memory attributes
|
||||||
|
* \param I O == ARM_MPU_ATTR_DEVICE: Device memory attributes, else: Inner memory attributes
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_ATTR(O, I) (((O & 0xFU) << 4U) | (((O & 0xFU) != 0U) ? (I & 0xFU) : ((I & 0x3U) << 2U)))
|
||||||
|
|
||||||
|
/** \brief Normal memory non-shareable */
|
||||||
|
#define ARM_MPU_SH_NON (0U)
|
||||||
|
|
||||||
|
/** \brief Normal memory outer shareable */
|
||||||
|
#define ARM_MPU_SH_OUTER (2U)
|
||||||
|
|
||||||
|
/** \brief Normal memory inner shareable */
|
||||||
|
#define ARM_MPU_SH_INNER (3U)
|
||||||
|
|
||||||
|
/** \brief Memory access permissions
|
||||||
|
* \param RO Read-Only: Set to 1 for read-only memory.
|
||||||
|
* \param NP Non-Privileged: Set to 1 for non-privileged memory.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_AP_(RO, NP) (((RO & 1U) << 1U) | (NP & 1U))
|
||||||
|
|
||||||
|
/** \brief Region Base Address Register value
|
||||||
|
* \param BASE The base address bits [31:5] of a memory region. The value is zero extended. Effective address gets 32 byte aligned.
|
||||||
|
* \param SH Defines the Shareability domain for this memory region.
|
||||||
|
* \param RO Read-Only: Set to 1 for a read-only memory region.
|
||||||
|
* \param NP Non-Privileged: Set to 1 for a non-privileged memory region.
|
||||||
|
* \oaram XN eXecute Never: Set to 1 for a non-executable memory region.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_RBAR(BASE, SH, RO, NP, XN) \
|
||||||
|
((BASE & MPU_RBAR_BASE_Msk) | \
|
||||||
|
((SH << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \
|
||||||
|
((ARM_MPU_AP_(RO, NP) << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk) | \
|
||||||
|
((XN << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk))
|
||||||
|
|
||||||
|
/** \brief Region Limit Address Register value
|
||||||
|
* \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended.
|
||||||
|
* \param IDX The attribute index to be associated with this memory region.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_RLAR(LIMIT, IDX) \
|
||||||
|
((LIMIT & MPU_RLAR_LIMIT_Msk) | \
|
||||||
|
((IDX << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \
|
||||||
|
(MPU_RLAR_EN_Msk))
|
||||||
|
|
||||||
|
#if defined(MPU_RLAR_PXN_Pos)
|
||||||
|
|
||||||
|
/** \brief Region Limit Address Register with PXN value
|
||||||
|
* \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended.
|
||||||
|
* \param PXN Privileged execute never. Defines whether code can be executed from this privileged region.
|
||||||
|
* \param IDX The attribute index to be associated with this memory region.
|
||||||
|
*/
|
||||||
|
#define ARM_MPU_RLAR_PXN(LIMIT, PXN, IDX) \
|
||||||
|
((LIMIT & MPU_RLAR_LIMIT_Msk) | \
|
||||||
|
((PXN << MPU_RLAR_PXN_Pos) & MPU_RLAR_PXN_Msk) | \
|
||||||
|
((IDX << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \
|
||||||
|
(MPU_RLAR_EN_Msk))
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Struct for a single MPU Region
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint32_t RBAR; /*!< Region Base Address Register value */
|
||||||
|
uint32_t RLAR; /*!< Region Limit Address Register value */
|
||||||
|
} ARM_MPU_Region_t;
|
||||||
|
|
||||||
|
/** Enable the MPU.
|
||||||
|
* \param MPU_Control Default access permissions for unconfigured regions.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
|
||||||
|
{
|
||||||
|
MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
|
||||||
|
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
|
||||||
|
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
|
||||||
|
#endif
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Disable the MPU.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_Disable(void)
|
||||||
|
{
|
||||||
|
__DMB();
|
||||||
|
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
|
||||||
|
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
|
||||||
|
#endif
|
||||||
|
MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef MPU_NS
|
||||||
|
/** Enable the Non-secure MPU.
|
||||||
|
* \param MPU_Control Default access permissions for unconfigured regions.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_Enable_NS(uint32_t MPU_Control)
|
||||||
|
{
|
||||||
|
MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
|
||||||
|
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
|
||||||
|
SCB_NS->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
|
||||||
|
#endif
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Disable the Non-secure MPU.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_Disable_NS(void)
|
||||||
|
{
|
||||||
|
__DMB();
|
||||||
|
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
|
||||||
|
SCB_NS->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
|
||||||
|
#endif
|
||||||
|
MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Set the memory attribute encoding to the given MPU.
|
||||||
|
* \param mpu Pointer to the MPU to be configured.
|
||||||
|
* \param idx The attribute index to be set [0-7]
|
||||||
|
* \param attr The attribute value to be set.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_SetMemAttrEx(MPU_Type* mpu, uint8_t idx, uint8_t attr)
|
||||||
|
{
|
||||||
|
const uint8_t reg = idx / 4U;
|
||||||
|
const uint32_t pos = ((idx % 4U) * 8U);
|
||||||
|
const uint32_t mask = 0xFFU << pos;
|
||||||
|
|
||||||
|
if (reg >= (sizeof(mpu->MAIR) / sizeof(mpu->MAIR[0]))) {
|
||||||
|
return; // invalid index
|
||||||
|
}
|
||||||
|
|
||||||
|
mpu->MAIR[reg] = ((mpu->MAIR[reg] & ~mask) | ((attr << pos) & mask));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the memory attribute encoding.
|
||||||
|
* \param idx The attribute index to be set [0-7]
|
||||||
|
* \param attr The attribute value to be set.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr)
|
||||||
|
{
|
||||||
|
ARM_MPU_SetMemAttrEx(MPU, idx, attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef MPU_NS
|
||||||
|
/** Set the memory attribute encoding to the Non-secure MPU.
|
||||||
|
* \param idx The attribute index to be set [0-7]
|
||||||
|
* \param attr The attribute value to be set.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_SetMemAttr_NS(uint8_t idx, uint8_t attr)
|
||||||
|
{
|
||||||
|
ARM_MPU_SetMemAttrEx(MPU_NS, idx, attr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Clear and disable the given MPU region of the given MPU.
|
||||||
|
* \param mpu Pointer to MPU to be used.
|
||||||
|
* \param rnr Region number to be cleared.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_ClrRegionEx(MPU_Type* mpu, uint32_t rnr)
|
||||||
|
{
|
||||||
|
mpu->RNR = rnr;
|
||||||
|
mpu->RLAR = 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Clear and disable the given MPU region.
|
||||||
|
* \param rnr Region number to be cleared.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
|
||||||
|
{
|
||||||
|
ARM_MPU_ClrRegionEx(MPU, rnr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef MPU_NS
|
||||||
|
/** Clear and disable the given Non-secure MPU region.
|
||||||
|
* \param rnr Region number to be cleared.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_ClrRegion_NS(uint32_t rnr)
|
||||||
|
{
|
||||||
|
ARM_MPU_ClrRegionEx(MPU_NS, rnr);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Configure the given MPU region of the given MPU.
|
||||||
|
* \param mpu Pointer to MPU to be used.
|
||||||
|
* \param rnr Region number to be configured.
|
||||||
|
* \param rbar Value for RBAR register.
|
||||||
|
* \param rlar Value for RLAR register.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_SetRegionEx(MPU_Type* mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar)
|
||||||
|
{
|
||||||
|
mpu->RNR = rnr;
|
||||||
|
mpu->RBAR = rbar;
|
||||||
|
mpu->RLAR = rlar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Configure the given MPU region.
|
||||||
|
* \param rnr Region number to be configured.
|
||||||
|
* \param rbar Value for RBAR register.
|
||||||
|
* \param rlar Value for RLAR register.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rlar)
|
||||||
|
{
|
||||||
|
ARM_MPU_SetRegionEx(MPU, rnr, rbar, rlar);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef MPU_NS
|
||||||
|
/** Configure the given Non-secure MPU region.
|
||||||
|
* \param rnr Region number to be configured.
|
||||||
|
* \param rbar Value for RBAR register.
|
||||||
|
* \param rlar Value for RLAR register.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t rlar)
|
||||||
|
{
|
||||||
|
ARM_MPU_SetRegionEx(MPU_NS, rnr, rbar, rlar);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Memcopy with strictly ordered memory access, e.g. for register targets.
|
||||||
|
* \param dst Destination data is copied to.
|
||||||
|
* \param src Source data is copied from.
|
||||||
|
* \param len Amount of data words to be copied.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
for (i = 0U; i < len; ++i)
|
||||||
|
{
|
||||||
|
dst[i] = src[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Load the given number of MPU regions from a table to the given MPU.
|
||||||
|
* \param mpu Pointer to the MPU registers to be used.
|
||||||
|
* \param rnr First region number to be configured.
|
||||||
|
* \param table Pointer to the MPU configuration table.
|
||||||
|
* \param cnt Amount of regions to be configured.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type* mpu, uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt)
|
||||||
|
{
|
||||||
|
const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U;
|
||||||
|
if (cnt == 1U) {
|
||||||
|
mpu->RNR = rnr;
|
||||||
|
ARM_MPU_OrderedMemcpy(&(mpu->RBAR), &(table->RBAR), rowWordSize);
|
||||||
|
} else {
|
||||||
|
uint32_t rnrBase = rnr & ~(MPU_TYPE_RALIASES-1U);
|
||||||
|
uint32_t rnrOffset = rnr % MPU_TYPE_RALIASES;
|
||||||
|
|
||||||
|
mpu->RNR = rnrBase;
|
||||||
|
while ((rnrOffset + cnt) > MPU_TYPE_RALIASES) {
|
||||||
|
uint32_t c = MPU_TYPE_RALIASES - rnrOffset;
|
||||||
|
ARM_MPU_OrderedMemcpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), c*rowWordSize);
|
||||||
|
table += c;
|
||||||
|
cnt -= c;
|
||||||
|
rnrOffset = 0U;
|
||||||
|
rnrBase += MPU_TYPE_RALIASES;
|
||||||
|
mpu->RNR = rnrBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
ARM_MPU_OrderedMemcpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), cnt*rowWordSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Load the given number of MPU regions from a table.
|
||||||
|
* \param rnr First region number to be configured.
|
||||||
|
* \param table Pointer to the MPU configuration table.
|
||||||
|
* \param cnt Amount of regions to be configured.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_Load(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt)
|
||||||
|
{
|
||||||
|
ARM_MPU_LoadEx(MPU, rnr, table, cnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef MPU_NS
|
||||||
|
/** Load the given number of MPU regions from a table to the Non-secure MPU.
|
||||||
|
* \param rnr First region number to be configured.
|
||||||
|
* \param table Pointer to the MPU configuration table.
|
||||||
|
* \param cnt Amount of regions to be configured.
|
||||||
|
*/
|
||||||
|
__STATIC_INLINE void ARM_MPU_Load_NS(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt)
|
||||||
|
{
|
||||||
|
ARM_MPU_LoadEx(MPU_NS, rnr, table, cnt);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user