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

📄 dvb_sys.c

📁 DVB软件,基于CT216软件的开发源程序.
💻 C
📖 第 1 页 / 共 3 页
字号:
/**************************************************************************

		(C)Copyright Cheertek Inc. 2002-2004,
		   D700, all right reserved.

		Product : STB Firmware

****************************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "ct_config.h"
#include "ct_type.h"
#include "ct_os.h"
#include "av_cfg.h"
#include "ct_tve.h"
#include "ct_audio.h"
#include "ct_video.h"
#include "ct_uart.h"
#include "ct_uart1.h"

#ifdef CT216E
#include "ct_uart2.h"
#endif //#ifdef CT216E

#include "ct_irq.h"
#include "ct_sys.h"
#include "ct_gpio.h"
#ifdef CT216E
#include "ct_ucode.h"
#endif //#ifdef CT216E
#include "ct_filter.h"
#include "io_config.h"

#include "dev_io.h" //Marlin 20060616
#include "ct_iic.h"
#include "dev_ir.h"
#include "ct_osd.h"
#ifndef CT956
#include "ct_adc.h"
#endif

/* includes the following header files for get version */
#if defined(CT216S) || defined(CT216T) || defined (CT216H)

#ifdef CARDREADER_ENABLE
	#include "ct_cardreader.h"
#endif

	#ifdef CI_ENABLE
	#include "ct_ci.h"
	#endif
	#include "ct_decsa.h"
	#include "ct_fd.h"
	#include "ct_flash.h"
	#include "ct_fp.h"
	#ifdef HDMI_ENABLE
	#include "ct_hdmi.h"
	#endif
#ifdef	IMAGE_ENABLE
	#include "ct_image.h"
#endif
	#include "ct_ir_kd.h"
#ifdef	MOVIE_ENABLE
	#include "ct_movie.h"
#endif
	#include "ct_nim.h"
	#include "ct_pwm.h"
	#include "ct_smc.h"
	#include "ct_ttx_vbi.h"
#ifdef USB_ENABLE	
	#include "ct_usb.h"
#endif


	#include "ct_vcxo.h"
	#include "dvb_file.h"
#endif //CT216S or CT216T

#include "dvb_sys.h"
#include "dvb_msg.h"
#include "dvb_fp.h"
#include "dvb_av.h"
#include "dvb_avio.h"
#include "dvb_osd.h"
#include "dvb_flash.h"
#include "dvb_nim.h"
#include "dvb_mem.h"
#include "dvb_si.h"
#include "dvb_ttx.h"
#include "dvb_usb.h"

#ifdef ENABLE_POWER_SAVING
#include "db_api.h"
#endif //ENABLE_POWER_SAVING
#ifdef  CONAX
	#include "ct_decsa.h"
	#include "cx_service.h"
	#include "ui_ca.h"
#endif //CONAX

#ifdef TONGFANG
	#include "tongfangca.h"
#endif //TONGFANG

#ifdef TUI
	#include "ct_decsa.h"
#endif //TUI


#include "dvb_sibk.h"

#ifdef ATA_ENABLE
	#include "dvb_ata.h"
#endif //ATA_ENABLE
#ifdef PVR_ENABLE
	#include "dvb_pvr.h"
#endif //PVR_ENABLE

#ifdef D_UI
	#include "ct_smc.h"
	#include "dvb_smc.h"
#endif //D_UI
#include "ap_defs.h"
#include "task_cfg.h"
/*******************************************************************************************/
#if 0
#define SYS_MSG(p)
#else
#define SYS_MSG(p)			printf p
#endif

#if 1
#define SYS_DBG(p)
#else
#define SYS_DBG(p) 		printf p
#endif

/*******************************************************************************************/          




#define TIMER2_USED

// following variables must be in critical section.

static u32 u32SystemTime = 0; //unit is second.

static s32 s32SleepTime = 0;  //Unit is second.
//================================================

