[Kernel] Add signal implementation.

1. Add signal implementation;
2. Change the 'rt_uint8_t' of cmd to 'int';
This commit is contained in:
bernard committed 2017-10-15 22:31:53 +08:00
1 parent cd215b2545
commit b27c7e4826
11 files changed
+479 -34

No files matched your search

+8 -1
View File
@@ -39,7 +39,7 @@ config RT_USING_OVERFLOW_CHECK
config RT_DEBUG_INIT
int "Enable system initialization informat print"
default 1
default 0
help
print the procedure name of initialization
@@ -100,6 +100,13 @@ config RT_USING_MESSAGEQUEUE
bool "Enable message queue"
default y
config RT_USING_SIGNALS
bool "Enable signals"
select RT_USING_MEMPOOL
default n
help
A signal is an asynchronous notification sent to a specific thread
in order to notify it of an event that occurred.
endmenu
menu "Memory Management"
+12 -2
View File
@@ -108,13 +108,23 @@ void rt_tick_increase(void)
* This function will calculate the tick from millisecond.
*
* @param ms the specified millisecond
* - Negative Number wait forever
* - Zero not wait
* - Max 0x7fffffff
*
* @return the calculated tick
*/
rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms)
int rt_tick_from_millisecond(rt_int32_t ms)
{
int tick;
if (ms < 0)
tick = RT_WAITING_FOREVER;
else
tick = (RT_TICK_PER_SECOND * ms + 999) / 1000;
/* return the calculated tick */
return (RT_TICK_PER_SECOND * ms + 999) / 1000;
return tick;
}
RTM_EXPORT(rt_tick_from_millisecond);
+5
View File
@@ -237,6 +237,11 @@ int rtthread_startup(void)
/* scheduler system initialization */
rt_system_scheduler_init();
#ifdef RT_USING_SIGNALS
/* signal system initialization */
rt_system_signal_init();
#endif
/* create init_thread */
rt_application_init();
+13 -3
View File
@@ -56,6 +56,11 @@ rt_err_t rt_device_register(rt_device_t dev,
dev->ref_count = 0;
dev->open_flag = 0;
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
dev->fops = RT_NULL;
rt_list_init(&(dev->wait_queue));
#endif
return RT_EOK;
}
RTM_EXPORT(rt_device_register);
@@ -213,11 +218,16 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
{
result = dev->open(dev, oflag);
}
else
{
/* set open flag */
dev->open_flag = (oflag & RT_DEVICE_OFLAG_MASK);
}
/* set open flag */
if (result == RT_EOK || result == -RT_ENOSYS)
{
dev->open_flag = oflag | RT_DEVICE_OFLAG_OPEN;
dev->open_flag |= RT_DEVICE_OFLAG_OPEN;
dev->ref_count++;
/* don't let bad things happen silently. If you are bitten by this assert,
@@ -349,7 +359,7 @@ RTM_EXPORT(rt_device_write);
*
* @return the result
*/
rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void *arg)
rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg)
{
RT_ASSERT(dev != RT_NULL);
@@ -359,7 +369,7 @@ rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void *arg)
return dev->control(dev, cmd, arg);
}
return RT_EOK;
return -RT_ENOSYS;
}
RTM_EXPORT(rt_device_control);
+4
View File
@@ -127,6 +127,10 @@ void rt_thread_idle_excute(void)
if (thread->cleanup != RT_NULL)
thread->cleanup(thread);
#ifdef RT_USING_SIGNALS
rt_thread_free_sig(thread);
#endif
/* if it's a system object, not delete it */
if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE)
{
+15 -13
View File
@@ -478,7 +478,7 @@ RTM_EXPORT(rt_sem_release);
*
* @return the error code
*/
rt_err_t rt_sem_control(rt_sem_t sem, rt_uint8_t cmd, void *arg)
rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg)
{
rt_ubase_t level;
RT_ASSERT(sem != RT_NULL);
@@ -644,14 +644,13 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
register rt_base_t temp;
struct rt_thread *thread;
/* this function must not be used in interrupt even if time = 0 */
RT_DEBUG_IN_THREAD_CONTEXT;
RT_ASSERT(mutex != RT_NULL);
/* get current thread */
thread = rt_thread_self();
if (!thread) return RT_EOK; /* return directory if scheduler not started */
/* this function must not be used in interrupt even if time = 0 */
RT_DEBUG_IN_THREAD_CONTEXT;
/* disable interrupt */
temp = rt_hw_interrupt_disable();
@@ -672,6 +671,7 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
}
else
{
__again:
/* The value of mutex is 1 in initial status. Therefore, if the
* value is great than 0, it indicates the mutex is avaible.
*/
@@ -740,6 +740,9 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
if (thread->error != RT_EOK)
{
/* interrupt by signal, try it again */
if (thread->error == -RT_EINTR) goto __again;
/* return error */
return thread->error;
}
@@ -778,13 +781,12 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
need_schedule = RT_FALSE;
/* get current thread */
thread = rt_thread_self();
if (!thread) return RT_EOK;
/* only thread could release mutex because we need test the ownership */
RT_DEBUG_IN_THREAD_CONTEXT;
/* get current thread */
thread = rt_thread_self();
/* disable interrupt */
temp = rt_hw_interrupt_disable();
@@ -870,7 +872,7 @@ RTM_EXPORT(rt_mutex_release);
*
* @return the error code
*/
rt_err_t rt_mutex_control(rt_mutex_t mutex, rt_uint8_t cmd, void *arg)
rt_err_t rt_mutex_control(rt_mutex_t mutex, int cmd, void *arg)
{
return -RT_ERROR;
}
@@ -1212,7 +1214,7 @@ RTM_EXPORT(rt_event_recv);
*
* @return the error code
*/
rt_err_t rt_event_control(rt_event_t event, rt_uint8_t cmd, void *arg)
rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg)
{
rt_ubase_t level;
RT_ASSERT(event != RT_NULL);
@@ -1687,7 +1689,7 @@ RTM_EXPORT(rt_mb_recv);
*
* @return the error code
*/
rt_err_t rt_mb_control(rt_mailbox_t mb, rt_uint8_t cmd, void *arg)
rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg)
{
rt_ubase_t level;
RT_ASSERT(mb != RT_NULL);
@@ -2235,7 +2237,7 @@ RTM_EXPORT(rt_mq_recv);
*
* @return the error code
*/
rt_err_t rt_mq_control(rt_mq_t mq, rt_uint8_t cmd, void *arg)
rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg)
{
rt_ubase_t level;
struct rt_mq_message *msg;
+3 -1
View File
@@ -1114,6 +1114,8 @@ RTM_EXPORT(rt_hw_console_output);
*/
void rt_kputs(const char *str)
{
if (!str) return;
#ifdef RT_USING_DEVICE
if (_console_device == RT_NULL)
{
@@ -1265,7 +1267,7 @@ const rt_uint8_t __lowest_bit_bitmap[] =
* @return return the index of the first bit set. If value is 0, then this function
* shall return 0.
*/
rt_ubase_t __rt_ffs(rt_ubase_t value)
int __rt_ffs(int value)
{
if (value == 0) return 0;
+17 -4
View File
@@ -42,7 +42,6 @@
static rt_int16_t rt_scheduler_lock_nest;
extern volatile rt_uint8_t rt_interrupt_nest;
extern rt_ubase_t __rt_ffs(rt_ubase_t value);
rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
struct rt_thread *rt_current_thread;
@@ -241,8 +240,18 @@ void rt_schedule(void)
if (rt_interrupt_nest == 0)
{
extern void rt_thread_handle_sig(rt_bool_t clean_state);
rt_hw_context_switch((rt_uint32_t)&from_thread->sp,
(rt_uint32_t)&to_thread->sp);
/* enable interrupt */
rt_hw_interrupt_enable(level);
#ifdef RT_USING_SIGNALS
/* check signal status */
rt_thread_handle_sig(RT_TRUE);
#endif
}
else
{
@@ -250,12 +259,16 @@ void rt_schedule(void)
rt_hw_context_switch_interrupt((rt_uint32_t)&from_thread->sp,
(rt_uint32_t)&to_thread->sp);
/* enable interrupt */
rt_hw_interrupt_enable(level);
}
}
else
{
/* enable interrupt */
rt_hw_interrupt_enable(level);
}
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
}
/*
+382
View File
File diff suppressed because it is too large. Load diff
+19 -9
View File
@@ -185,6 +185,16 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
0,
RT_TIMER_FLAG_ONE_SHOT);
/* initialize signal */
#ifdef RT_USING_SIGNALS
thread->sig_mask = 0x00;
thread->sig_pending = 0x00;
thread->sig_ret = RT_NULL;
thread->sig_vectors = RT_NULL;
thread->si_list = RT_NULL;
#endif
RT_OBJECT_HOOK_CALL(rt_thread_inited_hook, (thread));
return RT_EOK;
@@ -260,7 +270,7 @@ rt_err_t rt_thread_startup(rt_thread_t thread)
{
/* thread check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(thread->stat == RT_THREAD_INIT);
RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_INIT);
/* set current priority to init priority */
thread->current_priority = thread->init_priority;
@@ -305,7 +315,7 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
/* thread check */
RT_ASSERT(thread != RT_NULL);
if (thread->stat != RT_THREAD_INIT)
if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT)
{
/* remove from schedule */
rt_schedule_remove_thread(thread);
@@ -403,7 +413,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread)
/* thread check */
RT_ASSERT(thread != RT_NULL);
if (thread->stat != RT_THREAD_INIT)
if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_INIT)
{
/* remove from schedule */
rt_schedule_remove_thread(thread);
@@ -448,7 +458,7 @@ rt_err_t rt_thread_yield(void)
thread = rt_current_thread;
/* if the thread stat is READY and on ready queue list */
if (thread->stat == RT_THREAD_READY &&
if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_READY &&
thread->tlist.next != thread->tlist.prev)
{
/* remove thread from thread list */
@@ -535,7 +545,7 @@ RTM_EXPORT(rt_thread_delay);
*
* @return RT_EOK
*/
rt_err_t rt_thread_control(rt_thread_t thread, rt_uint8_t cmd, void *arg)
rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
{
register rt_base_t temp;
@@ -549,7 +559,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, rt_uint8_t cmd, void *arg)
temp = rt_hw_interrupt_disable();
/* for ready thread, change queue */
if (thread->stat == RT_THREAD_READY)
if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_READY)
{
/* remove thread from schedule queue first */
rt_schedule_remove_thread(thread);
@@ -622,7 +632,7 @@ rt_err_t rt_thread_suspend(rt_thread_t thread)
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: %s\n", thread->name));
if (thread->stat != RT_THREAD_READY)
if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_READY)
{
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread suspend: thread disorder, %d\n",
thread->stat));
@@ -664,7 +674,7 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread resume: %s\n", thread->name));
if (thread->stat != RT_THREAD_SUSPEND)
if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_SUSPEND)
{
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread resume: thread disorder, %d\n",
thread->stat));
@@ -705,7 +715,7 @@ void rt_thread_timeout(void *parameter)
/* thread check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(thread->stat == RT_THREAD_SUSPEND);
RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND);
/* set error number */
thread->error = -RT_ETIMEOUT;
+1 -1
View File
@@ -451,7 +451,7 @@ RTM_EXPORT(rt_timer_stop);
*
* @return RT_EOK
*/
rt_err_t rt_timer_control(rt_timer_t timer, rt_uint8_t cmd, void *arg)
rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
{
/* timer check */
RT_ASSERT(timer != RT_NULL);