📄 jpeg_mjpeg_system.c
字号:
/*****************************************************************************
Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved. This software is
proprietary and confidential to Analog Devices, Inc. and its licensors.
******************************************************************************
$RCSfile: jpeg_mjpeg_system.c,v $
$Revision: 1.4 $
$Date: 2006/11/13 01:30:51 $
Project: BlackfinSDK (JPEG-MJPEG)
Title: system services
Author(s): bmk
Revised by:
Description:
Functions to configure system services and start devices
for jpeg-mjpeg
References:
None
******************************************************************************
Tab Setting: 4
Target Processor: ADSP-BF5xx
Target Tools Revision: ADSP VisualDSP++ v4.5
******************************************************************************
Modification History:
====================
$Log: jpeg_mjpeg_system.c,v $
Revision 1.4 2006/11/13 01:30:51 bmk
BF561-removed ezDelay call in encoding mode
Revision 1.2 2006/11/10 07:18:58 bmk
merged BF533 & BF561 apps
Fixed BF561 cache issue
Revision 1.1 2006/11/03 07:12:09 bmk
SDK 2.0 files - Initial Entry
******************************************************************************
Includes
********************************/
#include <jpeg_mjpeg_system.h> // System includes
#include <jpeg_mjpeg_heap.h> // Heap includes
#include <jpeg_mjpeg_cache.h> // Cache includes
#include <jpeg_mjpeg_err.h> // JPEG-MJPEG error code process includes
#include <jpeg_mjpeg_cplb_tables.h> // CPLB table includes
// USB includes
#include <drivers\usb\net2272\adi_net2272.h> // NET2272 device driver includes
#include <drivers\usb\net2272\plx\nccommon.h> // Netchip common includes
#include <adi_usbcmd.h> // supported USB commands
#include <adi_usbio_blackfin.h> // USB I/O functions for Blackfin
// Device Driver Includes
#include <drivers\twi\adi_twi.h> // TWI driver includes
#include <drivers\ppi\adi_ppi.h> // PPI driver includes
#include <drivers\encoder\adi_adv717x.h> // video encoder driver includes
#include <drivers\decoder\adi_adv7183.h> // video decoder driver includes
/********************************
Local data and handles
********************************/
// DMA Manager data :base memory +
// memory for 1 PPI DMA channel +
// memory for 2 MDMA channels (USB driver) +
// memory for 2 MDMA channels (YUV to Video Frame)
static u8 DMAMgrData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY * 5)];
// Deferred Callback Manager data (memory for 1 service plus 6 posted callbacks)
static u8 DCBMgrData[ADI_DCB_QUEUE_SIZE + (ADI_DCB_ENTRY_SIZE)*6];
// Device Manager data: base memory +
// memory for video encoder or video decoder +
// 1 twi + 1 PPI + 1 USB device
static u8 DevMgrData[ADI_DEV_BASE_MEMORY + (ADI_DEV_DEVICE_MEMORY * 4)];
// Interrupt Manager data
#if defined(__ADSPBF533__)
// no secondary interrupts needed for BF533
static u8 IntMgrData[(ADI_INT_SECONDARY_MEMORY * 0)];
#elif defined(__ADSPBF561__)
// BF561 - USB uses MDMA in DMA controller 2 & requires secondary interrupt memory
// Interrupt memory for 1 MDMA stream in DMA controller 2
static u8 IntMgrData[(ADI_INT_SECONDARY_MEMORY * 1)];
#endif
/*****************
Callback functions
******************/
// Exception handler
static ADI_INT_HANDLER (ExceptionHandler);
// Hardware error handler
static ADI_INT_HANDLER (HWErrorHandler);
// Video In callback function (for ADV7183)
static void VideoInCallback (void *AppHandle, u32 Event, void *pArg);
// Video Out callback function (for ADV717x)
static void VideoOutCallback (void *AppHandle, u32 Event, void *pArg);
// USB driver callback
static void NET2272_Callback (void *AppHandle, u32 Event, void *pArg);
/************************
Local function prototype
************************/
// Installs USB driver
void InstallUSBdriver (void);
// updates video parameters to selected video mode
void UpdateVideoMode (void);
/*****************
Globals
******************/
// Device Driver and System Services Handles
// handle to the callback service Manager
ADI_DCB_HANDLE DCBManagerHandle;
// handle to the DMA Manager
ADI_DMA_MANAGER_HANDLE DMAManagerHandle;
// handle to the Device Manager
ADI_DEV_MANAGER_HANDLE DeviceManagerHandle;
// handle to the ADV717x device driver
ADI_DEV_DEVICE_HANDLE ADV717xDeviceHandle;
// handle to the ADV7183 device driver
ADI_DEV_DEVICE_HANDLE ADV7183DeviceHandle;
// handle to the USB device driver
ADI_DEV_DEVICE_HANDLE USBDeviceHandle;
// Video parameters
// Video data per line (bytes)
u32 DataPerLine;
// Number of lines per ITU656 video frame (bytes)
u32 FrameLines;
// Number of Active lines per ITU656 video frame (bytes)
u32 ActiveFrameLines;
// Number of bytes to skip to reach active video data in a single line
u32 ActiveVideoSkip;
// Number of bytes to skip to reach active video frame field1 (odd frame)
u32 Field1Skip;
// Number of bytes to skip to reach active video frame field2 (even frame)
u32 Field2Skip;
// Video Input/Output mode
u8 VideoMode;
// Selected Video Output mode
u8 OutputVideoMode;
// Device parameters
u8 Coding_Algorithm = CODING_ALGORITHM_JPEG;
u8 Coding_Action = CODING_ACTION_DECODE;
u8 File_Settings = GET_FILE_SETTINGS_FROM_TXT_FILE;
// Buffer to Hold YUV data from decoded JPEG image
// size to support only ITU656 resolution & YUV400/YUV420/YUV422 image formats
#pragma section("YUV_Buffer", NO_INIT)
u8 YUVBufs [YUV_BUF_SIZE];
// define two ITU656 video frame buffers (JPEG uses only one & MJPEG uses both)
// place them in separate SDRAM banks
#pragma section("ITU656_Buffer1", NO_INIT)
u8 ITU656_Frame0 [ITU656_BUF_SIZE];
#pragma section("ITU656_Buffer2", NO_INIT)
u8 ITU656_Frame1 [ITU656_BUF_SIZE];
// Buffer pointers
// Pointer to buffers containing YUV data of decoded JPEG image or to be encoded JPEG file
section("L1_data_a") u8 *pYUVBufs[NUM_YUV_BUFS] = {NULL} ;
// Pointer to buffers containing JPEG/MJPEG image in ITU656 frame format
section("L1_data_a") u8 *pITU656Frames[2] = { &ITU656_Frame0[0], &ITU656_Frame1[0] };
// YUV <-> ITU656 conversion parameters
u32 JPEGImageWidth; // Actual width of JPEG image to be encoded/decoded
u32 JPEGImageHeight; // Actual height of JPEG image to be encoded/decoded
unsigned int JPEGFrameFormat; // Frame format of decoded JPEG/MJPEG file
// Pointer to Video frame /YUV buffer ready for YUV <-> Video frame (ITU656) conversion (to update MDMA source descriptor)
section("L1_data_a") volatile u8 *pSrcDescStartAddr;
// Pointer to YUV/Video frame buffer ready for YUV <-> Video frame (ITU656) conversion (to update MDMA destination descriptor)
section("L1_data_a") volatile u8 *pDestDescStartAddr;
// Semaphores used for handshaking btwn ISR and foreground code.
section("L1_data_a") volatile bool StartMDMA;
section("L1_data_a") volatile bool FrameReady;
section("L1_data_a") volatile u8 BufferLevel;
section("L1_data_a") volatile u8 YUV_MDMA_BufID;
section("L1_data_a") volatile u8 MJPEG_YUV_BufID;
section("L1_data_a") volatile u32 VideoFrameCounter;
section("L1_data_a") volatile u32 FrameDroppedCounter;
section("L1_data_a") volatile bool VideoFrameCompletedFlag;
section("L1_data_a") volatile bool isMJEInputDataAvailable;
section("L1_data_a") volatile bool isMJDInputDataAvailable;
// JPEG/MJPEG frame background colour - black (UYVY)
char JPEGImageBackground[] = {0x80,0x10,0x80,0x10};
/*********************************************************************
Device Configuration tables
*********************************************************************/
#if defined(__ADSPBF533__)
// BF533 Ports (PF0=SCL,PF1=SDA) & Timer(Timer 0) used for Pseudo TWI
adi_twi_pseudo_port port={ADI_FLAG_PF0,ADI_FLAG_PF1,ADI_TMR_GP_TIMER_0,(ADI_INT_PERIPHERAL_ID)NULL};
#elif defined(__ADSPBF561__)
// BF561 Ports (PF0=SCL,PF1=SDA) & Timer(Timer 2) used for Pseudo TWI
adi_twi_pseudo_port port={ADI_FLAG_PF0,ADI_FLAG_PF1,ADI_TMR_GP_TIMER_2,(ADI_INT_PERIPHERAL_ID)NULL};
#endif
#if defined(__ADSPBF533__) || defined (__ADSPBF561__)
// Pseudo TWI Configuration to access video encoder/decoder registers
// Run TWI clock at 100MHz & 50% Duty Cycle
adi_twi_bit_rate rate={100,50};
ADI_DEV_CMD_VALUE_PAIR TWIConfig[]={ // configuration table for the TWI driver
{ ADI_TWI_CMD_SET_PSEUDO, (void *)(&port) },
{ ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *)ADI_DEV_MODE_SEQ_CHAINED},
{ ADI_TWI_CMD_SET_FIFO, (void *)0x0000 },
{ ADI_TWI_CMD_SET_RATE, (void *)(&rate) },
{ ADI_TWI_CMD_SET_LOSTARB, (void *)1 },
{ ADI_TWI_CMD_SET_ANAK, (void *)0 },
{ ADI_TWI_CMD_SET_DNAK, (void *)0 },
{ ADI_DEV_CMD_SET_DATAFLOW, (void *)TRUE },
{ ADI_DEV_CMD_END, NULL }
};
#else
#error "*** ERROR: Application doesnot support this processor yet ***"
#endif
/*********************************************************************
Function: InitSystem
Description: Initialises EZ kit & Video Parameters
*********************************************************************/
section("sdram0_bank1_nocache")
void InitSystem(void)
{
u8 i;
ezInit (1); // Initialise Ez kit (This app uses only one core)
ezTurnOffAllLEDs (); // Turn off all LEDs
OutputVideoMode = ITU656_NTSC; // Default output mode
VideoMode = OutputVideoMode; // Default video mode
VideoFrameCompletedFlag = FALSE;
isMJEInputDataAvailable = FALSE;
isMJDInputDataAvailable = FALSE;
VideoFrameCounter = 0;
FrameDroppedCounter = 0;
// generate YUV buffer addresses
for (i=0; i<NUM_YUV_BUFS;i++)
{
pYUVBufs[i] = &YUVBufs[(i*SINGLE_YUV_BUF_SIZE)];
}
// update video parameters
UpdateVideoMode();
// initialise the ezkit record button
ezInitButton(JPEG_MJPEG_RECORD_BUTTON);
return;
}
/*********************************************************************
Function: InstallMemory
Description: Initialises & installs Cache & Heap for JPEG-MJPEG
*********************************************************************/
section("sdram0_bank1_nocache")
void InstallMemory()
{
// Configure cache
disable_data_cache();
configure_data_cache_cplbs(codec_dcplbs_table);
enable_data_cache();
disable_instruction_cache();
configure_instruction_cache_cplbs(codec_icplbs_table);
enable_instruction_cache();
// Install heaps
InstallCodecHeaps();
return;
}
/*********************************************************************
Function: InstallSystemServices
Description: Installs system services
*********************************************************************/
// function implementations
section("sdram0_bank1_nocache")
void InstallSystemServices(void)
{
u32 ResponseCount; // response counter
// initialize the Interrupt Manager and hook the exception and hardware error interrupts
ezErrorCheck(adi_int_Init(IntMgrData, sizeof(IntMgrData), &ResponseCount, NULL));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -