#include "nm_ccan.h"

_NM_CCAN    g_NM_CCAN;
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_INIT
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_INIT(void)
{
   g_SleepInfo.bits.ccansleep = 0;
   //
  g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_1  = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_1 = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_1    = 0;
  //
  g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_2  = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_2 = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_2    = 0;
  //
  g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_3  = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_3 = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_3    = 0;
  //
  g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_4  = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_4 = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_4    = 0;
  //
  g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_5  = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_5 = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_5    = 0;
  //
  g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_6  = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_6 = 0;
  g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_6    = 0;
}

/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_1_EN
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_1_EN(void)
{
    g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_1  = 1;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_1 = 0;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_1    = 0;
}
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_1_DIS
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_1_DIS(void)
{
    g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_1  = 0;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_1 = 0;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_1    = 0;
} 
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_2_EN
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_2_EN(void)
{
    g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_2  = 1;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_2 = 0;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_2    = 0;
}
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_2_DIS
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_2_DIS(void)
{
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_2 = 1;
    if(g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_2 <= T1_5s)
    {
        g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_2 = 1;  
    }
    else
    {
        g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_2 = 0;
    }
} 
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_3_EN
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_3_EN(void)
{
    g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_3  = 1;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_3 = 0;
    //g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_3 = 1;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_3    = 0;
}
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_3_DIS
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_3_DIS(void)
{
    if((g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_3 == 1) && (g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_3 <= T1_5s))
    {
        g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_3 = 1;  
    }
    else
    {
        g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_3 = 0;
        //g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_3 = 0;
    }
} 
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_4_EN
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_4_EN(void)
{
    g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_4  = 1;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_4 = 1;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_4    = 0;
}
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_4_DIS
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_4_DIS(void)
{
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_4 = 1;
    if(g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_4 <= T1_5s)
    {
        g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_4 = 1;  
    }
    else
    {
        g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_4 = 0;
    }
}
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_5_EN
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_5_EN(void)
{
    g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_5  = 1;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_5 = 1;
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_5    = 0;
}
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_5_DIS
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_5_DIS(void)
{
    g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_5 = 1;
    if(g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_5 <= T1_5s)
    {
        g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_5 = 1;  
    }
    else
    {
        g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_5 = 0;
    }
}
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_6_EN
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_6_EN(void)
{
   // if(CF_Gway_ExtTailAct == 1)
   // {
   //     g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_6  = 1;
   //     g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_6 = 0;
   //     g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_6    = 0;    
   // }
}
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_NO_6_DIS
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_NO_6_DIS(void)
{
   // if(CF_Gway_ExtTailAct == 0)
   // {
   //     g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_6  = 0;
   //     g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_EN_NO_6 = 0;
   //     g_NM_CCAN.NM_CCAN_ACTIVE_TIME.TIME_NO_6    = 0;    
   // }
}
/*-------------------------------------------------------------------------
* Function Name  : NM_CCAN_ACTIVE_PROC_ALL_DIS
* Description    :
* Input          : None
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void NM_CCAN_ACTIVE_PROC_ALL_DIS(void)
{
    if(g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_1 || g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_2 || g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_3 || g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_4 || g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_5 || g_NM_CCAN.NM_CCAN_ACTIVE_STATE.STATE_NO_6)
    {
        g_NM_CCAN.NM_CCAN_STATE = 0;
        g_SleepInfo.bits.ccansleep = 0;
        //
        g_NM_CCAN.NM_CCAN_RXACTIVE.TIME_EN = 1;
        g_NM_CCAN.NM_CCAN_RXACTIVE.TIME    = 0;
    }
    else
    {
        if(g_SleepInfo.bits.ccansleep == 0)
        {
            g_SleepInfo.bits.ccansleep = 1; 
            g_NM_CCAN.NM_CCAN_STATE = 1;
            //
            g_NM_CCAN.NM_CCAN_RXACTIVE.TIME    = 0;
            g_NM_CCAN.NM_CCAN_RXACTIVE.TIME_EN = 1;
        }
        else if(g_SleepInfo.bits.ccansleep == 1)
        {
            g_NM_CCAN.NM_CCAN_STATE = 1;
            g_NM_CCAN.NM_CCAN_RXACTIVE.TIME_EN = 1;
            //
            if(g_NM_CCAN.NM_CCAN_RXACTIVE.TIME >= T1_5s)
            {
                g_SleepInfo.bits.ccansleep = 2;
                g_NM_CCAN.NM_CCAN_RXACTIVE.TIME_EN = 1;
                g_NM_CCAN.NM_CCAN_RXACTIVE.TIME    = 0;
            }           
        }
        else if(g_SleepInfo.bits.ccansleep == 2)
        {
            //g_NM_CCAN.NM_CCAN_RXACTIVE.TIME_EN = 1;
            //if(g_NM_CCAN.NM_CCAN_RXACTIVE.TIME >= T1_5s)
            //{
                g_SleepInfo.bits.ccansleep = 3;                  
            //}            
        }
    }
}