Containers (STL-compatible) StateMachines MessageBus and more for Embedded Systems. See www.etlcpp.com

Committer:
bobbery
Date:
Fri Mar 16 16:34:18 2018 +0000
Revision:
0:b47c2a7920c2
Works after using gcc_generic undef CAPACITY and replacing nullptr by std::nullptr

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bobbery 0:b47c2a7920c2 1 /******************************************************************************
bobbery 0:b47c2a7920c2 2 The MIT License(MIT)
bobbery 0:b47c2a7920c2 3
bobbery 0:b47c2a7920c2 4 Embedded Template Library.
bobbery 0:b47c2a7920c2 5 https://github.com/ETLCPP/etl
bobbery 0:b47c2a7920c2 6 https://www.etlcpp.com
bobbery 0:b47c2a7920c2 7
bobbery 0:b47c2a7920c2 8 Copyright(c) 2017 jwellbelove
bobbery 0:b47c2a7920c2 9
bobbery 0:b47c2a7920c2 10 Permission is hereby granted, free of charge, to any person obtaining a copy
bobbery 0:b47c2a7920c2 11 of this software and associated documentation files(the "Software"), to deal
bobbery 0:b47c2a7920c2 12 in the Software without restriction, including without limitation the rights
bobbery 0:b47c2a7920c2 13 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
bobbery 0:b47c2a7920c2 14 copies of the Software, and to permit persons to whom the Software is
bobbery 0:b47c2a7920c2 15 furnished to do so, subject to the following conditions :
bobbery 0:b47c2a7920c2 16
bobbery 0:b47c2a7920c2 17 The above copyright notice and this permission notice shall be included in all
bobbery 0:b47c2a7920c2 18 copies or substantial portions of the Software.
bobbery 0:b47c2a7920c2 19
bobbery 0:b47c2a7920c2 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
bobbery 0:b47c2a7920c2 21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
bobbery 0:b47c2a7920c2 22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
bobbery 0:b47c2a7920c2 23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
bobbery 0:b47c2a7920c2 24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bobbery 0:b47c2a7920c2 25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
bobbery 0:b47c2a7920c2 26 SOFTWARE.
bobbery 0:b47c2a7920c2 27 ******************************************************************************/
bobbery 0:b47c2a7920c2 28
bobbery 0:b47c2a7920c2 29 #ifndef __ETL_C_TIMER_FRAMEWORK__
bobbery 0:b47c2a7920c2 30 #define __ETL_C_TIMER_FRAMEWORK__
bobbery 0:b47c2a7920c2 31
bobbery 0:b47c2a7920c2 32 #include <stdint.h>
bobbery 0:b47c2a7920c2 33
bobbery 0:b47c2a7920c2 34 #include "ecl_user.h"
bobbery 0:b47c2a7920c2 35
bobbery 0:b47c2a7920c2 36 // Pass/fail results.
bobbery 0:b47c2a7920c2 37 enum
bobbery 0:b47c2a7920c2 38 {
bobbery 0:b47c2a7920c2 39 ECL_TIMER_FAIL = 0,
bobbery 0:b47c2a7920c2 40 ECL_TIMER_PASS = 1,
bobbery 0:b47c2a7920c2 41 };
bobbery 0:b47c2a7920c2 42
bobbery 0:b47c2a7920c2 43 typedef int ecl_timer_result_t;
bobbery 0:b47c2a7920c2 44
bobbery 0:b47c2a7920c2 45 // Enable states.
bobbery 0:b47c2a7920c2 46 enum
bobbery 0:b47c2a7920c2 47 {
bobbery 0:b47c2a7920c2 48 ECL_TIMER_DISABLED = ECL_TIMER_FAIL,
bobbery 0:b47c2a7920c2 49 ECL_TIMER_ENABLED = ECL_TIMER_PASS
bobbery 0:b47c2a7920c2 50 };
bobbery 0:b47c2a7920c2 51
bobbery 0:b47c2a7920c2 52 typedef int ecl_timer_enable_t;
bobbery 0:b47c2a7920c2 53
bobbery 0:b47c2a7920c2 54 // Timer modes.
bobbery 0:b47c2a7920c2 55 enum
bobbery 0:b47c2a7920c2 56 {
bobbery 0:b47c2a7920c2 57 ECL_TIMER_SINGLE_SHOT = 0,
bobbery 0:b47c2a7920c2 58 ECL_TIMER_REPEATING = 1
bobbery 0:b47c2a7920c2 59 };
bobbery 0:b47c2a7920c2 60
bobbery 0:b47c2a7920c2 61 typedef char ecl_timer_mode_t;
bobbery 0:b47c2a7920c2 62
bobbery 0:b47c2a7920c2 63 // Timer start action.
bobbery 0:b47c2a7920c2 64 enum
bobbery 0:b47c2a7920c2 65 {
bobbery 0:b47c2a7920c2 66 ECL_TIMER_START_DELAYED = 0,
bobbery 0:b47c2a7920c2 67 ECL_TIMER_START_IMMEDIATE = 1
bobbery 0:b47c2a7920c2 68 };
bobbery 0:b47c2a7920c2 69
bobbery 0:b47c2a7920c2 70 typedef char ecl_timer_start_t;
bobbery 0:b47c2a7920c2 71
bobbery 0:b47c2a7920c2 72 // Timer identifiers.
bobbery 0:b47c2a7920c2 73 enum
bobbery 0:b47c2a7920c2 74 {
bobbery 0:b47c2a7920c2 75 ECL_TIMER_NO_TIMER = 255
bobbery 0:b47c2a7920c2 76 };
bobbery 0:b47c2a7920c2 77
bobbery 0:b47c2a7920c2 78 typedef uint_least8_t ecl_timer_id_t;
bobbery 0:b47c2a7920c2 79
bobbery 0:b47c2a7920c2 80 // Timer times.
bobbery 0:b47c2a7920c2 81 #define ECL_TIMER_INACTIVE 0xFFFFFFFF
bobbery 0:b47c2a7920c2 82
bobbery 0:b47c2a7920c2 83 typedef uint32_t ecl_timer_time_t;
bobbery 0:b47c2a7920c2 84
bobbery 0:b47c2a7920c2 85 //*************************************************************************
bobbery 0:b47c2a7920c2 86 /// The configuration of a timer.
bobbery 0:b47c2a7920c2 87 //*************************************************************************
bobbery 0:b47c2a7920c2 88 struct ecl_timer_config
bobbery 0:b47c2a7920c2 89 {
bobbery 0:b47c2a7920c2 90 void (*pcallback)();
bobbery 0:b47c2a7920c2 91 ecl_timer_time_t period;
bobbery 0:b47c2a7920c2 92 ecl_timer_time_t delta;
bobbery 0:b47c2a7920c2 93 ecl_timer_id_t id;
bobbery 0:b47c2a7920c2 94 uint_least8_t previous;
bobbery 0:b47c2a7920c2 95 uint_least8_t next;
bobbery 0:b47c2a7920c2 96 char repeating;
bobbery 0:b47c2a7920c2 97 };
bobbery 0:b47c2a7920c2 98
bobbery 0:b47c2a7920c2 99 //*************************************************************************
bobbery 0:b47c2a7920c2 100 /// The API.
bobbery 0:b47c2a7920c2 101 //*************************************************************************
bobbery 0:b47c2a7920c2 102 void ecl_timer_data_init_default(struct ecl_timer_config* ptimer_data_);
bobbery 0:b47c2a7920c2 103 void ecl_timer_data_init(struct ecl_timer_config* ptimer_data_, ecl_timer_id_t id_, void(*pcallback_)(), ecl_timer_time_t period_, ecl_timer_mode_t repeating_);
bobbery 0:b47c2a7920c2 104 ecl_timer_result_t ecl_timer_is_active(struct ecl_timer_config* ptimer_data_);
bobbery 0:b47c2a7920c2 105 void ecl_set_timer_inactive(struct ecl_timer_config* ptimer_data_);
bobbery 0:b47c2a7920c2 106 void ecl_timer_init(struct ecl_timer_config* ptimers_, uint_least8_t max_timers_);
bobbery 0:b47c2a7920c2 107 ecl_timer_id_t ecl_timer_register(void(*pcallback_)(), ecl_timer_time_t period_, ecl_timer_mode_t repeating_);
bobbery 0:b47c2a7920c2 108 ecl_timer_result_t ecl_timer_unregister(ecl_timer_id_t id_);
bobbery 0:b47c2a7920c2 109 void ecl_timer_enable(ecl_timer_enable_t state_);
bobbery 0:b47c2a7920c2 110 ecl_timer_result_t ecl_timer_is_running(void);
bobbery 0:b47c2a7920c2 111 void ecl_timer_clear(void);
bobbery 0:b47c2a7920c2 112 ecl_timer_result_t ecl_timer_tick(uint32_t count);
bobbery 0:b47c2a7920c2 113 ecl_timer_result_t ecl_timer_start(ecl_timer_id_t id_, ecl_timer_start_t immediate_);
bobbery 0:b47c2a7920c2 114 ecl_timer_result_t ecl_timer_stop(ecl_timer_id_t id_);
bobbery 0:b47c2a7920c2 115 ecl_timer_result_t ecl_timer_set_period(ecl_timer_id_t id_, ecl_timer_time_t period_);
bobbery 0:b47c2a7920c2 116 ecl_timer_result_t ecl_timer_set_mode(ecl_timer_id_t id_, ecl_timer_mode_t repeating_);
bobbery 0:b47c2a7920c2 117
bobbery 0:b47c2a7920c2 118 #endif
bobbery 0:b47c2a7920c2 119