/src/os/ucos-ii/ftk_ucos_sim.c

http://ftk.googlecode.com/ · C · 127 lines · 76 code · 22 blank · 29 comment · 4 complexity · 2356ffb4f338922ee175ddd982a6ce7f MD5 · raw file

  1. /*
  2. * File: ftk_ucos_sim.c
  3. * Author: MinPengli <MinPengli@gmail.com>
  4. * Brief: uCOS-II specific functions.
  5. *
  6. * Copyright (c) 2009 - 2010 MinPengli <MinPengli@gmail.com>
  7. *
  8. * Licensed under the Academic Free License version 2.1
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. /*
  25. * History:
  26. * ================================================================
  27. * 2010-03-19 MinPengli <MinPengli@gmail.com> created
  28. *
  29. */
  30. #include <string.h>
  31. #include <assert.h>
  32. #include "ftk_log.h"
  33. #include "includes.h"
  34. static char g_work_dir[MAX_PATH+1] = {0};
  35. static char g_data_dir[MAX_PATH+1] = {0};
  36. static char g_testdata_dir[MAX_PATH+1] = {0};
  37. char* ftk_get_root_dir(void)
  38. {
  39. return g_work_dir;
  40. }
  41. char* ftk_get_data_dir(void)
  42. {
  43. return g_data_dir;
  44. }
  45. char* ftk_get_testdata_dir(void)
  46. {
  47. return g_testdata_dir;
  48. }
  49. int ftk_platform_init(int argc, char** argv)
  50. {
  51. int Ret = 0;
  52. char* p = NULL;
  53. if(_getcwd(g_work_dir, MAX_PATH) != NULL)
  54. {
  55. p = strstr(g_work_dir, "\\src");
  56. if(p != NULL)
  57. {
  58. *p = '\0';
  59. ftk_snprintf(g_data_dir, MAX_PATH, "%s\\data", g_work_dir);
  60. ftk_snprintf(g_testdata_dir, MAX_PATH, "%s\\testdata", g_work_dir);
  61. }
  62. }
  63. ucos_pipe_init();
  64. return 0;
  65. }
  66. void ftk_platform_deinit(void)
  67. {
  68. ucos_pipe_deinit();
  69. return;
  70. }
  71. char* ftk_strncpy(char *dest, const char *src, size_t n)
  72. {
  73. return strncpy(dest, src, n);
  74. }
  75. int ftk_snprintf(char *str, size_t size, const char *format, ...)
  76. {
  77. int ret = 0;
  78. va_list args;
  79. OS_ENTER_CRITICAL();
  80. va_start(args, format);
  81. ret = _vsnprintf(str, size-1, format, args);
  82. str[size-1] = '\0';
  83. OS_EXIT_CRITICAL();
  84. return ret;
  85. }
  86. int ftk_vsnprintf(char *str, size_t size, const char *format, va_list ap)
  87. {
  88. int ret = 0;
  89. OS_ENTER_CRITICAL();
  90. ret = _vsnprintf(str, size-1, format, ap);
  91. OS_EXIT_CRITICAL();
  92. return ret;
  93. }
  94. size_t ftk_get_relative_time(void)
  95. {
  96. FILETIME ft;
  97. LARGE_INTEGER li;
  98. __int64 t;
  99. GetSystemTimeAsFileTime(&ft);
  100. li.LowPart = ft.dwLowDateTime;
  101. li.HighPart = ft.dwHighDateTime;
  102. t = li.QuadPart; /* In 100-nanosecond intervals */
  103. t /= 10; /* In microseconds */
  104. return t/1000;
  105. }