Added tests for load module
This commit is contained in:
parent
f6aacf1dfa
commit
25cb285fd9
|
@ -49,10 +49,10 @@ add_custom_target(upload ALL
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
add_subdirectory(load)
|
||||||
add_subdirectory(zero_cross_detection)
|
add_subdirectory(zero_cross_detection)
|
||||||
add_subdirectory(ADC)
|
add_subdirectory(ADC)
|
||||||
add_subdirectory(RegEdit)
|
add_subdirectory(RegEdit)
|
||||||
add_subdirectory(usart)
|
add_subdirectory(usart)
|
||||||
add_subdirectory(TriacOut)
|
add_subdirectory(TriacOut)
|
||||||
add_subdirectory(load)
|
|
||||||
add_subdirectory(Enable)
|
add_subdirectory(Enable)
|
||||||
|
|
|
@ -1,22 +1,18 @@
|
||||||
|
add_library(load STATIC
|
||||||
|
load.c
|
||||||
|
)
|
||||||
|
target_include_directories(load PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
if(UNIT_TESTING)
|
if(UNIT_TESTING)
|
||||||
add_library(load STATIC
|
|
||||||
load.c
|
|
||||||
)
|
|
||||||
target_include_directories(load PUBLIC
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_link_libraries(load
|
target_link_libraries(load
|
||||||
MockRegEdit
|
MockRegEdit
|
||||||
|
MockADC
|
||||||
)
|
)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
add_library(load STATIC
|
|
||||||
load.c
|
|
||||||
)
|
|
||||||
target_include_directories(load PUBLIC
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_link_libraries(load
|
target_link_libraries(load
|
||||||
RegEdit
|
RegEdit
|
||||||
|
ADC
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -1,7 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Author: Jake G
|
||||||
|
* Date: 2024
|
||||||
|
* filename: load.c
|
||||||
|
* description: module_purpose
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __AVR_ATtiny404__
|
||||||
|
#define __AVR_ATtiny404__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include "load.h"
|
#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)
|
void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
|
||||||
|
|
64
src/main.c
64
src/main.c
|
@ -30,14 +30,67 @@
|
||||||
//Set the function pointer for the delay func
|
//Set the function pointer for the delay func
|
||||||
void (*Delay_MicroSeconds)(double us) = _delay_us;
|
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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Enable_SetPinsLow();
|
||||||
|
TriacOut_SetupPins();
|
||||||
|
ADC_Setup();
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
for(int i = 0; i < GatePulsesQty; i++){
|
for(int i = 0; i < GatePulsesQty; i++){
|
||||||
ZCD_Poll();
|
ZCD_Poll();
|
||||||
_delay_us(Tau);
|
_delay_us(Tau);
|
||||||
TriacOut_SetupPins();
|
|
||||||
TriacOut_SetAllHigh(); //Only G1 exists in High power mode
|
TriacOut_SetAllHigh(); //Only G1 exists in High power mode
|
||||||
TriacOut_PulsePins(GatePulses[i]);
|
TriacOut_PulsePins(GatePulses[i]);
|
||||||
}
|
}
|
||||||
|
@ -45,9 +98,14 @@ int main(int argc, char **argv)
|
||||||
//The G1 pin is low at this point.
|
//The G1 pin is low at this point.
|
||||||
_delay_ms(2500);
|
_delay_ms(2500);
|
||||||
ZCD_Poll();
|
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){
|
while(true){
|
||||||
; //Do nothing until new Power cycle/reset occurs
|
//; //Do nothing until new Power cycle/reset occurs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ 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
|
||||||
|
@ -38,6 +39,7 @@ target_link_libraries(Mock_Tests
|
||||||
test_MockRegEdit
|
test_MockRegEdit
|
||||||
test_MockADC
|
test_MockADC
|
||||||
test_zero_cross_detection
|
test_zero_cross_detection
|
||||||
|
test_load
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
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);
|
||||||
|
IMPORT_TEST_GROUP(test_load);
|
||||||
|
|
||||||
//START: main
|
//START: main
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
|
|
@ -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
|
||||||
|
)
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Author: Jake G
|
||||||
|
* Date: 2024
|
||||||
|
* filename: test_load.cpp
|
||||||
|
* description:
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
|
#include "CppUTestExt/MockSupport.h"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Reference in New Issue