diff options
| author | Arda <[email protected]> | 2014-11-24 11:57:31 +0800 |
|---|---|---|
| committer | Arda <[email protected]> | 2014-11-24 11:57:31 +0800 |
| commit | 143d3b82244b977735649e7d7c201d2affe67460 (patch) | |
| tree | 61503d3a150cef8d8184c858efc139b146b50cf6 /src | |
| parent | bc2a890ab08d163ccea323f7e719c4fdf53050cd (diff) | |
| parent | 9ecd18411fc1344e3d080d844b60c7070c3fb4d8 (diff) | |
Merge pull request #2 from RT-Thread/master
update from official source
Diffstat (limited to 'src')
| -rw-r--r-- | src/device.c | 6 | ||||
| -rw-r--r-- | src/idle.c | 32 | ||||
| -rw-r--r-- | src/kservice.c | 2 | ||||
| -rw-r--r-- | src/mem.c | 6 | ||||
| -rw-r--r-- | src/mempool.c | 97 | ||||
| -rw-r--r-- | src/module.c | 4 | ||||
| -rw-r--r-- | src/module.h | 2 | ||||
| -rw-r--r-- | src/object.c | 65 | ||||
| -rw-r--r-- | src/timer.c | 2 |
9 files changed, 140 insertions, 76 deletions
diff --git a/src/device.c b/src/device.c index 2bb3cc0f9c..957c9fc774 100644 --- a/src/device.c +++ b/src/device.c @@ -80,7 +80,7 @@ RTM_EXPORT(rt_device_unregister); * * @return the error code, RT_EOK on successfully. * - * @deprecated This function is not needed because the initialization + * @deprecated since 1.2.x, this function is not needed because the initialization * of a device is performed when applicaiton opens it. */ rt_err_t rt_device_init_all(void) @@ -362,8 +362,8 @@ rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void *arg) RTM_EXPORT(rt_device_control); /** - * This function will set the indication callback function when device receives - * data. + * This function will set the reception indication callback function. This callback function + * is invoked when this device receives data. * * @param dev the pointer of device driver structure * @param rx_ind the indication callback function diff --git a/src/idle.c b/src/idle.c index 7bca6c28cb..867af87612 100644 --- a/src/idle.c +++ b/src/idle.c @@ -44,16 +44,12 @@ static rt_uint8_t rt_thread_stack[IDLE_THREAD_STACK_SIZE]; extern rt_list_t rt_thread_defunct; #ifdef RT_USING_HOOK -/** - * @addtogroup Hook - */ - -/*@{*/ - static void (*rt_thread_idle_hook)(); /** - * This function will set a hook function to idle thread loop. + * @ingroup Hook + * This function sets a hook function to idle thread loop. When the system performs + * idle loop, this hook function should be invoked. * * @param hook the specified hook function * @@ -63,10 +59,22 @@ void rt_thread_idle_sethook(void (*hook)(void)) { rt_thread_idle_hook = hook; } - -/*@}*/ #endif +/* Return whether there is defunctional thread to be deleted. */ +rt_inline int _has_defunct_thread(void) +{ + /* The rt_list_isempty has prototype of "int rt_list_isempty(const rt_list_t *l)". + * So the compiler has a good reason that the rt_thread_defunct list does + * not change within rt_thread_idle_excute thus optimize the "while" loop + * into a "if". + * + * So add the volatile qualifier here. */ + const volatile rt_list_t *l = (const volatile rt_list_t*)&rt_thread_defunct; + + return l->next != l; +} + /** * @ingroup Thread * @@ -76,7 +84,7 @@ void rt_thread_idle_excute(void) { /* Loop until there is no dead thread. So one call to rt_thread_idle_excute * will do all the cleanups. */ - while (!rt_list_isempty(&rt_thread_defunct)) + while (_has_defunct_thread()) { rt_base_t lock; rt_thread_t thread; @@ -89,7 +97,7 @@ void rt_thread_idle_excute(void) lock = rt_hw_interrupt_disable(); /* re-check whether list is empty */ - if (!rt_list_isempty(&rt_thread_defunct)) + if (_has_defunct_thread()) { /* get defunct thread */ thread = rt_list_entry(rt_thread_defunct.next, @@ -180,7 +188,7 @@ static void rt_thread_idle_entry(void *parameter) } /** - * @ingroup SymstemInit + * @ingroup SystemInit * * This function will initialize idle thread, then start it. * diff --git a/src/kservice.c b/src/kservice.c index cb0064f38b..12878e67d1 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -1073,7 +1073,7 @@ rt_device_t rt_console_set_device(const char *name) /* set new console device */ _console_device = new; - rt_device_open(_console_device, RT_DEVICE_OFLAG_RDWR); + rt_device_open(_console_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM); } return old; @@ -176,10 +176,10 @@ static void plug_holes(struct heap_mem *mem) /** * @ingroup SystemInit * - * This function will init system heap + * This function will initialize system heap memory. * - * @param begin_addr the beginning address of system page - * @param end_addr the end address of system page + * @param begin_addr the beginning address of system heap memory. + * @param end_addr the end address of system heap memory. */ void rt_system_heap_init(void *begin_addr, void *end_addr) { diff --git a/src/mempool.c b/src/mempool.c index 05904bfbc7..b6d83597bf 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -323,23 +323,15 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time) rt_uint8_t *block_ptr; register rt_base_t level; struct rt_thread *thread; + rt_uint32_t before_sleep = 0; + + /* get current thread */ + thread = rt_thread_self(); /* disable interrupt */ level = rt_hw_interrupt_disable(); - if (mp->block_free_count) - { - /* memory block is available. decrease the free block counter */ - mp->block_free_count --; - - /* get block from block list */ - block_ptr = mp->block_list; - mp->block_list = *(rt_uint8_t **)block_ptr; - - /* point to memory pool */ - *(rt_uint8_t **)block_ptr = (rt_uint8_t *)mp; - } - else + while (mp->block_free_count == 0) { /* memory block is unavailable. */ if (time == 0) @@ -347,55 +339,64 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time) /* enable interrupt */ rt_hw_interrupt_enable(level); + rt_set_errno(-RT_ETIMEOUT); + return RT_NULL; } - else - { - RT_DEBUG_NOT_IN_INTERRUPT; - - /* get current thread */ - thread = rt_thread_self(); - - thread->error = RT_EOK; - /* need suspend thread */ - rt_thread_suspend(thread); - rt_list_insert_after(&(mp->suspend_thread), &(thread->tlist)); - mp->suspend_thread_count ++; + RT_DEBUG_NOT_IN_INTERRUPT; - if (time > 0) - { - /* init thread timer and start it */ - rt_timer_control(&(thread->thread_timer), - RT_TIMER_CTRL_SET_TIME, - &time); - rt_timer_start(&(thread->thread_timer)); - } + thread->error = RT_EOK; - /* enable interrupt */ - rt_hw_interrupt_enable(level); + /* need suspend thread */ + rt_thread_suspend(thread); + rt_list_insert_after(&(mp->suspend_thread), &(thread->tlist)); + mp->suspend_thread_count++; - /* do a schedule */ - rt_schedule(); + if (time > 0) + { + /* get the start tick of timer */ + before_sleep = rt_tick_get(); - if (thread->error != RT_EOK) - return RT_NULL; + /* init thread timer and start it */ + rt_timer_control(&(thread->thread_timer), + RT_TIMER_CTRL_SET_TIME, + &time); + rt_timer_start(&(thread->thread_timer)); + } - /* disable interrupt */ - level = rt_hw_interrupt_disable(); + /* enable interrupt */ + rt_hw_interrupt_enable(level); - /* decrease free block */ - mp->block_free_count --; + /* do a schedule */ + rt_schedule(); - /* get block from block list */ - block_ptr = mp->block_list; - mp->block_list = *(rt_uint8_t **)block_ptr; + if (thread->error != RT_EOK) + return RT_NULL; - /* point to memory pool */ - *(rt_uint8_t **)block_ptr = (rt_uint8_t *)mp; + if (time > 0) + { + time -= rt_tick_get() - before_sleep; + if (time < 0) + time = 0; } + /* disable interrupt */ + level = rt_hw_interrupt_disable(); } + /* memory block is available. decrease the free block counter */ + mp->block_free_count--; + + /* get block from block list */ + block_ptr = mp->block_list; + RT_ASSERT(block_ptr != RT_NULL); + + /* Setup the next free node. */ + mp->block_list = *(rt_uint8_t **)block_ptr; + + /* point to memory pool */ + *(rt_uint8_t **)block_ptr = (rt_uint8_t *)mp; + /* enable interrupt */ rt_hw_interrupt_enable(level); diff --git a/src/module.c b/src/module.c index 0603159b91..5d5d02c580 100644 --- a/src/module.c +++ b/src/module.c @@ -1120,8 +1120,8 @@ rt_module_t rt_module_open(const char *path) * This function will do a excutable program with main function and parameters. * * @param path the full path of application module - * @cmd_line the command line of program - * @size the size of command line of program + * @param cmd_line the command line of program + * @param size the size of command line of program * * @return the module object */ diff --git a/src/module.h b/src/module.h index d2d4c4fcc8..3c45c96d02 100644 --- a/src/module.h +++ b/src/module.h @@ -239,7 +239,7 @@ typedef struct #define SHT_DYNAMIC 6 /* dynamic section */ #define SHT_NOTE 7 /* note section */ #define SHT_NOBITS 8 /* no space section */ -#define SHT_REL 9 /* relation section without addends */ +#define SHT_REL 9 /* relocation section without addends */ #define SHT_SHLIB 10 /* reserved - purpose unknown */ #define SHT_DYNSYM 11 /* dynamic symbol table section */ #define SHT_NUM 12 /* number of section types */ diff --git a/src/object.c b/src/object.c index ed3173a0f5..32dc0f2384 100644 --- a/src/object.c +++ b/src/object.c @@ -403,22 +403,77 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type) { struct rt_object *object; struct rt_list_node *node; - struct rt_object_information *information; - extern volatile rt_uint8_t rt_interrupt_nest; + struct rt_object_information *information = RT_NULL; /* parameter check */ if ((name == RT_NULL) || (type > RT_Object_Class_Unknown)) return RT_NULL; /* which is invoke in interrupt status */ - if (rt_interrupt_nest != 0) - RT_ASSERT(0); + RT_DEBUG_NOT_IN_INTERRUPT; + +#ifdef RT_USING_MODULE + /* check whether to find a object inside a module. */ + { + const char *name_ptr; + int module_name_length; + + name_ptr = name; + while ((*name_ptr != '\0') && (*name_ptr != '/')) + name_ptr ++; + + if (*name_ptr == '/') + { + struct rt_module* module = RT_NULL; + + /* get the name length of module */ + module_name_length = name_ptr - name; + + /* enter critical */ + rt_enter_critical(); + + /* find module */ + information = &rt_object_container[RT_Object_Class_Module]; + for (node = information->object_list.next; + node != &(information->object_list); + node = node->next) + { + object = rt_list_entry(node, struct rt_object, list); + if ((rt_strncmp(object->name, name, module_name_length) == 0) && + module_name_length == RT_NAME_MAX || object->name[module_name_length] == '\0') + { + /* get module */ + module = (struct rt_module*)object; + break; + } + } + rt_exit_critical(); + + /* there is no this module inside the system */ + if (module == RT_NULL) return RT_NULL; + + /* get the object pool of module */ + information = &(module->module_object[type]); + + /* get object name */ + while ((*name_ptr == '/') && (*name_ptr != '\0')) name_ptr ++; + if (*name_ptr == '\0') + { + if (type == RT_Object_Class_Module) return object; + return RT_NULL; + } + + /* point to the object name */ + name = name_ptr; + } + } +#endif /* enter critical */ rt_enter_critical(); /* try to find object */ - information = &rt_object_container[type]; + if (information == RT_NULL) information = &rt_object_container[type]; for (node = information->object_list.next; node != &(information->object_list); node = node->next) diff --git a/src/timer.c b/src/timer.c index f71e40fcd6..ba2801530d 100644 --- a/src/timer.c +++ b/src/timer.c @@ -293,7 +293,7 @@ RTM_EXPORT(rt_timer_delete); */ rt_err_t rt_timer_start(rt_timer_t timer) { - int row_lvl; + unsigned int row_lvl; rt_list_t *timer_list; register rt_base_t level; rt_list_t *row_head[RT_TIMER_SKIP_LIST_LEVEL]; |
