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

📄 util.c

📁 一个不错的硬盘播放器程序,包含VFD显示程序,红外线遥控程序,硬盘读写程序,及解码程序等.
💻 C
📖 第 1 页 / 共 2 页
字号:
int  	*srcp;	/* source ptr in SRAM */
int  	n;	/* block size in dwords */
{
    int dx, dy, m;

#if 1
    buscon_wait(r2b);
#else
    buscon_wait_timeout(r2b, 300000);
#endif
    dy = n>>8; m = dy<<8; dx = n - m;
    if (dy) {
    	buscon_xfer(r2b, BDMA_USEDX, dst, 256, dy);
	dst += m;
        risc_fifo_write(srcp, m);
	srcp += m;
#if 1
    	buscon_wait(r2b);
#else
    	buscon_wait_timeout(r2b, 300000);
#endif
    }
    if (dx) {
    	buscon_xfer(r2b, 0, dst, dx, 1);
    	risc_fifo_write(srcp, dx);
#if 1
    	buscon_wait(r2b);
#else
    	buscon_wait_timeout(r2b, 300000);
#endif
    }
}

/*****************************************************************************
 DRAM clear via the VP.
 *****************************************************************************/
void    dram_clear(int dst, int n)
{
    VP_ucode(NCMDQ_VP_ucode, clearalldp);
    VP_ucode_wait();
    while (n>0) {
        int m = (n>128) ? 128 : n;
        VP_xfer(NCMDQ_VP_xfer, VPCMD_R_DP, 0, 0, dst, m, 1);
        dst += m;
        n -= m;
    }
    VP_xfer_wait();
}

#if 0
#ifndef PLAYONLY
/*------------------------------------------------------------------------
  Parameters:
      *dst	dst pointer in SRAM
      src	dword addr in DRAM
      size	block size in dwords

  Description:
------------------------------------------------------------------------*/
void	dram_to_sram(int *dst_ptr, int src, int size)
{
    int i, *src_ptr = (int *) dram(src);

    while (size--) {
	*dst_ptr++ = *src_ptr++;
    	for (i = 0; i < 32; i++)
	    asm("nop");
    }
}
#endif
#endif

/*****************************************************************************
 Sleep for a while. Try to match the specified cycles.
 I don't really know if the wrap around really works or not.
 *****************************************************************************/
void	risc_sleep_a_bit(int n)
{
    int elapsed;
    int start_time = mvd[riface_timer2];

    if (n <= 20) return;

    while (1) {
	elapsed = mvd[riface_timer2] - start_time;
	if (elapsed<0) {
	    elapsed += -timer2_period;	/* timer2_period is negative */
	}
	if (elapsed > n-20) break;
    }
}

/*------------------------------------------------------------------------
  Description:
      This function is called on every video vertical sync and to increase
      the glbTimer variable. If the output mode is PAL, we will add two
      to the glbTimer. Thus, we only have one the glbTimer which is 1/60
      second if the output mode is NTSC, or roughly 1/60 if the output
      mode is PAL.
------------------------------------------------------------------------*/
void update_glbTimer()
{
    static five_field_count;

    glbTimer++;
    five_field_count++;

    if ((vcx_scn_height == 288) && (five_field_count >= 5)) {
	/* adjust the PAL field time to NTSC field time */
	glbTimer++;
	five_field_count = 0;
    }
}


#ifdef SPATIAL
/*
 * Loader filter coefficients according to user specified spatializer level.
 *
 * Inputs:
 *	level:	Spatializer level
 *
 * Return:
 *	OSD string
 */
#if (CUST3 || P315)
#define assign_ptr(a, b)
#else
#define assign_ptr(a, b) { a = b; }
#endif
char * SPA_set_level(level)
int level;
{
    unsigned int * filter;
    int i, offset = 0;
    char * ptr;

    assign_ptr(ptr, MSG_audfx_off);

    if (level == SPA_SURROUND) {		/* 1 */
	assign_ptr(ptr, MSG_surround_on);
    } else if (level == SPA_3D) {		/* 2 */
	assign_ptr(ptr, MSG_3d);
	offset = BP_size;
    } else if (level == SPA_HALL) {		/* 3 */
	assign_ptr(ptr, MSG_hall);
	offset = BP_size * 2;
    } else if (level == SPA_VOCAL_CUT) {	/* 4 */
	assign_ptr(ptr, MSG_voice_can);
	offset = BP_size * 3;
    }

    filter = bp_ham + offset;
    for (i = 0; i < BP_size; i++) {
	*(int *) dram(BP_filter+i) = filter[i];
    }

    SPA_level = level;
    return(ptr);
}
#endif /* SPATIAL */


