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

📄 mupdd.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
📖 第 1 页 / 共 5 页
字号:
        goto Error;
    }

    if(!InterruptInitialize(g_MUGPI2Intr, g_hMUGPI2IntrEvent, NULL, 0))
    {
        CloseHandle(g_hMUGPI2IntrEvent);
        g_hMUGPI2IntrEvent = NULL;
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Interrupt initialization failed! \r\n"), __WFUNCTION__));
        goto Error;
    }

    if(!InterruptInitialize(g_MUGPI1Intr, g_hMUGPI1IntrEvent, NULL, 0))
    {
        CloseHandle(g_hMUGPI1IntrEvent);
        g_hMUGPI1IntrEvent = NULL;
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Interrupt initialization failed! \r\n"), __WFUNCTION__));
        goto Error;
    }

    if(!InterruptInitialize(g_MUGPI0Intr, g_hMUGPI0IntrEvent, NULL, 0))
    {
        CloseHandle(g_hMUGPI0IntrEvent);
        g_hMUGPI0IntrEvent = NULL;
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Interrupt initialization failed! \r\n"), __WFUNCTION__));
        goto Error;
    }

    // Initialize critical section for MU
    InitializeCriticalSection(&g_csMULock);

    InitializeCriticalSection(&g_csWriteBufferLock);
    InitializeCriticalSection(&g_csReadBufferLock);

    // Create queues for read messages and write messages
    queueOptions.dwSize = sizeof(MSGQUEUEOPTIONS);
    queueOptions.dwFlags = MSGQUEUE_ALLOW_BROKEN;
    maxNumMessages = BSPMUGetMaxQueueSize() / sizeof(MUShortMessage_c);
    queueOptions.dwMaxMessages = maxNumMessages;
    queueOptions.cbMaxMessage = sizeof(MUShortMessage_c);
    queueOptions.bReadAccess = TRUE; // we need read-access to msgqueue


    // Create read handles to transmit and receive queues
    g_hReadTransmitQueue = CreateMsgQueue(MU_TRANSMIT_QUEUE_NAME, &queueOptions);
    if (!g_hReadTransmitQueue)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Error creating Read Transmit queue.  Initialization failed! \r\n"), __WFUNCTION__));
        goto Error;
    }

    g_hReadReceiveQueue = CreateMsgQueue(MU_RECEIVE_QUEUE_NAME, &queueOptions);
    if (!g_hReadReceiveQueue)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Error creating Read Transmit queue.  Initialization failed! \r\n"), __WFUNCTION__));
        goto Error;
    }


    // Create write handles to transmit and receive queues
    queueOptions.bReadAccess = FALSE; // we need write-access to msgqueue

    g_hWriteTransmitQueue = CreateMsgQueue(MU_TRANSMIT_QUEUE_NAME, &queueOptions);
    if (!g_hWriteTransmitQueue)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Error creating Read Transmit queue.  Initialization failed! \r\n"), __WFUNCTION__));
        goto Error;
    }

    g_hWriteReceiveQueue = CreateMsgQueue(MU_RECEIVE_QUEUE_NAME, &queueOptions);
    if (!g_hWriteReceiveQueue)
    {
        DEBUGMSG(ZONE_ERROR,
            (TEXT("%s: Error creating Read Transmit queue.  Initialization failed! \r\n"), __WFUNCTION__));
        goto Error;
    }

    // Open MU registry path
    error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, MU_REG_PATH, 0 , 0, &hKey);
    if (error != ERROR_SUCCESS)
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: Failed to open MU registry path:%s [Error:0x%x]\r\n"), 
            __WFUNCTION__, MU_REG_PATH, error));
        return FALSE;
    }

    // Get Default Thread Priorities
    dwSize = sizeof(DWORD);

    error = RegQueryValueEx(hKey, MU_REG_GPI3_PRI_KEYWORD, NULL, NULL, (LPBYTE)&dwGPI3Priority, (LPDWORD)&dwSize);
    if (error == ERROR_SUCCESS) 
    {
        // Make sure it's valid CameraID
        if((dwGPI3Priority <= 97) || (dwGPI3Priority > 255))
        {
            DEBUGMSG(ZONE_WARN,(TEXT("%s: Invalid Thread Priority for GPI3: %d, set to default:%d\r\n"),
                __WFUNCTION__, dwGPI3Priority, MU_THREAD_PRIORITY_DEFAULT));
        }
    }
    else
    {
        DEBUGMSG(ZONE_WARN,(TEXT("%s: Failed to get the default MU GPI3 Thread Priority, setting to default: %d\r\n"),
            __WFUNCTION__, MU_THREAD_PRIORITY_DEFAULT));
    }

    error = RegQueryValueEx(hKey, MU_REG_GPI2_PRI_KEYWORD, NULL, NULL, (LPBYTE)&dwGPI2Priority, (LPDWORD)&dwSize);
    if (error == ERROR_SUCCESS) 
    {
        // Make sure it's valid CameraID
        if((dwGPI2Priority <= 97) || (dwGPI2Priority > 255))
        {
            DEBUGMSG(ZONE_WARN,(TEXT("%s: Invalid Thread Priority for GPI2: %d, set to default:%d\r\n"),
                __WFUNCTION__, dwGPI2Priority, MU_THREAD_PRIORITY_DEFAULT));
        }
    }
    else
    {
        DEBUGMSG(ZONE_WARN,(TEXT("%s: Failed to get the default MU GPI2 Thread Priority, setting to default: %d\r\n"),
            __WFUNCTION__, MU_THREAD_PRIORITY_DEFAULT));
    }

    error = RegQueryValueEx(hKey, MU_REG_GPI1_PRI_KEYWORD, NULL, NULL, (LPBYTE)&dwGPI1Priority, (LPDWORD)&dwSize);
    if (error == ERROR_SUCCESS) 
    {
        // Make sure it's valid CameraID
        if((dwGPI1Priority <= 97) || (dwGPI1Priority > 255))
        {
            DEBUGMSG(ZONE_WARN,(TEXT("%s: Invalid Thread Priority for GPI1: %d, set to default:%d\r\n"),
                __WFUNCTION__, dwGPI1Priority, MU_THREAD_PRIORITY_DEFAULT));
        }
    }
    else
    {
        DEBUGMSG(ZONE_WARN,(TEXT("%s: Failed to get the default MU GPI1 Thread Priority, setting to default: %d\r\n"),
            __WFUNCTION__, MU_THREAD_PRIORITY_DEFAULT));
    }

    error = RegQueryValueEx(hKey, MU_REG_GPI0_PRI_KEYWORD, NULL, NULL, (LPBYTE)&dwGPI0Priority, (LPDWORD)&dwSize);
    if (error == ERROR_SUCCESS) 
    {
        // Make sure it's valid CameraID
        if((dwGPI0Priority <= 97) || (dwGPI0Priority > 255))
        {
            DEBUGMSG(ZONE_WARN,(TEXT("%s: Invalid Thread Priority for GPI0: %d, set to default:%d\r\n"),
                __WFUNCTION__, dwGPI0Priority, MU_THREAD_PRIORITY_DEFAULT));
        }
    }
    else
    {
        DEBUGMSG(ZONE_WARN,(TEXT("%s: Failed to get the default MU GPI0 Thread Priority, setting to default: %d\r\n"),
            __WFUNCTION__, MU_THREAD_PRIORITY_DEFAULT));
    }

    error = RegQueryValueEx(hKey, MU_REG_RX_PRI_KEYWORD, NULL, NULL, (LPBYTE)&dwRXPriority, (LPDWORD)&dwSize);
    if (error == ERROR_SUCCESS) 
    {
        // Make sure it's valid CameraID
        if((dwRXPriority <= 97) || (dwRXPriority > 255))
        {
            DEBUGMSG(ZONE_WARN,(TEXT("%s: Invalid Thread Priority for RX: %d, set to default:%d\r\n"),
                __WFUNCTION__, dwRXPriority, MU_THREAD_PRIORITY_DEFAULT));
        }
    }
    else
    {
        DEBUGMSG(ZONE_WARN,(TEXT("%s: Failed to get the default MU RX Thread Priority, setting to default: %d\r\n"),
            __WFUNCTION__, MU_THREAD_PRIORITY_DEFAULT));
    }

    error = RegQueryValueEx(hKey, MU_REG_TX_PRI_KEYWORD, NULL, NULL, (LPBYTE)&dwTXPriority, (LPDWORD)&dwSize);
    if (error == ERROR_SUCCESS) 
    {
        // Make sure it's valid CameraID
        if((dwTXPriority <= 97) || (dwTXPriority > 255))
        {
            DEBUGMSG(ZONE_WARN,(TEXT("%s: Invalid Thread Priority for TX: %d, set to default:%d\r\n"),
                __WFUNCTION__, dwTXPriority, MU_THREAD_PRIORITY_DEFAULT));
        }
    }
    else
    {
        DEBUGMSG(ZONE_WARN,(TEXT("%s: Failed to get the default MU TX Thread Priority, setting to default: %d\r\n"),
            __WFUNCTION__, MU_THREAD_PRIORITY_DEFAULT));
    }

    // Close registry key
    RegCloseKey(hKey);

    DEBUGMSG(ZONE_ERROR,(TEXT("%s: Thread priorities, as read from registry:\nRX - %d\nTX - %d\nGPI3 - %d\nGPI2 - %d\nGPI1 - %d\nGPI0 - %d\r\n"),
        __WFUNCTION__, dwRXPriority, dwTXPriority, dwGPI3Priority, dwGPI2Priority, dwGPI1Priority, dwGPI0Priority));

    // Create thread to read messages from DSP
    if (!(g_hMUReadThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MUReadIntrThread, NULL, 0, NULL)))
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }
    else
    {
        DEBUGMSG(ZONE_INFO, (TEXT("%s: create MU thread success\r\n"), __WFUNCTION__));

        // Set our interrupt thread's priority
        CeSetThreadPriority(g_hMUReadThread, dwRXPriority);
    }

    // Create thread to write messages to DSP
    if (!(g_hMUWriteThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MUWriteIntrThread, NULL, 0, NULL)))
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }
    else
    {
        DEBUGMSG(ZONE_INFO, (TEXT("%s: create MU thread success\r\n"), __WFUNCTION__));

        // Set our interrupt thread's priority
        CeSetThreadPriority(g_hMUWriteThread, dwTXPriority);
    }


    // Create thread to service General Purpose Interrupt 3
    if (!(g_hMUGPI3Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MUGPI3IntrThread, NULL, 0, NULL)))
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }
    else
    {
        DEBUGMSG(ZONE_INFO, (TEXT("%s: create MU thread success\r\n"), __WFUNCTION__));

        // Set our interrupt thread's priority
        CeSetThreadPriority(g_hMUGPI3Thread, dwGPI3Priority);
    }

    // Create thread to service General Purpose Interrupt 2
    if (!(g_hMUGPI2Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MUGPI2IntrThread, NULL, 0, NULL)))
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }
    else
    {
        DEBUGMSG(ZONE_INFO, (TEXT("%s: create MU thread success\r\n"), __WFUNCTION__));

        // Set our interrupt thread's priority
        CeSetThreadPriority(g_hMUGPI2Thread, dwGPI2Priority);
    }

    // Create thread to service General Purpose Interrupt 1
    if (!(g_hMUGPI1Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MUGPI1IntrThread, NULL, 0, NULL)))
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }
    else
    {
        DEBUGMSG(ZONE_INFO, (TEXT("%s: create MU thread success\r\n"), __WFUNCTION__));

        // Set our interrupt thread's priority
        CeSetThreadPriority(g_hMUGPI1Thread, dwGPI1Priority);
    }

    // Create thread to service General Purpose Interrupt 0
    if (!(g_hMUGPI0Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MUGPI0IntrThread, NULL, 0, NULL)))
    {
        DEBUGMSG(ZONE_ERROR,(TEXT("%s: CreateThread failed!\r\n"), __WFUNCTION__));
        return FALSE;
    }
    else
    {
        DEBUGMSG(ZONE_INFO, (TEXT("%s: create MU thread success\r\n"), __WFUNCTION__));

        // Set our interrupt thread's priority
        CeSetThreadPriority(g_hMUGPI0Thread, dwGPI0Priority);
    }


    // Set initial state for MU registers by
    // resetting MCU-side registers
    MUResetMCURegs();

    MUStatus();

    MU_FUNCTION_EXIT();
    return TRUE;

