Ejemplo n.º 1
0
static int writespeed(int fd, char *buff_ptr, unsigned int total_length, int block_size)
{
    int index, length;
    rt_tick_t tick;
	
	/* prepare write data */
	for (index = 0; index < block_size; index++)
	{
		buff_ptr[index] = index;
	}
	index = 0;

	/* get the beginning tick */
    tick = rt_tick_get();
	while (index < total_length / block_size)
	{
		length = write(fd, buff_ptr, block_size);
		if (length != block_size)
		{
			rt_kprintf("write failed\n");
			break;
		}

		index ++;
	}
    tick = rt_tick_get() - tick;

    /* calculate write speed */
    return (total_length / tick * RT_TICK_PER_SECOND);

}
Ejemplo n.º 2
0
static void _sleep_entry(void)
{
	rt_tick_t timeout;
	rt_uint32_t ms;
	rt_uint32_t count;

	system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY);
	timeout = rt_timer_next_timeout_tick() - rt_tick_get();

	ms = timeout * (1000 / RT_TICK_PER_SECOND);
	rt_kprintf("os tick:%u entry sleep:%u tick\r\n", rt_tick_get(), timeout);

	_rtc_timer_start(ms);

	system_sleep();

	rt_enter_critical();
	count = rtc_count_get_count(&rtc_instance);
	ms = (count + 32) / 32.768;
	rtc_count_disable(&rtc_instance);
	sleep_tick_adjust(ms);
	timeout = rt_tick_get();
	rt_exit_critical();
	rt_kprintf("sleep exited, os tick:%u\n", timeout);
}
Ejemplo n.º 3
0
void msc_thread_entry(void *parameter)
{
    extern void player_ui_freeze(void);
    unsigned long test_unit_ready_start = rt_tick_get();
    test_unit_ready_last = test_unit_ready_start;

    /* wait connection */
    while( test_unit_ready_last == test_unit_ready_start )
    {
        rt_thread_delay( RT_TICK_PER_SECOND );
    }


    /* freeze player UI */
    player_ui_freeze();

    /* wait remove */
    while(1)
    {
        rt_thread_delay( RT_TICK_PER_SECOND/2 );
        if( rt_tick_get() - test_unit_ready_last > RT_TICK_PER_SECOND*2 )
        {
//            rt_kprintf("\r\nCable removed!\r\nSystemReset\r\n\r\n");
//            NVIC_SystemReset();
        }
    }
}
Ejemplo n.º 4
0
static void thread_entry(void* parameter)
{
	rt_tick_t tick;
	rt_kprintf("thread inited ok\n");

	tick = rt_tick_get();
	rt_kprintf("thread delay 10 tick\n");
	rt_thread_delay(10);
	if (rt_tick_get() - tick > 10)
	{
		tc_done(TC_STAT_FAILED);
		return;
	}

	tick = rt_tick_get();
	rt_kprintf("thread delay 15 tick\n");
	rt_thread_delay(15);
	if (rt_tick_get() - tick > 15)
	{
		tc_done(TC_STAT_FAILED);
		return;
	}

	rt_kprintf("thread exit\n");

	tc_done(TC_STAT_PASSED);
}
Ejemplo n.º 5
0
void PVD_IRQHandler(void)
{
	unsigned poweroff_cnt;
	unsigned long time;

	EXTI->PR = EXTI_Line16; //EXTI_ClearITPendingBit(EXTI_Line16);

	/* 系统上电前500ms, 不认为是掉电; 若已处于系统掉电状态, 将不再处理 */
	if ((rt_tick_get() < 50) || (NULL == rtc_dev) || is_system_powerdown) {
		return;
	}

	/*
		lcd_bl_led_off();
		buzzer_off(buzzer_gpio, buzzer_pin);
	*/
	is_system_powerdown = 1;
	sys_powerdown_delay4confirm = rt_tick_get();

	PWR_BackupAccessCmd(ENABLE);

	poweroff_cnt = BKP_ReadBackupRegister(RX_POWEROFF_CNT_BKP16BITS);
	BKP_WriteBackupRegister(RX_POWEROFF_CNT_BKP16BITS, ++poweroff_cnt);

	rt_device_control(rtc_dev, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
	BKP_WriteBackupRegister(RX_POWEROFF_N_BKP16BITS_H, (time>>16) & 0xffff);
	BKP_WriteBackupRegister(RX_POWEROFF_N_BKP16BITS_L, (time) & 0xffff);

	PWR_BackupAccessCmd(DISABLE);

	//rt_kprintf("%s", __FUNCTION__);

	return;
}
Ejemplo n.º 6
0
void Sram_thread_entry(void* parameter)
{
	rt_tick_t t1,t2;
	SRAM_Init();
	Fill_Buffer(aTxBuffer, BUFFER_SIZE, 0xA244250F);  
	//DMA_Config();
//	while(flag)
//	{
//		rt_thread_delay(1);
//	}
	rt_sem_take(&rt_sram_sem, RT_WAITING_FOREVER);
	while(flag1)
	{
		int fd;
		//int i=1024;
		fd = open("/ud/text.txt", O_WRONLY | O_CREAT,0);	
			if (fd >= 0)
			{
				t1 = rt_tick_get();
//				while(i>0)
//				{
					write(fd, RAM_Buffer, sizeof(RAM_Buffer));
//					i--;
//				}
				t2 = rt_tick_get();
				rt_kprintf("%d\n\r",t2-t1);
				close(fd);
			}
			rt_thread_delay(100);
		//SRAM_ReadBuffer(aTxBuffer,0,BUFFER_SIZE);
	}
	while(1);
	//Fill_Buffer(aTxBuffer, BUFFER_SIZE, 0xA244250F); 
}
Ejemplo n.º 7
0
rt_err_t gsm_send_wait_func( char *AT_cmd_string,
                             uint32_t timeout,
                             RESP_FUNC respfunc,
                             uint8_t no_of_attempts )
{
	rt_err_t		err;
	uint8_t			i;
	char			*pmsg;
	uint32_t		tick_start, tick_end;
	uint32_t		tm;
	__IO uint8_t	flag_wait;

	char			* pinfo;
	uint16_t		len;

	err = rt_sem_take( &sem_at, timeout );
	if( err != RT_EOK )
	{
		return err;
	}

	for( i = 0; i < no_of_attempts; i++ )
	{
		tick_start	= rt_tick_get( );
		tick_end	= tick_start + timeout;
		tm			= timeout;
		flag_wait	= 1;
		rt_kprintf( "%08d gsm>%s\r\n", tick_start, AT_cmd_string );
		m66_write( &dev_gsm, 0, AT_cmd_string, strlen( AT_cmd_string ) );
		while( flag_wait )
		{
			err = rt_mb_recv( &mb_gsmrx, (rt_uint32_t*)&pmsg, tm );
			if( err == RT_EOK )                         /*没有超时,判断信息是否正确*/
			{
				len		= ( *pmsg << 8 ) | ( *( pmsg + 1 ) );
				pinfo	= pmsg + 2;
				if( respfunc( pinfo, len ) == RT_EOK )  /*找到了*/
				{
					rt_free( pmsg );                    /*释放*/
					rt_sem_release( &sem_at );
					return RT_EOK;
				}
				rt_free( pmsg );                        /*释放*/
				/*计算剩下的超时时间,由于其他任务执行的延时,会溢出,要判断*/
				if( rt_tick_get( ) < tick_end )         /*还没有超时*/
				{
					tm = tick_end - rt_tick_get( );
				}else
				{
					flag_wait = 0;
				}
			}else /*已经超时*/
			{
				flag_wait = 0;
			}
		}
	}
	rt_sem_release( &sem_at );
	return ( -RT_ETIMEOUT );
}
Ejemplo n.º 8
0
/*
 * Waiting for bus not busy
 */
static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev,
					 char allow_sleep)
{
	unsigned long timeout;
	static rt_uint16_t to_cnt;

	timeout = rt_tick_get() + dev->bus->timeout;
	while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
	       & DAVINCI_I2C_STR_BB) {
		if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
			if (rt_tick_get() >= timeout) {
				rt_kprintf("timeout waiting for bus ready\n");
				to_cnt++;
				return -RT_ETIMEOUT;
			} else {
				to_cnt = 0;
				i2c_recover_bus(dev);
				i2c_davinci_init(dev);
			}
		}
		if (allow_sleep)
			rt_thread_delay(2);
	}

	return 0;
}
Ejemplo n.º 9
0
/**
 * This function will check timer list, if a timeout event happens, the
 * corresponding timeout function will be invoked.
 *
 */
