📄 xport.c
字号:
/* Copyright 1997, ESS Technology, Inc. *//* SCCSID @(#)xport.c 1.59 2/25/98 *//* * $Log$ */#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include "buffer.h"#include "const.h"#include "common.h"#include "debug.h"#include "mvd.h"#include "tdm.h"#include "low.h"#include "util.h"#include "vcxi.h"#include "xport.h"#define PRINTF(a)#if 0 /* doing sub-picture */#undef SUB_PICTURE#endif/**************************************************************************** Various defines ****************************************************************************/#define ALTMODE 0x00000013#define DVBMODE 0x00000003#define PS8MODE DVBMODE#define PS16MODE 0x00000001#define DestVideo 0#define DestAudio 2#define DestAux 4#define DestUser 6#define DestRisc 1#define makepid(pid,CCvalid,CCvalue,dest) \ ((1L<<21L) + \ ((pid &0x01fffL)<<8L) + \ ((CCvalid&0x00001L)<<7L) + \ ((CCvalue&0x0000fL)<<3L) + \ (dest & 0x00007L) )/**************************************************************************** Transport mode select. Things like 8 or 16 bit, DVB or DSS. ****************************************************************************/#define select_xport_mode(xport_type) \ (xport_type == DSS_SIMPLE)? (PS16MODE | 0x10) : PS16MODE;#define AID_CHECK 0x2d /* AC3 substream ID patch location */#define PS_BYPASS 0x2c /* AC3 substream ID check bypass for generic PS */#define SP_BYPASS 0x2f /* AC3 extra info code bypass for sub-picture */#define CONTINUE 0x32 /* This is where continue is *//**************************************************************************** Local function prototypes ****************************************************************************/#ifdef MPEG2static void patch_xport_ucode(int, int);#endifstatic void load_xport_cam(int *, int);PRIVATE void XPORT_adj_match_channel(int);PRIVATE unsigned int XPORT_UcodeImmd(int, unsigned int);/**************************************************************************** Local variables ****************************************************************************/#ifdef MPEG2static int xport_video = -1; /* PID of video packets */static int xport_audio = -1; /* PID of audio packets */#endifstatic int x07f07fff = 0x07f07fff;#ifdef MPEG2/**************************************************************************** Patch transport ucode. ****************************************************************************/static void patch_xport_ucode(int location, int code){ int real; mvd[xport_misc] = XPORT_LDMC | XPORT_RESET; mvd[xport_microcode_table+location] = code;#ifdef DEBUG mvd[xport_misc] = XPORT_RESET; mvd[xport_misc] = XPORT_LDMC | XPORT_RESET; real = mvd[xport_microcode_table+location]; real = mvd[xport_microcode_table+location] & 0x0fffffffL; if (real != code) { FATAL(("Xport ucode patch verification error\n")); }#endif mvd[xport_misc] = XPORT_RESET;}#endif/**************************************************************************** XPORT interrupt service routine ****************************************************************************/#ifdef XPORT20#define XPORT_MAX_FIFO 7 /* <00:mm> <ss:ff> <sub:code> <01:ID> * * <junk:d> <d:d> <d:d> */#else#define XPORT_MAX_FIFO 8 /* Add <mode:filenumber> */#endifunsigned short XPORT_fifo[XPORT_MAX_FIFO]; /* XPORT->RISC FIFO data *//* * XPORT seq interrupt handler. This routine reads all the XPORT * FIFO data. Due to a bug in XPORT hardware, it is more reliable to * read the FIFO while nobody is writing to the FIFO. The current * XPORT microcode will make sure that after the last RISC FIFO data * is sent, trigger a seq. interrupt; this interrupt is far away from * the next RISC FIFO data. * * The data will be read out, and it will be process in TDM interrup * just like before. * * Return: * 1: Equivalent to TDM interrupt (for DVD_VCD) */int XPORT_interrupt_service(void){ int loop, max, cnt; mvd[xport_clear_stat_bits] = 2; /* Clear seq. IRQ */ /* * Counter is usually one less than what is in the FIFO. However, * if there is nothing in FIFO, the counter is still 0. */ cnt = (mvd[xport_read_rff_count] & 0x3f) + 1;#ifdef DVD_VCD /* * For DVD_VCD, we have the following cases for RISC FIFO * 1) No data, this is equivalent to TDM interrupt (i.e. all the * data are in) * 2) 2 items, this is currCDtime. This is also equivalent to * TDM interrupt * 3) 3 items. For M2F1 (i.e. getSector), data is not in yet; * For M2F2 (playSector), this means we can't find stream ID, * so equivalent to TDM interrupt * 4) 5/7 items. Since there is ID and PTS etc, data is not in yet. * * There can be at most 2 XPORT interrupts in a sector, so if * XPORT_fifo_length is not zero, then we had 1 previous XPORT * interrupt without calling TDM interrupt handler; in which case, * don't read the RISC FIFO since it may hold data for the next * sector if the interrupt latency is too long. * * There is one corner case: * If the number of data bytes in a sector is very small, we may * get the end-of-data interrupt before we even handle the RISC-FIFO * data interrupt. As a result, we handle both interrupts in one * call to XPORT_interrupt_service. In which case, XPORT_fifo_length * will be 0 and cnt will be non-zero. If cnt is 5, we'll be mislead * to believe that data is not in yet when it is really in already. * * To be on the safe side, we'll do two things: * 1) When we enter, if XPORT_fifo_length == 0 and XPORT is executing * flush_pipe/find_synd2, treat it as a "TDM interrupt." * 2) When XPORT is in "stop state", force a "TDM interrupt." */ if (XPORT_fifo_length) cnt = 0; /* No real data */ else { int pc; pc = mvd[xport_read_status] & 0x7f; XPORT_fifo_length = cnt; /* * Since nobody is writing to the RISC FIFO, reading it now * shall give reliable result! * * Make sure the number of data item makes sense. */ if ((max = XPORT_fifo_length) > XPORT_MAX_FIFO) max = XPORT_MAX_FIFO; /* Read the FIFO data into an array */ for (loop = 0; loop < max; loop++) XPORT_fifo[loop] = mvd[xport_read_risc_data]; /* If we have more data unexpectly, throw them away */ for (loop; loop < XPORT_fifo_length; loop++) reg0 = mvd[xport_read_risc_data]; /* * Equivalent to TDM interrupt if we are flushing the pipe or * find next SYNC. */ if ((pc == XPORT_OFFSET_STOP_STATE) || ((pc >= XPORT_FLUSH_PIPE) && (pc <= XPORT_FIND_SYNC2_END))) return(1); /* Equivalent to TDM interrupt */ } if (cnt >= 5) return(0); /* Data not in yet */ else if (cnt == 3) /* Last data is <submode:coding>*/ return(XPORT_fifo[2] & 0x2000); /* Eq. to TDM int. for M2F2 data*/ else return(1); /* Equivalent to TDM interrupt */#else /* For VCD 1.1/2.0 */ /* * If XPORT_fifo_length is not 0, then TDM interrupt has not happened * yet; in other words, this is the "2nd packet" interrupt. Ignore * the interrupt. Don't touch the FIFO data because if the interrupt * latency is long, the next currCDtime may be in! */ if (XPORT_fifo_length == 0) { XPORT_fifo_length = cnt; /* * Since nobody is writing to the RISC FIFO, reading it now * shall give reliable result! * * Make sure the number of data item makes sense. */ if ((max = XPORT_fifo_length) > XPORT_MAX_FIFO) max = XPORT_MAX_FIFO; /* Read the FIFO data into an array */ for (loop = 0; loop < max; loop++) XPORT_fifo[loop] = mvd[xport_read_risc_data]; /* If we have more data unexpectly, throw them away */ for (loop; loop < XPORT_fifo_length; loop++) reg0 = mvd[xport_read_risc_data]; } return(0);#endif /* else of DVD_VCD */}/**************************************************************************** Download transport ucode. ****************************************************************************/void XPORT_load_ucode(uCode_table, size)int *uCode_table; /* table address */int size; /* table size in ints, 0 for user input */ { int *uCode; int i; PRINTF(("Loading xport ucode.\n")); assert(size); uCode = uCode_table; if (size > 0x80) { FATAL(("Ucode too long. Download aborted.\n")); } mvd[xport_misc] = XPORT_LDMC | XPORT_RESET; for (i=0; i < size; i++) mvd[xport_microcode_table+i] = uCode[i]; for(; i < 0x80; i++) mvd[xport_microcode_table+i] = 0x3f07f00L; #ifdef DEBUG mvd[xport_misc] = XPORT_RESET; mvd[xport_misc] = XPORT_LDMC | XPORT_RESET; for (i=0; i < size; i++) { int tmp; tmp = mvd[xport_microcode_table+i]; tmp = mvd[xport_microcode_table+i] & 0x0fffffffL; if( tmp != (uCode[i] & 0x0fffffffL)){ FATAL(("Xport ucode verify error\n")); } }#endif mvd[xport_misc] = XPORT_RESET;}/**************************************************************************** Load xport PID. ****************************************************************************/static void load_xport_cam(PID_table, size)int *PID_table; /* table address */int size;{ int *pid_data; int i, data, tmp; PRINTF(("Load pid table \n")); assert(size); pid_data = PID_table;#ifdef DEBUG if (size > 0x20) { FATAL(("PID table too long. Download aborted.\n")); }#endif /*-write ucode-*/ mvd[xport_misc] = XPORT_FLUSHCAM| XPORT_RESET; mvd[xport_misc] = XPORT_RESET; mvd[xport_misc] = XPORT_LDPID | XPORT_RESET; /* Load all the CAM entries */ for (i = 0; i < 0x20; i++) { data = 0; if (i < size) data = pid_data[i]; mvd[xport_pid_table+i] = data; }#ifdef DEBUG /* Check to make sure loading is successful */ for (i = 0; i < 0x20; i++) { data = 0; if (i < size) data = pid_data[i]; tmp = mvd[xport_pid_table+i]; tmp = mvd[xport_pid_table+i]; if ((unsigned char) tmp != (unsigned char) data) break; }#endif mvd[xport_misc] = XPORT_RESET;}#if (MPEG1 && MKROM)/* * Routine to restore CAM table. There is report that CAM table * content may change in some situation. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -