⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dvr_ref1.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 * Copyright (c) 1995,1996,1997 by TriMedia Technologies. 
 *
 * +------------------------------------------------------------------+
 * | This software is furnished under a license and may only be used  |
 * | and copied in accordance with the terms and conditions of  such  |
 * | a license and with the inclusion of this copyright notice. This  |
 * | software or any other copies of this software may not be provided|
 * | or otherwise made available to any other person.  The ownership  |
 * | and title of this software is not transferred.                   |
 * |                                                                  |
 * | The information in this software is subject  to change without   |
 * | any  prior notice and should not be construed as a commitment by |
 * | TriMedia Technologies.                                           |
 * |                                                                  |
 * | this code and information is provided "as is" without any        |
 * | warranty of any kind, either expressed or implied, including but |
 * | not limited to the implied warranties of merchantability and/or  |
 * | fitness for any particular purpose.                              |
 * +------------------------------------------------------------------+
 *
 *  Module name              : dvr_ref1.c  1.2                 
 *
 *  Last update              : 17:50:14  -  99/11/11         
 *
 *  Description              :
 *
 *
 *
 */

/* includes of system H files */
#include <stdio.h>
#include <stdlib.h>                    
#include <tm1/mmio.h>
#include <tm1/tmProcessor.h>
#include <tm1/tmBoard.h>
#include <tm1/tmAvFormats.h>
#include <tm1/tmAImmio.h>
#include <tm1/tmAOmmio.h>
#include <tm1/tmVImmio.h>
#include <tm1/tmVOmmio.h>
#include <tm1/tmAssert.h>
#include <tm1/tmIIC.h>
#include <tm1/tsaComponent.h>                 
#include <tm1/tmBoardID.h>
#include <tmlib/dprintf.h>
#include <tm1/tsaFlash.h>
#include <tm1/tsaReg.h>

/* includes of local H files */
#include "dvr_ref1.h"      /* defines for this board */
#include "av3169.h"         /* defines for video encoder */
#include "pcm1800.h"        /* audio ADC */
#include "tw98.h"           /* video decoder */
#include "yss903.h"

#define DEBUG_LEVEL 1

/* Debug Level 
 * 0 : Only error and warning messages that are useful to debug a component
 *     are displayed.
 * 1 : Report the function calls
 * 2 : Various stuff necessary to debug this lib, like intermediate values
 * 3 : Add verbosity ... complete
*/

#if (DEBUG_LEVEL == 0)
#define L1_DP(x)
#define L2_DP(x)
#endif

#if (DEBUG_LEVEL == 1)
#define L1_DP(x)  DP(x) 
#define L2_DP(x)        
#endif

#if (DEBUG_LEVEL == 2)
#define L1_DP(x)  
#define L2_DP(x)  DP(x)      
#endif

#if (DEBUG_LEVEL == 3)
#define L1_DP(x) DP(x)
#define L2_DP(x) DP(x)
#endif

#define TRY(x) \
do { \
tmLibdevErr_t _err = (x); \
if (_err != TMLIBDEV_OK) { \
L2_DP(("Failed at line %d in file %s. Err = %x\n", __LINE__, __FILE__, _err)); \
return _err; \
}} while (0) 

#define IIC_EEPROM_ADDRESS  0xA1    /* address of boot eeprom */

#define VO_INIT_FREQ    27000000.0    /* 27 MHz */



/* forward declarations of flash functions defined in this module */
static tmLibdevErr_t dvr_ref1FlashInit(void);
static tmLibdevErr_t dvr_ref1FlashReadWord(UInt32 address, UInt32 * data);
static tmLibdevErr_t dvr_ref1FlashWriteWord(UInt32 address, UInt32 data);
static tmLibdevErr_t dvr_ref1FlashReadBlock(UInt32 address, UInt32 * data, UInt32 numberOfWords);
static tmLibdevErr_t dvr_ref1FlashWriteBlock(UInt32 address, UInt32 * data, UInt32 numberOfWords);
static tmLibdevErr_t dvr_ref1FlashEraseSector(UInt32 sector);
static tmLibdevErr_t dvr_ref1FlashEraseAll(void);

static tmLibdevErr_t boardVOInit(pboardVOParam_t param);

