diff options
| author | bernard.xiong <[email protected]> | 2010-07-13 07:36:37 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2010-07-13 07:36:37 +0000 |
| commit | 214e44c3f9d79e34719cd9cef5e2fc596a693d47 (patch) | |
| tree | 5270f946a824b0d54689953aca65d6039ffaee3b /src | |
| parent | 69466590ff78faa11ed508d74a5509113b8dace0 (diff) | |
fix down alignment issue; fix the maximal number of rt_scheduler_lock_nest issue; fix rt_tick_from_millisecond issue.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@790 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'src')
| -rw-r--r-- | src/clock.c | 3 | ||||
| -rw-r--r-- | src/mem.c | 28 | ||||
| -rw-r--r-- | src/mempool.c | 9 | ||||
| -rw-r--r-- | src/scheduler.c | 9 | ||||
| -rw-r--r-- | src/slab.c | 3 |
5 files changed, 31 insertions, 21 deletions
diff --git a/src/clock.c b/src/clock.c index 6ca918d1f8..f34d09e32f 100644 --- a/src/clock.c +++ b/src/clock.c @@ -14,6 +14,7 @@ * 2006-08-10 Bernard remove the last rt_schedule in rt_tick_increase * 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 */ #include <rtthread.h> @@ -95,7 +96,7 @@ void rt_tick_increase() rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms) { /* return the calculated tick */ - return RT_TICK_PER_SECOND * (ms / 1000); + return (RT_TICK_PER_SECOND * ms) / 1000 + (RT_TICK_PER_SECOND * ms) % 1000 ? 1:0; } /*@}*/ @@ -12,6 +12,7 @@ * 2008-7-12 Bernard the first version * 2010-06-09 Bernard fix the end stub of heap * fix memory check in rt_realloc function + * 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca */ /* @@ -170,7 +171,7 @@ void rt_system_heap_init(void* begin_addr, void* end_addr) begin_addr = (void*)RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE); /* calculate the aligned memory size */ - mem_size_aligned = RT_ALIGN((rt_uint32_t)end_addr - (rt_uint32_t)begin_addr, RT_ALIGN_SIZE) - 2 * SIZEOF_STRUCT_MEM; + mem_size_aligned = RT_ALIGN_DOWN((rt_uint32_t)end_addr - (rt_uint32_t)begin_addr, RT_ALIGN_SIZE) - 2 * SIZEOF_STRUCT_MEM; /* point to begin address of heap */ heap_ptr = begin_addr; @@ -220,7 +221,10 @@ void *rt_malloc(rt_size_t size) if (size == 0) return RT_NULL; #ifdef RT_MEM_DEBUG - rt_kprintf("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE)); + if (size != RT_ALIGN(size, RT_ALIGN_SIZE) + rt_kprintf("malloc size %d, but align to %d\n", size, RT_ALIGN(size, RT_ALIGN_SIZE)); + else + rt_kprintf("malloc size %d\n", size); #endif /* alignment size */ @@ -351,7 +355,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize) if (newsize > mem_size_aligned) { #ifdef RT_MEM_DEBUG - rt_kprintf("no memory\n"); + rt_kprintf("realloc: out of memory\n"); #endif return RT_NULL; } @@ -498,15 +502,15 @@ void rt_free(void *rmem) rt_sem_release(&heap_sem); } -#ifdef RT_MEM_STATS
-void rt_memory_info(rt_uint32_t *total,
- rt_uint32_t *used,
- rt_uint32_t *max_used)
-{
- if (total != RT_NULL) *total = mem_size_aligned;
- if (used != RT_NULL) *used = used_mem;
- if (max_used != RT_NULL) *max_used = max_mem;
-}
+#ifdef RT_MEM_STATS +void rt_memory_info(rt_uint32_t *total, + rt_uint32_t *used, + rt_uint32_t *max_used) +{ + if (total != RT_NULL) *total = mem_size_aligned; + if (used != RT_NULL) *used = used_mem; + if (max_used != RT_NULL) *max_used = max_mem; +} #ifdef RT_USING_FINSH #include <finsh.h> diff --git a/src/mempool.c b/src/mempool.c index 34b4d4c51c..53f1162802 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -14,6 +14,7 @@ * 2006-06-30 Bernard fix the allocate/free block bug * 2006-08-04 Bernard add hook support * 2006-08-10 Bernard fix interrupt bug in rt_mp_alloc + * 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca */ #include <rthw.h> @@ -88,7 +89,7 @@ rt_err_t rt_mp_init(struct rt_mempool* mp, const char* name, void *start, rt_siz /* init memory pool */ mp->start_address = start; - mp->size = RT_ALIGN(size, RT_ALIGN_SIZE); + mp->size = RT_ALIGN_DOWN(size, RT_ALIGN_SIZE); mp->block_size = block_size; @@ -294,11 +295,11 @@ void *rt_mp_alloc (rt_mp_t mp, rt_int32_t time) else { /* memory block is unavailable. */ - if (time == 0)
- {
+ if (time == 0) + { /* enable interrupt */ rt_hw_interrupt_enable(level); - return RT_NULL;
+ return RT_NULL; } else { diff --git a/src/scheduler.c b/src/scheduler.c index e5c82279cb..be71234370 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -19,7 +19,9 @@ * 2006-09-05 Bernard add 32 priority level support * 2006-09-24 Bernard add rt_system_scheduler_start function * 2009-09-16 Bernard fix _rt_scheduler_stack_check - * 2010-04-11 yi.qiu add module feature + * 2010-04-11 yi.qiu add module feature + * 2010-07-13 Bernard fix the maximal number of rt_scheduler_lock_nest + * issue found by kuronca */ #include <rtthread.h> @@ -396,8 +398,9 @@ void rt_enter_critical() /* disable interrupt */ level = rt_hw_interrupt_disable(); - if (rt_scheduler_lock_nest < 255u) - rt_scheduler_lock_nest++; + /* the maximal number of nest is RT_UINT16_MAX, which is big + * enough and does not check here */ + rt_scheduler_lock_nest++; /* enable interrupt */ rt_hw_interrupt_enable(level); diff --git a/src/slab.c b/src/slab.c index dff6dd471c..216ee19500 100644 --- a/src/slab.c +++ b/src/slab.c @@ -10,6 +10,7 @@ * Change Logs: * Date Author Notes * 2008-07-12 Bernard the first version + * 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca */ /* @@ -326,7 +327,7 @@ void rt_system_heap_init(void *begin_addr, void* end_addr) /* align begin and end addr to page */ heap_start = RT_ALIGN((rt_uint32_t)begin_addr, RT_MM_PAGE_SIZE); - heap_end = RT_ALIGN((rt_uint32_t)end_addr, RT_MM_PAGE_SIZE); + heap_end = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_MM_PAGE_SIZE); limsize = heap_end - heap_start; npages = limsize / RT_MM_PAGE_SIZE; |
