Compare commits
4 commits
854f163556
...
ac94fdc304
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac94fdc304 | ||
|
|
2200e58002 | ||
|
|
1761ea38d9 | ||
|
|
5df1d549bd |
3 changed files with 160 additions and 14 deletions
|
|
@ -38,7 +38,7 @@ static bool valid_load(uint16_t val)
|
|||
return false;
|
||||
}
|
||||
|
||||
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||
static uint16_t sample_adc(uint8_t adc_pin)
|
||||
{
|
||||
ADC_Init(adc_pin);
|
||||
ADC_Enable();
|
||||
|
|
@ -46,6 +46,13 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_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);
|
||||
|
|
@ -58,12 +65,8 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
|||
|
||||
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
||||
{
|
||||
ADC_Init(adc_pin);
|
||||
ADC_Enable();
|
||||
ADC_SetPin(adc_pin);
|
||||
uint16_t val = ADC_ReadValue(adc_pin);
|
||||
uint16_t val = sample_adc(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);
|
||||
|
|
@ -73,3 +76,11 @@ 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,5 +45,10 @@ 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,9 +23,14 @@ 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()
|
||||
{
|
||||
|
|
@ -39,18 +44,143 @@ TEST(test_load, LoadPass)
|
|||
CHECK_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(test_load, PortAHandlerSuccess)
|
||||
void setup_adc_expectations(uint8_t adc_pin)
|
||||
{
|
||||
mock().expectOneCall("ADC_Init")
|
||||
.withUnsignedIntParameter("pin_num", 4);
|
||||
.withUnsignedIntParameter("pin_num", adc_pin);
|
||||
|
||||
mock().expectOneCall("ADC_Enable");
|
||||
mock().expectOneCall("ADC_ReadValue_Impl")
|
||||
.withUnsignedIntParameter("pin_num", 4);
|
||||
.withUnsignedIntParameter("pin_num", adc_pin);
|
||||
mock().expectOneCall("ADC_Disable");
|
||||
}
|
||||
|
||||
void expect_porta_disabled(uint8_t load_pin)
|
||||
{
|
||||
mock().expectOneCall("RegEdit_ClearBit")
|
||||
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||
.withUnsignedIntParameter("bit_num", 7);
|
||||
|
||||
Load_HandleLoadPortA(4, 7);
|
||||
.withUnsignedIntParameter("bit_num", load_pin);
|
||||
}
|
||||
|
||||
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