Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
45c4aca9e9 | ||
|
|
fbac2f8a3b | ||
|
|
df10f8d531 | ||
|
|
f9b2692779 | ||
|
|
7db4a62cb4 | ||
|
|
1dfedfeb81 | ||
|
|
511ab8846e | ||
|
|
3414e92753 | ||
|
|
d238261964 | ||
|
|
848a1d5b7e | ||
|
|
2b37b5925d | ||
|
|
6b319e531f | ||
|
|
b7d8f4b4b7 | ||
|
|
f010d88221 | ||
|
|
b99aafc23a | ||
|
|
f2ca9ced6e | ||
|
|
45f0418bfe | ||
|
|
090eadf7ba | ||
|
|
08b28e29c3 | ||
|
|
44c3602009 | ||
|
|
8b4f5220e6 | ||
|
|
3c0d65a3ad | ||
|
|
3d0e9831b3 | ||
|
|
7f5d92deab | ||
|
|
8fab85d670 | ||
|
|
e764e8fb1a | ||
|
|
0747f36f22 | ||
|
|
05c0eef7cd | ||
|
|
891bf52cb5 | ||
|
|
d897d409ff | ||
|
|
151c3792fc | ||
|
|
895091a6d8 | ||
|
|
9670667e07 | ||
|
|
c1026db079 | ||
|
|
6d2412afc5 | ||
|
|
5efac17f1d | ||
|
|
712c22a676 | ||
|
|
92da992ddd | ||
|
|
ee1c730ad8 | ||
|
|
af9e9c86a6 | ||
|
|
240d9483ea |
@@ -0,0 +1,7 @@
|
||||
# See: https://github.com/codespell-project/codespell#using-a-config-file
|
||||
[codespell]
|
||||
# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here:
|
||||
ignore-words-list = ,
|
||||
check-filenames =
|
||||
check-hidden =
|
||||
skip = ./.git,./src,./examples,./Packages_Patches,./LibraryPatches
|
||||
@@ -35,25 +35,27 @@ If applicable, add screenshots to help explain your problem.
|
||||
|
||||
Please ensure to specify the following:
|
||||
|
||||
* Arduino IDE version (e.g. 1.8.13) or Platform.io version
|
||||
* `ESP8266`,`ESP32` or `STM32` Core Version (e.g. ESP8266 core v2.7.4, ESP32 v1.0.5 or STM32 v1.9.0)
|
||||
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
|
||||
* `RP2040` Core Version (e.g. RP2040 core v2.6.3)
|
||||
* `RP2040` Board type (e.g. RASPBERRY_PI_PICO, RASPBERRY_PI_PICO_W, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc.)
|
||||
* Contextual information (e.g. what you were trying to achieve)
|
||||
* Simplest possible steps to reproduce
|
||||
* Anything that might be relevant in your opinion, such as:
|
||||
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a`
|
||||
* Network configuration
|
||||
|
||||
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
Arduino IDE version: 1.8.13
|
||||
ESP32 Core Version 1.0.5
|
||||
Arduino IDE version: 1.8.19
|
||||
RP2040 core v2.6.3
|
||||
RASPBERRY_PI_PICO Module
|
||||
OS: Ubuntu 20.04 LTS
|
||||
Linux xy-Inspiron-3593 5.4.0-66-generic #74-Ubuntu SMP Wed Jan 27 22:54:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
|
||||
Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
|
||||
|
||||
Context:
|
||||
I encountered an endless loop while trying to connect to Local WiFi.
|
||||
|
||||
I encountered a crash while using this library
|
||||
Steps to reproduce:
|
||||
1. ...
|
||||
2. ...
|
||||
@@ -64,3 +66,34 @@ Steps to reproduce:
|
||||
### Additional context
|
||||
|
||||
Add any other context about the problem here.
|
||||
|
||||
---
|
||||
|
||||
### Sending Feature Requests
|
||||
|
||||
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
|
||||
|
||||
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
|
||||
|
||||
---
|
||||
|
||||
### Sending Pull Requests
|
||||
|
||||
Pull Requests with changes and fixes are also welcome!
|
||||
|
||||
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
|
||||
|
||||
1. Change directory to the library GitHub
|
||||
|
||||
```
|
||||
xy@xy-Inspiron-3593:~$ cd Arduino/xy/RPI_PICO_TimerInterrupt_GitHub/
|
||||
xy@xy-Inspiron-3593:~/Arduino/xy/RPI_PICO_TimerInterrupt_GitHub$
|
||||
```
|
||||
|
||||
2. Issue astyle command
|
||||
|
||||
```
|
||||
xy@xy-Inspiron-3593:~/Arduino/xy/RPI_PICO_TimerInterrupt_GitHub$ bash utils/restyle.sh
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# See: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#about-the-dependabotyml-file
|
||||
version: 2
|
||||
|
||||
updates:
|
||||
# Configure check for outdated GitHub Actions actions in workflows.
|
||||
# See: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot
|
||||
- package-ecosystem: github-actions
|
||||
directory: / # Check the repository's workflows under /.github/workflows/
|
||||
schedule:
|
||||
interval: daily
|
||||
@@ -0,0 +1,31 @@
|
||||
# Configuration for probot-stale - https://github.com/probot/stale
|
||||
|
||||
daysUntilStale: 60
|
||||
daysUntilClose: 14
|
||||
limitPerRun: 30
|
||||
staleLabel: stale
|
||||
exemptLabels:
|
||||
- pinned
|
||||
- security
|
||||
- "to be implemented"
|
||||
- "for reference"
|
||||
- "move to PR"
|
||||
- "enhancement"
|
||||
|
||||
only: issues
|
||||
onlyLabels: []
|
||||
exemptProjects: false
|
||||
exemptMilestones: false
|
||||
exemptAssignees: false
|
||||
|
||||
markComment: >
|
||||
[STALE_SET] This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed in 14 days if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
|
||||
unmarkComment: >
|
||||
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it opening the future.
|
||||
|
||||
closeComment: >
|
||||
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
name: auto-github-actions
|
||||
on: [push]
|
||||
jobs:
|
||||
check-bats-version:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '14'
|
||||
- run: npm install -g bats
|
||||
- run: bats -v
|
||||
@@ -0,0 +1,28 @@
|
||||
name: Check Arduino
|
||||
|
||||
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
# Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint.
|
||||
- cron: "0 8 * * TUE"
|
||||
workflow_dispatch:
|
||||
repository_dispatch:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Arduino Lint
|
||||
uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
compliance: specification
|
||||
library-manager: update
|
||||
# Always use this setting for official repositories. Remove for 3rd party projects.
|
||||
official: true
|
||||
project-type: library
|
||||
@@ -0,0 +1,16 @@
|
||||
name: Report Size Deltas
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '*/5 * * * *'
|
||||
|
||||
jobs:
|
||||
report:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Comment size deltas reports to PRs
|
||||
uses: arduino/report-size-deltas@v1
|
||||
with:
|
||||
# The name of the workflow artifact created by the "Compile Examples" workflow
|
||||
sketches-reports-source: sketches-reports
|
||||
@@ -0,0 +1,22 @@
|
||||
name: Spell Check
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
schedule:
|
||||
# run every Tuesday at 3 AM UTC
|
||||
- cron: "0 3 * * 2"
|
||||
workflow_dispatch:
|
||||
repository_dispatch:
|
||||
|
||||
jobs:
|
||||
spellcheck:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# See: https://github.com/codespell-project/actions-codespell/blob/master/README.md
|
||||
- name: Spell check
|
||||
uses: codespell-project/actions-codespell@master
|
||||
+34
-8
@@ -14,9 +14,9 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
|
||||
|
||||
Please ensure to specify the following:
|
||||
|
||||
* Arduino IDE version (e.g. 1.8.13) or Platform.io version
|
||||
* `RP2040` Core Version (e.g. RP2040 core v1.2.1)
|
||||
* `RP2040` Board type (e.g. RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc.)
|
||||
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
|
||||
* `RP2040` Core Version (e.g. RP2040 core v2.6.3)
|
||||
* `RP2040` Board type (e.g. RASPBERRY_PI_PICO, RASPBERRY_PI_PICO_W, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc.)
|
||||
* Contextual information (e.g. what you were trying to achieve)
|
||||
* Simplest possible steps to reproduce
|
||||
* Anything that might be relevant in your opinion, such as:
|
||||
@@ -27,27 +27,53 @@ Please ensure to specify the following:
|
||||
### Example
|
||||
|
||||
```
|
||||
Arduino IDE version: 1.8.13
|
||||
RP2040 core v1.2.1
|
||||
Arduino IDE version: 1.8.19
|
||||
RP2040 core v2.6.3
|
||||
RASPBERRY_PI_PICO Module
|
||||
OS: Ubuntu 20.04 LTS
|
||||
Linux xy-Inspiron-3593 5.4.0-72-generic #80-Ubuntu SMP Mon Apr 12 17:35:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
|
||||
Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
|
||||
|
||||
Context:
|
||||
I encountered a crash while using TimerInterrupt.
|
||||
|
||||
I encountered a crash while using this library
|
||||
Steps to reproduce:
|
||||
1. ...
|
||||
2. ...
|
||||
3. ...
|
||||
4. ...
|
||||
```
|
||||
|
||||
### Additional context
|
||||
|
||||
Add any other context about the problem here.
|
||||
|
||||
---
|
||||
|
||||
### Sending Feature Requests
|
||||
|
||||
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
|
||||
|
||||
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
|
||||
|
||||
---
|
||||
|
||||
### Sending Pull Requests
|
||||
|
||||
Pull Requests with changes and fixes are also welcome!
|
||||
|
||||
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
|
||||
|
||||
1. Change directory to the library GitHub
|
||||
|
||||
```
|
||||
xy@xy-Inspiron-3593:~$ cd Arduino/xy/RPI_PICO_TimerInterrupt_GitHub/
|
||||
xy@xy-Inspiron-3593:~/Arduino/xy/RPI_PICO_TimerInterrupt_GitHub$
|
||||
```
|
||||
|
||||
2. Issue astyle command
|
||||
|
||||
```
|
||||
xy@xy-Inspiron-3593:~/Arduino/xy/RPI_PICO_TimerInterrupt_GitHub$ bash utils/restyle.sh
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
# Copyright (c) 2021 Earle F. Philhower, III
|
||||
#
|
||||
# Raspberry Pi RP2040 Core platform file
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
# For more info:
|
||||
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
|
||||
|
||||
name=Raspberry Pi RP2040 Boards(1.2.2)
|
||||
version=1.2.2
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
compiler.path={runtime.tools.pqt-gcc.path}/bin/
|
||||
|
||||
# Compile variables
|
||||
# -----------------
|
||||
|
||||
compiler.warning_flags=-w
|
||||
compiler.warning_flags.none=-w
|
||||
compiler.warning_flags.default=
|
||||
compiler.warning_flags.more=-Wall
|
||||
compiler.warning_flags.all=-Wall -Wextra
|
||||
|
||||
compiler.defines={build.led}
|
||||
compiler.includes="-iprefix{runtime.platform.path}/" "@{runtime.platform.path}/lib/platform_inc.txt"
|
||||
compiler.flags=-Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions
|
||||
compiler.wrap="@{runtime.platform.path}/lib/platform_wrap.txt"
|
||||
|
||||
compiler.c.cmd=arm-none-eabi-gcc
|
||||
compiler.c.flags=-c {compiler.defines} {compiler.flags} {compiler.includes} -std=gnu17 -g
|
||||
compiler.c.elf.cmd=arm-none-eabi-g++
|
||||
compiler.c.elf.flags={compiler.defines} {compiler.flags} -Wl,--gc-sections -u _printf_float -u _scanf_float
|
||||
compiler.S.cmd=arm-none-eabi-gcc
|
||||
compiler.S.flags=-c -g -x assembler-with-cpp -MMD {compiler.includes} -g
|
||||
compiler.cpp.cmd=arm-none-eabi-g++
|
||||
compiler.cpp.flags=-c {compiler.defines} {compiler.flags} {compiler.includes} -fno-rtti -std=gnu++17 -g
|
||||
|
||||
compiler.ar.cmd=arm-none-eabi-ar
|
||||
compiler.ar.flags=rcs
|
||||
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
||||
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
|
||||
compiler.elf2hex.bin.flags=-O binary
|
||||
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
|
||||
compiler.elf2hex.cmd=arm-none-eabi-objcopy
|
||||
compiler.ldflags={compiler.wrap} -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common
|
||||
compiler.size.cmd=arm-none-eabi-size
|
||||
compiler.define=-DARDUINO=
|
||||
compiler.readelf.cmd=arm-none-eabi-readelf
|
||||
|
||||
# this can be overriden in boards.txt
|
||||
build.extra_flags=
|
||||
|
||||
# These can be overridden in platform.local.txt
|
||||
compiler.c.extra_flags=
|
||||
compiler.c.elf.extra_flags=
|
||||
compiler.cpp.extra_flags=
|
||||
compiler.S.extra_flags=
|
||||
compiler.ar.extra_flags=
|
||||
compiler.elf2hex.extra_flags=
|
||||
|
||||
# Board configuration, set in boards.txt. Present here to ensure substitution works
|
||||
build.flash_length=
|
||||
build.eeprom_start=
|
||||
build.fs_start=
|
||||
build.fs_end=
|
||||
|
||||
build.boot2=boot2_generic_03h_4_padded_checksum
|
||||
|
||||
# Allow Pico boards do be auto-discovered by the IDE
|
||||
discovery.rp2040.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/discovery.py"
|
||||
|
||||
|
||||
# Compile patterns
|
||||
# ----------------
|
||||
|
||||
## Compile c files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile c++ files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile S files
|
||||
## KH Add -DBOARD_NAME="{build.board}"
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Create archives
|
||||
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
|
||||
archive_file_path={build.path}/{archive_file}
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.hooks.linking.prelink.1.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/simplesub.py" --input "{runtime.platform.path}/lib/memmap_default.ld" --out "{build.path}/memmap_default.ld" --sub __FLASH_LENGTH__ {build.flash_length} --sub __EEPROM_START__ {build.eeprom_start} --sub __FS_START__ {build.fs_start} --sub __FS_END__ {build.fs_end}
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-Wl,--script={build.path}/memmap_default.ld" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nosys.specs -Wl,--start-group {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "{runtime.platform.path}/lib/libpico.a" -lm "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_binary_info/include" "{runtime.platform.path}/assembly/{build.boot2}.S" -lc -lstdc++ -Wl,--end-group
|
||||
|
||||
## Create output (UF2 file)
|
||||
recipe.objcopy.uf2.pattern="{runtime.tools.pqt-elf2uf2.path}/elf2uf2" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.uf2"
|
||||
|
||||
build.preferred_out_format=uf2
|
||||
|
||||
## Save hex
|
||||
recipe.output.tmp_file={build.project_name}.{build.preferred_out_format}
|
||||
recipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_out_format}
|
||||
|
||||
## Compute size
|
||||
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
|
||||
recipe.size.regex=^(?:\.boot2|\.text|\.rodata|\.ARM\.extab|\.ARM\.exidx)\s+([0-9]+).*
|
||||
recipe.size.regex.data=^(?:\.data|\.bss|\.ram_vector_table|\.uninitialized_data)\s+([0-9]+).*
|
||||
|
||||
tools.uf2conv.path=
|
||||
# Because the variable expansion doesn't allow one tool to find another, the following lines
|
||||
# will point to "{runtime.platform.path}/tools/python3/python3" in GIT and
|
||||
# "{runtime.tools.pqt-python3.path}/python3" for JSON board manager releases.
|
||||
tools.uf2conv.cmd={runtime.tools.pqt-python3.path}/python3
|
||||
|
||||
tools.uf2conv.upload.protocol=uf2
|
||||
tools.uf2conv.upload.params.verbose=
|
||||
tools.uf2conv.upload.params.quiet=
|
||||
tools.uf2conv.upload.pattern="{cmd}" "{runtime.platform.path}/tools/uf2conv.py" --serial "{serial.port}" --family RP2040 --deploy "{build.path}/{build.project_name}.uf2"
|
||||
|
||||
|
||||
tools.picoprobe.cmd={runtime.tools.pqt-openocd.path}
|
||||
|
||||
tools.picoprobe.upload.protocol=picoprobe
|
||||
tools.picoprobe.upload.params.verbose=
|
||||
tools.picoprobe.upload.params.quiet=
|
||||
tools.picoprobe.upload.pattern="{cmd}/bin/openocd" -f "interface/picoprobe.cfg" -f "target/rp2040.cfg" -s "{cmd}/share/openocd/scripts" -c "program {build.path}/{build.project_name}.elf verify reset exit"
|
||||
@@ -0,0 +1,145 @@
|
||||
# Copyright (c) 2021 Earle F. Philhower, III
|
||||
#
|
||||
# Raspberry Pi RP2040 Core platform file
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
# For more info:
|
||||
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
|
||||
|
||||
name=Raspberry Pi RP2040 Boards(1.3.0)
|
||||
version=1.3.0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
compiler.path={runtime.tools.pqt-gcc.path}/bin/
|
||||
|
||||
# Compile variables
|
||||
# -----------------
|
||||
|
||||
compiler.warning_flags=-w
|
||||
compiler.warning_flags.none=-w
|
||||
compiler.warning_flags.default=
|
||||
compiler.warning_flags.more=-Wall
|
||||
compiler.warning_flags.all=-Wall -Wextra
|
||||
|
||||
compiler.defines={build.led}
|
||||
compiler.includes="-iprefix{runtime.platform.path}/" "@{runtime.platform.path}/lib/platform_inc.txt"
|
||||
compiler.flags=-Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions
|
||||
compiler.wrap="@{runtime.platform.path}/lib/platform_wrap.txt"
|
||||
|
||||
compiler.c.cmd=arm-none-eabi-gcc
|
||||
compiler.c.flags=-c {compiler.defines} {compiler.flags} {compiler.includes} -std=gnu17 -g
|
||||
compiler.c.elf.cmd=arm-none-eabi-g++
|
||||
compiler.c.elf.flags={compiler.defines} {compiler.flags} -Wl,--gc-sections -u _printf_float -u _scanf_float
|
||||
compiler.S.cmd=arm-none-eabi-gcc
|
||||
compiler.S.flags=-c -g -x assembler-with-cpp -MMD {compiler.includes} -g
|
||||
compiler.cpp.cmd=arm-none-eabi-g++
|
||||
compiler.cpp.flags=-c {compiler.defines} {compiler.flags} {compiler.includes} -fno-rtti -std=gnu++17 -g
|
||||
|
||||
compiler.ar.cmd=arm-none-eabi-ar
|
||||
compiler.ar.flags=rcs
|
||||
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
||||
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
|
||||
compiler.elf2hex.bin.flags=-O binary
|
||||
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
|
||||
compiler.elf2hex.cmd=arm-none-eabi-objcopy
|
||||
compiler.ldflags={compiler.wrap} -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common
|
||||
compiler.size.cmd=arm-none-eabi-size
|
||||
compiler.define=-DARDUINO=
|
||||
compiler.readelf.cmd=arm-none-eabi-readelf
|
||||
|
||||
# this can be overriden in boards.txt
|
||||
build.extra_flags=
|
||||
|
||||
# These can be overridden in platform.local.txt
|
||||
compiler.c.extra_flags=
|
||||
compiler.c.elf.extra_flags=
|
||||
compiler.cpp.extra_flags=
|
||||
compiler.S.extra_flags=
|
||||
compiler.ar.extra_flags=
|
||||
compiler.elf2hex.extra_flags=
|
||||
|
||||
# Board configuration, set in boards.txt. Present here to ensure substitution works
|
||||
build.flash_length=
|
||||
build.eeprom_start=
|
||||
build.fs_start=
|
||||
build.fs_end=
|
||||
|
||||
build.boot2=boot2_generic_03h_4_padded_checksum
|
||||
|
||||
# Allow Pico boards do be auto-discovered by the IDE
|
||||
discovery.rp2040.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/discovery.py"
|
||||
|
||||
|
||||
# Compile patterns
|
||||
# ----------------
|
||||
|
||||
## Compile c files
|
||||
## Add -DBOARD_NAME="{build.board}"
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile c++ files
|
||||
## Add -DBOARD_NAME="{build.board}"
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile S files
|
||||
## Add -DBOARD_NAME="{build.board}"
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Create archives
|
||||
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
|
||||
archive_file_path={build.path}/{archive_file}
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.hooks.linking.prelink.1.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/simplesub.py" --input "{runtime.platform.path}/lib/memmap_default.ld" --out "{build.path}/memmap_default.ld" --sub __FLASH_LENGTH__ {build.flash_length} --sub __EEPROM_START__ {build.eeprom_start} --sub __FS_START__ {build.fs_start} --sub __FS_END__ {build.fs_end}
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-Wl,--script={build.path}/memmap_default.ld" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nosys.specs -Wl,--start-group {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "{runtime.platform.path}/lib/libpico.a" -lm "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_binary_info/include" "{runtime.platform.path}/assembly/{build.boot2}.S" -lc -lstdc++ -Wl,--end-group
|
||||
|
||||
## Create output (UF2 file)
|
||||
recipe.objcopy.uf2.pattern="{runtime.tools.pqt-elf2uf2.path}/elf2uf2" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.uf2"
|
||||
|
||||
build.preferred_out_format=uf2
|
||||
|
||||
## Save hex
|
||||
recipe.output.tmp_file={build.project_name}.{build.preferred_out_format}
|
||||
recipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_out_format}
|
||||
|
||||
## Compute size
|
||||
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
|
||||
recipe.size.regex=^(?:\.boot2|\.text|\.rodata|\.ARM\.extab|\.ARM\.exidx)\s+([0-9]+).*
|
||||
recipe.size.regex.data=^(?:\.data|\.bss|\.ram_vector_table|\.uninitialized_data)\s+([0-9]+).*
|
||||
|
||||
tools.uf2conv.path=
|
||||
# Because the variable expansion doesn't allow one tool to find another, the following lines
|
||||
# will point to "{runtime.platform.path}/tools/python3/python3" in GIT and
|
||||
# "{runtime.tools.pqt-python3.path}/python3" for JSON board manager releases.
|
||||
tools.uf2conv.cmd={runtime.tools.pqt-python3.path}/python3
|
||||
|
||||
tools.uf2conv.upload.protocol=uf2
|
||||
tools.uf2conv.upload.params.verbose=
|
||||
tools.uf2conv.upload.params.quiet=
|
||||
tools.uf2conv.upload.pattern="{cmd}" "{runtime.platform.path}/tools/uf2conv.py" --serial "{serial.port}" --family RP2040 --deploy "{build.path}/{build.project_name}.uf2"
|
||||
|
||||
|
||||
tools.picoprobe.cmd={runtime.tools.pqt-openocd.path}
|
||||
|
||||
tools.picoprobe.upload.protocol=picoprobe
|
||||
tools.picoprobe.upload.params.verbose=
|
||||
tools.picoprobe.upload.params.quiet=
|
||||
tools.picoprobe.upload.pattern="{cmd}/bin/openocd" -f "interface/picoprobe.cfg" -f "target/rp2040.cfg" -s "{cmd}/share/openocd/scripts" -c "program {build.path}/{build.project_name}.elf verify reset exit"
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Arduino header for the Raspberry Pi Pico RP2040
|
||||
*
|
||||
* Copyright (c) 2021 Earle F. Philhower, III <earlephilhower@yahoo.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef Arduino_h
|
||||
#define Arduino_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
// Wacky deprecated AVR compatibilty functions
|
||||
#include "stdlib_noniso.h"
|
||||
|
||||
#include "api/ArduinoAPI.h"
|
||||
#include <pins_arduino.h>
|
||||
|
||||
|
||||
// Required for the port*Register macros
|
||||
#include "hardware/gpio.h"
|
||||
|
||||
#include "debug_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif // __cplusplus
|
||||
|
||||
// For compatibility to many platforms and libraries
|
||||
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
||||
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
||||
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
|
||||
|
||||
// Disable/reenable all interrupts. Safely handles nested disables
|
||||
void interrupts();
|
||||
void noInterrupts();
|
||||
|
||||
// GPIO change/value interrupts
|
||||
void attachInterrupt(pin_size_t pin, voidFuncPtr callback, PinStatus mode);
|
||||
void detachInterrupt(pin_size_t pin);
|
||||
|
||||
// AVR compatibilty macros...naughty and accesses the HW directly
|
||||
#define digitalPinToPort(pin) (0)
|
||||
#define digitalPinToBitMask(pin) (1UL << (pin))
|
||||
#define digitalPinToTimer(pin) (0)
|
||||
#define digitalPinToInterrupt(pin) (pin)
|
||||
#define NOT_AN_INTERRUPT (-1)
|
||||
#define portOutputRegister(port) ((volatile uint32_t*) sio_hw->gpio_out)
|
||||
#define portInputRegister(port) ((volatile uint32_t*) sio_hw->gpio_in)
|
||||
#define portModeRegister(port) ((volatile uint32_t*) sio_hw->gpio_oe)
|
||||
|
||||
// IO config
|
||||
void pinMode(pin_size_t pinNumber, PinMode pinMode);
|
||||
|
||||
// SIO (GPIO)
|
||||
void digitalWrite(pin_size_t pinNumber, PinStatus status);
|
||||
PinStatus digitalRead(pin_size_t pinNumber);
|
||||
|
||||
// ADC
|
||||
int analogRead(pin_size_t pinNumber);
|
||||
float analogReadTemp(); // Returns core temp in Centigrade
|
||||
|
||||
// PWM
|
||||
void analogWrite(pin_size_t pinNumber, int value);
|
||||
void analogWriteFreq(uint32_t freq);
|
||||
void analogWriteRange(uint32_t range);
|
||||
void analogWriteResolution(int res);
|
||||
|
||||
// Timing
|
||||
void delay(unsigned long);
|
||||
void delayMicroseconds(unsigned int us);
|
||||
unsigned long millis();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// Ancient AVR defines
|
||||
#define HAVE_HWSERIAL0
|
||||
#define HAVE_HWSERIAL1
|
||||
#define HAVE_HWSERIAL2
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "SerialUSB.h"
|
||||
#include "SerialUART.h"
|
||||
#include "RP2040.h"
|
||||
#include "Bootsel.h"
|
||||
|
||||
// Template which will evaluate at *compile time* to a single 32b number
|
||||
// with the specified bits set.
|
||||
template <size_t N>
|
||||
constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U) {
|
||||
return i < N ? (1L << a[i]) | __bitset(a, i+1) : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// ARM toolchain doesn't provide itoa etc, provide them
|
||||
#include "api/itoa.h"
|
||||
|
||||
#endif // Arduino_h
|
||||
@@ -0,0 +1,145 @@
|
||||
# Copyright (c) 2021 Earle F. Philhower, III
|
||||
#
|
||||
# Raspberry Pi RP2040 Core platform file
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
# For more info:
|
||||
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
|
||||
|
||||
name=Raspberry Pi RP2040 Boards(1.3.1)
|
||||
version=1.3.1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
compiler.path={runtime.tools.pqt-gcc.path}/bin/
|
||||
|
||||
# Compile variables
|
||||
# -----------------
|
||||
|
||||
compiler.warning_flags=-w
|
||||
compiler.warning_flags.none=-w
|
||||
compiler.warning_flags.default=
|
||||
compiler.warning_flags.more=-Wall
|
||||
compiler.warning_flags.all=-Wall -Wextra
|
||||
|
||||
compiler.defines={build.led}
|
||||
compiler.includes="-iprefix{runtime.platform.path}/" "@{runtime.platform.path}/lib/platform_inc.txt"
|
||||
compiler.flags=-Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions
|
||||
compiler.wrap="@{runtime.platform.path}/lib/platform_wrap.txt"
|
||||
|
||||
compiler.c.cmd=arm-none-eabi-gcc
|
||||
compiler.c.flags=-c {compiler.defines} {compiler.flags} {compiler.includes} -std=gnu17 -g
|
||||
compiler.c.elf.cmd=arm-none-eabi-g++
|
||||
compiler.c.elf.flags={compiler.defines} {compiler.flags} -Wl,--gc-sections -u _printf_float -u _scanf_float
|
||||
compiler.S.cmd=arm-none-eabi-gcc
|
||||
compiler.S.flags=-c -g -x assembler-with-cpp -MMD {compiler.includes} -g
|
||||
compiler.cpp.cmd=arm-none-eabi-g++
|
||||
compiler.cpp.flags=-c {compiler.defines} {compiler.flags} {compiler.includes} -fno-rtti -std=gnu++17 -g
|
||||
|
||||
compiler.ar.cmd=arm-none-eabi-ar
|
||||
compiler.ar.flags=rcs
|
||||
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
||||
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
|
||||
compiler.elf2hex.bin.flags=-O binary
|
||||
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
|
||||
compiler.elf2hex.cmd=arm-none-eabi-objcopy
|
||||
compiler.ldflags={compiler.wrap} -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common
|
||||
compiler.size.cmd=arm-none-eabi-size
|
||||
compiler.define=-DARDUINO=
|
||||
compiler.readelf.cmd=arm-none-eabi-readelf
|
||||
|
||||
# this can be overriden in boards.txt
|
||||
build.extra_flags=
|
||||
|
||||
# These can be overridden in platform.local.txt
|
||||
compiler.c.extra_flags=
|
||||
compiler.c.elf.extra_flags=
|
||||
compiler.cpp.extra_flags=
|
||||
compiler.S.extra_flags=
|
||||
compiler.ar.extra_flags=
|
||||
compiler.elf2hex.extra_flags=
|
||||
|
||||
# Board configuration, set in boards.txt. Present here to ensure substitution works
|
||||
build.flash_length=
|
||||
build.eeprom_start=
|
||||
build.fs_start=
|
||||
build.fs_end=
|
||||
|
||||
build.boot2=boot2_generic_03h_4_padded_checksum
|
||||
|
||||
# Allow Pico boards do be auto-discovered by the IDE
|
||||
discovery.rp2040.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/discovery.py"
|
||||
|
||||
|
||||
# Compile patterns
|
||||
# ----------------
|
||||
|
||||
## Compile c files
|
||||
## Add -DBOARD_NAME="{build.board}"
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile c++ files
|
||||
## Add -DBOARD_NAME="{build.board}"
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile S files
|
||||
## Add -DBOARD_NAME="{build.board}"
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Create archives
|
||||
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
|
||||
archive_file_path={build.path}/{archive_file}
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.hooks.linking.prelink.1.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/simplesub.py" --input "{runtime.platform.path}/lib/memmap_default.ld" --out "{build.path}/memmap_default.ld" --sub __FLASH_LENGTH__ {build.flash_length} --sub __EEPROM_START__ {build.eeprom_start} --sub __FS_START__ {build.fs_start} --sub __FS_END__ {build.fs_end}
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-Wl,--script={build.path}/memmap_default.ld" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nosys.specs -Wl,--start-group {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "{runtime.platform.path}/lib/libpico.a" -lm "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_binary_info/include" "{runtime.platform.path}/assembly/{build.boot2}.S" -lc -lstdc++ -Wl,--end-group
|
||||
|
||||
## Create output (UF2 file)
|
||||
recipe.objcopy.uf2.pattern="{runtime.tools.pqt-elf2uf2.path}/elf2uf2" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.uf2"
|
||||
|
||||
build.preferred_out_format=uf2
|
||||
|
||||
## Save hex
|
||||
recipe.output.tmp_file={build.project_name}.{build.preferred_out_format}
|
||||
recipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_out_format}
|
||||
|
||||
## Compute size
|
||||
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
|
||||
recipe.size.regex=^(?:\.boot2|\.text|\.rodata|\.ARM\.extab|\.ARM\.exidx)\s+([0-9]+).*
|
||||
recipe.size.regex.data=^(?:\.data|\.bss|\.ram_vector_table|\.uninitialized_data)\s+([0-9]+).*
|
||||
|
||||
tools.uf2conv.path=
|
||||
# Because the variable expansion doesn't allow one tool to find another, the following lines
|
||||
# will point to "{runtime.platform.path}/tools/python3/python3" in GIT and
|
||||
# "{runtime.tools.pqt-python3.path}/python3" for JSON board manager releases.
|
||||
tools.uf2conv.cmd={runtime.tools.pqt-python3.path}/python3
|
||||
|
||||
tools.uf2conv.upload.protocol=uf2
|
||||
tools.uf2conv.upload.params.verbose=
|
||||
tools.uf2conv.upload.params.quiet=
|
||||
tools.uf2conv.upload.pattern="{cmd}" "{runtime.platform.path}/tools/uf2conv.py" --serial "{serial.port}" --family RP2040 --deploy "{build.path}/{build.project_name}.uf2"
|
||||
|
||||
|
||||
tools.picoprobe.cmd={runtime.tools.pqt-openocd.path}
|
||||
|
||||
tools.picoprobe.upload.protocol=picoprobe
|
||||
tools.picoprobe.upload.params.verbose=
|
||||
tools.picoprobe.upload.params.quiet=
|
||||
tools.picoprobe.upload.pattern="{cmd}/bin/openocd" -f "interface/picoprobe.cfg" -f "target/rp2040.cfg" -s "{cmd}/share/openocd/scripts" -c "program {build.path}/{build.project_name}.elf verify reset exit"
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Arduino header for the Raspberry Pi Pico RP2040
|
||||
*
|
||||
* Copyright (c) 2021 Earle F. Philhower, III <earlephilhower@yahoo.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef Arduino_h
|
||||
#define Arduino_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
// Wacky deprecated AVR compatibilty functions
|
||||
#include "stdlib_noniso.h"
|
||||
|
||||
#include "api/ArduinoAPI.h"
|
||||
#include <pins_arduino.h>
|
||||
|
||||
|
||||
// Required for the port*Register macros
|
||||
#include "hardware/gpio.h"
|
||||
|
||||
#include "debug_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif // __cplusplus
|
||||
|
||||
// For compatibility to many platforms and libraries
|
||||
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
||||
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
||||
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
|
||||
|
||||
// Disable/reenable all interrupts. Safely handles nested disables
|
||||
void interrupts();
|
||||
void noInterrupts();
|
||||
|
||||
// GPIO change/value interrupts
|
||||
void attachInterrupt(pin_size_t pin, voidFuncPtr callback, PinStatus mode);
|
||||
void detachInterrupt(pin_size_t pin);
|
||||
|
||||
// AVR compatibilty macros...naughty and accesses the HW directly
|
||||
#define digitalPinToPort(pin) (0)
|
||||
#define digitalPinToBitMask(pin) (1UL << (pin))
|
||||
#define digitalPinToTimer(pin) (0)
|
||||
#define digitalPinToInterrupt(pin) (pin)
|
||||
#define NOT_AN_INTERRUPT (-1)
|
||||
#define portOutputRegister(port) ((volatile uint32_t*) sio_hw->gpio_out)
|
||||
#define portInputRegister(port) ((volatile uint32_t*) sio_hw->gpio_in)
|
||||
#define portModeRegister(port) ((volatile uint32_t*) sio_hw->gpio_oe)
|
||||
|
||||
// IO config
|
||||
void pinMode(pin_size_t pinNumber, PinMode pinMode);
|
||||
|
||||
// SIO (GPIO)
|
||||
void digitalWrite(pin_size_t pinNumber, PinStatus status);
|
||||
PinStatus digitalRead(pin_size_t pinNumber);
|
||||
|
||||
// ADC
|
||||
int analogRead(pin_size_t pinNumber);
|
||||
float analogReadTemp(); // Returns core temp in Centigrade
|
||||
|
||||
// PWM
|
||||
void analogWrite(pin_size_t pinNumber, int value);
|
||||
void analogWriteFreq(uint32_t freq);
|
||||
void analogWriteRange(uint32_t range);
|
||||
void analogWriteResolution(int res);
|
||||
|
||||
// Timing
|
||||
void delay(unsigned long);
|
||||
void delayMicroseconds(unsigned int us);
|
||||
unsigned long millis();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// Ancient AVR defines
|
||||
#define HAVE_HWSERIAL0
|
||||
#define HAVE_HWSERIAL1
|
||||
#define HAVE_HWSERIAL2
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "SerialUSB.h"
|
||||
#include "SerialUART.h"
|
||||
#include "RP2040.h"
|
||||
#include "Bootsel.h"
|
||||
|
||||
// Template which will evaluate at *compile time* to a single 32b number
|
||||
// with the specified bits set.
|
||||
template <size_t N>
|
||||
constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U) {
|
||||
return i < N ? (1L << a[i]) | __bitset(a, i+1) : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// ARM toolchain doesn't provide itoa etc, provide them
|
||||
#include "api/itoa.h"
|
||||
|
||||
#endif // Arduino_h
|
||||
@@ -0,0 +1,145 @@
|
||||
# Copyright (c) 2021 Earle F. Philhower, III
|
||||
#
|
||||
# Raspberry Pi RP2040 Core platform file
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
# For more info:
|
||||
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
|
||||
|
||||
name=Raspberry Pi RP2040 Boards(1.4.0)
|
||||
version=1.4.0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
compiler.path={runtime.tools.pqt-gcc.path}/bin/
|
||||
|
||||
# Compile variables
|
||||
# -----------------
|
||||
|
||||
compiler.warning_flags=-w
|
||||
compiler.warning_flags.none=-w
|
||||
compiler.warning_flags.default=
|
||||
compiler.warning_flags.more=-Wall
|
||||
compiler.warning_flags.all=-Wall -Wextra
|
||||
|
||||
compiler.defines={build.led}
|
||||
compiler.includes="-iprefix{runtime.platform.path}/" "@{runtime.platform.path}/lib/platform_inc.txt"
|
||||
compiler.flags=-Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions
|
||||
compiler.wrap="@{runtime.platform.path}/lib/platform_wrap.txt"
|
||||
|
||||
compiler.c.cmd=arm-none-eabi-gcc
|
||||
compiler.c.flags=-c {compiler.defines} {compiler.flags} {compiler.includes} -std=gnu17 -g
|
||||
compiler.c.elf.cmd=arm-none-eabi-g++
|
||||
compiler.c.elf.flags={compiler.defines} {compiler.flags} -Wl,--gc-sections -u _printf_float -u _scanf_float
|
||||
compiler.S.cmd=arm-none-eabi-gcc
|
||||
compiler.S.flags=-c -g -x assembler-with-cpp -MMD {compiler.includes} -g
|
||||
compiler.cpp.cmd=arm-none-eabi-g++
|
||||
compiler.cpp.flags=-c {compiler.defines} {compiler.flags} {compiler.includes} -fno-rtti -std=gnu++17 -g
|
||||
|
||||
compiler.ar.cmd=arm-none-eabi-ar
|
||||
compiler.ar.flags=rcs
|
||||
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
||||
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
|
||||
compiler.elf2hex.bin.flags=-O binary
|
||||
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
|
||||
compiler.elf2hex.cmd=arm-none-eabi-objcopy
|
||||
compiler.ldflags={compiler.wrap} -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common
|
||||
compiler.size.cmd=arm-none-eabi-size
|
||||
compiler.define=-DARDUINO=
|
||||
compiler.readelf.cmd=arm-none-eabi-readelf
|
||||
|
||||
# this can be overriden in boards.txt
|
||||
build.extra_flags=
|
||||
|
||||
# These can be overridden in platform.local.txt
|
||||
compiler.c.extra_flags=
|
||||
compiler.c.elf.extra_flags=
|
||||
compiler.cpp.extra_flags=
|
||||
compiler.S.extra_flags=
|
||||
compiler.ar.extra_flags=
|
||||
compiler.elf2hex.extra_flags=
|
||||
|
||||
# Board configuration, set in boards.txt. Present here to ensure substitution works
|
||||
build.flash_length=
|
||||
build.eeprom_start=
|
||||
build.fs_start=
|
||||
build.fs_end=
|
||||
|
||||
build.boot2=boot2_generic_03h_4_padded_checksum
|
||||
|
||||
# Allow Pico boards do be auto-discovered by the IDE
|
||||
discovery.rp2040.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/discovery.py"
|
||||
|
||||
|
||||
# Compile patterns
|
||||
# ----------------
|
||||
|
||||
## Compile c files
|
||||
## Add -DBOARD_NAME="{build.board}"
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile c++ files
|
||||
## Add -DBOARD_NAME="{build.board}"
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile S files
|
||||
## Add -DBOARD_NAME="{build.board}"
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Create archives
|
||||
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
|
||||
archive_file_path={build.path}/{archive_file}
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.hooks.linking.prelink.1.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/simplesub.py" --input "{runtime.platform.path}/lib/memmap_default.ld" --out "{build.path}/memmap_default.ld" --sub __FLASH_LENGTH__ {build.flash_length} --sub __EEPROM_START__ {build.eeprom_start} --sub __FS_START__ {build.fs_start} --sub __FS_END__ {build.fs_end}
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-Wl,--script={build.path}/memmap_default.ld" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nosys.specs -Wl,--as-needed -Wl,--start-group {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" -Wl,--whole-archive "{runtime.platform.path}/lib/libpico.a" -Wl,--no-whole-archive -lm "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_binary_info/include" "{runtime.platform.path}/assembly/{build.boot2}.S" -lc -lstdc++ -Wl,--end-group
|
||||
|
||||
## Create output (UF2 file)
|
||||
recipe.objcopy.uf2.pattern="{runtime.tools.pqt-elf2uf2.path}/elf2uf2" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.uf2"
|
||||
|
||||
build.preferred_out_format=uf2
|
||||
|
||||
## Save hex
|
||||
recipe.output.tmp_file={build.project_name}.{build.preferred_out_format}
|
||||
recipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_out_format}
|
||||
|
||||
## Compute size
|
||||
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
|
||||
recipe.size.regex=^(?:\.boot2|\.text|\.rodata|\.ARM\.extab|\.ARM\.exidx)\s+([0-9]+).*
|
||||
recipe.size.regex.data=^(?:\.data|\.bss|\.ram_vector_table|\.uninitialized_data)\s+([0-9]+).*
|
||||
|
||||
tools.uf2conv.path=
|
||||
# Because the variable expansion doesn't allow one tool to find another, the following lines
|
||||
# will point to "{runtime.platform.path}/tools/python3/python3" in GIT and
|
||||
# "{runtime.tools.pqt-python3.path}/python3" for JSON board manager releases.
|
||||
tools.uf2conv.cmd={runtime.tools.pqt-python3.path}/python3
|
||||
|
||||
tools.uf2conv.upload.protocol=uf2
|
||||
tools.uf2conv.upload.params.verbose=
|
||||
tools.uf2conv.upload.params.quiet=
|
||||
tools.uf2conv.upload.pattern="{cmd}" "{runtime.platform.path}/tools/uf2conv.py" --serial "{serial.port}" --family RP2040 --deploy "{build.path}/{build.project_name}.uf2"
|
||||
|
||||
|
||||
tools.picoprobe.cmd={runtime.tools.pqt-openocd.path}
|
||||
|
||||
tools.picoprobe.upload.protocol=picoprobe
|
||||
tools.picoprobe.upload.params.verbose=
|
||||
tools.picoprobe.upload.params.quiet=
|
||||
tools.picoprobe.upload.pattern="{cmd}/bin/openocd" -f "interface/picoprobe.cfg" -f "target/rp2040.cfg" -s "{cmd}/share/openocd/scripts" -c "program {build.path}/{build.project_name}.elf verify reset exit"
|
||||
@@ -2,29 +2,36 @@
|
||||
|
||||
[](https://www.ardu-badge.com/RPI_PICO_TimerInterrupt)
|
||||
[](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/releases)
|
||||
[](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/blob/master/LICENSE)
|
||||
[](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/blob/main/LICENSE)
|
||||
[](#Contributing)
|
||||
[](http://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues)
|
||||
|
||||
|
||||
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
|
||||
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
## Table of Contents
|
||||
|
||||
* [Important Change from v1.2.0](#Important-Change-from-v120)
|
||||
* [Why do we need this RPI_PICO_TimerInterrupt library](#why-do-we-need-this-rpi_pico_timerinterrupt-library)
|
||||
* [Features](#features)
|
||||
* [Why using ISR-based Hardware Timer Interrupt is better](#why-using-isr-based-hardware-timer-interrupt-is-better)
|
||||
* [Currently supported Boards](#currently-supported-boards)
|
||||
* [Important Notes about ISR](#important-notes-about-isr)
|
||||
* [Changelog](#changelog)
|
||||
* [Initial Releases v1.0.0](#initial-releases-v100)
|
||||
* [Changelog](changelog.md)
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Installation](#installation)
|
||||
* [Use Arduino Library Manager](#use-arduino-library-manager)
|
||||
* [Manual Install](#manual-install)
|
||||
* [VS Code & PlatformIO](#vs-code--platformio)
|
||||
* [Packages' Patches](#packages-patches)
|
||||
* [1. For RP2040-based boards](#1-for-rp2040-based-boards)
|
||||
* [1. For RP2040-based boards using Earle Philhower arduino-pico core](#1-for-rp2040-based-boards-using-earle-philhower-arduino-pico-core)
|
||||
* [1.1. To use BOARD_NAME](#11-to-use-board_name)
|
||||
* [1.2. To avoid compile error relating to microsecondsToClockCycles](#12-to-avoid-compile-error-relating-to-microsecondstoclockcycles)
|
||||
* [HOWTO Fix `Multiple Definitions` Linker Error](#howto-fix-multiple-definitions-linker-error)
|
||||
* [More useful Information](#more-useful-information)
|
||||
* [Usage](#usage)
|
||||
@@ -41,19 +48,22 @@
|
||||
* [ 2. Argument_None](examples/Argument_None)
|
||||
* [ 3. Argument_Simple](examples/Argument_Simple)
|
||||
* [ 4. Change_Interval](examples/Change_Interval).
|
||||
* [ 5. ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple)
|
||||
* [ 6. RPM_Measure](examples/RPM_Measure)
|
||||
* [ 7. SwitchDebounce](examples/SwitchDebounce)
|
||||
* [ 8. TimerInterruptTest](examples/TimerInterruptTest)
|
||||
* [ 5. ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex)
|
||||
* [ 6. ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple)
|
||||
* [ 7. RPM_Measure](examples/RPM_Measure)
|
||||
* [ 8. SwitchDebounce](examples/SwitchDebounce)
|
||||
* [ 9. TimerInterruptTest](examples/TimerInterruptTest)
|
||||
* [ 10. **multiFileProject**](examples/multiFileProject) **New**
|
||||
* [Example ISR_Timers_Array_Simple](#example-isr_timers_array_simple)
|
||||
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
|
||||
* [1. ISR_Timers_Array_Simple on RASPBERRY_PI_PICO](#1-isr_timers_array_simple-on-raspberry_pi_pico)
|
||||
* [2. TimerInterruptTest on RASPBERRY_PI_PICO](#2-timerinterrupttest-on-raspberry_pi_pico)
|
||||
* [3. Change_Interval on RASPBERRY_PI_PICO](#3-change_interval-on-raspberry_pi_pico)
|
||||
* [4. SwitchDebounce on RASPBERRY_PI_PICO](#4-switchdebounce-on-raspberry_pi_pico)
|
||||
* [5. ISR_Timers_Array_Simple on ADAFRUIT_FEATHER_RP2040](#5-isr_timers_array_simple-on-adafruit_feather_rp2040)
|
||||
* [6. ISR_16_Timers_Array_Complex on ADAFRUIT_ITSYBITSY_RP2040](#6-isr_16_timers_array_complex-on-adafruit_itsybitsy_rp2040)
|
||||
* [Debug](#debug)
|
||||
* [Troubleshooting](#troubleshooting)
|
||||
* [Releases](#releases)
|
||||
* [Issues](#issues)
|
||||
* [TO DO](#to-do)
|
||||
* [DONE](#done)
|
||||
@@ -65,6 +75,12 @@
|
||||
---
|
||||
---
|
||||
|
||||
### Important Change from v1.2.0
|
||||
|
||||
Please have a look at [HOWTO Fix `Multiple Definitions` Linker Error](#howto-fix-multiple-definitions-linker-error)
|
||||
|
||||
---
|
||||
|
||||
### Why do we need this [RPI_PICO_TimerInterrupt library](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt)
|
||||
|
||||
## Features
|
||||
@@ -73,7 +89,7 @@ This library enables you to use Interrupt from Hardware Timers on on RP2040-base
|
||||
|
||||
As **Hardware Timers are rare, and very precious assets** of any board, this library now enables you to use up to **16 ISR-based Timers, while consuming only 1 Hardware Timer**. Timers' interval is very long (**ulong millisecs**).
|
||||
|
||||
Now with these new **16 ISR-based timers**, the maximum interval is **practically unlimited** (limited only by unsigned long miliseconds) while **the accuracy is nearly perfect** compared to software timers.
|
||||
Now with these new **16 ISR-based timers**, the maximum interval is **practically unlimited** (limited only by unsigned long milliseconds) while **the accuracy is nearly perfect** compared to software timers.
|
||||
|
||||
The most important feature is they're ISR-based timers. Therefore, their executions are **not blocked by bad-behaving functions / tasks**. This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
@@ -84,11 +100,11 @@ Being ISR-based timers, their executions are not blocked by bad-behaving functio
|
||||
This non-being-blocked important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
You'll see blynkTimer Software is blocked while system is connecting to WiFi / Internet / Blynk, as well as by blocking task
|
||||
in loop(), using delay() function as an example. The elapsed time then is very unaccurate
|
||||
in `loop()`, using delay() function as an example. The elapsed time then is very unaccurate
|
||||
|
||||
### Why using ISR-based Hardware Timer Interrupt is better
|
||||
|
||||
Imagine you have a system with a **mission-critical** function, measuring water level and control the sump pump or doing something much more important. You normally use a software timer to poll, or even place the function in loop(). But what if another function is **blocking** the loop() or setup().
|
||||
Imagine you have a system with a **mission-critical** function, measuring water level and control the sump pump or doing something much more important. You normally use a software timer to poll, or even place the function in `loop()`. But what if another function is **blocking** the `loop()` or `setup()`.
|
||||
|
||||
So your function **might not be executed, and the result would be disastrous.**
|
||||
|
||||
@@ -96,19 +112,20 @@ You'd prefer to have your function called, no matter what happening with other f
|
||||
|
||||
The correct choice is to use a Hardware Timer with **Interrupt** to call your function.
|
||||
|
||||
These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they are much more **precise** (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy.
|
||||
These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they are much more **precise** (certainly depending on clock frequency accuracy) than other software timers using `millis()` or `micros()`. That's necessary if you need to measure some data requiring better accuracy.
|
||||
|
||||
Functions using normal software timers, relying on loop() and calling millis(), won't work if the loop() or setup() is blocked by certain operation. For example, certain function is blocking while it's connecting to WiFi or some services.
|
||||
Functions using normal software timers, relying on `loop()` and calling `millis()`, won't work if the `loop()` or `setup()` is blocked by certain operation. For example, certain function is blocking while it's connecting to WiFi or some services.
|
||||
|
||||
The catch is **your function is now part of an ISR (Interrupt Service Routine), and must be lean / mean, and follow certain rules.** More to read on:
|
||||
|
||||
[**HOWTO Attach Interrupt**](https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/)
|
||||
|
||||
|
||||
---
|
||||
|
||||
### Currently supported Boards
|
||||
|
||||
1. RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc.
|
||||
1. RP2040-based boards such as **RASPBERRY_PI_PICO, RASPBERRY_PI_PICO_W, ADAFRUIT_FEATHER_RP2040, Nano_RP2040_Connect, GENERIC_RP2040**, etc., using [`arduino-pico core`](https://github.com/earlephilhower/arduino-pico)
|
||||
|
||||
---
|
||||
|
||||
@@ -122,21 +139,19 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
|
||||
---
|
||||
---
|
||||
|
||||
## Changelog
|
||||
|
||||
### Initial Releases v1.0.0
|
||||
|
||||
1. Initial coding to support RP2040-based boards such as **RASPBERRY_PI_PICO**, etc. using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico)
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. [`Arduino IDE 1.8.13+` for Arduino](https://www.arduino.cc/en/Main/Software)
|
||||
2. [`Earle Philhower's arduino-pico core v1.2.1+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [](https://github.com/earlephilhower/arduino-pico/releases/latest)
|
||||
|
||||
1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [](https://github.com/arduino/Arduino/releases/latest)
|
||||
2. [`Earle Philhower's arduino-pico core v2.6.3+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [](https://github.com/earlephilhower/arduino-pico/releases/latest)
|
||||
3. To use with certain example, depending on which Ethernet card you're using:
|
||||
- [`Ethernet_Generic library v2.7.1+`](https://github.com/khoih-prog/Ethernet_Generic) for W5100, W5200 and W5500. [](https://github.com/khoih-prog/Ethernet_Generic/releases/latest)
|
||||
- [`EthernetENC library v2.0.3+`](https://github.com/jandrassy/EthernetENC) for ENC28J60. [](https://github.com/jandrassy/EthernetENC/releases/latest). **New and Better**
|
||||
- [`UIPEthernet library v2.0.12+`](https://github.com/UIPEthernet/UIPEthernet) for ENC28J60. [](https://github.com/UIPEthernet/UIPEthernet/releases/latest)
|
||||
4. To use with certain example
|
||||
- [`SimpleTimer library`](https://github.com/jfturcot/SimpleTimer) for [ISR_16_Timers_Array](examples/ISR_16_Timers_Array) and [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex) examples.
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
@@ -152,16 +167,16 @@ You can also use this link [ page.
|
||||
2. Download the latest release `RPI_PICO_TimerInterrupt-master.zip`.
|
||||
3. Extract the zip file to `RPI_PICO_TimerInterrupt-master` directory
|
||||
4. Copy whole `RPI_PICO_TimerInterrupt-master` folder to Arduino libraries' directory such as `~/Arduino/libraries/`.
|
||||
2. Download the latest release `RPI_PICO_TimerInterrupt-main.zip`.
|
||||
3. Extract the zip file to `RPI_PICO_TimerInterrupt-main` directory
|
||||
4. Copy whole `RPI_PICO_TimerInterrupt-main` folder to Arduino libraries' directory such as `~/Arduino/libraries/`.
|
||||
|
||||
### VS Code & PlatformIO
|
||||
|
||||
1. Install [VS Code](https://code.visualstudio.com/)
|
||||
2. Install [PlatformIO](https://platformio.org/platformio-ide)
|
||||
3. Install [**RPI_PICO_TimerInterrupt** library](https://platformio.org/lib/show/12177/RPI_PICO_TimerInterrupt) by using [Library Manager](https://platformio.org/lib/show/12177/RPI_PICO_TimerInterrupt/installation). Search for **RPI_PICO_TimerInterrupt** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
|
||||
4. Use included [platformio.ini](platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at [Project Configuration File](https://docs.platformio.org/page/projectconf.html)
|
||||
3. Install [**RPI_PICO_TimerInterrupt** library](https://registry.platformio.org/libraries/khoih-prog/RPI_PICO_TimerInterrupt) by using [Library Manager](https://registry.platformio.org/libraries/khoih-prog/RPI_PICO_TimerInterrupt/installation). Search for **RPI_PICO_TimerInterrupt** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
|
||||
4. Please visit documentation for the other options and examples at [Project Configuration File](https://docs.platformio.org/page/projectconf.html)
|
||||
|
||||
|
||||
---
|
||||
@@ -169,42 +184,65 @@ Another way to install is to:
|
||||
|
||||
### Packages' Patches
|
||||
|
||||
#### 1. For RP2040-based boards
|
||||
|
||||
***To be able to automatically detect and display BOARD_NAME on Seeeduino SAMD (RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc) boards***, you have to copy the file [RP2040 platform.txt](Packages_Patches/rp2040/hardware/rp2040/1.2.1) into rp2040 directory (~/.arduino15/packages/rp2040/hardware/rp2040/1.2.1).
|
||||
#### 1. For RP2040-based boards using [Earle Philhower arduino-pico core](https://github.com/earlephilhower/arduino-pico)
|
||||
|
||||
Supposing the rp2040 core version is 1.2.1. This file must be copied into the directory:
|
||||
#### Important: Only necessary if you use core v1.4.0-
|
||||
|
||||
- `~/.arduino15/packages/rp2040/hardware/rp2040/1.2.1/platform.txt`
|
||||
#### 1.1 To use BOARD_NAME
|
||||
|
||||
**To be able to automatically detect and display BOARD_NAME on RP2040-based boards (RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc) boards**, you have to copy the file [RP2040 platform.txt](Packages_Patches/rp2040/hardware/rp2040/1.4.0) into rp2040 directory (~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0).
|
||||
|
||||
Supposing the rp2040 core version is 1.4.0. This file must be copied into the directory:
|
||||
|
||||
- `~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0/platform.txt`
|
||||
|
||||
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
|
||||
This file must be copied into the directory:
|
||||
|
||||
- `~/.arduino15/packages/rp2040/hardware/rp2040/x.yy.zz/platform.txt`
|
||||
|
||||
With core after v1.4.0, this step is not necessary anymore thanks to the PR [Add -DBOARD_NAME="{build.board}" #136](https://github.com/earlephilhower/arduino-pico/pull/136).
|
||||
|
||||
#### 1.2 To avoid compile error relating to microsecondsToClockCycles
|
||||
|
||||
Some libraries, such as [Adafruit DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library), require the definition of microsecondsToClockCycles(). **To be able to compile and run on RP2040-based boards**, you have to copy the files in [**RP2040 Arduino.h**](Packages_Patches/rp2040/hardware/rp2040/1.4.0/cores/rp2040/Arduino.h) into rp2040 directory (~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0).
|
||||
|
||||
Supposing the rp2040 core version is 1.4.0. This file must be copied to replace:
|
||||
|
||||
- `~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0/cores/rp2040/Arduino.h`
|
||||
|
||||
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz
|
||||
This file must be copied to replace:
|
||||
|
||||
- `~/.arduino15/packages/rp2040/hardware/rp2040/x.yy.zz/cores/rp2040/Arduino.h`
|
||||
|
||||
With core after v1.4.0, this step is not necessary anymore thanks to the PR [Add defs for compatibility #142](https://github.com/earlephilhower/arduino-pico/pull/142).
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
### HOWTO Fix `Multiple Definitions` Linker Error
|
||||
|
||||
The current library implementation, using **xyz-Impl.h instead of standard xyz.cpp**, possibly creates certain `Multiple Definitions` Linker error in certain use cases. Although it's simple to just modify several lines of code, either in the library or in the application, the library is adding 2 more source directories
|
||||
The current library implementation, using `xyz-Impl.h` instead of standard `xyz.cpp`, possibly creates certain `Multiple Definitions` Linker error in certain use cases.
|
||||
|
||||
1. **scr_h** for new h-only files
|
||||
2. **src_cpp** for standard h/cpp files
|
||||
You can include these `.hpp` or `.h` files
|
||||
|
||||
besides the standard **src** directory.
|
||||
```C++
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
|
||||
To use the **old standard cpp** way, locate this library' directory, then just
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_ISR_Timer.hpp" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
```
|
||||
|
||||
1. **Delete the all the files in src directory.**
|
||||
2. **Copy all the files in src_cpp directory into src.**
|
||||
3. Close then reopen the application code in Arduino IDE, etc. to recompile from scratch.
|
||||
in many files. But be sure to use the following `.h` file **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error
|
||||
|
||||
To re-use the **new h-only** way, just
|
||||
```C++
|
||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_ISR_Timer.h" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
```
|
||||
|
||||
1. **Delete the all the files in src directory.**
|
||||
2. **Copy the files in src_h directory into src.**
|
||||
3. Close then reopen the application code in Arduino IDE, etc. to recompile from scratch.
|
||||
Check the new [**multiFileProject** example](examples/multiFileProject) for a `HOWTO` demo.
|
||||
|
||||
---
|
||||
---
|
||||
@@ -218,7 +256,7 @@ The RPI_PICO system timer peripheral provides a global microsecond timebase for
|
||||
|
||||
---
|
||||
|
||||
Now with these new `16 ISR-based timers` (while consuming only **1 hardware timer**), the maximum interval is practically unlimited (limited only by unsigned long miliseconds). The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
Now with these new `16 ISR-based timers` (while consuming only **1 hardware timer**), the maximum interval is practically unlimited (limited only by unsigned long milliseconds). The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
The `ISR_Timer_Complex` example will demonstrate the nearly perfect accuracy compared to software timers by printing the actual elapsed millisecs of each type of timers.
|
||||
@@ -240,7 +278,7 @@ Before using any Timer, you have to make sure the Timer has not been used by any
|
||||
|
||||
### 1.1 Init Hardware Timer
|
||||
|
||||
```
|
||||
```C++
|
||||
// Select the timer you're using, from ITimer0(0)-ITimer3(3)
|
||||
// Init RPI_PICO_Timer
|
||||
RPI_PICO_Timer ITimer1(1);
|
||||
@@ -250,7 +288,7 @@ RPI_PICO_Timer ITimer1(1);
|
||||
|
||||
Use one of these functions with **interval in unsigned long microseconds**
|
||||
|
||||
```
|
||||
```C++
|
||||
// interval (in us), callback is ISR
|
||||
bool setInterval(unsigned long interval, pico_timer_callback callback);
|
||||
|
||||
@@ -260,7 +298,7 @@ bool attachInterruptInterval(unsigned long interval, pico_timer_callback callbac
|
||||
|
||||
as follows
|
||||
|
||||
```
|
||||
```C++
|
||||
void TimerHandler()
|
||||
{
|
||||
// Doing something here inside ISR
|
||||
@@ -287,7 +325,7 @@ void setup()
|
||||
|
||||
Use one of these functions with **frequency in float Hz**
|
||||
|
||||
```
|
||||
```C++
|
||||
// frequency (in Hz), callback is ISR
|
||||
bool setFrequency(float frequency, pico_timer_callback callback)
|
||||
|
||||
@@ -297,7 +335,7 @@ bool attachInterrupt(float frequency, timer_callback callback);
|
||||
|
||||
as follows
|
||||
|
||||
```
|
||||
```C++
|
||||
void TimerHandler()
|
||||
{
|
||||
// Doing something here inside ISR
|
||||
@@ -329,7 +367,7 @@ The 16 ISR_based Timers, designed for long timer intervals, only support using *
|
||||
|
||||
### 2.2 Init Hardware Timer and ISR-based Timer
|
||||
|
||||
```
|
||||
```C++
|
||||
// Init RPI_PICO_Timer
|
||||
RPI_PICO_Timer ITimer1(1);
|
||||
|
||||
@@ -340,7 +378,7 @@ RPI_PICO_ISR_Timer ISR_timer;
|
||||
|
||||
### 2.3 Set Hardware Timer Interval and attach Timer Interrupt Handler functions
|
||||
|
||||
```
|
||||
```C++
|
||||
void TimerHandler()
|
||||
{
|
||||
ISR_timer.run();
|
||||
@@ -405,162 +443,20 @@ void setup()
|
||||
2. [Argument_None](examples/Argument_None)
|
||||
3. [Argument_Simple](examples/Argument_Simple)
|
||||
4. [Change_Interval](examples/Change_Interval)
|
||||
5. [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple)
|
||||
6. [RPM_Measure](examples/RPM_Measure)
|
||||
7. [SwitchDebounce](examples/SwitchDebounce)
|
||||
8. [TimerInterruptTest](examples/TimerInterruptTest)
|
||||
5. [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex)
|
||||
6. [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple)
|
||||
7. [RPM_Measure](examples/RPM_Measure)
|
||||
8. [SwitchDebounce](examples/SwitchDebounce)
|
||||
9. [TimerInterruptTest](examples/TimerInterruptTest)
|
||||
10. [**multiFileProject**](examples/multiFileProject). **New**
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
### Example [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple)
|
||||
|
||||
```
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/blob/b7d8f4b4b7eabec8c140fc55d88efb82939a6ad6/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino#L23-L168
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
||||
#define TIMER_INTERRUPT_DEBUG 1
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 4
|
||||
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
#include "RPi_Pico_ISR_Timer.h"
|
||||
|
||||
#include <SimpleTimer.h> // https://github.com/schinken/SimpleTimer
|
||||
|
||||
// Init RPI_PICO_Timer
|
||||
RPI_PICO_Timer ITimer1(1);
|
||||
|
||||
RPI_PICO_ISR_Timer ISR_timer;
|
||||
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN 25
|
||||
#endif
|
||||
|
||||
#define LED_TOGGLE_INTERVAL_MS 1000L
|
||||
|
||||
// You have to use longer time here if having problem because Arduino AVR clock is low, 16MHz => lower accuracy.
|
||||
// Tested OK with 1ms when not much load => higher accuracy.
|
||||
#define TIMER_INTERVAL_MS 1L
|
||||
|
||||
volatile uint32_t startMillis = 0;
|
||||
|
||||
volatile uint32_t deltaMillis2s = 0;
|
||||
volatile uint32_t deltaMillis5s = 0;
|
||||
|
||||
volatile uint32_t previousMillis2s = 0;
|
||||
volatile uint32_t previousMillis5s = 0;
|
||||
|
||||
|
||||
bool TimerHandler(struct repeating_timer *t)
|
||||
{
|
||||
static bool toggle = false;
|
||||
static int timeRun = 0;
|
||||
|
||||
ISR_timer.run();
|
||||
|
||||
// Toggle LED every LED_TOGGLE_INTERVAL_MS = 2000ms = 2s
|
||||
if (++timeRun == ((LED_TOGGLE_INTERVAL_MS) / TIMER_INTERVAL_MS) )
|
||||
{
|
||||
timeRun = 0;
|
||||
|
||||
//timer interrupt toggles pin LED_BUILTIN
|
||||
digitalWrite(LED_BUILTIN, toggle);
|
||||
toggle = !toggle;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void doingSomething2s()
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
deltaMillis2s = currentMillis - previousMillis2s;
|
||||
previousMillis2s = currentMillis;
|
||||
}
|
||||
|
||||
void doingSomething5s()
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
deltaMillis5s = currentMillis - previousMillis5s;
|
||||
previousMillis5s = currentMillis;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#define SIMPLE_TIMER_MS 2000L
|
||||
|
||||
// Init SimpleTimer
|
||||
SimpleTimer simpleTimer;
|
||||
|
||||
// Here is software Timer, you can do somewhat fancy stuffs without many issues.
|
||||
// But always avoid
|
||||
// 1. Long delay() it just doing nothing and pain-without-gain wasting CPU power.Plan and design your code / strategy ahead
|
||||
// 2. Very long "do", "while", "for" loops without predetermined exit time.
|
||||
void simpleTimerDoingSomething2s()
|
||||
{
|
||||
static unsigned long previousMillis = startMillis;
|
||||
|
||||
unsigned long currMillis = millis();
|
||||
|
||||
Serial.print(F("SimpleTimer : programmed ")); Serial.print(SIMPLE_TIMER_MS);
|
||||
Serial.print(F("ms, current time ms : ")); Serial.print(currMillis);
|
||||
Serial.print(F(", Delta ms : ")); Serial.println(currMillis - previousMillis);
|
||||
|
||||
Serial.print(F("Timer2s actual : ")); Serial.println(deltaMillis2s);
|
||||
Serial.print(F("Timer5s actual : ")); Serial.println(deltaMillis5s);
|
||||
|
||||
previousMillis = currMillis;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
Serial.print(F("\nStarting ISR_Timers_Array_Simple on "));
|
||||
Serial.println(BOARD_NAME);
|
||||
Serial.println(RPI_PICO_TIMER_INTERRUPT_VERSION);
|
||||
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
|
||||
|
||||
if (ITimer1.attachInterruptInterval(TIMER_INTERVAL_MS *1000, TimerHandler))
|
||||
{
|
||||
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
|
||||
}
|
||||
else
|
||||
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
|
||||
|
||||
ISR_timer.setInterval(2000L, doingSomething2s);
|
||||
ISR_timer.setInterval(5000L, doingSomething5s);
|
||||
|
||||
// You need this timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary.
|
||||
simpleTimer.setInterval(SIMPLE_TIMER_MS, simpleTimerDoingSomething2s);
|
||||
}
|
||||
|
||||
#define BLOCKING_TIME_MS 10000L
|
||||
|
||||
void loop()
|
||||
{
|
||||
// This unadvised blocking task is used to demonstrate the blocking effects onto the execution and accuracy to Software timer
|
||||
// You see the time elapse of ISR_Timer still accurate, whereas very unaccurate for Software Timer
|
||||
// The time elapse for 2000ms software timer now becomes 3000ms (BLOCKING_TIME_MS)
|
||||
// While that of ISR_Timer is still prefect.
|
||||
delay(BLOCKING_TIME_MS);
|
||||
|
||||
// You need this Software timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary
|
||||
// You don't need to and never call ISR_Timer.run() here in the loop(). It's already handled by ISR timer.
|
||||
simpleTimer.run();
|
||||
}
|
||||
```
|
||||
---
|
||||
---
|
||||
|
||||
@@ -574,14 +470,10 @@ While software timer, **programmed for 2s, is activated after more than 10.000s
|
||||
|
||||
```
|
||||
Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO
|
||||
RPi_Pico_TimerInterrupt v1.0.0
|
||||
RPi_Pico_TimerInterrupt v1.3.1
|
||||
CPU Frequency = 125 MHz
|
||||
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
|
||||
[TISR] _count = 0 - 1000
|
||||
[TISR] add_repeating_timer_us = 1000
|
||||
Starting ITimer1 OK, millis() = 1707
|
||||
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 3 , _fre = 1000000.00
|
||||
[TISR] _count = 0 - 1000
|
||||
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
|
||||
[TISR] _count = 0-1000
|
||||
[TISR] add_repeating_timer_us = 1000
|
||||
Starting ITimer3 OK, millis() = 1707
|
||||
SimpleTimer : programmed 2000ms, current time ms : 11707, Delta ms : 11707
|
||||
@@ -603,15 +495,15 @@ The following is the sample terminal output when running example [TimerInterrupt
|
||||
|
||||
```
|
||||
Starting TimerInterruptTest on RASPBERRY_PI_PICO
|
||||
RPi_Pico_TimerInterrupt v1.0.0
|
||||
RPi_Pico_TimerInterrupt v1.3.1
|
||||
CPU Frequency = 125 MHz
|
||||
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
|
||||
[TISR] _count = 0 - 1000000
|
||||
[TISR] timer_set_alarm_value (us) = 1000000
|
||||
Starting ITimer0 OK, millis() = 1781
|
||||
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
|
||||
[TISR] _count = 0 - 3000000
|
||||
[TISR] timer_set_alarm_value (us) = 3000000
|
||||
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 1.00
|
||||
[TISR] _count = 0-1000000
|
||||
[TISR] add_repeating_timer_us = 1000000
|
||||
Starting ITimer0 OK, millis() = 882
|
||||
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 0.33
|
||||
[TISR] _count = 0-3000000
|
||||
[TISR] add_repeating_timer_us = 3000000
|
||||
Starting ITimer1 OK, millis() = 1782
|
||||
ITimer0 called, millis() = 2781
|
||||
ITimer0 called, millis() = 3781
|
||||
@@ -647,14 +539,14 @@ The following is the sample terminal output when running example [Change_Interva
|
||||
|
||||
```
|
||||
Starting Change_Interval on RASPBERRY_PI_PICO
|
||||
RPi_Pico_TimerInterrupt v1.0.0
|
||||
RPi_Pico_TimerInterrupt v1.3.1
|
||||
CPU Frequency = 125 MHz
|
||||
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
|
||||
[TISR] _count = 0 - 2000000
|
||||
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 0.50
|
||||
[TISR] _count = 0-2000000
|
||||
[TISR] add_repeating_timer_us = 2000000
|
||||
Starting ITimer0 OK, millis() = 1544
|
||||
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
|
||||
[TISR] _count = 0 - 5000000
|
||||
Starting ITimer0 OK, millis() = 2363
|
||||
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 0.20
|
||||
[TISR] _count = 0-5000000
|
||||
[TISR] add_repeating_timer_us = 5000000
|
||||
Starting ITimer1 OK, millis() = 1544
|
||||
ITimer0: millis() = 3544
|
||||
@@ -728,10 +620,10 @@ The following is the sample terminal output when running example [SwitchDebounce
|
||||
|
||||
```
|
||||
Starting SwitchDebounce on RASPBERRY_PI_PICO
|
||||
RPi_Pico_TimerInterrupt v1.0.0
|
||||
RPi_Pico_TimerInterrupt v1.3.1
|
||||
CPU Frequency = 125 MHz
|
||||
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
|
||||
[TISR] _count = 0 - 20000
|
||||
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 50.00
|
||||
[TISR] _count = 0-20000
|
||||
[TISR] add_repeating_timer_us = 20000
|
||||
Starting ITimer1 OK, millis() = 1302
|
||||
SW Press, from millis() = 77377
|
||||
@@ -745,6 +637,181 @@ SW Released, from millis() = 80238
|
||||
SW Pressed total time ms = 1181
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 5. ISR_Timers_Array_Simple on ADAFRUIT_FEATHER_RP2040
|
||||
|
||||
The following is the sample terminal output when running example [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple) on ADAFRUIT_FEATHER_RP2040
|
||||
|
||||
```
|
||||
Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO
|
||||
RPi_Pico_TimerInterrupt v1.3.1
|
||||
CPU Frequency = 125 MHz
|
||||
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
|
||||
[TISR] _count = 0-1000
|
||||
[TISR] add_repeating_timer_us = 1000
|
||||
Starting ITimer1 OK, millis() = 1701
|
||||
SimpleTimer : programmed 2000ms, current time ms : 11707, Delta ms : 11707
|
||||
Timer2s actual : 2000
|
||||
Timer5s actual : 5000
|
||||
SimpleTimer : programmed 2000ms, current time ms : 21707, Delta ms : 10000
|
||||
Timer2s actual : 2000
|
||||
Timer5s actual : 5000
|
||||
SimpleTimer : programmed 2000ms, current time ms : 31708, Delta ms : 10001
|
||||
Timer2s actual : 2000
|
||||
Timer5s actual : 5000
|
||||
```
|
||||
|
||||
### 6. ISR_16_Timers_Array_Complex on ADAFRUIT_ITSYBITSY_RP2040
|
||||
|
||||
The following is the sample terminal output when running example [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex) on ADAFRUIT_ITSYBITSY_RP2040
|
||||
|
||||
```
|
||||
Starting ISR_16_Timers_Array_Complex on RASPBERRY_PI_PICO
|
||||
RPi_Pico_TimerInterrupt v1.3.1
|
||||
CPU Frequency = 125 MHz
|
||||
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 100.00
|
||||
[TISR] _count = 0-10000
|
||||
[TISR] add_repeating_timer_us = 10000
|
||||
Starting ITimer OK, millis() = 1797
|
||||
SimpleTimer : 2, ms : 11798, Dms : 10001
|
||||
Timer : 0, programmed : 5000, actual : 5005
|
||||
Timer : 1, programmed : 10000, actual : 0
|
||||
Timer : 2, programmed : 15000, actual : 0
|
||||
Timer : 3, programmed : 20000, actual : 0
|
||||
Timer : 4, programmed : 25000, actual : 0
|
||||
Timer : 5, programmed : 30000, actual : 0
|
||||
Timer : 6, programmed : 35000, actual : 0
|
||||
Timer : 7, programmed : 40000, actual : 0
|
||||
Timer : 8, programmed : 45000, actual : 0
|
||||
Timer : 9, programmed : 50000, actual : 0
|
||||
Timer : 10, programmed : 55000, actual : 0
|
||||
Timer : 11, programmed : 60000, actual : 0
|
||||
Timer : 12, programmed : 65000, actual : 0
|
||||
Timer : 13, programmed : 70000, actual : 0
|
||||
Timer : 14, programmed : 75000, actual : 0
|
||||
Timer : 15, programmed : 80000, actual : 0
|
||||
SimpleTimer : 2, ms : 21800, Dms : 10002
|
||||
Timer : 0, programmed : 5000, actual : 4995
|
||||
Timer : 1, programmed : 10000, actual : 10010
|
||||
Timer : 2, programmed : 15000, actual : 15005
|
||||
Timer : 3, programmed : 20000, actual : 0
|
||||
Timer : 4, programmed : 25000, actual : 0
|
||||
Timer : 5, programmed : 30000, actual : 0
|
||||
Timer : 6, programmed : 35000, actual : 0
|
||||
Timer : 7, programmed : 40000, actual : 0
|
||||
Timer : 8, programmed : 45000, actual : 0
|
||||
Timer : 9, programmed : 50000, actual : 0
|
||||
Timer : 10, programmed : 55000, actual : 0
|
||||
Timer : 11, programmed : 60000, actual : 0
|
||||
Timer : 12, programmed : 65000, actual : 0
|
||||
Timer : 13, programmed : 70000, actual : 0
|
||||
Timer : 14, programmed : 75000, actual : 0
|
||||
Timer : 15, programmed : 80000, actual : 0
|
||||
SimpleTimer : 2, ms : 31802, Dms : 10002
|
||||
Timer : 0, programmed : 5000, actual : 4995
|
||||
Timer : 1, programmed : 10000, actual : 10000
|
||||
Timer : 2, programmed : 15000, actual : 15005
|
||||
Timer : 3, programmed : 20000, actual : 20010
|
||||
Timer : 4, programmed : 25000, actual : 25005
|
||||
Timer : 5, programmed : 30000, actual : 0
|
||||
Timer : 6, programmed : 35000, actual : 0
|
||||
Timer : 7, programmed : 40000, actual : 0
|
||||
Timer : 8, programmed : 45000, actual : 0
|
||||
Timer : 9, programmed : 50000, actual : 0
|
||||
Timer : 10, programmed : 55000, actual : 0
|
||||
Timer : 11, programmed : 60000, actual : 0
|
||||
Timer : 12, programmed : 65000, actual : 0
|
||||
Timer : 13, programmed : 70000, actual : 0
|
||||
Timer : 14, programmed : 75000, actual : 0
|
||||
Timer : 15, programmed : 80000, actual : 0
|
||||
SimpleTimer : 2, ms : 41804, Dms : 10002
|
||||
Timer : 0, programmed : 5000, actual : 4995
|
||||
Timer : 1, programmed : 10000, actual : 10000
|
||||
Timer : 2, programmed : 15000, actual : 15005
|
||||
Timer : 3, programmed : 20000, actual : 20010
|
||||
Timer : 4, programmed : 25000, actual : 25005
|
||||
Timer : 5, programmed : 30000, actual : 30010
|
||||
Timer : 6, programmed : 35000, actual : 35005
|
||||
Timer : 7, programmed : 40000, actual : 0
|
||||
Timer : 8, programmed : 45000, actual : 0
|
||||
Timer : 9, programmed : 50000, actual : 0
|
||||
Timer : 10, programmed : 55000, actual : 0
|
||||
Timer : 11, programmed : 60000, actual : 0
|
||||
Timer : 12, programmed : 65000, actual : 0
|
||||
Timer : 13, programmed : 70000, actual : 0
|
||||
Timer : 14, programmed : 75000, actual : 0
|
||||
Timer : 15, programmed : 80000, actual : 0
|
||||
SimpleTimer : 2, ms : 51807, Dms : 10003
|
||||
Timer : 0, programmed : 5000, actual : 4995
|
||||
Timer : 1, programmed : 10000, actual : 10000
|
||||
Timer : 2, programmed : 15000, actual : 14995
|
||||
Timer : 3, programmed : 20000, actual : 20000
|
||||
Timer : 4, programmed : 25000, actual : 25005
|
||||
Timer : 5, programmed : 30000, actual : 30010
|
||||
Timer : 6, programmed : 35000, actual : 35005
|
||||
Timer : 7, programmed : 40000, actual : 40010
|
||||
Timer : 8, programmed : 45000, actual : 45005
|
||||
Timer : 9, programmed : 50000, actual : 50010
|
||||
Timer : 10, programmed : 55000, actual : 0
|
||||
Timer : 11, programmed : 60000, actual : 0
|
||||
Timer : 12, programmed : 65000, actual : 0
|
||||
Timer : 13, programmed : 70000, actual : 0
|
||||
Timer : 14, programmed : 75000, actual : 0
|
||||
Timer : 15, programmed : 80000, actual : 0
|
||||
SimpleTimer : 2, ms : 61809, Dms : 10002
|
||||
Timer : 0, programmed : 5000, actual : 5005
|
||||
Timer : 1, programmed : 10000, actual : 10000
|
||||
Timer : 2, programmed : 15000, actual : 15005
|
||||
Timer : 3, programmed : 20000, actual : 20000
|
||||
Timer : 4, programmed : 25000, actual : 25005
|
||||
Timer : 5, programmed : 30000, actual : 30000
|
||||
Timer : 6, programmed : 35000, actual : 35005
|
||||
Timer : 7, programmed : 40000, actual : 40010
|
||||
Timer : 8, programmed : 45000, actual : 45005
|
||||
Timer : 9, programmed : 50000, actual : 50010
|
||||
Timer : 10, programmed : 55000, actual : 55005
|
||||
Timer : 11, programmed : 60000, actual : 60010
|
||||
Timer : 12, programmed : 65000, actual : 0
|
||||
Timer : 13, programmed : 70000, actual : 0
|
||||
Timer : 14, programmed : 75000, actual : 0
|
||||
Timer : 15, programmed : 80000, actual : 0
|
||||
SimpleTimer : 2, ms : 71812, Dms : 10003
|
||||
Timer : 0, programmed : 5000, actual : 5005
|
||||
Timer : 1, programmed : 10000, actual : 10000
|
||||
Timer : 2, programmed : 15000, actual : 15005
|
||||
Timer : 3, programmed : 20000, actual : 20000
|
||||
Timer : 4, programmed : 25000, actual : 25005
|
||||
Timer : 5, programmed : 30000, actual : 30000
|
||||
Timer : 6, programmed : 35000, actual : 35005
|
||||
Timer : 7, programmed : 40000, actual : 40010
|
||||
Timer : 8, programmed : 45000, actual : 45005
|
||||
Timer : 9, programmed : 50000, actual : 50010
|
||||
Timer : 10, programmed : 55000, actual : 55005
|
||||
Timer : 11, programmed : 60000, actual : 60010
|
||||
Timer : 12, programmed : 65000, actual : 65005
|
||||
Timer : 13, programmed : 70000, actual : 70010
|
||||
Timer : 14, programmed : 75000, actual : 0
|
||||
Timer : 15, programmed : 80000, actual : 0
|
||||
SimpleTimer : 2, ms : 81814, Dms : 10002
|
||||
Timer : 0, programmed : 5000, actual : 5005
|
||||
Timer : 1, programmed : 10000, actual : 10000
|
||||
Timer : 2, programmed : 15000, actual : 14995
|
||||
Timer : 3, programmed : 20000, actual : 20000
|
||||
Timer : 4, programmed : 25000, actual : 24995
|
||||
Timer : 5, programmed : 30000, actual : 30000
|
||||
Timer : 6, programmed : 35000, actual : 35005
|
||||
Timer : 7, programmed : 40000, actual : 40000
|
||||
Timer : 8, programmed : 45000, actual : 45005
|
||||
Timer : 9, programmed : 50000, actual : 50010
|
||||
Timer : 10, programmed : 55000, actual : 55005
|
||||
Timer : 11, programmed : 60000, actual : 60010
|
||||
Timer : 12, programmed : 65000, actual : 65005
|
||||
Timer : 13, programmed : 70000, actual : 70010
|
||||
Timer : 14, programmed : 75000, actual : 75005
|
||||
Timer : 15, programmed : 80000, actual : 80010
|
||||
```
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
@@ -754,7 +821,7 @@ Debug is enabled by default on Serial.
|
||||
|
||||
You can also change the debugging level (_TIMERINTERRUPT_LOGLEVEL_) from 0 to 4
|
||||
|
||||
```cpp
|
||||
```C++
|
||||
// These define's must be placed at the beginning before #include "RPI_PICO_TimerInterrupt.h"
|
||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
||||
@@ -771,15 +838,6 @@ If you get compilation errors, more often than not, you may need to install a ne
|
||||
Sometimes, the library will only work if you update the board core to the latest version because I am using newly added functions.
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
## Releases
|
||||
|
||||
### Initial Releases v1.0.0
|
||||
|
||||
1. Initial coding to support **RP2040-based boards such as RASPBERRY_PI_PICO**, etc. using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico)
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
@@ -798,11 +856,17 @@ Submit issues to: [RPI_PICO_TimerInterrupt issues](https://github.com/khoih-prog
|
||||
|
||||
## DONE
|
||||
|
||||
1. Basic hardware timers for **RP2040-based boards such as RASPBERRY_PI_PICO**, using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico)
|
||||
2. More hardware-initiated software-enabled timers
|
||||
3. Longer time interval
|
||||
4. Add Version String
|
||||
5. Add Table of Contents
|
||||
1. Basic hardware timers for **RP2040-based boards such as RASPBERRY_PI_PICO**, using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico)
|
||||
2. More hardware-initiated software-enabled timers
|
||||
3. Longer time interval
|
||||
4. Add Version String
|
||||
5. Add Table of Contents
|
||||
6. Add support to new boards (**ADAFRUIT_ITSYBITSY_RP2040, ADAFRUIT_QTPY_RP2040, ADAFRUIT_STEMMAFRIEND_RP2040, ADAFRUIT_TRINKEYQT_RP2040, ADAFRUIT_MACROPAD_RP2040, SPARKFUN_PROMICRO_RP2040, Nano_RP2040_Connect, etc.**) using the arduino-pico core
|
||||
7. Fix `multiple-definitions` linker error
|
||||
8. Optimize library code by using `reference-passing` instead of `value-passing`
|
||||
9. Fix severe bug affecting time between the starts. Check [Enable fixed timing between timer calls (vs fixed time btw. end of timer call and next call as implemented) #3](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues/3)
|
||||
10. Using `float` instead of `ulong` for better interval accuracy
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
@@ -811,6 +875,14 @@ Submit issues to: [RPI_PICO_TimerInterrupt issues](https://github.com/khoih-prog
|
||||
|
||||
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.
|
||||
|
||||
1. [AndreasOKircher](https://github.com/AndreasOKircher) to report issue [Enable fixed timing between timer calls (vs fixed time btw. end of timer call and next call as implemented) #3](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues/3) leading to version v1.3.0 to fix `severe bug` affecting time between the starts
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center"><a href="https://github.com/AndreasOKircher"><img src="https://github.com/AndreasOKircher.png" width="100px;" alt="AndreasOKircher"/><br /><sub><b>AndreasOKircher</b></sub></a><br /></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
---
|
||||
|
||||
@@ -827,7 +899,7 @@ If you want to contribute to this project:
|
||||
|
||||
### License
|
||||
|
||||
- The library is licensed under [MIT](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/blob/master/LICENSE)
|
||||
- The library is licensed under [MIT](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/blob/main/LICENSE)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# RPI_PICO_TimerInterrupt Library
|
||||
|
||||
[](https://www.ardu-badge.com/RPI_PICO_TimerInterrupt)
|
||||
[](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/releases)
|
||||
[](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/blob/master/LICENSE)
|
||||
[](#Contributing)
|
||||
[](http://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues)
|
||||
|
||||
|
||||
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
|
||||
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
## Table of Contents
|
||||
|
||||
* [Changelog](#changelog)
|
||||
* [Releases v1.3.1](#releases-v131)
|
||||
* [Releases v1.3.0](#releases-v130)
|
||||
* [Releases v1.2.0](#releases-v120)
|
||||
* [Releases v1.1.1](#releases-v111)
|
||||
* [Releases v1.1.0](#releases-v110)
|
||||
* [Releases v1.0.1](#releases-v101)
|
||||
* [Initial Releases v1.0.0](#initial-releases-v100)
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
## Changelog
|
||||
|
||||
### Releases v1.3.1
|
||||
|
||||
1. Using `float` instead of `ulong` for better interval accuracy
|
||||
|
||||
### Releases v1.3.0
|
||||
|
||||
1. Fix severe bug affecting time between the starts. Check [Enable fixed timing between timer calls (vs fixed time btw. end of timer call and next call as implemented) #3](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues/3)
|
||||
|
||||
|
||||
### Releases v1.2.0
|
||||
|
||||
1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
|
||||
2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project.
|
||||
3. Optimize library code by using `reference-passing` instead of `value-passing`
|
||||
4. Update all examples
|
||||
|
||||
### Releases v1.1.1
|
||||
|
||||
1. Fix platform in `library.json`
|
||||
|
||||
### Releases v1.1.0
|
||||
|
||||
1. Add support to new boards (**ADAFRUIT_ITSYBITSY_RP2040, ADAFRUIT_QTPY_RP2040, ADAFRUIT_STEMMAFRIEND_RP2040, ADAFRUIT_TRINKEYQT_RP2040, ADAFRUIT_MACROPAD_RP2040, SPARKFUN_PROMICRO_RP2040, etc.**) using the arduino-pico core
|
||||
2. Add `ISR_16_Timers_Array_Complex` examples.
|
||||
3. Fix examples' bug
|
||||
|
||||
### Releases v1.0.1
|
||||
|
||||
1. Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
||||
|
||||
### Initial Releases v1.0.0
|
||||
|
||||
1. Initial coding to support RP2040-based boards such as **RASPBERRY_PI_PICO**, etc. using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico)
|
||||
|
||||
|
||||
|
||||
@@ -18,31 +18,15 @@
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
||||
#define TIMER_INTERRUPT_DEBUG 1
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 4
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
|
||||
#if !defined(LED_BUILTIN)
|
||||
@@ -63,6 +47,8 @@ volatile pinStruct myOutputPins = { LED_BUILTIN, 0, 1 };
|
||||
|
||||
bool TimerHandler(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle = false;
|
||||
|
||||
//timer interrupt toggles pins
|
||||
@@ -98,10 +84,9 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
Serial.print(F("\nStarting Argument_Complex on "));
|
||||
Serial.println(BOARD_NAME);
|
||||
Serial.print(F("\nStarting Argument_Complex on ")); Serial.println(BOARD_NAME);
|
||||
Serial.println(RPI_PICO_TIMER_INTERRUPT_VERSION);
|
||||
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
|
||||
//Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
|
||||
|
||||
// Interval in microsecs
|
||||
if (ITimer1.attachInterruptInterval(TIMER_INTERVAL_MS * 1000, TimerHandler))
|
||||
|
||||
@@ -18,19 +18,6 @@
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
/*
|
||||
@@ -45,9 +32,6 @@
|
||||
or the entire sequence of your code which accesses the data.
|
||||
*/
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||
@@ -55,16 +39,19 @@
|
||||
#define TIMER_INTERRUPT_DEBUG 1
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 4
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN 25 // Pin LED_BUILTIN mapped to pin GPIO25 of RPI_PICO, control on-board LED
|
||||
#define LED_BUILTIN 25
|
||||
#endif
|
||||
|
||||
#define PIN_D1 1 // Pin D1 mapped to pin GPIO1 of RPI_PICO
|
||||
|
||||
bool TimerHandler0(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle0 = false;
|
||||
|
||||
#if (TIMER_INTERRUPT_DEBUG > 0)
|
||||
@@ -80,6 +67,8 @@ bool TimerHandler0(struct repeating_timer *t)
|
||||
|
||||
bool TimerHandler1(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle1 = false;
|
||||
|
||||
#if (TIMER_INTERRUPT_DEBUG > 0)
|
||||
|
||||
@@ -18,31 +18,15 @@
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
||||
#define TIMER_INTERRUPT_DEBUG 1
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 4
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
|
||||
#if !defined(LED_BUILTIN)
|
||||
@@ -60,6 +44,8 @@ RPI_PICO_Timer ITimer2(2);
|
||||
|
||||
bool TimerHandler1(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle1 = false;
|
||||
|
||||
#if (TIMER_INTERRUPT_DEBUG > 0)
|
||||
@@ -77,6 +63,8 @@ bool TimerHandler1(struct repeating_timer *t)
|
||||
|
||||
bool TimerHandler2(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle2 = false;
|
||||
|
||||
#if (TIMER_INTERRUPT_DEBUG > 0)
|
||||
@@ -99,8 +87,7 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
Serial.print(F("\nStarting Argument_Simple on "));
|
||||
Serial.println(BOARD_NAME);
|
||||
Serial.print(F("\nStarting Argument_Simple on ")); Serial.println(BOARD_NAME);
|
||||
Serial.println(RPI_PICO_TIMER_INTERRUPT_VERSION);
|
||||
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
|
||||
|
||||
|
||||
@@ -18,19 +18,6 @@
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
/*
|
||||
@@ -45,20 +32,17 @@
|
||||
or the entire sequence of your code which accesses the data.
|
||||
*/
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
||||
#define TIMER_INTERRUPT_DEBUG 1
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 4
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN 25 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
|
||||
#define LED_BUILTIN 25
|
||||
#endif
|
||||
|
||||
#define PIN_D1 1 // Pin D1 mapped to pin GPIO1 of RPI_PICO
|
||||
@@ -68,6 +52,8 @@ volatile uint32_t Timer1Count = 0;
|
||||
|
||||
bool TimerHandler0(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle0 = false;
|
||||
|
||||
// Flag for checking to be sure ISR is working as Serial.print is not OK here in ISR
|
||||
@@ -86,6 +72,8 @@ bool TimerHandler0(struct repeating_timer *t)
|
||||
|
||||
bool TimerHandler1(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle1 = false;
|
||||
|
||||
// Flag for checking to be sure ISR is working as Serial.print is not OK here in ISR
|
||||
|
||||
@@ -0,0 +1,368 @@
|
||||
/****************************************************************************************************************************
|
||||
ISR_16_Timers_Array.ino
|
||||
RPi_Pico_ISR_Timer-Impl.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Notes:
|
||||
Special design is necessary to share data between interrupt code and the rest of your program.
|
||||
Variables usually need to be "volatile" types. Volatile tells the compiler to avoid optimizations that assume
|
||||
variable can not spontaneously change. Because your function may change variables while your program is using them,
|
||||
the compiler needs this hint. But volatile alone is often not enough.
|
||||
When accessing shared variables, usually interrupts must be disabled. Even with volatile,
|
||||
if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly.
|
||||
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
|
||||
or the entire sequence of your code which accesses the data.
|
||||
|
||||
This example will demonstrate the nearly perfect accuracy compared to software timers by printing the actual elapsed millisecs.
|
||||
Being ISR-based timers, their executions are not blocked by bad-behaving functions / tasks, such as connecting to WiFi, Internet
|
||||
and Blynk services. You can also have many (up to 16) timers to use.
|
||||
This non-being-blocked important feature is absolutely necessary for mission-critical tasks.
|
||||
You'll see blynkTimer is blocked while connecting to WiFi / Internet / Blynk, and elapsed time is very unaccurate
|
||||
In this super simple example, you don't see much different after Blynk is connected, because of no competing task is
|
||||
written
|
||||
*/
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 4
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
|
||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_ISR_Timer.h"
|
||||
|
||||
#include <SimpleTimer.h> // https://github.com/jfturcot/SimpleTimer
|
||||
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN 25
|
||||
#endif
|
||||
|
||||
#ifndef LED_BLUE
|
||||
#define LED_BLUE 10
|
||||
#endif
|
||||
|
||||
#ifndef LED_RED
|
||||
#define LED_RED 11
|
||||
#endif
|
||||
|
||||
#define HW_TIMER_INTERVAL_US 10000L
|
||||
|
||||
volatile uint32_t startMillis = 0;
|
||||
|
||||
// You can select RPI_PICO_Timer from 0 to 3
|
||||
// Init RPI_PICO_Timer
|
||||
RPI_PICO_Timer ITimer(1);
|
||||
|
||||
// Init RPI_PICO_ISR_Timer
|
||||
// Each RPI_PICO_ISR_Timer can service 16 different ISR-based timers
|
||||
RPI_PICO_ISR_Timer ISR_Timer;
|
||||
|
||||
#define LED_TOGGLE_INTERVAL_MS 2000L
|
||||
|
||||
// Never use Serial.print inside this ISR. Will hang the system
|
||||
bool TimerHandler(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle = false;
|
||||
static int timeRun = 0;
|
||||
|
||||
ISR_Timer.run();
|
||||
|
||||
// Toggle LED every LED_TOGGLE_INTERVAL_MS = 2000ms = 2s
|
||||
if (++timeRun == ((LED_TOGGLE_INTERVAL_MS * 1000) / HW_TIMER_INTERVAL_US) )
|
||||
{
|
||||
timeRun = 0;
|
||||
|
||||
//timer interrupt toggles pin LED_BUILTIN
|
||||
digitalWrite(LED_BUILTIN, toggle);
|
||||
toggle = !toggle;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#define NUMBER_ISR_TIMERS 16
|
||||
|
||||
typedef void (*irqCallback) ();
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#define USE_COMPLEX_STRUCT true
|
||||
|
||||
#if USE_COMPLEX_STRUCT
|
||||
|
||||
typedef struct
|
||||
{
|
||||
irqCallback irqCallbackFunc;
|
||||
uint32_t TimerInterval;
|
||||
unsigned long deltaMillis;
|
||||
unsigned long previousMillis;
|
||||
} ISRTimerData;
|
||||
|
||||
// In RP2040, avoid doing something fancy in ISR, for example Serial.print()
|
||||
// The pure simple Serial.prints here are just for demonstration and testing. Must be eliminate in working environment
|
||||
// Or you can get this run-time error / crash
|
||||
|
||||
void doingSomething(int index);
|
||||
|
||||
#else
|
||||
|
||||
volatile unsigned long deltaMillis [NUMBER_ISR_TIMERS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
volatile unsigned long previousMillis [NUMBER_ISR_TIMERS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
// You can assign any interval for any timer here, in milliseconds
|
||||
uint32_t TimerInterval[NUMBER_ISR_TIMERS] =
|
||||
{
|
||||
5000L, 10000L, 15000L, 20000L, 25000L, 30000L, 35000L, 40000L,
|
||||
45000L, 50000L, 55000L, 60000L, 65000L, 70000L, 75000L, 80000L
|
||||
};
|
||||
|
||||
void doingSomething(int index)
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
deltaMillis[index] = currentMillis - previousMillis[index];
|
||||
previousMillis[index] = currentMillis;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////
|
||||
// Shared
|
||||
////////////////////////////////////
|
||||
|
||||
void doingSomething0()
|
||||
{
|
||||
doingSomething(0);
|
||||
}
|
||||
|
||||
void doingSomething1()
|
||||
{
|
||||
doingSomething(1);
|
||||
}
|
||||
|
||||
void doingSomething2()
|
||||
{
|
||||
doingSomething(2);
|
||||
}
|
||||
|
||||
void doingSomething3()
|
||||
{
|
||||
doingSomething(3);
|
||||
}
|
||||
|
||||
void doingSomething4()
|
||||
{
|
||||
doingSomething(4);
|
||||
}
|
||||
|
||||
void doingSomething5()
|
||||
{
|
||||
doingSomething(5);
|
||||
}
|
||||
|
||||
void doingSomething6()
|
||||
{
|
||||
doingSomething(6);
|
||||
}
|
||||
|
||||
void doingSomething7()
|
||||
{
|
||||
doingSomething(7);
|
||||
}
|
||||
|
||||
void doingSomething8()
|
||||
{
|
||||
doingSomething(8);
|
||||
}
|
||||
|
||||
void doingSomething9()
|
||||
{
|
||||
doingSomething(9);
|
||||
}
|
||||
|
||||
void doingSomething10()
|
||||
{
|
||||
doingSomething(10);
|
||||
}
|
||||
|
||||
void doingSomething11()
|
||||
{
|
||||
doingSomething(11);
|
||||
}
|
||||
|
||||
void doingSomething12()
|
||||
{
|
||||
doingSomething(12);
|
||||
}
|
||||
|
||||
void doingSomething13()
|
||||
{
|
||||
doingSomething(13);
|
||||
}
|
||||
|
||||
void doingSomething14()
|
||||
{
|
||||
doingSomething(14);
|
||||
}
|
||||
|
||||
void doingSomething15()
|
||||
{
|
||||
doingSomething(15);
|
||||
}
|
||||
|
||||
#if USE_COMPLEX_STRUCT
|
||||
|
||||
ISRTimerData curISRTimerData[NUMBER_ISR_TIMERS] =
|
||||
{
|
||||
//irqCallbackFunc, TimerInterval, deltaMillis, previousMillis
|
||||
{ doingSomething0, 5000L, 0, 0 },
|
||||
{ doingSomething1, 10000L, 0, 0 },
|
||||
{ doingSomething2, 15000L, 0, 0 },
|
||||
{ doingSomething3, 20000L, 0, 0 },
|
||||
{ doingSomething4, 25000L, 0, 0 },
|
||||
{ doingSomething5, 30000L, 0, 0 },
|
||||
{ doingSomething6, 35000L, 0, 0 },
|
||||
{ doingSomething7, 40000L, 0, 0 },
|
||||
{ doingSomething8, 45000L, 0, 0 },
|
||||
{ doingSomething9, 50000L, 0, 0 },
|
||||
{ doingSomething10, 55000L, 0, 0 },
|
||||
{ doingSomething11, 60000L, 0, 0 },
|
||||
{ doingSomething12, 65000L, 0, 0 },
|
||||
{ doingSomething13, 70000L, 0, 0 },
|
||||
{ doingSomething14, 75000L, 0, 0 },
|
||||
{ doingSomething15, 80000L, 0, 0 }
|
||||
};
|
||||
|
||||
void doingSomething(int index)
|
||||
{
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
curISRTimerData[index].deltaMillis = currentMillis - curISRTimerData[index].previousMillis;
|
||||
curISRTimerData[index].previousMillis = currentMillis;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
irqCallback irqCallbackFunc[NUMBER_ISR_TIMERS] =
|
||||
{
|
||||
doingSomething0, doingSomething1, doingSomething2, doingSomething3,
|
||||
doingSomething4, doingSomething5, doingSomething6, doingSomething7,
|
||||
doingSomething8, doingSomething9, doingSomething10, doingSomething11,
|
||||
doingSomething12, doingSomething13, doingSomething14, doingSomething15
|
||||
};
|
||||
|
||||
#endif
|
||||
///////////////////////////////////////////
|
||||
|
||||
#define SIMPLE_TIMER_MS 2000L
|
||||
|
||||
// Init SimpleTimer
|
||||
SimpleTimer simpleTimer;
|
||||
|
||||
// Here is software Timer, you can do somewhat fancy stuffs without many issues.
|
||||
// But always avoid
|
||||
// 1. Long delay() it just doing nothing and pain-without-gain wasting CPU power.Plan and design your code / strategy ahead
|
||||
// 2. Very long "do", "while", "for" loops without predetermined exit time.
|
||||
void simpleTimerDoingSomething2s()
|
||||
{
|
||||
static unsigned long previousMillis = startMillis;
|
||||
|
||||
unsigned long currMillis = millis();
|
||||
|
||||
Serial.print(F("SimpleTimer : ")); Serial.print(SIMPLE_TIMER_MS / 1000);
|
||||
Serial.print(F(", ms : ")); Serial.print(currMillis);
|
||||
Serial.print(F(", Dms : ")); Serial.println(currMillis - previousMillis);
|
||||
|
||||
for (uint16_t i = 0; i < NUMBER_ISR_TIMERS; i++)
|
||||
{
|
||||
#if USE_COMPLEX_STRUCT
|
||||
Serial.print(F("Timer : ")); Serial.print(i);
|
||||
Serial.print(F(", programmed : ")); Serial.print(curISRTimerData[i].TimerInterval);
|
||||
Serial.print(F(", actual : ")); Serial.println(curISRTimerData[i].deltaMillis);
|
||||
#else
|
||||
Serial.print(F("Timer : ")); Serial.print(i);
|
||||
Serial.print(F(", programmed : ")); Serial.print(TimerInterval[i]);
|
||||
Serial.print(F(", actual : ")); Serial.println(deltaMillis[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
previousMillis = currMillis;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
delay(100);
|
||||
|
||||
Serial.print(F("\nStarting ISR_16_Timers_Array_Complex on ")); Serial.println(BOARD_NAME);
|
||||
Serial.println(RPI_PICO_TIMER_INTERRUPT_VERSION);
|
||||
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
|
||||
|
||||
// Interval in microsecs
|
||||
if (ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_US, TimerHandler))
|
||||
{
|
||||
startMillis = millis();
|
||||
Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(startMillis);
|
||||
}
|
||||
else
|
||||
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
|
||||
|
||||
startMillis = millis();
|
||||
|
||||
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
|
||||
// You can use up to 16 timer for each ISR_Timer
|
||||
for (uint16_t i = 0; i < NUMBER_ISR_TIMERS; i++)
|
||||
{
|
||||
#if USE_COMPLEX_STRUCT
|
||||
curISRTimerData[i].previousMillis = startMillis;
|
||||
ISR_Timer.setInterval(curISRTimerData[i].TimerInterval, curISRTimerData[i].irqCallbackFunc);
|
||||
#else
|
||||
previousMillis[i] = millis();
|
||||
ISR_Timer.setInterval(TimerInterval[i], irqCallbackFunc[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
// You need this timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary.
|
||||
simpleTimer.setInterval(SIMPLE_TIMER_MS, simpleTimerDoingSomething2s);
|
||||
}
|
||||
|
||||
#define BLOCKING_TIME_MS 10000L
|
||||
|
||||
void loop()
|
||||
{
|
||||
// This unadvised blocking task is used to demonstrate the blocking effects onto the execution and accuracy to Software timer
|
||||
// You see the time elapse of ISR_Timer still accurate, whereas very unaccurate for Software Timer
|
||||
// The time elapse for 2000ms software timer now becomes 3000ms (BLOCKING_TIME_MS)
|
||||
// While that of ISR_Timer is still prefect.
|
||||
delay(BLOCKING_TIME_MS);
|
||||
|
||||
// You need this Software timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary
|
||||
// You don't need to and never call ISR_Timer.run() here in the loop(). It's already handled by ISR timer.
|
||||
simpleTimer.run();
|
||||
}
|
||||
@@ -18,35 +18,21 @@
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
||||
#define TIMER_INTERRUPT_DEBUG 1
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 4
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
|
||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_ISR_Timer.h"
|
||||
|
||||
#include <SimpleTimer.h> // https://github.com/schinken/SimpleTimer
|
||||
#include <SimpleTimer.h> // https://github.com/jfturcot/SimpleTimer
|
||||
|
||||
// Init RPI_PICO_Timer
|
||||
RPI_PICO_Timer ITimer1(1);
|
||||
@@ -74,6 +60,8 @@ volatile uint32_t previousMillis5s = 0;
|
||||
|
||||
bool TimerHandler(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle = false;
|
||||
static int timeRun = 0;
|
||||
|
||||
@@ -144,8 +132,7 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
Serial.print(F("\nStarting ISR_Timers_Array_Simple on "));
|
||||
Serial.println(BOARD_NAME);
|
||||
Serial.print(F("\nStarting ISR_Timers_Array_Simple on ")); Serial.println(BOARD_NAME);
|
||||
Serial.println(RPI_PICO_TIMER_INTERRUPT_VERSION);
|
||||
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
|
||||
|
||||
@@ -156,6 +143,8 @@ void setup()
|
||||
else
|
||||
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
|
||||
|
||||
previousMillis5s = previousMillis2s = millis();
|
||||
|
||||
ISR_timer.setInterval(2000L, doingSomething2s);
|
||||
ISR_timer.setInterval(5000L, doingSomething5s);
|
||||
|
||||
|
||||
@@ -18,19 +18,6 @@
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Notes:
|
||||
@@ -53,16 +40,13 @@
|
||||
You can also use interrupt to detect whenever the SW is active, set a flag then use timer to count the time between active state
|
||||
*/
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
||||
#define TIMER_INTERRUPT_DEBUG 1
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 4
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
|
||||
#define PIN_D1 1 // Pin D1 mapped to pin GPIO1 of RPI_PICO
|
||||
@@ -85,6 +69,8 @@ volatile int debounceCounter;
|
||||
|
||||
bool TimerHandler0(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
if ( !digitalRead(SWPin) && (debounceCounter >= DEBOUNCING_INTERVAL_MS / TIMER0_INTERVAL_MS ) )
|
||||
{
|
||||
//min time between pulses has passed
|
||||
|
||||
@@ -18,19 +18,6 @@
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Notes:
|
||||
@@ -50,16 +37,13 @@
|
||||
SW is released.
|
||||
*/
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
||||
#define TIMER_INTERRUPT_DEBUG 1
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 4
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
|
||||
#define PIN_D1 1 // Pin D1 mapped to pin GPIO1 of RPI_PICO
|
||||
@@ -80,6 +64,8 @@ volatile bool SWLongPressed = false;
|
||||
|
||||
bool TimerHandler1(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static unsigned int debounceCountSWPressed = 0;
|
||||
static unsigned int debounceCountSWReleased = 0;
|
||||
|
||||
|
||||
@@ -18,19 +18,6 @@
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Notes:
|
||||
@@ -44,26 +31,25 @@
|
||||
or the entire sequence of your code which accesses the data.
|
||||
*/
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
||||
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
||||
#define TIMER_INTERRUPT_DEBUG 1
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 4
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
|
||||
#ifndef LED_BUILTIN
|
||||
#define LED_BUILTIN 25 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
|
||||
#define LED_BUILTIN 25
|
||||
#endif
|
||||
|
||||
#define PIN_D1 1 // Pin D1 mapped to pin GPIO1 of RPI_PICO
|
||||
|
||||
bool TimerHandler0(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle0 = false;
|
||||
static bool started = false;
|
||||
|
||||
@@ -86,6 +72,8 @@ bool TimerHandler0(struct repeating_timer *t)
|
||||
|
||||
bool TimerHandler1(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle1 = false;
|
||||
static bool started = false;
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/****************************************************************************************************************************
|
||||
multiFileProject.cpp
|
||||
RPi_Pico_ISR_Timer-Impl.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one SAMD timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
// To demo how to include files in multi-file Projects
|
||||
|
||||
#include "multiFileProject.h"
|
||||
@@ -0,0 +1,25 @@
|
||||
/****************************************************************************************************************************
|
||||
multiFileProject.h
|
||||
RPi_Pico_ISR_Timer-Impl.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one SAMD timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
// To demo how to include files in multi-file Projects
|
||||
|
||||
#pragma once
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_ISR_Timer.hpp"
|
||||
@@ -0,0 +1,38 @@
|
||||
/****************************************************************************************************************************
|
||||
multiFileProject.ino
|
||||
For Teensy boards
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/Teensy_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one NRF52 timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
// To demo how to include files in multi-file Projects
|
||||
|
||||
#if !( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED)
|
||||
#error This code is intended to run on the non-mbed RP2040 arduino-pico platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
#include "multiFileProject.h"
|
||||
|
||||
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_TimerInterrupt.h"
|
||||
|
||||
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
|
||||
#include "RPi_Pico_ISR_Timer.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
// put your setup code here, to run once:
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// put your main code here, to run repeatedly:
|
||||
}
|
||||
@@ -48,3 +48,9 @@ getNumAvailableTimers KEYWORD2
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
RPI_PICO_TIMER_INTERRUPT_VERSION LITERAL1
|
||||
RPI_PICO_TIMER_INTERRUPT_VERSION_MAJOR LITERAL1
|
||||
RPI_PICO_TIMER_INTERRUPT_VERSION_MINOR LITERAL1
|
||||
RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH LITERAL1
|
||||
RPI_PICO_TIMER_INTERRUPT_VERSION_INT LITERAL1
|
||||
|
||||
+6
-5
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "RPI_PICO_TimerInterrupt",
|
||||
"version": "1.0.0",
|
||||
"keywords": "timing, device, control, timer, interrupt, hardware, isr, isr-based, hardware-timer, mission-critical, accuracy, precise, non-blocking, raspberry-pico, rpi-pico, pico, rp2040",
|
||||
"version": "1.3.1",
|
||||
"keywords": "timing, device, control, timer, interrupt, hardware, isr, isr-based, hardware-timer, mission-critical, accuracy, non-blocking, raspberry-pico, rpi-pico, pico, rp2040, arduino-pico, rp2040w, raspberry-pico-w, pico-w",
|
||||
"description": "This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO. It now supports 16 ISR-based timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy.",
|
||||
"authors":
|
||||
{
|
||||
@@ -12,7 +12,7 @@
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "//https://github.com/khoih-prog/RPI_PICO_TimerInterrupt"
|
||||
"url": "https://github.com/khoih-prog/RPI_PICO_TimerInterrupt"
|
||||
},
|
||||
"homepage": "https://github.com/khoih-prog/RPI_PICO_TimerInterrupt",
|
||||
"export": {
|
||||
@@ -22,8 +22,9 @@
|
||||
"tests"
|
||||
]
|
||||
},
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "rp2040",
|
||||
"platforms": ["raspberrypi"],
|
||||
"examples": "examples/*/*/*.ino",
|
||||
"license": "MIT"
|
||||
"headers": ["RPi_Pico_TimerInterrupt.h", "RPi_Pico_ISR_Timer.h", "RPi_Pico_ISR_Timer.hpp"]
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
name=RPI_PICO_TimerInterrupt
|
||||
version=1.0.0
|
||||
version=1.3.1
|
||||
author=Khoi Hoang <khoih.prog@gmail.com>
|
||||
maintainer=Khoi Hoang <khoih.prog@gmail.com>
|
||||
sentence=This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO
|
||||
paragraph=These RPI_PICO_TimerInterrupt Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's mandatory if you need to measure some data requiring better accuracy. It now supports 16 ISR-based Timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based Timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks.
|
||||
category=Timing, Control, Device, Time, Timer, rp2040, raspberry-pico
|
||||
paragraph=These RPI_PICO_TimerInterrupt Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That is mandatory if you need to measure some data requiring better accuracy. It now supports 16 ISR-based Timers, while consuming only 1 Hardware Timer. Timers interval is very long (ulong millisecs). The most important feature is they are ISR-based Timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks.
|
||||
category=Device Control
|
||||
url=https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
architectures=rp2040
|
||||
repository=https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
license=MIT
|
||||
includes=RPi_Pico_TimerInterrupt.h,RPi_Pico_ISR_Timer.h
|
||||
includes=RPi_Pico_TimerInterrupt.h,RPi_Pico_ISR_Timer.h,RPi_Pico_ISR_Timer.hpp
|
||||
|
||||
@@ -0,0 +1,375 @@
|
||||
;PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
; ============================================================
|
||||
; chose environment:
|
||||
; ESP8266
|
||||
; ESP32
|
||||
; SAMD
|
||||
; NRF52
|
||||
; STM32
|
||||
; pico
|
||||
; ============================================================
|
||||
;default_envs = ESP8266
|
||||
;default_envs = ESP32
|
||||
;default_envs = SAMD
|
||||
default_envs = pico
|
||||
;default_envs = mbed_pico
|
||||
;default_envs = NRF52
|
||||
;default_envs = STM32
|
||||
;default_envs = portenta_h7_m7
|
||||
;default_envs = portenta_h7_m4
|
||||
|
||||
[env]
|
||||
; ============================================================
|
||||
; Serial configuration
|
||||
; choose upload speed, serial-monitor speed
|
||||
; ============================================================
|
||||
upload_speed = 921600
|
||||
;upload_port = COM11
|
||||
;monitor_speed = 9600
|
||||
;monitor_port = COM11
|
||||
|
||||
; Checks for the compatibility with frameworks and dev/platforms
|
||||
lib_compat_mode = strict
|
||||
lib_ldf_mode = chain+
|
||||
;lib_ldf_mode = deep+
|
||||
|
||||
lib_deps =
|
||||
|
||||
|
||||
build_flags =
|
||||
; set your debug output (default=Serial)
|
||||
; -D DEBUG_ESP_PORT=Serial
|
||||
; comment the following line to enable WiFi debugging
|
||||
; -D NDEBUG
|
||||
|
||||
[env:portenta_h7_m7]
|
||||
platform = ststm32
|
||||
board = portenta_h7_m7
|
||||
framework = arduino
|
||||
|
||||
[env:portenta_h7_m4]
|
||||
platform = ststm32
|
||||
board = portenta_h7_m4
|
||||
framework = arduino
|
||||
|
||||
[env:pico]
|
||||
; ============================================================
|
||||
; Just a sample for arduino-pice core
|
||||
; You have to research and fix if there is issue
|
||||
; ============================================================
|
||||
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
|
||||
board = pico
|
||||
framework = arduino
|
||||
board_build.core = earlephilhower
|
||||
|
||||
[env:mbed_pico]
|
||||
; ============================================================
|
||||
; Just a sample for mbed_rp2040 and mbed_nano cores
|
||||
; You have to research and fix if there is issue
|
||||
; ============================================================
|
||||
platform = raspberrypi
|
||||
board = pico
|
||||
framework = arduino
|
||||
upload_protocol = picotool
|
||||
|
||||
[env:ESP8266]
|
||||
platform = espressif8266
|
||||
framework = arduino
|
||||
; ============================================================
|
||||
; Board configuration
|
||||
; choose your board by uncommenting one of the following lines
|
||||
; ============================================================
|
||||
;board = gen4iod
|
||||
;board = huzzah
|
||||
;board = oak
|
||||
;board = esp_wroom_02
|
||||
;board = espduino
|
||||
;board = espectro
|
||||
;board = espino
|
||||
;board = espresso_lite_v1
|
||||
;board = espresso_lite_v2
|
||||
;board = esp12e
|
||||
;board = esp01_1m
|
||||
;board = esp01
|
||||
;board = esp07
|
||||
;board = esp8285
|
||||
;board = heltec_wifi_kit_8
|
||||
;board = inventone
|
||||
;board = nodemcu
|
||||
board = nodemcuv2
|
||||
;board = modwifi
|
||||
;board = phoenix_v1
|
||||
;board = phoenix_v2
|
||||
;board = sparkfunBlynk
|
||||
;board = thing
|
||||
;board = thingdev
|
||||
;board = esp210
|
||||
;board = espinotee
|
||||
;board = d1
|
||||
;board = d1_mini
|
||||
;board = d1_mini_lite
|
||||
;board = d1_mini_pro
|
||||
;board = wifi_slot
|
||||
;board = wifiduino
|
||||
;board = wifinfo
|
||||
;board = wio_link
|
||||
;board = wio_node
|
||||
;board = xinabox_cw01
|
||||
;board = esp32doit-devkit-v1
|
||||
|
||||
[env:ESP32]
|
||||
platform = espressif32
|
||||
framework = arduino
|
||||
; ============================================================
|
||||
; Board configuration
|
||||
; choose your board by uncommenting one of the following lines
|
||||
; ============================================================
|
||||
;board = esp32cam
|
||||
;board = alksesp32
|
||||
;board = featheresp32
|
||||
;board = espea32
|
||||
;board = bpi-bit
|
||||
;board = d-duino-32
|
||||
board = esp32doit-devkit-v1
|
||||
;board = pocket_32
|
||||
;board = fm-devkit
|
||||
;board = pico32
|
||||
;board = esp32-evb
|
||||
;board = esp32-gateway
|
||||
;board = esp32-pro
|
||||
;board = esp32-poe
|
||||
;board = oroca_edubot
|
||||
;board = onehorse32dev
|
||||
;board = lopy
|
||||
;board = lopy4
|
||||
;board = wesp32
|
||||
;board = esp32thing
|
||||
;board = sparkfun_lora_gateway_1-channel
|
||||
;board = ttgo-lora32-v1
|
||||
;board = ttgo-t-beam
|
||||
;board = turta_iot_node
|
||||
;board = lolin_d32
|
||||
;board = lolin_d32_pro
|
||||
;board = lolin32
|
||||
;board = wemosbat
|
||||
;board = widora-air
|
||||
;board = xinabox_cw02
|
||||
;board = iotbusio
|
||||
;board = iotbusproteus
|
||||
;board = nina_w10
|
||||
|
||||
[env:SAMD]
|
||||
platform = atmelsam
|
||||
framework = arduino
|
||||
; ============================================================
|
||||
; Choose your board by uncommenting one of the following lines
|
||||
; ============================================================
|
||||
; ============================================================
|
||||
; Board configuration Adafruit SAMD
|
||||
; ============================================================
|
||||
|
||||
;board = adafruit_feather_m0
|
||||
;board = adafruit_feather_m0_express
|
||||
;board = adafruit_metro_m0
|
||||
;board = adafruit_circuitplayground_m0
|
||||
;board = adafruit_gemma_m0
|
||||
;board = adafruit_trinket_m0
|
||||
;board = adafruit_itsybitsy_m0
|
||||
;board = adafruit_pirkey
|
||||
;board = adafruit_hallowing
|
||||
;board = adafruit_crickit_m0
|
||||
;board = adafruit_metro_m4
|
||||
;board = adafruit_grandcentral_m4
|
||||
board = adafruit_itsybitsy_m4
|
||||
;board = adafruit_feather_m4
|
||||
;board = adafruit_trellis_m4
|
||||
;board = adafruit_pyportal_m4
|
||||
;board = adafruit_pyportal_m4_titano
|
||||
;board = adafruit_pybadge_m4
|
||||
;board = adafruit_metro_m4_airliftlite
|
||||
;board = adafruit_pygamer_m4
|
||||
;board = adafruit_pygamer_advance_m4
|
||||
;board = adafruit_pybadge_airlift_m4
|
||||
;board = adafruit_monster_m4sk
|
||||
;board = adafruit_hallowing_m4
|
||||
|
||||
; ============================================================
|
||||
; Board configuration Arduino SAMD and SAM
|
||||
; ============================================================
|
||||
|
||||
;board = arduino_zero_edbg
|
||||
;board = arduino_zero_native
|
||||
;board = mkr1000
|
||||
;board = mkrzero
|
||||
;board = mkrwifi1010
|
||||
;board = nano_33_iot
|
||||
;board = mkrfox1200
|
||||
;board = mkrwan1300
|
||||
;board = mkrwan1310
|
||||
;board = mkrgsm1400
|
||||
;board = mkrnb1500
|
||||
;board = mkrvidor4000
|
||||
;board = adafruit_circuitplayground_m0
|
||||
;board = mzero_pro_bl_dbg
|
||||
;board = mzero_pro_bl
|
||||
;board = mzero_bl
|
||||
;board = tian
|
||||
;board = tian_cons
|
||||
;board = arduino_due_x_dbg
|
||||
;board = arduino_due_x
|
||||
|
||||
; ============================================================
|
||||
; Board configuration Seeeduino SAMD
|
||||
; ============================================================
|
||||
|
||||
;board = seeed_wio_terminal
|
||||
;board = Seeed_femto_m0
|
||||
;board = seeed_XIAO_m0
|
||||
;board = Wio_Lite_MG126
|
||||
;board = WioGPS
|
||||
;board = zero
|
||||
;board = rolawan
|
||||
;board = seeed_grove_ui_wireless
|
||||
|
||||
|
||||
[env:NRF52]
|
||||
platform = nordicnrf52
|
||||
framework = arduino
|
||||
; ============================================================
|
||||
; Board configuration Adafruit nRF52
|
||||
; choose your board by uncommenting one of the following lines
|
||||
; ============================================================
|
||||
;board = feather52832
|
||||
board = feather52840
|
||||
;board = feather52840sense
|
||||
;board = itsybitsy52840
|
||||
;board = cplaynrf52840
|
||||
;board = cluenrf52840
|
||||
;board = metro52840
|
||||
;board = pca10056
|
||||
;board = particle_xenon
|
||||
;board = mdbt50qrx
|
||||
;board = ninab302
|
||||
;board = ninab112
|
||||
|
||||
[env:STM32]
|
||||
platform = ststm32
|
||||
framework = arduino
|
||||
|
||||
; ============================================================
|
||||
; Choose your board by uncommenting one of the following lines
|
||||
; ============================================================
|
||||
|
||||
; ============================================================
|
||||
; Board configuration Nucleo-144
|
||||
; ============================================================
|
||||
|
||||
;board = nucleo_f207zg
|
||||
;board = nucleo_f429zi
|
||||
;board = nucleo_f746zg
|
||||
;board = nucleo_f756zg
|
||||
;board = nucleo_f767zi
|
||||
;board = nucleo_h743zi
|
||||
;board = nucleo_l496zg
|
||||
;board = nucleo_l496zg-p
|
||||
;board = nucleo_l4r5zi
|
||||
;board = nucleo_l4r5zi-p
|
||||
|
||||
; ============================================================
|
||||
; Board configuration Nucleo-64
|
||||
; ============================================================
|
||||
|
||||
;board = nucleo_f030r8
|
||||
;board = nucleo_f072rb
|
||||
|
||||
;board = nucleo_f091rc
|
||||
;board = nucleo_f103rb
|
||||
;board = nucleo_f302r8
|
||||
;board = nucleo_f303re
|
||||
;board = nucleo_f401re
|
||||
;board = nucleo_f411re
|
||||
;board = nucleo_f446re
|
||||
;board = nucleo_g071rb
|
||||
;board = nucleo_g431rb
|
||||
;board = nucleo_g474re
|
||||
;board = nucleo_l053r8
|
||||
;board = nucleo_l073rz
|
||||
;board = nucleo_l152re
|
||||
;board = nucleo_l433rc_p
|
||||
;board = nucleo_l452re
|
||||
;board = nucleo_l452re-p
|
||||
;board = nucleo_l476rg
|
||||
;board = pnucleo_wb55rg
|
||||
|
||||
; ============================================================
|
||||
; Board configuration Nucleo-32
|
||||
; ============================================================
|
||||
|
||||
;board = nucleo_f031k6
|
||||
;board = nucleo_l031k6
|
||||
;board = nucleo_l412kb
|
||||
;board = nucleo_l432lc
|
||||
;board = nucleo_f303k8
|
||||
;board = nucleo_g431kb
|
||||
|
||||
; ============================================================
|
||||
; Board configuration Discovery Boards
|
||||
; ============================================================
|
||||
|
||||
;board = disco_f030r8
|
||||
;board = disco_f072rb
|
||||
;board = disco_f030r8
|
||||
;board = disco_f100rb
|
||||
;board = disco_f407vg
|
||||
;board = disco_f413zh
|
||||
;board = disco_f746ng
|
||||
;board = disco_g0316
|
||||
;board = disco_l475vg_iot
|
||||
;board = disco_f072cz-lrwan1
|
||||
|
||||
; ============================================================
|
||||
; Board configuration STM32MP1 Boards
|
||||
; ============================================================
|
||||
|
||||
;board = stm32mp157a-dk1
|
||||
;board = stm32mp157c-dk2
|
||||
|
||||
; ============================================================
|
||||
; Board configuration Generic Boards
|
||||
; ============================================================
|
||||
|
||||
;board = bluepill_f103c6
|
||||
;board = bluepill_f103c8
|
||||
;board = blackpill_f103c8
|
||||
;board = stm32f103cx
|
||||
;board = stm32f103rx
|
||||
;board = stm32f103tx
|
||||
;board = stm32f103vx
|
||||
;board = stm32f103zx
|
||||
;board = stm32f103zet6
|
||||
;board = maplemini_f103cb
|
||||
;board = blackpill_f303cc
|
||||
;board = black_f407ve
|
||||
;board = black_f407vg
|
||||
;board = black_f407ze
|
||||
;board = black_f407zg
|
||||
;board = blue_f407ve_mini
|
||||
;board = blackpill_f401cc
|
||||
;board = blackpill_f411ce
|
||||
;board = coreboard_f401rc
|
||||
;board = feather_f405
|
||||
|
||||
; ============================================================
|
||||
; Board configuration Many more Boards to be filled
|
||||
; ============================================================
|
||||
|
||||
+118
-78
@@ -1,35 +1,41 @@
|
||||
/****************************************************************************************************************************
|
||||
RPi_Pico_ISR_Timer-Impl.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
RPi_Pico_ISR_Timer-Impl.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
Version: 1.3.1
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
||||
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
||||
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
||||
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
||||
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
||||
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
@@ -37,22 +43,22 @@
|
||||
#ifndef ISR_TIMER_GENERIC_IMPL_H
|
||||
#define ISR_TIMER_GENERIC_IMPL_H
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
RPI_PICO_ISR_Timer::RPI_PICO_ISR_Timer()
|
||||
: numTimers (-1)
|
||||
{
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::init()
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void RPI_PICO_ISR_Timer::init()
|
||||
{
|
||||
unsigned long current_millis = millis(); //elapsed();
|
||||
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
memset((void*) &timer[i], 0, sizeof (timer_t));
|
||||
timer[i].prev_millis = current_millis;
|
||||
@@ -61,7 +67,9 @@ void RPI_PICO_ISR_Timer::init()
|
||||
numTimers = 0;
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::run()
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void RPI_PICO_ISR_Timer::run()
|
||||
{
|
||||
uint8_t i;
|
||||
unsigned long current_millis;
|
||||
@@ -71,43 +79,43 @@ void RPI_PICO_ISR_Timer::run()
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during ISR
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
|
||||
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_DONTRUN;
|
||||
|
||||
// no callback == no timer, i.e. jump over empty slots
|
||||
if (timer[i].callback != NULL)
|
||||
if (timer[i].callback != NULL)
|
||||
{
|
||||
|
||||
// is it time to process this timer ?
|
||||
// see http://arduino.cc/forum/index.php/topic,124048.msg932592.html#msg932592
|
||||
|
||||
if ((current_millis - timer[i].prev_millis) >= timer[i].delay)
|
||||
if ((current_millis - timer[i].prev_millis) >= timer[i].delay)
|
||||
{
|
||||
unsigned long skipTimes = (current_millis - timer[i].prev_millis) / timer[i].delay;
|
||||
|
||||
|
||||
// update time
|
||||
timer[i].prev_millis += timer[i].delay * skipTimes;
|
||||
|
||||
// check if the timer callback has to be executed
|
||||
if (timer[i].enabled)
|
||||
if (timer[i].enabled)
|
||||
{
|
||||
|
||||
// "run forever" timers must always be executed
|
||||
if (timer[i].maxNumRuns == RPI_PICO_RUN_FOREVER)
|
||||
if (timer[i].maxNumRuns == RPI_PICO_RUN_FOREVER)
|
||||
{
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNONLY;
|
||||
}
|
||||
// other timers get executed the specified number of times
|
||||
else if (timer[i].numRuns < timer[i].maxNumRuns)
|
||||
else if (timer[i].numRuns < timer[i].maxNumRuns)
|
||||
{
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNONLY;
|
||||
timer[i].numRuns++;
|
||||
|
||||
// after the last run, delete the timer
|
||||
if (timer[i].numRuns >= timer[i].maxNumRuns)
|
||||
if (timer[i].numRuns >= timer[i].maxNumRuns)
|
||||
{
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNANDDEL;
|
||||
}
|
||||
@@ -117,7 +125,7 @@ void RPI_PICO_ISR_Timer::run()
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].toBeCalled == RPI_PICO_DEFCALL_DONTRUN)
|
||||
continue;
|
||||
@@ -136,21 +144,22 @@ void RPI_PICO_ISR_Timer::run()
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
// find the first available slot
|
||||
// return -1 if none found
|
||||
int RPI_PICO_ISR_Timer::findFirstFreeSlot()
|
||||
int RPI_PICO_ISR_Timer::findFirstFreeSlot()
|
||||
{
|
||||
// all slots are used
|
||||
if (numTimers >= RPI_PICO_MAX_TIMERS)
|
||||
if (numTimers >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// return the first slot with no callback (i.e. free)
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].callback == NULL)
|
||||
if (timer[i].callback == NULL)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@@ -160,23 +169,25 @@ int RPI_PICO_ISR_Timer::findFirstFreeSlot()
|
||||
return -1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
int RPI_PICO_ISR_Timer::setupTimer(unsigned long d, void* f, void* p, bool h, unsigned n)
|
||||
int RPI_PICO_ISR_Timer::setupTimer(const float& d, void* f, void* p, bool h, const unsigned& n)
|
||||
{
|
||||
int freeTimer;
|
||||
|
||||
if (numTimers < 0)
|
||||
if (numTimers < 0)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
freeTimer = findFirstFreeSlot();
|
||||
if (freeTimer < 0)
|
||||
|
||||
if (freeTimer < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (f == NULL)
|
||||
if (f == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -194,46 +205,59 @@ int RPI_PICO_ISR_Timer::setupTimer(unsigned long d, void* f, void* p, bool h, un
|
||||
return freeTimer;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimer(unsigned long d, timer_callback f, unsigned n)
|
||||
int RPI_PICO_ISR_Timer::setTimer(const float& d, timer_callback f, const unsigned& n)
|
||||
{
|
||||
return setupTimer(d, (void *)f, NULL, false, n);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimer(unsigned long d, timer_callback_p f, void* p, unsigned n)
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimer(const float& d, timer_callback_p f, void* p, const unsigned& n)
|
||||
{
|
||||
return setupTimer(d, (void *)f, p, true, n);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setInterval(unsigned long d, timer_callback f)
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
int RPI_PICO_ISR_Timer::setInterval(const float& d, timer_callback f)
|
||||
{
|
||||
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_FOREVER);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setInterval(unsigned long d, timer_callback_p f, void* p)
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
int RPI_PICO_ISR_Timer::setInterval(const float& d, timer_callback_p f, void* p)
|
||||
{
|
||||
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_FOREVER);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimeout(unsigned long d, timer_callback f)
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimeout(const float& d, timer_callback f)
|
||||
{
|
||||
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_ONCE);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimeout(unsigned long d, timer_callback_p f, void* p)
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimeout(const float& d, timer_callback_p f, void* p)
|
||||
{
|
||||
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_ONCE);
|
||||
}
|
||||
|
||||
bool RPI_PICO_ISR_Timer::changeInterval(unsigned numTimer, unsigned long d)
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
bool RPI_PICO_ISR_Timer::changeInterval(const unsigned& numTimer, const float& d)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Updates interval of existing specified timer
|
||||
if (timer[numTimer].callback != NULL)
|
||||
if (timer[numTimer].callback != NULL)
|
||||
{
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
@@ -246,26 +270,28 @@ bool RPI_PICO_ISR_Timer::changeInterval(unsigned numTimer, unsigned long d)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// false return for non-used numTimer, no callback
|
||||
return false;
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::deleteTimer(unsigned timerId)
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void RPI_PICO_ISR_Timer::deleteTimer(const unsigned& timerId)
|
||||
{
|
||||
if (timerId >= RPI_PICO_MAX_TIMERS)
|
||||
if (timerId >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// nothing to delete if no timers are in use
|
||||
if (numTimers == 0)
|
||||
if (numTimers == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// don't decrease the number of timers if the specified slot is already empty
|
||||
if (timer[timerId].callback != NULL)
|
||||
if (timer[timerId].callback != NULL)
|
||||
{
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
@@ -282,10 +308,12 @@ void RPI_PICO_ISR_Timer::deleteTimer(unsigned timerId)
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
// function contributed by code@rowansimms.com
|
||||
void RPI_PICO_ISR_Timer::restartTimer(unsigned numTimer)
|
||||
void RPI_PICO_ISR_Timer::restartTimer(const unsigned& numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -299,10 +327,11 @@ void RPI_PICO_ISR_Timer::restartTimer(unsigned numTimer)
|
||||
rp2040.resumeOtherCore();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
bool RPI_PICO_ISR_Timer::isEnabled(unsigned numTimer)
|
||||
bool RPI_PICO_ISR_Timer::isEnabled(const unsigned& numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -310,10 +339,11 @@ bool RPI_PICO_ISR_Timer::isEnabled(unsigned numTimer)
|
||||
return timer[numTimer].enabled;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void RPI_PICO_ISR_Timer::enable(unsigned numTimer)
|
||||
void RPI_PICO_ISR_Timer::enable(const unsigned& numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -321,10 +351,11 @@ void RPI_PICO_ISR_Timer::enable(unsigned numTimer)
|
||||
timer[numTimer].enabled = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void RPI_PICO_ISR_Timer::disable(unsigned numTimer)
|
||||
void RPI_PICO_ISR_Timer::disable(const unsigned& numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -332,16 +363,18 @@ void RPI_PICO_ISR_Timer::disable(unsigned numTimer)
|
||||
timer[numTimer].enabled = false;
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::enableAll()
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void RPI_PICO_ISR_Timer::enableAll()
|
||||
{
|
||||
// Enable all timers with a callback assigned (used)
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
||||
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
||||
{
|
||||
timer[i].enabled = true;
|
||||
}
|
||||
@@ -351,16 +384,18 @@ void RPI_PICO_ISR_Timer::enableAll()
|
||||
rp2040.resumeOtherCore();
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::disableAll()
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void RPI_PICO_ISR_Timer::disableAll()
|
||||
{
|
||||
// Disable all timers with a callback assigned (used)
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
||||
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
||||
{
|
||||
timer[i].enabled = false;
|
||||
}
|
||||
@@ -371,9 +406,11 @@ void RPI_PICO_ISR_Timer::disableAll()
|
||||
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::toggle(unsigned numTimer)
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void RPI_PICO_ISR_Timer::toggle(const unsigned& numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -381,11 +418,14 @@ void RPI_PICO_ISR_Timer::toggle(unsigned numTimer)
|
||||
timer[numTimer].enabled = !timer[numTimer].enabled;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
unsigned RPI_PICO_ISR_Timer::getNumTimers()
|
||||
unsigned RPI_PICO_ISR_Timer::getNumTimers()
|
||||
{
|
||||
return numTimers;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // ISR_TIMER_GENERIC_IMPL_H
|
||||
|
||||
|
||||
+28
-169
@@ -1,35 +1,41 @@
|
||||
/****************************************************************************************************************************
|
||||
RPi_Pico_ISR_Timer.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
RPi_Pico_ISR_Timer.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
Version: 1.3.1
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
||||
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
||||
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
||||
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
||||
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
||||
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
@@ -37,154 +43,7 @@
|
||||
#ifndef ISR_TIMER_GENERIC_H
|
||||
#define ISR_TIMER_GENERIC_H
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.0"
|
||||
#endif
|
||||
|
||||
#include "TimerInterrupt_Generic_Debug.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "pico/multicore.h"
|
||||
|
||||
#if defined(ARDUINO)
|
||||
#if ARDUINO >= 100
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define FLAG_VALUE 0xDEADBEEF
|
||||
|
||||
#define RPI_PICO_ISR_Timer RPI_PICO_ISRTimer
|
||||
|
||||
typedef void (*timer_callback)();
|
||||
typedef void (*timer_callback_p)(void *);
|
||||
|
||||
class RPI_PICO_ISR_Timer
|
||||
{
|
||||
|
||||
public:
|
||||
// maximum number of timers
|
||||
#define RPI_PICO_MAX_TIMERS 16
|
||||
#define RPI_PICO_RUN_FOREVER 0
|
||||
#define RPI_PICO_RUN_ONCE 1
|
||||
|
||||
// constructor
|
||||
RPI_PICO_ISR_Timer();
|
||||
|
||||
void init();
|
||||
|
||||
// this function must be called inside loop()
|
||||
void run();
|
||||
|
||||
// Timer will call function 'f' every 'd' milliseconds forever
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setInterval(unsigned long d, timer_callback f);
|
||||
|
||||
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds forever
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setInterval(unsigned long d, timer_callback_p f, void* p);
|
||||
|
||||
// Timer will call function 'f' after 'd' milliseconds one time
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimeout(unsigned long d, timer_callback f);
|
||||
|
||||
// Timer will call function 'f' with parameter 'p' after 'd' milliseconds one time
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimeout(unsigned long d, timer_callback_p f, void* p);
|
||||
|
||||
// Timer will call function 'f' every 'd' milliseconds 'n' times
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimer(unsigned long d, timer_callback f, unsigned n);
|
||||
|
||||
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds 'n' times
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimer(unsigned long d, timer_callback_p f, void* p, unsigned n);
|
||||
|
||||
// updates interval of the specified timer
|
||||
bool changeInterval(unsigned numTimer, unsigned long d);
|
||||
|
||||
// destroy the specified timer
|
||||
void deleteTimer(unsigned numTimer);
|
||||
|
||||
// restart the specified timer
|
||||
void restartTimer(unsigned numTimer);
|
||||
|
||||
// returns true if the specified timer is enabled
|
||||
bool isEnabled(unsigned numTimer);
|
||||
|
||||
// enables the specified timer
|
||||
void enable(unsigned numTimer);
|
||||
|
||||
// disables the specified timer
|
||||
void disable(unsigned numTimer);
|
||||
|
||||
// enables all timers
|
||||
void enableAll();
|
||||
|
||||
// disables all timers
|
||||
void disableAll();
|
||||
|
||||
// enables the specified timer if it's currently disabled, and vice-versa
|
||||
void toggle(unsigned numTimer);
|
||||
|
||||
// returns the number of used timers
|
||||
unsigned getNumTimers();
|
||||
|
||||
// returns the number of available timers
|
||||
unsigned getNumAvailableTimers()
|
||||
{
|
||||
return RPI_PICO_MAX_TIMERS - numTimers;
|
||||
};
|
||||
|
||||
private:
|
||||
// deferred call constants
|
||||
#define RPI_PICO_DEFCALL_DONTRUN 0 // don't call the callback function
|
||||
#define RPI_PICO_DEFCALL_RUNONLY 1 // call the callback function but don't delete the timer
|
||||
#define RPI_PICO_DEFCALL_RUNANDDEL 2 // call the callback function and delete the timer
|
||||
|
||||
// low level function to initialize and enable a new timer
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setupTimer(unsigned long d, void* f, void* p, bool h, unsigned n);
|
||||
|
||||
// find the first available slot
|
||||
int findFirstFreeSlot();
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned long prev_millis; // value returned by the millis() function in the previous run() call
|
||||
void* callback; // pointer to the callback function
|
||||
void* param; // function parameter
|
||||
bool hasParam; // true if callback takes a parameter
|
||||
unsigned long delay; // delay value
|
||||
unsigned maxNumRuns; // number of runs to be executed
|
||||
unsigned numRuns; // number of executed runs
|
||||
bool enabled; // true if enabled
|
||||
unsigned toBeCalled; // deferred function call (sort of) - N.B.: only used in run()
|
||||
} timer_t;
|
||||
|
||||
volatile timer_t timer[RPI_PICO_MAX_TIMERS];
|
||||
|
||||
// actual number of timers in use (-1 means uninitialized)
|
||||
volatile int numTimers;
|
||||
};
|
||||
|
||||
|
||||
#include "RPi_Pico_ISR_Timer.hpp"
|
||||
#include "RPi_Pico_ISR_Timer-Impl.h"
|
||||
|
||||
#endif // ISR_TIMER_GENERIC_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/****************************************************************************************************************************
|
||||
RPi_Pico_ISR_Timer.h
|
||||
RPi_Pico_ISR_Timer.hpp
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
@@ -25,26 +25,49 @@
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
Version: 1.3.1
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
||||
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
||||
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
||||
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
||||
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
||||
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ISR_TIMER_GENERIC_H
|
||||
#define ISR_TIMER_GENERIC_H
|
||||
#ifndef ISR_TIMER_GENERIC_HPP
|
||||
#define ISR_TIMER_GENERIC_HPP
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED)
|
||||
#if defined(USING_RPI_PICO_TIMER_INTERRUPT)
|
||||
#undef USING_RPI_PICO_TIMER_INTERRUPT
|
||||
#endif
|
||||
#define USING_RPI_PICO_TIMER_INTERRUPT true
|
||||
#else
|
||||
#error This code is intended to run on the non-mbed RP2040 arduino-pico platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.0"
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.3.1"
|
||||
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MAJOR 1
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MINOR 3
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 1
|
||||
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1003001
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "TimerInterrupt_Generic_Debug.h"
|
||||
|
||||
#include <stddef.h>
|
||||
@@ -68,9 +91,10 @@
|
||||
typedef void (*timer_callback)();
|
||||
typedef void (*timer_callback_p)(void *);
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
class RPI_PICO_ISR_Timer
|
||||
{
|
||||
|
||||
public:
|
||||
// maximum number of timers
|
||||
#define RPI_PICO_MAX_TIMERS 16
|
||||
@@ -88,50 +112,50 @@ class RPI_PICO_ISR_Timer
|
||||
// Timer will call function 'f' every 'd' milliseconds forever
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setInterval(unsigned long d, timer_callback f);
|
||||
int setInterval(const float& d, timer_callback f);
|
||||
|
||||
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds forever
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setInterval(unsigned long d, timer_callback_p f, void* p);
|
||||
int setInterval(const float& d, timer_callback_p f, void* p);
|
||||
|
||||
// Timer will call function 'f' after 'd' milliseconds one time
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimeout(unsigned long d, timer_callback f);
|
||||
int setTimeout(const float& d, timer_callback f);
|
||||
|
||||
// Timer will call function 'f' with parameter 'p' after 'd' milliseconds one time
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimeout(unsigned long d, timer_callback_p f, void* p);
|
||||
int setTimeout(const float& d, timer_callback_p f, void* p);
|
||||
|
||||
// Timer will call function 'f' every 'd' milliseconds 'n' times
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimer(unsigned long d, timer_callback f, unsigned n);
|
||||
int setTimer(const float& d, timer_callback f, const unsigned& n);
|
||||
|
||||
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds 'n' times
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimer(unsigned long d, timer_callback_p f, void* p, unsigned n);
|
||||
int setTimer(const float& d, timer_callback_p f, void* p, const unsigned& n);
|
||||
|
||||
// updates interval of the specified timer
|
||||
bool changeInterval(unsigned numTimer, unsigned long d);
|
||||
bool changeInterval(const unsigned& numTimer, const float& d);
|
||||
|
||||
// destroy the specified timer
|
||||
void deleteTimer(unsigned numTimer);
|
||||
void deleteTimer(const unsigned& numTimer);
|
||||
|
||||
// restart the specified timer
|
||||
void restartTimer(unsigned numTimer);
|
||||
void restartTimer(const unsigned& numTimer);
|
||||
|
||||
// returns true if the specified timer is enabled
|
||||
bool isEnabled(unsigned numTimer);
|
||||
bool isEnabled(const unsigned& numTimer);
|
||||
|
||||
// enables the specified timer
|
||||
void enable(unsigned numTimer);
|
||||
void enable(const unsigned& numTimer);
|
||||
|
||||
// disables the specified timer
|
||||
void disable(unsigned numTimer);
|
||||
void disable(const unsigned& numTimer);
|
||||
|
||||
// enables all timers
|
||||
void enableAll();
|
||||
@@ -140,7 +164,7 @@ class RPI_PICO_ISR_Timer
|
||||
void disableAll();
|
||||
|
||||
// enables the specified timer if it's currently disabled, and vice-versa
|
||||
void toggle(unsigned numTimer);
|
||||
void toggle(const unsigned& numTimer);
|
||||
|
||||
// returns the number of used timers
|
||||
unsigned getNumTimers();
|
||||
@@ -160,7 +184,7 @@ class RPI_PICO_ISR_Timer
|
||||
// low level function to initialize and enable a new timer
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setupTimer(unsigned long d, void* f, void* p, bool h, unsigned n);
|
||||
int setupTimer(const float& d, void* f, void* p, bool h, const unsigned& n);
|
||||
|
||||
// find the first available slot
|
||||
int findFirstFreeSlot();
|
||||
@@ -171,7 +195,7 @@ class RPI_PICO_ISR_Timer
|
||||
void* callback; // pointer to the callback function
|
||||
void* param; // function parameter
|
||||
bool hasParam; // true if callback takes a parameter
|
||||
unsigned long delay; // delay value
|
||||
float delay; // delay value
|
||||
unsigned maxNumRuns; // number of runs to be executed
|
||||
unsigned numRuns; // number of executed runs
|
||||
bool enabled; // true if enabled
|
||||
@@ -184,9 +208,8 @@ class RPI_PICO_ISR_Timer
|
||||
volatile int numTimers;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RPi_Pico_ISR_Timer-Impl.h"
|
||||
|
||||
#endif // ISR_TIMER_GENERIC_H
|
||||
#endif // ISR_TIMER_GENERIC_HPP
|
||||
|
||||
|
||||
+124
-56
@@ -1,36 +1,42 @@
|
||||
|
||||
/****************************************************************************************************************************
|
||||
RPi_Pico_TimerInterrupt.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
RPi_Pico_TimerInterrupt.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
Version: 1.3.1
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
||||
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
||||
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
||||
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
||||
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
||||
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
@@ -38,20 +44,37 @@
|
||||
#ifndef RPI_PICO_TIMERINTERRUPT_H
|
||||
#define RPI_PICO_TIMERINTERRUPT_H
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED)
|
||||
#if defined(USING_RPI_PICO_TIMER_INTERRUPT)
|
||||
#undef USING_RPI_PICO_TIMER_INTERRUPT
|
||||
#endif
|
||||
#define USING_RPI_PICO_TIMER_INTERRUPT true
|
||||
#else
|
||||
#define USING_RPI_PICO_TIMER_INTERRUPT true
|
||||
#error This code is intended to run on the non-mbed RP2040 arduino-pico platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.0"
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.3.1"
|
||||
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MAJOR 1
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MINOR 3
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 1
|
||||
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1003001
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef TIMER_INTERRUPT_DEBUG
|
||||
#define TIMER_INTERRUPT_DEBUG 0
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/timer.h"
|
||||
@@ -59,14 +82,16 @@
|
||||
|
||||
#include "TimerInterrupt_Generic_Debug.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
To enable an alarm:
|
||||
• Enable the interrupt at the timer with a write to the appropriate alarm bit in INTE: i.e. (1 << 0) for ALARM0
|
||||
• Enable the appropriate timer interrupt at the processor (see Section 2.3.2)
|
||||
• Write the time you would like the interrupt to fire to ALARM0 (i.e. the current value in TIMERAWL plus your desired
|
||||
To enable an alarm:
|
||||
• Enable the interrupt at the timer with a write to the appropriate alarm bit in INTE: i.e. (1 << 0) for ALARM0
|
||||
• Enable the appropriate timer interrupt at the processor (see Section 2.3.2)
|
||||
• Write the time you would like the interrupt to fire to ALARM0 (i.e. the current value in TIMERAWL plus your desired
|
||||
alarm time in microseconds). Writing the time to the ALARM register sets the ARMED bit as a side effect.
|
||||
Once the alarm has fired, the ARMED bit will be set to 0 . To clear the latched interrupt, write a 1 to the appropriate bit in
|
||||
INTR.
|
||||
Once the alarm has fired, the ARMED bit will be set to 0 . To clear the latched interrupt, write a 1 to the appropriate bit in
|
||||
INTR.
|
||||
*/
|
||||
|
||||
|
||||
@@ -79,119 +104,162 @@ typedef RPI_PICO_TimerInterrupt RPI_PICO_Timer;
|
||||
|
||||
typedef bool (*pico_timer_callback) (struct repeating_timer *t);
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
class RPI_PICO_TimerInterrupt
|
||||
{
|
||||
private:
|
||||
|
||||
|
||||
uint8_t _timerNo;
|
||||
|
||||
pico_timer_callback _callback; // pointer to the callback function
|
||||
float _frequency; // Timer frequency
|
||||
uint64_t _timerCount; // count to activate timer, in us
|
||||
|
||||
int64_t _timerCount; // count to activate timer, in us
|
||||
|
||||
struct repeating_timer _timer;
|
||||
|
||||
public:
|
||||
|
||||
RPI_PICO_TimerInterrupt(uint8_t timerNo)
|
||||
{
|
||||
{
|
||||
_timerNo = timerNo;
|
||||
_callback = NULL;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TIM_CLOCK_FREQ ( (float) 1000000.0f )
|
||||
|
||||
// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
// No params and duration now. To be added in the future by adding similar functions here
|
||||
bool setFrequency(float frequency, pico_timer_callback callback)
|
||||
bool setFrequency(const float& frequency, pico_timer_callback callback)
|
||||
{
|
||||
if (_timerNo < MAX_RPI_PICO_NUM_TIMERS)
|
||||
{
|
||||
{
|
||||
if ( (frequency == 0.0f) || (frequency > 100000.0f) || (callback == NULL) )
|
||||
{
|
||||
TISR_LOGERROR(F("Error. frequency == 0, higher than 100KHz or callback == NULL "));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// select timer frequency is 1MHz for better accuracy. We don't use 16-bit prescaler for now.
|
||||
// Will use later if very low frequency is needed.
|
||||
_frequency = (float) 1000000;
|
||||
_timerCount = (uint64_t) _frequency / frequency;
|
||||
|
||||
TISR_LOGWARN3(F("RPI_PICO_TimerInterrupt: _timerNo ="), _timerNo, F(", _fre ="), _frequency);
|
||||
TISR_LOGWARN3(F("_count ="), (uint32_t) (_timerCount >> 32) , F("-"), (uint32_t) (_timerCount));
|
||||
|
||||
_frequency = frequency;
|
||||
_timerCount = (int64_t) (TIM_CLOCK_FREQ / frequency);
|
||||
|
||||
TISR_LOGWARN5(F("_timerNo = "), _timerNo, F(", Clock (Hz) = "), TIM_CLOCK_FREQ, F(", _fre (Hz) = "), _frequency);
|
||||
TISR_LOGWARN3(F("_count = "), (uint32_t) (_timerCount >> 32), F("-"), (uint32_t) (_timerCount));
|
||||
|
||||
_callback = callback;
|
||||
|
||||
|
||||
// static bool add_repeating_timer_us(int64_t delay_us, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out);
|
||||
// static bool add_repeating_timer_ms(int64_t delay_ms, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out);
|
||||
// bool cancel_repeating_timer (repeating_timer_t *timer);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Important Notes
|
||||
// delay_ms the repeat delay in milliseconds; if >0 then this is the delay between one callback ending and the next
|
||||
// starting; if <0 then this is the negative of the time between the starts of the callbacks.
|
||||
// The value of 0 is treated as 1 microsecond
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
cancel_repeating_timer(&_timer);
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
|
||||
TISR_LOGWARN1(F("add_repeating_timer_us ="), _timerCount);
|
||||
|
||||
// Use negative value to select time between the starts of the callbacks
|
||||
add_repeating_timer_us(-(_timerCount), _callback, NULL, &_timer);
|
||||
|
||||
TISR_LOGWARN1(F("add_repeating_timer_us between starts = "), _timerCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
TISR_LOGERROR(F("Error. Timer must be 0-3"));
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
// No params and duration now. To be added in the future by adding similar functions here
|
||||
bool setInterval(unsigned long interval, pico_timer_callback callback)
|
||||
bool setInterval(const float& interval, pico_timer_callback callback)
|
||||
{
|
||||
return setFrequency((float) (1000000.0f / interval), callback);
|
||||
}
|
||||
|
||||
bool attachInterrupt(float frequency, pico_timer_callback callback)
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
bool attachInterrupt(const float& frequency, pico_timer_callback callback)
|
||||
{
|
||||
return setFrequency(frequency, callback);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
// No params and duration now. To be added in the future by adding similar functions here
|
||||
bool attachInterruptInterval(unsigned long interval, pico_timer_callback callback)
|
||||
bool attachInterruptInterval(const float& interval, pico_timer_callback callback)
|
||||
{
|
||||
return setFrequency( (float) ( 1000000.0f / interval), callback);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void detachInterrupt()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void disableTimer()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
}
|
||||
|
||||
// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
// Duration (in microseconds). Duration = 0 or not specified => run indefinitely
|
||||
void reattachInterrupt()
|
||||
{
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
add_repeating_timer_us(-(_timerCount), _callback, NULL, &_timer);
|
||||
}
|
||||
|
||||
// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
// Duration (in microseconds). Duration = 0 or not specified => run indefinitely
|
||||
void enableTimer()
|
||||
{
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
add_repeating_timer_us(-(_timerCount), _callback, NULL, &_timer);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
// Just stop clock source, clear the count
|
||||
void stopTimer()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
// Just reconnect clock source, start current count from 0
|
||||
void restartTimer()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
add_repeating_timer_us(-(_timerCount), _callback, NULL, &_timer);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
int8_t getTimer() __attribute__((always_inline))
|
||||
{
|
||||
return _timerNo;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
}; // class RPI_PICO_TimerInterrupt
|
||||
|
||||
#endif // RPI_PICO_TIMERINTERRUPT_H
|
||||
|
||||
@@ -1,35 +1,41 @@
|
||||
/****************************************************************************************************************************
|
||||
TimerInterrupt_Generic_Debug.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
TimerInterrupt_Generic_Debug.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
Version: 1.3.1
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
1.0.1 K Hoang 18/05/2021 Update README and Packages' Patches to match core arduino-pico core v1.4.0
|
||||
1.1.0 K Hoang 10/00/2021 Add support to new boards using the arduino-pico core
|
||||
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
|
||||
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
|
||||
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
|
||||
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
@@ -37,12 +43,16 @@
|
||||
#ifndef TIMERINTERRUPT_GENERIC_DEBUG_H
|
||||
#define TIMERINTERRUPT_GENERIC_DEBUG_H
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef TIMERINTERRUPT_DEBUG_PORT
|
||||
#define TISR_DBG_PORT TIMERINTERRUPT_DEBUG_PORT
|
||||
#else
|
||||
#define TISR_DBG_PORT Serial
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
// Change _TIMERINTERRUPT_LOGLEVEL_ to set tracing and logging verbosity
|
||||
// 0: DISABLED: no logging
|
||||
// 1: ERROR: errors
|
||||
@@ -54,28 +64,53 @@
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 1
|
||||
#endif
|
||||
|
||||
#define TISR_LOGERROR(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGERROR0(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGERROR1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGERROR2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGERROR3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
//////////////////////////////////////////
|
||||
|
||||
#define TISR_LOGWARN(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGWARN0(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGWARN1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGWARN2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGWARN3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
const char TISR_MARK[] = "[TISR] ";
|
||||
const char TISR_SP[] = " ";
|
||||
|
||||
#define TISR_LOGINFO(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGINFO0(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGINFO1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGINFO2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGINFO3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
#define TISR_PRINT TISR_DBG_PORT.print
|
||||
#define TISR_PRINTLN TISR_DBG_PORT.println
|
||||
|
||||
#define TISR_LOGDEBUG(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGDEBUG0(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGDEBUG1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGDEBUG2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGDEBUG3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
#define TISR_PRINT_MARK TISR_PRINT(TISR_MARK)
|
||||
#define TISR_PRINT_SP TISR_PRINT(TISR_SP)
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
#define TISR_LOGERROR(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINTLN(x); }
|
||||
#define TISR_LOGERROR0(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT(x); }
|
||||
#define TISR_LOGERROR1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINTLN(y); }
|
||||
#define TISR_LOGERROR2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINTLN(z); }
|
||||
#define TISR_LOGERROR3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINT(z); TISR_PRINTLN(w); }
|
||||
#define TISR_LOGERROR5(x,y,z,w, xx, yy) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINT(z); TISR_PRINT(w); TISR_PRINT(xx); TISR_PRINTLN(yy); }
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
#define TISR_LOGWARN(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT_MARK; TISR_PRINTLN(x); }
|
||||
#define TISR_LOGWARN0(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT(x); }
|
||||
#define TISR_LOGWARN1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINTLN(y); }
|
||||
#define TISR_LOGWARN2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINTLN(z); }
|
||||
#define TISR_LOGWARN3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINT(z); TISR_PRINTLN(w); }
|
||||
#define TISR_LOGWARN5(x,y,z,w, xx, yy) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINT(z); TISR_PRINT(w); TISR_PRINT(xx); TISR_PRINTLN(yy); }
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
#define TISR_LOGINFO(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT_MARK; TISR_PRINTLN(x); }
|
||||
#define TISR_LOGINFO0(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT(x); }
|
||||
#define TISR_LOGINFO1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINTLN(y); }
|
||||
#define TISR_LOGINFO2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINTLN(z); }
|
||||
#define TISR_LOGINFO3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINT(z); TISR_PRINTLN(w); }
|
||||
#define TISR_LOGINFO5(x,y,z,w, xx, yy) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINT(z); TISR_PRINT(w); TISR_PRINT(xx); TISR_PRINTLN(yy); }
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
#define TISR_LOGDEBUG(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT_MARK; TISR_PRINTLN(x); }
|
||||
#define TISR_LOGDEBUG0(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT(x); }
|
||||
#define TISR_LOGDEBUG1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINTLN(y); }
|
||||
#define TISR_LOGDEBUG2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINTLN(z); }
|
||||
#define TISR_LOGDEBUG3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINT(z); TISR_PRINTLN(w); }
|
||||
#define TISR_LOGDEBUG5(x,y,z,w, xx, yy) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT(y); TISR_PRINT(z); TISR_PRINT(w); TISR_PRINT(xx); TISR_PRINTLN(yy); }
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
#endif //TIMERINTERRUPT_GENERIC_DEBUG_H
|
||||
|
||||
@@ -1,383 +0,0 @@
|
||||
/****************************************************************************************************************************
|
||||
RPi_Pico_ISR_Timer.cpp
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "RPi_Pico_ISR_Timer.h"
|
||||
|
||||
RPI_PICO_ISR_Timer::RPI_PICO_ISR_Timer()
|
||||
: numTimers (-1)
|
||||
{
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::init()
|
||||
{
|
||||
unsigned long current_millis = millis(); //elapsed();
|
||||
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
memset((void*) &timer[i], 0, sizeof (timer_t));
|
||||
timer[i].prev_millis = current_millis;
|
||||
}
|
||||
|
||||
numTimers = 0;
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::run()
|
||||
{
|
||||
uint8_t i;
|
||||
unsigned long current_millis;
|
||||
|
||||
// get current time
|
||||
current_millis = millis(); //elapsed();
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during ISR
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_DONTRUN;
|
||||
|
||||
// no callback == no timer, i.e. jump over empty slots
|
||||
if (timer[i].callback != NULL)
|
||||
{
|
||||
|
||||
// is it time to process this timer ?
|
||||
// see http://arduino.cc/forum/index.php/topic,124048.msg932592.html#msg932592
|
||||
|
||||
if ((current_millis - timer[i].prev_millis) >= timer[i].delay)
|
||||
{
|
||||
unsigned long skipTimes = (current_millis - timer[i].prev_millis) / timer[i].delay;
|
||||
|
||||
// update time
|
||||
timer[i].prev_millis += timer[i].delay * skipTimes;
|
||||
|
||||
// check if the timer callback has to be executed
|
||||
if (timer[i].enabled)
|
||||
{
|
||||
|
||||
// "run forever" timers must always be executed
|
||||
if (timer[i].maxNumRuns == RPI_PICO_RUN_FOREVER)
|
||||
{
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNONLY;
|
||||
}
|
||||
// other timers get executed the specified number of times
|
||||
else if (timer[i].numRuns < timer[i].maxNumRuns)
|
||||
{
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNONLY;
|
||||
timer[i].numRuns++;
|
||||
|
||||
// after the last run, delete the timer
|
||||
if (timer[i].numRuns >= timer[i].maxNumRuns)
|
||||
{
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNANDDEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].toBeCalled == RPI_PICO_DEFCALL_DONTRUN)
|
||||
continue;
|
||||
|
||||
if (timer[i].hasParam)
|
||||
(*(timer_callback_p)timer[i].callback)(timer[i].param);
|
||||
else
|
||||
(*(timer_callback)timer[i].callback)();
|
||||
|
||||
if (timer[i].toBeCalled == RPI_PICO_DEFCALL_RUNANDDEL)
|
||||
deleteTimer(i);
|
||||
}
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during ISR
|
||||
rp2040.resumeOtherCore();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// find the first available slot
|
||||
// return -1 if none found
|
||||
int RPI_PICO_ISR_Timer::findFirstFreeSlot()
|
||||
{
|
||||
// all slots are used
|
||||
if (numTimers >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// return the first slot with no callback (i.e. free)
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].callback == NULL)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
// no free slots found
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int RPI_PICO_ISR_Timer::setupTimer(unsigned long d, void* f, void* p, bool h, unsigned n)
|
||||
{
|
||||
int freeTimer;
|
||||
|
||||
if (numTimers < 0)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
freeTimer = findFirstFreeSlot();
|
||||
if (freeTimer < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (f == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
timer[freeTimer].delay = d;
|
||||
timer[freeTimer].callback = f;
|
||||
timer[freeTimer].param = p;
|
||||
timer[freeTimer].hasParam = h;
|
||||
timer[freeTimer].maxNumRuns = n;
|
||||
timer[freeTimer].enabled = true;
|
||||
timer[freeTimer].prev_millis = millis();
|
||||
|
||||
numTimers++;
|
||||
|
||||
return freeTimer;
|
||||
}
|
||||
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimer(unsigned long d, timer_callback f, unsigned n)
|
||||
{
|
||||
return setupTimer(d, (void *)f, NULL, false, n);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimer(unsigned long d, timer_callback_p f, void* p, unsigned n)
|
||||
{
|
||||
return setupTimer(d, (void *)f, p, true, n);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setInterval(unsigned long d, timer_callback f)
|
||||
{
|
||||
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_FOREVER);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setInterval(unsigned long d, timer_callback_p f, void* p)
|
||||
{
|
||||
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_FOREVER);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimeout(unsigned long d, timer_callback f)
|
||||
{
|
||||
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_ONCE);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimeout(unsigned long d, timer_callback_p f, void* p)
|
||||
{
|
||||
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_ONCE);
|
||||
}
|
||||
|
||||
bool RPI_PICO_ISR_Timer::changeInterval(unsigned numTimer, unsigned long d)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Updates interval of existing specified timer
|
||||
if (timer[numTimer].callback != NULL)
|
||||
{
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
timer[numTimer].delay = d;
|
||||
timer[numTimer].prev_millis = millis();
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.resumeOtherCore();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// false return for non-used numTimer, no callback
|
||||
return false;
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::deleteTimer(unsigned timerId)
|
||||
{
|
||||
if (timerId >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// nothing to delete if no timers are in use
|
||||
if (numTimers == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// don't decrease the number of timers if the specified slot is already empty
|
||||
if (timer[timerId].callback != NULL)
|
||||
{
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
memset((void*) &timer[timerId], 0, sizeof (timer_t));
|
||||
timer[timerId].prev_millis = millis();
|
||||
|
||||
// update number of timers
|
||||
numTimers--;
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.resumeOtherCore();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// function contributed by code@rowansimms.com
|
||||
void RPI_PICO_ISR_Timer::restartTimer(unsigned numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
timer[numTimer].prev_millis = millis();
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.resumeOtherCore();
|
||||
}
|
||||
|
||||
|
||||
bool RPI_PICO_ISR_Timer::isEnabled(unsigned numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return timer[numTimer].enabled;
|
||||
}
|
||||
|
||||
|
||||
void RPI_PICO_ISR_Timer::enable(unsigned numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
timer[numTimer].enabled = true;
|
||||
}
|
||||
|
||||
|
||||
void RPI_PICO_ISR_Timer::disable(unsigned numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
timer[numTimer].enabled = false;
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::enableAll()
|
||||
{
|
||||
// Enable all timers with a callback assigned (used)
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
||||
{
|
||||
timer[i].enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.resumeOtherCore();
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::disableAll()
|
||||
{
|
||||
// Disable all timers with a callback assigned (used)
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
||||
{
|
||||
timer[i].enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.resumeOtherCore();
|
||||
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::toggle(unsigned numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
timer[numTimer].enabled = !timer[numTimer].enabled;
|
||||
}
|
||||
|
||||
|
||||
unsigned RPI_PICO_ISR_Timer::getNumTimers()
|
||||
{
|
||||
return numTimers;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,189 +0,0 @@
|
||||
/****************************************************************************************************************************
|
||||
RPi_Pico_ISR_Timer.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ISR_TIMER_GENERIC_H
|
||||
#define ISR_TIMER_GENERIC_H
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.0"
|
||||
#endif
|
||||
|
||||
#include "TimerInterrupt_Generic_Debug.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "pico/multicore.h"
|
||||
|
||||
#if defined(ARDUINO)
|
||||
#if ARDUINO >= 100
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define FLAG_VALUE 0xDEADBEEF
|
||||
|
||||
#define RPI_PICO_ISR_Timer RPI_PICO_ISRTimer
|
||||
|
||||
typedef void (*timer_callback)();
|
||||
typedef void (*timer_callback_p)(void *);
|
||||
|
||||
class RPI_PICO_ISR_Timer
|
||||
{
|
||||
|
||||
public:
|
||||
// maximum number of timers
|
||||
#define RPI_PICO_MAX_TIMERS 16
|
||||
#define RPI_PICO_RUN_FOREVER 0
|
||||
#define RPI_PICO_RUN_ONCE 1
|
||||
|
||||
// constructor
|
||||
RPI_PICO_ISR_Timer();
|
||||
|
||||
void init();
|
||||
|
||||
// this function must be called inside loop()
|
||||
void run();
|
||||
|
||||
// Timer will call function 'f' every 'd' milliseconds forever
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setInterval(unsigned long d, timer_callback f);
|
||||
|
||||
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds forever
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setInterval(unsigned long d, timer_callback_p f, void* p);
|
||||
|
||||
// Timer will call function 'f' after 'd' milliseconds one time
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimeout(unsigned long d, timer_callback f);
|
||||
|
||||
// Timer will call function 'f' with parameter 'p' after 'd' milliseconds one time
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimeout(unsigned long d, timer_callback_p f, void* p);
|
||||
|
||||
// Timer will call function 'f' every 'd' milliseconds 'n' times
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimer(unsigned long d, timer_callback f, unsigned n);
|
||||
|
||||
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds 'n' times
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setTimer(unsigned long d, timer_callback_p f, void* p, unsigned n);
|
||||
|
||||
// updates interval of the specified timer
|
||||
bool changeInterval(unsigned numTimer, unsigned long d);
|
||||
|
||||
// destroy the specified timer
|
||||
void deleteTimer(unsigned numTimer);
|
||||
|
||||
// restart the specified timer
|
||||
void restartTimer(unsigned numTimer);
|
||||
|
||||
// returns true if the specified timer is enabled
|
||||
bool isEnabled(unsigned numTimer);
|
||||
|
||||
// enables the specified timer
|
||||
void enable(unsigned numTimer);
|
||||
|
||||
// disables the specified timer
|
||||
void disable(unsigned numTimer);
|
||||
|
||||
// enables all timers
|
||||
void enableAll();
|
||||
|
||||
// disables all timers
|
||||
void disableAll();
|
||||
|
||||
// enables the specified timer if it's currently disabled, and vice-versa
|
||||
void toggle(unsigned numTimer);
|
||||
|
||||
// returns the number of used timers
|
||||
unsigned getNumTimers();
|
||||
|
||||
// returns the number of available timers
|
||||
unsigned getNumAvailableTimers()
|
||||
{
|
||||
return RPI_PICO_MAX_TIMERS - numTimers;
|
||||
};
|
||||
|
||||
private:
|
||||
// deferred call constants
|
||||
#define RPI_PICO_DEFCALL_DONTRUN 0 // don't call the callback function
|
||||
#define RPI_PICO_DEFCALL_RUNONLY 1 // call the callback function but don't delete the timer
|
||||
#define RPI_PICO_DEFCALL_RUNANDDEL 2 // call the callback function and delete the timer
|
||||
|
||||
// low level function to initialize and enable a new timer
|
||||
// returns the timer number (numTimer) on success or
|
||||
// -1 on failure (f == NULL) or no free timers
|
||||
int setupTimer(unsigned long d, void* f, void* p, bool h, unsigned n);
|
||||
|
||||
// find the first available slot
|
||||
int findFirstFreeSlot();
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned long prev_millis; // value returned by the millis() function in the previous run() call
|
||||
void* callback; // pointer to the callback function
|
||||
void* param; // function parameter
|
||||
bool hasParam; // true if callback takes a parameter
|
||||
unsigned long delay; // delay value
|
||||
unsigned maxNumRuns; // number of runs to be executed
|
||||
unsigned numRuns; // number of executed runs
|
||||
bool enabled; // true if enabled
|
||||
unsigned toBeCalled; // deferred function call (sort of) - N.B.: only used in run()
|
||||
} timer_t;
|
||||
|
||||
volatile timer_t timer[RPI_PICO_MAX_TIMERS];
|
||||
|
||||
// actual number of timers in use (-1 means uninitialized)
|
||||
volatile int numTimers;
|
||||
};
|
||||
|
||||
#endif // ISR_TIMER_GENERIC_H
|
||||
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
|
||||
/****************************************************************************************************************************
|
||||
RPi_Pico_TimerInterrupt.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef RPI_PICO_TIMERINTERRUPT_H
|
||||
#define RPI_PICO_TIMERINTERRUPT_H
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#else
|
||||
#define USING_RPI_PICO_TIMER_INTERRUPT true
|
||||
#endif
|
||||
|
||||
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.0"
|
||||
#endif
|
||||
|
||||
#ifndef TIMER_INTERRUPT_DEBUG
|
||||
#define TIMER_INTERRUPT_DEBUG 0
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/timer.h"
|
||||
#include "hardware/irq.h"
|
||||
|
||||
#include "TimerInterrupt_Generic_Debug.h"
|
||||
|
||||
/*
|
||||
To enable an alarm:
|
||||
• Enable the interrupt at the timer with a write to the appropriate alarm bit in INTE: i.e. (1 << 0) for ALARM0
|
||||
• Enable the appropriate timer interrupt at the processor (see Section 2.3.2)
|
||||
• Write the time you would like the interrupt to fire to ALARM0 (i.e. the current value in TIMERAWL plus your desired
|
||||
alarm time in microseconds). Writing the time to the ALARM register sets the ARMED bit as a side effect.
|
||||
Once the alarm has fired, the ARMED bit will be set to 0 . To clear the latched interrupt, write a 1 to the appropriate bit in
|
||||
INTR.
|
||||
*/
|
||||
|
||||
|
||||
class RPI_PICO_TimerInterrupt;
|
||||
|
||||
typedef RPI_PICO_TimerInterrupt RPI_PICO_Timer;
|
||||
|
||||
// We can use many timers here
|
||||
#define MAX_RPI_PICO_NUM_TIMERS 4
|
||||
|
||||
typedef bool (*pico_timer_callback) (struct repeating_timer *t);
|
||||
|
||||
|
||||
class RPI_PICO_TimerInterrupt
|
||||
{
|
||||
private:
|
||||
|
||||
uint8_t _timerNo;
|
||||
|
||||
pico_timer_callback _callback; // pointer to the callback function
|
||||
float _frequency; // Timer frequency
|
||||
uint64_t _timerCount; // count to activate timer, in us
|
||||
|
||||
struct repeating_timer _timer;
|
||||
|
||||
public:
|
||||
|
||||
RPI_PICO_TimerInterrupt(uint8_t timerNo)
|
||||
{
|
||||
_timerNo = timerNo;
|
||||
_callback = NULL;
|
||||
};
|
||||
|
||||
// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
// No params and duration now. To be added in the future by adding similar functions here
|
||||
bool setFrequency(float frequency, pico_timer_callback callback)
|
||||
{
|
||||
if (_timerNo < MAX_RPI_PICO_NUM_TIMERS)
|
||||
{
|
||||
// select timer frequency is 1MHz for better accuracy. We don't use 16-bit prescaler for now.
|
||||
// Will use later if very low frequency is needed.
|
||||
_frequency = (float) 1000000;
|
||||
_timerCount = (uint64_t) _frequency / frequency;
|
||||
|
||||
TISR_LOGWARN3(F("RPI_PICO_TimerInterrupt: _timerNo ="), _timerNo, F(", _fre ="), _frequency);
|
||||
TISR_LOGWARN3(F("_count ="), (uint32_t) (_timerCount >> 32) , F("-"), (uint32_t) (_timerCount));
|
||||
|
||||
_callback = callback;
|
||||
|
||||
// static bool add_repeating_timer_us(int64_t delay_us, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out);
|
||||
// static bool add_repeating_timer_ms(int64_t delay_ms, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out);
|
||||
// bool cancel_repeating_timer (repeating_timer_t *timer);
|
||||
cancel_repeating_timer(&_timer);
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
|
||||
TISR_LOGWARN1(F("add_repeating_timer_us ="), _timerCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
TISR_LOGERROR(F("Error. Timer must be 0-3"));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
// No params and duration now. To be added in the future by adding similar functions here
|
||||
bool setInterval(unsigned long interval, pico_timer_callback callback)
|
||||
{
|
||||
return setFrequency((float) (1000000.0f / interval), callback);
|
||||
}
|
||||
|
||||
bool attachInterrupt(float frequency, pico_timer_callback callback)
|
||||
{
|
||||
return setFrequency(frequency, callback);
|
||||
}
|
||||
|
||||
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
// No params and duration now. To be added in the future by adding similar functions here
|
||||
bool attachInterruptInterval(unsigned long interval, pico_timer_callback callback)
|
||||
{
|
||||
return setFrequency( (float) ( 1000000.0f / interval), callback);
|
||||
}
|
||||
|
||||
void detachInterrupt()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
}
|
||||
|
||||
void disableTimer()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
}
|
||||
|
||||
// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
void reattachInterrupt()
|
||||
{
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
}
|
||||
|
||||
// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
void enableTimer()
|
||||
{
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
}
|
||||
|
||||
// Just stop clock source, clear the count
|
||||
void stopTimer()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
}
|
||||
|
||||
// Just reconnect clock source, start current count from 0
|
||||
void restartTimer()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
}
|
||||
|
||||
int8_t getTimer() __attribute__((always_inline))
|
||||
{
|
||||
return _timerNo;
|
||||
};
|
||||
}; // class RPI_PICO_TimerInterrupt
|
||||
|
||||
#endif // RPI_PICO_TIMERINTERRUPT_H
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
/****************************************************************************************************************************
|
||||
TimerInterrupt_Generic_Debug.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef TIMERINTERRUPT_GENERIC_DEBUG_H
|
||||
#define TIMERINTERRUPT_GENERIC_DEBUG_H
|
||||
|
||||
#ifdef TIMERINTERRUPT_DEBUG_PORT
|
||||
#define TISR_DBG_PORT TIMERINTERRUPT_DEBUG_PORT
|
||||
#else
|
||||
#define TISR_DBG_PORT Serial
|
||||
#endif
|
||||
|
||||
// Change _TIMERINTERRUPT_LOGLEVEL_ to set tracing and logging verbosity
|
||||
// 0: DISABLED: no logging
|
||||
// 1: ERROR: errors
|
||||
// 2: WARN: errors and warnings
|
||||
// 3: INFO: errors, warnings and informational (default)
|
||||
// 4: DEBUG: errors, warnings, informational and debug
|
||||
|
||||
#ifndef _TIMERINTERRUPT_LOGLEVEL_
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 1
|
||||
#endif
|
||||
|
||||
#define TISR_LOGERROR(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGERROR0(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGERROR1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGERROR2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGERROR3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
|
||||
#define TISR_LOGWARN(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGWARN0(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGWARN1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGWARN2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGWARN3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
|
||||
#define TISR_LOGINFO(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGINFO0(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGINFO1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGINFO2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGINFO3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
|
||||
#define TISR_LOGDEBUG(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGDEBUG0(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGDEBUG1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGDEBUG2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGDEBUG3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
|
||||
#endif //TIMERINTERRUPT_GENERIC_DEBUG_H
|
||||
@@ -1,391 +0,0 @@
|
||||
/****************************************************************************************************************************
|
||||
RPi_Pico_ISR_Timer-Impl.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ISR_TIMER_GENERIC_IMPL_H
|
||||
#define ISR_TIMER_GENERIC_IMPL_H
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
RPI_PICO_ISR_Timer::RPI_PICO_ISR_Timer()
|
||||
: numTimers (-1)
|
||||
{
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::init()
|
||||
{
|
||||
unsigned long current_millis = millis(); //elapsed();
|
||||
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
memset((void*) &timer[i], 0, sizeof (timer_t));
|
||||
timer[i].prev_millis = current_millis;
|
||||
}
|
||||
|
||||
numTimers = 0;
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::run()
|
||||
{
|
||||
uint8_t i;
|
||||
unsigned long current_millis;
|
||||
|
||||
// get current time
|
||||
current_millis = millis(); //elapsed();
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during ISR
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_DONTRUN;
|
||||
|
||||
// no callback == no timer, i.e. jump over empty slots
|
||||
if (timer[i].callback != NULL)
|
||||
{
|
||||
|
||||
// is it time to process this timer ?
|
||||
// see http://arduino.cc/forum/index.php/topic,124048.msg932592.html#msg932592
|
||||
|
||||
if ((current_millis - timer[i].prev_millis) >= timer[i].delay)
|
||||
{
|
||||
unsigned long skipTimes = (current_millis - timer[i].prev_millis) / timer[i].delay;
|
||||
|
||||
// update time
|
||||
timer[i].prev_millis += timer[i].delay * skipTimes;
|
||||
|
||||
// check if the timer callback has to be executed
|
||||
if (timer[i].enabled)
|
||||
{
|
||||
|
||||
// "run forever" timers must always be executed
|
||||
if (timer[i].maxNumRuns == RPI_PICO_RUN_FOREVER)
|
||||
{
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNONLY;
|
||||
}
|
||||
// other timers get executed the specified number of times
|
||||
else if (timer[i].numRuns < timer[i].maxNumRuns)
|
||||
{
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNONLY;
|
||||
timer[i].numRuns++;
|
||||
|
||||
// after the last run, delete the timer
|
||||
if (timer[i].numRuns >= timer[i].maxNumRuns)
|
||||
{
|
||||
timer[i].toBeCalled = RPI_PICO_DEFCALL_RUNANDDEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].toBeCalled == RPI_PICO_DEFCALL_DONTRUN)
|
||||
continue;
|
||||
|
||||
if (timer[i].hasParam)
|
||||
(*(timer_callback_p)timer[i].callback)(timer[i].param);
|
||||
else
|
||||
(*(timer_callback)timer[i].callback)();
|
||||
|
||||
if (timer[i].toBeCalled == RPI_PICO_DEFCALL_RUNANDDEL)
|
||||
deleteTimer(i);
|
||||
}
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during ISR
|
||||
rp2040.resumeOtherCore();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// find the first available slot
|
||||
// return -1 if none found
|
||||
int RPI_PICO_ISR_Timer::findFirstFreeSlot()
|
||||
{
|
||||
// all slots are used
|
||||
if (numTimers >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// return the first slot with no callback (i.e. free)
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].callback == NULL)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
// no free slots found
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int RPI_PICO_ISR_Timer::setupTimer(unsigned long d, void* f, void* p, bool h, unsigned n)
|
||||
{
|
||||
int freeTimer;
|
||||
|
||||
if (numTimers < 0)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
freeTimer = findFirstFreeSlot();
|
||||
if (freeTimer < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (f == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
timer[freeTimer].delay = d;
|
||||
timer[freeTimer].callback = f;
|
||||
timer[freeTimer].param = p;
|
||||
timer[freeTimer].hasParam = h;
|
||||
timer[freeTimer].maxNumRuns = n;
|
||||
timer[freeTimer].enabled = true;
|
||||
timer[freeTimer].prev_millis = millis();
|
||||
|
||||
numTimers++;
|
||||
|
||||
return freeTimer;
|
||||
}
|
||||
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimer(unsigned long d, timer_callback f, unsigned n)
|
||||
{
|
||||
return setupTimer(d, (void *)f, NULL, false, n);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimer(unsigned long d, timer_callback_p f, void* p, unsigned n)
|
||||
{
|
||||
return setupTimer(d, (void *)f, p, true, n);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setInterval(unsigned long d, timer_callback f)
|
||||
{
|
||||
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_FOREVER);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setInterval(unsigned long d, timer_callback_p f, void* p)
|
||||
{
|
||||
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_FOREVER);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimeout(unsigned long d, timer_callback f)
|
||||
{
|
||||
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_ONCE);
|
||||
}
|
||||
|
||||
int RPI_PICO_ISR_Timer::setTimeout(unsigned long d, timer_callback_p f, void* p)
|
||||
{
|
||||
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_ONCE);
|
||||
}
|
||||
|
||||
bool RPI_PICO_ISR_Timer::changeInterval(unsigned numTimer, unsigned long d)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Updates interval of existing specified timer
|
||||
if (timer[numTimer].callback != NULL)
|
||||
{
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
timer[numTimer].delay = d;
|
||||
timer[numTimer].prev_millis = millis();
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.resumeOtherCore();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// false return for non-used numTimer, no callback
|
||||
return false;
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::deleteTimer(unsigned timerId)
|
||||
{
|
||||
if (timerId >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// nothing to delete if no timers are in use
|
||||
if (numTimers == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// don't decrease the number of timers if the specified slot is already empty
|
||||
if (timer[timerId].callback != NULL)
|
||||
{
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
memset((void*) &timer[timerId], 0, sizeof (timer_t));
|
||||
timer[timerId].prev_millis = millis();
|
||||
|
||||
// update number of timers
|
||||
numTimers--;
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.resumeOtherCore();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// function contributed by code@rowansimms.com
|
||||
void RPI_PICO_ISR_Timer::restartTimer(unsigned numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
timer[numTimer].prev_millis = millis();
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.resumeOtherCore();
|
||||
}
|
||||
|
||||
|
||||
bool RPI_PICO_ISR_Timer::isEnabled(unsigned numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return timer[numTimer].enabled;
|
||||
}
|
||||
|
||||
|
||||
void RPI_PICO_ISR_Timer::enable(unsigned numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
timer[numTimer].enabled = true;
|
||||
}
|
||||
|
||||
|
||||
void RPI_PICO_ISR_Timer::disable(unsigned numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
timer[numTimer].enabled = false;
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::enableAll()
|
||||
{
|
||||
// Enable all timers with a callback assigned (used)
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
||||
{
|
||||
timer[i].enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.resumeOtherCore();
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::disableAll()
|
||||
{
|
||||
// Disable all timers with a callback assigned (used)
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.idleOtherCore();
|
||||
|
||||
for (uint8_t i = 0; i < RPI_PICO_MAX_TIMERS; i++)
|
||||
{
|
||||
if (timer[i].callback != NULL && timer[i].numRuns == RPI_PICO_RUN_FOREVER)
|
||||
{
|
||||
timer[i].enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// RPI_PICO is a multi core / multi processing chip. It is mandatory to disable task switches during modifying shared vars
|
||||
rp2040.resumeOtherCore();
|
||||
|
||||
}
|
||||
|
||||
void RPI_PICO_ISR_Timer::toggle(unsigned numTimer)
|
||||
{
|
||||
if (numTimer >= RPI_PICO_MAX_TIMERS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
timer[numTimer].enabled = !timer[numTimer].enabled;
|
||||
}
|
||||
|
||||
|
||||
unsigned RPI_PICO_ISR_Timer::getNumTimers()
|
||||
{
|
||||
return numTimers;
|
||||
}
|
||||
|
||||
#endif // ISR_TIMER_GENERIC_IMPL_H
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
|
||||
/****************************************************************************************************************************
|
||||
RPi_Pico_TimerInterrupt.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef RPI_PICO_TIMERINTERRUPT_H
|
||||
#define RPI_PICO_TIMERINTERRUPT_H
|
||||
|
||||
#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) )
|
||||
#error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
|
||||
#else
|
||||
#define USING_RPI_PICO_TIMER_INTERRUPT true
|
||||
#endif
|
||||
|
||||
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
|
||||
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.0"
|
||||
#endif
|
||||
|
||||
#ifndef TIMER_INTERRUPT_DEBUG
|
||||
#define TIMER_INTERRUPT_DEBUG 0
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/timer.h"
|
||||
#include "hardware/irq.h"
|
||||
|
||||
#include "TimerInterrupt_Generic_Debug.h"
|
||||
|
||||
/*
|
||||
To enable an alarm:
|
||||
• Enable the interrupt at the timer with a write to the appropriate alarm bit in INTE: i.e. (1 << 0) for ALARM0
|
||||
• Enable the appropriate timer interrupt at the processor (see Section 2.3.2)
|
||||
• Write the time you would like the interrupt to fire to ALARM0 (i.e. the current value in TIMERAWL plus your desired
|
||||
alarm time in microseconds). Writing the time to the ALARM register sets the ARMED bit as a side effect.
|
||||
Once the alarm has fired, the ARMED bit will be set to 0 . To clear the latched interrupt, write a 1 to the appropriate bit in
|
||||
INTR.
|
||||
*/
|
||||
|
||||
|
||||
class RPI_PICO_TimerInterrupt;
|
||||
|
||||
typedef RPI_PICO_TimerInterrupt RPI_PICO_Timer;
|
||||
|
||||
// We can use many timers here
|
||||
#define MAX_RPI_PICO_NUM_TIMERS 4
|
||||
|
||||
typedef bool (*pico_timer_callback) (struct repeating_timer *t);
|
||||
|
||||
|
||||
class RPI_PICO_TimerInterrupt
|
||||
{
|
||||
private:
|
||||
|
||||
uint8_t _timerNo;
|
||||
|
||||
pico_timer_callback _callback; // pointer to the callback function
|
||||
float _frequency; // Timer frequency
|
||||
uint64_t _timerCount; // count to activate timer, in us
|
||||
|
||||
struct repeating_timer _timer;
|
||||
|
||||
public:
|
||||
|
||||
RPI_PICO_TimerInterrupt(uint8_t timerNo)
|
||||
{
|
||||
_timerNo = timerNo;
|
||||
_callback = NULL;
|
||||
};
|
||||
|
||||
// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
// No params and duration now. To be added in the future by adding similar functions here
|
||||
bool setFrequency(float frequency, pico_timer_callback callback)
|
||||
{
|
||||
if (_timerNo < MAX_RPI_PICO_NUM_TIMERS)
|
||||
{
|
||||
// select timer frequency is 1MHz for better accuracy. We don't use 16-bit prescaler for now.
|
||||
// Will use later if very low frequency is needed.
|
||||
_frequency = (float) 1000000;
|
||||
_timerCount = (uint64_t) _frequency / frequency;
|
||||
|
||||
TISR_LOGWARN3(F("RPI_PICO_TimerInterrupt: _timerNo ="), _timerNo, F(", _fre ="), _frequency);
|
||||
TISR_LOGWARN3(F("_count ="), (uint32_t) (_timerCount >> 32) , F("-"), (uint32_t) (_timerCount));
|
||||
|
||||
_callback = callback;
|
||||
|
||||
// static bool add_repeating_timer_us(int64_t delay_us, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out);
|
||||
// static bool add_repeating_timer_ms(int64_t delay_ms, repeating_timer_callback_t callback, void *user_data, repeating_timer_t *out);
|
||||
// bool cancel_repeating_timer (repeating_timer_t *timer);
|
||||
cancel_repeating_timer(&_timer);
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
|
||||
TISR_LOGWARN1(F("add_repeating_timer_us ="), _timerCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
TISR_LOGERROR(F("Error. Timer must be 0-3"));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
// No params and duration now. To be added in the future by adding similar functions here
|
||||
bool setInterval(unsigned long interval, pico_timer_callback callback)
|
||||
{
|
||||
return setFrequency((float) (1000000.0f / interval), callback);
|
||||
}
|
||||
|
||||
bool attachInterrupt(float frequency, pico_timer_callback callback)
|
||||
{
|
||||
return setFrequency(frequency, callback);
|
||||
}
|
||||
|
||||
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
// No params and duration now. To be added in the future by adding similar functions here
|
||||
bool attachInterruptInterval(unsigned long interval, pico_timer_callback callback)
|
||||
{
|
||||
return setFrequency( (float) ( 1000000.0f / interval), callback);
|
||||
}
|
||||
|
||||
void detachInterrupt()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
}
|
||||
|
||||
void disableTimer()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
}
|
||||
|
||||
// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
void reattachInterrupt()
|
||||
{
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
}
|
||||
|
||||
// Duration (in milliseconds). Duration = 0 or not specified => run indefinitely
|
||||
void enableTimer()
|
||||
{
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
}
|
||||
|
||||
// Just stop clock source, clear the count
|
||||
void stopTimer()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
}
|
||||
|
||||
// Just reconnect clock source, start current count from 0
|
||||
void restartTimer()
|
||||
{
|
||||
cancel_repeating_timer(&_timer);
|
||||
add_repeating_timer_us(_timerCount, _callback, NULL, &_timer);
|
||||
}
|
||||
|
||||
int8_t getTimer() __attribute__((always_inline))
|
||||
{
|
||||
return _timerNo;
|
||||
};
|
||||
}; // class RPI_PICO_TimerInterrupt
|
||||
|
||||
#endif // RPI_PICO_TIMERINTERRUPT_H
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
/****************************************************************************************************************************
|
||||
TimerInterrupt_Generic_Debug.h
|
||||
For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
|
||||
Written by Khoi Hoang
|
||||
|
||||
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
|
||||
Licensed under MIT license
|
||||
|
||||
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
|
||||
interrupts based on this timebase. It supports the following features:
|
||||
• A single 64-bit counter, incrementing once per microsecond
|
||||
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
|
||||
• Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
|
||||
|
||||
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
|
||||
unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks.
|
||||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
|
||||
Therefore, their executions are not blocked by bad-behaving functions / tasks.
|
||||
This important feature is absolutely necessary for mission-critical tasks.
|
||||
|
||||
Based on SimpleTimer - A timer library for Arduino.
|
||||
Author: mromani@ottotecnica.com
|
||||
Copyright (c) 2010 OTTOTECNICA Italy
|
||||
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.0.0
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- ---------- -----------
|
||||
1.0.0 K Hoang 11/05/2021 Initial coding to support RP2040-based boards such as RASPBERRY_PI_PICO. etc.
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef TIMERINTERRUPT_GENERIC_DEBUG_H
|
||||
#define TIMERINTERRUPT_GENERIC_DEBUG_H
|
||||
|
||||
#ifdef TIMERINTERRUPT_DEBUG_PORT
|
||||
#define TISR_DBG_PORT TIMERINTERRUPT_DEBUG_PORT
|
||||
#else
|
||||
#define TISR_DBG_PORT Serial
|
||||
#endif
|
||||
|
||||
// Change _TIMERINTERRUPT_LOGLEVEL_ to set tracing and logging verbosity
|
||||
// 0: DISABLED: no logging
|
||||
// 1: ERROR: errors
|
||||
// 2: WARN: errors and warnings
|
||||
// 3: INFO: errors, warnings and informational (default)
|
||||
// 4: DEBUG: errors, warnings, informational and debug
|
||||
|
||||
#ifndef _TIMERINTERRUPT_LOGLEVEL_
|
||||
#define _TIMERINTERRUPT_LOGLEVEL_ 1
|
||||
#endif
|
||||
|
||||
#define TISR_LOGERROR(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGERROR0(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGERROR1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGERROR2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGERROR3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
|
||||
#define TISR_LOGWARN(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGWARN0(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGWARN1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGWARN2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGWARN3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
|
||||
#define TISR_LOGINFO(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGINFO0(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGINFO1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGINFO2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGINFO3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
|
||||
#define TISR_LOGDEBUG(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); }
|
||||
#define TISR_LOGDEBUG0(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print(x); }
|
||||
#define TISR_LOGDEBUG1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); }
|
||||
#define TISR_LOGDEBUG2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); }
|
||||
#define TISR_LOGDEBUG3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); }
|
||||
|
||||
#endif //TIMERINTERRUPT_GENERIC_DEBUG_H
|
||||
@@ -0,0 +1,70 @@
|
||||
# Code formatting rules for Arduino libraries, modified from for KH libraries:
|
||||
#
|
||||
# https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf
|
||||
#
|
||||
|
||||
# astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino
|
||||
|
||||
--mode=c
|
||||
--lineend=linux
|
||||
--style=allman
|
||||
|
||||
# -r or -R
|
||||
#--recursive
|
||||
|
||||
# -c => Converts tabs into spaces
|
||||
convert-tabs
|
||||
|
||||
# -s2 => 2 spaces indentation
|
||||
--indent=spaces=2
|
||||
|
||||
# -t2 => tab =2 spaces
|
||||
#--indent=tab=2
|
||||
|
||||
# -C
|
||||
--indent-classes
|
||||
|
||||
# -S
|
||||
--indent-switches
|
||||
|
||||
# -xW
|
||||
--indent-preproc-block
|
||||
|
||||
# -Y => indent classes, switches (and cases), comments starting at column 1
|
||||
--indent-col1-comments
|
||||
|
||||
# -M120 => maximum of 120 spaces to indent a continuation line
|
||||
--max-continuation-indent=120
|
||||
|
||||
# -xC120 => max‑code‑length will break a line if the code exceeds # characters
|
||||
--max-code-length=120
|
||||
|
||||
# -f =>
|
||||
--break-blocks
|
||||
|
||||
# -p => put a space around operators
|
||||
--pad-oper
|
||||
|
||||
# -xg => Insert space padding after commas
|
||||
--pad-comma
|
||||
|
||||
# -H => put a space after if/for/while
|
||||
pad-header
|
||||
|
||||
# -xb => Break one line headers (e.g. if/for/while)
|
||||
--break-one-line-headers
|
||||
|
||||
# -c => Converts tabs into spaces
|
||||
#--convert-tabs
|
||||
|
||||
# if you like one-liners, keep them
|
||||
#keep-one-line-statements
|
||||
|
||||
# -xV
|
||||
--attach-closing-while
|
||||
|
||||
#unpad-paren
|
||||
|
||||
# -xp
|
||||
remove-comment-prefix
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
for dir in . ; do
|
||||
find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \;
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user