📄 mupdd.c
字号:
if (g_hMUTransmit1EmptyEvent)
{
CloseHandle(g_hMUTransmit1EmptyEvent);
g_hMUTransmit1EmptyEvent = NULL;
}
if (g_hMUTransmit0EmptyEvent)
{
CloseHandle(g_hMUTransmit0EmptyEvent);
g_hMUTransmit0EmptyEvent = NULL;
}
if (g_hMUReceive3FullEvent)
{
CloseHandle(g_hMUReceive3FullEvent);
g_hMUReceive3FullEvent = NULL;
}
if (g_hMUReceive2FullEvent)
{
CloseHandle(g_hMUReceive2FullEvent);
g_hMUReceive2FullEvent = NULL;
}
if (g_hMUReceive1FullEvent)
{
CloseHandle(g_hMUReceive1FullEvent);
g_hMUReceive1FullEvent = NULL;
}
if (g_hMUReceive0FullEvent)
{
CloseHandle(g_hMUReceive0FullEvent);
g_hMUReceive0FullEvent = NULL;
}
if (g_hMUGPI3Event)
{
CloseHandle(g_hMUGPI3Event);
g_hMUGPI3Event = NULL;
}
if (g_hMUGPI2Event)
{
CloseHandle(g_hMUGPI2Event);
g_hMUGPI2Event = NULL;
}
if (g_hMUGPI1Event)
{
CloseHandle(g_hMUGPI1Event);
g_hMUGPI1Event = NULL;
}
if (g_hMUGPI0Event)
{
CloseHandle(g_hMUGPI0Event);
g_hMUGPI0Event = NULL;
}
if (g_hMUReadThread)
{
CloseHandle(g_hMUReadThread);
g_hMUReadThread = NULL;
}
if (g_hMUWriteThread)
{
CloseHandle(g_hMUWriteThread);
g_hMUWriteThread = NULL;
}
if (g_hMUGPI3Thread)
{
CloseHandle(g_hMUGPI3Thread);
g_hMUGPI3Thread = NULL;
}
if (g_hMUGPI2Thread)
{
CloseHandle(g_hMUGPI2Thread);
g_hMUGPI2Thread = NULL;
}
if (g_hMUGPI1Thread)
{
CloseHandle(g_hMUGPI1Thread);
g_hMUGPI1Thread = NULL;
}
if (g_hMUGPI0Thread)
{
CloseHandle(g_hMUGPI0Thread);
g_hMUGPI0Thread = NULL;
}
CloseMsgQueue(g_hReadTransmitQueue);
CloseMsgQueue(g_hWriteTransmitQueue);
CloseMsgQueue(g_hReadReceiveQueue);
CloseMsgQueue(g_hWriteReceiveQueue);
// Delete MU critical section
DeleteCriticalSection(&g_csMULock);
MU_FUNCTION_EXIT();
return;
}
//------------------------------------------------------------------------------
//
// Function: MUGetMCR
//
// This function retrieves the MU control register value.
//
// Parameters:
// None.
//
// Returns:
// 32-bit MCR register value read from MU.
//
//------------------------------------------------------------------------------
DWORD MUGetMCR()
{
DWORD mcr;
MU_FUNCTION_ENTRY();
mcr = INREG32(&g_pMU->MCR);
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: MCR value read is 0x%x\r\n"), __WFUNCTION__, mcr));
MU_FUNCTION_EXIT();
return mcr;
}
//------------------------------------------------------------------------------
//
// Function: MUSetMCR
//
// This function sets the MU control register value.
//
// Parameters:
// mcr
// [out] 32-bit value to set the MCR register value.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void MUSetMCR(DWORD mcr)
{
MU_FUNCTION_ENTRY();
OUTREG32(&g_pMU->MCR, mcr);
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: MCR value set is 0x%x\r\n"), __WFUNCTION__, mcr));
MU_FUNCTION_EXIT();
}
//------------------------------------------------------------------------------
//
// Function: MUGetMSR
//
// This function retrieves the MU status register value.
//
// Parameters:
// None.
//
// Returns:
// 32-bit MSR register value read from MU.
//
//------------------------------------------------------------------------------
DWORD MUGetMSR()
{
DWORD msr;
MU_FUNCTION_ENTRY();
msr = INREG32(&g_pMU->MSR);
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: MSR value read is 0x%x\r\n"), __WFUNCTION__, msr));
MU_FUNCTION_EXIT();
return msr;
}
//------------------------------------------------------------------------------
//
// Function: MUWriteToDSP
//
// This function writes a short message to the DSP.
//
// Parameters:
// writeBuf
// [in] Pointer to buffer containing data to
// write to DSP.
//
// length
// [in] Number of bytes to write.
//
// Returns:
// TRUE if success, FALSE if failure.
//
//------------------------------------------------------------------------------
BOOL MUWriteToDSP(UINT8 *writeBuf, DWORD length)
{
MUShortMessage_c newMessage;
UINT16 numMessage, i, len;
MU_FUNCTION_ENTRY();
len = (UINT16) (length & 0xFF);
if ((len < MIN_MESSAGE_LENGTH) || len > (MAX_MESSAGE_LENGTH))
{
DEBUGMSG(ZONE_ERROR,(TEXT("%s: Invalid length parameter: %x\r\n"),
__WFUNCTION__, len));
return FALSE;
}
// Create MUShortMessage structure from write data
numMessage = len/4 + (((len % 4) != 0) ? 1 : 0);
newMessage.iLength = numMessage;
for (i = 0; i < numMessage; i++)
{
newMessage.dwChunk[i] = writeBuf[i * 4] | (writeBuf[(i * 4) + 1] << 8) |
(writeBuf[(i * 4) + 2] << 16) |(writeBuf[(i * 4) + 3] << 24);
}
// Waiting on a write-enabled handle to a queue
// This will block if the transmit queue is full
// If we time out, the queue is full, so we return an error
if (WaitForSingleObject(g_hWriteTransmitQueue, MU_WRITE_TIMEOUT) != WAIT_OBJECT_0)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Transmit queue is full\r\n"), __WFUNCTION__));
return FALSE;
}
// Add message to the Write Queue.
// MU ISR thread will then process this data when it is ready.
WriteMsgQueue(g_hWriteTransmitQueue, &newMessage, sizeof(MUShortMessage_c),
MU_WRITE_TIMEOUT, 0);
MU_FUNCTION_EXIT();
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: MUReadFromDSP
//
// This function reads a short message from the DSP.
// This is a blocking call.
//
// Parameters:
// readBuf
// [out] Pointer to buffer that will receive data
// read from DSP.
//
// length
// [in] Number of bytes to read.
//
// Returns:
// TRUE if success, FALSE if failure.
//
//------------------------------------------------------------------------------
BOOL MUReadFromDSP(UINT8 *readBuf, DWORD length)
{
MUShortMessage_c readMessage;
DWORD bytesRead, flags;
int i;
MU_FUNCTION_ENTRY();
if ((length < MIN_MESSAGE_LENGTH) || length > (MAX_MESSAGE_LENGTH))
{
DEBUGMSG(ZONE_ERROR,(TEXT("%s: Invalid length parameter: %x\r\n"),
__WFUNCTION__, length));
return FALSE;
}
// Wait for data in the read queue
if (WaitForSingleObject(g_hReadReceiveQueue, INFINITE) != WAIT_OBJECT_0)
{
DEBUGMSG(ZONE_ERROR, (TEXT("%s: WaitForSingleObject Timeout!\r\n"),
__WFUNCTION__));
return FALSE;
}
// Now read from read queue
// Our message queue handle has been signaled.
// Now try to read a captured image from the buffer queue.
if (!ReadMsgQueue(g_hReadReceiveQueue, &readMessage, sizeof(MUShortMessage_c),
&bytesRead, 10, &flags))
{
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Could not read from read queue!\r\n"),
__WFUNCTION__));
return FALSE;
}
// Check to see if we are attempting to read a longer message
// than was on the read queue.
if (readMessage.iLength > length)
{
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Message read longer (%d bytes) than requested length (%d bytes).\r\n"),
__WFUNCTION__, readMessage.iLength, length));
return FALSE;
}
// copy messages from queue to output buffer
for (i = 0; length > 0; i++, length -= 4, readBuf += 4)
{
// Application is attempting to read more than the length
// of the message read from the DSP. Quit copying in this case.
if (i >= readMessage.iLength)
{
break;
}
if (length < 4)
{
if (length == 0)
{
break;
}
memcpy(readBuf, &readMessage.dwChunk[i], length);
}
else
{
memcpy(readBuf, &readMessage.dwChunk[i], 4);
}
}
DEBUGMSG(ZONE_INFO, (TEXT("%s: Message read, first byte(readBuf): 0x%x\r\n"),
__WFUNCTION__, *readBuf));
MU_FUNCTION_EXIT();
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: MUGenerateGPI
//
// This function generates a General Purpose Interrupt
// based on the GPI number passed in.
//
// Parameters:
// gpiNum
// [out] General Purpose Interrupt signal to
// be generated.
//
// Returns:
// None.
//
//------------------------------------------------------------------------------
void MUGenerateGPI(DWORD gpiNum)
{
MU_FUNCTION_ENTRY();
// Request General Purpose Interrupt based on gpiNum.
// Only 1, 2, 3, and 4 are legal values.
switch (gpiNum)
{
case 1:
INSREG32BF(&g_pMU->MCR, MU_MCR_MGIR0,
MU_MCR_MGIR0_SET);
break;
case 2:
INSREG32BF(&g_pMU->MCR, MU_MCR_MGIR1,
MU_MCR_MGIR1_SET);
break;
case 3:
INSREG32BF(&g_pMU->MCR, MU_MCR_MGIR2,
MU_MCR_MGIR2_SET);
break;
case 4:
INSREG32BF(&g_pMU->MCR, MU_MCR_MGIR3,
MU_MCR_MGIR3_SET);
break;
}
MU_FUNCTION_EXIT();
}
//------------------------------------------------------------------------------
//
// Function: MUResetMCURegs
//
// Set MU MCU registers to initial state.
//
// Parameters:
// None.
//
// Returns:
// None
//
//------------------------------------------------------------------------------
void MUResetMCURegs(void)
{
DWORD mcrFields, msrFields;
MU_FUNCTION_ENTRY();
// There is no hardware reset support for only the MCU side,
// so we simulate reset by disabling all the interrupts and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -