From cfd580edf472f4a596434f27c398ac74712ab169 Mon Sep 17 00:00:00 2001 From: "bernard.xiong@gmail.com" Date: Wed, 29 Jun 2011 14:45:35 +0000 Subject: [PATCH] add rt_tick_set function git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1551 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- include/rtthread.h | 1 + src/clock.c | 15 +++++++++++++++ src/kservice.c | 13 +++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/rtthread.h b/include/rtthread.h index ea7806599f..c3bc0516b5 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -63,6 +63,7 @@ void rt_object_put_sethook(void (*hook)(struct rt_object* object)); */ void rt_system_tick_init(void); rt_tick_t rt_tick_get(void); +void rt_tick_set(rt_tick_t tick); void rt_tick_increase(void); rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms); diff --git a/src/clock.c b/src/clock.c index 9203fc57ed..f23ddc3279 100644 --- a/src/clock.c +++ b/src/clock.c @@ -15,8 +15,10 @@ * 2010-03-08 Bernard remove rt_passed_second * 2010-05-20 Bernard fix the tick exceeds the maximum limits * 2010-07-13 Bernard fix rt_tick_from_millisecond issue found by kuronca + * 2011-06-26 Bernard add rt_tick_set function. */ +#include #include static rt_tick_t rt_tick; @@ -51,6 +53,19 @@ rt_tick_t rt_tick_get() return rt_tick; } +/** + * This function will set current tick + */ +void rt_tick_set(rt_tick_t tick) +{ + rt_base_t level; + level = rt_hw_interrupt_disable(); + + rt_tick = tick; + + rt_hw_interrupt_enable(level); +} + /** * This function will notify kernel there is one tick passed. Normally, * this function is invoked by clock ISR. diff --git a/src/kservice.c b/src/kservice.c index 295a917842..10d2807082 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -44,7 +44,11 @@ rt_err_t rt_get_errno(void) { rt_thread_t tid; - RT_DEBUG_NOT_IN_INTERRUPT; + if(rt_interrupt_get_nest() != 0) + { + /* it's in interrupt context */ + return errno; + } tid = rt_thread_self(); if (tid == RT_NULL) return errno; @@ -61,7 +65,12 @@ void rt_set_errno(rt_err_t error) { rt_thread_t tid; - RT_DEBUG_NOT_IN_INTERRUPT; + if(rt_interrupt_get_nest() != 0) + { + /* it's in interrupt context */ + errno = error; + return; + } tid = rt_thread_self(); if (tid == RT_NULL) { errno = error; return; }