mocked timer test, EvseRead

This commit is contained in:
Janosch
2022-10-11 00:05:01 +01:00
parent 52877fb3ea
commit 7b038d5243
10 changed files with 133 additions and 79 deletions
+76
View File
@@ -58,3 +58,79 @@ static bool CheckTimeout()
return timeout > 0 && (now - startTime) > timeout;
}
static void EvseRead()
{
const int threshProxType1 = 2200;
const int threshProx = 3700;
const int thresh13A = 3200;
const int thresh20A = 2800;
const int thresh32A = 1800;
const int thresh63A = 1000;
int val = AnaIn::cablelim.Get();
if (timer_get_flag(TIM3, TIM_SR_CC2IF))
{
//The relationship between duty cycle and maximum current is linear
//until 85% = 51A. Above that it becomes non-linear but that is not
//relevant for our 10kW charger.
float evselim = timer_get_ic_value(TIM3, TIM_IC2) / 10;
evselim *= 0.666666f;
Param::SetFloat(Param::evselim, evselim);
}
else
{
//If no PWM detected, set limit to 0
Param::SetInt(Param::evselim, 0);
}
if (Param::GetInt(Param::inputype) == INP_TYPE2 ||
Param::GetInt(Param::inputype) == INP_TYPE2_3P ||
Param::GetInt(Param::inputype) == INP_TYPE2_AUTO)
{
if (val > threshProx)
{
Param::SetInt(Param::proximity, 0);
Param::SetInt(Param::cablelim, 0);
}
else
{
Param::SetInt(Param::proximity, 1);
if (val > thresh13A)
{
Param::SetInt(Param::cablelim, 13);
}
else if (val > thresh20A)
{
Param::SetInt(Param::cablelim, 20);
}
else if (val > thresh32A)
{
Param::SetInt(Param::cablelim, 32);
}
else if (val > thresh63A)
{
Param::SetInt(Param::cablelim, 63);
}
}
}
else if (Param::GetInt(Param::inputype) == INP_TYPE1)
{
if (val > threshProxType1)
{
Param::SetInt(Param::proximity, 0);
Param::SetInt(Param::cablelim, 0);
}
else
{
Param::SetInt(Param::proximity, 1);
Param::SetInt(Param::cablelim, 40);
}
}
else
{
Param::SetInt(Param::proximity, 0);
Param::SetInt(Param::cablelim, 32);
}
}
+3
View File
@@ -108,6 +108,9 @@
VALUE_ENTRY(c3udc, "V", 2035 ) \
VALUE_ENTRY(c3idc, "A", 2036 ) \
VALUE_ENTRY(test_time, "s", 2037 ) \
VALUE_ENTRY(test_timer_flag, "X", 2038 ) \
VALUE_ENTRY(test_timer_icvalue, "X", 2039 ) \
// TODO: How to hide this in interface?
/***** Enum String definitions *****/
Binary file not shown.
-77
View File
@@ -47,83 +47,6 @@ static Stm32Scheduler* scheduler;
static Can* can;
static PiController dcCurController;
static void EvseRead()
{
const int threshProxType1 = 2200;
const int threshProx = 3700;
const int thresh13A = 3200;
const int thresh20A = 2800;
const int thresh32A = 1800;
const int thresh63A = 1000;
int val = AnaIn::cablelim.Get();
if (timer_get_flag(TIM3, TIM_SR_CC2IF))
{
//The relationship between duty cycle and maximum current is linear
//until 85% = 51A. Above that it becomes non-linear but that is not
//relevant for our 10kW charger.
float evselim = timer_get_ic_value(TIM3, TIM_IC2) / 10;
evselim *= 0.666666f;
Param::SetFloat(Param::evselim, evselim);
}
else
{
//If no PWM detected, set limit to 0
Param::SetInt(Param::evselim, 0);
}
if (Param::GetInt(Param::inputype) == INP_TYPE2 ||
Param::GetInt(Param::inputype) == INP_TYPE2_3P ||
Param::GetInt(Param::inputype) == INP_TYPE2_AUTO)
{
if (val > threshProx)
{
Param::SetInt(Param::proximity, 0);
Param::SetInt(Param::cablelim, 0);
}
else
{
Param::SetInt(Param::proximity, 1);
if (val > thresh13A)
{
Param::SetInt(Param::cablelim, 13);
}
else if (val > thresh20A)
{
Param::SetInt(Param::cablelim, 20);
}
else if (val > thresh32A)
{
Param::SetInt(Param::cablelim, 32);
}
else if (val > thresh63A)
{
Param::SetInt(Param::cablelim, 63);
}
}
}
else if (Param::GetInt(Param::inputype) == INP_TYPE1)
{
if (val > threshProxType1)
{
Param::SetInt(Param::proximity, 0);
Param::SetInt(Param::cablelim, 0);
}
else
{
Param::SetInt(Param::proximity, 1);
Param::SetInt(Param::cablelim, 40);
}
}
else
{
Param::SetInt(Param::proximity, 0);
Param::SetInt(Param::cablelim, 32);
}
}
static bool CheckStartCondition()
{
+4 -2
View File
@@ -31,8 +31,10 @@ class AnaIn{
ANA_IN_LIST
#undef ANA_IN_ENTRY
bool Get() { return 1; }
void Set() {}
int val = 7;
int Get() { return val; }
void Set(int param) { val = param;}
};
+1
View File
@@ -21,6 +21,7 @@ int main() {
(TestCase){"test_disable_all", test_disable_all},
(TestCase){"test_calc_totals", test_calc_totals},
(TestCase){"test_check_timeout", test_check_timeout},
(TestCase){"test_evse_read", test_evse_read},
// Example:
//(TestCase){"Your tests name", function_name_without_brackets}
//...
BIN
View File
Binary file not shown.
+23
View File
@@ -50,3 +50,26 @@ void test_check_timeout()
res = CheckTimeout();
assert(res);
}
void test_evse_read()
{
// INP_MANUAL
Param::SetInt(Param::inputype, INP_MANUAL);
EvseRead();
assert(0 == Param::GetInt(Param::proximity));
assert(32 == Param::GetInt(Param::cablelim));
// INP_TYPE1
//under threshold
Param::SetInt(Param::inputype, INP_TYPE1);
EvseRead();
assert(1 == Param::GetInt(Param::proximity));
assert(40 == Param::GetInt(Param::cablelim));
//above
Param::SetInt(Param::inputype, INP_TYPE1);
AnaIn::cablelim.Set(2222);
EvseRead();
assert(0 == Param::GetInt(Param::proximity));
assert(0 == Param::GetInt(Param::cablelim));
}
+7
View File
@@ -3,3 +3,10 @@
uint32_t rtc_get_counter_val(){
return Param::Get(Param::test_time) >> 5;
}
bool timer_get_flag(uint32_t timer_peripheral, uint32_t flag){
return Param::Get(Param::test_timer_flag);
}
float timer_get_ic_value(uint32_t timer_peripheral, enum tim_ic_id ic_id){
return Param::GetFloat(Param::test_timer_icvalue);
}
+19
View File
@@ -1,3 +1,22 @@
#include <stdint.h>
#include "../libopeninv/include/params.h"
#ifndef TEST_TMOCK_H
#define TEST_TMOCK_H
#define TIM_SR_CC2IF (1 << 2)
#define PERIPH_BASE (0x40000000U)
#define PERIPH_BASE_APB1 (PERIPH_BASE + 0x00000)
#define TIM3_BASE (PERIPH_BASE_APB1 + 0x0400)
#define TIM3 TIM3_BASE
enum tim_ic_id {
TIM_IC1,
TIM_IC2,
TIM_IC3,
TIM_IC4,
};
uint32_t rtc_get_counter_val();
bool timer_get_flag(uint32_t timer_peripheral, uint32_t flag);
float timer_get_ic_value(uint32_t timer_peripheral, enum tim_ic_id ic_id);
#endif