Esempio n. 1
0
void rt_rms_exit(void)
{
    struct rt_rms *rms;
    register rt_base_t level;

    /* get current rms */
    rms = rt_current_rms;

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

    /* remove from schedule */
    rt_schedule_remove_rms(rms);
    /* change stat */
    rms->thread->stat = RT_RMS_CLOSE;

    /* remove it from timer list */
    rt_timer_detach(&rms->rms_timer);
    rt_timer_detach(&rms->thread->thread_timer);
    if(rt_object_is_systemobject((rt_object_t)rms->thread) == RT_TRUE)
    {
        rt_object_detach((rt_object_t)rms->thread);
    }
    rt_list_remove(&(rms->thread->tlist));
    rt_list_remove(&(rms->rlist));
    /* enable interrupt */
    rt_hw_interrupt_enable(level);

    /* switch to next task */
    rt_schedule();
}
Esempio n. 2
0
/*
 * can interrupt routines
 */
rt_inline int _can_int_rx(struct rt_can_device *can, struct rt_can_msg *data, int msgs)
{
    int size;
    struct rt_can_rx_fifo* rx_fifo;

    RT_ASSERT(can != RT_NULL);
    size = msgs; 
    
    rx_fifo = (struct rt_can_rx_fifo*) can->can_rx;
    RT_ASSERT(rx_fifo != RT_NULL);

    /* read from software FIFO */
    while (msgs)
    {
        rt_base_t level;
        struct rt_can_msg_list *listmsg=RT_NULL;
        /* disable interrupt */
        level = rt_hw_interrupt_disable();
#ifdef RT_CAN_USING_HDR
        rt_int32_t hdr = data->hdr;
        if (hdr >=0 && can->hdr && hdr < can->config.maxhdr && !rt_list_isempty(&can->hdr[hdr].list))
        {
             listmsg=rt_list_entry(can->hdr[hdr].list.next, struct rt_can_msg_list, hdrlist);
             rt_list_remove(&listmsg->list);
             rt_list_remove(&listmsg->hdrlist);
             if(can->hdr[hdr].msgs) {
               can->hdr[hdr].msgs--;                     
             }
             listmsg->owner = RT_NULL;
        } else if(hdr == -1)
Esempio n. 3
0
/**
 * This task will delete the rms task
 */
rt_err_t rt_rms_delete(rt_rms_t rms)
{

    RT_ASSERT(rms != RT_NULL);

    rt_timer_detach(&rms->thread->thread_timer);
    rt_timer_detach(&rms->rms_timer);

    rms->thread->stat = RT_RMS_CLOSE;
    rt_object_detach((rt_object_t)rms->thread);
    rt_list_remove(&(rms->thread->tlist));
    rt_list_remove(&(rms->rlist));

    return RT_RMS_EOK;
}
Esempio n. 4
0
static void rt_thread_exit(void)
{
	struct rt_thread *thread;
	register rt_base_t level;

	/* get current thread */
	thread = rt_current_thread;

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

	/* remove from schedule */
	rt_schedule_remove_thread(thread);
	/* change stat */
	thread->stat = RT_THREAD_CLOSE;

	/* remove it from timer list */
	rt_list_remove(&(thread->thread_timer.list));
	rt_object_detach((rt_object_t)&(thread->thread_timer));

	if ((rt_object_is_systemobject((rt_object_t)thread) == RT_EOK) &&
		thread->cleanup == RT_NULL) {
		rt_object_detach((rt_object_t)thread);
	} else {
		/* insert to defunct thread list */
		rt_list_insert_after(&rt_thread_defunct, &(thread->tlist));
	}

	/* enable interrupt */
	rt_hw_interrupt_enable(level);

	/* switch to next task */
	rt_schedule();
}
Esempio n. 5
0
/**
 * This function will remove a rms task from system ready queue.
 */
void rt_schedule_remove_rms(struct rt_rms *rms)
{
    register rt_base_t temp;

    RT_ASSERT(rms != RT_NULL);

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

    /* remove thread from ready list */
    rt_list_remove(&(rms->rlist));
    if(rt_list_isempty(&(rt_thread_priority_table[rms->thread->current_priority])))
    {
#if RT_THREAD_PRIORITY_MAX > 32
        rt_thread_ready_table[rms->thread->number] &= ~rms->thread->high_mask;
        if(rt_thread_ready_table[rms->thread->number] == 0)
        {
            rt_thread_ready_priority_group &= ~rms->thread->number_mask;
        }
#else
        rt_thread_ready_priority_group &= ~rms->thread->number_mask;
#endif
    }

    /* enable interrupt */
    rt_hw_interrupt_enable(temp);
}
Esempio n. 6
0
/**
 * This function will stop the timer
 *
 * @param timer the timer to be stopped
 *
 * @return the operation status, RT_EOK on OK, -RT_ERROR on error
 *
 */
rt_err_t rt_timer_stop(rt_timer_t timer)
{
	register rt_base_t level;

	/* 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_put_hook != RT_NULL) rt_object_put_hook(&(timer->parent));
#endif

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

	/* change stat */
	timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;

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

	/* enable interrupt */
	rt_hw_interrupt_enable(level);

	return RT_EOK;
}
Esempio n. 7
0
/**
 * This function will let current thread yield processor, and scheduler will
 * choose a highest thread to run. After yield processor, the current thread
 * is still in READY state.
 *
 * @return RT_EOK
 *
 */
rt_err_t rt_thread_yield(void)
{
	register rt_base_t level;
	struct rt_thread *thread;

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

	/* set to current thread */
	thread = rt_current_thread;

	/* if the thread stat is READY and on ready queue list */
	if (thread->stat == RT_THREAD_READY && thread->tlist.next != thread->tlist.prev)
	{
		/* remove thread from thread list */
		rt_list_remove(&(thread->tlist));

		/* put thread to end of ready queue */
		rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
			&(thread->tlist));

		/* enable interrupt */
		rt_hw_interrupt_enable(level);

		rt_schedule();

		return RT_EOK;
	}

	/* enable interrupt */
	rt_hw_interrupt_enable(level);

	return RT_EOK;
}
Esempio n. 8
0
static void rt_thread_idle_entry(void* parameter)
{
	while (1)
	{
#ifdef RT_USING_HOOK
		/* if there is an idle thread hook */
		if (rt_thread_idle_hook != RT_NULL) rt_thread_idle_hook();
#endif

#ifdef RT_USING_HEAP
		/* check the defunct thread list */
		if (!rt_list_isempty(&rt_thread_defunct))
		{
			rt_base_t lock;

			struct rt_thread* thread = rt_list_entry(rt_thread_defunct.next, struct rt_thread, tlist);

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

			rt_list_remove(&(thread->tlist));

			/* enable interrupt */
			rt_hw_interrupt_enable(lock);

			/* release thread's stack */
			rt_free(thread->stack_addr);

			/* delete thread object */
			rt_object_delete((rt_object_t)thread);
		}
#endif
	}
Esempio 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
}
Esempio n. 10
0
/**
 * This function will delete an object and release object memory.
 *
 * @param object the specified object to be deleted.
 */
void rt_object_delete(rt_object_t object)
{
	register rt_base_t temp;

	/* object check */
	RT_ASSERT(object != RT_NULL);
	RT_ASSERT(!(object->type & RT_Object_Class_Static));

	RT_OBJECT_HOOK_CALL(rt_object_detach_hook, (object));

	/* lock interrupt */
	temp = rt_hw_interrupt_disable();

	/* remove from old list */
	rt_list_remove(&(object->list));

	/* unlock interrupt */
	rt_hw_interrupt_enable(temp);

#if defined(RT_USING_MODULE) && defined(RT_USING_SLAB)
	if (object->flag & RT_OBJECT_FLAG_MODULE) 
		rt_module_free((rt_module_t)object->module_id, object);
	else
#endif

	/* free the memory of object */
	rt_free(object);
}
Esempio n. 11
0
rt_inline void _rt_timer_remove(rt_timer_t timer)
{
    int i;

    for (i = 0; i < RT_TIMER_SKIP_LIST_LEVEL; i++)
    {
        rt_list_remove(&timer->row[i]);
    }
}
Esempio 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.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)
		{
			RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));

			/* 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();

			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"));
}
Esempio n. 13
0
/**
 * RM Scheduling clock ISR
 */