void rt_soft_timer_check()
{
	rt_tick_t current_tick;
	rt_list_t *n;
	struct rt_timer *t;

#ifdef RT_TIMER_DEBUG
	rt_kprintf("software timer check enter\n");
#endif

	current_tick = rt_tick_get();

	for (n = rt_soft_timer_list.next; n != &(rt_soft_timer_list); )
	{
		t = rt_list_entry(n, struct rt_timer, list);
		
		/*
		 * It supposes that the new tick shall less than the half duration of tick max.
		 */
		if ((current_tick - t->timeout_tick) < RT_TICK_MAX/2)
		{
#ifdef RT_USING_HOOK
			if (rt_timer_timeout_hook != RT_NULL) rt_timer_timeout_hook(t);
#endif
			/* move node to the next */
			n = n->next;

			/* remove timer from timer list firstly */
			rt_list_remove(&(t->list));

			/* call timeout function */
			t->timeout_func(t->parameter);

			/* re-get tick */
			current_tick = rt_tick_get();

#ifdef RT_TIMER_DEBUG
			rt_kprintf("current tick: %d\n", current_tick);
#endif

			if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
					(t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
			{
				/* start it */
				t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
				rt_timer_start(t);
			}
			else
			{
				/* stop timer */
				t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
			}
		}
		else break; /* not check anymore */
	}

#ifdef RT_TIMER_DEBUG
	rt_kprintf("software timer check leave\n");
#endif
}
Ejemplo n.º 10
0
/**
 * This function will check timer list, if a timeout event happens, the
 * corresponding timeout function will be invoked.
 *
 * @note this function shall be invoked in operating system timer interrupt.
 */
void rt_timer_check(void)
{
    struct rt_timer *t;
    rt_tick_t current_tick;
    register rt_base_t level;

    RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check enter\n"));

    current_tick = rt_tick_get();

    /* disable interrupt */
    level = rt_hw_interrupt_disable();

    while (!rt_list_isempty(&rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1]))
    {
        t = rt_list_entry(rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next,
                          struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]);

        /*
         * It supposes that the new tick shall less than the half duration of
         * tick max.
         */
        if ((current_tick - t->timeout_tick) < RT_TICK_MAX/2)
        {
            RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));

            /* remove timer from timer list firstly */
            _rt_timer_remove(t);

            /* call timeout function */
            t->timeout_func(t->parameter);

            /* re-get tick */
            current_tick = rt_tick_get();

            RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));

            if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
                (t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
            {
                /* start it */
                t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
                rt_timer_start(t);
            }
            else
            {
                /* stop timer */
                t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
            }
        }
        else
            break;
    }

    /* enable interrupt */
    rt_hw_interrupt_enable(level);

    RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check leave\n"));
}
Ejemplo n.º 11
0
/***********************************************************
* Function:
* Description:
* Input:
* Input:
* Output:
* Return:
* Others:
***********************************************************/
rt_err_t gsm_send_wait_str_ok( char *AT_cmd_string,
                               uint32_t timeout,
                               char * respstr,
                               uint8_t no_of_attempts )
{
	rt_err_t		err;
	uint8_t			i = 0;
	char			*pmsg;
	uint32_t		tick_start, tick_end;
	uint32_t		tm;
	__IO uint8_t	flag_wait = 1;
	err = rt_sem_take( &sem_at, timeout );
	if( err != RT_EOK )
	{
		return err;
	}

	for( i = 0; i < no_of_attempts; i++ )
	{
		tick_start	= rt_tick_get( );
		tick_end	= tick_start + timeout;
		tm			= timeout;
		flag_wait	= 1;
		rt_kprintf( "%08d gsm>%s\r\n", tick_start, AT_cmd_string );
		m66_write( &dev_gsm, 0, AT_cmd_string, strlen( AT_cmd_string ) );
		while( flag_wait )
		{
			err = rt_mb_recv( &mb_gsmrx, (rt_uint32_t*)&pmsg, tm );
			if( err == RT_EOK )                                 /*没有超时,判断信息是否正确*/
			{
				if( strstr( pmsg + 2, respstr ) != RT_NULL )    /*找到了*/
				{
					rt_free( pmsg );                            /*释放*/
					goto lbl_send_wait_ok;
				}
				rt_free( pmsg );                                /*释放*/
				/*计算剩下的超时时间,由于其他任务执行的延时,会溢出,要判断*/
				if( rt_tick_get( ) < tick_end )                 /*还没有超时*/
				{
					tm = tick_end - rt_tick_get( );
				}else
				{
					flag_wait = 0;
				}
			}else /*已经超时*/
			{
				flag_wait = 0;
			}
		}
	}
	rt_sem_release( &sem_at );
	return -RT_ETIMEOUT;

lbl_send_wait_ok:
	err = gsm_wait_str( "OK", RT_TICK_PER_SECOND * 2 );
	rt_sem_release( &sem_at );
	return err;
}
Ejemplo n.º 12
0
/**
 * This function will check timer list, if a timeout event happens, the
 * corresponding timeout function will be invoked.
 */
