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

📄 philips_dtv_ref5.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
 * Copyright (c) 1995 - 1999 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              : philips_dtv_ref5.c    1.6
 *
 *  Last update              : 19:04:43 - 00/11/09
 *
 * Description              :
 *
 * Board Support Package for Trimedia peripherals. This particular file supports
 * the Philips DTV REF 5 (Saturn).
 *
 *
 */

#include <tm1/mmio.h>
#include <tm1/tmBoardID.h>
#include <tm1/tmBoard.h>
#include <tm1/tmProcessor.h>
#include <tm1/tmVImmio.h>
#include <tm1/tmAssert.h>
#include <tm1/tmHDVOmmio.h>
#include <tm1/tmAvFormats.h>
#include <tmlib/dprintf.h>
#include <tm1/tsaComponent.h>
#include <tm1/tmGPIO.h>
#include <tm1/tmGPIOpins.h>
#include <tm1/tmGPIOmmio.h>
#include <tm1/tsaFlash.h>
#include <tm1/tsaFlashBoard.h>
#include <tm1/tsaPIC.h>
#include <tm1/tsaPICboard.h>
#include <tm1/tsaIR.h>
#include <tm1/tsaIRboard.h>
#include <tm1/tmIIC.h>
#include <tm1/tsaReg.h>
#include <tm1/tmVO.h>  /* required to setup saa7125 */

/* includes of local H files */
#include "philips_dtv_ref5.h"
#include "dtv_ref5_audio.h"
#include "voSupport.h"
#include "saa7125.h"
#include "xioReg.h"
#include "iicDirection.h"

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

#define DP_R5(x)
#define IR_DP(x)

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

/* forward declarations of functions defined in this module */
static tmLibdevErr_t dtvRef5_board_activate(pcomponent_t comp);
static tmLibdevErr_t dtvRef5_board_init(void);
static tmLibdevErr_t dtvRef5_board_detect(void);
static tmLibdevErr_t dtvRef5_board_register(pcomponent_t comp);
static tmLibdevErr_t dtvRef5DirectionSwitch(UInt32 direction);

/* forward declarations of flash functions defined in this module */
static tmLibdevErr_t dtvRef5FlashInit(void);
static tmLibdevErr_t dtvRef5FlashReadWord(UInt32 address, UInt32 * data);
static tmLibdevErr_t dtvRef5FlashWriteWord(UInt32 address, UInt32 data);
static tmLibdevErr_t dtvRef5FlashReadBlock(UInt32 address, UInt32 * data, UInt32 numberOfWords);
static tmLibdevErr_t dtvRef5FlashWriteBlock(UInt32 address, UInt32 * data, UInt32 numberOfWords);
static tmLibdevErr_t dtvRef5FlashEraseSector(UInt32 sector);
static tmLibdevErr_t dtvRef5FlashEraseAll(void);

/* declaration of PIC functions */
static tmLibdevErr_t dtvRef5PICInit(UInt32 source);
static tmLibdevErr_t dtvRef5PICTerm(UInt32 source);
static tmLibdevErr_t dtvRef5PICStart(UInt32 source);
static tmLibdevErr_t dtvRef5PICStop(UInt32 source);
static tmLibdevErr_t dtvRef5PICAck(UInt32 source);
static Bool dtvRef5PICSourceDetect(UInt32 * source);

/* declaration of IR functions */
static tmLibdevErr_t dtvRef5IRInit(pboardIRParam_t params);
static tmLibdevErr_t dtvRef5IRTerm(void);
static tmLibdevErr_t dtvRef5IRStart(void);
static tmLibdevErr_t dtvRef5IRStop(void);
static void dtvRef5IRGetEvent(tsaIREvent_t *event, UInt32 *value);

static UInt boardID = 0;

/* PIC support */
#define DTV_REF5_PIC_NUM_SUPPORTED_INTS 1
#define DTV_REF5_PIC_SOURCE_IR          0
#define DTV_REF5_PIC_SOURCE_MENU        1
#define DTV_REF5_PIC_SOURCE_UP          2
#define DTV_REF5_PIC_SOURCE_DN          3
#define DTV_REF5_PIC_NUM_SRCS           4
/* these are the sources supported by the PIC */
static tsaPICSource_t dtvRef5PICSrcTable[DTV_REF5_PIC_NUM_SRCS] = 
{
    picSourceIrIn0, picSourceUsr0, picSourceUsr1, picSourceUsr2
};