void rt_rms_wakeup(void *parameter)
{
    register struct rt_rms *rms;
    rt_int8_t count = 0;
    rt_tick_t tick = 0;
    rt_ubase_t priority = (rt_ubase_t)parameter;

    tick = rt_tick_get();
    /* awake idle tasks */
    rms = rt_list_entry(rt_rms_idle_table[priority].next, struct rt_rms, rlist);
    if(rms != RT_NULL && rms->deadline <= tick && rms->thread->stat == RT_RMS_IDLE)
    {

        rms->deadline += rms->period;
        rms->thread->stat = RT_RMS_READY;

        rt_list_remove(&(rt_rms_idle_table[priority]));

        rt_schedule_insert_rms(rms);

        count++;
    }

    rms = rt_list_entry(rt_rms_zombie_table[priority].next, struct rt_rms, rlist);
    /* remove all zombie tasks for which their deadline is expired */
    if(rms != RT_NULL && rms->deadline <= tick && rms->thread->stat == RT_RMS_ZOMBIE)
    {
        utilization -= rms->utilization;
        rms->thread->stat = RT_RMS_CLOSE;
        rt_list_remove(&(rt_rms_zombie_table[priority]));
        rt_rms_delete(rms);
        count ++;
    }

    /* if at least a task has been awakened, call the scheduler */
    if(count > 0)
    {
        rt_schedule();
    }
}
Esempio n. 14
0
/**
 * @ingroup Thread
 *
 * This function will perform system background job when system idle.
 */
void rt_thread_idle_excute(void)
{
    /* check the defunct thread list */
    if (!rt_list_isempty(&rt_thread_defunct))
    {
        rt_base_t lock;
        rt_thread_t thread;
#ifdef RT_USING_MODULE
        rt_module_t module = RT_NULL;
#endif
        RT_DEBUG_NOT_IN_INTERRUPT;

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

        /* re-check whether list is empty */
        if (!rt_list_isempty(&rt_thread_defunct))
        {
            /* get defunct thread */
            thread = rt_list_entry(rt_thread_defunct.next,
                                   struct rt_thread,
                                   tlist);
#ifdef RT_USING_MODULE
            /* get thread's parent module */
            module = (rt_module_t)thread->module_id;

            /* if the thread is module's main thread */
            if (module != RT_NULL && module->module_thread == thread)
            {
                /* detach module's main thread */
                module->module_thread = RT_NULL;
            }
#endif
            /* remove defunct thread */
            rt_list_remove(&(thread->tlist));
            /* invoke thread cleanup */
            if (thread->cleanup != RT_NULL)
                thread->cleanup(thread);

            /* if it's a system object, not delete it */
            if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE)
            {
                /* enable interrupt */
                rt_hw_interrupt_enable(lock);

                return;
            }
        }
Esempio n. 15
0
File: mq.c Progetto: amsl/RTGUI_NoOS
rt_err_t rt_mq_delete (rt_mq_t *mq)
{
	/* parameter check */
	RT_ASSERT(mq != RT_NULL);

	/* remove from list */
	rt_list_remove(&(mq->list));

	/* free mailbox pool */
	rt_free(mq->msg_pool);

	/* delete mailbox object */
	rt_free(mq);

	return RT_EOK;
}
Esempio n. 16
0
/**
 * This function will resume a rms task and put it into ready queue
 */
rt_err_t rt_rms_resume(rt_rms_t rms)
{
    register rt_base_t temp;

    /* rms check */
    RT_ASSERT(rms != RT_NULL);

    temp = rt_hw_interrupt_disable();

    rt_list_remove(&(rms->rlist));
    rt_timer_stop(&rms->thread->thread_timer);
    rt_hw_interrupt_enable(temp);

    rt_schedule_insert_rms(rms);

    return RT_RMS_EOK;
}
Esempio n. 17
0
rt_err_t rt_mq_detach(rt_mq_t mq)
{
	/* parameter check */
	RT_ASSERT(mq != RT_NULL);

	SDL_DestroySemaphore(hmq->msg);
	SDL_DestroySemaphore(hmq->mutex);
	
	free(mq->host_mq);
	mq->host_mq = NULL;

	/* remove from list */
	SDL_mutexP(_mq_list_mutex);
	rt_list_remove(&(mq->list));
	SDL_mutexV(_mq_list_mutex);

	return RT_EOK;
}
Esempio n. 18
0
/**
 * This function will detach a static object from object system,
 * and the memory of static object is not freed.
 *
 * @param object the specified object to be detached.
 */
void rt_object_detach(rt_object_t object)
{
	register rt_base_t temp;

	/* object check */
	RT_ASSERT(object != RT_NULL);

	RT_OBJECT_HOOK_CALL(rt_object_detach_hook, (object));

	/* lock interrupt */
	temp = rt_hw_interrupt_disable();

	/* remove from old list */
	rt_list_remove(&(object->list));

	/* unlock interrupt */
	rt_hw_interrupt_enable(temp);
}
Esempio n. 19
0
/**
 * This function will detach a static object from object system,
 * and the memory of static object is not freed.
 *
 * @param object the specified object to be detached.
 */
void rt_object_detach(rt_object_t object)
{
	register rt_base_t temp;

	/* object check */
	RT_ASSERT(object != RT_NULL);

#ifdef RT_USING_HOOK
	if (rt_object_detach_hook != RT_NULL) rt_object_detach_hook(object);
#endif

	/* lock interrupt */
	temp = rt_hw_interrupt_disable();

	/* remove from old list */
	rt_list_remove(&(object->list));

	/* unlock interrupt */
	rt_hw_interrupt_enable(temp);
}
Esempio n. 20
0
/**
 * This function will delete a timer and release timer memory
 *
 * @param timer the timer to be deleted
 *
 * @return the operation status, RT_EOK on OK; RT_ERROR on error
 *
 */
rt_err_t rt_timer_delete(rt_timer_t timer)
{
	register rt_base_t level;

	/* timer check */
	RT_ASSERT(timer != RT_NULL);

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

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

	/* enable interrupt */
	rt_hw_interrupt_enable(level);

	rt_object_delete((rt_object_t)timer);

	return -RT_EOK;
}
Esempio n. 21
0
/*
 * This function will remove a thread from system ready queue.
 *
 * @param thread the thread to be removed
 *
 * @note Please do not invoke this function in user application.
 */
void rt_schedule_remove_thread(struct rt_thread *thread)
{
    register rt_base_t temp;

    RT_ASSERT(thread != RT_NULL);

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

#if RT_THREAD_PRIORITY_MAX <= 32
    RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("remove thread[%.*s], the priority: %d\n",
                                      RT_NAME_MAX, thread->name,
                                      thread->current_priority));
#else
    RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
                 ("remove thread[%.*s], the priority: %d 0x%x %d\n",
                  RT_NAME_MAX,
                  thread->name,
                  thread->number,
                  thread->number_mask,
                  thread->high_mask));
