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

📄 psi.c

📁 有线电视系统前端设备复用器原代码。 用语接受卫星信号
💻 C
📖 第 1 页 / 共 5 页
字号:
		MemCopy((unsigned char *)&g_gen_si_info.pat_section,(unsigned char *)&g_default_pat_section,sizeof(SI_SECTION_DATA));
		g_gen_si_info.pmt_section_number=0;
		g_gen_si_info.cat_section.section_length=0;
		g_gen_si_info.flag=1;

		New_SDT.SectionCount=0;
		Nit.TS_Count        =0;
		Eit.TS_Count        =0;

		return;
	}
	else
	{/*获得PSI信息*/
		MemCopy(buf,BD_FLASH_ADDR + 32*1024 + 4,PSILength);

		tmp=0;
		for(i=0;i<PSILength;i++)
			tmp+=*(unsigned char *)(buf + i);

		/*判断校验和是否一致*/
		if(tmp!=VerifyFlag)
			goto InvalidDataLabel;

		/*----------------------------------------------------*/
		/* load pat                                           */
		/*----------------------------------------------------*/
		Offset=4;
		Sections=*(unsigned short *)(buf + Offset);
		Offset+=sizeof(unsigned short);

		if(Sections!=1)
			goto InvalidDataLabel;

		for(i=0;i<Sections;i++)
		{/*填充PAT段*/
			SectionLength=*(unsigned short *)(buf + Offset);
			Offset+=sizeof(unsigned short);

			g_gen_si_info.pat_section.section_length=SectionLength;
			g_gen_si_info.pat_section.pid=0;
			g_gen_si_info.pat_section.continue_counter=0;			
			MemCopy(g_gen_si_info.pat_section.section,buf + Offset,SectionLength);

			Offset+=SectionLength;
		}

		/*----------------------------------------------------*/
		/* load cat                                           */
		/*----------------------------------------------------*/
		g_gen_si_info.cat_section.section_length=0;

		Sections=*(unsigned short *)(buf + Offset);
		Offset+=sizeof(unsigned short);

		if(Sections>0)
		{/*填充CAT段*/	
			if(Sections!=1)
				goto InvalidDataLabel;

			for(i=0;i<Sections;i++)
			{
				SectionLength=*(unsigned short *)(buf + Offset);
				Offset+=sizeof(unsigned short);

				g_gen_si_info.cat_section.section_length=SectionLength;
				g_gen_si_info.cat_section.pid=1;
				g_gen_si_info.cat_section.continue_counter=0;			
				MemCopy(g_gen_si_info.cat_section.section,buf + Offset,SectionLength);

				Offset+=SectionLength;
			}
		}

		MemCopy((unsigned char *)&g_gen_si_info.updated_cat_section,(unsigned char *)&g_gen_si_info.cat_section,sizeof(SI_SECTION_DATA));

		/*----------------------------------------------------*/
		/* load pmt                                           */
		/*----------------------------------------------------*/
		PMTs=*(unsigned short *)(buf + Offset);
		Offset+=sizeof(unsigned short);

		if(PMTs>=32)
			goto InvalidDataLabel;

		g_gen_si_info.pmt_section_number=PMTs;

		for(i=0;i<PMTs;i++)
		{/*填充PMT段*/
			Sections=*(unsigned short *)(buf + Offset);
			Offset+=sizeof(unsigned short);

			if(Sections!=1)
				goto InvalidDataLabel;

			for(j=0;j<Sections;j++)
			{
				SectionLength=*(unsigned short *)(buf + Offset);
				Offset+=sizeof(unsigned short);
	
				pid=*(unsigned short *)(buf + Offset);
				Offset+=sizeof(unsigned short);

				g_gen_si_info.pmt_sectoin_list[i].section_length=SectionLength;
				g_gen_si_info.pmt_sectoin_list[i].pid=pid;
				g_gen_si_info.pmt_sectoin_list[i].continue_counter=0;			
				MemCopy(g_gen_si_info.pmt_sectoin_list[i].section,buf + Offset,SectionLength);

				Offset+=SectionLength;
			}

			MemCopy((unsigned char *)&g_gen_si_info.updated_pmt_sectoin_list[i],(unsigned char *)&g_gen_si_info.pmt_sectoin_list[i],sizeof(SI_SECTION_DATA));
		}

		g_gen_si_info.flag=1;
		/*----------------------------------------------------*/
		/* load SDT                                           */
		/*----------------------------------------------------*/
		Sections=*(unsigned short *)(buf + Offset);
		Offset+=sizeof(unsigned short);

		if(Sections>16)
			goto InvalidDataLabel;

		New_SDT.SectionCount=Sections;

		for(i=0;i<Sections;i++)
		{/*填充SDT段*/
			SectionLength=*(unsigned short *)(buf + Offset);
			Offset+=sizeof(unsigned short);

			if(SectionLength>1100)
				goto InvalidDataLabel;

			New_SDT.SectionList[i].SectionLength=SectionLength;

			MemCopy(New_SDT.SectionList[i].Section,buf + Offset,SectionLength);
			Offset+=SectionLength;
		}

		/*----------------------------------------------------*/
		/*load NIT                                            */
		/*----------------------------------------------------*/
		Nit.TS_Count=*(unsigned short *)(buf + Offset);
		Offset+=sizeof(unsigned short);

		if(Nit.TS_Count>16)
			goto InvalidDataLabel;

		Nit.Transport_Stream_ID=*(unsigned long *)(buf + Offset);
		Offset +=sizeof(unsigned long);

		Nit.Network_ID=*(unsigned long *)(buf + Offset);
		Offset +=sizeof(unsigned long);

		for(i=0;i<Nit.TS_Count;i++)
		{/*填充NIT包*/
			SectionLength=*(unsigned short *)(buf + Offset);
			Offset+=sizeof(unsigned short);

			if(SectionLength!=188)
				goto InvalidDataLabel;

			MemCopy(Nit.NIT_TS[i],buf + Offset,SectionLength);
			Offset+=SectionLength;
		}

#if 0
		/*----------------------------------------------------*/
		/*Load EIT                                            */
		/*----------------------------------------------------*/
		Eit.TS_Count=*(unsigned short *)(buf + Offset);
		Offset+=sizeof(unsigned short);

		Eit.Present_Flowing_Flag=*(unsigned char *)(buf + Offset);
		Offset+=sizeof(unsigned char);

		Eit.Schedule_Flag       =*(unsigned char *)(buf + Offset);
		Offset+=sizeof(unsigned char);

		for(i=0;i<Eit.TS_Count;i++)
		{
			SectionLength=*(unsigned short *)(buf + Offset);
			Offset+=sizeof(unsigned short);

			MemCopy(Eit.EIT_TS[i],buf + Offset,SectionLength);
			Offset+=SectionLength;
		}
#endif

		/*----------------------------------------------------*/
		/* load PID remap table                               */
		/*----------------------------------------------------*/
		for(i=0;i<8;i++)
		{
			PID_Remap_Table_Item_Count[i]=*(unsigned short *)(buf + Offset);
			Offset+=sizeof(unsigned short);

			if(PID_Remap_Table_Item_Count[i]>256)
				goto InvalidDataLabel;

			for(j=0;j<PID_Remap_Table_Item_Count[i];j++)
			{
				pItem=(PID_REMAP_TABLE_ITEM *)(buf + Offset);

				PID_Remap_Table_List[i][j].OldPID=pItem->OldPID;
				PID_Remap_Table_List[i][j].NewPID=pItem->NewPID;
				PID_Remap_Table_List[i][j].Output=pItem->Output;

				Offset+=sizeof(PID_REMAP_TABLE_ITEM);
			}
		}

		MemFree(buf);
		return;

InvalidDataLabel:
		
		MemFree(buf);

		InitDefPATSection();		
		MemCopy((unsigned char *)&g_gen_si_info.pat_section,(unsigned char *)&g_default_pat_section,sizeof(SI_SECTION_DATA));
		g_gen_si_info.pmt_section_number=0;
		g_gen_si_info.cat_section.section_length=0;

		New_SDT.SectionCount=0;
		Nit.TS_Count        =0;
		Eit.TS_Count        =0;
	}
}