static bool8 b8SystemStandby = FALSE;
static u32 u32Holdrand = 0;
static EN_SYS_COUNTRY_TYPE enDvbSystemCountry;
static bool8 b8TDTGetFlag = FALSE;
static bool8 b8TOTGetFlag = FALSE;
static char * _pcImageHeader = NULL;
static bool8 b8GMTUsage = TRUE;
static ST_SystemInitParameters* pstSystemParameters = NULL;
static CTOS_TIMER stSysTime;
#ifdef ENABLE_LCN_SUPPORT
static bool8 b8LCNEnable = FALSE;
#endif
static u8 au8SysStack[DVB_SYS_TASK_STACK_SIZE];
static CTOS_TASK Sys_Task;
static CTOS_SEMAPHORE stTimerSemaphore;

u8 signal_point;
static u8 au8AP_CH_SWStack[DVB_CH_SWITCH_TASK_STACK_SIZE];
static CTOS_TASK AP_CH_SW_task_ctl;
static CTOS_SEMAPHORE semAP_SW_CH;

static void (*pfAP_CH_SW_CallBack)(void); /* call back func */

extern void switch_channel_taskf( void );

//Summer Time Function
//>>bug 009 by xbjiang
//void DVB_SummerTimeSet( struct _tm * pstTM );
void DVB_SummerTimeSet( struct _tm * pstTM ,bool8 OnOff);
//<<bug 009 by xbjiang
//Startup Get GMT time flag
static bool8 Startup_flag = FALSE;
static bool8 _b8AP_CH_SW_Suspend = FALSE;
static bool8 b8StopChannelSwitch = FALSE;

static bool8 b8SystemInit_Zero = FALSE;

EN_DRV_RESULT CT_UART2_Initial(void);
//void CT_NIM_Config(EN_CT_DEMUX_DP enDpSel);

#ifdef CT_OS_TASK_INFO
CTOS_TIMER  StackMonitorTimer;
static bool8 b8StackMonitorCreate = FALSE;
extern void CT_OS_TaskUsage(u32 argc);
#endif

extern void Init_PopupMessage( void );

#if 0
void Test_MicroSecond_Delay (void);
#endif
/*********************************************************************************************/
void ap_ch_sw_register( void (* ap_ch_sw_cb)( void ) ) 
{ 
	pfAP_CH_SW_CallBack = ap_ch_sw_cb;
}
/*********************************************************************************************/

void ap_ch_sw_task_signal( void ) 
{
	CT_OS_FreeSemaphore(& semAP_SW_CH);
//SYS_MSG (">>>signal_point[%d]\n", signal_point);
//	DVB_TimerBlockingWait(100);
}

void ap_ch_switch_stop(void)
{
    b8StopChannelSwitch = TRUE;

	while (b8StopChannelSwitch == TRUE)
    {
	    CT_OS_Delay (2);	
	}	
}

/*********************************************************************************************/

void ap_ch_sw_task( u32 argc, void * argv )
{
	EN_CTOS_STATUS enStatus;

	char semaphore_name[CTOS_MAX_NAME];
	u32 current_count;
	EN_CTOS_SUSPEND_TYPE suspend_type;
	u32 tasks_suspended;
	CTOS_TASK *first_task;

	enStatus = CT_OS_CreateSemaphore(& semAP_SW_CH, "ch_sw", 0, EN_CTOS_SUSPEND_FIFO);

	if (enStatus == EN_CTOS_SUCCESS)
	{
		SYS_DBG(( "ch_sw task Created\n"));
	}
	else
	{
		SYS_MSG(( "ch_sw task Create Fail %d\n", enStatus));
	}

	while (1)
	{
        // process stop command
        if(b8StopChannelSwitch==TRUE)
        {
        	DVB_AVDemuxDisable();
        	DVB_VideoSetPID (0);
        	DVB_AudioSetPID (0);
            CT_OS_ResetSemaphore(& semAP_SW_CH, 0);

            b8StopChannelSwitch = FALSE;
        }
        
        // process channel switching command
		if (CT_OS_WaitOnSemaphore(& semAP_SW_CH, 10) == EN_CTOS_SUCCESS)
		{
			enStatus = CT_OS_Semaphore_Information(& semAP_SW_CH, semaphore_name,
											  & current_count,
											  & suspend_type,
											  & tasks_suspended,
											  & first_task);

			if (enStatus == EN_CTOS_SUCCESS)
			{
				//SYS_MSG(("++++++++++ current_count[%d]\n", current_count));
				if (current_count>2)
				{
					if (CT_OS_ResetSemaphore(& semAP_SW_CH, 0) != EN_CTOS_SUCCESS)
					{
						SYS_MSG((" RRRRRRRRR reset fail\n"));
					}
				}
			}

			if (pfAP_CH_SW_CallBack)
			{
				//SYS_DBG(("$$$$$$$$$$$$$$$$$$ call call back\n"));
				pfAP_CH_SW_CallBack();
			}
			
		}
	}
}
/*********************************************************************************************/

