| 1 |
#include "unity.h" |
| 2 |
#include "Types.h" |
| 3 |
#include "TimerConfigurator.h" |
| 4 |
#include "AT91SAM7X256.h" |
| 5 |
#include "MockTimerInterruptConfigurator.h" |
| 6 |
|
| 7 |
AT91S_PMC PmcPeripheral; |
| 8 |
AT91S_TC TimerCounter0Peripheral; |
| 9 |
AT91S_PIO PioBPeripheral; |
| 10 |
|
| 11 |
void setUp(void) |
| 12 |
{ |
| 13 |
} |
| 14 |
|
| 15 |
void tearDown(void) |
| 16 |
{ |
| 17 |
} |
| 18 |
|
| 19 |
void testEnablePeripheralClocksShouldEnableClockToTimer0Peripheral(void) |
| 20 |
{ |
| 21 |
AT91C_BASE_PMC->PMC_PCER = 0; |
| 22 |
Timer_EnablePeripheralClocks(); |
| 23 |
TEST_ASSERT_EQUAL( |
| 24 |
TIMER0_CLOCK_ENABLE, |
| 25 |
AT91C_BASE_PMC->PMC_PCER & TIMER0_CLOCK_ENABLE); |
| 26 |
} |
| 27 |
|
| 28 |
void testEnablePeripheralClocksShouldEnableClockToPIOBPeripheral(void) |
| 29 |
{ |
| 30 |
AT91C_BASE_PMC->PMC_PCER = 0; |
| 31 |
Timer_EnablePeripheralClocks(); |
| 32 |
TEST_ASSERT_EQUAL( |
| 33 |
PIOB_CLOCK_ENABLE, |
| 34 |
AT91C_BASE_PMC->PMC_PCER & PIOB_CLOCK_ENABLE); |
| 35 |
} |
| 36 |
|
| 37 |
void testResetShouldSetTimer0ClockDisableBit_DisableTimer0Interrupts_ClearStatusRegister(void) |
| 38 |
{ |
| 39 |
AT91C_BASE_TC0->TC_CCR = 0; |
| 40 |
AT91C_BASE_TC0->TC_IDR = 0; |
| 41 |
AT91C_BASE_TC0->TC_SR = 0xFFFFFFFF; |
| 42 |
Timer_Reset(); |
| 43 |
TEST_ASSERT_EQUAL(0x00000002, AT91C_BASE_TC0->TC_CCR); |
| 44 |
TEST_ASSERT_EQUAL(0xffffffff, AT91C_BASE_TC0->TC_IDR); |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
void testEnableOutputPinShouldEnable_TIOA0_DigitalOutput(void) |
| 49 |
{ |
| 50 |
AT91C_BASE_PIOB->PIO_PDR = 0; |
| 51 |
Timer_EnableOutputPin(); |
| 52 |
TEST_ASSERT_EQUAL(TIOA0_PIN_MASK, AT91C_BASE_PIOB->PIO_PDR); |
| 53 |
} |
| 54 |
|
| 55 |
void testConfigureModeShouldConfigureTimer0ClockSourceForMasterClockDividedBy1024(void) |
| 56 |
{ |
| 57 |
AT91C_BASE_TC0->TC_CMR = 0; |
| 58 |
Timer_ConfigureMode(); |
| 59 |
TEST_ASSERT_EQUAL(0x00000004, AT91C_BASE_TC0->TC_CMR & 0x00000007); |
| 60 |
} |
| 61 |
|
| 62 |
void testConfigureModeShouldConfigureTimer0ForWaveGeneration(void) |
| 63 |
{ |
| 64 |
AT91C_BASE_TC0->TC_CMR = 0; |
| 65 |
Timer_ConfigureMode(); |
| 66 |
TEST_ASSERT_EQUAL(0x00008000, AT91C_BASE_TC0->TC_CMR & 0x00008000); |
| 67 |
} |
| 68 |
|
| 69 |
void testConfigureModeShouldConfigureTimer0ForUpModeWithAutomaticTriggerOnRCCompare(void) |
| 70 |
{ |
| 71 |
AT91C_BASE_TC0->TC_CMR = 0; |
| 72 |
Timer_ConfigureMode(); |
| 73 |
TEST_ASSERT_EQUAL(0x00004000, AT91C_BASE_TC0->TC_CMR & 0x00006000); |
| 74 |
} |
| 75 |
|
| 76 |
void testConfigureModeShouldConfigureTimer0ToToggleTIOAOnRCCompare(void) |
| 77 |
{ |
| 78 |
AT91C_BASE_TC0->TC_CMR = 0; |
| 79 |
Timer_ConfigureMode(); |
| 80 |
TEST_ASSERT_EQUAL(0x000C0000, AT91C_BASE_TC0->TC_CMR & 0x000C0000); |
| 81 |
} |
| 82 |
|
| 83 |
void testConfigurePeriodShouldConfigureRegisterCFor10msInterval(void) |
| 84 |
{ |
| 85 |
AT91C_BASE_TC0->TC_RC = 0; |
| 86 |
Timer_ConfigurePeriod(); |
| 87 |
TEST_ASSERT_EQUAL(469, AT91C_BASE_TC0->TC_RC); |
| 88 |
} |
| 89 |
|
| 90 |
void testEnableShouldSetEnableFlagForTimer0(void) |
| 91 |
{ |
| 92 |
AT91C_BASE_TC0->TC_CCR = 0; |
| 93 |
Timer_Enable(); |
| 94 |
TEST_ASSERT_EQUAL_INT(1, AT91C_BASE_TC0->TC_CCR); |
| 95 |
} |
| 96 |
|
| 97 |
void testConfigureInterruptHandler(void) |
| 98 |
{ |
| 99 |
Timer_DisableInterrupt_Expect(); |
| 100 |
Timer_ResetSystemTime_Expect(); |
| 101 |
Timer_ConfigureInterrupt_Expect(); |
| 102 |
Timer_EnableInterrupt_Expect(); |
| 103 |
|
| 104 |
Timer_ConfigureInterruptHandler(); |
| 105 |
} |
| 106 |
|
| 107 |
void testStartShouldSetSoftwareTriggerFlag(void) |
| 108 |
{ |
| 109 |
AT91C_BASE_TC0->TC_CCR = 0; |
| 110 |
Timer_Start(); |
| 111 |
TEST_ASSERT_EQUAL(0x04, AT91C_BASE_TC0->TC_CCR); |
| 112 |
} |