| 1 | /** |
|---|
| 2 | @file |
|---|
| 3 | DHL_OSAL_Print.c |
|---|
| 4 | |
|---|
| 5 | @brief |
|---|
| 6 | OSAL Debug IO Implementation |
|---|
| 7 | |
|---|
| 8 | Copyright 2006~2010 Digital STREAM Technology, Inc. |
|---|
| 9 | All Rights Reserved |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include "DHL_Types.h" |
|---|
| 15 | |
|---|
| 16 | #include "DHL_OSAL.h" |
|---|
| 17 | #include "DHL_OSAL_Priv.h" |
|---|
| 18 | |
|---|
| 19 | // os specific include |
|---|
| 20 | //#include <stdio.h> |
|---|
| 21 | ////#include <string.h> |
|---|
| 22 | //#include <stdarg.h> |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | #if COMMENT |
|---|
| 26 | ____Config____(){} |
|---|
| 27 | #endif |
|---|
| 28 | |
|---|
| 29 | /* |
|---|
| 30 | ÀÌ ¸ðµâ ³»ºÎ¿¡¼ »ç¿ëµÇ´Â °¢Á¾ configuration Á¤ÀÇ. |
|---|
| 31 | */ |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | #if COMMENT |
|---|
| 37 | ____Types____(){} |
|---|
| 38 | #endif |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | #if COMMENT |
|---|
| 45 | ____Init____(){} |
|---|
| 46 | #endif |
|---|
| 47 | #if 0 |
|---|
| 48 | |
|---|
| 49 | static BOOL s_dbgio_init; |
|---|
| 50 | |
|---|
| 51 | static void os_dbgio_init(void) |
|---|
| 52 | { |
|---|
| 53 | //DSI_init(OS_DBGIO_PORT); |
|---|
| 54 | //DSI_set_baudrate(OS_DBGIO_PORT, OS_DBGIO_BAUD); |
|---|
| 55 | |
|---|
| 56 | s_dbgio_init = TRUE; |
|---|
| 57 | } |
|---|
| 58 | #endif |
|---|
| 59 | |
|---|
| 60 | #if COMMENT |
|---|
| 61 | ____OS_Printf____(){} |
|---|
| 62 | #endif |
|---|
| 63 | #if 0 |
|---|
| 64 | /* Buffer for DSI_printf */ |
|---|
| 65 | #define OS_PRINTF_MAX_LEN 256 |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | /* |
|---|
| 69 | Çѹø¿¡ Ãâ·Â °¡´ÉÇÑ ÃÖ´ë ±æÀÌ Á¦ÇÑÀÌ ÀÖÀ½.. |
|---|
| 70 | */ |
|---|
| 71 | int dbg_val = 0; |
|---|
| 72 | |
|---|
| 73 | int DHL_OS_Printf(const char *fmt, ...) |
|---|
| 74 | { |
|---|
| 75 | if(dbg_val == 1) |
|---|
| 76 | { |
|---|
| 77 | int len; |
|---|
| 78 | va_list args; |
|---|
| 79 | char buf[OS_PRINTF_MAX_LEN+1]; |
|---|
| 80 | int i; |
|---|
| 81 | |
|---|
| 82 | if (!s_dbgio_init) os_dbgio_init(); |
|---|
| 83 | |
|---|
| 84 | va_start(args, fmt); |
|---|
| 85 | |
|---|
| 86 | len = vsnprintf(buf, OS_PRINTF_MAX_LEN, fmt, args); |
|---|
| 87 | buf[OS_PRINTF_MAX_LEN] = 0; |
|---|
| 88 | |
|---|
| 89 | i = 0; |
|---|
| 90 | while (buf[i] != 0) |
|---|
| 91 | { |
|---|
| 92 | if (buf[i] == '\n') |
|---|
| 93 | { |
|---|
| 94 | MDrv_UART_PutChar('\r'); |
|---|
| 95 | } |
|---|
| 96 | MDrv_UART_PutChar(buf[i++]); |
|---|
| 97 | } |
|---|
| 98 | return len; |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | int _DHL_OS_Printf(const char *fmt, ...) |
|---|
| 103 | { |
|---|
| 104 | int len; |
|---|
| 105 | va_list args; |
|---|
| 106 | char buf[OS_PRINTF_MAX_LEN+1]; |
|---|
| 107 | int i; |
|---|
| 108 | |
|---|
| 109 | if (!s_dbgio_init) os_dbgio_init(); |
|---|
| 110 | |
|---|
| 111 | va_start(args, fmt); |
|---|
| 112 | |
|---|
| 113 | len = vsnprintf(buf, OS_PRINTF_MAX_LEN, fmt, args); |
|---|
| 114 | buf[OS_PRINTF_MAX_LEN] = 0; |
|---|
| 115 | |
|---|
| 116 | i = 0; |
|---|
| 117 | while (buf[i] != 0) |
|---|
| 118 | { |
|---|
| 119 | if (buf[i] == '\n') |
|---|
| 120 | { |
|---|
| 121 | MDrv_UART_PutChar('\r'); |
|---|
| 122 | } |
|---|
| 123 | MDrv_UART_PutChar(buf[i++]); |
|---|
| 124 | } |
|---|
| 125 | return len; |
|---|
| 126 | |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | // 1->debug start 0->debug end |
|---|
| 130 | // printf ÀÇ Ãæµ¹À» ÀǽÉ. °¡±ÞÀû debuging ¿Ü¿¡ play »óÅÂÀÏ °æ¿ì È£ÃâÇÏÁö¸»ÀÚ |
|---|
| 131 | |
|---|
| 132 | void dbg_print(int val) |
|---|
| 133 | { |
|---|
| 134 | dbg_val = val; |
|---|
| 135 | if(val==1) |
|---|
| 136 | _DHL_OS_Printf("\n.. DEBUG-START ..\n"); |
|---|
| 137 | else if(val==0) |
|---|
| 138 | _DHL_OS_Printf("\n.. DEBUG-END ..\n"); |
|---|
| 139 | |
|---|
| 140 | } |
|---|
| 141 | #endif |
|---|
| 142 | #if COMMENT |
|---|
| 143 | ____OS_GetChar____(){} |
|---|
| 144 | #endif |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | #if 1 /* broadcom specific */ |
|---|
| 148 | |
|---|
| 149 | #ifdef CONFIG_GP |
|---|
| 150 | #error please check return code of console_getch() function. |
|---|
| 151 | #endif |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | // return -1 if no key input. |
|---|
| 155 | int getch_timeout(int timeoutms) |
|---|
| 156 | { |
|---|
| 157 | extern int console_getch(void); |
|---|
| 158 | /* it is defined in ministd.c, which was static function. |
|---|
| 159 | it is non-blocking call. |
|---|
| 160 | it returns 0 if no input key available. |
|---|
| 161 | */ |
|---|
| 162 | extern void gettimeofday(b_timeval *tv); |
|---|
| 163 | |
|---|
| 164 | int ch; |
|---|
| 165 | unsigned long ulstart, ulnow; |
|---|
| 166 | |
|---|
| 167 | b_timeval now; |
|---|
| 168 | gettimeofday(&now); |
|---|
| 169 | ulstart = now.tv_sec * 1000 + now.tv_usec/1000; |
|---|
| 170 | |
|---|
| 171 | while (1) { |
|---|
| 172 | ch = console_getch(); |
|---|
| 173 | if (ch > 0) |
|---|
| 174 | return ch; |
|---|
| 175 | gettimeofday(&now); |
|---|
| 176 | ulnow = now.tv_sec * 1000 + now.tv_usec/1000; |
|---|
| 177 | if (ulnow - ulstart >= timeoutms) |
|---|
| 178 | break; |
|---|
| 179 | //OSTimeDly(); // current system config: 200 ticks/sec. 50ms per 1tick. |
|---|
| 180 | bos_sleep(10); |
|---|
| 181 | } |
|---|
| 182 | return -1; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | #else |
|---|
| 186 | #error not imple |
|---|
| 187 | #endif |
|---|
| 188 | |
|---|
| 189 | int DHL_OS_GetChar(void) |
|---|
| 190 | { |
|---|
| 191 | char key; |
|---|
| 192 | int ch = 0; |
|---|
| 193 | |
|---|
| 194 | // 1st |
|---|
| 195 | key = (char)getch_timeout(100); |
|---|
| 196 | if (key == 0x1b) |
|---|
| 197 | { |
|---|
| 198 | // nothing... |
|---|
| 199 | } |
|---|
| 200 | else |
|---|
| 201 | { |
|---|
| 202 | ch = key; |
|---|
| 203 | |
|---|
| 204 | goto exit; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | // 2nd |
|---|
| 208 | key = (char)getch_timeout(100); |
|---|
| 209 | if (key == 0x5b) |
|---|
| 210 | { |
|---|
| 211 | // nothing... |
|---|
| 212 | } |
|---|
| 213 | else |
|---|
| 214 | { |
|---|
| 215 | ch = DHL_EXTKEY_ESC; |
|---|
| 216 | |
|---|
| 217 | goto exit; |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | // 3rd |
|---|
| 221 | key = (char)getch_timeout(100); |
|---|
| 222 | if (key == 0x32) |
|---|
| 223 | { |
|---|
| 224 | ch = DHL_EXTKEY_HOME; |
|---|
| 225 | } |
|---|
| 226 | else if (key == 0x33) |
|---|
| 227 | { |
|---|
| 228 | ch = DHL_EXTKEY_PGUP; |
|---|
| 229 | } |
|---|
| 230 | else if (key == 0x34) |
|---|
| 231 | { |
|---|
| 232 | ch = DHL_EXTKEY_DEL; |
|---|
| 233 | } |
|---|
| 234 | else if (key == 0x35) |
|---|
| 235 | { |
|---|
| 236 | ch = DHL_EXTKEY_END; |
|---|
| 237 | } |
|---|
| 238 | else if (key == 0x36) |
|---|
| 239 | { |
|---|
| 240 | ch = DHL_EXTKEY_PGDN; |
|---|
| 241 | } |
|---|
| 242 | else if (key == 0x41) |
|---|
| 243 | { |
|---|
| 244 | ch = DHL_EXTKEY_UP; |
|---|
| 245 | |
|---|
| 246 | goto exit; |
|---|
| 247 | } |
|---|
| 248 | else if (key == 0x42) |
|---|
| 249 | { |
|---|
| 250 | ch = DHL_EXTKEY_DN; |
|---|
| 251 | |
|---|
| 252 | goto exit; |
|---|
| 253 | } |
|---|
| 254 | else if (key == 0x43) |
|---|
| 255 | { |
|---|
| 256 | ch = DHL_EXTKEY_RG; |
|---|
| 257 | |
|---|
| 258 | goto exit; |
|---|
| 259 | } |
|---|
| 260 | else if (key == 0x44) |
|---|
| 261 | { |
|---|
| 262 | ch = DHL_EXTKEY_LF; |
|---|
| 263 | |
|---|
| 264 | goto exit; |
|---|
| 265 | } |
|---|
| 266 | else |
|---|
| 267 | { |
|---|
| 268 | ch = DHL_EXTKEY_ESC; |
|---|
| 269 | |
|---|
| 270 | goto exit; |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | // 4th |
|---|
| 274 | key = (char)getch_timeout(100); |
|---|
| 275 | if (key == 0x7e) |
|---|
| 276 | { |
|---|
| 277 | // nothing... |
|---|
| 278 | } |
|---|
| 279 | else |
|---|
| 280 | { |
|---|
| 281 | ch = DHL_EXTKEY_ESC; |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | exit: |
|---|
| 285 | return ch; |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | #if COMMENT |
|---|
| 292 | ____Utilities____(){} |
|---|
| 293 | #endif |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | /* |
|---|
| 297 | ¶óÀÎ ´ÜÀ§ ÀÔ·Â API. |
|---|
| 298 | ¸®Åϰª: ÀÔ·Â ¹ÞÀº ±ÛÀÚ ¼ö. |
|---|
| 299 | */ |
|---|
| 300 | int dhl_os_get_line(char *buf, int size, DHL_OS_GET_LINE_FLAGS flags) |
|---|
| 301 | { |
|---|
| 302 | char *p = buf; |
|---|
| 303 | UINT32 key; |
|---|
| 304 | char tmp[10] = {0, }; |
|---|
| 305 | BOOL cancelled = FALSE; |
|---|
| 306 | |
|---|
| 307 | if (!buf) return -2; |
|---|
| 308 | |
|---|
| 309 | while (1) |
|---|
| 310 | { |
|---|
| 311 | key = DHL_OS_GetChar(); |
|---|
| 312 | |
|---|
| 313 | if (key == 0) |
|---|
| 314 | continue; |
|---|
| 315 | |
|---|
| 316 | if (key == 0xd || key == 0xa) { |
|---|
| 317 | *p = 0; // null terminate and exit |
|---|
| 318 | if (!(flags & eDHL_OS_GLF_NOECHO)) |
|---|
| 319 | DHL_OS_Printf("\n"); |
|---|
| 320 | break; |
|---|
| 321 | } |
|---|
| 322 | else if (key == 0x1b) { // ESC key |
|---|
| 323 | cancelled = TRUE; |
|---|
| 324 | break; |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | // process input key |
|---|
| 328 | // |
|---|
| 329 | if (key == '\b' || key == 0x7F) { // backspace is treated as special |
|---|
| 330 | if (p > buf) { // go back ÇÒ ±ÛÀÚ°¡ ÀÖ´Â °æ¿ì¿¡¸¸.. |
|---|
| 331 | if (!(flags & eDHL_OS_GLF_NOECHO)) |
|---|
| 332 | DHL_OS_Printf("\b \b"); |
|---|
| 333 | *--p = ' '; |
|---|
| 334 | } |
|---|
| 335 | continue; |
|---|
| 336 | } |
|---|
| 337 | else if ((int)(p - buf) < size-1) { |
|---|
| 338 | if (!(flags & eDHL_OS_GLF_NOECHO)) { |
|---|
| 339 | // ÇѱÛÀÚ¸¸ Ãâ·Â. passwd ¿É¼ÇÀÇ °æ¿ì * Ãâ·Â. |
|---|
| 340 | tmp[0] = (flags & eDHL_OS_GLF_PASSWD) ? '*' : key; |
|---|
| 341 | tmp[1] = 0; // ÇÑ ±ÛÀÚ¸¸ Ãâ·Â. |
|---|
| 342 | DHL_OS_Printf(tmp); |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | *p++ = key; |
|---|
| 346 | } |
|---|
| 347 | else { |
|---|
| 348 | // do nothing, just ignore key.. buffer full |
|---|
| 349 | } |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | if (cancelled) |
|---|
| 353 | return -1; |
|---|
| 354 | |
|---|
| 355 | // trim trailing spaces |
|---|
| 356 | |
|---|
| 357 | p = buf + strlen(buf) - 1; |
|---|
| 358 | |
|---|
| 359 | while (p >= buf && (*p == ' ' || *p == '\t')) { |
|---|
| 360 | *p-- = 0; |
|---|
| 361 | //n_trim++; |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | // skip head spaces and tab |
|---|
| 365 | |
|---|
| 366 | p = buf; |
|---|
| 367 | while (*p == ' ' || *p == '\t') p++; |
|---|
| 368 | |
|---|
| 369 | // shift strings |
|---|
| 370 | if (p != buf) |
|---|
| 371 | memmove(buf, p, strlen(p)+1); |
|---|
| 372 | |
|---|
| 373 | return strlen(buf); |
|---|
| 374 | |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | /* end of file */ |
|---|
| 381 | |
|---|