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

📄 musdk.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//-----------------------------------------------------------------------------
//
//  Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
//  THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
//  BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
//  Freescale Semiconductor, Inc.
//
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//
//  File:  musdk.c
//
//  This module provides wrapper functions for accessing
//  the stream interface for the MU driver.
//
//-----------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include "mxarm11.h"
#include "mu.h"


//-----------------------------------------------------------------------------
// External Functions


//-----------------------------------------------------------------------------
// External Variables


//-----------------------------------------------------------------------------
// Defines
#define MU_FUNCTION_ENTRY() \
    DEBUGMSG(ZONE_FUNCTION, (TEXT("++%s\r\n"), __WFUNCTION__))
#define MU_FUNCTION_EXIT() \
    DEBUGMSG(ZONE_FUNCTION, (TEXT("--%s\r\n"), __WFUNCTION__))

#ifdef DEBUG
// Debug zone bit positions
#define ZONEID_INFO       12
#define ZONEID_FUNCTION   13
#define ZONEID_WARN       14
#define ZONEID_ERROR      15

// Debug zone masks
#define ZONEMASK_INFO     (1<<ZONEID_INFO)
#define ZONEMASK_FUNCTION (1<<ZONEID_FUNCTION)
#define ZONEMASK_WARN     (1<<ZONEID_WARN)
#define ZONEMASK_ERROR    (1<<ZONEID_ERROR)

// Debug zone args to DEBUGMSG
#define ZONE_INFO         DEBUGZONE(ZONEID_INFO)
#define ZONE_FUNCTION     DEBUGZONE(ZONEID_FUNCTION)
#define ZONE_WARN         DEBUGZONE(ZONEID_WARN)
#define ZONE_ERROR        DEBUGZONE(ZONEID_ERROR)
#endif


//------------------------------------------------------------------------------
// Types


//------------------------------------------------------------------------------
// Global Variables
#ifdef DEBUG
extern DBGPARAM dpCurSettings =
{
    _T("GPT"),
    {
        _T(""), _T(""), _T(""), _T(""),
        _T(""), _T(""), _T(""), _T(""),
        _T(""),_T(""),_T(""),_T(""),
        _T("Info"),_T("Function"),_T("Warnings"),_T("Errors")
    },
    ZONEMASK_ERROR | ZONEMASK_WARN | ZONEMASK_INFO
};
#endif


//------------------------------------------------------------------------------
// Local Variables


//------------------------------------------------------------------------------
// Local Functions

//------------------------------------------------------------------------------
//
// Function: MUOpenMU
//
// This method creates a handle to the MU stream driver.
//
// Parameters:
//      None
//
// Returns:
//      Handle to MU driver, which is set in this method.
//      Returns INVALID_HANDLE_VALUE if failure.
//
//------------------------------------------------------------------------------
HANDLE MUOpenMU(void)
{
    HANDLE hMU;

    MU_FUNCTION_ENTRY();

    hMU = CreateFile(TEXT("MGU1:"),        // name of device
        GENERIC_READ|GENERIC_WRITE,         // desired access
        FILE_SHARE_READ|FILE_SHARE_WRITE,   // sharing mode
        NULL,                               // security attributes (ignored)
        OPEN_EXISTING,                      // creation disposition
        FILE_FLAG_RANDOM_ACCESS,            // flags/attributes
        NULL);                              // template file (ignored)

    // if we failed to get handle to MU
    if (hMU == INVALID_HANDLE_VALUE)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s:  CreateFile MU failed!\r\n"), __WFUNCTION__));
        return hMU;
    }

    MU_FUNCTION_EXIT();

    return hMU;
}


//------------------------------------------------------------------------------
//
// Function: MUCloseMU
//
// This method closes a handle to the MU stream driver.
//
// Parameters:
//      hGpt
//          [in/out] Handle to close.
//
// Returns:
//      TRUE if success.
//      FALSE if failure.
//
//------------------------------------------------------------------------------
BOOL MUCloseMU(HANDLE hMU)
{
    MU_FUNCTION_ENTRY();

    // if we don't have handle to MU driver
    if (hMU != NULL)
    {
        if (!CloseHandle(hMU))
        {
            DEBUGMSG(ZONE_ERROR,
                (TEXT("%s: CloseHandle failed!\r\n"), __WFUNCTION__));
            return FALSE;
        }
    }

    MU_FUNCTION_EXIT();

    return TRUE;
}

