Updated the load module to one-shot the disable of pins baesd on load.
This commit is contained in:
parent
73e99fc3b9
commit
5405e4b8b6
|
@ -22,6 +22,18 @@
|
|||
#include "MockRegEdit.h"
|
||||
#endif
|
||||
|
||||
//These two arrays allow us to track the A and B ports to know when
|
||||
//one has been disabled before.
|
||||
static bool porta_disabled[8] = {0};
|
||||
static bool portb_disabled[8] = {0};
|
||||
|
||||
static bool valid_load(uint16_t val)
|
||||
{
|
||||
if(val > 527 && val < 1000) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||
|
@ -32,12 +44,13 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
|||
uint16_t val = ADC_ReadValue(adc_pin);
|
||||
|
||||
ADC_Disable();
|
||||
if(val > 527 && val < 1000){
|
||||
if(valid_load(val) && !porta_disabled[adc_pin]){
|
||||
RegEdit_SetBit((void *) &PORTA.DIR, out_pin);
|
||||
RegEdit_SetBit((void *) &PORTA.OUT, out_pin);
|
||||
}
|
||||
else{
|
||||
RegEdit_ClearBit((void *) &PORTA.OUT, out_pin);
|
||||
porta_disabled[adc_pin] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,11 +62,12 @@ void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
|
|||
uint16_t val = ADC_ReadValue(adc_pin);
|
||||
|
||||
ADC_Disable();
|
||||
if(val > 527 && val < 1000){
|
||||
if(valid_load(val) && !portb_disabled[adc_pin]){
|
||||
RegEdit_SetBit((void *) &PORTB.DIR, out_pin);
|
||||
RegEdit_SetBit((void *) &PORTB.OUT, out_pin);
|
||||
}
|
||||
else{
|
||||
RegEdit_ClearBit((void *) &PORTB.OUT, out_pin);
|
||||
portb_disabled[adc_pin] = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,10 +47,15 @@ TEST(test_load, PortAHandlerSuccess)
|
|||
mock().expectOneCall("ADC_Enable");
|
||||
mock().expectOneCall("ADC_ReadValue_Impl")
|
||||
.withUnsignedIntParameter("pin_num", 4);
|
||||
|
||||
mock().expectOneCall("ADC_Disable");
|
||||
|
||||
mock().expectOneCall("RegEdit_ClearBit")
|
||||
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||
.withUnsignedIntParameter("bit_num", 7);
|
||||
|
||||
Load_HandleLoadPortA(4, 7);
|
||||
}
|
||||
|
||||
|
||||
//Need to setup a one-shot or way for it to only enable once.
|
||||
|
|
Loading…
Reference in New Issue