#ifdef ECHO
/************************************************************************
 * Following code is echo related. Since echo.c is protected, I'll	*
 * leave this code here so we can have compilation options and customers*
 * can make changes.							*
 ************************************************************************/
#ifdef DSC_SW_DETECT_CENTER
static int mic_level_ok(mic_dc_level)
int mic_dc_level;
{
    int i;
    int mic_mean = 0;
    int *ptr = (int *)dram(MIC_start + ECHO_AF); /* skip 1st 48 DWs */

    for (i = 0; i < (ECHO_AF * 2); i++) {
	int t = (int)(*ptr++);
	int t0 = t>>16;
	int t1 = (t<<16)>>16;
	mic_mean += t0 + t1;
	asm("nop");
	asm("nop");
    }
    mic_mean /= (ECHO_AF * 2 * 2);

    if ((mic_mean > mic_dc_level) || (mic_mean < -(mic_dc_level)))
	return 0;
    else 
	return 1;
}
#endif /* DSC_SW_DETECT_CENTER */

/*
 * This is a new algorithm of turning on MIC. We'll not hog CPU
 * until MIC is turned on. In contrast, we'll just start taking in
 * the data then release CPU. When 3 * 48B are collected, we'll
 * stop taking in the data in the interrupt service routine. Then
 * we'll compute the average here. If the average is good, then we
 * consider the MIC is turned on successfully; otherwise, we'll
 * go the whole thing again.
 *
 * For older 3207's, since reference voltage may not be stable for
 * few seconds, we'll be conservative and wait for 8 seconds before
 * starting taking in the data.
 */
void MIC_turn_on()
{
    PRIVATE int mic_dc_level = 0x80;

    if (IS_POWER_DOWN)
      return;

#ifndef DSC_SW_DETECT_CENTER
    /* Newest 3207 doesn't need the average stuff any more */
    DSC_mic_off();
    DSC_mic_on();
    MIC_init();
    MIC_is_turned_on = 1;
#else

    /* 
     * Don't do the evaluation for 8 seconds (hopefully the reference
     * voltage can be stabilized by then.
     */
    if (glbTimer < EIGHT_SECOND)
      return;

    if (MIC_got_sample == 1) {
	/* 
	 * According to interrupt service routine, we got enough data
	 * (i.e. enough for evaluation.)
	 */

	/*
	 * We'll loop 256 times in small increment. After which, we'll
	 * jump geomatrically.
	 */
	if (mic_dc_level > 0x1080) {
	    goto gotit;	/* Prevent very long loop! */
	} else if (mic_dc_level == 0x880) {
	    mic_dc_level = 0x1000;
	    mic_sensitivity = 7;
	} else if (mic_dc_level == 0x480) {
	    mic_dc_level = 0x800;
	    mic_sensitivity = 6;
	} else if (mic_dc_level == 0x280) {
	    mic_dc_level = 0x400;
	    mic_sensitivity = 5;
	} else if (mic_dc_level == 0x180) {
	    mic_dc_level = 0x200;
	    mic_sensitivity = 4;
	} else if (mic_dc_level == 0x100) {
	    mic_sensitivity = 3;
	}

	if (mic_level_ok(mic_dc_level)) {
	  gotit:
	    MIC_is_turned_on = 1;
	    if (vcx_echo >= 0) {
		/* 
		 * In case ECHO is already on, we need to initialize
		 * MIC stuff, then start take in.
		 */
		MIC_init();
		MIC_start_take_in();
	    } else {
		/* To be consistent with before */
		MIC_stop_take_in();
	    }
	    return;
	}
	mic_dc_level++;
    }

    if (MIC_got_sample != 2) {
	/* Not getting sample, then start collecting data. */
	DSC_mic_off();
	DSC_mic_on();
	MIC_init();
	MIC_start_take_in();
	MIC_got_sample = 2;
    }
#endif /* else of DSC_SW_DETECT_CENTER */
}



#endif /* ECHO */

⌨️ 快捷键说明

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