⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mavcmd.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 3 页
字号:
Maverick_CloseDir(void)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "closedir" request.
    //
    sParam.ulRequestCode = REQUEST_CLOSEDIR;

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return success.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return success.
        //
        return(1);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_MakeDir creates the specified directory on the specified drive.
//
//****************************************************************************
unsigned long
Maverick_MakeDir(unsigned long ulDrive, const unsigned short *pusDirName)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "makedir" request.
    //
    sParam.ulRequestCode = REQUEST_MAKEDIR;
    sParam.uParams.sMakeDir.ulDriveNum = ulDrive;
    memcpy(sParam.uParams.sMakeDir.pusDirName, pusDirName, 256);

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return success.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return success.
        //
        return(1);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_RemoveDir removes the specified directry from the specified drive.
//
//****************************************************************************
unsigned long
Maverick_RemoveDir(unsigned long ulDrive, const unsigned short *pusDirName)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "removedir" request.
    //
    sParam.ulRequestCode = REQUEST_REMOVEDIR;
    sParam.uParams.sRemoveDir.ulDriveNum = ulDrive;
    memcpy(sParam.uParams.sRemoveDir.pusDirName, pusDirName, 256);

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return success.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return success.
        //
        return(1);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_TotalSpace returns the total capacity of the specified drive.
//
//****************************************************************************
unsigned long
Maverick_TotalSpace(unsigned long ulDrive)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "totalspace" request.
    //
    sParam.ulRequestCode = REQUEST_TOTAL_SPACE;
    sParam.uParams.sTotalSpace.ulDriveNum = ulDrive;

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return the drive
    // capacity.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return the drive capacity.
        //
        return(sResult.uResults.sTotalSpace.ulBytes);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_FreeSpace returns the currently available capacity on the
// specified drive.
//
//****************************************************************************
unsigned long
Maverick_FreeSpace(unsigned long ulDrive)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "freespace" request.
    //
    sParam.ulRequestCode = REQUEST_FREE_SPACE;
    sParam.uParams.sFreeSpace.ulDriveNum = ulDrive;

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return the free space.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return the free space.
        //
        return(sResult.uResults.sFreeSpace.ulBytes);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_Format formats the specified drive.
//
//****************************************************************************
unsigned long
Maverick_Format(unsigned long ulDrive)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "format" request.
    //
    sParam.ulRequestCode = REQUEST_FORMAT;
    sParam.uParams.sFormat.ulDriveNum = ulDrive;

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return success.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return success.
        //
        return(1);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_StartUpdate indicates that a software update is about to be
// performed.
//
//****************************************************************************
unsigned long
Maverick_StartUpdate(void)
{
    MavUsb_IoctlParams sParam;
    MavUsb_IoctlResults sResult;
    unsigned long ulCount, ulResult;

    //
    // Set up the "start_update" request.
    //
    sParam.ulRequestCode = REQUEST_START_UPDATE;

    //
    // Send the request to the Maverick(tm) USB driver.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_DEVICE_REQUEST, &sParam,
                               sizeof(MavUsb_IoctlParams), &sResult,
                               sizeof(MavUsb_IoctlResults), &ulCount, NULL);

    //
    // If the IOCTL was successfuly, the correct number of bytes were returned,
    // and the request was handled by the device, then return success.
    //
    if(ulResult &&
       (ulCount == sizeof(MavUsb_IoctlResults)) &&
       sResult.ulReturnCode)
    {
        //
        // Return success.
        //
        return(1);
    }

    //
    // Return an error.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_ResetTransferCount resets the count of bytes transferred to/from
// the USB device.
//
//****************************************************************************
void
Maverick_ResetTransferCount(void)
{
    unsigned long ulCount;

    //
    // Reset the transfer byte count.
    //
    DeviceIoControl(hFile, IOCTL_MAVUSB_RESET_TRANSFER_COUNT, NULL, 0, NULL,
                    0, &ulCount, NULL);
}

//****************************************************************************
//
// Maverick_GetTransferCount returns the number of bytes transferred to/from
// the USB device.
//
//****************************************************************************
unsigned long
Maverick_GetTransferCount(void)
{
    unsigned long ulResult, ulCount, ulValue;

    //
    // Get the count of bytes transferred.
    //
    ulResult = DeviceIoControl(hStatusFile, IOCTL_MAVUSB_GET_TRANSFER_COUNT,
                               NULL, 0, &ulValue, sizeof(unsigned long),
                               &ulCount, NULL);

    //
    // If the IOCTL was successful and the correct number of bytes were
    // returned, then return the current transfer count.
    //
    if(ulResult && (ulCount == sizeof(unsigned long)))
    {
        //
        // Return the transfer count.
        //
        return(ulValue);
    }

    //
    // Return zero.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_GetDeviceName gets the name of the device from the USB device
// descriptor.
//
//****************************************************************************
unsigned long
Maverick_GetDeviceName(unsigned short *pusBuffer, unsigned long ulLength)
{
    unsigned long ulResult, ulCount;

    //
    // Get the count of bytes transferred.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_GET_NAME, NULL, 0,
                               pusBuffer, ulLength, &ulCount, NULL);

    //
    // If the IOCTL was successful then return success.
    //
    if(ulResult)
    {
        //
        // Success.
        //
        return(1);
    }

    //
    // Return failure.
    //
    return(0);
}

//****************************************************************************
//
// Maverick_GetManufacturerName gets the name of the device from the USB
// device descriptor.
//
//****************************************************************************
unsigned long
Maverick_GetManufacturerName(unsigned short *pusBuffer, unsigned long ulLength)
{
    unsigned long ulResult, ulCount;

    //
    // Get the count of bytes transferred.
    //
    ulResult = DeviceIoControl(hFile, IOCTL_MAVUSB_GET_MANUFACTURER_NAME, NULL,
                               0, pusBuffer, ulLength, &ulCount, NULL);

    //
    // If the IOCTL was successful then return success.
    //
    if(ulResult)
    {
        //
        // Success.
        //
        return(1);
    }

    //
    // Return failure.
    //
    return(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -