예제 #1
0
////////////////////////////////////////////////////////////////////////////
// demoCleanUp()
// close the port and the driver
//
////////////////////////////////////////////////////////////////////////////
static XLstatus demoCleanUp(void)
{
   XLstatus xlStatus;
    
   if (g_xlPortHandle != XL_INVALID_PORTHANDLE)
   {
      xlStatus = xlClosePort(g_xlPortHandle);
      printf("- ClosePort        : PH(0x%x), %s\n", g_xlPortHandle, xlGetErrorString(xlStatus));
   }

   g_xlPortHandle = XL_INVALID_PORTHANDLE;
   xlCloseDriver();

   return XL_SUCCESS;    // No error handling
}
예제 #2
0
/**
* \brief         This will close the connection with the driver. This will be
*                called before deleting HI layer. This will be called during
*                application close.
* \param         void
* \return        Operation Result. 0 incase of no errors. Failure Error codes(-1) otherwise.
* \authors       Arunkumar Karri
* \date          07.10.2011 Created
*/
static int nDisconnectFromDriver()
{
    int nReturn = 0;
    XLstatus xlStatus;

    if (g_xlPortHandle[0] != XL_INVALID_PORTHANDLE)
    {
        xlStatus = xlDeactivateChannel( g_xlPortHandle[0], g_xlChannelMask );
        xlStatus = xlClosePort(g_xlPortHandle[0]);
        //SSH + fix for Issue# 393 - cannot disconnect bus master in some scenarios.
        //g_xlPortHandle[i] = XL_INVALID_PORTHANDLE;
        //SSH -
    }
    else
    {
        nReturn = -1;
    }
    sg_bCurrState = STATE_HW_INTERFACE_SELECTED;

    return nReturn;
}
예제 #3
0
////////////////////////////////////////////////////////////////////////////
// demoInitDriver
// initializes the driver with one port and all founded channels which
// have a connected CAN cab/piggy.
//
////////////////////////////////////////////////////////////////////////////
XLstatus demoInitDriver(XLaccess *pxlChannelMaskTx, unsigned char *pxlChannelIndex)
{
   XLstatus          xlStatus;
   XLaccess          xlChannelMaskTx = 0;
   unsigned int      i;
  
  
   // ------------------------------------
   // open the driver
   // ------------------------------------
   xlStatus = xlOpenDriver ();
  
   // ------------------------------------
   // get/print the hardware configuration
   // ------------------------------------
   if (XL_SUCCESS == xlStatus)
   {
      xlStatus = xlGetDriverConfig(&g_xlDrvConfig);
   }
  
   if (XL_SUCCESS == xlStatus)
   {
      demoPrintConfig();
    
      printf("Usage: J1939_stack_test <BaudRate> <ApplicationName> <Identifier>\n\n");
    
      // ------------------------------------
      // select the wanted channels
      // ------------------------------------
      g_xlChannelMask = 0;

      for (i=0; i < g_xlDrvConfig.channelCount; i++)
      {
         // we take all hardware we found and
         // check that we have only CAN cabs/piggy's
         // at the moment there is no VN8910 XLAPI support!
         if (g_xlDrvConfig.channel[i].channelBusCapabilities & XL_BUS_ACTIVE_CAP_CAN)
         { 
            if (!*pxlChannelMaskTx)
            {
               *pxlChannelMaskTx = g_xlDrvConfig.channel[i].channelMask;
               *pxlChannelIndex  = g_xlDrvConfig.channel[i].channelIndex;
            }

            g_xlChannelMask |= g_xlDrvConfig.channel[i].channelMask;
         }
      }
    
      if (!g_xlChannelMask)
      {
         printf("ERROR: no available channels found! (e.g. no CANcabs...)\n\n");
         xlStatus = XL_ERROR;
      }
   }

   g_xlPermissionMask = g_xlChannelMask;
  
   // ------------------------------------
   // open ONE port including all channels
   // ------------------------------------
   if (XL_SUCCESS == xlStatus)
   {
      xlStatus = xlOpenPort(&g_xlPortHandle, g_AppName, g_xlChannelMask, &g_xlPermissionMask, RX_QUEUE_SIZE, XL_INTERFACE_VERSION, XL_BUS_TYPE_CAN);
      printf("- OpenPort         : CM=0x%I64x, PH=0x%02X, PM=0x%I64x, %s\n", 
      g_xlChannelMask, g_xlPortHandle, g_xlPermissionMask, xlGetErrorString(xlStatus));
   }

   if ((XL_SUCCESS == xlStatus) && (XL_INVALID_PORTHANDLE != g_xlPortHandle))
   { 
      // ------------------------------------
      // if we have permission we set the
      // bus parameters (baudrate)
      // ------------------------------------
      if (g_xlChannelMask == g_xlPermissionMask)
      {
         xlStatus = xlCanSetChannelBitrate(g_xlPortHandle, g_xlChannelMask, g_BaudRate);
         printf("- SetChannelBitrate: baudr.=%u, %s\n",g_BaudRate, xlGetErrorString(xlStatus));
      } 
      else
      {
         printf("-                  : we have NO init access!\n");
      } 
   }
   else
   {
      xlClosePort(g_xlPortHandle);
      g_xlPortHandle = XL_INVALID_PORTHANDLE;
      xlStatus = XL_ERROR;
   }
  
   return xlStatus;
}