void rt_soft_timer_check(void)
{
    rt_tick_t current_tick;
    rt_list_t *n;
    struct rt_timer *t;

    RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check enter\n"));

    current_tick = rt_tick_get();

    for (n = rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1].next;
         n != &(rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL-1]);)
    {
        t = rt_list_entry(n, struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL-1]);

        /*
         * It supposes that the new tick shall less than the half duration of
         * tick max.
         */
        if ((current_tick - t->timeout_tick) < RT_TICK_MAX / 2)
        {
            RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));

            /* move node to the next */
            n = n->next;

            /* remove timer from timer list firstly */
            _rt_timer_remove(t);

            /* call timeout function */
            t->timeout_func(t->parameter);

            /* re-get tick */
            current_tick = rt_tick_get();

            RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));

            if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
                (t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
            {
                /* start it */
                t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
                rt_timer_start(t);
            }
            else
            {
                /* stop timer */
                t->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
            }
        }
        else break; /* not check anymore */
    }

    RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n"));
}
Ejemplo n.º 13
0
/*gsm供电的处理纤程*/
static void rt_thread_gsm_power_on( void* parameter )
{
	rt_err_t	ret;
	int			i;
	AT_CMD_RESP at_init[] =
	{
		{ "",			   RESP_TYPE_STR,		  RT_NULL,	  "OK",			  RT_TICK_PER_SECOND * 5, 1	 },
		{ "",			   RESP_TYPE_STR,		  RT_NULL,	  "OK",			  RT_TICK_PER_SECOND * 5, 1	 },
		{ "ATE0\r\n",	   RESP_TYPE_STR,		  RT_NULL,	  "OK",			  RT_TICK_PER_SECOND * 5, 1	 },
		{ "ATV1\r\n",	   RESP_TYPE_STR,		  RT_NULL,	  "OK",			  RT_TICK_PER_SECOND * 5, 1	 },
		{ "AT%TSIM\r\n",   RESP_TYPE_STR_WITHOK,  RT_NULL,	  "%TSIM 1",	  RT_TICK_PER_SECOND * 2, 5	 },


		{ "AT+CMGF=0\r\n", RESP_TYPE_STR,		  RT_NULL,	  "OK",			  RT_TICK_PER_SECOND * 3, 3	 },
		{ "AT+CNMI=1,2\r\n",RESP_TYPE_STR,		  RT_NULL,	  "OK",			  RT_TICK_PER_SECOND * 3, 3	 },

		
		{ "AT+CPIN?\r\n",  RESP_TYPE_STR_WITHOK,  RT_NULL,	  "+CPIN: READY", RT_TICK_PER_SECOND * 2, 30 },
		
		{ "AT+CIMI\r\n",   RESP_TYPE_FUNC_WITHOK, resp_CIMI,  RT_NULL,		  RT_TICK_PER_SECOND * 2, 10 },
		{ "AT+CLIP=1\r\n", RESP_TYPE_STR,		  RT_NULL,	  "OK",			  RT_TICK_PER_SECOND * 2, 10 },
		{ "AT+CREG?\r\n",  RESP_TYPE_FUNC_WITHOK, resp_CGREG, RT_NULL,		  RT_TICK_PER_SECOND * 2, 30 },
	};

lbl_poweron_start:
	rt_kprintf( "%08d gsm_power_on>start\r\n", rt_tick_get( ) );

	GPIO_ResetBits( GSM_PWR_PORT, GSM_PWR_PIN );
	GPIO_ResetBits( GSM_TERMON_PORT, GSM_TERMON_PIN );
	rt_thread_delay( RT_TICK_PER_SECOND / 10 );
	GPIO_SetBits( GSM_TERMON_PORT, GSM_TERMON_PIN );
	GPIO_SetBits( GSM_PWR_PORT, GSM_PWR_PIN );

	for( i = 0; i < sizeof( at_init ) / sizeof( AT_CMD_RESP ); i++ )
	{
		if( gsm_send( at_init[i].atcmd, \
		              at_init[i].resp, \
		              at_init[i].compare_str, \
		              at_init[i].type, \
		              at_init[i].timeout, \
		              at_init[i].retry ) != RT_EOK )
		{
			/*todo 错误计数,通知显示*/
			rt_kprintf( "%08d stage=%d\r\n", rt_tick_get( ), i );
			goto lbl_poweron_start;
		}
	}

	rt_kprintf( "%08d gsm_power_on>end\r\n", rt_tick_get( ) );

	gsm_state = GSM_AT; /*当前出于AT状态,可以拨号,连接*/
}
Ejemplo n.º 14
0
static void _touch_session()
{
    touch_point_t tpd;
#ifdef RT_USING_RTGUI
    struct rtgui_event_mouse emouse;
#endif

    ft5406_read_touch(&tpd);

#ifdef RT_USING_RTGUI
    emouse.parent.sender = RT_NULL;
    emouse.wid = RT_NULL;

    emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
    emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN;
    emouse.x = tpd.TOUCH_X;
    emouse.y = tpd.TOUCH_Y;
    emouse.ts = rt_tick_get();
    emouse.id = emouse.ts;
    if (emouse.id == 0) emouse.id = 1;
    rtgui_server_post_event(&emouse.parent, sizeof(emouse));
#endif

    do
    {
        rt_thread_delay(RT_TICK_PER_SECOND / BSP_TOUCH_SAMPLE_HZ);
        if (ft5406_read_touch(&tpd) != 0)
            break;

#ifdef RT_USING_RTGUI
        emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
        emouse.x = tpd.TOUCH_X;
        emouse.y = tpd.TOUCH_Y;
        emouse.ts = rt_tick_get();
        rtgui_server_post_event(&emouse.parent, sizeof(emouse));
#endif
    }
    while (1);

#ifdef RT_USING_RTGUI
    /* Always send touch up event. */
    emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
    emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP;
    emouse.x = tpd.TOUCH_X;
    emouse.y = tpd.TOUCH_Y;
    emouse.ts = rt_tick_get();
    rtgui_server_post_event(&emouse.parent, sizeof(emouse));
#endif

    //} while (rt_sem_take(&_tp_sem, TOUCH_SLP_TIME) == RT_EOK);
}
Ejemplo n.º 15
0
mqtt_err_t mqtt_waitForDNS(uint32_t timeout)
{
	rt_tick_t ticks = timeout * RT_TICK_PER_SECOND/1000;
	ticks += rt_tick_get();

	while(!dnsDone){
		if(rt_tick_get() > ticks)
		{
			dnsDone = 0;
			return mqtt_timeout;
		}
	}
		dnsDone = 0;
		return mqtt_errSuccess;
}
Ejemplo n.º 16
0
//****************************防超时程序********************************
//函数定义: uint8_t AvoidTimeout(uint32_t TimeOfTimeout,uint32_t Period,uint8_t (*DetectCondition)())
//描    述:在TimeOfTimeout时间内,每Period时间检测一次DetectCondition()返回的值是否有效
//入口参数:TimeOfTimeout:防超时总时间(单位:systick)
//          Period       :每Period时间检测一次,即时间因子(单位:systick)
//          (*DetectCondition)():检测条件,等于ConditionValue则条件满足,检测结束,否则延时Period时间继续检测
//          ConditionValue      ;条件成立的值
//出口参数:0:在TimeOfTimeout时间内,检测到条件成立
//          1:在TimeOfTimeout时间内,没有检测到条件成立
//备    注:Editor:Armink 2012-03-09    Company: BXXJS
//**********************************************************************
uint8_t AvoidTimeout(uint32_t TimeOfTimeout,uint32_t Period,uint8_t (*DetectCondition)(),uint8_t ConditionValue)
{
	uint32_t LastTimeLocal, CurTimeLocal;
	uint8_t ConditionValueLocal;
	LastTimeLocal = rt_tick_get();
	CurTimeLocal  =  LastTimeLocal;
	while(CurTimeLocal - LastTimeLocal < TimeOfTimeout)
	{	 
		CurTimeLocal = rt_tick_get();
		ConditionValueLocal = DetectCondition();
		if (ConditionValueLocal == ConditionValue) return 0;
		rt_thread_delay(Period);
	}	
	return 1;
} 
Ejemplo n.º 17
0
static void _lg_fmtout(
        struct log_trace_session *session, const char *fmt, va_list argptr)
{
    /* 1 for ']' */
    static char _trace_buf[1+LOG_TRACE_BUFSZ];
    char *ptr;
    rt_size_t length;

