| 1 | /** |
|---|
| 2 | @file |
|---|
| 3 | DHL_SYS_Platform.c |
|---|
| 4 | |
|---|
| 5 | @brief |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | ÀÌ ¸ðµâ¿¡ ´ëÇÑ °£´ÜÇÑ ¼³¸í.. |
|---|
| 9 | ex: AudioVideo decoding/capture/output implementation |
|---|
| 10 | |
|---|
| 11 | Copyright 2006~2010 Digital STREAM Technology, Inc. |
|---|
| 12 | All Rights Reserved |
|---|
| 13 | */ |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | #include "DHL_OSAL.h" |
|---|
| 17 | #include "DHL_DBG.h" |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | //#include <stdio.h> |
|---|
| 22 | ////#include <string.h> // for memcpy |
|---|
| 23 | |
|---|
| 24 | /* |
|---|
| 25 | ¸ðµç Çì´õ ÆÄÀÏÀ» Æ÷ÇÔÇÏÁö´Â ¾ÊÀ¸¸ç, compile timeÀ» ÁÙÀ̱â À§ÇØ |
|---|
| 26 | °¢ ¸ðµâÀº ÇÊ¿äÇÑ ¸¸ÅÀÇ Çì´õ¸¦ ¼±¾ðÇϵµ·Ï ÇÔ. |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | /* |
|---|
| 32 | DHL µð¹ö±× ¸ðµâ À̸§ Á¤ÀÇ ·ê Âü°í: |
|---|
| 33 | |
|---|
| 34 | DHL ¸ðµâµéÀº ¸ðµÎ * ·Î ½ÃÀÛ. |
|---|
| 35 | API´Â ´ë¹®ÀÚ, Platform ¹× ±âŸ´Â ¼Ò¹®ÀÚ »ç¿ë. |
|---|
| 36 | |
|---|
| 37 | µðÆúÆ® ·¹º§Àº 0À¸·Î ¼³Á¤ÇÑ´Ù. (0: ¿¡·¯ ¸Þ½ÃÁö¸¸ Ãâ·Â) |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | */ |
|---|
| 41 | |
|---|
| 42 | //DHL_MODULE("*MMM", 0); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | #if COMMENT |
|---|
| 47 | ____Config____(){} |
|---|
| 48 | #endif |
|---|
| 49 | |
|---|
| 50 | /* |
|---|
| 51 | ÀÌ ¸ðµâ ³»ºÎ¿¡¼ »ç¿ëµÇ´Â °¢Á¾ configuration Á¤ÀÇ. |
|---|
| 52 | */ |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | /* #define SUPPORT_FAST_SWITCHING_OPTIMIZATION 1 */ |
|---|
| 56 | /* #define FUNC_MONITOR_TIMER_ID TIMER_ID_FUNC_MONITOR */ |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | #if COMMENT |
|---|
| 61 | ____Types____(){} |
|---|
| 62 | #endif |
|---|
| 63 | |
|---|
| 64 | /* |
|---|
| 65 | ÀÌ ¸ðµâ ³»ºÎ¿¡¼ »ç¿ëµÇ´Â structure ¹× enumerations. |
|---|
| 66 | */ |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | #if COMMENT |
|---|
| 71 | ____Variables____(){} |
|---|
| 72 | #endif |
|---|
| 73 | |
|---|
| 74 | /* |
|---|
| 75 | global·Î Àû¿ëµÇ´Â variable Á¤ÀÇ. |
|---|
| 76 | °¢ function º°·Î Ư¼öÇÑ ¿ëµµÀÇ variableÀº °¢ functionX block ¿¡¼ Á¤ÀÇ °¡´É. |
|---|
| 77 | */ |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | #if COMMENT |
|---|
| 85 | _____DbgPrint_____(){} |
|---|
| 86 | #endif |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | #define DHL_DBG_USE_MUTEX 1 |
|---|
| 90 | // OS_LockTask °ú °°Àº »óÅ¿¡¼µµ debug print¸¦ ÇÏ·Á°í ÇÑ´Ù¸é |
|---|
| 91 | // mutex¸¦ »ç¿ëÇÏÁö ¾Ê¾Æ¾ß ÇÑ´Ù. |
|---|
| 92 | // ÀÏ´Ü caller°¡ À¯ÀÇÇØ¼ »ç¿ëÇϱâ·Î Çϰí mutex »ç¿ëÇÔ. |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | //------------------------------------------------------------------- |
|---|
| 96 | // debug log function. |
|---|
| 97 | // special prefix is inserted at the head of line, |
|---|
| 98 | // not to be confused with other UART message.. |
|---|
| 99 | // |
|---|
| 100 | |
|---|
| 101 | // µð¹ö±× ¸Þ½ÃÁö Ç¥½ÃµÇ´Â ¿¹: full option |
|---|
| 102 | // |
|---|
| 103 | // [APP] {tCmdExecute,130} 0320 Channel Up |
|---|
| 104 | // [DMC] {tDmc,105} 0320 Dmc_ChangeChannelUp(uid 3) |
|---|
| 105 | // SetTuner, AIR, 8VSB <--- driver¿¡¼ Ãâ·ÂÇÏ´Â ¸Þ½ÃÁö |
|---|
| 106 | // [DMC] {tDmc,105} 0323 Channel change end |
|---|
| 107 | // [Timer] {tTimer, 200} 00324 Timer started, tid 1 period 3 |
|---|
| 108 | // [APP] {AppGUI,120} 0324 channel |
|---|
| 109 | // [EPG] {tEpgTask,120} 0326 epg start.. |
|---|
| 110 | // |
|---|
| 111 | // |
|---|
| 112 | // °¢ ¸ðµâº°·Î PREFIX À̸§À» º¯°æÇؼ »ç¿ë. |
|---|
| 113 | // ±ÛÀÚ ¼ö Á¦ÇÑÀº ¾øÀ¸³ª 3~5ÀÚ·Î ¸ÂÃçÁÖ¸é ÁÁ°ÚÀ½. |
|---|
| 114 | // |
|---|
| 115 | // ¿¹) [iLink] [EPG] [PNR] µîµî.. |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | BOOL g_dhl_useMessage = TRUE; |
|---|
| 120 | // ¾ç»ê ½ÃÁ¡¿¡´Â ÀÌ º¯¼ö¸¦ FALSE·Î Çϰí ÃâÇÏÇϸé ÁöÀúºÐÇÑ ¸Þ¼¼Áö¸¦ ¾ø¾Ù¼ö ÀÖÀ½. |
|---|
| 121 | // ¹®Á¦°¡ ¹ß»ý½Ã UART¸¦ ÅëÇØ¼ ÀÌ º¯¼ö¸¦ ON ½ÃŲ ÈÄ µð¹ö±ëÀ» ÇÒ ¼ö ÀÖ´Ù. |
|---|
| 122 | |
|---|
| 123 | BOOL g_dhl_usePrintPrefix = TRUE; |
|---|
| 124 | // TRUEÀ̸é log message ¾Õ¿¡ [TAG]¸¦ Ãß°¡. |
|---|
| 125 | |
|---|
| 126 | BOOL g_dhl_printTimeTick = TRUE; |
|---|
| 127 | // TRUEÀ̸é log message ¾Õ¿¡ time tag¸¦ Ãß°¡. |
|---|
| 128 | // time tag´Â ¸Þ½ÃÁöµé °£ÀÇ ½Ã°£ °ü°è¸¦ Á¶»çÇÒ ¶§ Æí¸®ÇÔ. ½Ã°£ ´ÜÀ§´Â ¾Æ·¡ ÂüÁ¶. |
|---|
| 129 | |
|---|
| 130 | BOOL g_dhl_printTaskInfo = FALSE; |
|---|
| 131 | // TRUEÀ̸é task ID¸¦ °°ÀÌ Ç¥½Ã. |
|---|
| 132 | |
|---|
| 133 | BOOL g_dhl_useOsalPrintf = FALSE; |
|---|
| 134 | // TRUEÀ̸é DHL_OS_Printf »ç¿ë. |
|---|
| 135 | |
|---|
| 136 | DHL_OS_SEMA_ID g_dhl_printSema4; |
|---|
| 137 | // Print ÇÔ¼ö ³»ºÎÀûÀ¸·Î »ç¿ëÇÏ´Â Sema4 |
|---|
| 138 | |
|---|
| 139 | int g_dhl_sema4InitFailCount; |
|---|
| 140 | // Semaphore »ý¼º½Ã ¿¡·¯ ¹ß»ý Ƚ¼ö Ä«¿îÅÍ |
|---|
| 141 | // ÀÌ Ä«¿îÅÍ °ªÀ» °ü¸®ÇÏ´Â ÀÌÀ¯´Â ½Ã½ºÅÛ ¸®¼Ò½º µîÀÇ ÀÌÀ¯·Î Semaphore »ý¼ºÀÌ ½ÇÆÐÇÒ °æ¿ì |
|---|
| 142 | // ¸Å Print call ¸¶´Ù Semaphore »ý¼ºÀ» Àç½Ãµµ ÇÏ°Ô µÇ¸é ½Ã½ºÅÛ¿¡ ¾Ç¿µÇâÀ» ÁÙ ¼ö Àֱ⠶§¹®. |
|---|
| 143 | // ÀÏÁ¤ Ƚ¼ö ÀÌ»ó ½ÇÆÐÇÑ´Ù¸é Semaphore ¾øÀÌ ±×³É ÁøÇàÇÑ´Ù. |
|---|
| 144 | // |
|---|
| 145 | |
|---|
| 146 | BOOL g_dhl_flushBufferAlways; |
|---|
| 147 | // true ÀÌ¸é ¸Å printf ¸¶´Ù console buffer¸¦ flush ÇÑ´Ù. |
|---|
| 148 | // ÀÌ ¼³Á¤À» º¯°æÇÏ´Â API¸¦ ÀÌ¿ë. |
|---|
| 149 | |
|---|
| 150 | static int timetick(void) |
|---|
| 151 | { |
|---|
| 152 | // timing information. |
|---|
| 153 | // should not greater than 9999. |
|---|
| 154 | |
|---|
| 155 | #if 1 |
|---|
| 156 | return DHL_OS_GetMsCount() % 10000; |
|---|
| 157 | |
|---|
| 158 | #elif 1 |
|---|
| 159 | // 10 millisec unit. uCOS specific. os ticks per second is 200. |
|---|
| 160 | // to release cpu burden, i used hard-coded value. |
|---|
| 161 | return ((OS_GetTickCount() / 2) % 10000); |
|---|
| 162 | |
|---|
| 163 | #elif 1 |
|---|
| 164 | return ((OS_GetTickCount()*100/OS_GetTicksPerSecond()) % 10000); |
|---|
| 165 | // |
|---|
| 166 | // Ãâ·ÂµÉ timetickÀÇ ´ÜÀ§´Â 0.1ÃÊ·Î ÇÔ. |
|---|
| 167 | // UINT32 typeÀ̹ǷΠx10¿¡¼ overflow°¡ ³¯ ¼ö Àִµ¥ º° ¹®Á¦ ¾ÈµÊ. |
|---|
| 168 | // |
|---|
| 169 | |
|---|
| 170 | #elif 1 |
|---|
| 171 | return (dhl_sys_get_ms_tick() % 10000); |
|---|
| 172 | |
|---|
| 173 | #elif 1 |
|---|
| 174 | return ((Demux_GetSTC()/90) % 10000); |
|---|
| 175 | // ´ÜÀ§´Â millisec |
|---|
| 176 | |
|---|
| 177 | #endif |
|---|
| 178 | |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | #if DHL_DBG_USE_MUTEX |
|---|
| 183 | static void p_dbg_create_mutex() |
|---|
| 184 | { |
|---|
| 185 | DHL_OS_SEMA_ID mysema4 = (DHL_OS_SEMA_ID)0; |
|---|
| 186 | |
|---|
| 187 | if (g_dhl_printSema4 == (DHL_OS_SEMA_ID)0 && g_dhl_sema4InitFailCount < 5) // create sema4 |
|---|
| 188 | { |
|---|
| 189 | mysema4 = DHL_OS_CreateMutexSemaphore("DhlPrintf"); |
|---|
| 190 | |
|---|
| 191 | if (mysema4 == (DHL_OS_SEMA_ID)0) { |
|---|
| 192 | DHL_OS_Printf("!! DhlPrintf Sema4 creation failed.\n"); |
|---|
| 193 | g_dhl_sema4InitFailCount++; |
|---|
| 194 | } |
|---|
| 195 | else { |
|---|
| 196 | // Semaphore »ý¼º ¼º°ø. ÀÌÁ¦ »ý¼ºµÈ sema4¸¦ g_dhl_printSema4¿¡ ¾ÈÀüÇÏ°Ô assignÇÑ´Ù. |
|---|
| 197 | |
|---|
| 198 | if (1) |
|---|
| 199 | { |
|---|
| 200 | UINT32 mask = DHL_OS_DisableInterrupts(); |
|---|
| 201 | if (g_dhl_printSema4 == 0) { |
|---|
| 202 | // OS_LockTask µÈ »óÅ¿¡¼ g_dhl_printSema4¸¦ ÃʱâÈ ÇÑ´Ù. |
|---|
| 203 | g_dhl_printSema4 = mysema4; |
|---|
| 204 | mysema4 = (DHL_OS_SEMA_ID)0; |
|---|
| 205 | } |
|---|
| 206 | DHL_OS_RestoreInterrupts(mask); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | if (mysema4) { // ÀÌ¹Ì g_dhl_printSema4°¡ ´Ù¸¥ ŽºÅ©¿¡ ÀÇÇØ »ý¼ºÀÌ µÈ °æ¿ìÀÓ. |
|---|
| 210 | DHL_OS_Printf("!! Simultaneous DbgPrint Sema4 Creation detected %x. Safe release ours %x\n", |
|---|
| 211 | (UINT32)g_dhl_printSema4, (UINT32)mysema4); |
|---|
| 212 | DHL_OS_DeleteSemaphore(mysema4); |
|---|
| 213 | mysema4 = (DHL_OS_SEMA_ID)0; |
|---|
| 214 | } |
|---|
| 215 | else |
|---|
| 216 | DHL_OS_Printf("DhlPrintf Sema4 created\n"); |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | } |
|---|
| 220 | #endif // DHL_DBG_USE_MUTEX |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | /* DbgPrintFlag options |
|---|
| 225 | */ |
|---|
| 226 | |
|---|
| 227 | #define DHL_DPF_TASKNAME 0x1 |
|---|
| 228 | #define DHL_DPF_TASKPRIO 0x2 |
|---|
| 229 | #define DHL_DPF_TIMETICK 0x4 |
|---|
| 230 | |
|---|
| 231 | #define DHL_DPF_STDERR 0x100 // stderr ¿¡ Ãâ·ÂÇϵµ·Ï ÇÔ. |
|---|
| 232 | #define DHL_DPF_FLUSH 0x200 // ¸Å printf ¸¶´Ù flush¸¦ ¼öÇà. |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | int dhl_dbg_print_base(char *prefix, UINT32 flags, char *format, va_list ap) |
|---|
| 236 | { |
|---|
| 237 | int n = 0; |
|---|
| 238 | int len_prefix, len_taskinfo, len_timetick; |
|---|
| 239 | |
|---|
| 240 | char *p; |
|---|
| 241 | |
|---|
| 242 | #if DHL_DBG_USE_MUTEX |
|---|
| 243 | static char s_buf[4096]; // static buffer |
|---|
| 244 | #endif |
|---|
| 245 | char l_buf[1024]; // local buffer |
|---|
| 246 | char *buf; |
|---|
| 247 | |
|---|
| 248 | static BOOL s_bFirstColumn = TRUE; |
|---|
| 249 | |
|---|
| 250 | char ticks[10]; |
|---|
| 251 | |
|---|
| 252 | #if DHL_DBG_USE_MUTEX |
|---|
| 253 | static char taskinfo[128]; // task name is actually unlimited string.. |
|---|
| 254 | // anyway, we can safely use static array because this function is protected by semaphore. |
|---|
| 255 | #endif |
|---|
| 256 | |
|---|
| 257 | // for using static buffer, i blocked this function with sema4. |
|---|
| 258 | BOOL bSemTakenHere = FALSE; |
|---|
| 259 | |
|---|
| 260 | DHL_OS_TASK_INFO info; |
|---|
| 261 | DHL_RESULT dhr; |
|---|
| 262 | |
|---|
| 263 | BOOL bTaskName = (flags & DHL_DPF_TASKNAME) ? 1 : 0; |
|---|
| 264 | BOOL bTaskPrio = (flags & DHL_DPF_TASKPRIO) ? 1 : 0; |
|---|
| 265 | BOOL bTime = (flags & DHL_DPF_TIMETICK) ? 1 : 0; |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | if (!g_dhl_useMessage) return 0; |
|---|
| 269 | |
|---|
| 270 | if (format == NULL) |
|---|
| 271 | return 0; |
|---|
| 272 | |
|---|
| 273 | if (prefix == NULL) prefix = ""; |
|---|
| 274 | len_prefix = strlen(prefix); |
|---|
| 275 | |
|---|
| 276 | #if DHL_DBG_USE_MUTEX |
|---|
| 277 | if (g_dhl_printSema4 == (DHL_OS_SEMA_ID)0) |
|---|
| 278 | p_dbg_create_mutex(); |
|---|
| 279 | |
|---|
| 280 | // ÇöÀç os scheduler°¡ lock »óŶó¸é mutex¸¦ lockÀÌ deadlockÀ» À¯¹ßÇÒ ¼ö ÀÖÀ½. |
|---|
| 281 | if (DHL_OS_GetIntState()) { |
|---|
| 282 | DHL_OS_Printf("~"); buf = l_buf; |
|---|
| 283 | } |
|---|
| 284 | #if 0 // »õ·Î¿î DHL OSAL ¿¡¼´Â task lock API°¡ Á¦°ÅµÇ¾úÀ½. |
|---|
| 285 | else if (osi_in_tasklock(NULL)) { |
|---|
| 286 | DHL_OS_Printf("^"); buf = l_buf; |
|---|
| 287 | } |
|---|
| 288 | #endif |
|---|
| 289 | else { |
|---|
| 290 | buf = s_buf; |
|---|
| 291 | if (g_dhl_printSema4) { |
|---|
| 292 | DHL_OS_TakeSemaphore(g_dhl_printSema4, DHL_TIMEOUT_FOREVER); |
|---|
| 293 | bSemTakenHere = TRUE; |
|---|
| 294 | } |
|---|
| 295 | } |
|---|
| 296 | #else |
|---|
| 297 | buf = l_buf; // use local buffer. then no mutex required. |
|---|
| 298 | #endif |
|---|
| 299 | |
|---|
| 300 | if (strlen(format) > 512) |
|---|
| 301 | DHL_OS_Printf("!! Warning! too long msg. may be overflow..\n"); |
|---|
| 302 | |
|---|
| 303 | p = buf; |
|---|
| 304 | |
|---|
| 305 | // var list¸¦ buffer¿¡ expand ½ÃŲ´Ù. |
|---|
| 306 | if (format) |
|---|
| 307 | n = vsnprintf(p, sizeof(p), format, ap); |
|---|
| 308 | else |
|---|
| 309 | strcpy(buf, "NULL"); |
|---|
| 310 | |
|---|
| 311 | if (g_dhl_usePrintPrefix) |
|---|
| 312 | { |
|---|
| 313 | // debug messageÁßÀÇ LF (LineFeed) ´ÙÀ½¿¡ "[Prefix] {Task,Priority} time_tag " ¸¦ »ðÀÔ. |
|---|
| 314 | // |
|---|
| 315 | // ÇöÀç Ä¿¼°¡ column zero¿¡ ÀÖÀ» °æ¿ì¿¡¸¸ tag¸¦ »ðÀÔÇÑ´Ù. |
|---|
| 316 | // |
|---|
| 317 | int safty_limit = 0; |
|---|
| 318 | |
|---|
| 319 | p = buf; |
|---|
| 320 | |
|---|
| 321 | if (s_bFirstColumn) |
|---|
| 322 | { |
|---|
| 323 | #if DHL_DBG_USE_MUTEX |
|---|
| 324 | if (bTaskName || bTaskPrio) { |
|---|
| 325 | dhr = DHL_OS_GetTaskInfo(DHL_OS_GetTaskID(), &info); |
|---|
| 326 | if (dhr != DHL_OK) |
|---|
| 327 | snprintf(taskinfo, sizeof(taskinfo), "{? 0x%x} ", dhr); |
|---|
| 328 | else if (bTaskName && bTaskPrio) |
|---|
| 329 | snprintf(taskinfo, sizeof(taskinfo), "{%s,%2x} ", info.name, info.priority); |
|---|
| 330 | else if (bTaskName) |
|---|
| 331 | snprintf(taskinfo, sizeof(taskinfo), "{%s} ", info.name); |
|---|
| 332 | else |
|---|
| 333 | snprintf(taskinfo, sizeof(taskinfo),"{p%2x} ", info.priority); |
|---|
| 334 | |
|---|
| 335 | len_taskinfo = strlen(taskinfo); |
|---|
| 336 | } |
|---|
| 337 | else |
|---|
| 338 | len_taskinfo = 0; |
|---|
| 339 | #endif |
|---|
| 340 | |
|---|
| 341 | if (bTime) { |
|---|
| 342 | snprintf(ticks, 10, "%04d ", timetick()); |
|---|
| 343 | len_timetick = 5; |
|---|
| 344 | } |
|---|
| 345 | else |
|---|
| 346 | len_timetick = 0; |
|---|
| 347 | |
|---|
| 348 | if (len_prefix + len_taskinfo + len_timetick > 0) |
|---|
| 349 | memmove(p + len_prefix + len_taskinfo + len_timetick, p, strlen(p)+1); // °ø°£È®º¸. prefix + taskinfo + time_tick |
|---|
| 350 | |
|---|
| 351 | if (len_prefix) |
|---|
| 352 | memcpy(p, prefix, len_prefix); // prefix »ðÀÔ. |
|---|
| 353 | |
|---|
| 354 | #if DHL_DBG_USE_MUTEX |
|---|
| 355 | if (len_taskinfo) |
|---|
| 356 | memcpy(p+len_prefix, taskinfo, len_taskinfo); // taskinfo »ðÀÔ. |
|---|
| 357 | #endif |
|---|
| 358 | |
|---|
| 359 | if (len_timetick) |
|---|
| 360 | memcpy(p+len_prefix+len_taskinfo, ticks, len_timetick); // time_tick »ðÀÔ. |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | while (1) { |
|---|
| 364 | p = strchr(p, 0xA); // LF Äڵ带 ãÀ½. |
|---|
| 365 | if (p == NULL) { |
|---|
| 366 | break; |
|---|
| 367 | } |
|---|
| 368 | if (*++p == 0) { // ÀÌ LF°¡ ¸¶Áö¸· ¹®ÀÚ¶ó¸é ¿©±â¼ Á¾·á. |
|---|
| 369 | break; |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | #if DHL_DBG_USE_MUTEX |
|---|
| 373 | if (bTaskName || bTaskPrio) { |
|---|
| 374 | dhr = DHL_OS_GetTaskInfo(DHL_OS_GetTaskID(), &info); |
|---|
| 375 | if (dhr != DHL_OK) |
|---|
| 376 | snprintf(taskinfo, sizeof(taskinfo), "{? 0x%x} ", dhr); |
|---|
| 377 | else if (bTaskName && bTaskPrio) |
|---|
| 378 | snprintf(taskinfo, sizeof(taskinfo), "{%s,%2x} ", info.name, info.priority); |
|---|
| 379 | else if (bTaskName) |
|---|
| 380 | snprintf(taskinfo, sizeof(taskinfo), "{%s} ", info.name); |
|---|
| 381 | else |
|---|
| 382 | snprintf(taskinfo, sizeof(taskinfo), "{p%2x} ", info.priority); |
|---|
| 383 | |
|---|
| 384 | len_taskinfo = strlen(taskinfo); |
|---|
| 385 | } |
|---|
| 386 | else |
|---|
| 387 | len_taskinfo = 0; |
|---|
| 388 | #endif // DHL_DBG_USE_MUTEX |
|---|
| 389 | |
|---|
| 390 | if (bTime) { |
|---|
| 391 | sprintf(ticks, "%04d ", timetick()); |
|---|
| 392 | len_timetick = 5; |
|---|
| 393 | } |
|---|
| 394 | else |
|---|
| 395 | len_timetick = 0; |
|---|
| 396 | |
|---|
| 397 | if (len_prefix + len_taskinfo + len_timetick > 0) |
|---|
| 398 | memmove(p + len_prefix + len_taskinfo + len_timetick, p, strlen(p)+1); // °ø°£È®º¸. prefix + taskinfo + time_tick |
|---|
| 399 | |
|---|
| 400 | if (len_prefix) |
|---|
| 401 | memcpy(p, prefix, len_prefix); // prefix »ðÀÔ. |
|---|
| 402 | |
|---|
| 403 | #if DHL_DBG_USE_MUTEX |
|---|
| 404 | if (len_taskinfo) |
|---|
| 405 | memcpy(p+len_prefix, taskinfo, len_taskinfo); // taskinfo »ðÀÔ. |
|---|
| 406 | #endif |
|---|
| 407 | |
|---|
| 408 | if (len_timetick) |
|---|
| 409 | memcpy(p+len_prefix+len_taskinfo, ticks, len_timetick); // time_tick »ðÀÔ. |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | if (safty_limit++ > 10) { |
|---|
| 413 | DHL_OS_Printf("!! Warning! too many LFs. skip remainings.\n"); |
|---|
| 414 | break; |
|---|
| 415 | } |
|---|
| 416 | } |
|---|
| 417 | p = buf; |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | // now print it! |
|---|
| 421 | |
|---|
| 422 | if (flags & DHL_DPF_FLUSH) { |
|---|
| 423 | fprintf(1/*stderr*/, p); |
|---|
| 424 | } |
|---|
| 425 | else { |
|---|
| 426 | DHL_OS_Printf(p); |
|---|
| 427 | // in this case, message print may be deferred at arbitrary time. |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | if (flags & DHL_DPF_FLUSH) |
|---|
| 431 | ; //dhl_dbg_flush_console(); |
|---|
| 432 | |
|---|
| 433 | |
|---|
| 434 | if (p[strlen(p)-1] == 0xA) // ¸¶Áö¸· ±ÛÀÚ°¡ LF¶ó¸é Ä¿¼´Â ÀÌÁ¦ ¸Ç óÀ½À¸·Î À̵¿ÇÞÀ½. |
|---|
| 435 | s_bFirstColumn = TRUE; |
|---|
| 436 | else |
|---|
| 437 | s_bFirstColumn = FALSE; |
|---|
| 438 | |
|---|
| 439 | if (bSemTakenHere) // ÀÌ ÇÔ¼ö¿¡¼ takeÇß´ø °æ¿ì¿¡¸¸ Sem release¸¦ ÇÑ´Ù. |
|---|
| 440 | DHL_OS_GiveSemaphore(g_dhl_printSema4); |
|---|
| 441 | |
|---|
| 442 | return n; |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | int dhl_dbg_print(char *prefix, char *format, va_list ap) |
|---|
| 446 | { |
|---|
| 447 | return dhl_dbg_print_base(prefix, DHL_DPF_TIMETICK, format, ap); |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | #if COMMENT |
|---|
| 454 | ____Level_Print____(){} |
|---|
| 455 | #endif |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | |
|---|
| 459 | /* |
|---|
| 460 | usage: |
|---|
| 461 | DHL_DBG("this_module", 1); |
|---|
| 462 | // eDBG_MODULE_LVL_Warn. means that Error(0) and Warn(1) level message is allowed to print. |
|---|
| 463 | |
|---|
| 464 | dprint(0, "this is error level..\n"); // this is Error level. printed. |
|---|
| 465 | dprint(1, "this is warn level..\n"); // this is Warn level. printed. |
|---|
| 466 | dprint(2, "this is info level..\n"); // this is Info level. NOT printed. |
|---|
| 467 | |
|---|
| 468 | if (dprintable(3)) // memdump msg is Verbose level. NOT printed. |
|---|
| 469 | memdump(...); |
|---|
| 470 | |
|---|
| 471 | */ |
|---|
| 472 | |
|---|
| 473 | #define MAX_MODULE_NUM 128 |
|---|
| 474 | |
|---|
| 475 | static struct { |
|---|
| 476 | char name[16]; |
|---|
| 477 | int level; |
|---|
| 478 | } p_module_level_table[MAX_MODULE_NUM]; |
|---|
| 479 | |
|---|
| 480 | static int p_module_level_idx; |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | void DHL_DBG_SetModuleLevel(char *module_name, int level) |
|---|
| 484 | { |
|---|
| 485 | int i; |
|---|
| 486 | if (!module_name) return; |
|---|
| 487 | if (level < eDBG_MODULE_LVL_Silent) { |
|---|
| 488 | DHL_OS_Printf("!! invalid dbg module level %d\n", level); |
|---|
| 489 | return; |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | for(i=0; i<p_module_level_idx; i++) { |
|---|
| 493 | if(strcmp(module_name, p_module_level_table[i].name)==0) { |
|---|
| 494 | p_module_level_table[i].level=level; |
|---|
| 495 | break; |
|---|
| 496 | } |
|---|
| 497 | } |
|---|
| 498 | if (i<p_module_level_idx) { |
|---|
| 499 | DHL_OS_Printf("dbg module '%s' level changed to %d\n", module_name, level); |
|---|
| 500 | return; |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | // allocate new dbg module entry |
|---|
| 504 | if(p_module_level_idx>=MAX_MODULE_NUM) return; |
|---|
| 505 | |
|---|
| 506 | strncpy(p_module_level_table[p_module_level_idx].name,module_name,15); |
|---|
| 507 | p_module_level_table[p_module_level_idx].name[15] = 0; |
|---|
| 508 | p_module_level_table[p_module_level_idx].level=level; |
|---|
| 509 | p_module_level_idx++; |
|---|
| 510 | |
|---|
| 511 | DHL_OS_Printf("dbg module '%s' added, level %d. total %d modules\n", |
|---|
| 512 | module_name, level, p_module_level_idx); |
|---|
| 513 | |
|---|
| 514 | } |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | int DHL_DBG_GetModuleLevel(char *module_name) |
|---|
| 518 | { |
|---|
| 519 | int i; |
|---|
| 520 | if (!module_name) return eDBG_MODULE_LVL_Unknown; |
|---|
| 521 | |
|---|
| 522 | for(i=0; i<p_module_level_idx; i++) { |
|---|
| 523 | if(strcmp(module_name, p_module_level_table[i].name)==0) { |
|---|
| 524 | return p_module_level_table[i].level; |
|---|
| 525 | } |
|---|
| 526 | } |
|---|
| 527 | return eDBG_MODULE_LVL_Unknown; |
|---|
| 528 | } |
|---|
| 529 | |
|---|
| 530 | /* |
|---|
| 531 | check that module is registerred and add with new level. |
|---|
| 532 | if already registerred, skip. |
|---|
| 533 | |
|---|
| 534 | ¾îÂ¥ÇÇ level print ¿¡¼ üũÇÏ°Ô µÇ¹Ç·Î, |
|---|
| 535 | ÇѹøÀÇ Ã¼Å©·Î init °ú level check¸¦ °°ÀÌ ¼öÇàÇÏ´Â ÇÔ¼ö°¡ ´õ È¿À²ÀûÀÓ. |
|---|
| 536 | ÀÌ ÇÔ¼ö¿¡¼ levelÀ» ¾Ë¾Æ³½ ÈÄ ¹Ì¸® üũÇϰí LevelPrint°¡ ¾Æ´Ï¶ó |
|---|
| 537 | Print ÇÔ¼ö¸¦ »ç¿ëÇÒ ¼öµµ ÀÖ´Â ¹æ¹ý Á¦°ø. |
|---|
| 538 | */ |
|---|
| 539 | int DHL_DBG_CheckAndInitModuleLevel(char *module_name, int default_level) |
|---|
| 540 | { |
|---|
| 541 | //tDBG_MODULE_LVL level; |
|---|
| 542 | int level; |
|---|
| 543 | if ((level = DHL_DBG_GetModuleLevel(module_name)) == eDBG_MODULE_LVL_Unknown) { |
|---|
| 544 | DHL_DBG_SetModuleLevel(module_name, default_level); |
|---|
| 545 | level = default_level; |
|---|
| 546 | } |
|---|
| 547 | return (int)level; |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | void DHL_DBG_PrintModuleLevel(const char *substr) |
|---|
| 551 | { |
|---|
| 552 | int i; |
|---|
| 553 | int n_modules = 0; |
|---|
| 554 | const char *border; |
|---|
| 555 | |
|---|
| 556 | if (substr && substr[0]) |
|---|
| 557 | DHL_OS_Printf("modules that contains '%s'\n", substr); |
|---|
| 558 | |
|---|
| 559 | border = "===================================\n"; |
|---|
| 560 | DHL_OS_Printf(border); |
|---|
| 561 | |
|---|
| 562 | for(i=0; i<p_module_level_idx; i++) { |
|---|
| 563 | if (substr && substr[0] && |
|---|
| 564 | strstr(p_module_level_table[i].name, substr) == NULL) |
|---|
| 565 | continue; |
|---|
| 566 | DHL_OS_Printf(" (%2d) %-10s : %d\n", i, |
|---|
| 567 | p_module_level_table[i].name, p_module_level_table[i].level); |
|---|
| 568 | n_modules++; |
|---|
| 569 | } |
|---|
| 570 | DHL_OS_Printf(border); |
|---|
| 571 | DHL_OS_Printf(" %d modules \n", n_modules); |
|---|
| 572 | } |
|---|
| 573 | |
|---|
| 574 | |
|---|
| 575 | |
|---|
| 576 | int DHL_DBG_LevelPrint(char *prefix, int level, char *format, va_list ap) |
|---|
| 577 | { |
|---|
| 578 | int n; |
|---|
| 579 | int module_level=eDBG_MODULE_LVL_Unknown; |
|---|
| 580 | char prefix2[48]; |
|---|
| 581 | DHL_OS_TASK_INFO tinfo; |
|---|
| 582 | DHL_RESULT dhr; |
|---|
| 583 | |
|---|
| 584 | //°Ë»ö |
|---|
| 585 | for(n=0; n<p_module_level_idx; n++) { |
|---|
| 586 | if(strcmp(prefix, p_module_level_table[n].name)==0) { |
|---|
| 587 | module_level=p_module_level_table[n].level; |
|---|
| 588 | break; |
|---|
| 589 | } |
|---|
| 590 | } |
|---|
| 591 | if (module_level == eDBG_MODULE_LVL_Unknown) { |
|---|
| 592 | DHL_OS_Printf("!! unknown module '%s'!!\n", prefix); |
|---|
| 593 | return 0; |
|---|
| 594 | } |
|---|
| 595 | |
|---|
| 596 | if(module_level < level) { |
|---|
| 597 | //DHL_OS_Printf("module '%s', mlv %d > lvl %d, msg '%s' skipped\n", prefix, level, format); |
|---|
| 598 | return 0; |
|---|
| 599 | } |
|---|
| 600 | |
|---|
| 601 | dhr = DHL_OS_GetTaskInfo(DHL_OS_GetTaskID(), &tinfo); |
|---|
| 602 | if (dhr) |
|---|
| 603 | sprintf(prefix2, "[%s ?? 0x%x] ", prefix, dhr); |
|---|
| 604 | else |
|---|
| 605 | sprintf(prefix2, "[%s %d %s] ", prefix, tinfo.priority, tinfo.name); |
|---|
| 606 | |
|---|
| 607 | return dhl_dbg_print(prefix2, format, ap); |
|---|
| 608 | } |
|---|
| 609 | |
|---|
| 610 | int DHL_DBG_KeyPrint(char *prefix, char *format, va_list ap) |
|---|
| 611 | { |
|---|
| 612 | DHL_OS_Printf("|%s| not implemented...\n", __FUNCTION__); |
|---|
| 613 | |
|---|
| 614 | return 0; |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | /* end of file */ |
|---|
| 620 | |
|---|