static boardPICIntCaps_t dtvRef5PICIntCaps[DTV_REF5_PIC_NUM_SUPPORTED_INTS] =
{
{
    intGPIO,                /* interrupt */
    True,                   /* levelTriggered */
    intPRIO_3,              /* interrupt priority */
    DTV_REF5_PIC_NUM_SRCS,  /* numSources */
    dtvRef5PICSrcTable,
    dtvRef5PICInit,         /* initFunc */
    dtvRef5PICTerm,         /* termFunc */
    dtvRef5PICSourceDetect, /* sourceDetectFunc */
    dtvRef5PICStart,        /* startFunc */
    dtvRef5PICStop,         /* stopFunc */
    dtvRef5PICAck,          /* ackFunc */
}
};

static boardPICConfig_t dtvRef5PIC =
{
    "REF5 PIC",
    DTV_REF5_PIC_NUM_SUPPORTED_INTS,
    dtvRef5PICIntCaps
};

/* IR support */
#define DTV_REF5_IR_SUPPORTED_DEVICES (irdRC5)
static boardIRConfig_t dtvRef5IR =
{
    "GPIO IR",
    dtvRef5IRInit,     /* initFunc */
    dtvRef5IRTerm,     /* termFunc */
    dtvRef5IRStart,    /* startFunc */
    dtvRef5IRStop,     /* stopFunc */
    Null,              /* config not supported */
    dtvRef5IRGetEvent, /* getEventFunc */
    DTV_REF5_IR_SUPPORTED_DEVICES
};

/* flash support */
static boardFlashConfig_t dtvRef5Flash = 
{
    "Am29F032B",
    dtvRef5FlashInit,
    dtvRef5FlashReadWord,
    dtvRef5FlashWriteWord,
    dtvRef5FlashReadBlock,
    dtvRef5FlashWriteBlock,
    dtvRef5FlashEraseSector,
    dtvRef5FlashEraseAll,
    DTV_REF5_FLASH_SIZE,
    DTV_REF5_FLASH_SECTOR_NR,
    DTV_REF5_FLASH_SECTOR_SIZE,
    0xffffffff
};

/* Describe audio out. Only AO1_SD4 o/p used  */
static boardAOConfig_t dtvRef5_ao_1 =
{
    "DTV REF5 AO1",        /* determined in init */
    dtvRef5_AO_Init_1,     /* init */
    dtvRef5_AO_Term_1,     /* term */
    dtvRef5_AO_Start_1,    /* start */
    dtvRef5_AO_Stop_1,     /* stop */
    dtvRef5_AO_SetSRate_1, /* set srate */
    dtvRef5_AO_GetSRate_1, /* get srate */
    Null,                      /* set volume */
    Null,                      /* get volume */
    Null,                      /* set output */
    Null,                      /* get output */
    Null,                      /* config */
    DTV_REF5_SUPPORTED_AUDIO_OUT_TYPES_1,    /* audioTypeFormats */
    DTV_REF5_SUPPORTED_AUDIO_OUT_SUBTYPES_1, /* audioSubtypeFormats*/
    DTV_REF5_OUTPUT_AUDIO_ADAPTERS_1,       /* audioAdapters */
    intAUDIOOUT,               /* interrupt number */
    AO1_STATUS,                /* mmioBase */
    50000,                     /* max sample rate */
    20000,                     /* min sample rate */
    GPIO_AO1_OSCLK,            /* gpio first pin */
    GPIO_AO1_SD4               /* gpio last pin */
};

/*
 * HDVO
 */
tmLibdevErr_t dtvRef5_HDVO_Init (tmVideoAnalogStandard_t standard,
				     tmVideoAnalogAdapter_t  adapterType,
				     tmVideoTypeFormat_t     videoType,
				     hdvoImageOutputMode_t   videoSubtype,
				     UInt32                  description)
{
    UInt32        temp;
    tmLibdevErr_t err;
    boardVOParam_t param;

    param.videoStandard = standard;

    /*
     * HDVO is Clk and Sync master
     */
    hdvoEnableMCP_CTRL_ClkOut();
    hdvoEnableMCP_CTRL_Sync_Master();

    switch (standard) {
    case vas720x480p:
      DP(("dtvRef5_HDVO_Init: initialising for progressive output \n"));

      temp = MMIO(GPIOJ_OUT);
      temp &= 0xfffcffff; /* reset for SAA 7167 and SAA 7125 low */
      temp |= 0x00020000; /* take SAA 7167 out of reset */
      MMIO(GPIOJ_OUT) = temp;
      
      /* workaround for bug in tmhal.c */
      temp = MMIO(GPIOJ_MOD2);
      temp |= 0x0a;
      MMIO(GPIOJ_MOD2) = temp;
      
      /* Init saa7167 */
      err = iicWriteReg(0xBE, 0, 0x1e);
      if (err != TMLIBDEV_OK) {
	DP(("SAA7167 Initialisation failed \n"));
	return err;
      }
      break;

    case vasNTSC:
      DP(("dtvRef5_HDVO_Init: initialising for interlaced output \n"));

      temp = MMIO(GPIOJ_OUT);
      temp &= 0xfffcffff; /* reset for SAA 7167 and SAA 7125 low */
      temp |= 0x00010000; /* take SAA 7125 out of reset */
      MMIO(GPIOJ_OUT) = temp;
      
      /* workaround for bug in tmhal.c */
      temp = MMIO(GPIOJ_MOD2);
      temp |= 0x0a;
      MMIO(GPIOJ_MOD2) = temp;

      /* Init saa7125 */
      err = saa7125Init(&param);

      if (err) {
	DP(("dtvRef5_HDVO_Init: saa7125Init returned 0x%x\n", err));
	return err;

      }
      break;

    default:
      DP(("dtvRef5_HDVO_Init: Unsupported video standard 0x%x\n", standard));
      return BOARD_ERR_UNSUPPORTED_STANDARD;
    }

    return TMLIBDEV_OK;
}