#define MAX_MEM_INFO    100

typedef struct ST_MEM_RECORD
{
	u32* pu32Pointer;
	u32 u32Size;
} ST_MEM_RECORD;

static ST_MEM_RECORD stMemRecord[MAX_MEM_INFO];
/*********************************************************************************************/

u32 _ms2tick( u32 u32ms )
{
	u32ms = u32ms / CTOS_MS_PER_TICKS;

	if (u32ms == 0)
	{
		u32ms = 1;
	}
	return u32ms;
}
/*********************************************************************************************/

u32 _ms2tick2( u32 u32ms )
{

#ifdef TIMER2_USED

	return u32ms;

#else

	return (_ms2tick(u32ms));

#endif

}
/*********************************************************************************************/

static void _dvb_SystemTimerRun( u32 u32ID )
{
	u32 u32CurrentTime;

	static u32 u32Tick4SystemTime = 0;
	static u32 u32KeepLastTick = 0;

#ifdef TIMER2_USED

	const u32 u32TickOneSec = 1000;

#else

	const u32 u32TickOneSec = 1000 / CTOS_MS_PER_TICKS;

#endif                     /* end #ifdef TIMER2_USED */

	u32 u32SystemTimeTemp; // for multi task protection
	s32 s32SleepTimeTemp;  // for multi task protection


	u32CurrentTime = DVB_TimerGet();
	// increase system time in second.
	u32Tick4SystemTime += DVB_TimerMinus(u32CurrentTime, u32KeepLastTick);

	//reset u32KeepLastTick
	u32KeepLastTick = u32CurrentTime;

	if (u32Tick4SystemTime>=u32TickOneSec)
	{
		// count system time
		u32SystemTimeTemp = u32SystemTime;

		u32SystemTimeTemp += (u32Tick4SystemTime / u32TickOneSec);
		u32SystemTime = u32SystemTimeTemp;
		//		SYS_DBG(("Tick=%ld, System time=%ld, Sleep=%ld\n", u32CurrentTime, u32SystemTime, s32SleepTime));

		if (s32SleepTime>0)
		{
			// count sleep time
			s32SleepTimeTemp = s32SleepTime;

			s32SleepTimeTemp -= (u32Tick4SystemTime / u32TickOneSec);
			s32SleepTime = s32SleepTimeTemp;

			if (s32SleepTime<=0)
			{
				//        	    SYS_DBG(("Go to Sleep......\n"));
				//        	    DVB_SendKey(0);
				DVB_SendKey(KEY_POWER);
			}
		}

		u32Tick4SystemTime %= u32TickOneSec;
	}
}
/*********************************************************************************************/

void DVB_SystemInit_Parameters( ST_SystemInitParameters * pstParameters ) 
{ 
	pstSystemParameters = pstParameters;
}

//*********************************************************************
/********************************************************************/

/*****************************************************************/

u32 DVB_TimerGet( void )
{
	u32 u32Ticks = 0;

#ifdef TIMER2_USED
    extern CT_STATUS CT_SYS_GetTimerTickInMS(u32 *u32Tick);
	if (CT_SYS_GetTimerTickInMS(& u32Ticks) == EN_CTOS_SUCCESS)
	{
		return u32Ticks;
	}

	return 0;

#else

	CT_OS_GetClock(& u32Ticks);
	return u32Ticks;

#endif

}
/*******************************************************************************************/          

u32 DVB_TimerPlus( u32 u32Timer, u16 u16MillSec )
{
	u32Timer += _ms2tick2(u16MillSec);

	return u32Timer;
}
/*******************************************************************************************/          

u32 DVB_TimerMinus( u32 u32TimerNew, u32 u32TimerOld )
{
	u32 u32Tick;

	if (u32TimerNew>=u32TimerOld)
	{
		u32Tick = u32TimerNew - u32TimerOld;

		return u32Tick;
	}

	if ((u32TimerNew & 0xC0000000) == 0 && (u32TimerOld & 0xC0000000) != 0)
	{
		u32Tick = 0xFFFFFFFF - u32TimerOld;

		u32Tick += u32TimerNew;
		return u32Tick;
	}

	return 0; // the time2 is new, the timer1 is old
}
/*******************************************************************************************/          

