From 712c22a676b6447c300373fc406586e0a4e420d7 Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Thu, 10 Jun 2021 23:26:48 -0400 Subject: [PATCH] v1.1.0 to add support to new boards ### 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 --- CONTRIBUTING.md | 10 +- README.md | 227 ++++++++++- .../Argument_Complex/Argument_Complex.ino | 12 +- examples/Argument_None/Argument_None.ino | 6 +- examples/Argument_Simple/Argument_Simple.ino | 10 +- examples/Change_Interval/Change_Interval.ino | 7 +- .../ISR_16_Timers_Array_Complex.ino | 379 ++++++++++++++++++ .../ISR_Timers_Array_Simple.ino | 12 +- examples/RPM_Measure/RPM_Measure.ino | 9 +- examples/SwitchDebounce/SwitchDebounce.ino | 7 +- .../TimerInterruptTest/TimerInterruptTest.ino | 7 +- library.json | 4 +- library.properties | 4 +- src/RPi_Pico_ISR_Timer-Impl.h | 7 +- src/RPi_Pico_ISR_Timer.h | 14 +- src/RPi_Pico_TimerInterrupt.h | 35 +- src/TimerInterrupt_Generic_Debug.h | 65 ++- src_cpp/RPi_Pico_ISR_Timer.cpp | 3 +- src_cpp/RPi_Pico_ISR_Timer.h | 14 +- src_cpp/RPi_Pico_TimerInterrupt.h | 35 +- src_cpp/TimerInterrupt_Generic_Debug.h | 65 ++- src_h/RPi_Pico_ISR_Timer-Impl.h | 7 +- src_h/RPi_Pico_ISR_Timer.h | 14 +- src_h/RPi_Pico_TimerInterrupt.h | 35 +- src_h/TimerInterrupt_Generic_Debug.h | 65 ++- 25 files changed, 866 insertions(+), 187 deletions(-) create mode 100644 examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b0a2d5c..226eea8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,8 +14,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p Please ensure to specify the following: -* Arduino IDE version (e.g. 1.8.13) or Platform.io version -* `RP2040` Core Version (e.g. RP2040 core v1.4.0) +* 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.) * Contextual information (e.g. what you were trying to achieve) * Simplest possible steps to reproduce @@ -27,11 +27,11 @@ Please ensure to specify the following: ### Example ``` -Arduino IDE version: 1.8.13 -RP2040 core v1.4.0 +Arduino IDE version: 1.8.15 +RP2040 core v1.8.1 RASPBERRY_PI_PICO Module OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux +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 Context: I encountered a crash while using TimerInterrupt. diff --git a/README.md b/README.md index 6124a8b..c0499e9 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ * [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) * [Prerequisites](#prerequisites) @@ -44,16 +45,19 @@ * [ 2. Argument_None](examples/Argument_None) * [ 3. Argument_Simple](examples/Argument_Simple) * [ 4. Change_Interval](examples/Change_Interval). - * [ 5. ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple) - * [ 6. RPM_Measure](examples/RPM_Measure) - * [ 7. SwitchDebounce](examples/SwitchDebounce) - * [ 8. TimerInterruptTest](examples/TimerInterruptTest) + * [ 5. ISR_Timers_Array_Complex](examples/ISR_Timers_Array_Complex) + * [ 6. ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple) + * [ 7. RPM_Measure](examples/RPM_Measure) + * [ 8. SwitchDebounce](examples/SwitchDebounce) + * [ 9. TimerInterruptTest](examples/TimerInterruptTest) * [Example ISR_Timers_Array_Simple](#example-isr_timers_array_simple) * [Debug Terminal Output Samples](#debug-terminal-output-samples) * [1. ISR_Timers_Array_Simple on RASPBERRY_PI_PICO](#1-isr_timers_array_simple-on-raspberry_pi_pico) * [2. TimerInterruptTest on RASPBERRY_PI_PICO](#2-timerinterrupttest-on-raspberry_pi_pico) * [3. Change_Interval on RASPBERRY_PI_PICO](#3-change_interval-on-raspberry_pi_pico) * [4. SwitchDebounce on RASPBERRY_PI_PICO](#4-switchdebounce-on-raspberry_pi_pico) + * [5. ISR_Timers_Array_Simple on ADAFRUIT_FEATHER_RP2040](#5-isr_timers_array_simple-on-adafruit_feather_rp2040) + * [6. ISR_Timers_Array_Complex on ADAFRUIT_ITSYBITSY_RP2040](#6-isr_timers_array_complex-on-adafruit_itsybitsy_rp2040) * [Debug](#debug) * [Troubleshooting](#troubleshooting) * [Releases](#releases) @@ -127,6 +131,12 @@ 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 @@ -141,8 +151,8 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine), ## Prerequisites -1. [`Arduino IDE 1.8.13+` for Arduino](https://www.arduino.cc/en/Main/Software) -2. [`Earle Philhower's arduino-pico core v1.4.0+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest) +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. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest) --- --- @@ -431,10 +441,11 @@ void setup() 2. [Argument_None](examples/Argument_None) 3. [Argument_Simple](examples/Argument_Simple) 4. [Change_Interval](examples/Change_Interval) - 5. [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple) - 6. [RPM_Measure](examples/RPM_Measure) - 7. [SwitchDebounce](examples/SwitchDebounce) - 8. [TimerInterruptTest](examples/TimerInterruptTest) + 5. [ISR_Timers_Array_Complex](examples/ISR_Timers_Array_Complex) + 6. [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple) + 7. [RPM_Measure](examples/RPM_Measure) + 8. [SwitchDebounce](examples/SwitchDebounce) + 9. [TimerInterruptTest](examples/TimerInterruptTest) --- --- @@ -442,10 +453,6 @@ void setup() ### Example [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple) ``` -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#endif - // 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. @@ -600,7 +607,7 @@ While software timer, **programmed for 2s, is activated after more than 10.000s ``` Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO -RPi_Pico_TimerInterrupt v1.0.1 +RPi_Pico_TimerInterrupt v1.1.0 CPU Frequency = 125 MHz [TISR] RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00 [TISR] _count = 0 - 1000 @@ -629,7 +636,7 @@ The following is the sample terminal output when running example [TimerInterrupt ``` Starting TimerInterruptTest on RASPBERRY_PI_PICO -RPi_Pico_TimerInterrupt v1.0.1 +RPi_Pico_TimerInterrupt v1.1.0 CPU Frequency = 125 MHz [TISR] RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00 [TISR] _count = 0 - 1000000 @@ -673,7 +680,7 @@ The following is the sample terminal output when running example [Change_Interva ``` Starting Change_Interval on RASPBERRY_PI_PICO -RPi_Pico_TimerInterrupt v1.0.1 +RPi_Pico_TimerInterrupt v1.1.0 CPU Frequency = 125 MHz [TISR] RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00 [TISR] _count = 0 - 2000000 @@ -754,7 +761,7 @@ The following is the sample terminal output when running example [SwitchDebounce ``` Starting SwitchDebounce on RASPBERRY_PI_PICO -RPi_Pico_TimerInterrupt v1.0.1 +RPi_Pico_TimerInterrupt v1.1.0 CPU Frequency = 125 MHz [TISR] RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00 [TISR] _count = 0 - 20000 @@ -771,6 +778,183 @@ SW Released, from millis() = 80238 SW Pressed total time ms = 1181 ``` +--- + +### 5. ISR_Timers_Array_Simple on ADAFRUIT_FEATHER_RP2040 + +The following is the sample terminal output when running example [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple) on ADAFRUIT_FEATHER_RP2040 + +``` + +Starting ISR_Timers_Array_Simple on ADAFRUIT_FEATHER_RP2040 +RPi_Pico_TimerInterrupt v1.1.0 +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() = 1701 +SimpleTimer : programmed 2000ms, current time ms : 11707, Delta ms : 11707 +Timer2s actual : 2000 +Timer5s actual : 5000 +SimpleTimer : programmed 2000ms, current time ms : 21707, Delta ms : 10000 +Timer2s actual : 2000 +Timer5s actual : 5000 +SimpleTimer : programmed 2000ms, current time ms : 31708, Delta ms : 10001 +Timer2s actual : 2000 +Timer5s actual : 5000 +``` + +### 6. ISR_16_Timers_Array_Complex on ADAFRUIT_ITSYBITSY_RP2040 + +The following is the sample terminal output when running example [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex) on ADAFRUIT_ITSYBITSY_RP2040 + +``` + +Starting ISR_16_Timers_Array_Complex on ADAFRUIT_ITSYBITSY_RP2040 +RPi_Pico_TimerInterrupt v1.1.0 +CPU Frequency = 125 MHz +[TISR] RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00 +[TISR] _count = 0 - 10000 +[TISR] add_repeating_timer_us = 10000 +Starting ITimer OK, millis() = 1797 +SimpleTimer : 2, ms : 11798, Dms : 10001 +Timer : 0, programmed : 5000, actual : 5005 +Timer : 1, programmed : 10000, actual : 0 +Timer : 2, programmed : 15000, actual : 0 +Timer : 3, programmed : 20000, actual : 0 +Timer : 4, programmed : 25000, actual : 0 +Timer : 5, programmed : 30000, actual : 0 +Timer : 6, programmed : 35000, actual : 0 +Timer : 7, programmed : 40000, actual : 0 +Timer : 8, programmed : 45000, actual : 0 +Timer : 9, programmed : 50000, actual : 0 +Timer : 10, programmed : 55000, actual : 0 +Timer : 11, programmed : 60000, actual : 0 +Timer : 12, programmed : 65000, actual : 0 +Timer : 13, programmed : 70000, actual : 0 +Timer : 14, programmed : 75000, actual : 0 +Timer : 15, programmed : 80000, actual : 0 +SimpleTimer : 2, ms : 21800, Dms : 10002 +Timer : 0, programmed : 5000, actual : 4995 +Timer : 1, programmed : 10000, actual : 10010 +Timer : 2, programmed : 15000, actual : 15005 +Timer : 3, programmed : 20000, actual : 0 +Timer : 4, programmed : 25000, actual : 0 +Timer : 5, programmed : 30000, actual : 0 +Timer : 6, programmed : 35000, actual : 0 +Timer : 7, programmed : 40000, actual : 0 +Timer : 8, programmed : 45000, actual : 0 +Timer : 9, programmed : 50000, actual : 0 +Timer : 10, programmed : 55000, actual : 0 +Timer : 11, programmed : 60000, actual : 0 +Timer : 12, programmed : 65000, actual : 0 +Timer : 13, programmed : 70000, actual : 0 +Timer : 14, programmed : 75000, actual : 0 +Timer : 15, programmed : 80000, actual : 0 +SimpleTimer : 2, ms : 31802, Dms : 10002 +Timer : 0, programmed : 5000, actual : 4995 +Timer : 1, programmed : 10000, actual : 10000 +Timer : 2, programmed : 15000, actual : 15005 +Timer : 3, programmed : 20000, actual : 20010 +Timer : 4, programmed : 25000, actual : 25005 +Timer : 5, programmed : 30000, actual : 0 +Timer : 6, programmed : 35000, actual : 0 +Timer : 7, programmed : 40000, actual : 0 +Timer : 8, programmed : 45000, actual : 0 +Timer : 9, programmed : 50000, actual : 0 +Timer : 10, programmed : 55000, actual : 0 +Timer : 11, programmed : 60000, actual : 0 +Timer : 12, programmed : 65000, actual : 0 +Timer : 13, programmed : 70000, actual : 0 +Timer : 14, programmed : 75000, actual : 0 +Timer : 15, programmed : 80000, actual : 0 +SimpleTimer : 2, ms : 41804, Dms : 10002 +Timer : 0, programmed : 5000, actual : 4995 +Timer : 1, programmed : 10000, actual : 10000 +Timer : 2, programmed : 15000, actual : 15005 +Timer : 3, programmed : 20000, actual : 20010 +Timer : 4, programmed : 25000, actual : 25005 +Timer : 5, programmed : 30000, actual : 30010 +Timer : 6, programmed : 35000, actual : 35005 +Timer : 7, programmed : 40000, actual : 0 +Timer : 8, programmed : 45000, actual : 0 +Timer : 9, programmed : 50000, actual : 0 +Timer : 10, programmed : 55000, actual : 0 +Timer : 11, programmed : 60000, actual : 0 +Timer : 12, programmed : 65000, actual : 0 +Timer : 13, programmed : 70000, actual : 0 +Timer : 14, programmed : 75000, actual : 0 +Timer : 15, programmed : 80000, actual : 0 +SimpleTimer : 2, ms : 51807, Dms : 10003 +Timer : 0, programmed : 5000, actual : 4995 +Timer : 1, programmed : 10000, actual : 10000 +Timer : 2, programmed : 15000, actual : 14995 +Timer : 3, programmed : 20000, actual : 20000 +Timer : 4, programmed : 25000, actual : 25005 +Timer : 5, programmed : 30000, actual : 30010 +Timer : 6, programmed : 35000, actual : 35005 +Timer : 7, programmed : 40000, actual : 40010 +Timer : 8, programmed : 45000, actual : 45005 +Timer : 9, programmed : 50000, actual : 50010 +Timer : 10, programmed : 55000, actual : 0 +Timer : 11, programmed : 60000, actual : 0 +Timer : 12, programmed : 65000, actual : 0 +Timer : 13, programmed : 70000, actual : 0 +Timer : 14, programmed : 75000, actual : 0 +Timer : 15, programmed : 80000, actual : 0 +SimpleTimer : 2, ms : 61809, Dms : 10002 +Timer : 0, programmed : 5000, actual : 5005 +Timer : 1, programmed : 10000, actual : 10000 +Timer : 2, programmed : 15000, actual : 15005 +Timer : 3, programmed : 20000, actual : 20000 +Timer : 4, programmed : 25000, actual : 25005 +Timer : 5, programmed : 30000, actual : 30000 +Timer : 6, programmed : 35000, actual : 35005 +Timer : 7, programmed : 40000, actual : 40010 +Timer : 8, programmed : 45000, actual : 45005 +Timer : 9, programmed : 50000, actual : 50010 +Timer : 10, programmed : 55000, actual : 55005 +Timer : 11, programmed : 60000, actual : 60010 +Timer : 12, programmed : 65000, actual : 0 +Timer : 13, programmed : 70000, actual : 0 +Timer : 14, programmed : 75000, actual : 0 +Timer : 15, programmed : 80000, actual : 0 +SimpleTimer : 2, ms : 71812, Dms : 10003 +Timer : 0, programmed : 5000, actual : 5005 +Timer : 1, programmed : 10000, actual : 10000 +Timer : 2, programmed : 15000, actual : 15005 +Timer : 3, programmed : 20000, actual : 20000 +Timer : 4, programmed : 25000, actual : 25005 +Timer : 5, programmed : 30000, actual : 30000 +Timer : 6, programmed : 35000, actual : 35005 +Timer : 7, programmed : 40000, actual : 40010 +Timer : 8, programmed : 45000, actual : 45005 +Timer : 9, programmed : 50000, actual : 50010 +Timer : 10, programmed : 55000, actual : 55005 +Timer : 11, programmed : 60000, actual : 60010 +Timer : 12, programmed : 65000, actual : 65005 +Timer : 13, programmed : 70000, actual : 70010 +Timer : 14, programmed : 75000, actual : 0 +Timer : 15, programmed : 80000, actual : 0 +SimpleTimer : 2, ms : 81814, Dms : 10002 +Timer : 0, programmed : 5000, actual : 5005 +Timer : 1, programmed : 10000, actual : 10000 +Timer : 2, programmed : 15000, actual : 14995 +Timer : 3, programmed : 20000, actual : 20000 +Timer : 4, programmed : 25000, actual : 24995 +Timer : 5, programmed : 30000, actual : 30000 +Timer : 6, programmed : 35000, actual : 35005 +Timer : 7, programmed : 40000, actual : 40000 +Timer : 8, programmed : 45000, actual : 45005 +Timer : 9, programmed : 50000, actual : 50010 +Timer : 10, programmed : 55000, actual : 55005 +Timer : 11, programmed : 60000, actual : 60010 +Timer : 12, programmed : 65000, actual : 65005 +Timer : 13, programmed : 70000, actual : 70010 +Timer : 14, programmed : 75000, actual : 75005 +Timer : 15, programmed : 80000, actual : 80010 +``` + --- --- @@ -802,6 +986,12 @@ Sometimes, the library will only work if you update the board core to the latest ## 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 @@ -833,6 +1023,7 @@ Submit issues to: [RPI_PICO_TimerInterrupt issues](https://github.com/khoih-prog 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 --- --- diff --git a/examples/Argument_Complex/Argument_Complex.ino b/examples/Argument_Complex/Argument_Complex.ino index 68d1929..e1f3d2a 100644 --- a/examples/Argument_Complex/Argument_Complex.ino +++ b/examples/Argument_Complex/Argument_Complex.ino @@ -26,18 +26,15 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 *****************************************************************************************************************************/ -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#endif - // These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h" // _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4 // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. @@ -99,10 +96,9 @@ void setup() Serial.begin(115200); while (!Serial); - Serial.print(F("\nStarting Argument_Complex on ")); - Serial.println(BOARD_NAME); + Serial.print(F("\nStarting Argument_Complex on ")); Serial.println(BOARD_NAME); Serial.println(RPI_PICO_TIMER_INTERRUPT_VERSION); - Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz")); + //Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz")); // Interval in microsecs if (ITimer1.attachInterruptInterval(TIMER_INTERVAL_MS * 1000, TimerHandler)) diff --git a/examples/Argument_None/Argument_None.ino b/examples/Argument_None/Argument_None.ino index 057b06d..db9b9ac 100644 --- a/examples/Argument_None/Argument_None.ino +++ b/examples/Argument_None/Argument_None.ino @@ -26,12 +26,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 *****************************************************************************************************************************/ /* @@ -46,9 +47,6 @@ or the entire sequence of your code which accesses the data. */ -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#endif // These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h" // _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4 diff --git a/examples/Argument_Simple/Argument_Simple.ino b/examples/Argument_Simple/Argument_Simple.ino index 6e0b01d..3ed18e2 100644 --- a/examples/Argument_Simple/Argument_Simple.ino +++ b/examples/Argument_Simple/Argument_Simple.ino @@ -26,18 +26,15 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 *****************************************************************************************************************************/ -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#endif - // These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h" // _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4 // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. @@ -100,8 +97,7 @@ void setup() Serial.begin(115200); while (!Serial); - Serial.print(F("\nStarting Argument_Simple on ")); - Serial.println(BOARD_NAME); + Serial.print(F("\nStarting Argument_Simple on ")); Serial.println(BOARD_NAME); Serial.println(RPI_PICO_TIMER_INTERRUPT_VERSION); Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz")); diff --git a/examples/Change_Interval/Change_Interval.ino b/examples/Change_Interval/Change_Interval.ino index c37676b..2280b84 100644 --- a/examples/Change_Interval/Change_Interval.ino +++ b/examples/Change_Interval/Change_Interval.ino @@ -26,12 +26,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 *****************************************************************************************************************************/ /* @@ -46,10 +47,6 @@ or the entire sequence of your code which accesses the data. */ -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#endif - // These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h" // _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4 // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. diff --git a/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino b/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino new file mode 100644 index 0000000..e34d8fb --- /dev/null +++ b/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino @@ -0,0 +1,379 @@ +/**************************************************************************************************************************** + ISR_16_Timers_Array.ino + RPi_Pico_ISR_Timer-Impl.h + For RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040. + Written by Khoi Hoang + + Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt + Licensed under MIT license + + The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates + interrupts based on this timebase. It supports the following features: + • A single 64-bit counter, incrementing once per microsecond + • This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus. + • Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3 + + Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by + unsigned long miliseconds), you just consume only one RPI_PICO timer and avoid conflicting with other cores' tasks. + The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers + Therefore, their executions are not blocked by bad-behaving functions / tasks. + This important feature is absolutely necessary for mission-critical tasks. + + 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: + Special design is necessary to share data between interrupt code and the rest of your program. + Variables usually need to be "volatile" types. Volatile tells the compiler to avoid optimizations that assume + variable can not spontaneously change. Because your function may change variables while your program is using them, + the compiler needs this hint. But volatile alone is often not enough. + When accessing shared variables, usually interrupts must be disabled. Even with volatile, + if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly. + If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled + or the entire sequence of your code which accesses the data. + + This example will demonstrate the nearly perfect accuracy compared to software timers by printing the actual elapsed millisecs. + Being ISR-based timers, their executions are not blocked by bad-behaving functions / tasks, such as connecting to WiFi, Internet + and Blynk services. You can also have many (up to 16) timers to use. + This non-being-blocked important feature is absolutely necessary for mission-critical tasks. + You'll see blynkTimer is blocked while connecting to WiFi / Internet / Blynk, and elapsed time is very unaccurate + In this super simple example, you don't see much different after Blynk is connected, because of no competing task is + written +*/ + +// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h" +// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4 +#define _TIMERINTERRUPT_LOGLEVEL_ 4 + +#include "RPi_Pico_TimerInterrupt.h" +#include "RPi_Pico_ISR_Timer.h" + +#include // https://github.com/jfturcot/SimpleTimer + +#ifndef LED_BUILTIN + #define LED_BUILTIN 25 +#endif + +#ifndef LED_BLUE + #define LED_BLUE 10 +#endif + +#ifndef LED_RED + #define LED_RED 11 +#endif + +#define HW_TIMER_INTERVAL_US 10000L + +volatile uint32_t startMillis = 0; + + +// You can select RPI_PICO_Timer from 0 to 3 +// Init RPI_PICO_Timer +RPI_PICO_Timer ITimer(1); + +// Init RPI_PICO_ISR_Timer +// Each RPI_PICO_ISR_Timer can service 16 different ISR-based timers +RPI_PICO_ISR_Timer ISR_Timer; + +#define LED_TOGGLE_INTERVAL_MS 2000L + +// Never use Serial.print inside this ISR. Will hang the system +bool TimerHandler(struct repeating_timer *t) +{ + static bool toggle = false; + static int timeRun = 0; + + ISR_Timer.run(); + + // Toggle LED every LED_TOGGLE_INTERVAL_MS = 2000ms = 2s + if (++timeRun == ((LED_TOGGLE_INTERVAL_MS * 1000) / HW_TIMER_INTERVAL_US) ) + { + timeRun = 0; + + //timer interrupt toggles pin LED_BUILTIN + digitalWrite(LED_BUILTIN, toggle); + toggle = !toggle; + } + + return true; +} + +///////////////////////////////////////////////// + +#define NUMBER_ISR_TIMERS 16 + +typedef void (*irqCallback) (); + +///////////////////////////////////////////////// + +#define USE_COMPLEX_STRUCT true + +#if USE_COMPLEX_STRUCT + +typedef struct +{ + irqCallback irqCallbackFunc; + uint32_t TimerInterval; + unsigned long deltaMillis; + unsigned long previousMillis; +} ISRTimerData; + +// In RP2040, avoid doing something fancy in ISR, for example Serial.print() +// The pure simple Serial.prints here are just for demonstration and testing. Must be eliminate in working environment +// Or you can get this run-time error / crash + +void doingSomething(int index); + +#else + +volatile unsigned long deltaMillis [NUMBER_ISR_TIMERS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +volatile unsigned long previousMillis [NUMBER_ISR_TIMERS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +// You can assign any interval for any timer here, in milliseconds +uint32_t TimerInterval[NUMBER_ISR_TIMERS] = +{ + 5000L, 10000L, 15000L, 20000L, 25000L, 30000L, 35000L, 40000L, + 45000L, 50000L, 55000L, 60000L, 65000L, 70000L, 75000L, 80000L +}; + +void doingSomething(int index) +{ + unsigned long currentMillis = millis(); + + deltaMillis[index] = currentMillis - previousMillis[index]; + previousMillis[index] = currentMillis; +} + +#endif + +//////////////////////////////////// +// Shared +//////////////////////////////////// + +void doingSomething0() +{ + doingSomething(0); +} + +void doingSomething1() +{ + doingSomething(1); +} + +void doingSomething2() +{ + doingSomething(2); +} + +void doingSomething3() +{ + doingSomething(3); +} + +void doingSomething4() +{ + doingSomething(4); +} + +void doingSomething5() +{ + doingSomething(5); +} + +void doingSomething6() +{ + doingSomething(6); +} + +void doingSomething7() +{ + doingSomething(7); +} + +void doingSomething8() +{ + doingSomething(8); +} + +void doingSomething9() +{ + doingSomething(9); +} + +void doingSomething10() +{ + doingSomething(10); +} + +void doingSomething11() +{ + doingSomething(11); +} + +void doingSomething12() +{ + doingSomething(12); +} + +void doingSomething13() +{ + doingSomething(13); +} + +void doingSomething14() +{ + doingSomething(14); +} + +void doingSomething15() +{ + doingSomething(15); +} + +#if USE_COMPLEX_STRUCT + +ISRTimerData curISRTimerData[NUMBER_ISR_TIMERS] = +{ + //irqCallbackFunc, TimerInterval, deltaMillis, previousMillis + { doingSomething0, 5000L, 0, 0 }, + { doingSomething1, 10000L, 0, 0 }, + { doingSomething2, 15000L, 0, 0 }, + { doingSomething3, 20000L, 0, 0 }, + { doingSomething4, 25000L, 0, 0 }, + { doingSomething5, 30000L, 0, 0 }, + { doingSomething6, 35000L, 0, 0 }, + { doingSomething7, 40000L, 0, 0 }, + { doingSomething8, 45000L, 0, 0 }, + { doingSomething9, 50000L, 0, 0 }, + { doingSomething10, 55000L, 0, 0 }, + { doingSomething11, 60000L, 0, 0 }, + { doingSomething12, 65000L, 0, 0 }, + { doingSomething13, 70000L, 0, 0 }, + { doingSomething14, 75000L, 0, 0 }, + { doingSomething15, 80000L, 0, 0 } +}; + +void doingSomething(int index) +{ + unsigned long currentMillis = millis(); + + curISRTimerData[index].deltaMillis = currentMillis - curISRTimerData[index].previousMillis; + curISRTimerData[index].previousMillis = currentMillis; +} + +#else + +irqCallback irqCallbackFunc[NUMBER_ISR_TIMERS] = +{ + doingSomething0, doingSomething1, doingSomething2, doingSomething3, + doingSomething4, doingSomething5, doingSomething6, doingSomething7, + doingSomething8, doingSomething9, doingSomething10, doingSomething11, + doingSomething12, doingSomething13, doingSomething14, doingSomething15 +}; + +#endif +/////////////////////////////////////////// + +#define SIMPLE_TIMER_MS 2000L + +// Init SimpleTimer +SimpleTimer simpleTimer; + +// Here is software Timer, you can do somewhat fancy stuffs without many issues. +// But always avoid +// 1. Long delay() it just doing nothing and pain-without-gain wasting CPU power.Plan and design your code / strategy ahead +// 2. Very long "do", "while", "for" loops without predetermined exit time. +void simpleTimerDoingSomething2s() +{ + static unsigned long previousMillis = startMillis; + + unsigned long currMillis = millis(); + + Serial.print(F("SimpleTimer : ")); Serial.print(SIMPLE_TIMER_MS / 1000); + Serial.print(F(", ms : ")); Serial.print(currMillis); + Serial.print(F(", Dms : ")); Serial.println(currMillis - previousMillis); + + for (uint16_t i = 0; i < NUMBER_ISR_TIMERS; i++) + { +#if USE_COMPLEX_STRUCT + Serial.print(F("Timer : ")); Serial.print(i); + Serial.print(F(", programmed : ")); Serial.print(curISRTimerData[i].TimerInterval); + Serial.print(F(", actual : ")); Serial.println(curISRTimerData[i].deltaMillis); +#else + Serial.print(F("Timer : ")); Serial.print(i); + Serial.print(F(", programmed : ")); Serial.print(TimerInterval[i]); + Serial.print(F(", actual : ")); Serial.println(deltaMillis[i]); +#endif + } + + previousMillis = currMillis; +} + +void setup() +{ + pinMode(LED_BUILTIN, OUTPUT); + + Serial.begin(115200); + while (!Serial); + + delay(100); + + Serial.print(F("\nStarting ISR_16_Timers_Array_Complex on ")); Serial.println(BOARD_NAME); + Serial.println(RPI_PICO_TIMER_INTERRUPT_VERSION); + Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz")); + + // Interval in microsecs + if (ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_US, TimerHandler)) + { + startMillis = millis(); + Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(startMillis); + } + else + Serial.println(F("Can't set ITimer. Select another freq. or timer")); + + startMillis = millis(); + + // Just to demonstrate, don't use too many ISR Timers if not absolutely necessary + // You can use up to 16 timer for each ISR_Timer + for (uint16_t i = 0; i < NUMBER_ISR_TIMERS; i++) + { +#if USE_COMPLEX_STRUCT + curISRTimerData[i].previousMillis = startMillis; + ISR_Timer.setInterval(curISRTimerData[i].TimerInterval, curISRTimerData[i].irqCallbackFunc); +#else + previousMillis[i] = millis(); + ISR_Timer.setInterval(TimerInterval[i], irqCallbackFunc[i]); +#endif + } + + // You need this timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary. + simpleTimer.setInterval(SIMPLE_TIMER_MS, simpleTimerDoingSomething2s); +} + +#define BLOCKING_TIME_MS 10000L + +void loop() +{ + // This unadvised blocking task is used to demonstrate the blocking effects onto the execution and accuracy to Software timer + // You see the time elapse of ISR_Timer still accurate, whereas very unaccurate for Software Timer + // The time elapse for 2000ms software timer now becomes 3000ms (BLOCKING_TIME_MS) + // While that of ISR_Timer is still prefect. + delay(BLOCKING_TIME_MS); + + // You need this Software timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary + // You don't need to and never call ISR_Timer.run() here in the loop(). It's already handled by ISR timer. + simpleTimer.run(); +} diff --git a/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino b/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino index 8a9716e..9721607 100644 --- a/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino +++ b/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino @@ -26,18 +26,15 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 *****************************************************************************************************************************/ -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#endif - // These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h" // _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4 // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. @@ -145,8 +142,7 @@ void setup() Serial.begin(115200); while (!Serial); - Serial.print(F("\nStarting ISR_Timers_Array_Simple on ")); - Serial.println(BOARD_NAME); + Serial.print(F("\nStarting ISR_Timers_Array_Simple on ")); Serial.println(BOARD_NAME); Serial.println(RPI_PICO_TIMER_INTERRUPT_VERSION); Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz")); @@ -157,6 +153,8 @@ void setup() else Serial.println(F("Can't set ITimer1. Select another freq. or timer")); + previousMillis5s = previousMillis2s = millis(); + ISR_timer.setInterval(2000L, doingSomething2s); ISR_timer.setInterval(5000L, doingSomething5s); diff --git a/examples/RPM_Measure/RPM_Measure.ino b/examples/RPM_Measure/RPM_Measure.ino index 22c2a87..28dce6e 100644 --- a/examples/RPM_Measure/RPM_Measure.ino +++ b/examples/RPM_Measure/RPM_Measure.ino @@ -26,12 +26,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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.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: @@ -54,10 +55,6 @@ You can also use interrupt to detect whenever the SW is active, set a flag then use timer to count the time between active state */ -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#endif - // These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h" // _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4 // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. diff --git a/examples/SwitchDebounce/SwitchDebounce.ino b/examples/SwitchDebounce/SwitchDebounce.ino index 252e9de..8fd72f8 100644 --- a/examples/SwitchDebounce/SwitchDebounce.ino +++ b/examples/SwitchDebounce/SwitchDebounce.ino @@ -26,12 +26,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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: @@ -51,10 +52,6 @@ SW is released. */ -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#endif - // These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h" // _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4 // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. diff --git a/examples/TimerInterruptTest/TimerInterruptTest.ino b/examples/TimerInterruptTest/TimerInterruptTest.ino index 77fe111..81bc4fd 100644 --- a/examples/TimerInterruptTest/TimerInterruptTest.ino +++ b/examples/TimerInterruptTest/TimerInterruptTest.ino @@ -26,12 +26,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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: @@ -45,10 +46,6 @@ or the entire sequence of your code which accesses the data. */ -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#endif - // These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h" // _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4 // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. diff --git a/library.json b/library.json index 83615d6..0fc17a7 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "name": "RPI_PICO_TimerInterrupt", - "version": "1.0.1", - "keywords": "timing, device, control, timer, interrupt, hardware, isr, isr-based, hardware-timer, mission-critical, accuracy, precise, non-blocking, raspberry-pico, rpi-pico, pico, rp2040", + "version": "1.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", "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": { diff --git a/library.properties b/library.properties index 11323c0..88a244a 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=RPI_PICO_TimerInterrupt -version=1.0.1 +version=1.1.0 author=Khoi Hoang maintainer=Khoi Hoang sentence=This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO paragraph=These RPI_PICO_TimerInterrupt Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's mandatory if you need to measure some data requiring better accuracy. It now supports 16 ISR-based Timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based Timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. -category=Timing, Control, Device, Time, Timer, rp2040, raspberry-pico +category=Timing, Control, Device, Time, Timer url=https://github.com/khoih-prog/RPI_PICO_TimerInterrupt architectures=rp2040 repository=https://github.com/khoih-prog/RPI_PICO_TimerInterrupt diff --git a/src/RPi_Pico_ISR_Timer-Impl.h b/src/RPi_Pico_ISR_Timer-Impl.h index 41a3629..91285ec 100644 --- a/src/RPi_Pico_ISR_Timer-Impl.h +++ b/src/RPi_Pico_ISR_Timer-Impl.h @@ -25,12 +25,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 @@ -38,10 +39,6 @@ #ifndef ISR_TIMER_GENERIC_IMPL_H #define ISR_TIMER_GENERIC_IMPL_H -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#endif - #include RPI_PICO_ISR_Timer::RPI_PICO_ISR_Timer() diff --git a/src/RPi_Pico_ISR_Timer.h b/src/RPi_Pico_ISR_Timer.h index 5fee42f..6014527 100644 --- a/src/RPi_Pico_ISR_Timer.h +++ b/src/RPi_Pico_ISR_Timer.h @@ -25,12 +25,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 @@ -38,12 +39,17 @@ #ifndef ISR_TIMER_GENERIC_H #define ISR_TIMER_GENERIC_H -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED) + #if defined(USING_RPI_PICO_TIMER_INTERRUPT) + #undef USING_RPI_PICO_TIMER_INTERRUPT + #endif + #define USING_RPI_PICO_TIMER_INTERRUPT true +#else + #error This code is intended to run on the non-mbed RP2040 arduino-pico platform! Please check your Tools->Board setting. #endif #ifndef RPI_PICO_TIMER_INTERRUPT_VERSION - #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.1" + #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.1.0" #endif #include "TimerInterrupt_Generic_Debug.h" diff --git a/src/RPi_Pico_TimerInterrupt.h b/src/RPi_Pico_TimerInterrupt.h index 3ae9fb9..c1afd92 100644 --- a/src/RPi_Pico_TimerInterrupt.h +++ b/src/RPi_Pico_TimerInterrupt.h @@ -26,12 +26,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 @@ -39,24 +40,40 @@ #ifndef RPI_PICO_TIMERINTERRUPT_H #define RPI_PICO_TIMERINTERRUPT_H -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#else +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED) + #if defined(USING_RPI_PICO_TIMER_INTERRUPT) + #undef USING_RPI_PICO_TIMER_INTERRUPT + #endif #define USING_RPI_PICO_TIMER_INTERRUPT true +#else + #error This code is intended to run on the non-mbed RP2040 arduino-pico platform! Please check your Tools->Board setting. #endif #ifndef RPI_PICO_TIMER_INTERRUPT_VERSION - #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.1" + #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.1.0" #endif #ifndef TIMER_INTERRUPT_DEBUG #define TIMER_INTERRUPT_DEBUG 0 #endif -#include -#include "pico/stdlib.h" -#include "hardware/timer.h" -#include "hardware/irq.h" +#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 + #include "pico/stdlib.h" + #include "hardware/timer.h" + #include "hardware/irq.h" +#endif #include "TimerInterrupt_Generic_Debug.h" diff --git a/src/TimerInterrupt_Generic_Debug.h b/src/TimerInterrupt_Generic_Debug.h index 545893c..1eb5363 100644 --- a/src/TimerInterrupt_Generic_Debug.h +++ b/src/TimerInterrupt_Generic_Debug.h @@ -25,12 +25,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 @@ -55,28 +56,50 @@ #define _TIMERINTERRUPT_LOGLEVEL_ 1 #endif -#define TISR_LOGERROR(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGERROR0(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print(x); } -#define TISR_LOGERROR1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGERROR2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGERROR3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +////////////////////////////////////////// -#define TISR_LOGWARN(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGWARN0(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print(x); } -#define TISR_LOGWARN1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGWARN2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGWARN3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +const char TISR_MARK[] = "[TISR] "; +const char TISR_SP[] = " "; -#define TISR_LOGINFO(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGINFO0(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print(x); } -#define TISR_LOGINFO1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGINFO2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGINFO3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +#define TISR_PRINT TISR_DBG_PORT.print +#define TISR_PRINTLN TISR_DBG_PORT.println -#define TISR_LOGDEBUG(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGDEBUG0(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print(x); } -#define TISR_LOGDEBUG1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGDEBUG2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGDEBUG3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +#define TISR_PRINT_MARK TISR_PRINT(TISR_MARK) +#define TISR_PRINT_SP TISR_PRINT(TISR_SP) + + +////////////////////////////////////////// + +#define TISR_LOGERROR(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINTLN(x); } +#define TISR_LOGERROR0(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT(x); } +#define TISR_LOGERROR1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_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 diff --git a/src_cpp/RPi_Pico_ISR_Timer.cpp b/src_cpp/RPi_Pico_ISR_Timer.cpp index f5a6cb3..f70831f 100644 --- a/src_cpp/RPi_Pico_ISR_Timer.cpp +++ b/src_cpp/RPi_Pico_ISR_Timer.cpp @@ -25,12 +25,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 diff --git a/src_cpp/RPi_Pico_ISR_Timer.h b/src_cpp/RPi_Pico_ISR_Timer.h index a30c3e0..82af210 100644 --- a/src_cpp/RPi_Pico_ISR_Timer.h +++ b/src_cpp/RPi_Pico_ISR_Timer.h @@ -25,12 +25,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 @@ -38,12 +39,17 @@ #ifndef ISR_TIMER_GENERIC_H #define ISR_TIMER_GENERIC_H -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED) + #if defined(USING_RPI_PICO_TIMER_INTERRUPT) + #undef USING_RPI_PICO_TIMER_INTERRUPT + #endif + #define USING_RPI_PICO_TIMER_INTERRUPT true +#else + #error This code is intended to run on the non-mbed RP2040 arduino-pico platform! Please check your Tools->Board setting. #endif #ifndef RPI_PICO_TIMER_INTERRUPT_VERSION - #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.1" + #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.1.0" #endif #include "TimerInterrupt_Generic_Debug.h" diff --git a/src_cpp/RPi_Pico_TimerInterrupt.h b/src_cpp/RPi_Pico_TimerInterrupt.h index 3ae9fb9..c1afd92 100644 --- a/src_cpp/RPi_Pico_TimerInterrupt.h +++ b/src_cpp/RPi_Pico_TimerInterrupt.h @@ -26,12 +26,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 @@ -39,24 +40,40 @@ #ifndef RPI_PICO_TIMERINTERRUPT_H #define RPI_PICO_TIMERINTERRUPT_H -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#else +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED) + #if defined(USING_RPI_PICO_TIMER_INTERRUPT) + #undef USING_RPI_PICO_TIMER_INTERRUPT + #endif #define USING_RPI_PICO_TIMER_INTERRUPT true +#else + #error This code is intended to run on the non-mbed RP2040 arduino-pico platform! Please check your Tools->Board setting. #endif #ifndef RPI_PICO_TIMER_INTERRUPT_VERSION - #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.1" + #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.1.0" #endif #ifndef TIMER_INTERRUPT_DEBUG #define TIMER_INTERRUPT_DEBUG 0 #endif -#include -#include "pico/stdlib.h" -#include "hardware/timer.h" -#include "hardware/irq.h" +#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 + #include "pico/stdlib.h" + #include "hardware/timer.h" + #include "hardware/irq.h" +#endif #include "TimerInterrupt_Generic_Debug.h" diff --git a/src_cpp/TimerInterrupt_Generic_Debug.h b/src_cpp/TimerInterrupt_Generic_Debug.h index 545893c..1eb5363 100644 --- a/src_cpp/TimerInterrupt_Generic_Debug.h +++ b/src_cpp/TimerInterrupt_Generic_Debug.h @@ -25,12 +25,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 @@ -55,28 +56,50 @@ #define _TIMERINTERRUPT_LOGLEVEL_ 1 #endif -#define TISR_LOGERROR(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGERROR0(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print(x); } -#define TISR_LOGERROR1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGERROR2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGERROR3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +////////////////////////////////////////// -#define TISR_LOGWARN(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGWARN0(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print(x); } -#define TISR_LOGWARN1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGWARN2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGWARN3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +const char TISR_MARK[] = "[TISR] "; +const char TISR_SP[] = " "; -#define TISR_LOGINFO(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGINFO0(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print(x); } -#define TISR_LOGINFO1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGINFO2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGINFO3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +#define TISR_PRINT TISR_DBG_PORT.print +#define TISR_PRINTLN TISR_DBG_PORT.println -#define TISR_LOGDEBUG(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGDEBUG0(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print(x); } -#define TISR_LOGDEBUG1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGDEBUG2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGDEBUG3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +#define TISR_PRINT_MARK TISR_PRINT(TISR_MARK) +#define TISR_PRINT_SP TISR_PRINT(TISR_SP) + + +////////////////////////////////////////// + +#define TISR_LOGERROR(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINTLN(x); } +#define TISR_LOGERROR0(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT(x); } +#define TISR_LOGERROR1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_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 diff --git a/src_h/RPi_Pico_ISR_Timer-Impl.h b/src_h/RPi_Pico_ISR_Timer-Impl.h index 41a3629..91285ec 100644 --- a/src_h/RPi_Pico_ISR_Timer-Impl.h +++ b/src_h/RPi_Pico_ISR_Timer-Impl.h @@ -25,12 +25,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 @@ -38,10 +39,6 @@ #ifndef ISR_TIMER_GENERIC_IMPL_H #define ISR_TIMER_GENERIC_IMPL_H -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#endif - #include RPI_PICO_ISR_Timer::RPI_PICO_ISR_Timer() diff --git a/src_h/RPi_Pico_ISR_Timer.h b/src_h/RPi_Pico_ISR_Timer.h index 5fee42f..6014527 100644 --- a/src_h/RPi_Pico_ISR_Timer.h +++ b/src_h/RPi_Pico_ISR_Timer.h @@ -25,12 +25,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 @@ -38,12 +39,17 @@ #ifndef ISR_TIMER_GENERIC_H #define ISR_TIMER_GENERIC_H -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED) + #if defined(USING_RPI_PICO_TIMER_INTERRUPT) + #undef USING_RPI_PICO_TIMER_INTERRUPT + #endif + #define USING_RPI_PICO_TIMER_INTERRUPT true +#else + #error This code is intended to run on the non-mbed RP2040 arduino-pico platform! Please check your Tools->Board setting. #endif #ifndef RPI_PICO_TIMER_INTERRUPT_VERSION - #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.1" + #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.1.0" #endif #include "TimerInterrupt_Generic_Debug.h" diff --git a/src_h/RPi_Pico_TimerInterrupt.h b/src_h/RPi_Pico_TimerInterrupt.h index 3ae9fb9..c1afd92 100644 --- a/src_h/RPi_Pico_TimerInterrupt.h +++ b/src_h/RPi_Pico_TimerInterrupt.h @@ -26,12 +26,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 @@ -39,24 +40,40 @@ #ifndef RPI_PICO_TIMERINTERRUPT_H #define RPI_PICO_TIMERINTERRUPT_H -#if !( defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) - #error This code is intended to run on the RASPBERRY_PI_PICO platform! Please check your Tools->Board setting. -#else +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) && !defined(ARDUINO_ARCH_MBED) + #if defined(USING_RPI_PICO_TIMER_INTERRUPT) + #undef USING_RPI_PICO_TIMER_INTERRUPT + #endif #define USING_RPI_PICO_TIMER_INTERRUPT true +#else + #error This code is intended to run on the non-mbed RP2040 arduino-pico platform! Please check your Tools->Board setting. #endif #ifndef RPI_PICO_TIMER_INTERRUPT_VERSION - #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.0.1" + #define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.1.0" #endif #ifndef TIMER_INTERRUPT_DEBUG #define TIMER_INTERRUPT_DEBUG 0 #endif -#include -#include "pico/stdlib.h" -#include "hardware/timer.h" -#include "hardware/irq.h" +#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 + #include "pico/stdlib.h" + #include "hardware/timer.h" + #include "hardware/irq.h" +#endif #include "TimerInterrupt_Generic_Debug.h" diff --git a/src_h/TimerInterrupt_Generic_Debug.h b/src_h/TimerInterrupt_Generic_Debug.h index 545893c..1eb5363 100644 --- a/src_h/TimerInterrupt_Generic_Debug.h +++ b/src_h/TimerInterrupt_Generic_Debug.h @@ -25,12 +25,13 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.0.1 + 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 @@ -55,28 +56,50 @@ #define _TIMERINTERRUPT_LOGLEVEL_ 1 #endif -#define TISR_LOGERROR(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGERROR0(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print(x); } -#define TISR_LOGERROR1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGERROR2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGERROR3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +////////////////////////////////////////// -#define TISR_LOGWARN(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGWARN0(x) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print(x); } -#define TISR_LOGWARN1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGWARN2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGWARN3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>1) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +const char TISR_MARK[] = "[TISR] "; +const char TISR_SP[] = " "; -#define TISR_LOGINFO(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGINFO0(x) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print(x); } -#define TISR_LOGINFO1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGINFO2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGINFO3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>2) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +#define TISR_PRINT TISR_DBG_PORT.print +#define TISR_PRINTLN TISR_DBG_PORT.println -#define TISR_LOGDEBUG(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.println(x); } -#define TISR_LOGDEBUG0(x) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print(x); } -#define TISR_LOGDEBUG1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(y); } -#define TISR_LOGDEBUG2(x,y,z) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(z); } -#define TISR_LOGDEBUG3(x,y,z,w) if(_TIMERINTERRUPT_LOGLEVEL_>3) { TISR_DBG_PORT.print("[TISR] "); TISR_DBG_PORT.print(x); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(y); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.print(z); TISR_DBG_PORT.print(" "); TISR_DBG_PORT.println(w); } +#define TISR_PRINT_MARK TISR_PRINT(TISR_MARK) +#define TISR_PRINT_SP TISR_PRINT(TISR_SP) + + +////////////////////////////////////////// + +#define TISR_LOGERROR(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINTLN(x); } +#define TISR_LOGERROR0(x) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT(x); } +#define TISR_LOGERROR1(x,y) if(_TIMERINTERRUPT_LOGLEVEL_>0) { TISR_PRINT_MARK; TISR_PRINT(x); TISR_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