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 |
@@ -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.15) or Platform.io version
|
||||
* `RP2040` Core Version (e.g. RP2040 core v1.8.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.15
|
||||
RP2040 core v1.8.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-74-generic #83-Ubuntu SMP Sat May 8 02:35:39 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
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,24 +2,27 @@
|
||||
|
||||
[](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)
|
||||
* [Releases v1.1.0](#releases-v110)
|
||||
* [Releases v1.0.1](#releases-v101)
|
||||
* [Initial Releases v1.0.0](#initial-releases-v100)
|
||||
* [Changelog](changelog.md)
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Installation](#installation)
|
||||
* [Use Arduino Library Manager](#use-arduino-library-manager)
|
||||
@@ -50,6 +53,7 @@
|
||||
* [ 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)
|
||||
@@ -60,7 +64,6 @@
|
||||
* [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)
|
||||
@@ -72,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
|
||||
@@ -80,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.
|
||||
|
||||
@@ -91,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.**
|
||||
|
||||
@@ -103,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)
|
||||
|
||||
---
|
||||
|
||||
@@ -129,31 +139,19 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
|
||||
---
|
||||
---
|
||||
|
||||
## Changelog
|
||||
|
||||
### 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)
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. [`Arduino IDE 1.8.15+` for Arduino](https://www.arduino.cc/en/Main/Software)
|
||||
2. [`Earle Philhower's arduino-pico core v1.8.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.
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
@@ -169,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) or [**RPI_PICO_TimerInterrupt** library](https://platformio.org/lib/show/12273/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)
|
||||
|
||||
|
||||
---
|
||||
@@ -225,24 +223,26 @@ With core after v1.4.0, this step is not necessary anymore thanks to the PR [Add
|
||||
|
||||
### 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.
|
||||
|
||||
---
|
||||
---
|
||||
@@ -256,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.
|
||||
@@ -278,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);
|
||||
@@ -288,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);
|
||||
|
||||
@@ -298,7 +298,7 @@ bool attachInterruptInterval(unsigned long interval, pico_timer_callback callbac
|
||||
|
||||
as follows
|
||||
|
||||
```
|
||||
```C++
|
||||
void TimerHandler()
|
||||
{
|
||||
// Doing something here inside ISR
|
||||
@@ -325,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)
|
||||
|
||||
@@ -335,7 +335,7 @@ bool attachInterrupt(float frequency, timer_callback callback);
|
||||
|
||||
as follows
|
||||
|
||||
```
|
||||
```C++
|
||||
void TimerHandler()
|
||||
{
|
||||
// Doing something here inside ISR
|
||||
@@ -367,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);
|
||||
|
||||
@@ -378,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();
|
||||
@@ -448,154 +448,15 @@ void setup()
|
||||
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)
|
||||
|
||||
```
|
||||
// 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
|
||||
https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/blob/b7d8f4b4b7eabec8c140fc55d88efb82939a6ad6/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino#L23-L168
|
||||
|
||||
#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();
|
||||
}
|
||||
```
|
||||
---
|
||||
---
|
||||
|
||||
@@ -609,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.1.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
|
||||
@@ -638,15 +495,15 @@ The following is the sample terminal output when running example [TimerInterrupt
|
||||
|
||||
```
|
||||
Starting TimerInterruptTest on RASPBERRY_PI_PICO
|
||||
RPi_Pico_TimerInterrupt v1.1.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
|
||||
@@ -682,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.1.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
|
||||
@@ -763,10 +620,10 @@ The following is the sample terminal output when running example [SwitchDebounce
|
||||
|
||||
```
|
||||
Starting SwitchDebounce on RASPBERRY_PI_PICO
|
||||
RPi_Pico_TimerInterrupt v1.1.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
|
||||
@@ -787,12 +644,11 @@ SW Pressed total time ms = 1181
|
||||
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 ADAFRUIT_FEATHER_RP2040
|
||||
RPi_Pico_TimerInterrupt v1.1.0
|
||||
Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO
|
||||
RPi_Pico_TimerInterrupt v1.3.1
|
||||
CPU Frequency = 125 MHz
|
||||
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 1 , _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 ITimer1 OK, millis() = 1701
|
||||
SimpleTimer : programmed 2000ms, current time ms : 11707, Delta ms : 11707
|
||||
@@ -811,12 +667,11 @@ Timer5s actual : 5000
|
||||
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 ADAFRUIT_ITSYBITSY_RP2040
|
||||
RPi_Pico_TimerInterrupt v1.1.0
|
||||
Starting ISR_16_Timers_Array_Complex on RASPBERRY_PI_PICO
|
||||
RPi_Pico_TimerInterrupt v1.3.1
|
||||
CPU Frequency = 125 MHz
|
||||
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
|
||||
[TISR] _count = 0 - 10000
|
||||
[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
|
||||
@@ -966,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.
|
||||
@@ -983,25 +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
|
||||
|
||||
### 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)
|
||||
|
||||
---
|
||||
---
|
||||
|
||||
@@ -1020,12 +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
|
||||
6. 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
|
||||
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
|
||||
|
||||
|
||||
---
|
||||
---
|
||||
@@ -1034,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>
|
||||
|
||||
|
||||
---
|
||||
|
||||
@@ -1050,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,21 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
@@ -41,6 +26,7 @@
|
||||
#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)
|
||||
@@ -61,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
|
||||
|
||||
@@ -18,21 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
/*
|
||||
@@ -54,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)
|
||||
@@ -79,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,21 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
@@ -41,6 +26,7 @@
|
||||
#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)
|
||||
@@ -58,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)
|
||||
@@ -75,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)
|
||||
|
||||
@@ -18,21 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
/*
|
||||
@@ -53,10 +38,11 @@
|
||||
#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
|
||||
@@ -66,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
|
||||
@@ -84,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
|
||||
|
||||
@@ -18,21 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Notes:
|
||||
@@ -58,7 +43,10 @@
|
||||
// _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
|
||||
@@ -79,7 +67,6 @@
|
||||
|
||||
volatile uint32_t startMillis = 0;
|
||||
|
||||
|
||||
// You can select RPI_PICO_Timer from 0 to 3
|
||||
// Init RPI_PICO_Timer
|
||||
RPI_PICO_Timer ITimer(1);
|
||||
@@ -93,6 +80,8 @@ RPI_PICO_ISR_Timer ISR_Timer;
|
||||
// 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;
|
||||
|
||||
|
||||
@@ -18,21 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
|
||||
@@ -41,10 +26,13 @@
|
||||
#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);
|
||||
@@ -72,6 +60,8 @@ volatile uint32_t previousMillis5s = 0;
|
||||
|
||||
bool TimerHandler(struct repeating_timer *t)
|
||||
{
|
||||
(void) t;
|
||||
|
||||
static bool toggle = false;
|
||||
static int timeRun = 0;
|
||||
|
||||
|
||||
@@ -18,21 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Notes:
|
||||
@@ -61,6 +46,7 @@
|
||||
#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
|
||||
@@ -83,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,21 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Notes:
|
||||
@@ -58,6 +43,7 @@
|
||||
#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
|
||||
@@ -78,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,21 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
/*
|
||||
Notes:
|
||||
@@ -52,16 +37,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 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;
|
||||
|
||||
@@ -84,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.1.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, arduino-pico",
|
||||
"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.1.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
|
||||
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
-76
@@ -1,37 +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.1.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
|
||||
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
|
||||
@@ -41,16 +45,20 @@
|
||||
|
||||
#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;
|
||||
@@ -59,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;
|
||||
@@ -69,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;
|
||||
}
|
||||
@@ -115,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;
|
||||
@@ -134,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;
|
||||
}
|
||||
@@ -158,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;
|
||||
}
|
||||
@@ -192,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();
|
||||
@@ -244,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();
|
||||
@@ -280,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;
|
||||
}
|
||||
@@ -297,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;
|
||||
}
|
||||
@@ -308,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;
|
||||
}
|
||||
@@ -319,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;
|
||||
}
|
||||
@@ -330,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;
|
||||
}
|
||||
@@ -349,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;
|
||||
}
|
||||
@@ -369,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;
|
||||
}
|
||||
@@ -379,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
-176
@@ -1,37 +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.1.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
|
||||
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
|
||||
@@ -39,159 +43,7 @@
|
||||
#ifndef ISR_TIMER_GENERIC_H
|
||||
#define ISR_TIMER_GENERIC_H
|
||||
|
||||
#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.1.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,19 +25,25 @@
|
||||
Based on BlynkTimer.h
|
||||
Author: Volodymyr Shymanskyy
|
||||
|
||||
Version: 1.1.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_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)
|
||||
@@ -48,10 +54,20 @@
|
||||
#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.1.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>
|
||||
@@ -75,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
|
||||
@@ -95,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();
|
||||
@@ -147,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();
|
||||
@@ -167,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();
|
||||
@@ -178,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
|
||||
@@ -191,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
|
||||
|
||||
|
||||
+125
-75
@@ -1,38 +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.1.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
|
||||
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
|
||||
@@ -40,51 +44,54 @@
|
||||
#ifndef RPI_PICO_TIMERINTERRUPT_H
|
||||
#define RPI_PICO_TIMERINTERRUPT_H
|
||||
|
||||
#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(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
|
||||
#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.1.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
|
||||
|
||||
#if defined(ARDUINO_ARCH_MBED)
|
||||
#warning Using MBED RP2040 platform
|
||||
#include "pico.h"
|
||||
//#include "pico/stdio.h"
|
||||
#include "pico/time.h"
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/uart.h"
|
||||
|
||||
#include "hardware/timer.h"
|
||||
#include "hardware/irq.h"
|
||||
#else
|
||||
#warning Using RP2040 platform
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/timer.h"
|
||||
#include "hardware/irq.h"
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#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
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -97,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,37 +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.1.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
|
||||
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
|
||||
@@ -39,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
|
||||
@@ -67,39 +75,42 @@ const char TISR_SP[] = " ";
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGERROR2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGERROR3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_PRINTLN(w); }
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGWARN2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGWARN3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_PRINTLN(w); }
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGINFO2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGINFO3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_PRINTLN(w); }
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGDEBUG2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGDEBUG3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_PRINTLN(w); }
|
||||
#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,385 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#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,196 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ISR_TIMER_GENERIC_H
|
||||
#define ISR_TIMER_GENERIC_H
|
||||
|
||||
#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.1.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,216 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef RPI_PICO_TIMERINTERRUPT_H
|
||||
#define RPI_PICO_TIMERINTERRUPT_H
|
||||
|
||||
#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.1.0"
|
||||
#endif
|
||||
|
||||
#ifndef TIMER_INTERRUPT_DEBUG
|
||||
#define TIMER_INTERRUPT_DEBUG 0
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_MBED)
|
||||
#warning Using MBED RP2040 platform
|
||||
#include "pico.h"
|
||||
//#include "pico/stdio.h"
|
||||
#include "pico/time.h"
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/uart.h"
|
||||
|
||||
#include "hardware/timer.h"
|
||||
#include "hardware/irq.h"
|
||||
#else
|
||||
#warning Using RP2040 platform
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/timer.h"
|
||||
#include "hardware/irq.h"
|
||||
#endif
|
||||
|
||||
#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,105 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#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
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
||||
const char TISR_MARK[] = "[TISR] ";
|
||||
const char TISR_SP[] = " ";
|
||||
|
||||
#define TISR_PRINT TISR_DBG_PORT.print
|
||||
#define TISR_PRINTLN TISR_DBG_PORT.println
|
||||
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGERROR2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGERROR3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_PRINTLN(w); }
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGWARN2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGWARN3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_PRINTLN(w); }
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGINFO2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGINFO3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_PRINTLN(w); }
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGDEBUG2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGDEBUG3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_PRINTLN(w); }
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
||||
#endif //TIMERINTERRUPT_GENERIC_DEBUG_H
|
||||
@@ -1,389 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ISR_TIMER_GENERIC_IMPL_H
|
||||
#define ISR_TIMER_GENERIC_IMPL_H
|
||||
|
||||
#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,216 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef RPI_PICO_TIMERINTERRUPT_H
|
||||
#define RPI_PICO_TIMERINTERRUPT_H
|
||||
|
||||
#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.1.0"
|
||||
#endif
|
||||
|
||||
#ifndef TIMER_INTERRUPT_DEBUG
|
||||
#define TIMER_INTERRUPT_DEBUG 0
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_MBED)
|
||||
#warning Using MBED RP2040 platform
|
||||
#include "pico.h"
|
||||
//#include "pico/stdio.h"
|
||||
#include "pico/time.h"
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/uart.h"
|
||||
|
||||
#include "hardware/timer.h"
|
||||
#include "hardware/irq.h"
|
||||
#else
|
||||
#warning Using RP2040 platform
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/timer.h"
|
||||
#include "hardware/irq.h"
|
||||
#endif
|
||||
|
||||
#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,105 +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.1.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.
|
||||
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
|
||||
*****************************************************************************************************************************/
|
||||
|
||||
#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
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
||||
const char TISR_MARK[] = "[TISR] ";
|
||||
const char TISR_SP[] = " ";
|
||||
|
||||
#define TISR_PRINT TISR_DBG_PORT.print
|
||||
#define TISR_PRINTLN TISR_DBG_PORT.println
|
||||
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGERROR2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGERROR3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_PRINTLN(w); }
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGWARN2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGWARN3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_PRINTLN(w); }
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGINFO2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGINFO3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_PRINTLN(w); }
|
||||
|
||||
//////////////////////////////////////////
|
||||
|
||||
#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_PRINT_SP; TISR_PRINTLN(y); }
|
||||
#define TISR_LOGDEBUG2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINTLN(z); }
|
||||
#define TISR_LOGDEBUG3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_PRINT_SP; TISR_PRINT(y); TISR_PRINT_SP; TISR_PRINT(z); TISR_PRINT_SP; TISR_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