Compare commits

..

No commits in common. "004f8f3bb5e32400008051602d00eaccfabed4df" and "ea7341d6c8a6cc71165d5bb3e115a7516d1c1339" have entirely different histories.

5 changed files with 22 additions and 185 deletions

View file

@ -22,23 +22,21 @@
#include "MockRegEdit.h" #include "MockRegEdit.h"
#endif #endif
//These two arrays allow us to track the A and B ports to know when //These two arrays allow us to track the A and B ports to know when
//one has been disabled before. //one has been disabled before.
static bool porta_disabled[8] = {0}; static bool porta_disabled[8] = {0};
static bool portb_disabled[8] = {0}; static bool portb_disabled[8] = {0};
static bool valid_load(uint16_t val) static bool valid_load(uint16_t val)
{ {
if(val > LOWTHRESH && val < HIGHTHRESH) { if(val > 527 && val < 1000) {
return true; return true;
} }
return false; 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_Init(adc_pin);
ADC_Enable(); ADC_Enable();
@ -46,13 +44,6 @@ static uint16_t sample_adc(uint8_t adc_pin)
uint16_t val = ADC_ReadValue(adc_pin); uint16_t val = ADC_ReadValue(adc_pin);
ADC_Disable(); 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]){ if(valid_load(val) && !porta_disabled[adc_pin]){
RegEdit_SetBit((void *) &PORTA.DIR, out_pin); RegEdit_SetBit((void *) &PORTA.DIR, out_pin);
RegEdit_SetBit((void *) &PORTA.OUT, out_pin); RegEdit_SetBit((void *) &PORTA.OUT, out_pin);
@ -65,8 +56,12 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
void Load_HandleLoadPortB(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]){ if(valid_load(val) && !portb_disabled[adc_pin]){
RegEdit_SetBit((void *) &PORTB.DIR, out_pin); RegEdit_SetBit((void *) &PORTB.DIR, out_pin);
RegEdit_SetBit((void *) &PORTB.OUT, out_pin); RegEdit_SetBit((void *) &PORTB.OUT, out_pin);
@ -76,11 +71,3 @@ void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
portb_disabled[adc_pin] = true; portb_disabled[adc_pin] = true;
} }
} }
void Load_SoftResetDisabledLoads()
{
for(int i = 0; i < 8; i++){
porta_disabled[i] = false;
portb_disabled[i] = false;
}
}

View file

@ -10,45 +10,23 @@
#ifndef LOAD_H #ifndef LOAD_H
#define LOAD_H #define LOAD_H
#include <stdint.h>
/** /**
* @brief Low Threshold * @brief Low Threshold
* Anything below or equal to the value will cause the pin to lock into the disabled *
* state.
*/ */
#define LOWTHRESH 517 #define LOWTHRESH 527
/** /**
* @brief High Threshold * @brief High Threshold
* Anything equal or above the value will cause the pin to lock into the disabled *
* state.
*/ */
#define HIGHTHRESH 830 #define HIGHTHRESH 1000
/**
* @brief Checks if the adc pin is inbetween LOWTHRESH and HIGHTHRESH and then
* sets or disables the output pin on PORTA.
* @param adc_pin the pin number that the load value is read from.
* @param out_pin The pin that is set high if the adc_pin input is valid.
*/
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin); void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin);
/**
* @brief Checks if the adc pin is inbetween LOWTHRESH and HIGHTHRESH and then
* sets or disables the output pin on PORTB.
* @param adc_pin the pin number that the load value is read from.
* @param out_pin The pin that is set high if the adc_pin input is valid.
*/
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin); void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin);
void Load_HandlePinLoads(void);
/**
* @brief Resets the disabled array state.
*/
void Load_SoftResetDisabledLoads(void);
#endif /* LOAD_H */ #endif /* LOAD_H */

View file

@ -9,7 +9,6 @@ add_subdirectory(RegEdit)
add_subdirectory(simple_test) add_subdirectory(simple_test)
add_subdirectory(zero_cross_detection) add_subdirectory(zero_cross_detection)
add_subdirectory(TriacOut) add_subdirectory(TriacOut)
add_subdirectory(load)
# TEST_RUNNER # TEST_RUNNER
@ -34,7 +33,6 @@ add_executable(Mock_Tests
target_link_libraries(Mock_Tests target_link_libraries(Mock_Tests
${CPPUTEST_LIBRARIES}/libCppUTest.a ${CPPUTEST_LIBRARIES}/libCppUTest.a
${CPPUTEST_LIBRARIES}/libCppUTestExt.a ${CPPUTEST_LIBRARIES}/libCppUTestExt.a
test_load
test_MockRegEdit test_MockRegEdit
test_MockADC test_MockADC
test_zero_cross_detection test_zero_cross_detection

View file

@ -2,7 +2,6 @@
//ImportTestGroups //ImportTestGroups
IMPORT_TEST_GROUP(test_load);
IMPORT_TEST_GROUP(test_MockRegEdit); IMPORT_TEST_GROUP(test_MockRegEdit);
IMPORT_TEST_GROUP(test_MockADC); IMPORT_TEST_GROUP(test_MockADC);
IMPORT_TEST_GROUP(test_zero_cross_detection); IMPORT_TEST_GROUP(test_zero_cross_detection);

View file

@ -23,14 +23,9 @@ extern "C"
TEST_GROUP(test_load) TEST_GROUP(test_load)
{ {
uint8_t adc_pin;
uint8_t load_pin;
void setup() void setup()
{ {
adc_pin = 4;
load_pin = 7;
MockADC_ZeroIndex();
Load_SoftResetDisabledLoads();
} }
void teardown() void teardown()
{ {
@ -44,143 +39,23 @@ TEST(test_load, LoadPass)
CHECK_TRUE(true); CHECK_TRUE(true);
} }
void setup_adc_expectations(uint8_t adc_pin) TEST(test_load, PortAHandlerSuccess)
{ {
mock().expectOneCall("ADC_Init") mock().expectOneCall("ADC_Init")
.withUnsignedIntParameter("pin_num", adc_pin); .withUnsignedIntParameter("pin_num", 4);
mock().expectOneCall("ADC_Enable"); mock().expectOneCall("ADC_Enable");
mock().expectOneCall("ADC_ReadValue_Impl") mock().expectOneCall("ADC_ReadValue_Impl")
.withUnsignedIntParameter("pin_num", adc_pin); .withUnsignedIntParameter("pin_num", 4);
mock().expectOneCall("ADC_Disable"); mock().expectOneCall("ADC_Disable");
}
void expect_porta_disabled(uint8_t load_pin)
{
mock().expectOneCall("RegEdit_ClearBit") mock().expectOneCall("RegEdit_ClearBit")
.withPointerParameter("reg", (void *) &PORTA.OUT) .withPointerParameter("reg", (void *) &PORTA.OUT)
.withUnsignedIntParameter("bit_num", load_pin); .withUnsignedIntParameter("bit_num", 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); Load_HandleLoadPortA(4, 7);
}
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);
} }
//Need to setup a one-shot or way for it to only enable once.
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);
}