162 lines
4.2 KiB
C++
162 lines
4.2 KiB
C++
/*
|
|
* Author: username
|
|
* Date: todays_date
|
|
* filename: test_wwdg.c
|
|
* description: module_purpose
|
|
*/
|
|
|
|
#include "CppUTest/CommandLineTestRunner.h"
|
|
#include "CppUTestExt/MockSupport.h"
|
|
|
|
extern "C"
|
|
{
|
|
#include "ch32fun.h"
|
|
#include "wwdg.h"
|
|
}
|
|
|
|
TEST_GROUP(tg_wwdg)
|
|
{
|
|
void setup()
|
|
{
|
|
|
|
}
|
|
void teardown()
|
|
{
|
|
mock().checkExpectations();
|
|
mock().clear();
|
|
}
|
|
};
|
|
|
|
|
|
TEST(tg_wwdg, EnableCallsCorrectFunctiions)
|
|
{
|
|
//The APB1 contains the WWDG peripheral.
|
|
mock().expectOneCall("RegEdit_u32_SetBit")
|
|
.withPointerParameter("reg", (void *)&RCC->APB1PCENR)
|
|
.withUnsignedIntParameter("bit_num", RCC_WWDGEN_BIT);
|
|
|
|
mock().expectOneCall("RegEdit_u32_SetBit")
|
|
.withPointerParameter("reg", (void *)&WWDG->CTLR)
|
|
.withUnsignedIntParameter("bit_num", WWDG_CTLR_WDGA_BIT);
|
|
|
|
wwdg_enable();
|
|
}
|
|
|
|
TEST(tg_wwdg, DisableWWDG_DisablesPeriphClock)
|
|
{
|
|
mock().expectOneCall("RegEdit_u32_ClearBit")
|
|
.withPointerParameter("reg", (void *)&RCC->APB1PCENR)
|
|
.withUnsignedIntParameter("bit_num", RCC_WWDGEN_BIT);
|
|
wwdg_disable();
|
|
}
|
|
|
|
TEST(tg_wwdg, SetClockDivReturnsFalseOnInvalidValues)
|
|
{
|
|
for(uint8_t i = 4; i > 10; i++){
|
|
CHECK_FALSE(wwdg_set_clock_div(i));
|
|
}
|
|
}
|
|
|
|
TEST(tg_wwdg, SetClockDivReturnsTrueOnValidValues)
|
|
{
|
|
for(uint8_t i = 0; i <= 3; i++){
|
|
mock().expectOneCall("RegEdit_u16_ClearBit")
|
|
.withPointerParameter("reg", (void *)&WWDG->CFGR)
|
|
.withUnsignedIntParameter("bit_num", 7);
|
|
mock().expectOneCall("RegEdit_u16_ClearBit")
|
|
.withPointerParameter("reg", (void *)&WWDG->CFGR)
|
|
.withUnsignedIntParameter("bit_num", 8);
|
|
|
|
mock().expectOneCall("RegEdit_u16_OR_Num")
|
|
.withPointerParameter("reg", (void *)&WWDG->CFGR)
|
|
.withUnsignedIntParameter("num", i);
|
|
}
|
|
|
|
for(uint8_t i = 0; i <= 3; i++){
|
|
CHECK_TRUE(wwdg_set_clock_div(i));
|
|
}
|
|
}
|
|
|
|
|
|
TEST(tg_wwdg, SetWindowCounterReturnsFalseOnInvalidInputs)
|
|
{
|
|
//We take all zeros logically and'd with the first six bits inverted.
|
|
//uint16_t mask = UINT16_MAX & ~127; //0xFF80
|
|
uint8_t value = 0;
|
|
bool ret = true;
|
|
|
|
for(value = 0; value < 0x3F; value++){
|
|
ret = wwdg_set_window(value);
|
|
CHECK_EQUAL(false, ret);
|
|
}
|
|
for(value = 128; value < 255; value++){
|
|
ret = wwdg_set_window(value);
|
|
CHECK_EQUAL(false, ret);
|
|
}
|
|
}
|
|
|
|
TEST(tg_wwdg, SetWindowCounterReturnsTrueOnValidInputs)
|
|
{
|
|
//We take all zeros logically and'd with the first six bits inverted.
|
|
uint16_t mask = UINT16_MAX & ~127; //0xFF80
|
|
uint8_t value = 0;
|
|
bool ret = true;
|
|
|
|
for(value = 0x40; value <= 127; value++){
|
|
//The first bits 0:6 need to be cleared before being set.
|
|
mock().expectOneCall("RegEdit_u16_AND_Num")
|
|
.withPointerParameter("reg", (void *)&WWDG->CFGR)
|
|
.withUnsignedIntParameter("num", mask);
|
|
|
|
mock().expectOneCall("RegEdit_u16_OR_Num")
|
|
.withPointerParameter("reg", (void *)&WWDG->CFGR)
|
|
.withUnsignedIntParameter("num", value);
|
|
}
|
|
|
|
for(value = 0x40; value <= 127; value++){
|
|
ret = wwdg_set_window(value);
|
|
CHECK_EQUAL(true, ret);
|
|
}
|
|
}
|
|
|
|
TEST(tg_wwdg, SetEalryWakeUpSetsBit)
|
|
{
|
|
mock().expectOneCall("RegEdit_u16_SetBit")
|
|
.withPointerParameter("reg", (void *)&WWDG->CFGR)
|
|
.withUnsignedIntParameter("bit_num", WWDG_EWI_BIT);
|
|
|
|
wwdg_enable_interrupt();
|
|
}
|
|
|
|
|
|
TEST(tg_wwdg, ClearEalyWakeUpClearsBit)
|
|
{
|
|
mock().expectOneCall("RegEdit_u16_ClearBit")
|
|
.withPointerParameter("reg", (void *)&WWDG->CFGR)
|
|
.withUnsignedIntParameter("bit_num", WWDG_EWI_BIT);
|
|
|
|
wwdg_disable_interrupt();
|
|
}
|
|
|
|
TEST(tg_wwdg, ResetFunctionSetsRegister)
|
|
{
|
|
//uint16_t fake_reg = 0;
|
|
uint16_t reset_value = 126;
|
|
|
|
/*
|
|
mock().expectOneCall("RegEdit_u16_ReadReg")
|
|
.withPointerParameter("reg", (void *)&WWDG->CTLR);
|
|
//.andReturnValue();
|
|
*/
|
|
|
|
mock().expectOneCall("RegEdit_u16_AND_Num")
|
|
.withPointerParameter("reg", (void *)&WWDG->CTLR)
|
|
.withUnsignedIntParameter("num", 0xFF80);
|
|
|
|
mock().expectOneCall("RegEdit_u16_OR_Num")
|
|
.withPointerParameter("reg", (void *)&WWDG->CTLR)
|
|
.withUnsignedIntParameter("num", reset_value);
|
|
|
|
CHECK_TRUE(wwdg_reset_timer(reset_value));
|
|
}
|
|
|