Skip to content

Commit 54014db

Browse files
Added normal timer mode
1 parent f15a072 commit 54014db

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

include/NextagEmbeddedPlatform/chips/atmega328p/descriptor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ struct Atmega328pDescriptor
3131
static volatile uint8_t & counter;
3232
static volatile uint8_t & interrupt;
3333

34-
// static constexpr uint8_t timerModeMask = _BV(CS00) | _BV(CS01) | _BV(CS02);
34+
static constexpr uint8_t timerModeMask = _BV(CS00) | _BV(CS01) | _BV(CS02);
3535
enum class TimerMode
3636
{
37+
NORMAL = createCombinedRegisterValue(0, 0),
3738
CTC = createCombinedRegisterValue(_BV(WGM01), 0)
3839
};
3940

include/NextagEmbeddedPlatform/concepts/drivers/timer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ concept HasTimerInterrupt = requires(T t) {
5252
template <typename T>
5353
concept HasTimerMode = requires(T t) {
5454
typename T::TimerMode;
55+
T::timerModeMask;
5556
};
5657

5758
template <typename T>

include/NextagEmbeddedPlatform/drivers/timer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ template <typename TimerDescriptor>
1717
class Timer
1818
{
1919
public:
20+
using Descriptor = TimerDescriptor;
2021
using TimerMode = typename TimerDescriptor::TimerMode;
2122
using ClockSelect = typename TimerDescriptor::ClockSelect;
2223
using Interrupt = typename TimerDescriptor::Interrupt;
@@ -27,6 +28,7 @@ class Timer
2728
static void setMode(TimerMode timerMode)
2829
requires HasCombinedTimerMode<TimerDescriptor>
2930
{
31+
TimerDescriptor::controlAB &= ~TimerDescriptor::timerModeMask;
3032
TimerDescriptor::controlAB |= static_cast<uint16_t>(timerMode);
3133
}
3234

tests/drivers/timer/timer0_tests.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,27 @@ class Timer0Tests : public NextagTest::Test
3030
}
3131
};
3232

33+
TEST_F(Timer0Tests, SetModeToNormal_SetsCorrectRegisters)
34+
{
35+
Timer0::setMode(Timer0::TimerMode::NORMAL);
36+
TEST_ASSERT_BITS_LOW(_BV(WGM01) | _BV(WGM00), TCCR0A);
37+
TEST_ASSERT_BIT_LOW(_BV(WGM02), TCCR0B);
38+
}
39+
3340
TEST_F(Timer0Tests, SetModeToCTC_SetsCorrectRegisters)
3441
{
3542
Timer0::setMode(Timer0::TimerMode::CTC);
3643
TEST_ASSERT_BITS_HIGH(_BV(WGM01), TCCR0A);
44+
TEST_ASSERT_BITS_LOW(_BV(WGM00), TCCR0A);
45+
TEST_ASSERT_BITS_LOW(_BV(WGM02), TCCR0B);
46+
}
47+
48+
TEST_F(Timer0Tests, SetModeToNormal_AfterSetToCTC_SetsCorrectRegisters)
49+
{
50+
Timer0::setMode(Timer0::TimerMode::CTC);
51+
Timer0::setMode(Timer0::TimerMode::NORMAL);
52+
TEST_ASSERT_BITS_LOW(_BV(WGM01) | _BV(WGM00), TCCR0A);
53+
TEST_ASSERT_BIT_LOW(_BV(WGM02), TCCR0B);
3754
}
3855

3956
TEST_F(Timer0Tests, SetClockSource_SetsCorrectRegisterValue)

0 commit comments

Comments
 (0)