bool8 DVB_TimerAfter( u32 u32Timer1, u32 u32Timer2 )
{
	if (u32Timer1>u32Timer2)
	{
		return TRUE;
	}
	if ((u32Timer1 & 0xC0000000) == 0 && (u32Timer2 & 0xC0000000) != 0)
	{
		return TRUE;
	}
	return FALSE;
}
/*******************************************************************************************/          

bool8 DVB_TimerWait( ST_DVB_TimerWait * pstTimerWait, u16 u16MillSec )
{

#if 0

	pstTimerWait->u32Tick = _ms2tick(u16MillSec);

	pstTimerWait->u32Current_time = DVB_TimerGet();
	pstTimerWait->u32Timeout_time = DVB_TimerPlus(pstTimerWait->u32Current_time, u16MillSec);

	while (TRUE)
	{
		if (DVB_DetectKey())
			return FALSE;

		pstTimerWait->u32Current_time = DVB_TimerGet();

		if (DVB_TimerAfter(pstTimerWait->u32Current_time, pstTimerWait->u32Timeout_time) == TRUE)
		{
			break;
		}

		CT_OS_Delay(1);
	}

	return TRUE;

#else

	return DVB_DetectKeyTimeout(u16MillSec);
	//	if ( DVB_DetectKey() ) return FALSE;
	//	return TRUE;

#endif

}
/*******************************************************************************************/          

bool8 DVB_TimerPollWait( u16 u16MillSec )
{
	u32 u32Timeout_time, u32Current_time;

	u32Current_time = DVB_TimerGet();
	u32Timeout_time = DVB_TimerPlus(u32Current_time, u16MillSec);

	while (TRUE)
	{
		if (DVB_DetectKey())
		{
			return FALSE;
		}
		u32Current_time = DVB_TimerGet();

		if (DVB_TimerAfter(u32Current_time, u32Timeout_time) == TRUE)
		{
			break;
		}

#ifdef TIMER2_USED

		if (DVB_TimerMinus(u32Timeout_time, u32Current_time)>20) //20 tick = 20ms
		{
			CT_OS_Delay(1);                                      //1 tick for OS delay = 10 ms
		}

#else

		CT_OS_Delay(1);

#endif

	}

	return TRUE;
}
/*******************************************************************************************/          

void DVB_TimerBlockingWait( u16 u16MillSec )
{
	u32 u32Timeout_time, u32Current_time;

	u32Current_time = DVB_TimerGet();
	u32Timeout_time = DVB_TimerPlus(u32Current_time, u16MillSec);

	while (TRUE)
	{

#ifdef TIMER2_USED

		u32Current_time = DVB_TimerGet();

		if (DVB_TimerAfter(u32Current_time, u32Timeout_time) == TRUE)
		{
			break;
		}

		if (DVB_TimerMinus(u32Timeout_time, u32Current_time)>20) //20 tick = 20ms
		{
			CT_OS_Delay(1);                                      //1 tick for OS delay = 10 ms
		}

#else

		CT_OS_Delay(_ms2tick(u16MillSec));

#endif

	}
}
/*******************************************************************************************/          

/********************************************************************/
/********************************************************************/
/********************************************************************/
/********************************************************************/
void DVB_SystemInit_Zero( void )
{
	u16 u16Temp1 = 0;
	ST_FLASH_INFO_T stFlashInf;

	b8SystemInit_Zero = TRUE;

	for (u16Temp1 = 0; u16Temp1<MAX_MEM_INFO; u16Temp1++)
	{
		stMemRecord[u16Temp1].pu32Pointer = NULL;
	}

	CT_SYS_Initial();

#ifdef CODE_SEGMENT_START_BANK
	CT_SYS_SetImageAddress(CODE_SEGMENT_START_BANK*0x10000); //application image address in flash.
#else
	CT_SYS_SetImageAddress(0x10000); //application image address in flash.
#endif

	CT_UART_Initial();

	CT_UART_Enable_Interrupts(TRUE);

⌨️ 快捷键说明

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