Error:
    MURelease();

    return FALSE;
}


//------------------------------------------------------------------------------
//
// Function: MURelease
//
// This function will release all resources and terminate the IST thread.
//
// Parameters:
//      None
//
// Returns:
//      None
//
//------------------------------------------------------------------------------
void MURelease(void)
{
    MU_FUNCTION_ENTRY();

    // Release SYSINTRs
    KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &g_MUTXIntr, sizeof(DWORD), NULL, 0, NULL);
    g_MUTXIntr = SYSINTR_UNDEFINED;

    KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &g_MURXIntr, sizeof(DWORD), NULL, 0, NULL);
    g_MURXIntr = SYSINTR_UNDEFINED;

    KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &g_MUGPI3Intr, sizeof(DWORD), NULL, 0, NULL);
    g_MUGPI3Intr = SYSINTR_UNDEFINED;

    KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &g_MUGPI2Intr, sizeof(DWORD), NULL, 0, NULL);
    g_MUGPI2Intr = SYSINTR_UNDEFINED;

    KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &g_MUGPI1Intr, sizeof(DWORD), NULL, 0, NULL);
    g_MUGPI1Intr = SYSINTR_UNDEFINED;

    KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &g_MUGPI0Intr, sizeof(DWORD), NULL, 0, NULL);
    g_MUGPI0Intr = SYSINTR_UNDEFINED;

    // deregister the system interrupts
    if (g_MUTXIntr != SYSINTR_UNDEFINED)
    {
        InterruptDisable(g_MUTXIntr);
        g_MUTXIntr = SYSINTR_UNDEFINED;
    }

    if (g_MURXIntr != SYSINTR_UNDEFINED)
    {
        InterruptDisable(g_MURXIntr);
        g_MURXIntr = SYSINTR_UNDEFINED;
    }

    if (g_MUGPI3Intr != SYSINTR_UNDEFINED)
    {
        InterruptDisable(g_MUGPI3Intr);
        g_MUGPI3Intr = SYSINTR_UNDEFINED;
    }

    if (g_MUGPI2Intr != SYSINTR_UNDEFINED)
    {
        InterruptDisable(g_MUGPI2Intr);
        g_MUGPI2Intr = SYSINTR_UNDEFINED;
    }

    if (g_MUGPI1Intr != SYSINTR_UNDEFINED)
    {
        InterruptDisable(g_MUGPI1Intr);
        g_MUGPI1Intr = SYSINTR_UNDEFINED;
    }

    if (g_MUGPI0Intr != SYSINTR_UNDEFINED)
    {
        InterruptDisable(g_MUGPI0Intr);
        g_MUGPI0Intr = SYSINTR_UNDEFINED;
    }


    if (g_hMUTXIntrEvent)
    {
        CloseHandle(g_hMUTXIntrEvent);
        g_hMUTXIntrEvent = NULL;
    }

    if (g_hMURXIntrEvent)
    {
        CloseHandle(g_hMURXIntrEvent);
        g_hMURXIntrEvent = NULL;
    }

    if (g_hMUGPI3IntrEvent)
    {
        CloseHandle(g_hMUGPI3IntrEvent);
        g_hMUGPI3IntrEvent = NULL;
    }

    if (g_hMUGPI2IntrEvent)
    {
        CloseHandle(g_hMUGPI2IntrEvent);
        g_hMUGPI2IntrEvent = NULL;
    }

    if (g_hMUGPI1IntrEvent)
    {
        CloseHandle(g_hMUGPI1IntrEvent);
        g_hMUGPI1IntrEvent = NULL;
    }

    if (g_hMUGPI0IntrEvent)
    {
        CloseHandle(g_hMUGPI0IntrEvent);
        g_hMUGPI0IntrEvent = NULL;
    }

    if (g_hMUTransmit3EmptyEvent)
    {
        CloseHandle(g_hMUTransmit3EmptyEvent);
        g_hMUTransmit3EmptyEvent = NULL;
    }

    if (g_hMUTransmit2EmptyEvent)
    {
        CloseHandle(g_hMUTransmit2EmptyEvent);
        g_hMUTransmit2EmptyEvent = NULL;
    }

⌨️ 快捷键说明

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