xref: /utopia/UTPA2-700.0.x/modules/hsl/api/hsl/frhsl_cfg.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 /***************************************************************************
79  *
80  * Copyright ?2008-2010 MStar Semiconductor, Inc. All Rights Reserved
81  *
82  **************************************************************************/
83 /** \file
84  * \brief This is the header file to configure the FrHsl module.
85  * This file contains default definitions of platform-specific macros to
86  * customise the HSL hardware, interface and logging routines.  All macros
87  * defined here can be overridden/'overloaded' in a platform-specific header file.
88  */
89 #if defined (MSOS_TYPE_LINUX)
90 #ifndef FRHSLCFG_H
91 #define FRHSLCFG_H
92 
93 
94 #include "MsTypes.h"
95 #include <unistd.h>
96 #include <pthread.h>
97 
98 #include <dlfcn.h>
99 
100 
101 #ifdef  __cplusplus
102 extern "C" {
103 #endif
104 
105 /*******************************************************************************
106 ** Constants
107 *******************************************************************************/
108 
109 #define ENABLE_ALL_GROUP_IDS            1
110 #define DISABLE_ALL_GROUP_IDS           0
111 
112 /*******************************************************************************
113 ** Macros
114 *******************************************************************************/
115 
116 /** Macro that can be redefined to allow code to be added at the
117  *  start of the HSL flow control interrupt.
118  *  Macro that can be redefined to allow code to be added at the
119  *  start of the HSL flow control interrupt.
120  */
121 #if !defined (M_FrHslFlowControlIntBegin)
122 # define M_FrHslFlowControlIntBegin()
123 #endif
124 
125 /** Macro that can be redefined to allow code to be added at the
126  *  end of the HSL flow control interrupt.
127  *  Macro that can be redefined to allow code to be added at the
128  *  end of the HSL flow control interrupt.
129  */
130 #if !defined (M_FrHslFlowControlIntEnd)
131 # define M_FrHslFlowControlIntEnd()
132 #endif
133 
134 
135 /*******************************************************************************
136 * Alternative macros
137 *******************************************************************************/
138 
139 
140 /** \def FR_HSL_V2_UNITIALISED_LOG_ID
141  *  Log point id assigned when using MDF to capture a new log point.
142  *  Log point id assigned when using MDF to capture a new log point.
143  *  This value should be used when adding a log point with a new MDF
144  *  compatible log point id but using HSL version 2 macros.
145  *  e.g. M_FrHslPrintf1(FR_HSL_V2_UNITIALISED_LOG_ID, NEW_MDF_COMPAT_ID,"NewMdfCompaqId: %#.4x", arg1);
146  *  NEW_MDF_COMPAT_ID is the new log point added for MDF to be able to decode it.
147  */
148 #define FR_HSL_V2_UNITIALISED_LOG_ID ((MS_U16)0x0000)
149 
150 /** \def FR_HSL_V2_UNPROCESSED_LOG_ID
151  *  Log point id assigned when an HSL version 2 statement has not been processed by silox.exe.
152  *  Log point id assigned when an HSL version 2 statement has not been processed by silox.exe.
153  *  This ID is used as part of stub functions which will print a default HSL log message when
154  *  new HSL log points have been added but have not been processed by silox.exe.
155  */
156 #define FR_HSL_V2_UNPROCESSED_LOG_ID ((MS_U16)0x0002)
157 
158 
159 // large part of the data are bookmarks (8 * BUFFER_SEGMENTS_COUNT)
160 #define SYS_STATE_BUFSIZE (1024)
161 
162 #define TX_BUFFER_SIZE (5*1024)
163 #define MAX_OUTPUT_THREADS 1
164 // MS_U8 used to store the next bm number - max count 255
165 #define BUFFER_SEGMENTS_COUNT 10
166 #define BUFFER_DUMP_SEGMENTS 3
167 #define BUFFER_FREE_SPACE_PERCENTAGE 15
168 #define PENDING_WRITE_LIST_LEN 255
169 #define ASSERT_RT_CLOCK_FAIL_TW 1000
170 
171 /*******************************************************************************
172 ** Global Data
173 *******************************************************************************/
174 typedef struct ST_HSL_CONTROLLER* p_HslController;
175 
176 typedef struct ST_LIST_NODE
177 {
178     MS_U32 u32bufferIndex;
179     MS_U32 u32timestamp;
180     struct ST_LIST_NODE *prev;
181     struct ST_LIST_NODE *next;
182 } stListNode;
183 
184 typedef struct
185 {
186     MS_U32 address;
187     MS_U32 timerWrapDelta;
188 } stRBbookmark;
189 
190 // this structure need to save in ring buffer
191 // after crashing, it can be used to output the remaining message
192 // make sure the size of this structure MUST less than SYS_STATE_BUFSIZE
193 typedef struct ST_RB_SYSTEM_STATE
194 {
195     MS_U32 ssize;               // size of system state reserved RAM area
196     MS_U32 sbufStart;           // system state RAM start address
197     MS_U32 sbufEnd;             // system state RAM address end
198 
199     MS_U32  bufSize;            // size of ringbuffer
200     MS_U32  bufStart;           // ring buffer start address
201     MS_U32  bufEnd;             // ring buffer end address
202 
203     // runtime constants
204     MS_U32  bufMinFreeBytes;     // defines a threshold for triggering data dumping
205     MS_U32  bufSegmentSize;
206 
207     // access to the following is protected by the bufferMutex
208     MS_U32  bufUsedEnd;         // end of the currently used buffer space (adjusted
209     MS_U32  bufWritePos;        // current write position in ring buffer
210     MS_U32  bufReadPos;         // position of output pointer
211     MS_U32  bufReadLimit;       // last byte of valid fully written data update after write finishes
212     MS_U32  bufFlags;
213     MS_U32  hslLastTwTime;      // timestamp of the last timerwrap
214 
215     // controlled by outputCondMutex
216     MS_U32  bufBytesToSend;     // amount of data to be transfered from the ring buffer
217     stRBbookmark bufBookmarks[BUFFER_SEGMENTS_COUNT];
218     MS_U8    dumpFlag;            // marks a necessity to insert a log point informing about a data dump into the output stream.
219     MS_U8   syncMarker;         // countdown for writing sync marker
220     MS_U8   nextBookmark;
221     MS_U8    flushOnConnect;        // indicates whether the complete buffer contents should be flushed on connection
222     MS_U8    dynamicAlloc;        // indicates the type of allocation and a necessity to release memory on exit. (0 static/1 dynamic)
223 } stSystemState;
224 
225 // manages the data associated with a specific thread instance.
226 typedef void * (*start_routine)(void *);
227 
228 typedef enum
229 {
230     read_thread=0,
231     write_thread,
232     output_thread,
233     prMS_S32_thread
234 }THREADTYPE;
235 
236 typedef struct
237 {
238     MS_S32          streamId;
239     pthread_t       threadId;
240     MS_S32          priority;
241     THREADTYPE  typeId;
242     start_routine   funcPtr;
243     void*               funcParam; // ptr to array of bytes to log.
244 } hslThread;
245 
246 
247 typedef struct ST_HSL_CONTROLLER
248 {
249     // system state pointer
250     stSystemState* pSystemState;                // location of structure for system state
251     MS_U32 u32Port;  // port on which connections will be accepted
252     MS_U8 u8Instance;
253     MS_BOOL bInit;
254 
255     // Global variables
256     //TODO!: Initialize output threads
257     hslThread logThreads[MAX_OUTPUT_THREADS];
258 /*    =
259     {
260             {0, 0, 0, output_thread, bufferWriteThread, NULL}
261     }; */
262 
263     stListNode pendingWriteList[PENDING_WRITE_LIST_LEN];
264     stListNode *pendingWriteHead; //TODO: initialize pointers with zeros
265     MS_U16 pendingWriteLength;
266 
267     volatile MS_BOOL thread_finalize;
268 
269     pthread_mutex_t  bufferMutex;            // mutex for accessing the ring buffer
270     pthread_mutex_t  inputMutex;             // mutex synchronising the input threads
271     pthread_mutex_t  outputCondMutex;        // mutex for I/O sync
272     pthread_cond_t   outputCond;             // ring buffer output sync condition
273 
274     pthread_mutex_t pendingWriteMutex;       // mutex for the pending write linked list;
275 
276     pthread_t threadCmdRecvStart;
277     pthread_mutex_t socketReadMutex;   // mutex variable for socket read
278 
279     MS_BOOL g_AutoTestRun;
280     int hServerSocket, hClientSocket;
281 
282 } stHslController;
283 
284 /*******************************************************************************
285 ** Global Function Prototypes
286 *******************************************************************************/
287 
288 void FrHslResetConnection(stHslController* const _hsl);
289 MS_BOOL FrHslInitialiseBegin(void);
290 MS_BOOL FrHslInitialiseEnd(void);
291 MS_BOOL FrHslStop(void);
292 void FrHslWritePayload (const MS_BOOL bLast, const MS_U16 u16Payload, MS_U8 *pu8Buff);
293 void FrHslWriteHeader(const MS_U8 u8MsgType, const MS_U16 u16ID, MS_U8 *pu8Buff, MS_U32 u32Time);
294 MS_BOOL FrHslCommand(p_HslController _hsl, CmdInfo* const pCmd);
295 
296 #define HSL_MAX_LIBRARY_COUNT 50
297 #define HSL_MAX_THREAD_COUNT 200
298 #define HSL_MAX_THREAD_NAME 17
299 #define HSL_MAX_LIBRARY_NAME 100
300 
301 typedef struct LibraryShortInfoTag
302 {
303     MS_U16 rec_no;
304     MS_U16 rec_total;
305     void*  base_address;
306     void*  on_load_addr;
307     char   name[HSL_MAX_LIBRARY_NAME];
308 } ST_LIBRARY_SHORT_INFO;
309 extern ST_LIBRARY_SHORT_INFO gDynamicLibraryInfo[HSL_MAX_LIBRARY_COUNT];
310 extern MS_U16 gDynamicLibraryCount;
311 
312 typedef struct ThreadInfoTag
313 {
314     MS_U32  thread_ID;
315     char   thread_name[HSL_MAX_THREAD_NAME];
316 } ST_THREAD_INFO;
317 extern ST_THREAD_INFO gThreadInfo[HSL_MAX_THREAD_COUNT];
318 extern MS_U16 gThreadCount;
319 
320 #define MAX_SELFTEST_THREAD_CNT 20
321 extern pthread_t gTestThreads[MAX_SELFTEST_THREAD_CNT];
322 extern MS_BOOL gRunLoadTest;
323 void *HslSelfTestThreadFun(void* pArg);
324 
325 #ifdef  __cplusplus
326 }
327 #endif
328 
329 #endif
330 /* END OF FILE */
331 #endif
332