|
|
@@ -1,26 +1,25 @@
|
|
|
#include "shark_charge.h"
|
|
|
#include "app_rs485_1.h"
|
|
|
+#include "shark_xl.h"
|
|
|
#include "app.h"
|
|
|
|
|
|
shark_bool shark_charger_detected;
|
|
|
shark_bool shark_charger_enabled;
|
|
|
-shark_u16 shark_charger_remove;
|
|
|
|
|
|
shark_u16 shark_charge_times;
|
|
|
shark_bool shark_battery_full;
|
|
|
|
|
|
+static shark_u16 shark_charger_remove;
|
|
|
+static shark_u16 shark_charger_insert;
|
|
|
+
|
|
|
void shark_charge_init(void)
|
|
|
{
|
|
|
rcu_periph_clock_enable(GPIO_RCU_CHG_DET);
|
|
|
gpio_init(GPIO_PORT_CHG_DET, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_CHG_DET);
|
|
|
|
|
|
rcu_periph_clock_enable(GPIO_RCU_CHG_EN);
|
|
|
+ gpio_bit_reset(GPIO_PORT_CHG_EN, GPIO_PIN_CHG_EN);
|
|
|
gpio_init(GPIO_PORT_CHG_EN, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_CHG_EN);
|
|
|
-
|
|
|
- gpio_exti_source_select(EXTI_PORT_CHG_DET, EXTI_PIN_CHG_DET);
|
|
|
- exti_init(EXTI_CHG_DET, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
|
|
|
- exti_interrupt_flag_clear(EXTI_CHG_DET);
|
|
|
- nvic_irq_enable(EXTI4_IRQn, 1, 0);
|
|
|
}
|
|
|
|
|
|
void shark_charger_set_enable(shark_bool enable)
|
|
|
@@ -52,27 +51,36 @@ void shark_charger_set_enable(shark_bool enable)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void shark_charger_disable(void)
|
|
|
+void shark_charger_disable(u16 times)
|
|
|
{
|
|
|
- if (shark_charge_times > SHARK_CHG_TIME_MIN) {
|
|
|
+ if (shark_charge_times > times) {
|
|
|
shark_charger_set_enable(shark_false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void shark_charge_tick(void)
|
|
|
{
|
|
|
- if (shark_charger_remove > 0) {
|
|
|
- if (shark_charger_remove > 1) {
|
|
|
- shark_charger_remove--;
|
|
|
+ if (gpio_input_bit_get(GPIO_PORT_CHG_DET, GPIO_PIN_CHG_DET) == RESET) {
|
|
|
+ shark_charger_remove = 0;
|
|
|
+
|
|
|
+ if (shark_charger_insert < 50) {
|
|
|
+ shark_charger_insert++;
|
|
|
+ } else if (shark_xl_check() == shark_false) {
|
|
|
+ shark_charger_detected = shark_true;
|
|
|
+
|
|
|
+ if (shark_charger_enabled && shark_charge_times < SHARK_CHG_TIME_MAX) {
|
|
|
+ shark_charge_times++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ shark_charger_insert = 0;
|
|
|
+
|
|
|
+ if (shark_charger_remove < 2000) {
|
|
|
+ shark_charger_remove++;
|
|
|
} else {
|
|
|
- shark_charger_remove = 0;
|
|
|
shark_charger_detected = shark_false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (shark_charger_enabled && shark_charge_times < SHARK_CHG_TIME_MAX) {
|
|
|
- shark_charge_times++;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
void shark_charge_poll(void)
|
|
|
@@ -82,21 +90,27 @@ void shark_charge_poll(void)
|
|
|
switch (cb_operate_state) {
|
|
|
case CB_BAT1:
|
|
|
if (sub_bms_info_1.packet_common.charge_flag == 0) {
|
|
|
- shark_charger_disable();
|
|
|
+ shark_charger_disable(SHARK_CHG_TIME_MIN);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case CB_BAT2:
|
|
|
if (sub_bms_info_2.packet_common.charge_flag == 0) {
|
|
|
- shark_charger_disable();
|
|
|
+ shark_charger_disable(SHARK_CHG_TIME_MIN);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case CB_BAT1_BAT2_PARRALLEL:
|
|
|
- if (sub_bms_info_1.packet_common.charge_flag == 0 && sub_bms_info_2.packet_common.charge_flag == 0) {
|
|
|
- shark_charger_disable();
|
|
|
- } else if (shark_battery_is_discharge1() || shark_battery_is_discharge2()) {
|
|
|
- shark_charger_disable();
|
|
|
+ if (sub_bms_info_1.packet_common.charge_flag == 0) {
|
|
|
+ if (sub_bms_info_2.packet_common.charge_flag == 0) {
|
|
|
+ shark_charger_disable(SHARK_CHG_TIME_MIN);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (shark_battery_get_current12() < 0) {
|
|
|
+ shark_charger_disable(SHARK_CHG_TIME_MIN);
|
|
|
+ }
|
|
|
+ } else if (sub_bms_info_2.packet_common.charge_flag == 0 && shark_battery_get_current12() < 0) {
|
|
|
+ shark_charger_disable(SHARK_CHG_TIME_MIN);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
@@ -105,13 +119,3 @@ void shark_charge_poll(void)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-void EXTI4_IRQHandler(void)
|
|
|
-{
|
|
|
- if (exti_flag_get(EXTI_4) != RESET) {
|
|
|
- exti_flag_clear(EXTI_4);
|
|
|
- shark_charger_remove = 0;
|
|
|
- shark_charger_detected = shark_true;
|
|
|
- }
|
|
|
-}
|
|
|
-
|