    RT_ASSERT(session);
    RT_ASSERT(fmt);

    rt_snprintf(_trace_buf, sizeof(_trace_buf), "[%08x][", rt_tick_get());
    if (_traceout_device != RT_NULL)
    {
        rt_device_write(_traceout_device, -1, _trace_buf, 11);
        rt_device_write(_traceout_device, -1,
                session->id.name, _idname_len(session->id.num));
    }

    _trace_buf[0] = ']';
    ptr = &_trace_buf[1];
    length = rt_vsnprintf(ptr, LOG_TRACE_BUFSZ, fmt, argptr);

    if (length >= LOG_TRACE_BUFSZ)
        length = LOG_TRACE_BUFSZ - 1;

    if (_traceout_device != RT_NULL)
    {
        rt_device_write(_traceout_device, -1, _trace_buf, length + 1);
    }
}
Ejemplo n.º 18
0
/**
 * This function will start the timer
 *
 * @param timer the timer to be started
 *
 * @return the operation status, RT_EOK on OK, -RT_ERROR on error
 *
 */
rt_err_t rt_timer_start(rt_timer_t timer)
{
	struct rt_timer* t;
	register rt_base_t level;
	rt_list_t *n, *timer_list;

	/* timer check */
	RT_ASSERT(timer != RT_NULL);
	if (timer->parent.flag & RT_TIMER_FLAG_ACTIVATED) return -RT_ERROR;

#ifdef RT_USING_HOOK
	if (rt_object_take_hook != RT_NULL) rt_object_take_hook(&(timer->parent));
#endif

	/* disable interrupt */
	level = rt_hw_interrupt_disable();

	/* get timeout tick, the max timeout tick shall not great than RT_TICK_MAX/2 */
	RT_ASSERT(timer->init_tick < RT_TICK_MAX/2);
	timer->timeout_tick = rt_tick_get() + timer->init_tick;

#ifdef RT_USING_TIMER_SOFT
	if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
	{
		/* insert timer to soft timer list */
		timer_list = &rt_soft_timer_list;
	}
	else
#endif
	{
		/* insert timer to system timer list */
		timer_list = &rt_timer_list;
	}

	for (n = timer_list->next; n != timer_list; n = n->next)
	{
		t = rt_list_entry(n, struct rt_timer, list);
		
		/*
		 * It supposes that the new tick shall less than the half duration of tick max.
		 */
		if ((t->timeout_tick - timer->timeout_tick) < RT_TICK_MAX/2)
		{
			rt_list_insert_before(n, &(timer->list));
			break;
		}
	}
	/* no found suitable position in timer list */
	if (n == timer_list)
	{
		rt_list_insert_before(n, &(timer->list));
	}
		
	timer->parent.flag |= RT_TIMER_FLAG_ACTIVATED;

	/* enable interrupt */
	rt_hw_interrupt_enable(level);

	return -RT_EOK;
}
Ejemplo n.º 19
0
static void sleep_tick_adjust(uint32_t ms)
{
	uint32_t diff;

	diff = rt_tick_from_millisecond(ms);

	rt_tick_set(rt_tick_get() + diff);
	{
		struct rt_thread *thread;

		/* check time slice */
		thread = rt_thread_self();

		if (thread->remaining_tick <= diff)
		{
			/* change to initialized tick */
			thread->remaining_tick = thread->init_tick;

			/* yield */
			rt_thread_yield();
		}
		else
		{
			thread->remaining_tick -= diff;
		}

		/* check timer */
		rt_timer_check();
	}
}
Ejemplo n.º 20
0
/**
 * This function will start a rms task and put it to system ready queue
 */
