/**
\return HRESULT success or error code.
*/
HRESULT QuarkLegacyGpioControllerClass::_openController()
{
    HRESULT hr = S_OK;

    hr = OpenControllerDevice(
             galileoLegacyGpioDeviceName,
             m_hController,
             FILE_SHARE_READ | FILE_SHARE_WRITE);

    return hr;
}
Example #2
0
/**
\return TRUE success, FALSE failure, GetLastError() provides the error code.
*/
BOOL LegacyGpioControllerClass::_openController()
{
    BOOL status = TRUE;
    BOOL error = ERROR_SUCCESS;

    status = OpenControllerDevice(
        legacyGpioDeviceName,
        m_hController,
        FILE_SHARE_READ | FILE_SHARE_WRITE);
    if (!status)
    {
        error = GetLastError();
    }

    if (!status) { SetLastError(error); }
    return status;
}
/**
Get the base address of a memory mapped controller in the SOC.
\param[in] deviceName The name of the PCI device used to map the controller in question.
\param[out] handle Handle opened to the device specified by deviceName.
\param[out] baseAddress Base address of the controller in question.
\param[in] shareMode Sharing specifier as specified to CreateFile().
\return TRUE success, FALSE failure, GetLastError() provides the error code.
*/
BOOL GetControllerBaseAddress(PWCHAR deviceName, HANDLE & handle, PVOID & baseAddress, DWORD shareMode)
{
    BOOL status = TRUE;
    DWORD error = ERROR_SUCCESS;
    DMAP_MAPMEMORY_OUTPUT_BUFFER buf = { 0 };
    DWORD bytesReturned = 0;

    status = OpenControllerDevice(deviceName, handle, shareMode);
    if (!status) { error = GetLastError(); }

    if (status && (baseAddress == nullptr))
    {
        // Retrieve the base address of controller registers.
        status = DeviceIoControl(
            handle,
            IOCTL_DMAP_MAPMEMORY,
            nullptr,
            0,
            &buf,
            sizeof(buf),
            &bytesReturned,
            nullptr);
        if (!status)
        {
            error = GetLastError();
            CloseHandle(handle);
            handle = INVALID_HANDLE_VALUE;
            baseAddress = nullptr;
        }
        else
        {
            // Pass back the base address of the controller registers to the caller.
            baseAddress = buf.Address;
        }
    }

    if (!status) { SetLastError(error); }
    return status;
}