tmLibdevErr_t dtvRef5_HDVO_Term(void) 
{ 
    return TMLIBDEV_OK;
}

tmLibdevErr_t dtvRef5_HDVO_Config(UInt32 address, UInt32 value)
{
    return TMLIBDEV_OK;
}

static boardHDVOConfig_t dtvRef5_hdvo =
{
  "HDVO1",
  &dtvRef5_HDVO_Init,
  &dtvRef5_HDVO_Term,
  &dtvRef5_HDVO_Config,
  vas720x480p | vasNTSC,
  vaaGeneric,
  vtfYUV | vtfRGB,
  hdvoImageOutput_8b_YUV422 | hdvoImageOutput_8b_444,
  vdfInterlaced | vdfProgressive,
  intHDVO,
  GPIO_HDVO_CLK,
  GPIO_HDVO_D29
};

static boardMPConfig_t dtvRef5_mp =
{
  intMPEG,
  MP_VLD_COMMAND,  /* mmio base offset of pipe */
};  

/***********************************************************************/
static tmLibdevErr_t dtvRef5DirectionSwitch(UInt32 direction)
{
    UInt32 val = MMIO(GPIOJ_OUT) & ~DTV_REF5_IIC_DIRECTION_MASK;

    switch (direction)
    {
    case IIC_DIRECTION_BOOT_ROM:
        val |= DTV_REF5_IIC_DIRECTION_BOOT;
        break;
    case IIC_DIRECTION_NIM1:
    case IIC_DIRECTION_RTC:
        val |= DTV_REF5_IIC_DIRECTION_RTC;
        break;
    default:
        return 1;
    }

    MMIO(GPIOJ_OUT) = val;

    return TMLIBDEV_OK;
}

/* PIC functions */
/* Event register definition */
#define REF5_GPIO_IR_EVENT   0
#define REF5_GPIO_MENU_EVENT 1
#define REF5_GPIO_UP_EVENT   2
#define REF5_GPIO_DN_EVENT   3

static tmLibdevErr_t dtvRef5PICInit(UInt32 source)
{
    DP_R5(("dtvRef5PICInit(%d)\n", source));

    switch (source)
    {
    case DTV_REF5_PIC_SOURCE_IR:
    {
        /* Initialize event handler for GPIOJ05. This pin uses event 0. */
        gpioSetSOURCE_SEL(REF5_GPIO_IR_EVENT, GPIO_GPIOJ05);
        gpioSetEVENT_MODE(REF5_GPIO_IR_EVENT, 0x03);
        gpioEnableEV_INTEN(REF5_GPIO_IR_EVENT);

        break;
    }    
    case DTV_REF5_PIC_SOURCE_MENU:
    {
        /* Initialize event handler for GPIOJ00. This pin uses event 1. */
        gpioSetSOURCE_SEL(REF5_GPIO_MENU_EVENT, GPIO_GPIOJ00);
        gpioSetEVENT_MODE(REF5_GPIO_MENU_EVENT, 0x02);
        gpioEnableEV_INTEN(REF5_GPIO_MENU_EVENT);

        break;
    }    
    case DTV_REF5_PIC_SOURCE_UP:
    {
        /* Initialize event handler for GPIOJ01. This pin uses event 2. */
        gpioSetSOURCE_SEL(REF5_GPIO_UP_EVENT, GPIO_GPIOJ01);
        gpioSetEVENT_MODE(REF5_GPIO_UP_EVENT, 0x02);

⌨️ 快捷键说明

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