static tmLibdevErr_t dvr_ref1_VI_Init (pboardVIParam_t param);
static tmLibdevErr_t dvr_ref1_VI_Configure(UInt32 subaddr, UInt32 value);
static tmLibdevErr_t dvr_ref1_VI_SetBrightness(UInt val);
static tmLibdevErr_t dvr_ref1_VI_SetContrast(UInt val);
static tmLibdevErr_t dvr_ref1_VI_SetHue(UInt val);
static tmLibdevErr_t dvr_ref1_VI_SetAnalogInput(pboardVIDec_t pVD, tmVideoAnalogAdapter_t adapter, UInt adapterInstance);
static tmLibdevErr_t dvr_ref1_VI_GetAnalogInput(pboardVIDec_t pVD, tmVideoAnalogAdapter_t *adapter, UInt *adapterInstance);
//static tmLibdevErr_t dvr_ref1_VI_SetStandard(pboardVIDec_t pVD, tmVideoAnalogStandard_t standard);

static tmLibdevErr_t dvr_ref1_AO_init(pboardAOParam_t param);
static tmLibdevErr_t dvr_ref1_AO_SetSRate(Float sRate);
static tmLibdevErr_t dvr_ref1_AO_GetSRate(Float * sRate);
static tmLibdevErr_t dvr_ref1_AO_term(void);
static tmLibdevErr_t dvr_ref1_AO_start(void);
static tmLibdevErr_t dvr_ref1_AO_stop(void);
static tmLibdevErr_t dvr_ref1_AO_Config(UInt32 subaddr, Pointer value);
static tmLibdevErr_t dvr_ref1_AO_SetVolume(Int lGain, Int rGain);
static tmLibdevErr_t dvr_ref1_AO_GetVolume(Int *lGain, Int *rGain);

static tmLibdevErr_t dvr_ref1_AI_SetSRate(Float sRate);
static tmLibdevErr_t dvr_ref1_AI_Init(pboardAIParam_t param);
static tmLibdevErr_t dvr_ref1_AI_Term(void);
static tmLibdevErr_t dvr_ref1_AI_Start(void);
static tmLibdevErr_t dvr_ref1_AI_Stop(void);
static tmLibdevErr_t dvr_ref1_AI_GetSRate(Float * sRate);
static tmLibdevErr_t dvr_ref1_AI_SetInput(tmAudioAnalogAdapter_t input);
static tmLibdevErr_t dvr_ref1_AI_GetInput(tmAudioAnalogAdapter_t * input);

/* Describe video out. */
static boardVOConfig_t dvr_ref1_vo =
{
    "av3169",                   /* decoder name */
    boardVOInit,                 /* init */
    Null,                        /* term */
    Null,                        /* Hue  */
    Null,                        /* Saturation   */
    Null,
    Null,                        /* Contrast */
    Null,                        /* config */
    
    AV3169_SUPPORTED_STANDARDS,  /* supported color standards */
    AV3169_SUPPORTED_ADAPTERS,   /* supported adapters */
    intVIDEOOUT,                 /* interrupt number */
    VO_STATUS,                   /* mmioBase */
    0,                           /* gpio first pin */
    0                            /* gpio last pin */
};

#define NO_OF_VIDEO_ADAPTERS 3
static boardVIAdapterEntry_t dvr_ref1_vi_adapters [NO_OF_VIDEO_ADAPTERS] =
{
    { vaaCVBS,   0, 2 },           /* CVBS    adapter 0 */
    { vaaCVBS,   1, 1 },           /* CVBS    adapter 1 */
    { vaaSvideo, 0, 4 }            /* S-Video adapter 0 */
};


