📄 ppi_l1_ppi_line_transfers.c
字号:
/*********************************************************************************
Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved.
This software is proprietary and confidential. By using this software you agree
to the terms of the associated Analog Devices License Agreement.
Description:This template is designed to transfer frame data on a line basis. The
line buffers are placed in L1 memory. L2 and external memory is not used.
*********************************************************************************/
/*********************************************************************
Include files
*********************************************************************/
#include <services\services.h> // system services
#include <drivers\adi_dev.h> // device manager includes
#include <drivers\ppi\adi_ppi.h> // PPI driver includes
#include <stdio.h>
//for cycle count
#include <ccblkfn.h>
#include <sysreg.h>
#include "ppi_L1_ppi_line_transfers.h"
#include "..\..\..\..\utilities\ezkitutilities.h" // EZ-Kit utilities
#include "..\sml3\L3.h"
/*********************************************************************
User configurations:
Callbacks can be either "live" meaning they happen at hardware interrupt
time, or "deferred" meaning that the Deferred Callback Service is used
to make callbacks at a lower priority interrupt level. Deferred
callbacks usually allow the system to process data more efficiently with
lower interrupt latencies.
The macro below can be used to toggle between "live" and "deferred"
callbacks. All drivers and system services that make callbacks into an
application are passed a handle to a callback service. If that handle
is NULL, then live callbacks are used. If that handle is non-NULL,
meaning the handle is a real handle into a deferred callback service,
then callbacks are deferred using the given callback service.
*********************************************************************/
//#define USE_DEFERRED_CALLBACKS
/*********************************************************************
Device manager data
*********************************************************************/
u8 IntMgrData[(ADI_INT_SECONDARY_MEMORY)];
// DMA Manager data (base memory + memory for 1 DMA channel)
u8 DMAMgrData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY * 8)];
// Deferred Callback Manager data (memory for 1 service plus 4 posted callbacks)
#if defined(USE_DEFERRED_CALLBACKS)
u8 DCBMgrData[ADI_DCB_QUEUE_SIZE + (ADI_DCB_ENTRY_SIZE)*4];
#endif
// Device Manager data (base memory + memory for 1 device)
u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * 4)];
/*Input buffer*/
section("L1_data_a") char subFrame1[1716 * L1NumRows];
section("L1_data_a") char subFrame2[1716 * L1NumRows];
section("L1_data_a") char subFrame3[1716 * L1NumRows];
/*processed buffer*/
section("L1_data_a") char subFrame4[1716 * L1NumRows];
section("L1_data_a") char subFrame5[1716 * L1NumRows];
section("L1_data_a") char subFrame6[1716 * L1NumRows];
ADI_DCB_HANDLE DCBManagerHandle; // handle to the callback service
ADI_DMA_MANAGER_HANDLE DMAManagerHandle; // handle to the DMA Manager
ADI_DEV_MANAGER_HANDLE DeviceManagerHandle; // handle to the Device Manager
ADI_DMA_STREAM_HANDLE StreamHandle; // handle to the memory stream
ADI_DMA_STREAM_HANDLE StreamHandle1; // handle to the memory stream
ADI_DEV_2D_BUFFER Buffer2D_IN[NUM_BUFFERS_L1]; // buffer to be sent to PPI Driver
ADI_DEV_2D_BUFFER Buffer2D_OUT[NUM_BUFFERS_L1];
ADI_DEV_2D_BUFFER Buffer2D_Copy[NUM_BUFFERS]; // buffer to be sent to PPI Driver
ADI_DMA_2D_TRANSFER Buffer2D_IN_DMA[NUM_BUFFERS_L1]; // DMA buffer
ADI_DMA_2D_TRANSFER Buffer2D_OUT_DMA[NUM_BUFFERS_L1]; // DMA buffer
ADI_DMA_2D_TRANSFER Buffer2D_Copy_DMA;
unsigned int Counter = 0; // counter for the line number brought from PPI to L1
int curr_Counter=0; //current line being processed
volatile int cycle_count;
int cycle_count2=0;
extern void sys_init(void);
extern void buffer_init(void);
/*********************************************************************
Function: PPI0_callback
Description:A callback is generated when PPI0
has completed processing of the input line buffer.
Increment the counter for every input line captured.
*********************************************************************/
static void PPI0_callback(
void *AppHandle,
u32 Event,
void *pArg)
{
//static unsigned int Counter = 0; // count the number of input buffers processed
ADI_DEV_BUFFER *pBuffer; // pointer to the buffer that was processed
// CASEOF (event type)
switch (Event) {
// CASE (buffer processed)
case ADI_DEV_EVENT_BUFFER_PROCESSED:
Counter++;
if(Counter >NUM_TRANSFER)
Counter =1;
break;
// CASE (an error)
case ADI_DEV_EVENT_DMA_ERROR_INTERRUPT:
case ADI_PPI_EVENT_ERROR_INTERRUPT:
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
// ENDCASE
}
// return
}
/*********************************************************************
Function: PPI1_callback
Description:This callback fucntion can be generated when PPI1 has
transferred line buffer to the output device. In the
current implementation no callback is generated for
processing of output buffers.
*********************************************************************/
static void PPI1_callback(
void *AppHandle,
u32 Event,
void *pArg)
{
ADI_DEV_BUFFER *pBuffer; // pointer to the buffer that was processed
switch (Event) {
// CASE (buffer processed)
case ADI_DEV_EVENT_BUFFER_PROCESSED:
pBuffer = (ADI_DEV_BUFFER *)pArg;
break;
// CASE (an error)
case ADI_DEV_EVENT_DMA_ERROR_INTERRUPT:
case ADI_PPI_EVENT_ERROR_INTERRUPT:
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
// ENDCASE
}
// return
}
/*********************************************************************
Function: PPI1_callback
Description:This callback fucntion can be generated when PPI1 has
transferred line buffer to the output device. In the
current implementation no callback is generated for
processing of output buffers.
*********************************************************************/
static void MDMA_callback(
void *AppHandle,
u32 Event,
void *pArg)
{
ADI_DEV_BUFFER *pBuffer; // pointer to the buffer that was processed
switch (Event) {
// CASE (buffer processed)
case ADI_DEV_EVENT_BUFFER_PROCESSED:
pBuffer = (ADI_DEV_BUFFER *)pArg;
break;
// CASE (an error)
case ADI_DEV_EVENT_DMA_ERROR_INTERRUPT:
case ADI_PPI_EVENT_ERROR_INTERRUPT:
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
// ENDCASE
}
// return
}
/*********************************************************************
Function: Setup_VideoIn
Description: This function is called to capture video data on
the video-in device. The function first
enables the AD7183 video decoder and then configures
the PPI0 to enable video In.
*********************************************************************/
void Setup_VideoIn(
ADI_DCB_HANDLE DCBManagerHandle,
ADI_DMA_MANAGER_HANDLE DMAManagerHandle,
ADI_DEV_MANAGER_HANDLE DeviceManagerHandle,
ADI_DEV_2D_BUFFER *pBuffer2D
)
{
int i;
// table of configuration values for the PPI on input
ADI_DEV_CMD_VALUE_PAIR InboundConfigurationTable [] = {
{ ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *)ADI_DEV_MODE_CHAINED_LOOPBACK},
{ ADI_PPI_CMD_SET_CONTROL_REG, (void *)0x0184 },
{ ADI_PPI_CMD_SET_LINES_PER_FRAME_REG, (void *)525 },
{ ADI_DEV_CMD_END, NULL },
};
ADI_DEV_DEVICE_HANDLE DeviceHandle;
// enable the video decoder (7183)
ezEnableVideoDecoder();
// give the decoder time to sync
for (i = 0; i < 0xfffff; i++) ;
// open the PPI driver for input
ezErrorCheck(adi_dev_Open(DeviceManagerHandle, &ADIPPIEntryPoint, 0, NULL, &DeviceHandle, ADI_DEV_DIRECTION_INBOUND, DMAManagerHandle, DCBManagerHandle, PPI0_callback));
// configure the PPI driver with the values from the inbound configuration table
ezErrorCheck(adi_dev_Control(DeviceHandle, ADI_DEV_CMD_TABLE, InboundConfigurationTable));
// give the PPI driver the buffer to process
ezErrorCheck(adi_dev_Read(DeviceHandle, ADI_DEV_2D, (ADI_DEV_BUFFER*)pBuffer2D));
// tell the PPI driver to enable data flow
ezErrorCheck(adi_dev_Control(DeviceHandle, ADI_DEV_CMD_SET_DATAFLOW, (void *)TRUE));
}
/*********************************************************************
Function: Setup_VideoOut
Description: This function is called to display video data on
the video-out device. The function first
enables the AD7171 video encoder and then configures
the PPI1 to enable video out.
*********************************************************************/
void Setup_VideoOut(
ADI_DCB_HANDLE DCBManagerHandle,
ADI_DMA_MANAGER_HANDLE DMAManagerHandle,
ADI_DEV_MANAGER_HANDLE DeviceManagerHandle,
ADI_DEV_2D_BUFFER *pBuffer2D
){
// table of configuration values for the PPI on output
ADI_DEV_CMD_VALUE_PAIR OutboundConfigurationTable [] = {
{ ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *)ADI_DEV_MODE_CHAINED_LOOPBACK },
{ ADI_PPI_CMD_SET_CONTROL_REG, (void *)0x0182 },
{ ADI_PPI_CMD_SET_LINES_PER_FRAME_REG, (void *)525 },
{ ADI_DEV_CMD_END, NULL },
};
int i; // counter
ADI_DEV_DEVICE_HANDLE DeviceHandle; // handle to the device driver
// enable video encoder (7171)
ezEnableVideoEncoder();
// give the encoder time to sync
for (i = 0; i < 0xfffff; i++) ;
//open the PPI driver for output
ezErrorCheck(adi_dev_Open(DeviceManagerHandle, &ADIPPIEntryPoint, 1, NULL, &DeviceHandle, ADI_DEV_DIRECTION_OUTBOUND, DMAManagerHandle, DCBManagerHandle, PPI1_callback));
// configure the PPI driver with the values from the outbound configuration table
ezErrorCheck(adi_dev_Control(DeviceHandle, ADI_DEV_CMD_TABLE, OutboundConfigurationTable));
// give the PPI driver the buffer to process
ezErrorCheck(adi_dev_Write(DeviceHandle, ADI_DEV_2D, (ADI_DEV_BUFFER *)pBuffer2D));
// tell the PPI driver to enable dataflow
ezErrorCheck(adi_dev_Control(DeviceHandle, ADI_DEV_CMD_SET_DATAFLOW, (void *)TRUE));
// return
}
int static MEMDMA_CallBack(void *ClientHandle, u32 Event, void *pArg)
{
return 0;
}
/*********************************************************************
Function: main
Description: Sets up input and output PPI.
Enters a loop, continually transferring frame data
line by line
Should the last pushbutton switch ever be pressed, the loop
will exit and close down the Device Manager, DMA
Manager and, if it was enabled, the Deferred Callback
Manager.
*********************************************************************/
void main(void) {
volatile int i;
sys_init();
// populate the buffer that we'll use for the PPI input and output
buffer_init();
//move to buffer_transfer.c; dma_open
ezErrorCheck(adi_dma_MemoryOpen(DMAManagerHandle,
ADI_DMA_MDMA1_0,
(void *)0x12345678,
&StreamHandle,
NULL));
ezErrorCheck(adi_dma_MemoryOpen(DMAManagerHandle,
ADI_DMA_MDMA1_1,
(void *)0x12345678,
&StreamHandle1,
NULL));
//Since 2 PPI's on BF561 input/output video can be done simultaneously
// capture a frame of video
//Use PPI0
Setup_VideoIn(DCBManagerHandle, DMAManagerHandle, DeviceManagerHandle,&Buffer2D_IN[0]);
//For display use PPI1
Setup_VideoOut(DCBManagerHandle, DMAManagerHandle, DeviceManagerHandle, &Buffer2D_OUT[0]);
while(Counter < 1);
// WHILE (the last pushbutton is not pressed)
while (ezIsButtonPushed(EZ_LAST_BUTTON) == FALSE)
{
//Counter is incremented after every line transfer.
//curr_Counter holds the current line in the frame being processed
while(curr_Counter == Counter);
curr_Counter = Counter;
switch(curr_Counter%NUM_BUFFERS_L1)
{
case 1: /*Process subFrame1
* Place application code here. The line is in subFrame1.
* For ITU-R-656; the active video needs to seperated for every line, if entire frame mode is used
* For the template the processed buffer is assumed in subFrame1
*/
break;
case 2:
/*Process subFrame2
* Place application code here. The line is in subFrame3.
* For ITU-R-656; the active video needs to seperated for every line, if entire frame mode is used
* For the template the processed buffer is assumed in subFrame2
*/
break;
case 0:
/*Process subFrame3
* Place application code here. The line is in subFrame5.
* For ITU-R-656; the active video needs to seperated for every line, if entire frame mode is used
* For the template the processed buffer is assumed in subFrame3
*/
break;
}//end of switch
}
//close MEMDMA channels
adi_dma_MemoryClose(StreamHandle,TRUE);
adi_dma_MemoryClose(StreamHandle1,TRUE);
// close the Device Manager
ezErrorCheck(adi_dev_Terminate(DeviceManagerHandle));
// close down the DMA Manager
ezErrorCheck(adi_dma_Terminate(DMAManagerHandle));
// close down the Deferred Callback Manager
#if defined(USE_DEFERRED_CALLBACKS)
ezErrorCheck(adi_dcb_Terminate());
#endif
// return
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -