Example #1
0
/**
* \brief         This function will connect the tool with hardware. This will
*                establish the data link between the application and hardware.
* \param[in]     bConnect TRUE to Connect, FALSE to Disconnect
* \return        Returns defERR_OK if successful otherwise corresponding Error code.
* \authors       Arunkumar Karri
* \date          07.10.2011 Created
*/
static int nConnect(BOOL bConnect)
{
    int nReturn = -1;
    XLstatus xlStatus;

    if (!sg_bIsConnected && bConnect) // Disconnected and to be connected
    {
        /* Set the permission mask for all channel access */
        g_xlPermissionMask = g_xlChannelMask;


        xlStatus = xlOpenPort(&g_xlPortHandle[0], g_AppName, g_xlChannelMask, &g_xlPermissionMask,
                              RX_QUEUE_SIZE, XL_INTERFACE_VERSION, XL_BUS_TYPE_LIN);

        if (XL_SUCCESS == xlStatus)
        {
            //Calculate connected Timestamp
            QueryPerformanceCounter(&sg_QueryTickCount);
            // Get frequency of the performance counter
            QueryPerformanceFrequency(&sg_lnFrequency);
            // Convert it to time stamp with the granularity of hundreds of microsecond
            //if (sg_QueryTickCount.QuadPart * 10000 > sg_QueryTickCount.QuadPart)
            if ((sg_QueryTickCount.QuadPart * 10000) > sg_lnFrequency.QuadPart)
            {
                sg_TimeStamp = (sg_QueryTickCount.QuadPart * 10000) / sg_lnFrequency.QuadPart;
            }
            else
            {
                sg_TimeStamp = (sg_QueryTickCount.QuadPart / sg_lnFrequency.QuadPart) * 10000;
            }

            /* Transit into 'CREATE TIME MAP' state */
            sg_byCurrState = CREATE_MAP_TIMESTAMP;
            vMapDeviceChannelIndex();
            sg_bIsConnected = bConnect;

            xlFlushReceiveQueue(g_xlPortHandle[0]);
            /* Set LIN channel Params */
            nReturn = nSetBaudRate();
        }
        else
        {
            return S_FALSE;
        }

    }
    else if (sg_bIsConnected && !bConnect) // Connected & to be disconnected
    {
        sg_bIsConnected = bConnect;
        Sleep(0); // Let other threads run for once
        nReturn = nDisconnectFromDriver();
    }
    else
    {
        nReturn = defERR_OK;
    }
    if ( sg_bIsConnected )
    {
        InitializeCriticalSection(&sg_CritSectForWrite);

    }
    else
    {
        DeleteCriticalSection(&sg_CritSectForWrite);
    }

    return nReturn;
}
Example #2
0
/**
* \brief         This function will connect the tool with hardware. This will
*                establish the data link between the application and hardware.
* \param[in]     bConnect TRUE to Connect, FALSE to Disconnect
* \return        Returns defERR_OK if successful otherwise corresponding Error code.
* \authors       [email protected]
* \date          05.29.2015 Created
*/
static int nConnect(BOOL bConnect)
{
    int nReturn = -1;
    LinStatus xlStatus;
    LinHandle  hnd;

    if (!sg_bIsConnected && bConnect) // Disconnected and to be connected
    {
        /* Set the permission mask for all channel access */
        for( UINT i = 0; i < sg_nNoOfChannels; i++)
        {
            //open LIN channel
            hnd =  linOpenChannel(sg_aodChannels[i].m_nChannel,sg_aodChannels[i].m_unLINMode);

            if (hnd >= 0)
            {
                sg_aodChannels[i].m_hnd = hnd;
            }
            else
            {
                return S_FALSE;
            }
        }
        nReturn = nSetBaudRate();
        if(nReturn == defERR_OK)
        {
            for( UINT i = 0; i < sg_nNoOfChannels; i++)
            {
                xlStatus = linBusOn(sg_aodChannels[i].m_hnd);
                if (xlStatus < 0)
                {
                    return S_FALSE;
                }
                else
                {
                    sg_aodChannels[i].m_nIsOnBus = 1;
                }
            }
            // Update configuration to restore the settings
            /* Transit into 'CREATE TIME MAP' state */
            sg_byCurrState = CREATE_MAP_TIMESTAMP;
            sg_bIsConnected = bConnect;
        }
    }
    else if (sg_bIsConnected && !bConnect) // Connected & to be disconnected
    {
        sg_bIsConnected = bConnect;
        Sleep(0); // Let other threads run for once
        nReturn = nDisconnectFromDriver();
    }
    else
    {
        nReturn = defERR_OK;
    }
    if ( sg_bIsConnected )
    {
        InitializeCriticalSection(&sg_CritSectForWrite);
        //Calculate connected Timestamp
        QueryPerformanceCounter(&sg_QueryTickCount);
        // Get frequency of the performance counter
        QueryPerformanceFrequency(&sg_lnFrequency);
        // Convert it to time stamp with the granularity of hundreds of microsecond
        //if (sg_QueryTickCount.QuadPart * 10000 > sg_QueryTickCount.QuadPart)
        if ((sg_QueryTickCount.QuadPart * 10000) > sg_lnFrequency.QuadPart)
        {
            sg_TimeStamp = (sg_QueryTickCount.QuadPart * 10000) / sg_lnFrequency.QuadPart;
        }
        else
        {
            sg_TimeStamp = (sg_QueryTickCount.QuadPart / sg_lnFrequency.QuadPart) * 10000;
        }
    }
    else
    {
        DeleteCriticalSection(&sg_CritSectForWrite);
    }

    return nReturn;
}