/* Describe video in. */
static boardVIConfig_t dvr_ref1_vi =
{
    "tw98",                         /* decoder name */
    dvr_ref1_VI_Init,                   /* decode init */
    Null,                           /* decoder term */
    Null,                           /* get standard */
    dvr_ref1_VI_SetHue,
    Null,
    dvr_ref1_VI_SetBrightness,
    dvr_ref1_VI_SetContrast,
    dvr_ref1_VI_Configure,              /* config */
    TW98_SUPPORTED_STANDARDS,       /* supported color standards */
    TW98_SUPPORTED_ADAPTERS,        /* supported adapters */
    intVIDEOIN,                     /* interrupt number */
    VI_STATUS,                      /* mmioBase */
    0,                              /* gpio first pin */
    0,                              /* gpio last pin */
    TW98_CAPABILITIES_FLAGS,        /* saa7111 capabilities */
    TW98_OUTPUT_FORMATS,            /* saa7111 output formats */
    tw98GetVSyncFallingEdge,        /* returns line number of VSync falling edge */
    Null,                           /* returns sliced Closed Caption data */
    Null,                           /* gives information if CC data have been available */
    Null,                           /* returns supported services for each VBI line */
    Null,                           /* sets data services to be sliced */
    Null,                           /* enables HW slicing */
    Null,                           /* set video standard for slicer */
    Null,                           /* get slicer's video standard */
    Null,                           /* toggle slicer's field ID */
    Null,                           /* set input of slicer */
    Null,                           /* get slicer's input */
    Null,                           /* set BCSH for active video */
    Null,                           /* get BCSH for active video */
    dvr_ref1_VI_SetAnalogInput,         /* set video input mode */
    dvr_ref1_VI_GetAnalogInput,         /* get video input mode */
    tw98SetStandard,                /* set video standard */
    Null,                           /* set video source type */
    Null,                           /* get video source type */
    Null,                           /* set the video's output format */
    Null,                           /* get the video's output format */
    Null,                           /* set video acquisition window */
    Null,                           /* get video acquisition window */
    tw98GetDefaultAcquisitionWnd,   /* get the default acquisition window */
    Null,                           /* set video output size */
    Null,                           /* set interlaced mode */
    Null, // saa7111DisableDecoder,          /* disable video decoder */
    Null, // saa7111EnablePowerSaveMode,     /* set power save mode */
    Null,                           /* get number of GPIOs on decoder */
    Null,                           /* set the state of one GPIO pin */
    Null,                           /* get a GPIO pin's state */
    Null,                           /* open VBI decoder */
    Null,                           /* enable VBI */
    Null,                           /* set VBI mode */
    Null,                           /* set the slicer's mode */
    Null,                           /* close VBI decoder */
    Null,                           /* get the slicer's line flags */
    { TW98_IIC_ADDRESS,             /* TW98's I2C slave address */
      NO_OF_VIDEO_ADAPTERS,         /* number of adapters          */
      dvr_ref1_vi_adapters,             /* mapping table of adapters to inputs */
      vasNone,
      0,
      Null },
    Null                            /* Get the standard for a specific adapter */
};

/* flash support */
static boardFlashConfig_t dvr_ref1Flash = 
{
    "Am29F040B",
    dvr_ref1FlashInit,
    dvr_ref1FlashReadWord,
    dvr_ref1FlashWriteWord,
    dvr_ref1FlashReadBlock,
    dvr_ref1FlashWriteBlock,
    dvr_ref1FlashEraseSector,
    dvr_ref1FlashEraseAll,
    DVR_REV1_FLASH_SIZE,
    DVR_REV1_FLASH_SECTOR_NR,
    DVR_REV1_FLASH_SECTOR_SIZE,
    0xffffffff
};

/* audio out */
static boardAOConfig_t dvr_ref1_ao = 
{
    "wm8725",            /* name of the codec */
    dvr_ref1_AO_init,        /* init */
    dvr_ref1_AO_term,        /* close */
    dvr_ref1_AO_start,       /* start */
    dvr_ref1_AO_stop,        /* stop */
    dvr_ref1_AO_SetSRate,    /* set srate */
    dvr_ref1_AO_GetSRate,    /* get srate */
    dvr_ref1_AO_SetVolume,   /* set volume */
    dvr_ref1_AO_GetVolume,   /* get volume */
    Null,                /* set output */
    Null,                /* get output */
    dvr_ref1_AO_Config,      /* config */    

    DVR_REV1_SUPPORTED_DATA_TYPES,      /* audioTypeFormats */
    DVR_REV1_SUPPORTED_DATA_SUBTYPES,   /* audioSubtypeFormats*/
    DVR_REV1_OUTPUT_AUDIO_ADAPTERS,     /* audioAdapters */
    intAUDIOOUT,                    /* interrupt */
    AO_STATUS,                      /* mmioBase */
    50000,                          /* max sRate */
    30000,                          /* min sRate */
    0,                              /* gpio first pin */
    0                               /* gpio last pin */
};

