/*
 * CanMid_Stack.c
 *
 *  Created on: Nov 20, 2019
 *      Author: yang_p1
 */

//#include "TypeDef.h"
//#include "TskConfig.h"
//#include "System.h"
//#include "CanMid_Stack.h"
//#include "CanExt.h"
//#include "Log.h"
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include "Middleware/CAN/BSW/Ccl/ccl_inc.h"
#include "CAN_Stack.h"
#include "Config/Include/APP_Config.h"
#include "Abstraction/Include/OS_Interface.h"
#include "Driver/SPI/LPSPI_SpiDrv.h"
#include "Driver/GPIO/Gpio_drv.h"
#include "Driver/CAN/CAN_Transciever_drv.h"
//#include "Gpio.h"

//#include "Can.h"
//#include "CanSig.h"
//#include "CanMgrExt.h"

//#include "DTC.h"



#define OPEN_LOG_RX_CHANGE_INDICATION

#if 0
unsigned int j=0;
#endif


int32_t nswCanStackTmout;


void ApplCanRxQueueOverrun(void);
void wvdCanStack_Reset(void);


static unsigned char 	CclStartFlag=FALSE;

//#define OPEN_LOG_NW


static OS_TaskParam CanStackMgrParam;

CanStackMsg_st* CanStackMgrStdMsg;

static void CanStackMgr_task_init()
{
//	SPI2_init();
	Can_trans_init();
	CanMid_CanDrvInit();
	//for pre-dv
//	transceiver_wakeup_mode();
//	CclRequestCommunication(0);
	//for end

	//check	INH status
	 if(GPIO_INPUT_Port_Lev_Read(PTC,PIN_INDEX_11)==PORT_LOW )
	 {
		 transceiver_wakeup_mode();
		 CclCanWakeUpInt();
	 }
}


void CanStackMgr_MainProcess(CanStackMsg_st* CanStackMgrStdMsg)
{
	//OS_StdMsg_st* MsgRx= MsgRx;
	if(CanStackMgrStdMsg != NULL)
	{
		switch(CanStackMgrStdMsg->event_code)
		{
			case EV_STANDBYIN:

				break;
			case EV_STANDBYOUT:

				break;
		}
	}else
	{

	}
}

static void CanStackMgr_recv_msg(uint16_t event_code, void* data, uint32_t data_size)
{
	CanStackMgrStdMsg->data_size = event_code;
	CanStackMgrStdMsg->data_buff = data;
	CanStackMgrStdMsg->data_size = data_size;

	CanStackMgr_MainProcess(CanStackMgrStdMsg);
}

static void CanStackMgr_recv_time_out()
{
	CclScheduleTask();



}

static void CanStackMgr_loop()
{
	;
}

void* CanStackMgr_getTaskParam()
{
	CanStackMgrParam.queue_id = MSG_ID_CANSTACK;
	CanStackMgrParam.wait_time = CAN_STACK_TIMEOUT;
	CanStackMgrParam.task_init = CanStackMgr_task_init;
	CanStackMgrParam.recv_msg = CanStackMgr_recv_msg;
	CanStackMgrParam.time_out = CanStackMgr_recv_time_out;
	CanStackMgrParam.loop = CanStackMgr_loop;
    return &CanStackMgrParam;
}













void wvdCanStack_Reset(void)
{
	nswCanStackTmout=CAN_STACK_TIMEOUT;
}


void CCL_API_CALLBACK_TYPE ApplCclInit(void)
{
}

void ApplCclPreCCLTask(void)
{
}
void ApplCclPostCCLTask(void)
{
}
void CCL_API_CALLBACK_TYPE ApplCclComStart(void)
{

}
void CCL_API_CALLBACK_TYPE ApplCclComStop(void)
{
}
void CCL_API_CALLBACK_TYPE ApplCclComWait(void)
{
}
void CCL_API_CALLBACK_TYPE ApplCclComResume(void)
{
}

void ApplCclCanInit( CAN_CHANNEL_CANTYPE_FIRST CanObjectHandle txHwObjectFirstUsed, CanObjectHandle txHwObjectFirstUnused )
{
}
void ApplCclCanTxObjStart( CAN_CHANNEL_CANTYPE_FIRST CanObjectHandle txHwObject )
{
}
void ApplCclCanTxObjConfirmed( CAN_CHANNEL_CANTYPE_FIRST CanObjectHandle txHwObject )
{
}
void ApplIlInit(IL_CHANNEL_ILTYPE_ONLY)
{
}

void ApplIlRxStop(IL_CHANNEL_ILTYPE_ONLY)
{
}
void ApplIlRxStart(IL_CHANNEL_ILTYPE_ONLY)
{
}
void ApplIlTxStop(IL_CHANNEL_ILTYPE_ONLY)
{
}
void ApplIlTxStart(IL_CHANNEL_ILTYPE_ONLY)
{
}
vuint8 CCL_API_CALLBACK_TYPE ApplCclCanStandby(CCL_CHANNEL_CCLTYPE_FIRST vuint8 sleepResult)
{
	return 0; //success
}


void ApplCanRxQueueOverrun(void)
{

}

void CanMid_SetCclStartFlag(unsigned char value)
{
	CclStartFlag=value;
}