//------------------------------------------------------------------------------
//
// Function: MUGetControl
//
// This method returns the value of the MU control register.
//
// Parameters:
//      hMU
//          [in] Handle to MU driver.
//
//      pMU_MCR
//          [in] Pointer to MU control register structure
//          that will hold control register return value.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void MUGetControl(HANDLE hMU, DWORD *pMU_MCR)
{
    MU_FUNCTION_ENTRY();

    // issue the IOCTL to get the MU control register
    if (!DeviceIoControl(hMU,     // file handle to the driver
        MU_IOCTL_GET_MCR,         // I/O control code
        NULL,                     // in buffer
        0,                        // in buffer size
        pMU_MCR,                  // out buffer
        sizeof(DWORD),            // out buffer size
        0,                        // number of bytes returned
        NULL))                    // ignored (=NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: MU_IOCTL_GET_MCR failed!\r\n"), __WFUNCTION__));
    }

    MU_FUNCTION_EXIT();
}


//------------------------------------------------------------------------------
//
// Function: MUSetControl
//
// This method sets the value of the MU control register.
//
// Parameters:
//      hMU
//          [in] Handle to MU driver.
//
//      MU_MCR
//          [in] 32-bit MU control register 
//          value to set.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void MUSetControl(HANDLE hMU, DWORD MU_MCR)
{
    MU_FUNCTION_ENTRY();

    // issue the IOCTL to set the MU control register
    if (!DeviceIoControl(hMU,     // file handle to the driver
        MU_IOCTL_SET_MCR,          // I/O control code
        NULL,                      // in buffer
        MU_MCR,                    // in buffer size
        NULL,                      // out buffer
        0,                         // out buffer size
        0,                         // number of bytes returned
        NULL))                     // ignored (=NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: MU_IOCTL_SET_MCR failed!\r\n"), __WFUNCTION__));
    }

    MU_FUNCTION_EXIT();
}

//------------------------------------------------------------------------------
//
// Function: MUGetStatus
//
// This method returns the value of the MU status register.
//
// Parameters:
//      hMU
//          [in] Handle to MU driver.
//
//      pMU_MCR
//          [out] Pointer to MU status register structure
//          that will hold status register return value.
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
void MUGetStatus(HANDLE hMU, DWORD *pMU_MSR)
{
    MU_FUNCTION_ENTRY();

    // issue the IOCTL to get the MU status register
    if (!DeviceIoControl(hMU,     // file handle to the driver
        MU_IOCTL_GET_MSR,          // I/O control code
        NULL,                      // in buffer
        0,                         // in buffer size
        pMU_MSR,                   // out buffer
        sizeof(DWORD),             // out buffer size
        0,                         // number of bytes returned
        NULL))                     // ignored (=NULL)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: MU_IOCTL_GET_MSR failed!\r\n"), __WFUNCTION__));
    }

    MU_FUNCTION_EXIT();

    return;
}


//------------------------------------------------------------------------------
//
// Function: MUWriteData
//
// This method allows the caller to send a short message 
// from the MCU to the DSP.
//
// Parameters:
//      hMU
//          [in] Handle to MU driver.
//
//      length
//          [in] Length of write buffer.
//
//      dataBufPtr
//          [in] Pointer to data buffer to write.
//
// Returns:
//      TRUE if success.
//      FALSE if failure.
//
//------------------------------------------------------------------------------
BOOL MUWriteData(HANDLE hMU, UINT16 length, UINT8 *dataBufPtr)
{
    DWORD bytesWritten;

    MU_FUNCTION_ENTRY();

    if (!WriteFile(hMU, dataBufPtr, length, (LPDWORD) &bytesWritten, NULL))
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: MU WriteFile failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }

    if (length != bytesWritten)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Did not write the correct number of bytes!\r\n"), __WFUNCTION__));
        return FALSE;
    }

    MU_FUNCTION_EXIT();

    return TRUE;
}


//------------------------------------------------------------------------------
//
// Function: MUReadData
//
// This method allows the caller to read a short message 
// from the DSP to the MCU.
//
// Parameters:
//      hMU
//          [in] Handle to MU driver.
//

⌨️ 快捷键说明

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