moving definition to charger.cpp
This commit is contained in:
@@ -40,7 +40,7 @@ LDFLAGS = -Llibopencm3/lib -T$(LDSCRIPT) -march=armv7 -nostartfiles -Wl,--gc-
|
|||||||
OBJSL = main.o hwinit.o stm32scheduler.o params.o terminal.o terminal_prj.o \
|
OBJSL = main.o hwinit.o stm32scheduler.o params.o terminal.o terminal_prj.o \
|
||||||
my_string.o digio.o sine_core.o my_fp.o printf.o anain.o \
|
my_string.o digio.o sine_core.o my_fp.o printf.o anain.o \
|
||||||
param_save.o errormessage.o stm32_can.o \
|
param_save.o errormessage.o stm32_can.o \
|
||||||
picontroller.o terminalcommands.o chargercan.o
|
picontroller.o terminalcommands.o chargercan.o charger.o
|
||||||
|
|
||||||
OBJS = $(patsubst %.o,obj/%.o, $(OBJSL))
|
OBJS = $(patsubst %.o,obj/%.o, $(OBJSL))
|
||||||
vpath %.c src/ libopeninv/src
|
vpath %.c src/ libopeninv/src
|
||||||
@@ -125,10 +125,11 @@ Test:
|
|||||||
g++ -c -Ilibopeninv/include/ -Iinclude -o params.o libopeninv/src/params.cpp
|
g++ -c -Ilibopeninv/include/ -Iinclude -o params.o libopeninv/src/params.cpp
|
||||||
g++ -c -Ilibopeninv/include/ -Iinclude -o errormessage.o libopeninv/src/errormessage.cpp
|
g++ -c -Ilibopeninv/include/ -Iinclude -o errormessage.o libopeninv/src/errormessage.cpp
|
||||||
g++ -c -Ilibopeninv/include/ -Iinclude -o printf.o libopeninv/src/printf.cpp
|
g++ -c -Ilibopeninv/include/ -Iinclude -o printf.o libopeninv/src/printf.cpp
|
||||||
|
g++ -c -Ilibopeninv/include/ -Iinclude -o charger.o src/charger.cpp -D TEST_COMMON_H
|
||||||
g++ -c -Ilibopeninv/include/ -Iinclude -o digio_mock.o test/digio_mock.cpp
|
g++ -c -Ilibopeninv/include/ -Iinclude -o digio_mock.o test/digio_mock.cpp
|
||||||
g++ -c -Ilibopeninv/include/ -Iinclude -o timer_mock.o test/timer_mock.cpp
|
g++ -c -Ilibopeninv/include/ -Iinclude -o timer_mock.o test/timer_mock.cpp
|
||||||
ar rcs libopeninv/libopeninv.a *.o
|
ar rcs libopeninv/libopeninv.a *.o
|
||||||
rm -f my_fp.o my_string.o params.o errormessage.o printf.o digio_mock.o timer_mock.o chademo.o terminal.o
|
rm -f my_fp.o my_string.o params.o errormessage.o printf.o digio_mock.o timer_mock.o terminal.o
|
||||||
g++ -gdwarf-2 -g test/test.c -Llibopeninv -Iinclude -lopeninv -o test/test.out && gdb -ex='set confirm on' -ex=run -ex=quit --args ./test/test.out
|
g++ -gdwarf-2 -g test/test.c -Llibopeninv -Iinclude -lopeninv -o test/test.out && gdb -ex='set confirm on' -ex=run -ex=quit --args ./test/test.out
|
||||||
cleanTest:
|
cleanTest:
|
||||||
cd test && $(MAKE) clean
|
cd test && $(MAKE) clean
|
||||||
|
|||||||
+9
-134
@@ -1,136 +1,11 @@
|
|||||||
|
#ifndef CHARGER_H
|
||||||
|
#define CHARGER_H
|
||||||
#include "../libopeninv/include/params.h"
|
#include "../libopeninv/include/params.h"
|
||||||
#ifdef TEST_COMMON_H
|
extern uint32_t startTime;
|
||||||
#include "../test/digio_mock.h"
|
bool IsEvseInput();
|
||||||
#include "../test/timer_mock.h"
|
bool CheckUnplugged();
|
||||||
#else
|
bool CheckTimeout();
|
||||||
#include <libopencm3/stm32/timer.h>
|
void CalcTotals();
|
||||||
#include <libopencm3/stm32/rtc.h>
|
void DisableAll();
|
||||||
|
void EvseRead();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool IsEvseInput();
|
|
||||||
static void DisableAll();
|
|
||||||
|
|
||||||
static bool IsEvseInput()
|
|
||||||
{
|
|
||||||
enum inputs input = (enum inputs)Param::GetInt(Param::inputype);
|
|
||||||
return input == INP_TYPE1 || input == INP_TYPE2 || input == INP_TYPE2_3P || input == INP_TYPE2_AUTO;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool CheckUnplugged()
|
|
||||||
{
|
|
||||||
return IsEvseInput() && !Param::GetBool(Param::proximity);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void DisableAll()
|
|
||||||
{
|
|
||||||
DigIo::hvena_out.Clear();
|
|
||||||
DigIo::acpres_out.Clear();
|
|
||||||
DigIo::evseact_out.Clear();
|
|
||||||
DigIo::ch1act_out.Clear();
|
|
||||||
DigIo::ch2act_out.Clear();
|
|
||||||
DigIo::ch2act_out.Clear();
|
|
||||||
DigIo::ch1ena_out.Clear();
|
|
||||||
DigIo::ch2ena_out.Clear();
|
|
||||||
DigIo::ch3ena_out.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CalcTotals()
|
|
||||||
{
|
|
||||||
s32fp totalCurrent = Param::Get(Param::c1idc) + Param::Get(Param::c2idc) + Param::Get(Param::c3idc);
|
|
||||||
|
|
||||||
Param::SetFixed(Param::idc, totalCurrent);
|
|
||||||
s32fp u1 = Param::Get(Param::c1udc);
|
|
||||||
s32fp u2 = Param::Get(Param::c2udc);
|
|
||||||
s32fp u3 = Param::Get(Param::c3udc);
|
|
||||||
|
|
||||||
s32fp udcmax = MAX(u1, MAX(u2, u3));
|
|
||||||
Param::SetFixed(Param::udc, udcmax);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t startTime;
|
|
||||||
static bool CheckTimeout()
|
|
||||||
{
|
|
||||||
uint32_t now = rtc_get_counter_val();
|
|
||||||
uint32_t timeout = Param::GetInt(Param::timelim);
|
|
||||||
|
|
||||||
timeout *= 60;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
+136
@@ -0,0 +1,136 @@
|
|||||||
|
#include "my_math.h"
|
||||||
|
#include "charger.h"
|
||||||
|
#ifdef TEST_COMMON_H
|
||||||
|
#include "../test/test_common.h"
|
||||||
|
#include "../test/digio_mock.h"
|
||||||
|
#include "../test/timer_mock.h"
|
||||||
|
#else
|
||||||
|
#include "digio.h"
|
||||||
|
#include "anain.h"
|
||||||
|
#include <libopencm3/stm32/timer.h>
|
||||||
|
#include <libopencm3/stm32/rtc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool IsEvseInput()
|
||||||
|
{
|
||||||
|
enum inputs input = (enum inputs)Param::GetInt(Param::inputype);
|
||||||
|
return input == INP_TYPE1 || input == INP_TYPE2 || input == INP_TYPE2_3P || input == INP_TYPE2_AUTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckUnplugged()
|
||||||
|
{
|
||||||
|
return IsEvseInput() && !Param::GetBool(Param::proximity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisableAll()
|
||||||
|
{
|
||||||
|
DigIo::hvena_out.Clear();
|
||||||
|
DigIo::acpres_out.Clear();
|
||||||
|
DigIo::evseact_out.Clear();
|
||||||
|
DigIo::ch1act_out.Clear();
|
||||||
|
DigIo::ch2act_out.Clear();
|
||||||
|
DigIo::ch2act_out.Clear();
|
||||||
|
DigIo::ch1ena_out.Clear();
|
||||||
|
DigIo::ch2ena_out.Clear();
|
||||||
|
DigIo::ch3ena_out.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CalcTotals()
|
||||||
|
{
|
||||||
|
s32fp totalCurrent = Param::Get(Param::c1idc) + Param::Get(Param::c2idc) + Param::Get(Param::c3idc);
|
||||||
|
|
||||||
|
Param::SetFixed(Param::idc, totalCurrent);
|
||||||
|
s32fp u1 = Param::Get(Param::c1udc);
|
||||||
|
s32fp u2 = Param::Get(Param::c2udc);
|
||||||
|
s32fp u3 = Param::Get(Param::c3udc);
|
||||||
|
|
||||||
|
s32fp udcmax = MAX(u1, MAX(u2, u3));
|
||||||
|
Param::SetFixed(Param::udc, udcmax);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckTimeout()
|
||||||
|
{
|
||||||
|
uint32_t now = rtc_get_counter_val();
|
||||||
|
uint32_t timeout = Param::GetInt(Param::timelim);
|
||||||
|
|
||||||
|
timeout *= 60;
|
||||||
|
|
||||||
|
return timeout > 0 && (now - startTime) > timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+1
-1
@@ -46,7 +46,7 @@
|
|||||||
static Stm32Scheduler* scheduler;
|
static Stm32Scheduler* scheduler;
|
||||||
static Can* can;
|
static Can* can;
|
||||||
static PiController dcCurController;
|
static PiController dcCurController;
|
||||||
|
uint32_t startTime;
|
||||||
|
|
||||||
static bool CheckStartCondition()
|
static bool CheckStartCondition()
|
||||||
{
|
{
|
||||||
|
|||||||
Binary file not shown.
@@ -3,6 +3,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
|
uint32_t startTime;
|
||||||
|
|
||||||
void test_calc_totals()
|
void test_calc_totals()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user