diff --git a/examples/ArmTimerCallbacks - C/ArmTimerCallbacks.uvoptx b/examples/ArmTimerCallbacks - C/ArmTimerCallbacks.uvoptx index a96071c6..f18af392 100644 --- a/examples/ArmTimerCallbacks - C/ArmTimerCallbacks.uvoptx +++ b/examples/ArmTimerCallbacks - C/ArmTimerCallbacks.uvoptx @@ -248,18 +248,6 @@ 1 3 - 1 - 0 - 0 - 0 - ..\..\src\c\ecl_timer_list.c - ecl_timer_list.c - 0 - 0 - - - 1 - 4 5 0 0 @@ -271,19 +259,7 @@ 1 - 5 - 5 - 0 - 0 - 0 - ..\..\src\c\ecl_timer_list.h - ecl_timer_list.h - 0 - 0 - - - 1 - 6 + 4 5 0 0 diff --git a/examples/ArmTimerCallbacks - C/ArmTimerCallbacks.uvprojx b/examples/ArmTimerCallbacks - C/ArmTimerCallbacks.uvprojx index 28b06f23..1dab4f9a 100644 --- a/examples/ArmTimerCallbacks - C/ArmTimerCallbacks.uvprojx +++ b/examples/ArmTimerCallbacks - C/ArmTimerCallbacks.uvprojx @@ -10,8 +10,8 @@ Target 1 0x4 ARM-ADS - 5060528::V5.06 update 5 (build 528)::ARMCC - 0 + 6070000::V6.7::.\ARMCLANG + 1 STM32F401RETx @@ -320,7 +320,7 @@ 1 0 0 - 2 + 3 0 0 1 @@ -390,21 +390,11 @@ 1 ..\..\src\c\ecl_timer.c - - ecl_timer_list.c - 1 - ..\..\src\c\ecl_timer_list.c - ecl_timer.h 5 ..\..\src\c\ecl_timer.h - - ecl_timer_list.h - 5 - ..\..\src\c\ecl_timer_list.h - ecl_user.h 5 diff --git a/src/c/ecl_timer.c b/src/c/ecl_timer.c index 29b5b17b..2b6e3e77 100644 --- a/src/c/ecl_timer.c +++ b/src/c/ecl_timer.c @@ -30,7 +30,174 @@ SOFTWARE. #include #include "ecl_timer.h" -#include "ecl_timer_list.h" + +//***************************************************************************** +// Internal timer list +//***************************************************************************** + +static ecl_timer_id_t head; +static ecl_timer_id_t tail; +static ecl_timer_id_t current; + +static struct ecl_timer_config* ptimers; + +static void ecl_timer_list_init(struct ecl_timer_config* const ptimers_) +{ + ptimers = ptimers_; + head = ECL_TIMER_NO_TIMER; + tail = ECL_TIMER_NO_TIMER; + current = ECL_TIMER_NO_TIMER; +} + +//******************************* +static struct ecl_timer_config* ecl_timer_list_front() +{ + return &ptimers[head]; +} + +//******************************* +static ecl_timer_id_t ecl_timer_list_begin() +{ + current = head; + return current; +} + +//******************************* +static ecl_timer_id_t ecl_timer_list_next(ecl_timer_id_t last) +{ + current = ptimers[last].next; + return current; +} + +//******************************* +static int ecl_timer_list_empty() +{ + return head == ECL_TIMER_NO_TIMER; +} + +//******************************* +// Inserts the timer at the correct delta position +//******************************* +static void ecl_timer_list_insert(ecl_timer_id_t id_) +{ + struct ecl_timer_config* ptimer = &ptimers[id_]; + + if (head == ECL_TIMER_NO_TIMER) + { + // No entries yet. + head = id_; + tail = id_; + ptimer->previous = ECL_TIMER_NO_TIMER; + ptimer->next = ECL_TIMER_NO_TIMER; + } + else + { + // We already have entries. + ecl_timer_id_t test_id = ecl_timer_list_begin(); + + while (test_id != ECL_TIMER_NO_TIMER) + { + struct ecl_timer_config* ptest = &ptimers[test_id]; + + // Find the correct place to insert. + if (ptimer->delta <= ptest->delta) + { + if (ptest->id == head) + { + head = ptimer->id; + } + + // Insert before ptest-> + ptimer->previous = ptest->previous; + ptest->previous = ptimer->id; + ptimer->next = ptest->id; + + // Adjust the next delta to compensate. + ptest->delta -= ptimer->delta; + + if (ptimer->previous != ECL_TIMER_NO_TIMER) + { + ptimers[ptimer->previous].next = ptimer->id; + } + break; + } + else + { + ptimer->delta -= ptest->delta; + } + + test_id = ecl_timer_list_next(test_id); + } + + // Reached the end? + if (test_id == ECL_TIMER_NO_TIMER) + { + // Tag on to the tail. + ptimers[tail].next = ptimer->id; + ptimer->previous = tail; + ptimer->next = ECL_TIMER_NO_TIMER; + tail = ptimer->id; + } + } +} + +//******************************* +static void ecl_timer_list_remove(ecl_timer_id_t id_, int has_expired) +{ + struct ecl_timer_config* ptimer = &ptimers[id_]; + + if (head == id_) + { + head = ptimer->next; + } + else + { + ptimers[ptimer->previous].next = ptimer->next; + } + + if (tail == id_) + { + tail = ptimer->previous; + } + else + { + ptimers[ptimer->next].previous = ptimer->previous; + } + + if (!has_expired) + { + // Adjust the next delta. + if (ptimer->next != ECL_TIMER_NO_TIMER) + { + ptimers[ptimer->next].delta += ptimer->delta; + } + } + + ptimer->previous = ECL_TIMER_NO_TIMER; + ptimer->next = ECL_TIMER_NO_TIMER; + ptimer->delta = ECL_TIMER_INACTIVE; +} + +//******************************* +static void ecl_timer_list_clear() +{ + ecl_timer_id_t id = ecl_timer_list_begin(); + + while (id != ECL_TIMER_NO_TIMER) + { + struct ecl_timer_config* ptimer = &ptimers[id]; + id = ecl_timer_list_next(id); + ptimer->next = ECL_TIMER_NO_TIMER; + } + + head = ECL_TIMER_NO_TIMER; + tail = ECL_TIMER_NO_TIMER; + current = ECL_TIMER_NO_TIMER; +} + +//***************************************************************************** +// Timer Framework +//***************************************************************************** //******************************************* /// Default initialisation. diff --git a/src/c/ecl_timer_list.c b/src/c/ecl_timer_list.c deleted file mode 100644 index 1e728ff0..00000000 --- a/src/c/ecl_timer_list.c +++ /dev/null @@ -1,201 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2017 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include "ecl_timer.h" -#include "ecl_timer_list.h" - -//************************************************************************* -/// A specialised intrusive linked list for timer data. -//************************************************************************* - -static ecl_timer_id_t head; -static ecl_timer_id_t tail; -static ecl_timer_id_t current; - -struct ecl_timer_config* ptimers; - -void ecl_timer_list_init(struct ecl_timer_config* const ptimers_) -{ - ptimers = ptimers_; - head = ECL_TIMER_NO_TIMER; - tail = ECL_TIMER_NO_TIMER; - current = ECL_TIMER_NO_TIMER; -} - -//******************************* -struct ecl_timer_config* ecl_timer_list_front() -{ - return &ptimers[head]; -} - -//******************************* -ecl_timer_id_t ecl_timer_list_begin() -{ - current = head; - return current; -} - -//******************************* -ecl_timer_id_t ecl_timer_list_previous(ecl_timer_id_t last) -{ - current = ptimers[last].previous; - return current; -} - -//******************************* -ecl_timer_id_t ecl_timer_list_next(ecl_timer_id_t last) -{ - current = ptimers[last].next; - return current; -} - -//******************************* -int ecl_timer_list_empty() -{ - return head == ECL_TIMER_NO_TIMER; -} - -//******************************* -// Inserts the timer at the correct delta position -//******************************* -void ecl_timer_list_insert(ecl_timer_id_t id_) -{ - struct ecl_timer_config* ptimer = &ptimers[id_]; - - if (head == ECL_TIMER_NO_TIMER) - { - // No entries yet. - head = id_; - tail = id_; - ptimer->previous = ECL_TIMER_NO_TIMER; - ptimer->next = ECL_TIMER_NO_TIMER; - } - else - { - // We already have entries. - ecl_timer_id_t test_id = ecl_timer_list_begin(); - - while (test_id != ECL_TIMER_NO_TIMER) - { - struct ecl_timer_config* ptest = &ptimers[test_id]; - - // Find the correct place to insert. - if (ptimer->delta <= ptest->delta) - { - if (ptest->id == head) - { - head = ptimer->id; - } - - // Insert before ptest-> - ptimer->previous = ptest->previous; - ptest->previous = ptimer->id; - ptimer->next = ptest->id; - - // Adjust the next delta to compensate. - ptest->delta -= ptimer->delta; - - if (ptimer->previous != ECL_TIMER_NO_TIMER) - { - ptimers[ptimer->previous].next = ptimer->id; - } - break; - } - else - { - ptimer->delta -= ptest->delta; - } - - test_id = ecl_timer_list_next(test_id); - } - - // Reached the end? - if (test_id == ECL_TIMER_NO_TIMER) - { - // Tag on to the tail. - ptimers[tail].next = ptimer->id; - ptimer->previous = tail; - ptimer->next = ECL_TIMER_NO_TIMER; - tail = ptimer->id; - } - } -} - -//******************************* -void ecl_timer_list_remove(ecl_timer_id_t id_, int has_expired) -{ - struct ecl_timer_config* ptimer = &ptimers[id_]; - - if (head == id_) - { - head = ptimer->next; - } - else - { - ptimers[ptimer->previous].next = ptimer->next; - } - - if (tail == id_) - { - tail = ptimer->previous; - } - else - { - ptimers[ptimer->next].previous = ptimer->previous; - } - - if (!has_expired) - { - // Adjust the next delta. - if (ptimer->next != ECL_TIMER_NO_TIMER) - { - ptimers[ptimer->next].delta += ptimer->delta; - } - } - - ptimer->previous = ECL_TIMER_NO_TIMER; - ptimer->next = ECL_TIMER_NO_TIMER; - ptimer->delta = ECL_TIMER_INACTIVE; -} - -//******************************* -void ecl_timer_list_clear() -{ - ecl_timer_id_t id = ecl_timer_list_begin(); - - while (id != ECL_TIMER_NO_TIMER) - { - struct ecl_timer_config* ptimer = &ptimers[id]; - id = ecl_timer_list_next(id); - ptimer->next = ECL_TIMER_NO_TIMER; - } - - head = ECL_TIMER_NO_TIMER; - tail = ECL_TIMER_NO_TIMER; - current = ECL_TIMER_NO_TIMER; -} diff --git a/src/c/ecl_timer_list.h b/src/c/ecl_timer_list.h deleted file mode 100644 index 7662b48e..00000000 --- a/src/c/ecl_timer_list.h +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2017 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#ifndef __ETL_C_TIMER_FRAMEWORK_LIST__ -#define __ETL_C_TIMER_FRAMEWORK_LIST__ - -#include "ecl_timer.h" - -void ecl_timer_list_init(struct ecl_timer_config* const ptimers_); -struct ecl_timer_config* ecl_timer_list_front(void); -ecl_timer_id_t ecl_timer_list_begin(void); -ecl_timer_id_t ecl_timer_list_previous(ecl_timer_id_t last); -ecl_timer_id_t ecl_timer_list_next(ecl_timer_id_t last); -int ecl_timer_list_empty(void); -void ecl_timer_list_insert(ecl_timer_id_t id_); -void ecl_timer_list_remove(ecl_timer_id_t id_, int has_expired); -void ecl_timer_list_clear(void); - -#endif