File tree Expand file tree Collapse file tree
include/NextagEmbeddedPlatform Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ concept HasTimerInterrupt = requires(T t) {
5252template <typename T>
5353concept HasTimerMode = requires (T t) {
5454 typename T::TimerMode;
55+ T::timerModeMask;
5556};
5657
5758template <typename T>
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ template <typename TimerDescriptor>
1717class Timer
1818{
1919public:
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
Original file line number Diff line number Diff 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+
3340TEST_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
3956TEST_F (Timer0Tests, SetClockSource_SetsCorrectRegisterValue)
You can’t perform that action at this time.
0 commit comments