mid_common.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*! \addtogroup dvb_common DVB Middleware Common
  2. * @{
  3. */
  4. /******************************************************************************/
  5. /**
  6. *
  7. * @file mid_common.h
  8. *
  9. * @brief This file specifies the APIs provided to control middleware
  10. *
  11. * @note Copyright (c) 2009 Sunplus Technology Co., Ltd. \n
  12. * All rights reserved.
  13. *
  14. * @author
  15. *
  16. ******************************************************************************/
  17. #ifndef _MID_COMMON_H_2008_05_12_
  18. #define _MID_COMMON_H_2008_05_12_
  19. /*******************************************************************************
  20. * Header include
  21. ******************************************************************************/
  22. #include <types.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include "gl_mempool.h"
  26. #include "customize.h"
  27. /*******************************************************************************
  28. * Define
  29. ******************************************************************************/
  30. //#define MID_DVB_VERSION (0x1005010A) //the date of major relase
  31. //#define FLASH_SIZE (DVB_FLASH_SIZE)
  32. //#define HEADER_ITEM_OFFSET(type, field) ((long)&(((type *)0)->field)) /**< get offset of item in a data structure */
  33. typedef enum
  34. {
  35. DEMUX_UNIT0 = 0, /*!< */
  36. #ifdef SUPPORT_DUAL_NIM
  37. DEMUX_UNIT1, /*!< */
  38. #endif
  39. DEMUX_TOTAL_UNITS /*!< */
  40. } DemuxUnit_t;
  41. #undef PRIMARY_LIVE_INPUT
  42. #ifndef PRIMARY_LIVE_INPUT
  43. #define PRIMARY_LIVE_INPUT DEMUX_UNIT0
  44. #endif
  45. #ifdef SUPPORT_DUAL_NIM
  46. #undef SECOND_LIVE_INPUT
  47. #ifndef SECOND_LIVE_INPUT
  48. #define SECOND_LIVE_INPUT DEMUX_UNIT1
  49. #endif
  50. #endif
  51. typedef enum
  52. {
  53. /* common status values */
  54. MID_SUCCESS, /*!< successful outcome */
  55. MID_ERR_FAILURE, /*!< operation failed */
  56. MID_ERR_INVALID_HANDLE, /*!< invalid handle */
  57. MID_ERR_INVALID_ID, /*!< invalid identifier */
  58. MID_ERR_INVALID_PARAM, /*!< invalid parameter */
  59. MID_ERR_INVALID_OP, /*!< requested operation is invalid */
  60. MID_ERR_MEMORY_ALLOC, /*!< problem allocating memory */
  61. MID_ERR_MEMORY_SIZE, /*!< problem with the size of memory */
  62. /* < supplied */
  63. MID_ERR_RESOURCE_UNAVAILABLE,
  64. MID_ERR_TIMEOUT, /*!< timeout */
  65. MID_WARN_NO_ACTION, /* < the function completed successfully,*/
  66. /* < but no action was taken */
  67. MID_WARN_PARAM_CLIPPED, /*!< the function has completed */
  68. /*!< successfully, though a parameter was */
  69. /*!< clipped to within a valid range. */
  70. MID_WARN_BUFFER_EMPTY,
  71. MID_WARN_BUFFER_FULL,
  72. MID_WARN_UNINITED, /*!< has not been initialized yet */
  73. MID_WARN_INITED, /*!< has been initialized already */
  74. MID_ERR_MODE_MISMATCH, /*!< deinterlacer off*/
  75. MID_ERR_MAX /*!< Max error number*/
  76. } MID_Status_t;
  77. #define CRC32 GL_CRC32
  78. #ifndef INVALID_PID
  79. #define INVALID_PID 0x1fff
  80. #endif
  81. /*******************************************************************************
  82. * Enumerator
  83. ******************************************************************************/
  84. /*******************************************************************************
  85. * Structure
  86. ******************************************************************************/
  87. /*----------------------STRUCTURE DEFINES----------------------*/
  88. typedef UINT32 LIVE_INPUT_UNIT;
  89. /**
  90. * \brief rtc_head
  91. */
  92. typedef struct __attribute__ ((packed)) {
  93. unsigned short year;
  94. unsigned char mon;
  95. unsigned char date;
  96. unsigned char hour;
  97. unsigned char min;
  98. unsigned char sec;
  99. }rtc_head;
  100. /**
  101. * \brief _mid_common_bits_util_t
  102. */
  103. typedef struct _mid_common_bits_util_t
  104. {
  105. UINT8 *pStart; /*!< \brief data start address */
  106. UINT8 *pEnd; /*!< \brief data end address */
  107. UINT8 *pCur; /*!< \brief data current address */
  108. int nLeftBits; /*!< \brief left bits count of last byte */
  109. UINT8 *pData; /*!< \brief data address */
  110. UINT32 nSize; /*!< \brief data size */
  111. UINT16 rBytes; /*!< \brief current read position of bytes of the data */
  112. UINT8 rBits; /*!< \brief current read position of bits in the last byte */
  113. }MID_CmnBitsUtil_t, *LP_MID_CmnBitsUtil_t;
  114. //JennyLee 20100624 added for mantis 86055 [start]
  115. #ifdef SUPPORT_TRD
  116. #define MAX_TRDNAME_LEN 64 //because this is a 6-bit field in the spec.
  117. #define MAX_SRV_TRD 4 //TODO: actually we are not sure what is the maximum ?
  118. #define TRD_COUNTRY_MATCHED (1<<0)
  119. #define TRD_HAS_PRIMARY (1<<1)
  120. #define TRD_HAS_SECONDARY (1<<2)
  121. #define TRD_HAS_TERTIARY (1<<3)
  122. #define MAX_REGION_LEVEL 4
  123. /*target region signalling*/
  124. typedef struct dvbpsi_target_region_dr_s
  125. {
  126. UINT8 u8RegionDepth;
  127. char u8CountryCode[3];
  128. UINT16 RegionLevel[MAX_REGION_LEVEL+1]; //o not used
  129. struct dvbpsi_target_region_dr_s *next;
  130. } dvbpsi_target_region_dr_t;
  131. typedef struct dvbpsi_target_region_name_dr_s
  132. {
  133. UINT8 u8RegionDepth;
  134. char u8CountryCode[3];
  135. UINT8 u8IsoLangCode[3];
  136. UINT16 RegionLevel[MAX_REGION_LEVEL+1]; //o not used
  137. unsigned char ucName[MAX_TRDNAME_LEN];
  138. struct dvbpsi_target_region_name_dr_s *next;
  139. } dvbpsi_target_region_name_dr_t;
  140. typedef struct trd_in_db_s
  141. {
  142. UINT8 u8DepthStatus; // 0 means not found the TRD
  143. UINT8 u8PrimaryCode;
  144. UINT8 u8SecondayCode;
  145. UINT16 u16TertiaryCode;
  146. } trd_in_db_t;
  147. #endif
  148. //JennyLee 20100624 added for mantis 86055 [end]
  149. /*******************************************************************************
  150. * Macro
  151. ******************************************************************************/
  152. //-------mem alloc utility start ------------------------------------------------------//
  153. #define HAL_DCACHE_LINE_SIZE 32
  154. #define ZERO_MALLOC_FUNC(func_malloc, x) \
  155. ({ \
  156. UINT32 x_align = (x + (HAL_DCACHE_LINE_SIZE-1)) & (~(HAL_DCACHE_LINE_SIZE-1)); \
  157. UINT8 *ret = (UINT8 *)func_malloc(x_align); \
  158. if(ret) memset(ret, 0, x_align); \
  159. ret; \
  160. })
  161. #define SAFR_FREE_FUNC(func_free, p) {if(p){ func_free(p); p = NULL;}}
  162. // malloc cached DRAM-A or DRAM-B when A not enough
  163. #define zero_malloc(x) ZERO_MALLOC_FUNC(GL_MemAlloc, x)
  164. // free
  165. #define SAFE_FREE(p) SAFR_FREE_FUNC(GL_MemFree, p)
  166. // malloc uncache DRAM-A
  167. #define zero_malloc_UncachedA(x) ZERO_MALLOC_FUNC(GL_MemAllocUncachedA, x)
  168. // malloc uncache DRAM-B
  169. #define zero_malloc_UncachedB(x) ZERO_MALLOC_FUNC(GL_MemAllocUncachedB, x)
  170. // free
  171. #define SAFE_FREE_UCACHED(p) SAFR_FREE_FUNC(GL_MemFreeUncached, p)
  172. // malloc cache DRAM-A
  173. //UINT8 *zero_malloc_UncachedA(UINT32 x);
  174. #define zero_malloc_CachedA(x) ZERO_MALLOC_FUNC(GL_MemAllocAlignedA, x)
  175. // malloc uncache DRAM-B
  176. #define zero_malloc_CachedB(x) ZERO_MALLOC_FUNC(GL_MemAllocAlignedB, x)
  177. // free
  178. #define SAFE_FREE_CACHED(p) SAFR_FREE_FUNC(GL_MemFreeAligned, p)
  179. //-------mem alloc utility end ------------------------------------------------------//
  180. /*******************************************************************************
  181. * Program
  182. ******************************************************************************/
  183. void MID_CmnTransStrWithSpeciChar(UINT8 *pu8Src, UINT32 u32Len); //Mika_100629: mantis 92541
  184. void MID_CmnTransStrWithoutControlChar(UINT8 *pu8Src, UINT32 u32Len); //Mika_100707: mantis 94427
  185. int MID_CmnGetDynamicStrLength(UINT8 *pbSrc, UINT32 dLen); //Mika_100629: modify string length incorrect possibly
  186. /******************************************************************************/
  187. /**
  188. * \fn void MID_CmnTransStrWith00(UINT8 *pu8Src, UINT32 u32Len)
  189. *
  190. * \brief trans char 0x00 to 0x20(for DTG SI/PSI ).\n
  191. *
  192. * \param *pu8Src: pointer of a char str.\n
  193. *
  194. * \param u32Len: data length.\n
  195. * \return \e void
  196. *
  197. * \note none
  198. *
  199. ******************************************************************************/
  200. //-------trans char 0x00 to 0x20(for DTG SI/PSI )--------------------------------------//
  201. void MID_CmnTransStrWith00(UINT8 *pu8Src, UINT32 u32Len);
  202. /******************************************************************************/
  203. /**
  204. * \fn void MID_CmnTransStrWith00(UINT8 *pu8Src, UINT32 u32Len)
  205. *
  206. * \brief skip 0xFF, and less than 0x20 chars (for DTG SI/PSI ).\n
  207. *
  208. * \param *pu8Src: pointer of a char str.\n
  209. *
  210. * \param u32Len: data length.\n
  211. *
  212. * \return \e void
  213. *
  214. * \note none
  215. *
  216. ******************************************************************************/
  217. void MID_CmnTransStrWithoutSpeciChar(UINT8 *pu8Src, UINT32 u32Len);
  218. /******************************************************************************/
  219. /**
  220. * \fn void MID_CmnTransStrWithoutNewline(UINT8 *pu8Src, UINT32 u32Len)
  221. *
  222. * \brief skip 0x8A (for DTG SI/PSI ).\n
  223. *
  224. * \param *pu8Src: pointer of a char str.\n
  225. *
  226. * \param u32Len: data length.\n
  227. *
  228. * \return \e void
  229. *
  230. * \note none
  231. *
  232. ******************************************************************************/
  233. void MID_CmnTransStrWithoutNewline(UINT8 *pu8Src, UINT32 u32Len);
  234. /******************************************************************************/
  235. /**
  236. * \fn void MID_CmnTransStrWithEllipsis(UINT8 *pu8Src, UINT32 *pu32Len, UINT32 u32MaxLen)
  237. *
  238. * \brief TransStrWithEllipsis.\n
  239. *
  240. * \param *pu8Src: pointer of a char str.\n
  241. *
  242. * \param *pu32Len: data length.\n
  243. *
  244. * \param u32MaxLen: Max data length.\n
  245. *
  246. * \return \e void
  247. *
  248. * \note 100401 Fasky added for mantis 83029 start only when querying.\n
  249. *
  250. ******************************************************************************/
  251. void MID_CmnTransStrWithEllipsis(UINT8 *pu8Src, UINT32 *pu32Len, UINT32 u32MaxLen);
  252. /******************************************************************************/
  253. /**
  254. * \fn int MID_CmnDecompressString(UINT8 *pu8Src, UINT32 u32Len)
  255. *
  256. * \brief to decompress the compressed text. \n
  257. *
  258. * \param *pu8Src: pointer of a char str.\n
  259. *
  260. * \param u32Len: data length.\n
  261. *
  262. * \return \e number of charactor
  263. *
  264. * \note for DTG T2 SI/PSI specification \n
  265. *
  266. ******************************************************************************/
  267. int MID_CmnDecompressString(UINT8 *pu8Src, UINT32 u32Len); //glenn@20100610
  268. /******************************************************************************/
  269. /**
  270. * \fn void MID_CmnBitsInit(MID_CmnBitsUtil_t *pBits, UINT8 *pData, int nSize)
  271. *
  272. * \brief to complete the struct of MID_CmnBitsUtil_t.\n
  273. *
  274. * \param *pBits: pointer of input MID_CmnBitsUtil_t struct\n
  275. *
  276. * \param *pData: point of data add.\n
  277. *
  278. * \param nSize: buffer size.\n
  279. *
  280. * \return \e void
  281. *
  282. * \note none
  283. *
  284. ******************************************************************************/
  285. void MID_CmnSetDemuxUnit(LIVE_INPUT_UNIT TunerId);
  286. LIVE_INPUT_UNIT MID_CmnGetDemuxUnit( void);
  287. #endif // _MID_COMMON_H_2008_05_12_