#endif

    /* remove thread from ready list */
    rt_list_remove(&(thread->tlist));
    if (rt_list_isempty(&(rt_thread_priority_table[thread->current_priority])))
    {
#if RT_THREAD_PRIORITY_MAX > 32
        rt_thread_ready_table[thread->number] &= ~thread->high_mask;
        if (rt_thread_ready_table[thread->number] == 0)
        {
            rt_thread_ready_priority_group &= ~thread->number_mask;
        }
#else
        rt_thread_ready_priority_group &= ~thread->number_mask;
#endif
    }

    /* enable interrupt */
    rt_hw_interrupt_enable(temp);
}
Esempio n. 22
0
/**
 * This function will delete an object and release object memory.
 *
 * @param object the specified object to be deleted.
 */
void rt_object_delete(rt_object_t object)
{
	register rt_base_t temp;

	/* object check */
	RT_ASSERT(object != RT_NULL);
	RT_ASSERT(!(object->type & RT_Object_Class_Static));

#ifdef RT_USING_HOOK
	if (rt_object_detach_hook != RT_NULL) rt_object_detach_hook(object);
#endif

	/* lock interrupt */
	temp = rt_hw_interrupt_disable();

	/* remove from old list */
	rt_list_remove(&(object->list));

	/* unlock interrupt */
	rt_hw_interrupt_enable(temp);

	/* free the memory of object */
	rt_free(object);
}
Esempio n. 23
0
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))
	{
		t = rt_list_entry(rt_timer_list.next, 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)
		{
			RT_OBJECT_HOOK_CALL(rt_timer_timeout_hook, (t));

			/* 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();

			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);

	/* increase soft timer tick */
#ifdef RT_USING_TIMER_SOFT
	rt_soft_timer_tick_increase();
#endif

	RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check leave\n"));
}