diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 883430d..d833ae0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,10 +49,10 @@ add_custom_target(upload ALL endif() +add_subdirectory(load) add_subdirectory(zero_cross_detection) add_subdirectory(ADC) add_subdirectory(RegEdit) add_subdirectory(usart) add_subdirectory(TriacOut) -add_subdirectory(load) add_subdirectory(Enable) diff --git a/src/load/CMakeLists.txt b/src/load/CMakeLists.txt index 5493a0b..a61e227 100644 --- a/src/load/CMakeLists.txt +++ b/src/load/CMakeLists.txt @@ -1,22 +1,18 @@ +add_library(load STATIC + load.c +) +target_include_directories(load PUBLIC + ${CMAKE_CURRENT_LIST_DIR} +) + if(UNIT_TESTING) - add_library(load STATIC - load.c - ) - target_include_directories(load PUBLIC - ${CMAKE_CURRENT_LIST_DIR} - ) target_link_libraries(load MockRegEdit + MockADC ) - else() - add_library(load STATIC - load.c - ) - target_include_directories(load PUBLIC - ${CMAKE_CURRENT_LIST_DIR} - ) target_link_libraries(load - RegEdit + RegEdit + ADC ) endif() diff --git a/src/load/load.c b/src/load/load.c index 0a65291..6343875 100644 --- a/src/load/load.c +++ b/src/load/load.c @@ -1,7 +1,27 @@ +/* + * Author: Jake G + * Date: 2024 + * filename: load.c + * description: module_purpose + */ + +#ifndef __AVR_ATtiny404__ +#define __AVR_ATtiny404__ +#endif + + #include #include "load.h" -#include "ADC.h" -#include "RegEdit.h" + + +#ifndef UNIT_TESTING + #include "ADC.h" + #include "RegEdit.h" +#else + #include "MockADC/MockADC.h" + #include "MockRegEdit.h" +#endif + void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin) diff --git a/src/main.c b/src/main.c index c6f5842..f7766e2 100644 --- a/src/main.c +++ b/src/main.c @@ -30,14 +30,67 @@ //Set the function pointer for the delay func void (*Delay_MicroSeconds)(double us) = _delay_us; +static void setup_adc0(void) +{ + //Set the bits used. + ADC0.CTRLA = 0x0; + + //Set the sample accumulation number to 32 + ADC0.CTRLB = 0x5; + + //Set the Voltage Reference point to VCC. + ADC0.CTRLC |= (1<<4); + + //Set the Prescaler to divide the F_PER by 32 + ADC0.CTRLC |= (1<<2); + + //Setup a initialization delay + ADC0.CTRLD |= (2<<5); + + //Add ADC variation for cleaner readings + ADC0.CTRLD |= (1<<4); + + //Enable the ADC + ADC0.CTRLA |= (1<<0); +} + +static void setup_pa4_adc(void) +{ + //Set the PA4 pin as an input pin. + PORTA.DIR ^= ~(1<<4); + + //Configure the MUXPOS or which pin gets connected to ADC0 periph. + ADC0.MUXPOS = 0x04; //AIN4 +} + +static uint16_t read_adc0(void) +{ + ADC0.COMMAND = ADC_STCONV_bm; + + //Wait until the sampling/conversion is done. + while (!(ADC0.INTFLAGS & ADC_RESRDY_bm)) + { + ; + } + + //Bit Shift to account for the accumulated samples. + //AKA we divide by 32 + uint16_t value = ADC0.RES >> 5; + return value; +} + int main(int argc, char **argv) -{ +{ + + Enable_SetPinsLow(); + TriacOut_SetupPins(); + ADC_Setup(); + while(true){ for(int i = 0; i < GatePulsesQty; i++){ ZCD_Poll(); _delay_us(Tau); - TriacOut_SetupPins(); TriacOut_SetAllHigh(); //Only G1 exists in High power mode TriacOut_PulsePins(GatePulses[i]); } @@ -45,9 +98,14 @@ int main(int argc, char **argv) //The G1 pin is low at this point. _delay_ms(2500); ZCD_Poll(); - Enable_SetPinsHigh(); + + //Enable pins are enabled(set high) if the ADCLOAD value is valid. + Load_HandleLoadPortA(ADC_LOAD1, EN1); + Load_HandleLoadPortB(ADC_LOAD2, EN2); + Load_HandleLoadPortB(ADC_LOAD3, EN3); + while(true){ - ; //Do nothing until new Power cycle/reset occurs + //; //Do nothing until new Power cycle/reset occurs } } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f74ed76..de5f9ce 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,6 +10,7 @@ add_subdirectory(RegEdit) add_subdirectory(simple_test) add_subdirectory(zero_cross_detection) add_subdirectory(TriacOut) +add_subdirectory(load) # TEST_RUNNER @@ -38,6 +39,7 @@ target_link_libraries(Mock_Tests test_MockRegEdit test_MockADC test_zero_cross_detection + test_load ) diff --git a/tests/MockTests.cpp b/tests/MockTests.cpp index b078f58..ff2ebee 100644 --- a/tests/MockTests.cpp +++ b/tests/MockTests.cpp @@ -5,6 +5,7 @@ IMPORT_TEST_GROUP(test_MockRegEdit); IMPORT_TEST_GROUP(test_MockADC); IMPORT_TEST_GROUP(test_zero_cross_detection); +IMPORT_TEST_GROUP(test_load); //START: main int main(int argc, char** argv) diff --git a/tests/load/CMakeLists.txt b/tests/load/CMakeLists.txt new file mode 100644 index 0000000..f33cce9 --- /dev/null +++ b/tests/load/CMakeLists.txt @@ -0,0 +1,12 @@ +# TEST_RUNNER +add_library(test_load + test_load.cpp +) + +target_link_libraries(test_load + ${CPPUTEST_LIBRARIES}/libCppUTest.a + ${CPPUTEST_LIBRARIES}/libCppUTestExt.a + load + MockADC + MockRegEdit +) diff --git a/tests/load/test_load.cpp b/tests/load/test_load.cpp new file mode 100644 index 0000000..6fef0cf --- /dev/null +++ b/tests/load/test_load.cpp @@ -0,0 +1,35 @@ +/* + * Author: Jake G + * Date: 2024 + * filename: test_load.cpp + * description: + */ + +#include "CppUTest/CommandLineTestRunner.h" +#include "CppUTestExt/MockSupport.h" +#include + +extern "C" +{ +#include "load.h" +#include "MockADC.h" +#include "MockADC.h" +} + +TEST_GROUP(test_load) +{ + void setup() + { + + } + void teardown() + { + mock().checkExpectations(); + mock().clear(); + } +}; + +TEST(test_load, LoadPass) +{ + CHECK_TRUE(true); +}