/*第一次写PID映射表到FPGA*/
unsigned long WriteReMapTableFirstTime(void)
{
	int volatile    i,j,k;
	unsigned char   volatile Msb;
	unsigned char   volatile MiddleByte;
	unsigned char   volatile Low4bits;
	unsigned char   volatile Found,Index;
	unsigned short  volatile PID9;
	unsigned short  volatile OldPID,NewPID;

	unsigned char   volatile Finished;

	PID_MAP_TABLE   Map;

	InitPIDRemap();

	for(i=0;i<8;i++)
	{
		Map.PIDs=0;
		Finished=0;

		for(j=0;j<PID_Remap_Table_Item_Count[i];j++)
		{
			
			OldPID=PID_Remap_Table_List[i][j].OldPID;
			NewPID=PID_Remap_Table_List[i][j].NewPID;

			if(PID_Remap_Table_List[i][j].Output)
			{
				PID9=OldPID&0x1FF0;				
				/*--------------------------------------------------*/
				/* 搜索该PID9在MAP TABLE中的位置                    */
				/*--------------------------------------------------*/
				Found=0;

				for(k=0;k<Map.PIDs;k++)
				{
					if(Map.PID9[k]==PID9)
					{
						Found=1;
						Index=k;
						break;
					}
				}
				if(!Found)
				{
					Index=Map.PIDs;

					/*--------------------------------------------------*/
					/* 如果生成的Index=0x0F,跳过不用                   */
					/*--------------------------------------------------*/
					if(Index==0x0F)
					{
						Map.PID9[Index++]=0x1FFF;
						Map.PIDs++;	
					}

					Map.PID9[Index]=PID9;
					Map.PIDs++;					
				}

				/*------------------------------------------------------*/
				/*级连口不超过64,其他口不超过32                        */
				/*------------------------------------------------------*/
				if(i==0)
				{
					if(Index==0x40)
						break;
				}
				else
				{
					if(Index==0x20)
						break;
				}

				/*--------------------------------------------------*/
				/* 如果是要复用的,需要将要复用的节目PID最高位置0   */
				/* 反之要置为1                                      */
				/*--------------------------------------------------*/
	
				NewPID=NewPID&0x7FFF;
		
				Msb        =(unsigned char)((OldPID&0x1FFF)>>12);
				MiddleByte =(unsigned char)((OldPID&0x0FF0)>>4);
				Low4bits   =(unsigned char)(OldPID&0x000F);

				*(unsigned char *)(HIGH_INDEX_ADDR_REG_H_BASE_ADDR + i*0x100)=Msb;
				*(unsigned char *)(HIGH_INDEX_ADDR_REG_L_BASE_ADDR + i*0x100)=MiddleByte;
				*(unsigned char *)(HIGH_INDEX_REG_BASE_ADDR + i*0x100)       =Index;
				*(unsigned char *)(PID_DATA_H_REG_BASE_ADDR + i*0x100)       =(unsigned char)((NewPID&0xFF00)>>8);
				*(unsigned char *)(PID_DATA_L_REG_BASE_ADDR + i*0x100)       =(unsigned char)(NewPID&0x00FF);
				*(unsigned char *)(LOW_INDEX_REG_BASE_ADDR  + i*0x100)       =Low4bits;
				
			}
			else
				continue;
		}
	}
	return 0;
}

