From fffecb47d5e010468482b236013b4579b3c06975 Mon Sep 17 00:00:00 2001 From: camilo Date: Thu, 13 Jun 2024 21:52:37 -0500 Subject: [PATCH] added STEP and DELTA events to input --- doc/pages/_1_background.dox | 86 ++++++++++++++++++------------------ doc/pages/_2_foundations.dox | 4 +- doc/pages/_4_events.dox | 3 -- doc/pages/ext_fsm.dox | 3 -- library.json | 2 +- library.properties | 2 +- src/CMakeLists.txt | 2 +- src/QuarkTS.h | 10 ++--- src/include/input.hpp | 12 ++++- src/input.cpp | 18 ++++++++ 10 files changed, 82 insertions(+), 60 deletions(-) diff --git a/doc/pages/_1_background.dox b/doc/pages/_1_background.dox index 5d8949d6..db9e5efa 100644 --- a/doc/pages/_1_background.dox +++ b/doc/pages/_1_background.dox @@ -3,30 +3,30 @@ * * @section q_about About the OS * QuarkTS++ (the C++ port of QuarkTS) -* is an open-source operating system that is built on top of a +* is an open-source operating system that is built on top of a * RTC cooperative quasistatic scheduler. Its simplified kernel -* implements a specialized round-robin scheme using a linked-chain approach and +* implements a specialized round-robin scheme using a linked-chain approach and * an event-queue to provide true FIFO priority scheduling. -* +* * Why cooperative? * -* Rather than having preemption, tasks manage their own life-cycle. This bring -* significant benefits, fewer re-entrance problems are encountered, because +* Rather than having preemption, tasks manage their own life-cycle. This bring +* significant benefits, fewer re-entrance problems are encountered, because * tasks cannot be interrupted arbitrarily by other tasks, but only at positions -* permitted by the programmer, so you mostly do not need to worry about pitfalls +* permitted by the programmer, so you mostly do not need to worry about pitfalls * of the concurrent approach(resource sharing, races, deadlocks, etc...). * * What is it made for? -* The design goal of QuarkTS++ is to achieve its stated functionality using a -* small, simple, and (most importantly) robust implementation to make it +* The design goal of QuarkTS++ is to achieve its stated functionality using a +* small, simple, and (most importantly) robust implementation to make it * suitable on resource-constrained microcontrollers, where a full-preemptive RTOS -* is an overkill and their inclusion adds unnecessary complexity to the firmware -* development. In addition with a @ref q_fsm support, @ref q_qcoroutines, time +* is an overkill and their inclusion adds unnecessary complexity to the firmware +* development. In addition with a @ref q_fsm support, @ref q_qcoroutines, time * control and the inter-task communication primitives, QuarkTS++ provides a modern * environment to build stable and predictable event-driven multitasking embedded -* software. Their modularity and reliability make this OS a great choice to -* develop efficiently a wide range of applications in low-cost devices, +* software. Their modularity and reliability make this OS a great choice to +* develop efficiently a wide range of applications in low-cost devices, * including automotive controls, monitoring and Internet of Things * * Why should I choose it? @@ -41,20 +41,20 @@ * * @section q_license License * QuarkTS++ is licensed under the MIT License. You may copy, distribute and modify -* the software without any restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the OS, and to permit persons to whom the OS is furnished to do so. -* This OS is provided as is in the hope that it will be useful, but WITHOUT ANY -* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +* the software without any restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the OS, and to permit persons to whom the OS is furnished to do so. +* This OS is provided as is in the hope that it will be useful, but WITHOUT ANY +* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. * * For more details, see the MIT License line by line. -* +* * * @section q_hardwarecompatibility Hardware compatibility -* QuarkTS++ has no direct hardware dependencies, so it is portable to many -* platforms and C compilers. -* +* QuarkTS++ has no direct hardware dependencies, so it is portable to many +* platforms and C compilers. +* * The following cores have been powered with QuarkTS++ successfully: * * - ARM cores(ATMEL, STM32, LPC, Kinetis, Nordic and others) @@ -70,48 +70,48 @@ * guidelines and complemented with multiple static-analysis checks targeted to * safe critical applications. * -* Simply using QuarkTS++ in an application, does not mean developers can make a -* claim related to the development process and compliance of the OS to any -* requirements or product specification, without first, following a recognized -* system-wide conformance verification process. Conformance evidence must then -* be presented, audited and accepted by a recognized and relevant independent +* Simply using QuarkTS++ in an application, does not mean developers can make a +* claim related to the development process and compliance of the OS to any +* requirements or product specification, without first, following a recognized +* system-wide conformance verification process. Conformance evidence must then +* be presented, audited and accepted by a recognized and relevant independent * assessment organization. Without undergoing this process of due diligence, no * claim can be made as to the suitability of QuarkTS++ to be used in any safety or * otherwise commercially critical application. * -* Besides the previous information, the OS sets the following clarifications +* Besides the previous information, the OS sets the following clarifications * regarding coding policies and naming conventions: * * - All the QuarkTS++ implementation follows the C++11 standard strictly. * - Dynamic memory allocation is banned to conform the industry standards for -* safety-critical software: @b MISRA-C++, @b DO178B, @b IEC-61508, @b ISO-26262 +* safety-critical software: @b MISRA-C++, @b DO178B, @b IEC-61508, @b ISO-26262 * and so on. -* - Because errors in string manipulation have long been recognized as a leading -* source of buffer overflows in C, several mitigation strategies have been -* devised. These include mitigation strategies designed to prevent buffer -* overflows from occurring and strategies designed to detect buffer overflows +* - Because errors in raw-string manipulation have long been recognized as a leading +* source of buffer overflows in C/C++, several mitigation strategies have been +* devised. These include mitigation strategies designed to prevent buffer +* overflows from occurring and strategies designed to detect buffer overflows * and securely recover without allowing the failure to be exploited. * - In line with MISRA guides and for portability between platforms, we use the * @c stdint.h with typedefs that indicate size and signedness in place of the basic * types. -* - In line with @b MISRA guides, unqualified standard @c char and @c char* types +* - In line with @b MISRA guides, unqualified standard @c char and @c char* types * are only permitted to hold ASCII characters and strings respectively. -* - The @c _t suffix is used to denote a type definition (i.e @c base_t , +* - The @c _t suffix is used to denote a type definition (i.e @c base_t , * @c signal_t , @c cycles_t, ...). * - Enum values and constants are written in all upper case. * - Almost all functions returns a boolean value of type @c bool, where a -* @c true - @c 1u value indicates a successful procedure and @c false - @c 0u, +* @c true - @c 1u value indicates a successful procedure and @c false - @c 0u, * the failure of the procedure -* +* * @section q_memusage Memory usage -* As a quasi-static scheduler is implemented here, dynamic scheduling is not -* required and the assignment of tasks must be done before program execution -* begins. The kernel is designed to allow unlimited tasks and kernel objects, -* but of course, the whole application will be constrained by the memory +* As a quasi-static scheduler is implemented here, dynamic scheduling is not +* required and the assignment of tasks must be done before program execution +* begins. The kernel is designed to allow unlimited tasks and kernel objects, +* but of course, the whole application will be constrained by the memory * specifications of the embedded system. * -* The kernel's memory footprint can be scaled down to contain only the features -* required for your application, typically @c 3.7Kb of code space and less +* The kernel's memory footprint can be scaled down to contain only the features +* required for your application, typically @c 3.7Kb of code space and less * than @c 1Kb of data space. * *
@@ -135,5 +135,5 @@ * Remaining utilities 2980 * *
-* +* */ diff --git a/doc/pages/_2_foundations.dox b/doc/pages/_2_foundations.dox index 303eaac6..c7555c5c 100644 --- a/doc/pages/_2_foundations.dox +++ b/doc/pages/_2_foundations.dox @@ -213,7 +213,7 @@ * by their priority value dictate when a task can change to the @c RUNNING state. * * @subsection q_removetask Removing a task -* The qOS::core::removeTask() function removes the task from the scheduling scheme. +* The qOS::core::remove() function removes the task from the scheduling scheme. * This means the task node will be disconnected from the kernel chain, * preventing additional overhead provided by the scheduler when it does checks * over it and course, preventing it from running. @@ -434,7 +434,7 @@ * Considering that the kernel is hardware-independent, the application writer * should provide the necessary piece of code to enable and disable interrupts. * -* For this, the critical::setInterruptsED() method should be used. In this way, +* For this, the qOS::critical::setInterruptsED() method should be used. In this way, * communication between ISR and tasks using queued notifications or data queues * is performed safely. * diff --git a/doc/pages/_4_events.dox b/doc/pages/_4_events.dox index aad3456d..52187362 100644 --- a/doc/pages/_4_events.dox +++ b/doc/pages/_4_events.dox @@ -33,9 +33,6 @@ * * Please review the @ref qOS::event_t class reference for more details. * -* @note When tasks are defined using the object-oriented programming approach, -* this structure can be obtained within the @c activities method using the -* qOS::task::eventData(). * * @section q_event_timeelapsed The Time-Elapsed event * Running tasks at pre-determined rates is desirable in many situations, like diff --git a/doc/pages/ext_fsm.dox b/doc/pages/ext_fsm.dox index 3546ef8e..ef7633aa 100644 --- a/doc/pages/ext_fsm.dox +++ b/doc/pages/ext_fsm.dox @@ -145,9 +145,6 @@ * field. (here, a cast to qOS::event_t is mandatory). * - @ref qOS::sm::handler_t::StateData (read-only) : State associated data. Storage-pointer. * -* @note When states are defined using the object-oriented programming approach, -* this structure can be obtained within the @c activities method using the -* qOS::sm::state::getHandler(). * * Within the callback function of every state or the @c activities method, only one * level of dispatching (based on the signal) is necessary. Typically this is diff --git a/library.json b/library.json index 51b18333..1290f9eb 100644 --- a/library.json +++ b/library.json @@ -16,7 +16,7 @@ "maintainer": true } ], - "version": "1.7.0", + "version": "1.7.1", "license": "MIT", "frameworks": "arduino", "platforms": "*" diff --git a/library.properties b/library.properties index 432c2d00..062d07fc 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=QuarkTS -version=1.7.0 +version=1.7.1 license=MIT author=J. Camilo Gomez C. maintainer=J. Camilo Gomez C. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bab6a336..512a8236 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required( VERSION 3.2 ) project( quarkts-cpp - VERSION 1.7.0 + VERSION 1.7.1 DESCRIPTION "An open-source OS for small embedded applications" LANGUAGES CXX ) diff --git a/src/QuarkTS.h b/src/QuarkTS.h index 47eedfcc..af66fe20 100644 --- a/src/QuarkTS.h +++ b/src/QuarkTS.h @@ -1,7 +1,7 @@ /*! * @file QuarkTS.h * @author J. Camilo Gomez C. - * @version 1.7.0 + * @version 1.7.1 * @note This file is part of the QuarkTS++ distribution. * @brief Global inclusion header **/ @@ -41,8 +41,8 @@ This file is part of the QuarkTS++ OS distribution. #ifndef QOS_CPP_H #define QOS_CPP_H -#define QUARKTS_CPP_VERSION "1.7.0" -#define QUARKTS_CPP_VERNUM ( 170u ) +#define QUARKTS_CPP_VERSION "1.7.1" +#define QUARKTS_CPP_VERNUM ( 171u ) #define QUARKTS_CPP_CAPTION "QuarkTS++ OS " QUARKTS_CPP_VERSION #include "config/config.h" @@ -70,7 +70,7 @@ namespace qOS { constexpr const uint8_t number = QUARKTS_CPP_VERNUM; constexpr const uint8_t mayor = 1U; constexpr const uint8_t minor = 7U; - constexpr const uint8_t rev = 0U; + constexpr const uint8_t rev = 1U; } namespace product { constexpr const char* author = "J. Camilo Gomez C."; @@ -84,7 +84,7 @@ namespace qOS { } namespace build { - constexpr const uint32_t number = 4135; + constexpr const uint32_t number = 4136; constexpr const char* date = __DATE__; constexpr const char* time = __TIME__; constexpr const char* std = "c++11"; diff --git a/src/include/input.hpp b/src/include/input.hpp index 8969f80e..66efa136 100644 --- a/src/include/input.hpp +++ b/src/include/input.hpp @@ -48,6 +48,8 @@ namespace qOS { STEADY_IN_HIGH, /**< Event when the input-channel has been kept on high (or above the high threshold) for the specified time .*/ STEADY_IN_LOW, /**< Event when the input-channel has been kept on low (or below the low threshold) for the specified time .*/ STEADY_IN_BAND, /**< Event when the analog input-channel has remained within the band for the specified time .*/ + DELTA, /**< Event when the difference of the last and latest reading of an analog input channel is greater than the defined delta*/ + STEP, /**< Event on step reading of the analog-input channel*/ /*! @cond */ MAX_EVENTS /*! @endcond */ @@ -332,6 +334,9 @@ namespace qOS { channelStateFcn_t channelState{ nullptr }; analogValue_t high{ 800 }; analogValue_t low{ 200 }; + analogValue_t last{ 0.0F }; + analogValue_t delta{ 1.0e+20F }; + analogValue_t step{ 1.0e+20F }; analogValue_t hysteresis{ 20 }; qOS::clock_t tSteadyBand{ 0xFFFFFFFFU }; @@ -367,7 +372,7 @@ namespace qOS { */ analogChannel( const uint8_t inputChannel, const analogValue_t lowerThreshold, const analogValue_t upperThreshold, const analogValue_t h = 0.1F ) : channel( inputChannel ), high( upperThreshold ), low( lowerThreshold ) { - hysteresis = ( h < 0 ) ? -h : h; + hysteresis = ( h < 0.0F ) ? -h : h; } /** * @brief Get the channel type. @@ -427,6 +432,11 @@ namespace qOS { reader = r; return true; } + /** + * @brief Unshares the specified input channel if was marked as + * shared. + * @return @c true on success. Otherwise @c false. + */ bool unShare( void ) noexcept override { ptrValue = &value; diff --git a/src/input.cpp b/src/input.cpp index a3c70669..6c003bba 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -15,7 +15,19 @@ void input::digitalChannel::updateReading( void ) noexcept /*============================================================================*/ void input::analogChannel::updateReading(void) noexcept { + analogValue_t diff; value = ( isShared() ) ? ptrValue[ 0 ] : reader( number ); + diff = value - last; + if ( diff >= delta ) { + dispatchEvent( input::event::DELTA ); + } + if ( diff >= step ) { + auto mult = static_cast( diff/step ); + for ( int i = 0 ; i < mult; ++i ) { + dispatchEvent( input::event::STEP ); + } + } + last = value; } /*============================================================================*/ void input::digitalChannel::fallingEdgeState( input::digitalChannel& c ) @@ -422,6 +434,12 @@ bool input::analogChannel::setParameter( const input::event e, const analogValue case input::event::IN_BAND: hysteresis = p; break; + case input::event::DELTA: + delta = p; + break; + case input::event::STEP: + step = p; + break; default: retValue = false; break;