rt_rms_t rt_rms_startup(rt_rms_t rms)
{
    /* rms check */
    RT_ASSERT(rms != RT_NULL);
    RT_ASSERT(rms->thread->stat == RT_RMS_INIT);

    /* set current priority to init priority */
    rms->thread->current_priority = rms->thread->init_priority;
#if RT_THREAD_PRIORITY_MAX > 32
    rms->thread->number = rms->thread->current_priority >> 3;
    rms->thread->number_mask = 1L << rms->thread->number;
    rms->thread->high_mask = 1L << (rms->thread->current_priority & 0x07);
#else
    rms->thread->number_mask = 1L << rms->thread->current_priority;
#endif

    /* change rms stat */
    rms->thread->stat = RT_RMS_SLEEP;
    rms->deadline = rt_tick_get() + rms->period;

    /* resume rms task */
    rt_rms_resume(rms);
    if(rt_rms_self() != RT_NULL)
    {
        /* do a scheduling */
        rt_schedule();
    }

    return RT_RMS_EOK;
}
Ejemplo n.º 21
0
int clock_settime (clockid_t clockid, const struct timespec *tp)
{
	int second;
	rt_tick_t tick;
	rt_device_t device;

	if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL)) {
		rt_set_errno(EINVAL);
		return -1;
	}

	/* get second */
	second = tp->tv_sec;
	/* get tick */
	tick = rt_tick_get();

	/* update timevalue */
	_timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK;
	_timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1;

	/* update for RTC device */
	device = rt_device_find("rtc");
	if (device != RT_NULL) {
		/* set realtime seconds */
		rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second);
	} else return -1;

	return 0;
}
Ejemplo n.º 22
0
static void show( void )
{
	pMenuItem->tick = rt_tick_get( );
	pos				= 0;
	scr_mode		= SCR_PHOTO_MENU;
	display( );
}
Ejemplo n.º 23
0
/* 线程入口 */
static void thread_entry(void* parameter)
{
	rt_err_t result;
	rt_tick_t tick;

	/* 获得当前的OS Tick */
	tick = rt_tick_get();

	/* 试图持有信号量,最大等待10个OS Tick后返回 */
	result = rt_sem_take(&sem, 10);
	if (result == -RT_ETIMEOUT)
	{
		/* 超时后判断是否刚好是10个OS Tick */
		if (rt_tick_get() - tick != 10)
		{
			tc_done(TC_STAT_FAILED);
			rt_sem_detach(&sem);
			return;
		}
		rt_kprintf("take semaphore timeout\n");
	}
	else
	{
		/* 因为没有其他地方是否信号量,所以不应该成功持有信号量,否则测试失败 */
		tc_done(TC_STAT_FAILED);
		rt_sem_detach(&sem);
		return;
	}

	/* 释放一次信号量 */
	rt_sem_release(&sem);

	/* 永久等待方式持有信号量 */
	result = rt_sem_take(&sem, RT_WAITING_FOREVER);
	if (result != RT_EOK)
	{
		/* 不成功则测试失败 */
		tc_done(TC_STAT_FAILED);
		rt_sem_detach(&sem);
		return;
	}

	/* 测试通过 */
	tc_done(TC_STAT_PASSED);
	/* 脱离信号量对象 */
	rt_sem_detach(&sem);
}
Ejemplo n.º 24
0
static void cpu_usage_idle_hook()
{
	rt_tick_t tick;
	rt_uint32_t count;
	volatile rt_uint32_t loop;

	if (total_count == 0)
	{
		loop = 0;

		/* get total count */
		rt_enter_critical();
		tick = rt_tick_get();
		while(rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
		{
			total_count ++;
			while (loop < CPU_USAGE_LOOP) loop ++;
		}
		rt_exit_critical();
	}

	count = 0;
	loop  = 0;
	/* get CPU usage */
	tick = rt_tick_get();
	while (rt_tick_get() - tick < CPU_USAGE_CALC_TICK)
	{
		count ++;
		while (loop < CPU_USAGE_LOOP) loop ++;
	}

	/* calculate major and minor */
	if (count < total_count)
	{
		count = total_count - count;
		cpu_usage_major = (count * 100) / total_count;
		cpu_usage_minor = ((count * 100) % total_count) * 100 / total_count;
	}
	else
	{
		total_count = count;

		/* no CPU usage */
		cpu_usage_major = 0;
		cpu_usage_minor = 0;
	}
}
Ejemplo n.º 25
0
void writespeed(const char* filename, int total_length, int block_size)
{
	int fd, index, length;
	char *buff_ptr;
	rt_tick_t tick;

	fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0);
	if (fd < 0) {
		rt_kprintf("open file:%s failed\n", filename);
		return;
	}

	buff_ptr = rt_malloc(block_size);
	if (buff_ptr == RT_NULL) {
		rt_kprintf("no memory\n");
		close(fd);

		return;
	}

	/* prepare write data */
	for (index = 0; index < block_size; index++) {
		buff_ptr[index] = index;
	}
	index = 0;

	/* get the beginning tick */
	tick = rt_tick_get();
	while (index < total_length / block_size) {
		length = write(fd, buff_ptr, block_size);
		if (length != block_size) {
			rt_kprintf("write failed\n");
			break;
		}

		index ++;
	}
	tick = rt_tick_get() - tick;

	/* close file and release memory */
	close(fd);
	rt_free(buff_ptr);

	/* calculate write speed */
	rt_kprintf("File write speed: %d byte/s\n", total_length / tick * RT_TICK_PER_SECOND);
}
Ejemplo n.º 26
0
static void timeout1(void* parameter)
{
    rt_tick_t timeout = 3000;
    rt_kprintf("periodic timer is timeout\n");
    
    rt_kprintf("the time set is %d\n", (rt_tick_get()-tick));
    tick = rt_tick_get();
    count ++;
   
    if (count >= 8)
    {
        rt_timer_control(timer1, RT_TIMER_CTRL_SET_ONESHOT, (void *)&timeout);
    
        rt_timer_control(timer1, RT_TIMER_CTRL_SET_TIME, (void *)&timeout);
        count = 0;
    }
}
Ejemplo n.º 27
0
void push_event_touch_begin(int x, int y)
{
    struct rtgui_event_mouse emouse;

    emouse_id = rt_tick_get();

    emouse.parent.sender = RT_NULL;
    emouse.wid = RT_NULL;

    emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
    emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN;
    emouse.x = x;
    emouse.y = y;
    emouse.ts = rt_tick_get();
    emouse.id = emouse_id;
    dbg_log(DBG_LOG, "[line]:%d down event id:%d x:%d y:%d\n", __LINE__, emouse.id, x, y);
    rtgui_server_post_event(&emouse.parent, sizeof(emouse));
}
Ejemplo n.º 28
0
int SensorManager::pollSensor(SensorBase *sensor, sensors_event_t *events, int number, int duration)
{
    rt_tick_t tick;
    int result, index;

    if (sensor == NULL) return -1;

    tick = rt_tick_get();
    for (index = 0; index < number; index ++)
    {
        result = sensor->poll(&events[index]);
        if (result < 0) break;

        if (rt_tick_get() - tick > duration) break;
    }

    return index;
}
Ejemplo n.º 29
0
static void show( void )
{
	pMenuItem->tick = rt_tick_get( );
	if(( menu_pos > 6 )||(menu_first_in & BIT(1)))
	{
		menu_pos = 0;
	}
	menu_first_in &=~(BIT(1));
	menuswitch( );
}
Ejemplo n.º 30
0
static int readspeed(int fd, char *buff_ptr, rt_size_t total_length ,int block_size)
{
    rt_tick_t tick;
	
    tick = rt_tick_get();
    total_length = 0;
    while (1)
    {
        int length;
        length = read(fd, buff_ptr, block_size);

        if (length <= 0) break;
        total_length += length;
    }
    tick = rt_tick_get() - tick;
	
    /* calculate read speed */
	return (total_length / tick * RT_TICK_PER_SECOND);
}