HRESULT CDIL_LIN_VectorXL::StartHardware(void) { // ------------------------------------ // go with all selected channels on bus // ------------------------------------ xlFlushReceiveQueue(g_xlPortHandle[0]); XLstatus xlStatus = XL_ERROR; HRESULT nReturn = S_FALSE; xlStatus = xlActivateChannel(g_xlPortHandle[0], g_xlChannelMask, XL_BUS_TYPE_LIN, XL_ACTIVATE_RESET_CLOCK); if(xlStatus == XL_SUCCESS) { sg_bCurrState = STATE_CONNECTED; nReturn = S_OK; //nSetApplyConfiguration(); } return nReturn; }
/** * \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; }