/* describe audio in */
static boardAIConfig_t dvr_ref1_ai =
{
    "pcm1800",          /* codec name */
    dvr_ref1_AI_Init,       /* init */
    dvr_ref1_AI_Term,       /* term */
    dvr_ref1_AI_Start,      /* start */
    dvr_ref1_AI_Stop,       /* stop */
    dvr_ref1_AI_SetSRate,   /* set srate */
    dvr_ref1_AI_GetSRate,   /* get srate */
    Null,               /* set volume */
    Null,               /* get volume */
    dvr_ref1_AI_SetInput,   /* set input */
    dvr_ref1_AI_GetInput,   /* get input */
    Null,               /* config */
    Null,               /* getFormat */

    pcm1800_SUPPORTED_DATA_TYPE,        /* audioTypeFormats */    
    pcm1800_SUPPORTED_DATA_SUBTYPES,    /* audioSubtypeFormats*/
    DVR_REV1_INPUT_AUDIO_ADAPTERS,          /* audioAdapters */
    intAUDIOIN,                         /* interrupt number */
    AI_STATUS,                          /* mmioBase */
    pcm1800_MAX_SRATE,                  /* max sRate */
    pcm1800_MIN_SRATE,                  /* min sRate */
    0,                                  /* gpio first pin */
    0                                   /* gpio last pin */
};


/***********************************************************************
 * Convert a floating point sample rate value
 * to a 32 bit frequency control value for the DDS.
 *
 * Accurate to .5 ppm.
 * The DDS can do better than this, but 64 bit math is
 *  required to use this interface.
 */
static UInt hertz2Control(Float rate, Int sckdiv, Int wsdiv, Int sfdiv, Float cpuClockRate)
{
    UInt DDSval;
    rate = rate * (Float) sckdiv *(Float) wsdiv *(Float) sfdiv;
    /* clock freq is in hz.  Math is 32 bit- should be 64 bit! */
    DDSval = (UInt) (0.5 + (1431655765.0 * (rate / (3*cpuClockRate)))) ;

    /* DP(("rate %f, mult %d, cpuClock %f, dds %x\n", 
        rate, sckdiv*wsdiv*sfdiv, cpuClockRate, DDSval)); */
    return DDSval;
}


/*********************************************************************
 *****************      AO section          **************************
 *********************************************************************/
/* 
   Assumptions:
    part is installed on dvr_ref1 board.
    CPU is tm1300
    Attached to first AO unit.
    Clock is generated by TM.
    Clock should be generated externally at 384 * 48khz, but this requires the A/D working.
 */
 
/*******************************************************/
static Bool AO_shutdown = True; 
static Bool AI_shutdown = True;

static void dvr_ref1AttemptToggleAudioReset(Bool ao_shutdown, Bool ai_shutdown)
{
    if (ao_shutdown && ai_shutdown)
    {
        DP(("Toggling audio reset\n"));

        /* hardware supports only stereo16 */
        aiSetWSDIV(63);
        aiSetSCKDIV(5);
        dvr_ref1_AI_SetSRate(48000);
        aiSetCAP_MODE( 3);          /* Stereo 16 bits per sample */
        aiDisableSIGN_CONVERT();
        aiMsbFirst();               /* MSB first */
        aiSetFRAMEMODE(0);          /* ignore valid bit */
        aiSampleRisingCLOCK_EDGE(); /* sample on rising edge */
        aiStartFallingEdgeWS();
        aiSetSSPOS( 0);    
        aiSetLEFTPOS(0);
        aiSetRIGHTPOS(32);

        dvr_ref1ResetAudio();
        microsleep(100);
        dvr_ref1EnableAudio();

#ifdef __LITTLE_ENDIAN__
        aiEnableLITTLE_ENDIAN();
#else
        aiDisableLITTLE_ENDIAN();
#endif
    }
}

/*******************************************************/
static tmLibdevErr_t dvr_ref1_AO_init(pboardAOParam_t param)
{
    Int                 err = TMLIBDEV_OK;
    UInt                ddsVal;
    Float               cpuClockRate;
    pprocCapabilities_t procCap;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -