📄 st_pti.c
字号:
/*------------------------------------------------------------------------------
*
* File name : pti.c
*
* Description : PTI Commands
*
* COPYRIGHT (C) STMicroelectronics 2005.
*
*
* WARNING : Pti_SlotKeepInfo array is not protected by semaphore !
* It would be a good idea to do it, to be able to access it from
* different tasks. For trickmode as example.
---------------------------------------------------------------------------- */
/* Includes ----------------------------------------------------------------- */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <partitio.h>
#include "stddefs.h"
#include "stlite.h"
#include "stdevice.h"
#include "st_pti.h"
#include "stclkrv.h"
#include "stevt.h"
#include "stsys.h"
#include "sttbx.h"
#include "stttx.h"
#ifdef TESTTOOL
#include "api.h"
#include "testtool.h"
#endif
#include "app_data.h"
#include "stpti.h"
#include "clk.h"
#include "evt.h"
#include "aud.h"
#include "vid.h"
#include "tsmerge.h"
#include "service.h"
#include "stpti_hal.h"
/* STPTI handle table */
STPTI_Handle_t PtiPSHdnl[PTI_MAXDEVICE][PTI_MAXOPEN]; /* Handle for PTI */
PTI_ProcessStream_t PtiProcessStream[PTI_MAXOPEN]=
{
/* StreamType */
/* Vid.devid Vid.CF Vid.UseCF Vid.bufsize Aud.CF Aud.UseCF Aud.bufsize */
/* Use carousel */
/* Use hdd */
/* PTI_PS_TSI : TSI acquisition (PAT, PMT...) */
{PTI_STREAMTYPE_AV,
{{VID_MAXDEVICE, 0, FALSE, 0}, {0, FALSE, 0}},
{0},
{0}
},
/* PTI_PS_AV1 : Video decoder # 1 and Audio decoder #1 */
{PTI_STREAMTYPE_AV,
{{VID_1_MPEG, VIDEO_CD_FIFO1, FALSE, 32*1024}, {AUDIO_CD_FIFO, TRUE, 32*1024}},
{0},
{0}
},
/* PTI_PS_PES : For PES */
{PTI_STREAMTYPE_AV,
{{VID_MAXDEVICE, 0, FALSE, 32*1024}, {0, FALSE, 32*1024}},
{0},
{0}
}
};
/* Parameter for STPTI */
PTI_DeviceHandle_t PtiDeviceHandle[PTI_MAXDEVICE]=
{
{"PTI_0", /* DeviceName */
PtiPSHdnl[PTI_0], /* Handle_p */
PtiProcessStream, /* ProcessStream_p */
STPTI_DEVICE_PTI_4, /* DeviceType */
PTI_BASE_ADDRESS, /* TCDeviceAddress */
PTI_INTERRUPT, /* TCDeviceInterrupt */
STPTI_FILTER_OPERATING_MODE_32x8, /* Filter Mode */
EVT_BACK, /* EVT DeviceId */
PTI_SERVICE_DVB, /* Service */
STPTI_STREAM_ID_TSIN0 /* StreamId */
},
{"PTI_1", /* DeviceName */
PtiPSHdnl[PTI_1], /* Handle_p */
PtiProcessStream, /* ProcessStream_p */
STPTI_DEVICE_PTI_4, /* DeviceType */
PTI_BASE_ADDRESS, /* TCDeviceAddress */
PTI_INTERRUPT, /* TCDeviceInterrupt */
#if 1 // EXT_SHARE
STPTI_FILTER_OPERATING_MODE_48x8,
#else
STPTI_FILTER_OPERATING_MODE_32x8, /* Filter Mode */
#endif
EVT_BACK, /* EVT DeviceId */
PTI_SERVICE_DVB, /* Service */
#ifndef TSIN1_NORMAL
STPTI_STREAM_ID_TSIN0 /* StreamId */
#else
STPTI_STREAM_ID_TSIN1 /* StreamId */
#endif
},
{"PTI_2", /* DeviceName */
PtiPSHdnl[PTI_2], /* Handle_p */
PtiProcessStream, /* ProcessStream_p */
STPTI_DEVICE_PTI_4, /* DeviceType */
PTI_BASE_ADDRESS, /* TCDeviceAddress */
PTI_INTERRUPT, /* TCDeviceInterrupt */
STPTI_FILTER_OPERATING_MODE_32x8, /* Filter Mode */
EVT_BACK, /* EVT DeviceId */
PTI_SERVICE_DVB, /* Service */
STPTI_STREAM_ID_SWTS0 /* StreamId */
},
{"PTI_3", /* DeviceName */
PtiPSHdnl[PTI_3], /* Handle_p */
PtiProcessStream, /* ProcessStream_p */
STPTI_DEVICE_PTI_4, /* DeviceType */
PTI_BASE_ADDRESS, /* TCDeviceAddress */
PTI_INTERRUPT, /* TCDeviceInterrupt */
STPTI_FILTER_OPERATING_MODE_32x8, /* Filter Mode */
EVT_BACK, /* EVT DeviceId */
PTI_SERVICE_DVB, /* Service */
STPTI_STREAM_ID_TSIN2 /* StreamId */
}
};
/*
** This array is common to both service builds
** and the array is selected in transport.c
*/
STPTI_SlotType_t STPTI_SlotTypes_DVB[NUM_PTI_SLOTS] = {
STPTI_SLOT_TYPE_PES, /* Video */
STPTI_SLOT_TYPE_PES, /* Audio */
STPTI_SLOT_TYPE_PCR, /* PCR */
STPTI_SLOT_TYPE_PES, /* TTX */
STPTI_SLOT_TYPE_PES, /* Subt */
STPTI_SLOT_TYPE_SECTION,/* DSMCC */
STPTI_SLOT_TYPE_NULL,
STPTI_SLOT_TYPE_NULL,
STPTI_SLOT_TYPE_NULL,
STPTI_SLOT_TYPE_NULL,
STPTI_SLOT_TYPE_NULL
};
/* Private Constants -------------------------------------------------------- */
#define PTI_VIDEO_BUFFER_SIZE (64*1024) /* 64 KBytes */
#define PTI_AUDIO_BUFFER_SIZE (32*1024) /* 32 KBytes */
#if (TTPTI_MULTI_INSTANCE == TRUE)
#define INS_DEVICEID "<DeviceId>"
#define INS_DEVICEHANDLEID "<DeviceId><HandleId>"
#else
#define INS_DEVICEID
#define INS_DEVICEHANDLEID
#endif /* (TTPTI_MULTI_INSTANCE == TRUE) */
/* Private Variables -------------------------------------------------------- */
/* Global structure to store PTI information used to retrieve informatin as : */
/* - SlotHandle for statistic */
/* - SlotHandle for unallocate it at stop */
/* - ... */
Pti_SlotKeepInfo_t Pti_SlotKeepInfo[PTI_MAXDEVICE][PTI_MAXOPEN][PTI_SLOT_TYPE_MAXID];
STPTI_Buffer_t PTI_AudioBufferHandle_Multiple[PTI_MAXDEVICE],PTI_VideoBufferHandle_Multiple[PTI_MAXDEVICE];
STPTI_Buffer_t TTX_BufferHandle; /* teletext support */
STPTI_Signal_t TTX_SignalHandle;
/* Semaphore to ensure correct multi thread */
static BOOL pti_SemInit = FALSE;
static semaphore_t pti_SemLock;
/* Private Macros ----------------------------------------------------------- */
/* Private Function prototypes ---------------------------------------------- */
/* Externals ---------------------------------------------------------------- */
ST_ErrorCode_t SERVICE_PTI_InitParams(SERVICE_Mode_t SERVICE_Mode,
STPTI_InitParams_t *STPTI_InitParams,
STPTI_SlotType_t **STPTI_SlotTypes);
/* PTI is not critical for CPU and system performance so Protect function */
/* are not macros because it has no Init, so we must manage it internaly. */
/*-----------------------------------------------------------------------------
* Function : PTI_Protect
* Protect by semaphore shared data
* Do the initialisation if needed.
* Input : N/A
* Output : N/A
* Return : ErrCode
* -------------------------------------------------------------------------- */
static ST_ErrorCode_t PTI_Protect(void)
{
/* First check if init of the semaphore is already done */
if (pti_SemInit == FALSE)
{
/* Init the semaphore to 1 and wait on the semaphore is the same as */
/* setting directly the semaphore to 0. */
semaphore_init_fifo(&pti_SemLock,0);
/* We are now in critical section */
pti_SemInit = TRUE;
}
else
{
semaphore_wait(&pti_SemLock);
}
return ST_NO_ERROR;
} /* PTI_Proctect */
/*------------------------------------------------------------------------------
* Function : PTI_UnProtect
* Protect by semaphore shared data
* Input : N/A
* Output : N/A
* Return : ErrCode
* -------------------------------------------------------------------------- */
static ST_ErrorCode_t PTI_UnProtect(void)
{
/* Wake up locked task on semaphore (if any) */
semaphore_signal(&pti_SemLock);
return ST_NO_ERROR;
} /* PTI_UnProctect */
ST_ErrorCode_t PTI_EnableErrorEvents(PTI_DeviceId_t DeviceId)
{
ST_ErrorCode_t ST_ErrorCode = ST_NO_ERROR;
ST_ErrorCode = STPTI_EnableErrorEvent(PTI_GET_DEVICENAME(DeviceId), STPTI_EVENT_SECTIONS_DISCARDED_ON_CRC_CHECK_EVT);
if (ST_ErrorCode != ST_NO_ERROR)
return( ST_ErrorCode );
ST_ErrorCode = STPTI_EnableErrorEvent(PTI_GET_DEVICENAME(DeviceId), STPTI_EVENT_TC_CODE_FAULT_EVT);
if (ST_ErrorCode != ST_NO_ERROR)
return( ST_ErrorCode );
ST_ErrorCode = STPTI_EnableErrorEvent(PTI_GET_DEVICENAME(DeviceId), STPTI_EVENT_INVALID_PARAMETER_EVT);
if (ST_ErrorCode != ST_NO_ERROR)
return( ST_ErrorCode );
ST_ErrorCode = STPTI_EnableErrorEvent(PTI_GET_DEVICENAME(DeviceId), STPTI_EVENT_BUFFER_OVERFLOW_EVT);
if (ST_ErrorCode != ST_NO_ERROR)
return( ST_ErrorCode );
ST_ErrorCode = STPTI_EnableErrorEvent(PTI_GET_DEVICENAME(DeviceId), STPTI_EVENT_CC_ERROR_EVT);
if (ST_ErrorCode != ST_NO_ERROR)
return( ST_ErrorCode );
ST_ErrorCode = STPTI_EnableErrorEvent(PTI_GET_DEVICENAME(DeviceId), STPTI_EVENT_INTERRUPT_FAIL_EVT);
if (ST_ErrorCode != ST_NO_ERROR)
return( ST_ErrorCode );
ST_ErrorCode = STPTI_EnableErrorEvent(PTI_GET_DEVICENAME(DeviceId), STPTI_EVENT_INVALID_LINK_EVT);
if (ST_ErrorCode != ST_NO_ERROR)
return( ST_ErrorCode );
ST_ErrorCode = STPTI_EnableErrorEvent(PTI_GET_DEVICENAME(DeviceId), STPTI_EVENT_PACKET_ERROR_EVT);
if (ST_ErrorCode != ST_NO_ERROR)
return( ST_ErrorCode );
STTBX_Report((STTBX_REPORT_LEVEL_INFO,"PTI Events Enabled:%s\n",
GetErrorText(ST_ErrorCode)));
return( ST_NO_ERROR );
}
/* TESTTOOL Functions ------------------------------------------------------- */
#ifdef TESTTOOL
#if (TTPTI_MULTI_INSTANCE == TRUE)
/*------------------------------------------------------------------------------
* Name : PtiGetParamDeviceId
* Description : Get device id (from 0 to PTI_MAXOPEN)
* Parameters : *pars_p, *DeviceId_p
* Assumptions :
* Limitations :
* Returns : TRUE if error, FALSE if success
* -------------------------------------------------------------------------- */
BOOL PtiGetParamDeviceId (parse_t *pars_p, PTI_DeviceId_t *DeviceId_p)
{
BOOL RetErr=FALSE;
RetErr = STTST_GetInteger(pars_p, 0, (S32 *)DeviceId_p);
if ( (RetErr) || (*DeviceId_p >= PTI_MAXOPEN) )
{
STTBX_Print(("Invalid DeviceId %d (0 to %d only)",*DeviceId_p, PTI_MAXOPEN));
RetErr = TRUE;
}
return (RetErr);
} /* PtiGetParamDeviceId() */
/*------------------------------------------------------------------------------
* Name : PtiGetParamHandleId
* Description : Get handle id (from 0 to PTI_MAXOPEN)
* Parameters : *pars_p, *HandleId_p
* Assumptions :
* Limitations :
* Returns : TRUE if error, FALSE if success
* --------------------------------------------------------------------------- */
BOOL PtiGetParamHandleId (parse_t *pars_p, PTI_HandleId_t *HandleId_p)
{
BOOL RetErr=FALSE;
RetErr = STTST_GetInteger(pars_p, 0, (S32 *)HandleId_p);
if ( (RetErr) || (*HandleId_p >= PTI_MAXOPEN) )
{
STTBX_Print(("Invalid HandleId %d (0 to %d only)",*HandleId_p, PTI_MAXOPEN));
RetErr = TRUE;
}
return (RetErr);
} /* PtiGetParamHandleId() */
#endif /* (TTPTI_MULTI_INSTANCE == TRUE) */
/*------------------------------------------------------------------------------
* Name : TTPTI_Init
* Description : Initialize a pti
* Parameters : *pars_p, *result_sym_p
* Assumptions :
* Limitations :
* Returns : TRUE if error, FALSE if success
* -------------------------------------------------------------------------- */
static BOOL TTPTI_Init(parse_t *pars_p, char *result_sym_p)
{
BOOL RetErr;
ST_ErrorCode_t ErrCode;
PTI_DeviceId_t DeviceId;
SERVICE_Mode_t SERVICE_Mode;
S32 Lvar;
DeviceId = 0;
RetErr = FALSE;
ErrCode = ST_NO_ERROR;
#if (TTPTI_MULTI_INSTANCE == TRUE)
/* get DeviceId */
RetErr = PtiGetParamDeviceId(pars_p, &DeviceId);
if (RetErr == TRUE)
{
STTST_TagCurrentLine(pars_p, "expected Device Id");
}
#endif
/* get the service mode */
if (RetErr == FALSE)
{
RetErr = STTST_GetInteger(pars_p, SERVICE_MODE_DVB, &Lvar);
if (RetErr == TRUE)
{
STTST_TagCurrentLine(pars_p, "expected service mode: SERVICE_MODE_DVB | SERVICE_MODE_DTV");
}
SERVICE_Mode = (SERVICE_Mode_t)Lvar;
}
/* call pti function */
if (RetErr == FALSE)
{
ErrCode = PTI_Init(DeviceId, SERVICE_Mode);
if ( ErrCode != ST_NO_ERROR)
{
RetErr = TRUE;
}
}
if (RetErr == TRUE)
{
API_ErrorCount++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -