📄 coreb_old.c
字号:
/**********************************************************************
Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved.
PLease refer to the "readme" file for a description of this example.
***********************************************************************/
/*********************************************************************
Include files
*********************************************************************/
#include <services/services.h>
#include <ezkitutilities.h>
#include <drivers/adi_dev.h>
#include <drivers/adi_ppi.h>
#include "../Buffer.h"
#define ADI_NUM_SECONDARY_HANDLERS 2
#define ADI_NUM_DEVICES 1
/*********************************************************************
Static data
*********************************************************************/
// storage for interrupt manager secondary handlers
static u8 IntMgrData[(ADI_INT_SECONDARY_MEMORY * ADI_NUM_SECONDARY_HANDLERS)];
// DMA Manager data (base memory + memory for 1 DMA channel)
static u8 DMAMgrData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY * 1)];
// Deferred Callback Manager data (memory for 1 service plus 4 posted callbacks)
#if defined(USE_DEFERRED_CALLBACKS)
static u8 DCBMgrData[ADI_DCB_QUEUE_SIZE + (ADI_DCB_ENTRY_SIZE)*4];
#endif
// Device Manager data (base memory + memory for each device)
static u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * ADI_NUM_DEVICES)];
/*********************************************************************
Function: ExceptionHandler
HWErrorHandler
Description: We should never get an exception or hardware error,
but just in case we'll catch them and simply turn
on all the LEDS should one ever occur.
*********************************************************************/
static ADI_INT_HANDLER(ExceptionHandler) // exception handler
{
ezErrorCheck(1);
return(ADI_INT_RESULT_PROCESSED);
}
static ADI_INT_HANDLER(HWErrorHandler) // hardware error handler
{
ezErrorCheck(1);
return(ADI_INT_RESULT_PROCESSED);
}
/*********************************************************************
Function: Callback
Description: Each type of callback event has it's own unique ID
so we can use a single callback function for all
callback events. The switch statement tells us
which event has occurred.
In the example, we'll get a callback when the PPI
has completed processing of the input buffer. We
don't really need the callback function as the main
code uses the ProcessedFlag field of the buffer to
determine when the inbound buffer has completed
processing, but it's included here for illustrative
purposes.
Note that in the device driver model, in order to
generate a callback for buffer completion, the
CallbackParameter of the buffer must be set to a non-NULL
value. That non-NULL value is then passed to the
callback function as the pArg parameter. In the example,
the CallbackParameter is set to be the address of the
buffer itself. That allows the callback function to
determine which buffer was processed. Often the
CallbackParameter value is set to NULL for every buffer
except the last buffer in a chain. That technique causes
the callback function to get called only when the last
buffer in the chain has been processed.
*********************************************************************/
static void 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:
// point to the buffer
//pBuffer = (ADI_DEV_BUFFER *)pArg;
// increment our counter
Counter++;
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: main
Description:
*********************************************************************/
void main(void) {
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
// buffers to be sent to PPI Driver
ADI_DEV_2D_BUFFER FirstBuffer2D, SecondBuffer2D, ThirdBuffer2D,FourthBuffer2D;
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 },
};
ADI_DEV_DEVICE_HANDLE DeviceHandle;
u32 ResponseCount;
// initialize the Interrupt Manager
ezErrorCheck(adi_int_Init(IntMgrData, sizeof(IntMgrData), &ResponseCount, NULL));
// Initialize buttons & LEDs
ezInit(2);
// hook the exception handler and gardware error handler
ezErrorCheck(adi_int_CECHook(3, ExceptionHandler, NULL, FALSE));
ezErrorCheck(adi_int_CECHook(5, HWErrorHandler, NULL, FALSE));
// initialize the Deferred Callback Manager and setup a queue
#if defined(USE_DEFERRED_CALLBACKS)
ezErrorCheck(adi_dcb_Init(&DCBMgrData[0], ADI_DCB_QUEUE_SIZE, &ResponseCount, NULL));
ezErrorCheck(adi_dcb_Open(14, &DCBMgrData[ADI_DCB_QUEUE_SIZE], (ADI_DCB_ENTRY_SIZE)*4, &ResponseCount, &DCBManagerHandle));
#else
DCBManagerHandle = NULL;
#endif
// initialize the DMA Manager
ezErrorCheck(adi_dma_Init(DMAMgrData, sizeof(DMAMgrData), &ResponseCount, &DMAManagerHandle, NULL));
// initialize the Device Manager
ezErrorCheck(adi_dev_Init(DevMgrData, sizeof(DevMgrData), &ResponseCount, &DeviceManagerHandle, NULL));
// populate the buffer that we'll use for the PPI output
FirstBuffer2D.Data = sFrame0OUT;
FirstBuffer2D.ElementWidth = TRANSFER_LENGTH;
FirstBuffer2D.XCount = 1716/TRANSFER_LENGTH;
FirstBuffer2D.XModify = TRANSFER_LENGTH;
FirstBuffer2D.YCount = NUMROWS;
FirstBuffer2D.YModify = TRANSFER_LENGTH;
FirstBuffer2D.CallbackParameter = &FirstBuffer2D;//NULL;
// FirstBuffer2D.pNext = NULL;
FirstBuffer2D.pNext = &SecondBuffer2D;
SecondBuffer2D.Data = sFrame1OUT;
SecondBuffer2D.ElementWidth = TRANSFER_LENGTH;
SecondBuffer2D.XCount = 1716/TRANSFER_LENGTH;
SecondBuffer2D.XModify = TRANSFER_LENGTH;
SecondBuffer2D.YCount = NUMROWS;
SecondBuffer2D.YModify = TRANSFER_LENGTH;
SecondBuffer2D.CallbackParameter = &FirstBuffer2D;//NULL;
SecondBuffer2D.pNext = &ThirdBuffer2D;
ThirdBuffer2D.Data = sFrame2OUT;
ThirdBuffer2D.ElementWidth = TRANSFER_LENGTH;
ThirdBuffer2D.XCount = 1716/TRANSFER_LENGTH;
ThirdBuffer2D.XModify = TRANSFER_LENGTH;
ThirdBuffer2D.YCount = NUMROWS;
ThirdBuffer2D.YModify = TRANSFER_LENGTH;
ThirdBuffer2D.CallbackParameter = &FirstBuffer2D;//NULL;
ThirdBuffer2D.pNext = &FourthBuffer2D;
FourthBuffer2D.Data = sFrame3OUT;
FourthBuffer2D.ElementWidth = TRANSFER_LENGTH;
FourthBuffer2D.XCount = 1716/TRANSFER_LENGTH;
FourthBuffer2D.XModify = TRANSFER_LENGTH;
FourthBuffer2D.YCount = NUMROWS;
FourthBuffer2D.YModify = TRANSFER_LENGTH;
FourthBuffer2D.CallbackParameter = &FirstBuffer2D;//NULL;
FourthBuffer2D.pNext = NULL;
ezEnableVideoEncoder();
// open the PPI driver for output
// ezErrorCheck(adi_dev_Open(DeviceManagerHandle, &ADIPPIEntryPoint, 1, NULL, &DeviceHandle, ADI_DEV_DIRECTION_OUTBOUND, DMAManagerHandle, DCBManagerHandle, 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 *)&FirstBuffer2D));
// tell the PPI driver to enable dataflow
// ezErrorCheck(adi_dev_Control(DeviceHandle, ADI_DEV_CMD_SET_DATAFLOW, (void *)TRUE));
while(ButtonPressed == FALSE);
// close the PPI driver
ezErrorCheck(adi_dev_Close(DeviceHandle));
// 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 + -