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

📄 buffer.c

📁 用8051采用pwm方式播放 串口语音数据
💻 C
字号:
/********************************************************************************************\
name        : buffer.c
description : serial port flash and dac sharing common ram
author      :coolfire
data        :6/28/07
\********************************************************************************************/

/*includes*/
#include "buffer.h"
#include <stdio.h>

extern mode_t mode;

Uchar idata BUFFER[64]=
{
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};

int buflen=64;

/* global variant*/
Uchar idata *pFlash  =NULL;
Uchar idata *pSerial =NULL;
Uchar idata *pDac    =NULL;

Uint32 data serialcounter;
Uint32 data flashcounter;
Uint32 data daccounter;
Uint32 data gl_counter;
Uint32 data wav_len_w;
Uint32 data wav_len_r;

/* internal function*/
void flash_read_buf();
void flash_write_buf();
void serial_write_buf();
void dac_read_buf();

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*\


\*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void serial_write_buf()
{

	while(wav_len_w--)
	{
			if(serialcounter==flashcounter+1)
				if(pSerial==pFlash)
					return;/*             */

			serial_receive(pSerial++);


			if(serialcounter==0)
				if(pSerial==BUFFER+8)
					{
						wav_len_w=(Uint32)*(pSerial-4);
						gl_counter=wav_len_w;
					}

			if(pSerial==BUFFER+buflen)
				{
					serialcounter++;
					pSerial=BUFFER;
				}

	}/*end while*/

}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*\
data : 6/30/07
\*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void dac_read_buf()
{
    while(1)
    {
		if(pDac==pFlash)
			if(daccounter==flashcounter)
				{
					if(wav_len_w==4294967295)
						mode=idle;
					return;/*                   */
				}
		dac_read(pDac++);
		if(pDac==BUFFER+buflen)
		{
			daccounter++;
			pDac=BUFFER;
		}
	}/*end while*/
}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*\

\*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void flash_read_buf()
{
	while(wav_len_w--)
	{
		if(pFlash==pSerial)
			if(flashcounter==serialcounter)
				{
					if(wav_len_w==4294967295)
						mode=idle;
					return;/*                   */
				}

		flash_read(pFlash++);
		if(pFlash==BUFFER+buflen)
		{
			flashcounter++;
			pFlash=BUFFER;
		}

	}/*end while*/

}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*\
data 6/30/07
\*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void flash_write_buf()
{
	while(wav_len_r--)
	{
			if(flashcounter==daccounter+1)
				if(pDac==pFlash)
					return;/*           */

			flash_write(pFlash++);

			if(flashcounter==0)
				{
					if(pFlash==BUFFER+8)
						{
							wav_len_r=(Uint32)*(pFlash-4);
							gl_counter=wav_len_r;
						}
			   }

			if(pFlash==BUFFER+buflen)
				{
					flashcounter++;
					pFlash=BUFFER;
				}
	}/*end while*/
}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*\

\*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void read_buffer(type_t type)
{
	switch(type)
	{
		case flash:
			flash_read_buf();
			break;
		case dac:
			dac_read_buf();
			break;
	}
}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*\

\*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void write_buffer(type_t type)
{
	switch(type)
	{
		case serial:
			serial_write_buf();
			break;
		case flash:
		   flash_write_buf();
			break;
	}
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*\

\*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void init_buffer()
{
  //init pointer 
  pSerial =BUFFER;
  pFlash  =BUFFER;
  pDac    =BUFFER;
  
  //init counter
  serialcounter =0;
  flashcounter  =0;
  daccounter    =0;
  gl_counter    =0;
  wav_len_w       =9;
  wav_len_r       =9;
}

⌨️ 快捷键说明

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