/*-----------------------------------------------------------------*/
/*往FPGA中写PID对照表                                              */
/*-----------------------------------------------------------------*/
unsigned long WriteReMapTable(void)
{
	int volatile    i,j,k,l;
	unsigned char   volatile Msb;
	unsigned char   volatile MiddleByte;
	unsigned char   volatile Low4bits;
	unsigned char   volatile Found,Index;
	unsigned short  volatile PID9;
	unsigned short  volatile OldPID,NewPID;

	unsigned short  OldPrgNo;

	unsigned char   volatile Finished;

	PID_MAP_TABLE   Map;

	InitPIDRemap();

	for(i=0;i<8;i++)
	{
		Map.PIDs=0;
		Finished=0;

		PID_Remap_Table_Item_Count[i]=0;

		for(j=0;j<PID_Info[i].PIDs;j++)
		{
			OldPID=PID_Remap_Table_List[i][j].OldPID=PID_Info[i].PID_Map[j].OldPID;
			NewPID=PID_Remap_Table_List[i][j].NewPID=PID_Info[i].PID_Map[j].SetPID;
			PID_Remap_Table_Item_Count[i]++;

			OldPrgNo=PID_Info[i].PID_Map[j].OldPrgNo;
	              
			/*if(PIDSelected(i,NewPID))*/
			if(NewPID == 0x0C02)
				my_Delay(10);/*by xu*/
			if(PIDSelected(i,OldPID,NewPID,OldPrgNo))
			{
				PID_Remap_Table_List[i][j].Output=1;

				PID9=OldPID&0x1FF0;
				/*----------------------------------------------*/
				/* 搜索该PID9在MAP TABLE中的位置            */
				/*----------------------------------------------*/
				Found=0;

⌨️ 快捷键说明

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