Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development'
Browse files Browse the repository at this point in the history
# Conflicts:
#	library.properties
#	src/callback_timer.h
#	src/message_timer.h
#	test/test_callback_timer.cpp
#	test/test_message_timer.cpp
  • Loading branch information
jwellbelove committed Oct 21, 2017
1 parent a471097 commit 13de62b
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 52 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -9,6 +9,9 @@ test/keil/Debug
test/keil/Release
test/keil/Objects
test/keil/Listings
examples/ArmTimerCallbacks/Listings
examples/ArmTimerCallbacks/Objects
examples/ArmTimerCallbacks/DebugConfig

#################
## Eclipse
Expand All @@ -27,6 +30,7 @@ local.properties
.classpath
.settings/
.loadpath
*.uvguix.John

# External tool builders
.externalToolBuilders/
Expand Down
2 changes: 1 addition & 1 deletion library.properties
@@ -1,5 +1,5 @@
name=Embedded Template Library
version=10.0.1
version=10.0.2
author= John Wellbelove <john.wellbelove@etlcpp.com>
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
sentence=A C++ template library tailored for embedded systems.
Expand Down
60 changes: 31 additions & 29 deletions src/callback_timer.h
Expand Up @@ -57,7 +57,7 @@ namespace etl
previous(etl::timer::id::NO_TIMER),
next(etl::timer::id::NO_TIMER),
repeating(true),
is_c_callback(true)
has_c_callback(true)
{
}

Expand All @@ -75,7 +75,7 @@ namespace etl
previous(etl::timer::id::NO_TIMER),
next(etl::timer::id::NO_TIMER),
repeating(repeating_),
is_c_callback(true)
has_c_callback(true)
{
}

Expand All @@ -93,7 +93,7 @@ namespace etl
previous(etl::timer::id::NO_TIMER),
next(etl::timer::id::NO_TIMER),
repeating(repeating_),
is_c_callback(false)
has_c_callback(false)
{
}

Expand All @@ -120,7 +120,7 @@ namespace etl
uint_least8_t previous;
uint_least8_t next;
bool repeating;
bool is_c_callback;
bool has_c_callback;

private:

Expand Down Expand Up @@ -453,7 +453,6 @@ namespace etl
}

registered_timers = 0;
tick_count = 0;

enable_timer_updates();
}
Expand All @@ -468,42 +467,53 @@ namespace etl
{
if (enabled)
{
if (process_semaphore == 0)
if (process_semaphore.load() == 0)
{
// We have something to do?
if (!active_list.empty())
{
tick_count += count;
bool has_active = !active_list.empty();

while (!active_list.empty() && (tick_count >= active_list.front().delta))
if (has_active)
{
while (has_active && (count >= active_list.front().delta))
{
etl::callback_timer_data& timer = active_list.front();

tick_count -= timer.delta;
count -= timer.delta;

active_list.remove(timer.id, true);

if (timer.repeating)
{
// Reinsert the timer.
timer.delta = timer.period;
active_list.insert(timer.id);
}

if (timer.p_callback != nullptr)
{
if (timer.is_c_callback)
if (timer.has_c_callback)
{
// Call the C callback.
reinterpret_cast<void(*)()>(timer.p_callback)();
}
else
{
// Call the function wrapper callback.
(*reinterpret_cast<etl::ifunction<void>*>(timer.p_callback))();
}
}

has_active = !active_list.empty();
}

return true;
if (has_active)
{
// Subtract any remainder from the next due timeout.
active_list.front().delta -= count;
}
}

return true;
}
}

Expand All @@ -515,18 +525,18 @@ namespace etl
//*******************************************
bool start(etl::timer::id::type id_, bool immediate_ = false)
{
bool result = false;

disable_timer_updates();

bool result = false;

// Valid timer id?
if (id_ != etl::timer::id::NO_TIMER)
{
etl::callback_timer_data& timer = timer_array[id_];

// Registered timer?
if (timer.id != etl::timer::id::NO_TIMER)
{
{
// Has a valid period.
if (timer.period != etl::timer::state::INACTIVE)
{
Expand All @@ -535,17 +545,11 @@ namespace etl
active_list.remove(timer.id, false);
}

// Compensate for current tick count.
timer.delta = tick_count;

if (!immediate_)
{
timer.delta += timer.period;
}

timer.delta = immediate_ ? 0 : timer.period;
active_list.insert(timer.id);

result = true;
}
}
}
}

Expand All @@ -559,10 +563,10 @@ namespace etl
//*******************************************
bool stop(etl::timer::id::type id_)
{
bool result = false;

disable_timer_updates();

bool result = false;

// Valid timer id?
if (id_ != etl::timer::id::NO_TIMER)
{
Expand Down Expand Up @@ -622,7 +626,6 @@ namespace etl
active_list(timer_array_),
enabled(false),
process_semaphore(0),
tick_count(0),
registered_timers(0),
MAX_TIMERS(MAX_TIMERS_)
{
Expand Down Expand Up @@ -654,7 +657,6 @@ namespace etl

volatile bool enabled;
volatile etl::timer_semaphore_t process_semaphore;
volatile uint32_t tick_count;
volatile uint_least8_t registered_timers;

public:
Expand Down
36 changes: 18 additions & 18 deletions src/message_timer.h
Expand Up @@ -40,6 +40,7 @@ SOFTWARE.
#include "message_bus.h"
#include "static_assert.h"
#include "timer.h"
#include "atomic.h"

#undef ETL_FILE
#define ETL_FILE "41"
Expand Down Expand Up @@ -417,7 +418,6 @@ namespace etl
}

registered_timers = 0;
tick_count = 0;

enable_timer_updates();
}
Expand All @@ -432,18 +432,18 @@ namespace etl
{
if (enabled)
{
if (process_semaphore == 0)
if (process_semaphore.load() == 0)
{
// We have something to do?
if (!active_list.empty())
{
tick_count += count;
bool has_active = !active_list.empty();

while (!active_list.empty() && (tick_count >= active_list.front().delta))
if (has_active)
{
while (has_active && (count >= active_list.front().delta))
{
etl::message_timer_data& timer = active_list.front();

tick_count -= timer.delta;
count -= timer.delta;

active_list.remove(timer.id, true);

Expand All @@ -467,10 +467,18 @@ namespace etl
timer.p_router->receive(*(timer.p_message));
}
}

has_active = !active_list.empty();
}

return true;
if (has_active)
{
// Subtract any remainder from the next due timeout.
active_list.front().delta -= count;
}
}

return true;
}
}

Expand Down Expand Up @@ -502,15 +510,9 @@ namespace etl
active_list.remove(timer.id, false);
}

// Compensate for current tick count.
timer.delta = tick_count;

if (!immediate_)
{
timer.delta += timer.period;
}

timer.delta = immediate_ ? 0 : timer.period;
active_list.insert(timer.id);

result = true;
}
}
Expand Down Expand Up @@ -589,7 +591,6 @@ namespace etl
active_list(timer_array_),
enabled(false),
process_semaphore(0),
tick_count(0),
registered_timers(0),
MAX_TIMERS(MAX_TIMERS_)
{
Expand Down Expand Up @@ -621,7 +622,6 @@ namespace etl

volatile bool enabled;
volatile etl::timer_semaphore_t process_semaphore;
volatile uint32_t tick_count;
volatile uint_least8_t registered_timers;

public:
Expand Down

0 comments on commit 13de62b

Please sign in to comment.