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
This commit is contained in:
parent
69466590ff
commit
214e44c3f9
@ -137,9 +137,14 @@ typedef rt_uint32_t rt_off_t; /* Type for offset. */
|
||||
/**
|
||||
* @def RT_ALIGN(size, align)
|
||||
* Return the most contiguous size aligned at specified width. RT_ALIGN(13, 4)
|
||||
* would equal to 16. It is needed in some critical contexts.
|
||||
* would return 16.
|
||||
*
|
||||
* @def RT_ALIGN_DOWN(size, align)
|
||||
* Return the down number of aligned at specified width. RT_ALIGN_DOWN(13, 4)
|
||||
* would return 12.
|
||||
*/
|
||||
#define RT_ALIGN(size, align) (((size) + (align) - 1) & ~((align)-1))
|
||||
#define RT_ALIGN_DOWN(size, align) ((size) & ~((align) -1))
|
||||
|
||||
/**
|
||||
* @def RT_NULL
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
|
10
src/mem.c
10
src/mem.c
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user