📄 videoinedgedetection_callbacks.c
字号:
#elif defined(__ADSPBF533__)
// check for Frame Capture button press
// Frame Capture will start only after this button gets released
else if ((int)pArg == PAUSE_FRAME_CAPTURE_BUTTON)
{
// Check Frame Capture Button system status flag
if (PBFlag.Frame_Capture)
{
// if the flag is set, then the button was previously pressed & just released
// Frame capture button has been pressed & released. change trigger status to wait for next button press
ezErrorCheck(adi_flag_SetTrigger(PAUSE_FRAME_CAPTURE_BUTTON,ADI_FLAG_TRIGGER_RISING_EDGE));
// set the Pause button system flag to indicate the button has been released
PBFlag.Frame_Capture = FALSE;
// ignore multiple button press as only one button should be serviced at a time
// check Update flags and even if one of them is set, ignore this button press
if (!(SystemFlag.UpdateVideoInBufs || SystemFlag.UpdateVideoOutBufs || SystemFlag.UpdateVideoMode))
{
// Set Frame capture flag
SystemFlag.Pause_Frame_Capture = TRUE;
// BF533 - video out callback will be active almost 100% of the time
SystemFlag.UpdateVideoOutBufs = TRUE;
}
}
else // Frame Capture button is in pressed state
{
// Frame Capture button has been pressed. change trigger status to wait until its released
ezErrorCheck(adi_flag_SetTrigger(PAUSE_FRAME_CAPTURE_BUTTON,ADI_FLAG_TRIGGER_FALLING_EDGE));
// set the Frame Capture button system flag to indicate the button has been pressed
PBFlag.Frame_Capture = TRUE;
}
}
#endif
// check if Toggle display button was pressed
else if ((int)pArg == TOGGLE_DISPLAY_BUTTON)
{
// Check Toggle Display Button system status flag
if (PBFlag.Toggle_Display == TRUE)
{
// if the flag is set, then the button was previously pressed & just released
// Toggle Display button has been pressed & released. change trigger status to wait for next button press
ezErrorCheck(adi_flag_SetTrigger(TOGGLE_DISPLAY_BUTTON,ADI_FLAG_TRIGGER_RISING_EDGE));
// set the Toggle Display button system flag to indicate the button has been released
PBFlag.Toggle_Display = FALSE;
// ignore multiple button press as only one button should be serviced at a time
// check Update flags and even if one of them is set, ignore this button press
if (!(SystemFlag.UpdateVideoInBufs || SystemFlag.UpdateVideoOutBufs || SystemFlag.UpdateVideoMode))
{
// toggle sobel enable flag
SystemFlag.SobelEnable ^= 1;
// set UpdateBufs_VideoOut to update video buffers Video Out callback
// Video Out callback will be active in all modes (pause enable/disable mode or toggle video mode)
SystemFlag.UpdateVideoOutBufs = TRUE;
}
}
else // Toggle Display button is in pressed state
{
// Toggle Display button has been pressed. change trigger status to wait until its released
ezErrorCheck(adi_flag_SetTrigger(TOGGLE_DISPLAY_BUTTON,ADI_FLAG_TRIGGER_FALLING_EDGE));
// set the Toggle Display button system flag to indicate the button has been pressed
PBFlag.Toggle_Display = TRUE;
}
}
break;
default: // other events
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
}
}
/*********************************************************************
Function: UpdateVideoMode
Description: Switches between PAL and NTSC on-the-fly
Reads ADV7183 Status1 Reg
Status1 Reg:
bit 0 => ADV7183 is in Lock (1) with video / lost(0)
bit 1 => ADV7183 have lost sync (1) since previous read
bits 6,5,4 => Autodetection Result (value 0,1=NTSC / 2,3,4,6=PAL)
*********************************************************************/
section("sdram_bank1")
void UpdateVideoMode()
{
ADI_DEV_ACCESS_REGISTER Status1; // read ADV7183 Status1 reg
Status1.Address = ADV7183_STATUS1_RO; // Status1 reg address
Status1.Data = 0; // clear the location where the data will be read to
// call Device Access to read Status1 reg
ezErrorCheck(adi_dev_Control(ADV7183DeviceHandle, ADI_DEV_CMD_REGISTER_READ, (void *) &Status1));
// check if ADV7183 have lost lock
if (!(Status1.Data & 1))
{
// if so, update ITU656 mode as no video input available
SystemFlag.ITU656_Mode = NO_VIDEO_INPUT;
// don't update buffers if No video input is found
}
// check if ADV7183 have lost sync since previous reg read
else if (Status1.Data & 2)
{
// if so, then update ITU656 video mode
switch ((Status1.Data >> 4) & 0x07) // retrive ITU656 video mode
{
// case (NTSC video)
case 0:
case 1:
// update ITU656 mode NTSC
SystemFlag.ITU656_Mode = ITU656_NTSC;
// New video mode detected. Set flag to Update video mode
SystemFlag.UpdateVideoFlag = TRUE;
break;
// case (PAL video)
case 2:
case 3:
case 4:
case 6:
// update ITU656 mode NTSC
SystemFlag.ITU656_Mode = ITU656_PAL;
// New video mode detected. Set flag to Update buffers
SystemFlag.UpdateVideoFlag = TRUE;
break;
// other video modes (SECAM) not supported yet
default:
SystemFlag.ITU656_Mode = NO_VIDEO_INPUT;
// don't update buffers if No video input is found
break;
}
}
else // Re-sync the present video mode
SystemFlag.UpdateVideoFlag = TRUE;
// update video parameters
// Check video mode
if (SystemFlag.ITU656_Mode == ITU656_PAL)
{
// video mode is ITU656 PAL
// Video data per line (bytes)
DataPerLine = PAL_DATA_PER_LINE;
// Number of lines per ITU656 video frame (bytes)
FrameLines = PAL_FRAME_LINES;
// Number of bytes to skip to reach active video data in a single line
ActiveVideoSkip = PAL_ACTIVE_VIDEO_SKIP;
// Number of bytes to skip to reach active video frame field1 (odd frame)
Field1Skip = PAL_F1_SKIP;
// Number of bytes to skip to reach active video frame field2 (even frame)
Field2Skip = PAL_F2_SKIP;
// Sobel buffer row size (for valid Edge Detected data only)
SobelRowSize = (PAL_ACTIVE_FLINES / SOBEL_FIELD_BLOCKS_PAL);
// PAL video frame - Active field spilt to # number of blocks
SobelFieldBlocks= SOBEL_FIELD_BLOCKS_PAL;
// Number of Sobel blocks per active field (for NTSC)
SobelBlockCount = SOBEL_BLOCK_COUNT_PAL;
}
else // load NTSC values for for no video mode or NTSC video mode
{
// Video mode is ITU656 NTSC or no video input
// Video data per line (bytes)
DataPerLine = NTSC_DATA_PER_LINE;
// Number of lines per ITU656 video frame (bytes)
FrameLines = NTSC_FRAME_LINES;
// Number of bytes to skip to reach active video data in a single line
ActiveVideoSkip = NTSC_ACTIVE_VIDEO_SKIP;
// Number of bytes to skip to reach active video frame field1 (odd frame)
Field1Skip = NTSC_F1_SKIP;
// Number of bytes to skip to reach active video frame field2 (even frame)
Field2Skip = NTSC_F2_SKIP;
// Sobel buffer row size (for valid Edge Detected data only)
SobelRowSize = (NTSC_ACTIVE_FLINES / SOBEL_FIELD_BLOCKS_NTSC);
// NTSC video frame - Active field spilt to # number of blocks
SobelFieldBlocks= SOBEL_FIELD_BLOCKS_NTSC;
// Number of Sobel blocks per active field (for NTSC)
SobelBlockCount = SOBEL_BLOCK_COUNT_NTSC;
}
return;
}
/*********************************************************************
Function: UpdateBufferIDs
Description: Updates Video In/Out buffers IDs
*********************************************************************/
section("App_Code_L1")
void UpdateBufferIDs (void)
{
#if defined(__ADSPBF561__)
// check Update Video Mode flag
if (SystemFlag.UpdateVideoMode == TRUE)
{
// Update video mode button has been pressed.
UpdateVideoMode(); // check the video mode
// check update video flag
if (!SystemFlag.UpdateVideoFlag)
{
// no need to update video mode
SystemFlag.UpdateVideoMode = FALSE;
return;
}
}
// Disable Video In dataflow
EnableVideoIn (FALSE);
// Disable Video Out dataflow
EnableVideoOut (FALSE);
// Close ADV717x PPI device
ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_ADV717x_CMD_SET_PPI_STATUS, (void *) ADI_ADV717x_PPI_CLOSE));
// check if new video mode was detected
if (SystemFlag.UpdateVideoFlag == TRUE)
{
// if so, reset the whole system to new video mode
// Close MDMA streams
CloseMDMA_Streams ();
// start video streaming with new video mode
SystemFlag.Pause_Frame_Capture = FALSE;
// clear UpdateVideo flag
SystemFlag.UpdateVideoFlag = FALSE;
// Configure and Install MDMA for Sobel Edge Detection with new video mode
ConfigureMDMA();
// Update ADV717x Operating video mode
UpdateADV717xVideoMode ();
// Format the Video Out frame to specified video mode
FormatVideoOutFrames();
}
// check Pause flag status
if (SystemFlag.Pause_Frame_Capture == FALSE)
{
// Pause is disabled. So Enable Video streaming
// Close ADV7183 to submit new buffers
ezErrorCheck(adi_dev_Close(ADV7183DeviceHandle));
// install ADV7183 device
InstallVideoDecoder();
// Enable Video In dataflow
EnableVideoIn (TRUE);
// Clear field copy flag as Pause is disabled
SystemFlag.FieldcopyDone = FALSE;
}
// check if pause is enabled and Field copy is already done
else if (SystemFlag.Pause_Frame_Capture && (!SystemFlag.FieldcopyDone))
{
// Pause enabled. copy paused video in buf field to avoid interleave problem
if (SystemFlag.ITU656_Mode == ITU656_NTSC)
{
// Incoming video stream is NTSC
// Arguments - pointer to video frame start location, frame type, field source, active data only
adi_video_CopyField((char *)(((ADI_DEV_BUFFER *)pPausedBuffer)->TwoD.Data), NTSC_IL,2, TRUE);
}
else if (SystemFlag.ITU656_Mode == ITU656_PAL)
{
// Incoming video stream is PAL
// Arguments - pointer to video frame start location, frame type, field source, active data only
adi_video_CopyField((char *)(((ADI_DEV_BUFFER *)pPausedBuffer)->TwoD.Data), PAL_IL, 2, TRUE);
}
// Mark as Field copy is already done
SystemFlag.FieldcopyDone = TRUE;
// Initialise Sobel edge detection for the paused frame
SobelInInit ((u32 *) pPausedBuffer);
// clear the flag as new frame is ready for edge detection
SystemFlag.SobelDone = FALSE;
}
// Open ADV717x PPI device
ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_ADV717x_CMD_SET_PPI_STATUS, (void *) ADI_ADV717x_PPI_OPEN));
// Set Dataflow method
ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *) ADI_DEV_MODE_CHAINED_LOOPBACK));
// Enable streaming
ezErrorCheck(adi_dev_Control(ADV717xDeviceHandle, ADI_DEV_CMD_SET_STREAMING, (void *) TRUE));
// submit Video Out buffer(s)
SubmitVideoOutBuffers();
// Enable Video Out dataflow
EnableVideoOut (TRUE);
#elif defined(__ADSPBF533__)
// Disable Video Out dataflow
EnableVideoOut (FALSE);
// Close ADV717x device (video encoder)
ezErrorCheck(adi_dev_Close(ADV717xDeviceHandle));
// Check if Frame capture button is pressed
if (SystemFlag.Pause_Frame_Capture == TRUE)
{
// Close MDMA streams
CloseMDMA_Streams ();
// Enable Video decoder (ADV7183) in BF533 Ez-Kit
ezEnableVideoDecoder();
// delay to stabilise 7183
ezDelay(ADV7183_DELAY);
// Install video decoder (ADV7183)
InstallVideoDecoder();
// Enable Video In dataflow to kick off frame capture
EnableVideoIn (TRUE);
// Clear frame capture flag
SystemFlag.Pause_Frame_Capture = FALSE;
#if defined(VIDEO_IN_SLIDE_SHOW) // Conditional compilation macro to enable slide show mode
SlideShowFrameCount = 0; // clear frame frequency check count
#endif
}
else // toggle between sobel/original image
{
// Instal Video Encoder (video output - ADV717x)
InstallVideoEncoder ();
// Enable Video Out dataflow
EnableVideoOut (TRUE);
}
#endif
SystemFlag.UpdateVideoMode = FALSE; // Video mode has been updated
SystemFlag.UpdateVideoInBufs = FALSE; // clear buffer update flag (video in callback)
SystemFlag.UpdateVideoOutBufs = FALSE; // clear buffer update flag (video out callback)
return;
}
/*****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -