/** @file DHL_OSAL_Print.c @brief OSAL Debug IO Implementation Copyright 2006~2010 Digital STREAM Technology, Inc. All Rights Reserved */ #include "DHL_Types.h" #include "DHL_OSAL.h" #include "DHL_OSAL_Priv.h" // os specific include //#include ////#include //#include #if COMMENT ____Config____(){} #endif /* ÀÌ ¸ðµâ ³»ºÎ¿¡¼­ »ç¿ëµÇ´Â °¢Á¾ configuration Á¤ÀÇ. */ #if COMMENT ____Types____(){} #endif #if COMMENT ____Init____(){} #endif #if 0 static BOOL s_dbgio_init; static void os_dbgio_init(void) { //DSI_init(OS_DBGIO_PORT); //DSI_set_baudrate(OS_DBGIO_PORT, OS_DBGIO_BAUD); s_dbgio_init = TRUE; } #endif #if COMMENT ____OS_Printf____(){} #endif #if 0 /* Buffer for DSI_printf */ #define OS_PRINTF_MAX_LEN 256 /* Çѹø¿¡ Ãâ·Â °¡´ÉÇÑ ÃÖ´ë ±æÀÌ Á¦ÇÑÀÌ ÀÖÀ½.. */ int dbg_val = 0; int DHL_OS_Printf(const char *fmt, ...) { if(dbg_val == 1) { int len; va_list args; char buf[OS_PRINTF_MAX_LEN+1]; int i; if (!s_dbgio_init) os_dbgio_init(); va_start(args, fmt); len = vsnprintf(buf, OS_PRINTF_MAX_LEN, fmt, args); buf[OS_PRINTF_MAX_LEN] = 0; i = 0; while (buf[i] != 0) { if (buf[i] == '\n') { MDrv_UART_PutChar('\r'); } MDrv_UART_PutChar(buf[i++]); } return len; } } int _DHL_OS_Printf(const char *fmt, ...) { int len; va_list args; char buf[OS_PRINTF_MAX_LEN+1]; int i; if (!s_dbgio_init) os_dbgio_init(); va_start(args, fmt); len = vsnprintf(buf, OS_PRINTF_MAX_LEN, fmt, args); buf[OS_PRINTF_MAX_LEN] = 0; i = 0; while (buf[i] != 0) { if (buf[i] == '\n') { MDrv_UART_PutChar('\r'); } MDrv_UART_PutChar(buf[i++]); } return len; } // 1->debug start 0->debug end // printf ÀÇ Ãæµ¹À» ÀǽÉ. °¡±ÞÀû debuging ¿Ü¿¡ play »óÅÂÀÏ °æ¿ì È£ÃâÇÏÁö¸»ÀÚ void dbg_print(int val) { dbg_val = val; if(val==1) _DHL_OS_Printf("\n.. DEBUG-START ..\n"); else if(val==0) _DHL_OS_Printf("\n.. DEBUG-END ..\n"); } #endif #if COMMENT ____OS_GetChar____(){} #endif #if 1 /* broadcom specific */ #ifdef CONFIG_GP #error please check return code of console_getch() function. #endif // return -1 if no key input. int getch_timeout(int timeoutms) { extern int console_getch(void); /* it is defined in ministd.c, which was static function. it is non-blocking call. it returns 0 if no input key available. */ extern void gettimeofday(b_timeval *tv); int ch; unsigned long ulstart, ulnow; b_timeval now; gettimeofday(&now); ulstart = now.tv_sec * 1000 + now.tv_usec/1000; while (1) { ch = console_getch(); if (ch > 0) return ch; gettimeofday(&now); ulnow = now.tv_sec * 1000 + now.tv_usec/1000; if (ulnow - ulstart >= timeoutms) break; //OSTimeDly(); // current system config: 200 ticks/sec. 50ms per 1tick. bos_sleep(10); } return -1; } #else #error not imple #endif int DHL_OS_GetChar(void) { char key; int ch = 0; // 1st key = (char)getch_timeout(100); if (key == 0x1b) { // nothing... } else { ch = key; goto exit; } // 2nd key = (char)getch_timeout(100); if (key == 0x5b) { // nothing... } else { ch = DHL_EXTKEY_ESC; goto exit; } // 3rd key = (char)getch_timeout(100); if (key == 0x32) { ch = DHL_EXTKEY_HOME; } else if (key == 0x33) { ch = DHL_EXTKEY_PGUP; } else if (key == 0x34) { ch = DHL_EXTKEY_DEL; } else if (key == 0x35) { ch = DHL_EXTKEY_END; } else if (key == 0x36) { ch = DHL_EXTKEY_PGDN; } else if (key == 0x41) { ch = DHL_EXTKEY_UP; goto exit; } else if (key == 0x42) { ch = DHL_EXTKEY_DN; goto exit; } else if (key == 0x43) { ch = DHL_EXTKEY_RG; goto exit; } else if (key == 0x44) { ch = DHL_EXTKEY_LF; goto exit; } else { ch = DHL_EXTKEY_ESC; goto exit; } // 4th key = (char)getch_timeout(100); if (key == 0x7e) { // nothing... } else { ch = DHL_EXTKEY_ESC; } exit: return ch; } #if COMMENT ____Utilities____(){} #endif /* ¶óÀÎ ´ÜÀ§ ÀÔ·Â API. ¸®Åϰª: ÀÔ·Â ¹ÞÀº ±ÛÀÚ ¼ö. */ int dhl_os_get_line(char *buf, int size, DHL_OS_GET_LINE_FLAGS flags) { char *p = buf; UINT32 key; char tmp[10] = {0, }; BOOL cancelled = FALSE; if (!buf) return -2; while (1) { key = DHL_OS_GetChar(); if (key == 0) continue; if (key == 0xd || key == 0xa) { *p = 0; // null terminate and exit if (!(flags & eDHL_OS_GLF_NOECHO)) DHL_OS_Printf("\n"); break; } else if (key == 0x1b) { // ESC key cancelled = TRUE; break; } // process input key // if (key == '\b' || key == 0x7F) { // backspace is treated as special if (p > buf) { // go back ÇÒ ±ÛÀÚ°¡ ÀÖ´Â °æ¿ì¿¡¸¸.. if (!(flags & eDHL_OS_GLF_NOECHO)) DHL_OS_Printf("\b \b"); *--p = ' '; } continue; } else if ((int)(p - buf) < size-1) { if (!(flags & eDHL_OS_GLF_NOECHO)) { // ÇѱÛÀÚ¸¸ Ãâ·Â. passwd ¿É¼ÇÀÇ °æ¿ì * Ãâ·Â. tmp[0] = (flags & eDHL_OS_GLF_PASSWD) ? '*' : key; tmp[1] = 0; // ÇÑ ±ÛÀÚ¸¸ Ãâ·Â. DHL_OS_Printf(tmp); } *p++ = key; } else { // do nothing, just ignore key.. buffer full } } if (cancelled) return -1; // trim trailing spaces p = buf + strlen(buf) - 1; while (p >= buf && (*p == ' ' || *p == '\t')) { *p-- = 0; //n_trim++; } // skip head spaces and tab p = buf; while (*p == ' ' || *p == '\t') p++; // shift strings if (p != buf) memmove(buf, p, strlen(p)+1); return strlen(buf); } /* end of file */