PageRenderTime 455ms CodeModel.GetById 204ms app.highlight 6ms RepoModel.GetById 144ms app.codeStats 0ms

/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/*
 26 *  History:
 27 * ================================================================
 28 * 2010-03-19 MinPengli <MinPengli@gmail.com> created
 29 *
 30 */
 31
 32#include <string.h>
 33#include <assert.h>
 34#include "ftk_log.h"
 35#include "includes.h"
 36
 37static char g_work_dir[MAX_PATH+1] = {0};
 38static char g_data_dir[MAX_PATH+1] = {0};
 39static char g_testdata_dir[MAX_PATH+1] = {0};
 40
 41char* ftk_get_root_dir(void)
 42{
 43	return g_work_dir;
 44}
 45
 46char* ftk_get_data_dir(void)
 47{
 48	return g_data_dir;
 49}
 50
 51char* ftk_get_testdata_dir(void)
 52{
 53	return g_testdata_dir;
 54}
 55
 56int ftk_platform_init(int argc, char** argv)
 57{
 58	int Ret = 0;
 59	char* p = NULL;
 60	
 61	if(_getcwd(g_work_dir, MAX_PATH) != NULL)
 62	{
 63		p = strstr(g_work_dir, "\\src");
 64		if(p != NULL)
 65		{
 66			*p = '\0';
 67			ftk_snprintf(g_data_dir, MAX_PATH, "%s\\data", g_work_dir);
 68			ftk_snprintf(g_testdata_dir, MAX_PATH, "%s\\testdata", g_work_dir);
 69		}
 70	}
 71
 72	ucos_pipe_init();
 73
 74	return 0;
 75}
 76
 77void ftk_platform_deinit(void)
 78{
 79	ucos_pipe_deinit();
 80
 81	return;
 82}
 83
 84char* ftk_strncpy(char *dest, const char *src, size_t n)
 85{
 86	return strncpy(dest, src, n);
 87}
 88
 89int   ftk_snprintf(char *str, size_t size, const char *format, ...)
 90{
 91	int ret = 0;
 92	va_list args;
 93
 94	OS_ENTER_CRITICAL();
 95	va_start(args, format);
 96	ret = _vsnprintf(str, size-1, format, args);
 97	str[size-1] = '\0';
 98	OS_EXIT_CRITICAL();
 99
100	return ret;
101}
102
103int   ftk_vsnprintf(char *str, size_t size, const char *format, va_list ap)
104{
105	int ret = 0;
106
107	OS_ENTER_CRITICAL();
108	ret = _vsnprintf(str, size-1, format, ap);
109	OS_EXIT_CRITICAL();
110
111	return ret; 
112}
113
114size_t ftk_get_relative_time(void)
115{
116	FILETIME        ft;
117	LARGE_INTEGER   li;
118	__int64         t;
119
120	GetSystemTimeAsFileTime(&ft);
121	li.LowPart  = ft.dwLowDateTime;
122	li.HighPart = ft.dwHighDateTime;
123	t  = li.QuadPart;       /* In 100-nanosecond intervals */
124	t /= 10;                /* In microseconds */
125
126	return t/1000;
127}