📄 videoinedgedetection_buffers.c
字号:
Description: Installs & configures Memory DMA
*********************************************************************/
section("App_Code_L1")
void ConfigureMDMA(
) {
// Configure MDMA 2D structures
/*******************************************
video in buffer to sobel in buffer stream
*******************************************/
/**** Sobel In stream destination buffer config ****/
// count to copy a block of size (SOBEL_COLUMN_SIZE+SOBEL_OFFSET) * (SobelRowSize+SOBEL_OFFSET)
MDMA_Sobel_In_Des.XCount = (SOBEL_COLUMN_SIZE+SOBEL_OFFSET);
// Copy luma values only
MDMA_Sobel_In_Des.XModify = 1; // 1 byte increment
// count to copy a block of size (SOBEL_COLUMN_SIZE+SOBEL_OFFSET) * (SobelRowSize+SOBEL_OFFSET)
MDMA_Sobel_In_Des.YCount = (SobelRowSize+SOBEL_OFFSET);
// Move to next row
MDMA_Sobel_In_Des.YModify = 1; // same as xmodify
/**** Sobel In stream source buffer config ****/
// count to copy a block of size (SOBEL_COLUMN_SIZE+SOBEL_OFFSET) * (SobelRowSize+SOBEL_OFFSET)
MDMA_Sobel_In_Src.XCount = (SOBEL_COLUMN_SIZE+SOBEL_OFFSET);
// Copy luma values only
MDMA_Sobel_In_Src.XModify = 2; // 2 byte increment (alternative data skipped)
// count to copy a block of size (SOBEL_COLUMN_SIZE+SOBEL_OFFSET) * (SobelRowSize+SOBEL_OFFSET)
MDMA_Sobel_In_Src.YCount = (SobelRowSize+SOBEL_OFFSET);
// Move to next row, point to first luma location minus 2
MDMA_Sobel_In_Src.YModify = (DataPerLine - ((SOBEL_COLUMN_SIZE+SOBEL_OFFSET) * 2) + 2); // finally add xmodify
/*******************************************
sobel out buffer to video out buffer stream
*******************************************/
/**** Sobel Out stream destination buffer config ****/
// count to copy sobel out valid data only
MDMA_Sobel_Out_Des.XCount = SOBEL_COLUMN_SIZE;
// Copy valid data to luma locations only
MDMA_Sobel_Out_Des.XModify = 2;
// count to copy sobel out valid data only
MDMA_Sobel_Out_Des.YCount = SobelRowSize;
// Move to next row, point to first luma location
MDMA_Sobel_Out_Des.YModify = (DataPerLine - (SOBEL_COLUMN_SIZE * 2) + 2); // finally add xmodify
/**** Sobel Out stream source buffer config *****/
// count to copy sobel out valid data only
MDMA_Sobel_Out_Src.XCount = SOBEL_COLUMN_SIZE;
// Copy luma values only
MDMA_Sobel_Out_Src.XModify = 1;
// count to copy sobel out valid data only
MDMA_Sobel_Out_Src.YCount = SobelRowSize;
// Move to next row
MDMA_Sobel_Out_Src.YModify = 3; // skip last column data in present row and first column data in next row + xmodify
/*********************************************************
Install MDMA video in buffer to sobel in buffer stream
*********************************************************/
// Open MDMA
#if defined(__ADSPBF533__)
// DMA Manager Handle, DMA Controller- MDMA stream 0, Client Handle, Stream Handle, live callback
ezErrorCheck(adi_dma_MemoryOpen (DMAManagerHandle,ADI_DMA_MDMA_0,NULL,&MDMA_Handle_Stream0,NULL));
#elif defined(__ADSPBF561__)
// DMA Manager Handle, DMA Controller 2 - MDMA stream 0, Client Handle, Stream Handle, live callback
ezErrorCheck(adi_dma_MemoryOpen (DMAManagerHandle,ADI_DMA_MDMA2_0,NULL,&MDMA_Handle_Stream0,NULL));
#endif
/*********************************************************
Install MDMA sobel out buffer to video out buffer stream
*********************************************************/
// Open MDMA
#if defined(__ADSPBF533__)
// DMA Manager Handle, DMA Controller- MDMA stream 1, Client Handle, Stream Handle, live callback
ezErrorCheck(adi_dma_MemoryOpen (DMAManagerHandle,ADI_DMA_MDMA_1,NULL,&MDMA_Handle_Stream1,NULL));
#elif defined(__ADSPBF561__)
// DMA Manager Handle, DMA Controller 2 - MDMA stream 1, Client Handle, Stream Handle, live callback
ezErrorCheck(adi_dma_MemoryOpen (DMAManagerHandle,ADI_DMA_MDMA2_1,NULL,&MDMA_Handle_Stream1,NULL));
#endif
return;
}
/*********************************************************************
Function: CloseMDMA_Streams
Description: Closes Memory DMA streams
*********************************************************************/
section ("sdram_bank1")
void CloseMDMA_Streams (void)
{
// Close MDMA stream 0
ezErrorCheck(adi_dma_MemoryClose (MDMA_Handle_Stream0,FALSE));
// Close MDMA stream 1
ezErrorCheck(adi_dma_MemoryClose (MDMA_Handle_Stream1,FALSE));
}
/*********************************************************************
Function: MDMA_Callback0
Description: Memory DMA callback dunction (sobel in)
*********************************************************************/
section ("Callback_Code_L1")
static void MDMA_Callback0(
void *AppHandle,
u32 Event,
void *pArg
){
// Case of (event type)
switch (Event) {
// Case descriptor processed
case ADI_DMA_EVENT_DESCRIPTOR_PROCESSED:
// Check if sobel out is enabled
if (!SobelFlag.InitSobelOut)
{
// if not, enable Sobel Out MDMA stream
SobelFlag.SobelOutMDMALock = FALSE;
// Sobel Out MDMA has been initialised
SobelFlag.InitSobelOut = TRUE;
}
// check sobel in bufx id that generated callback
if (SobelFlag.SobelInBufID)
{
// Callback generated by Sobel_In_Buf1. Clear flag - indicates buffer already has luma values
SobelFlag.SobelInBuf1Done = FALSE;
}
else
{
// Callback generated by Sobel_In_Buf_0. Clear flag - indicates buffer already has luma values
SobelFlag.SobelInBuf0Done = FALSE;
}
// Mark as Video in bufx to sobel in bufx MDMA is ready for next data stream
SobelFlag.SobelInMDMALock = FALSE;
break;
// Case DMA Error
case ADI_DEV_EVENT_DMA_ERROR_INTERRUPT:
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
default: // other events
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
}
}
/*********************************************************************
Function: MDMA_Callback1
Description: Memory DMA callback function (sobel out)
*********************************************************************/
section ("Callback_Code_L1")
static void MDMA_Callback1(
void *AppHandle,
u32 Event,
void *pArg
){
// Case of (event type)
switch (Event) {
// Case descriptor processed
case ADI_DMA_EVENT_DESCRIPTOR_PROCESSED:
// check Sobel_Out_Bufx id that generated callback
if (SobelFlag.SobelOutBufID)
{
// callback generated by Sobel_Out_Buf1
// Clear flag - indicates buffer is ready to accept edge detected output
SobelFlag.SobelOutBuf1Done = FALSE;
}
else
{
// callback generated by Sobel_Out_Buf0
// Clear flag - indicates buffer is ready to accept edge detected output
SobelFlag.SobelOutBuf0Done = FALSE;
}
// Mark as Sobel_Out_Bufx to Video_Out_Buf MDMA is ready for data streaming
SobelFlag.SobelOutMDMALock = FALSE;
break;
// Case DMA Error
case ADI_DEV_EVENT_DMA_ERROR_INTERRUPT:
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
default: // other events
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
}
}
/*********************************************************************
Function: Sobel_In_Init
Description: Initialises Vidio In to Sobel In streaming
*********************************************************************/
section ("Callback_Code_L1")
void SobelInInit (
u32 *pBuffer
){
/***********************************************
Initialise Video In/Out buffer address pointers
Video In Start address - init to point first
luma value minus 2 of Video_In_Bufx Active Field1
to account for sobel algorithim invaild data,
pass extra 2 rows per block & 2 columns per row
Video Out Start address - init to point first
luma value of Video_Out_Buf Active Field1
***********************************************/
if (pBuffer == (u32 *) (&Video_In_Buffer2D[0])) // implies Video_In_Buf0 ready for sobel conversion
{
// Start address - init to point the first luma value minus 2 of Video_In_Buf0 Active Field1
pVideoInBuf = (u8 *)(&Video_In_Buf0[0] + (Field1Skip + ActiveVideoSkip - (DataPerLine + ITU_Y_OFFSET)));
}
#if defined(__ADSPBF561__)
else if (pBuffer == (u32 *) (&Video_In_Buffer2D[1])) // implies Video_In_Buf1 ready for sobel conversion
{
// Start address - init to point the first luma value minus 2 of Video_In_Buf1 Active Field1
pVideoInBuf = (u8 *)(&Video_In_Buf1[0] + (Field1Skip + ActiveVideoSkip - (DataPerLine + ITU_Y_OFFSET)));
}
#endif
else
return; // this buffer is not for us
// Video out start address - init to point the first luma value of Video_Out_Buf Active Field1
pVideoOutBuf = (u8 *)(&Video_Out_Buf[0] + (Field1Skip + ActiveVideoSkip + ITU_Y_OFFSET));
tpVideoInBuf = NULL; // clear the temp video in buffer pointer
tpVideoOutBuf = NULL; // clear the temp video out buffer pointer
/***********************************************
Init Sobel Buffer management Flags & Counters
***********************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -