Compare commits
No commits in common. "ac94fdc304b803b3a31ec536a2f01e4d51e2c8c4" and "854f1635569b69865dce41e54d16a2240384ef17" have entirely different histories.
ac94fdc304
...
854f163556
3 changed files with 13 additions and 159 deletions
|
|
@ -38,7 +38,7 @@ static bool valid_load(uint16_t val)
|
|||
return false;
|
||||
}
|
||||
|
||||
static uint16_t sample_adc(uint8_t adc_pin)
|
||||
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||
{
|
||||
ADC_Init(adc_pin);
|
||||
ADC_Enable();
|
||||
|
|
@ -46,13 +46,6 @@ static uint16_t sample_adc(uint8_t adc_pin)
|
|||
uint16_t val = ADC_ReadValue(adc_pin);
|
||||
|
||||
ADC_Disable();
|
||||
return val;
|
||||
}
|
||||
|
||||
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||
{
|
||||
uint16_t val = sample_adc(adc_pin);
|
||||
|
||||
if(valid_load(val) && !porta_disabled[adc_pin]){
|
||||
RegEdit_SetBit((void *) &PORTA.DIR, out_pin);
|
||||
RegEdit_SetBit((void *) &PORTA.OUT, out_pin);
|
||||
|
|
@ -65,8 +58,12 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
|||
|
||||
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
||||
{
|
||||
uint16_t val = sample_adc(adc_pin);
|
||||
ADC_Init(adc_pin);
|
||||
ADC_Enable();
|
||||
ADC_SetPin(adc_pin);
|
||||
uint16_t val = ADC_ReadValue(adc_pin);
|
||||
|
||||
ADC_Disable();
|
||||
if(valid_load(val) && !portb_disabled[adc_pin]){
|
||||
RegEdit_SetBit((void *) &PORTB.DIR, out_pin);
|
||||
RegEdit_SetBit((void *) &PORTB.OUT, out_pin);
|
||||
|
|
@ -76,11 +73,3 @@ void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
|||
portb_disabled[adc_pin] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Load_SoftResetDisabledLoads()
|
||||
{
|
||||
for(int i = 0; i < 8; i++){
|
||||
porta_disabled[i] = false;
|
||||
portb_disabled[i] = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,10 +45,5 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin);
|
|||
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Resets the disabled array state.
|
||||
*/
|
||||
void Load_SoftResetDisabledLoads(void);
|
||||
|
||||
#endif /* LOAD_H */
|
||||
|
||||
|
|
|
|||
|
|
@ -23,14 +23,9 @@ extern "C"
|
|||
|
||||
TEST_GROUP(test_load)
|
||||
{
|
||||
uint8_t adc_pin;
|
||||
uint8_t load_pin;
|
||||
void setup()
|
||||
{
|
||||
adc_pin = 4;
|
||||
load_pin = 7;
|
||||
MockADC_ZeroIndex();
|
||||
Load_SoftResetDisabledLoads();
|
||||
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
|
|
@ -44,143 +39,18 @@ TEST(test_load, LoadPass)
|
|||
CHECK_TRUE(true);
|
||||
}
|
||||
|
||||
void setup_adc_expectations(uint8_t adc_pin)
|
||||
TEST(test_load, PortAHandlerSuccess)
|
||||
{
|
||||
mock().expectOneCall("ADC_Init")
|
||||
.withUnsignedIntParameter("pin_num", adc_pin);
|
||||
.withUnsignedIntParameter("pin_num", 4);
|
||||
|
||||
mock().expectOneCall("ADC_Enable");
|
||||
mock().expectOneCall("ADC_ReadValue_Impl")
|
||||
.withUnsignedIntParameter("pin_num", adc_pin);
|
||||
.withUnsignedIntParameter("pin_num", 4);
|
||||
mock().expectOneCall("ADC_Disable");
|
||||
}
|
||||
|
||||
void expect_porta_disabled(uint8_t load_pin)
|
||||
{
|
||||
mock().expectOneCall("RegEdit_ClearBit")
|
||||
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||
.withUnsignedIntParameter("bit_num", load_pin);
|
||||
.withUnsignedIntParameter("bit_num", 7);
|
||||
|
||||
Load_HandleLoadPortA(4, 7);
|
||||
}
|
||||
|
||||
void expect_porta_enabled(uint8_t load_pin)
|
||||
{
|
||||
mock().expectOneCall("RegEdit_SetBit")
|
||||
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
||||
.withUnsignedIntParameter("bit_num", load_pin);
|
||||
|
||||
mock().expectOneCall("RegEdit_SetBit")
|
||||
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||
.withUnsignedIntParameter("bit_num", load_pin);
|
||||
}
|
||||
|
||||
void expect_portb_disabled(uint8_t load_pin)
|
||||
{
|
||||
mock().expectOneCall("RegEdit_ClearBit")
|
||||
.withPointerParameter("reg", (void *) &PORTB.OUT)
|
||||
.withUnsignedIntParameter("bit_num", load_pin);
|
||||
}
|
||||
|
||||
|
||||
void expect_portb_enabled(uint8_t load_pin)
|
||||
{
|
||||
mock().expectOneCall("RegEdit_SetBit")
|
||||
.withPointerParameter("reg", (void *) &PORTB.DIR)
|
||||
.withUnsignedIntParameter("bit_num", load_pin);
|
||||
|
||||
mock().expectOneCall("RegEdit_SetBit")
|
||||
.withPointerParameter("reg", (void *) &PORTB.OUT)
|
||||
.withUnsignedIntParameter("bit_num", load_pin);
|
||||
}
|
||||
|
||||
TEST(test_load, PortAHandlerDisabledHigh)
|
||||
{
|
||||
MockADC_PushValue(HIGHTHRESH);
|
||||
|
||||
setup_adc_expectations(adc_pin);
|
||||
expect_porta_disabled(load_pin);
|
||||
|
||||
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||
}
|
||||
|
||||
TEST(test_load, PortAHandlerDisabledLow)
|
||||
{
|
||||
MockADC_PushValue(LOWTHRESH);
|
||||
|
||||
setup_adc_expectations(adc_pin);
|
||||
expect_porta_disabled(load_pin);
|
||||
|
||||
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||
}
|
||||
|
||||
TEST(test_load, PortAHandlerEnabledWhenValid)
|
||||
{
|
||||
MockADC_PushValue(HIGHTHRESH - 1);
|
||||
|
||||
setup_adc_expectations(adc_pin);
|
||||
expect_porta_enabled(load_pin);
|
||||
|
||||
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||
}
|
||||
|
||||
TEST(test_load, PortAHandlerDisblesUntilPowerReset)
|
||||
{
|
||||
MockADC_PushValue(HIGHTHRESH - 1);
|
||||
MockADC_PushValue(HIGHTHRESH);
|
||||
|
||||
setup_adc_expectations(adc_pin);
|
||||
expect_porta_disabled(load_pin);
|
||||
|
||||
setup_adc_expectations(adc_pin);
|
||||
expect_porta_disabled(load_pin);
|
||||
|
||||
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(test_load, PortBHandlerDisabledHigh)
|
||||
{
|
||||
MockADC_PushValue(HIGHTHRESH);
|
||||
|
||||
setup_adc_expectations(adc_pin);
|
||||
expect_portb_disabled(load_pin);
|
||||
|
||||
Load_HandleLoadPortB(adc_pin, load_pin);
|
||||
}
|
||||
|
||||
TEST(test_load, PortBHandlerDisabledLow)
|
||||
{
|
||||
MockADC_PushValue(LOWTHRESH);
|
||||
|
||||
setup_adc_expectations(adc_pin);
|
||||
expect_portb_disabled(load_pin);
|
||||
|
||||
Load_HandleLoadPortB(adc_pin, load_pin);
|
||||
}
|
||||
|
||||
TEST(test_load, PortBHandlerEnabledWhenValid)
|
||||
{
|
||||
MockADC_PushValue(HIGHTHRESH - 1);
|
||||
|
||||
setup_adc_expectations(adc_pin);
|
||||
expect_portb_enabled(load_pin);
|
||||
|
||||
Load_HandleLoadPortB(adc_pin, load_pin);
|
||||
}
|
||||
|
||||
TEST(test_load, PortBHandlerDisblesUntilPowerReset)
|
||||
{
|
||||
MockADC_PushValue(HIGHTHRESH - 1);
|
||||
MockADC_PushValue(HIGHTHRESH);
|
||||
|
||||
setup_adc_expectations(adc_pin);
|
||||
expect_portb_disabled(load_pin);
|
||||
|
||||
setup_adc_expectations(adc_pin);
|
||||
expect_portb_disabled(load_pin);
|
||||
|
||||
Load_HandleLoadPortB(adc_pin, load_pin);
|
||||
Load_HandleLoadPortB(adc_pin, load_pin);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue