/*********************************************************************************
 * Copyright(C),Ningbo Joyson Preh Car Connect Co.,Ltd.
 * FileName:    Power_Core.c
 * Author:      Zheng shijie
 * Version :    Ver0.1
 * Date:        2020-11-19
 * Description:
 *
 *********************************************************************************/
#include "Backup_Battery.h"
#include "Abstraction/Include/OS_Interface.h"
#include "Abstraction/OS/Kernel.h"
#include "Abstraction/Driver/GPIO/Gpio_abs.h"
#include "Driver/GPIO/Gpio_drv.h"
#include "Driver/IIC/LPI2C_I2cDrv.h"
#include "App/Power/Power_Os.h"
#include "Middleware/BkBattery/Backup_Battery_Core.h"
#include "Config/Include/APP_Config.h"

/***********************************System os api***********************************/
static OS_TaskParam BackupBatteryParam;
static void BackupBattery_task_init(void);
static void BackupBattery_recv_msg(uint16_t event_code, void* data, uint32_t data_size);
/*********************************************************************************
  * Function:	   BackupBattery_task_init
  * Description:
  * Input:		-
  * Output: 	 -
  * Return: 	 void
  *********************************************************************************
  * No.   Date			  Author		  Modification
  *--------------------------------------------------------------------------------
  * 01	  2020-11-19  Zhengshijie	  New
  *
 **********************************************************************************/
static void BackupBattery_task_init(void)
{
	/*iic1 channel drv init*/
	LPI2C1_init();
	/*creat backup battery timer*/
	OS_createTimer(TIMER_ID_BATTERY_CHARGER,3600000,1,BackupBatteryCharger);//loop
	OS_createTimer(TIMER_ID_BATTERY_CHECK,10000,1,BackupBatteryStatusCheck);//loop

}
/*********************************************************************************
  * Function:	   BackupBatteryProcess
  * Description:
  * Input:		-
  * Output: 	 -
  * Return: 	 void
  *********************************************************************************
  * No.   Date			  Author		  Modification
  *--------------------------------------------------------------------------------
  * 01	  2020-11-19  Zhengshijie	  New
  *
 **********************************************************************************/
void BackupBatteryProcess(uint16_t event)
{

	switch(event)
	{
	case EVENT_MCU_POWER_STANDBYOUT:
		BackupBatteryStandbyout();
		break;
	case EVENT_MCU_POWER_STANDBYIN:
		BackupBatteryStandbyin();
		break;
	case EVENT_MCU_POWER_BATTERY_ENTER_ISR:
		BackupBatteryChargerStop();
		break;
	case EVENT_MCU_POWER_BATTERY_EXIT_ISR:
		BackupBatteryChargerCheck();
		break;
	default:
		break;
	}
}
/*********************************************************************************
  * Function:	   BackupBattery_recv_msg
  * Description:
  * Input:		-
  * Output: 	 -
  * Return: 	 void
  *********************************************************************************
  * No.   Date			  Author		  Modification
  *--------------------------------------------------------------------------------
  * 01	  2020-11-19  Zhengshijie	  New
  *
 **********************************************************************************/
static void BackupBattery_recv_msg(uint16_t event_code, void* data, uint32_t data_size)
{
	BackupBatteryProcess(event_code);
}

void* BackupBattery_getTaskParam()
{
	BackupBatteryParam.queue_id = MSG_ID_BACKUPBATTERY;
	BackupBatteryParam.wait_time = OS_WAIT_INFINITE;
	BackupBatteryParam.task_init = BackupBattery_task_init;//task has been created
	BackupBatteryParam.recv_msg = BackupBattery_recv_msg;
    //BackupBatteryParam.time_out = ;
    //BackupBatteryParam.loop = ;
    return &BackupBatteryParam;
}
