DWORD PCIE_SW_EventUnregister(WDC_DEVICE_HANDLE hDev)
{
    DWORD dwStatus;
    
    TraceLog("PCIE_SW_EventUnregister entered. Device handle: 0x%p\n", hDev);
    
    if (!IsValidDevice((PWDC_DEVICE)hDev, "PCIE_SW_EventUnregister"))
        return WD_INVALID_PARAMETER;

    if (!WDC_EventIsRegistered(hDev))
    {
        ErrLog("Cannot unregister events - no events currently registered ...\n");
        return WD_OPERATION_ALREADY_DONE;
    }

    dwStatus = WDC_EventUnregister(hDev);
    
    if (WD_STATUS_SUCCESS != dwStatus)
    {
        ErrLog("Failed to unregister events. Error 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
    }

    return dwStatus;
}
DWORD PCIE_SW_IntDisable(WDC_DEVICE_HANDLE hDev)
{
    DWORD dwStatus;
    PWDC_DEVICE pDev = (PWDC_DEVICE)hDev;
    PPCIE_SW_DEV_CTX pDevCtx;

    TraceLog("PCIE_SW_IntDisable entered. Device handle: 0x%p\n", hDev);

    if (!IsValidDevice(pDev, "PCIE_SW_IntDisable"))
        return WD_INVALID_PARAMETER;

    pDevCtx = (PPCIE_SW_DEV_CTX)WDC_GetDevContext(pDev);
 
    if (!WDC_IntIsEnabled(hDev))
    {
        ErrLog("Interrupts are already disabled ...\n");
        return WD_OPERATION_ALREADY_DONE;
    }

    /* TODO: You can add code here to write to the device in order
             to physically disable the hardware interrupts */

    /* Disable the interrupts */
    dwStatus = WDC_IntDisable(hDev);
    if (WD_STATUS_SUCCESS != dwStatus)
    {
        ErrLog("Failed disabling interrupts. Error 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
    }

    return dwStatus;
}
DWORD PCIE_SW_IntEnable(WDC_DEVICE_HANDLE hDev, PCIE_SW_INT_HANDLER funcIntHandler)
{
    DWORD dwStatus;
    PWDC_DEVICE pDev = (PWDC_DEVICE)hDev;
    PPCIE_SW_DEV_CTX pDevCtx;

    TraceLog("PCIE_SW_IntEnable entered. Device handle: 0x%p\n", hDev);

    if (!IsValidDevice(pDev, "PCIE_SW_IntEnable"))
        return WD_INVALID_PARAMETER;

    if (!IsItemExists(pDev, ITEM_INTERRUPT))
        return WD_OPERATION_FAILED;

    pDevCtx = (PPCIE_SW_DEV_CTX)WDC_GetDevContext(pDev);

    /* Check if interrupts are already enabled */
    if (WDC_IntIsEnabled(hDev))
    {
        ErrLog("Interrupts are already enabled ...\n");
        return WD_OPERATION_ALREADY_DONE;
    }

    /* Define the number of interrupt transfer commands to use */
    #define NUM_TRANS_CMDS 0

    /* NOTE: In order to correctly handle PCI interrupts, you need to
             ADD CODE HERE to set up transfer commands to read/write the
             relevant register(s) in order to correctly acknowledge the
             interrupts, as dictated by your hardware's specifications.
             When adding transfer commands, be sure to also modify the
             definition of NUM_TRANS_CMDS (above) accordingly. */

    /* Store the diag interrupt handler routine, which will be executed by
       PCIE_SW_IntHandler() when an interrupt is received */
    pDevCtx->funcDiagIntHandler = funcIntHandler;
    
    /* Enable the interrupts */
    /* NOTE: When adding read transfer commands, set the INTERRUPT_CMD_COPY flag
             in the 4th argument (dwOptions) passed to WDC_IntEnable() */
    dwStatus = WDC_IntEnable(hDev, NULL, 0, 0,
        PCIE_SW_IntHandler, (PVOID)pDev, WDC_IS_KP(hDev));
        
    if (WD_STATUS_SUCCESS != dwStatus)
    {
        ErrLog("Failed enabling interrupts. Error 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        
        return dwStatus;
    }

    /* TODO: You can add code here to write to the device in order
             to physically enable the hardware interrupts */

    TraceLog("PCIE_SW_IntEnable: Interrupts enabled\n");

    return WD_STATUS_SUCCESS;
}
Exemple #4
0
/* -----------------------------------------------
    Device open/close
   ----------------------------------------------- */
WDC_DEVICE_HANDLE EDEN_DeviceOpen(const WD_PCI_CARD_INFO *pDeviceInfo)
{
    DWORD dwStatus;
    PEDEN_DEV_CTX pDevCtx = NULL;
    WDC_DEVICE_HANDLE hDev = NULL;
    EDEN_DEV_ADDR_DESC devAddrDesc;
    PWDC_DEVICE pDev;

    /* Validate arguments */
    if (!pDeviceInfo)
    {
        ErrLog("EDEN_DeviceOpen: Error - NULL device information struct pointer\n");
        return NULL;
    }

    /* Allocate memory for the EDEN device context */
    pDevCtx = (PEDEN_DEV_CTX)malloc(sizeof (EDEN_DEV_CTX));
    if (!pDevCtx)
    {
        ErrLog("Failed allocating memory for EDEN device context\n");
        return NULL;
    }

    BZERO(*pDevCtx);

    /* Open a WDC device handle */
    dwStatus = WDC_PciDeviceOpen(&hDev, pDeviceInfo, pDevCtx, NULL, NULL, NULL);
    if (WD_STATUS_SUCCESS != dwStatus)
    {
        ErrLog("Failed opening a WDC device handle. Error 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        goto Error;
    }

    pDev = hDev;
    devAddrDesc.dwNumAddrSpaces = pDev->dwNumAddrSpaces;
    devAddrDesc.pAddrDesc = pDev->pAddrDesc;

    /* Open a handle to a Kernel PlugIn driver */
    WDC_KernelPlugInOpen(hDev, KP_EDEN_DRIVER_NAME, &devAddrDesc);

    /* Validate device information */
    if (!DeviceValidate((PWDC_DEVICE)hDev))
        goto Error;

    /* Return handle to the new device */
    TraceLog("EDEN_DeviceOpen: Opened a EDEN device (handle 0x%p)\n"
        "Device uses a Kernel PlugIn driver (%s)\n", hDev, KP_EDEN_DRIVER_NAME);
    return hDev;

Error:    
    if (hDev)
        EDEN_DeviceClose(hDev);
    else
        free(pDevCtx);

    return NULL;
}
BOOL PCIE_SW_DeviceClose(WDC_DEVICE_HANDLE hDev)
{
    DWORD dwStatus;
    PWDC_DEVICE pDev = (PWDC_DEVICE)hDev;
    PPCIE_SW_DEV_CTX pDevCtx;
    
    TraceLog("PCIE_SW_DeviceClose entered. Device handle: 0x%p\n", hDev);

    if (!hDev)
    {
        ErrLog("PCIE_SW_DeviceClose: Error - NULL device handle\n");
        return FALSE;
    }

    pDevCtx = (PPCIE_SW_DEV_CTX)WDC_GetDevContext(pDev);
    
    /* Disable interrupts */
    if (WDC_IntIsEnabled(hDev))
    {
        dwStatus = PCIE_SW_IntDisable(hDev);
        if (WD_STATUS_SUCCESS != dwStatus)
        {
            ErrLog("Failed disabling interrupts. Error 0x%lx - %s\n",
                dwStatus, Stat2Str(dwStatus));
        }
    }

    /* Close the device */
    dwStatus = WDC_PciDeviceClose(hDev);
    if (WD_STATUS_SUCCESS != dwStatus)
    {
        ErrLog("Failed closing a WDC device handle (0x%p). Error 0x%lx - %s\n",
            hDev, dwStatus, Stat2Str(dwStatus));
    }

    /* Free PCIE_SW device context memory */
    if (pDevCtx)
        free (pDevCtx);
    
    return (WD_STATUS_SUCCESS == dwStatus);
}
/* -----------------------------------------------
    PCIE_SW and WDC library initialize/uninit
   ----------------------------------------------- */
DWORD PCIE_SW_LibInit(void)
{
    DWORD dwStatus;
 
    /* init only once */
    if (++LibInit_count > 1)
        return WD_STATUS_SUCCESS;
 
#if defined(WD_DRIVER_NAME_CHANGE)
    /* Set the driver name */
    if (!WD_DriverName(PCIE_SW_DEFAULT_DRIVER_NAME))
    {
        ErrLog("Failed to set the driver name for WDC library.\n");
        return WD_SYSTEM_INTERNAL_ERROR;
    }
#endif

    /* Set WDC library's debug options (default: level TRACE, output to Debug Monitor) */
    dwStatus = WDC_SetDebugOptions(WDC_DBG_DEFAULT, NULL);
    if (WD_STATUS_SUCCESS != dwStatus)
    {
        ErrLog("Failed to initialize debug options for WDC library.\n"
            "Error 0x%lx - %s\n", dwStatus, Stat2Str(dwStatus));
        
        return dwStatus;
    }

    /* Open a handle to the driver and initialize the WDC library */
    dwStatus = WDC_DriverOpen(WDC_DRV_OPEN_DEFAULT, PCIE_SW_DEFAULT_LICENSE_STRING);
    if (WD_STATUS_SUCCESS != dwStatus)
    {
        ErrLog("Failed to initialize the WDC library. Error 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        
        return dwStatus;
    }

    return WD_STATUS_SUCCESS;
}
/* -----------------------------------------------
    Device open/close
   ----------------------------------------------- */
WDC_DEVICE_HANDLE PCIE_SW_DeviceOpen(const WD_PCI_CARD_INFO *pDeviceInfo)
{
    DWORD dwStatus;
    PPCIE_SW_DEV_CTX pDevCtx = NULL;
    WDC_DEVICE_HANDLE hDev = NULL;

    /* Validate arguments */
    if (!pDeviceInfo)
    {
        ErrLog("PCIE_SW_DeviceOpen: Error - NULL device information struct pointer\n");
        return NULL;
    }

    /* Allocate memory for the PCIE_SW device context */
    pDevCtx = (PPCIE_SW_DEV_CTX)malloc(sizeof (PCIE_SW_DEV_CTX));
    if (!pDevCtx)
    {
        ErrLog("Failed allocating memory for PCIE_SW device context\n");
        return NULL;
    }

    BZERO(*pDevCtx);

    /* Open a WDC device handle */
    dwStatus = WDC_PciDeviceOpen(&hDev, pDeviceInfo, pDevCtx, NULL, NULL, NULL);
    if (WD_STATUS_SUCCESS != dwStatus)
    {
        ErrLog("Failed opening a WDC device handle. Error 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        goto Error;
    }

    /* Validate device information */
    if (!DeviceValidate((PWDC_DEVICE)hDev))
        goto Error;

    /* Return handle to the new device */
    TraceLog("PCIE_SW_DeviceOpen: Opened a PCIE_SW device (handle 0x%p)\n", hDev);
    return hDev;

Error:    
    if (hDev)
        PCIE_SW_DeviceClose(hDev);
    else
        free(pDevCtx);

    return NULL;
}
Exemple #8
0
DWORD EDEN_IntEnable(WDC_DEVICE_HANDLE hDev, EDEN_INT_HANDLER funcIntHandler)
{
    DWORD dwStatus;
    PWDC_DEVICE pDev = (PWDC_DEVICE)hDev;
    PEDEN_DEV_CTX pDevCtx;

    TraceLog("EDEN_IntEnable entered. Device handle: 0x%p\n", hDev);

    if (!IsValidDevice(pDev, "EDEN_IntEnable"))
        return WD_INVALID_PARAMETER;

    if (!IsItemExists(pDev, ITEM_INTERRUPT))
        return WD_OPERATION_FAILED;

    pDevCtx = (PEDEN_DEV_CTX)WDC_GetDevContext(pDev);

    /* Check if interrupts are already enabled */
    if (WDC_IntIsEnabled(hDev))
    {
        ErrLog("Interrupts are already enabled ...\n");
        return WD_OPERATION_ALREADY_DONE;
    }

    /* Store the diag interrupt handler routine, which will be executed by
       EDEN_IntHandler() when an interrupt is received */
    pDevCtx->funcDiagIntHandler = funcIntHandler;
    
    /* Enable the interrupts */
    /* NOTE: When adding read transfer commands, set the INTERRUPT_CMD_COPY flag
             in the 4th argument (dwOptions) passed to WDC_IntEnable() */
    dwStatus = WDC_IntEnable(hDev, NULL, 0, 0,
        EDEN_IntHandler, (PVOID)pDev, WDC_IS_KP(hDev));
        
    if (WD_STATUS_SUCCESS != dwStatus)
    {
        ErrLog("Failed enabling interrupts. Error 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        
        return dwStatus;
    }

    /* TODO: You can add code here to write to the device in order
             to physically enable the hardware interrupts */

    TraceLog("EDEN_IntEnable: Interrupts enabled\n");

    return WD_STATUS_SUCCESS;
}
DWORD PCIE_SW_LibUninit(void)
{
    DWORD dwStatus;

    if (--LibInit_count > 0)
        return WD_STATUS_SUCCESS;
 
    /* Uninit the WDC library and close the handle to WinDriver */
    dwStatus = WDC_DriverClose();
    if (WD_STATUS_SUCCESS != dwStatus)
    {
        ErrLog("Failed to uninit the WDC library. Error 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
    }

    return dwStatus;
}
Exemple #10
0
// Destructor
CQ2RTApplication::~CQ2RTApplication(void)
{
	CAppGlobalDefs::DeInit();

	if(CHECK_NOT_EMULATION(CAppParams::Instance()->DataCard_Emulation))
	{
		DWORD dwStatus = EdenPCI_DeInit();
		CQLog::Write(LOG_TAG_PRINT, QFormatStr("EdenPCI_DeInit(), dwStatus: %s", Stat2Str(dwStatus)));
	}

	CAppParams::DeInit();
	CModesManager::DeInit();
#ifdef OBJET_MACHINE
	CBatchNoTable::GetInstance()->DeInit();
	CActionsHistoryTable::GetInstance()->DeInit();
#endif
	DeInitLogFile();
}
DWORD PCIE_SW_EventRegister(WDC_DEVICE_HANDLE hDev, PCIE_SW_EVENT_HANDLER funcEventHandler)
{
    DWORD dwStatus;
    PWDC_DEVICE pDev = (PWDC_DEVICE)hDev;
    PPCIE_SW_DEV_CTX pDevCtx;
    DWORD dwActions = WD_ACTIONS_ALL;
    /* TODO: Modify the above to set up the plug-and-play/power management
             events for which you wish to receive notifications.
             dwActions can be set to any combination of the WD_EVENT_ACTION
             flags defined in windrvr.h */

    TraceLog("PCIE_SW_EventRegister entered. Device handle: 0x%p\n", hDev);
    
    if (!IsValidDevice(pDev, "PCIE_SW_EventRegister"))
        return WD_INVALID_PARAMETER;

    pDevCtx = (PPCIE_SW_DEV_CTX)WDC_GetDevContext(pDev);

    /* Check if event is already registered */
    if (WDC_EventIsRegistered(hDev))
    {
        ErrLog("Events are already registered ...\n");
        return WD_OPERATION_ALREADY_DONE;
    }

    /* Store the diag event handler routine to be executed from PCIE_SW_EventHandler() upon an event */
    pDevCtx->funcDiagEventHandler = funcEventHandler;

    /* Register event */
    dwStatus = WDC_EventRegister(hDev, dwActions, PCIE_SW_EventHandler, hDev, FALSE);
    
    if (WD_STATUS_SUCCESS != dwStatus)
    {
        ErrLog("Failed to register events. Error 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        return dwStatus;
    }

    TraceLog("Events registered\n");

    return WD_STATUS_SUCCESS;
}
Exemple #12
0
// Function: LPT_IntAEnable()
//   Enable the interrupt.
// Parameters:
//   hLPT [in] handle to the card as received from LPT_Open.
//   funcIntHandler [in] The call back function to be called upon interrupt.
// Return Value:
//   TRUE if the interrupt was successfully enabled. FALSE otherwise.
BOOL LPT_IntAEnable (LPT_HANDLE hLPT, LPT_IntA_HANDLER funcIntHandler)
{
    DWORD dwStatus;

    // Check if interrupt is already enabled
    if (hLPT->IntA.hThread)
        return FALSE;

    // Calls WD_IntEnable() and creates an interrupt handler thread
    hLPT->IntA.funcIntHandler = funcIntHandler;
    dwStatus = InterruptEnable(&hLPT->IntA.hThread, hLPT->hWD, &hLPT->IntA.Int, LPT_IntAHandler, (PVOID) hLPT);
    if (dwStatus)
    {
        sprintf(LPT_ErrorString, "InterruptEnable() failed with status 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        return FALSE;
    }

    return TRUE;
}
Exemple #13
0
void PCMCIA_Print_card_info(WD_PCMCIA_SLOT pcmciaSlot)
{
    HANDLE hWD;
    DWORD dwStatus;
    WD_PCMCIA_CARD_INFO pcmciaCardInfo;

    if (!PCMCIA_Get_WD_handle(&hWD))
        return;

    BZERO(pcmciaCardInfo);
    pcmciaCardInfo.pcmciaSlot = pcmciaSlot;
    dwStatus = WD_PcmciaGetCardInfo(hWD, &pcmciaCardInfo);
    if (dwStatus)
    {
        printf("WD_PcmciaGetCardInfo() failed (0x%lx) - %s\n", dwStatus, Stat2Str(dwStatus));
        goto Exit;
    }

    WD_CARD_print(&pcmciaCardInfo.Card, "   ");
Exit:
    WD_Close(hWD);
}
Exemple #14
0
void PCMCIA_Print_all_cards_info()
{
    HANDLE hWD;
    WD_PCMCIA_SCAN_CARDS scanCards;
    WD_PCMCIA_CARD_INFO cardInfo;
    DWORD dwStatus, i;

    if (!PCMCIA_Get_WD_handle (&hWD)) return;

    printf ("PCMCIA bus scan:\n\n");
    BZERO(scanCards);
    dwStatus = WD_PcmciaScanCards (hWD, &scanCards);
    if (dwStatus)
    {
        printf("WD_PcmciaScanCards() failed (0x%lx) - %s\n",
            dwStatus, Stat2Str(dwStatus));
        goto Exit;
    }
    
    for (i=0; i<scanCards.dwCards; i++)
    {
        printf ("Card %ld: Manufacturer ID: %04hx, Card ID: %04hx\n",
            i, scanCards.cardId[i].wManufacturerId, scanCards.cardId[i].wCardId);
        printf ("Bus %d, socket %d, function %d\n",
            (UINT32)scanCards.cardSlot[i].uBus,
            (UINT32)scanCards.cardSlot[i].uSocket,
            (UINT32)scanCards.cardSlot[i].uFunction);

        BZERO(cardInfo);
        cardInfo.pcmciaSlot = scanCards.cardSlot[i];
        WD_PcmciaGetCardInfo(hWD, &cardInfo);
        WD_CARD_print(&cardInfo.Card, "   ");
        printf ("\n");
    }
Exit:
    WD_Close (hWD);
}
Exemple #15
0
// Interface functions to the FIFO
TQErrCode FIFOPCI_WriteAsync(PBYTE Buffer,unsigned BufferLength)
{
  DWORD dwStatus = WD_STATUS_SUCCESS;
  if (BufferLength * sizeof(DWORD) > SIZE_OF_NON_PAGED_BUFFER)
    return Q2RT_FIFOPCI_BUFFER_LENGTH_ERROR;

  if(gEmulationMode)
    return Q_NO_ERROR;

  FIFOPCI_MasterReset();
  gbFIFOStartFlag = TRUE;

#if defined(USE_KERNEL_PLUGIN) /*{*/
  dwStatus = EdenPCI_InitParamsForISR(BufferLength);
  CQLog::Write(LOG_TAG_PRINT,QFormatStr("dwStatus: %s", Stat2Str(dwStatus)));

  if (WD_STATUS_SUCCESS != dwStatus)
     return Q2RT_KERNEL_PLUGIN_FAILURE;

  /* copy the buffer to the non paged buffer */
  memcpy(EdenPCI_GetNonPagedBuffer(), Buffer, BufferLength * sizeof(DWORD));
#else /* } USE_KERNEL_PLUGIN { */

  bFIFOUnderrunError = 0;
  FIFOPCI_InitParamsForISR((PULONG) Buffer, BufferLength);

#endif /* } USE_KERNEL_PLUGIN */
  FIFOPCI_MasterReset();
  EdenPCISystem_INTREnable(LOCAL_FIFO);
  if (gFIFOFullEvent.WaitFor(FIFO_FULL_EVENT_TIMEOUT) == QLib::wrSignaled) // write GO On
     EdenPCI_WriteDWORD(AD_PCI_BAR2, FIFO_GO_REG, 0x01);
  else
     return Q2RT_FIFO_EVENT_TIMEOUT;

  return Q_NO_ERROR;
}/* FIFOPCI_WriteAsync */
Exemple #16
0
// Function: LPT_Open()
//   Register an ISA card to enable working with it.
//   The handle returned from this function is used by most of the functions in this file.
// Parameters:
//   phLPT [out] returns the handle to the opened card.
// Return Value:
//   TRUE if the card was opened successfully. FALSE if there were any errors.
BOOL LPT_Open (LPT_HANDLE *phLPT)
{
    LPT_HANDLE hLPT = (LPT_HANDLE)malloc(sizeof(LPT_STRUCT));

    WD_VERSION ver;
    DWORD dwStatus;

    *phLPT = NULL;
    LPT_ErrorString[0] = '\0';
    if (!hLPT)
    {
        sprintf(LPT_ErrorString, "Failed allocating memory\n");
        return FALSE;
    }
    BZERO(*hLPT);

    dwStatus = LPT_RegisterWinDriver();
    if (dwStatus)
    {
        sprintf(LPT_ErrorString, "Failed registering WinDriver license\n");
        goto Exit;
    }

    hLPT->hWD = WD_Open();

    // Verify that the handle is valid and that the version number is correct
    if (hLPT->hWD==INVALID_HANDLE_VALUE)
    {
        sprintf(LPT_ErrorString, "Failed opening WinDriver device\n");
        goto Exit;
    }

    BZERO(ver);
    WD_Version(hLPT->hWD,&ver);
    if (ver.dwVer<WD_VER)
    {
        sprintf(LPT_ErrorString, "Incorrect WinDriver version. Expected %d.%02d, got %ld.%02ld\n",
             WD_VER/100, WD_VER, ver.dwVer/100, ver.dwVer);
        goto Exit;
    }

    LPT_SetCardElements(hLPT);
    hLPT->cardReg.fCheckLockOnly = FALSE;
    dwStatus = WD_CardRegister(hLPT->hWD, &hLPT->cardReg);
    if (dwStatus)
    {
        sprintf(LPT_ErrorString, "Failed locking device. Status 0x%lx - %s\n",
            dwStatus, Stat2Str(dwStatus));
        goto Exit;
    }

    BZERO (hLPT->IntA);
    hLPT->IntA.Int.hInterrupt = hLPT->cardReg.Card.Item[LPT_IntA].I.Int.hInterrupt;
    hLPT->IntA.Int.dwOptions = hLPT->cardReg.Card.Item[LPT_IntA].I.Int.dwOptions;

    // LPT_Open() was successful
    *phLPT = hLPT;
    return TRUE;

Exit:
    // An error occured during the execution of LPT_Open()
    if (hLPT->cardReg.hCard) 
        WD_CardUnregister(hLPT->hWD, &hLPT->cardReg);
    if (hLPT->hWD!=INVALID_HANDLE_VALUE)
        WD_Close(hLPT->hWD);
    free (hLPT);
    return FALSE;
}
Exemple #17
0
// Application init function (override)
bool CQ2RTApplication::AppInit(void)
{
	if(QFileSystemInit() != Q_NO_ERROR)
		QMonitor.WarningMessage("Can not initialize file system");
#ifdef OS_VXWORKS
	else
	{
		// Set starting work directory
		if(QChangeDirectory(APPLICATION_FILE_PATH) != Q_NO_ERROR)
			QMonitor.WarningMessage("Can not change directory to application directory");
	}

	AppFilePath.Value() = APPLICATION_FILE_PATH;
#endif

	// Set high priority for this process (windows only)
#ifdef OS_WINDOWS
	SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
#endif

	// Init application parameters manager
	if(! CAppParams::Init(AppFilePath.Value() + LOAD_STRING(IDS_CONFIGS_DIRNAME)))
		return false;
	// Initialize the global error handler
	CErrorHandler::Init();

	// Initialize the log file
	InitLogFile();

	// Create a mini-sequencer object
	m_MiniSequencer = new CMiniSequencer("AppMiniSequencer");

	// Initilize the modes manager
	CModesManager::Init(CAppParams::Instance(), AppFilePath.Value(), m_MiniSequencer);

	CAppParams::Instance()->EnableDisableSaveEvents(true);

	InitFrontEnd();
	CModesManager::Instance()->EnterMode(DEFAULT_MODE, DEFAULT_MODES_DIR);
	CModesManager::Instance()->EnterMode(OPERATION_MODE_NAME(CAppParams::Instance()->PipesOperationMode), GENERAL_MODES_DIR);

	// Initilize the maintenance counters system
	CMaintenanceCounters::Init(NUM_OF_MAINTENANCE_COUNTERS, AppFilePath.Value() + LOAD_STRING(IDS_CONFIGS_DIRNAME) + "Maintenance.dat");
	SetMaintenanceCountersDefaultWarnings();
	CMaintenanceCounters::GetInstance()->LoadFromFile();
	SetMachineSinceDateParam(); //OBJET_MACHINE
	ApplyParametersChange();

	// Initialize the data card
	if(CHECK_NOT_EMULATION(CAppParams::Instance()->DataCard_Emulation))
	{
		DWORD dwStatus = EdenPCISystem_Init();
		if(dwStatus != WD_STATUS_SUCCESS)
		{
			m_IsPciCardInitialized = false;
			CQLog::Write(LOG_TAG_PRINT, QFormatStr("Data PCI card problem, dwStatus: %s", Stat2Str(dwStatus)));
			QMonitor.WarningMessage(QFormatStr("Data PCI card problem: %s", Stat2Str(dwStatus)));
		}
		else
		{
			m_IsPciCardInitialized = true;
			SetFIFOUnderrunErrorCallback(FIFOUnderrunErrorCallback, NULL);
		}
	}

	// Initialize communication related components
	InitCommComponents();

	m_LayerProcess   = new CLayerProcess;
	m_HostComm = new CHostComm;

	// Create a mini-sequencer object

	// Create other system objects

	m_MachineManager = new CMachineManager;
	m_Tester         = new CTester;

	// Initialize BIT system
	m_BITManager = new CBITManager;
	AppBIT::Init();
	RefreshBIT();

#ifdef OBJET_MACHINE
	CActionsHistoryTable::GetInstance()->Init();
#endif

	// Protect "Show incoming slices" menu
	// ------------------------------------------------------------------------
	Chasp hasp(ChaspFeature::fromFeature(INT_FROM_RESOURCE(IDN_HASP_INCOMING_SLICES_PROTECTION_FEATURE)));
	try
	{
		haspStatus status = hasp.login(HASP_OBJET_VENDOR_CODE, HASP_LOCAL_SCOPE);
		bool show = false;
		if(HASP_SUCCEEDED(status))
		{
			show = true;
		}
		else
		{
			show = false;
		}
		m_MachineManager->GetMachineSequencer()->HandleIncomingSlicesProtection(show);
	}
	__finally
	{
		hasp.logout();
	}

	// ------------------------------------------------------------------------
	 // Enable m_SolubleSupportAllowed flag
	// ------------------------------------------------------------------------

	TLicensedMaterialsList MaterialsList  = CBackEndInterface::Instance()->GetLicensedMaterialsList();

	for(TLicensedMaterialsList::iterator it = MaterialsList.begin() ; it != MaterialsList.end() ; it++)
	{
		if( it->MaterialName == "SUP707" || it->MaterialName == "SUP706" )
		{
			SetSupportReplacementAllowed(true);
			break;
		}
	}
	// ------------------------------------------------------------------------

	// ------------------------------------------------------------------------

	// Enable m_QATestsAllowed flag
	// ------------------------------------------------------------------------
	Chasp hasp1(ChaspFeature::fromFeature(INT_FROM_RESOURCE(IDN_HASP_QA_TESTS_ALLOWED_FEATURE)));
	try
	{
		haspStatus status = hasp1.login(HASP_OBJET_VENDOR_CODE, HASP_LOCAL_SCOPE);
		bool enable = false;
		if(HASP_SUCCEEDED(status))
		{
			enable = true;
		}
		else
		{
			enable = false;
		}
		SetQATestsAllowed(enable);
	}
	__finally
	{
		hasp1.logout();
	}
	// ------------------------------------------------------------------------

#ifndef EMULATION_ONLY
	//HASP feature number is generated from application version, for example Connex500 ver 57.1 - HASP feature: 571
	ChaspFeature feature = ChaspFeature::fromFeature(GetHaspFeatureNum());
	CHaspInterfaceWrapper::Init(feature, LOG_TAG_HASP, m_MachineManager->GetMachineSequencer()->HandleHaspStatus);
#else
	CHaspInterfaceWrapper::Init();
#endif

	LogThreadsProperties();

	try
	{
		m_timeoutTimer = new TTimer(NULL); //bug 5950
	}
	catch(std::bad_alloc& ba)
	{
		m_timeoutTimer = NULL;
		CQLog::Write(LOG_TAG_GENERAL, "m_timeoutTimer - Memory allocation failed: %s", ba.what());
	}

	QMonitor.SetServiceCallsCheckingMsgSafety(
	    CFrontEndInterface::IsWizardRunning,
	    CFrontEndInterface::CancelWizard);
	return true;
}