diff options
| author | HubretXie <[email protected]> | 2019-04-02 16:07:28 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-04-02 16:07:28 +0800 |
| commit | dc2ee97e66d63f408798956ca52398a953a3691a (patch) | |
| tree | 809490db47a5e764c196a6b91d5f4d3daa108afe /src | |
| parent | 1e16a1ef23135d54b8e8972909b9c64fa815ed9d (diff) | |
| parent | 762cdcc2721673c643b8864de534336d21ca129e (diff) | |
Merge pull request #1 from RT-Thread/master
SYNC
Diffstat (limited to 'src')
| -rw-r--r-- | src/Kconfig | 11 | ||||
| -rw-r--r-- | src/clock.c | 6 | ||||
| -rw-r--r-- | src/kservice.c | 52 | ||||
| -rw-r--r-- | src/slab.c | 42 |
4 files changed, 63 insertions, 48 deletions
diff --git a/src/Kconfig b/src/Kconfig index fbfae65882..e0a8050ff1 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -8,6 +8,15 @@ config RT_NAME_MAX Each kernel object, such as thread, timer, semaphore etc, has a name, the RT_NAME_MAX is the maximal size of this object name. +config RT_USING_ARCH_DATA_TYPE + bool "Use the data types defined in ARCH_CPU" + default n + help + For the data type like, `rt_uint8/int8_t, rt_uint16/int16_t, rt_uint32/int32_t`, + BSP can define these basic data types in ARCH_CPU level. + + Please re-define these data types in rtconfig_project.h file. + config RT_USING_SMP bool "Enable SMP(Symmetric multiprocessing)" default n @@ -91,7 +100,7 @@ config IDLE_THREAD_STACK_SIZE config RT_USING_TIMER_SOFT bool "Enable software timer with a timer thread" - default n + default y help the timeout function context of soft-timer is under a high priority timer thread. diff --git a/src/clock.c b/src/clock.c index 5fcd1d4ae4..a652282b6e 100644 --- a/src/clock.c +++ b/src/clock.c @@ -112,13 +112,13 @@ rt_tick_t rt_tick_from_millisecond(rt_int32_t ms) rt_tick_t tick; if (ms < 0) - { - tick = RT_WAITING_FOREVER; + { + tick = (rt_tick_t)RT_WAITING_FOREVER; } else { tick = RT_TICK_PER_SECOND * (ms / 1000); - tick += (RT_TICK_PER_SECOND * (ms%1000) + 999) / 1000; + tick += (RT_TICK_PER_SECOND * (ms % 1000) + 999) / 1000; } /* return the calculated tick */ diff --git a/src/kservice.c b/src/kservice.c index 3663766225..c940e86d0b 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -668,7 +668,7 @@ static char *print_number(char *buf, while (size-- > 0) { - if (buf <= end) + if (buf < end) *buf = ' '; ++ buf; } @@ -676,11 +676,11 @@ static char *print_number(char *buf, if (sign) { - if (buf <= end) + if (buf < end) { *buf = sign; - -- size; } + -- size; ++ buf; } @@ -689,16 +689,16 @@ static char *print_number(char *buf, { if (base == 8) { - if (buf <= end) + if (buf < end) *buf = '0'; ++ buf; } else if (base == 16) { - if (buf <= end) + if (buf < end) *buf = '0'; ++ buf; - if (buf <= end) + if (buf < end) { *buf = type & LARGE ? 'X' : 'x'; } @@ -712,7 +712,7 @@ static char *print_number(char *buf, { while (size-- > 0) { - if (buf <= end) + if (buf < end) *buf = c; ++ buf; } @@ -721,7 +721,7 @@ static char *print_number(char *buf, #ifdef RT_PRINTF_PRECISION while (i < precision--) { - if (buf <= end) + if (buf < end) *buf = '0'; ++ buf; } @@ -730,14 +730,14 @@ static char *print_number(char *buf, /* put number in the temporary buffer */ while (i-- > 0 && (precision_bak != 0)) { - if (buf <= end) + if (buf < end) *buf = tmp[i]; ++ buf; } while (size-- > 0) { - if (buf <= end) + if (buf < end) *buf = ' '; ++ buf; } @@ -769,7 +769,7 @@ rt_int32_t rt_vsnprintf(char *buf, #endif str = buf; - end = buf + size - 1; + end = buf + size; /* Make sure end is always >= buf */ if (end < buf) @@ -782,7 +782,7 @@ rt_int32_t rt_vsnprintf(char *buf, { if (*fmt != '%') { - if (str <= end) + if (str < end) *str = *fmt; ++ str; continue; @@ -863,20 +863,20 @@ rt_int32_t rt_vsnprintf(char *buf, { while (--field_width > 0) { - if (str <= end) *str = ' '; + if (str < end) *str = ' '; ++ str; } } /* get character */ c = (rt_uint8_t)va_arg(args, int); - if (str <= end) *str = c; + if (str < end) *str = c; ++ str; /* put width */ while (--field_width > 0) { - if (str <= end) *str = ' '; + if (str < end) *str = ' '; ++ str; } continue; @@ -894,21 +894,21 @@ rt_int32_t rt_vsnprintf(char *buf, { while (len < field_width--) { - if (str <= end) *str = ' '; + if (str < end) *str = ' '; ++ str; } } for (i = 0; i < len; ++i) { - if (str <= end) *str = *s; + if (str < end) *str = *s; ++ str; ++ s; } while (len < field_width--) { - if (str <= end) *str = ' '; + if (str < end) *str = ' '; ++ str; } continue; @@ -931,7 +931,7 @@ rt_int32_t rt_vsnprintf(char *buf, continue; case '%': - if (str <= end) *str = '%'; + if (str < end) *str = '%'; ++ str; continue; @@ -953,12 +953,12 @@ rt_int32_t rt_vsnprintf(char *buf, break; default: - if (str <= end) *str = '%'; + if (str < end) *str = '%'; ++ str; if (*fmt) { - if (str <= end) *str = *fmt; + if (str < end) *str = *fmt; ++ str; } else @@ -995,8 +995,14 @@ rt_int32_t rt_vsnprintf(char *buf, #endif } - if (str <= end) *str = '\0'; - else *end = '\0'; + if (size > 0) + { + if (str < end) *str = '\0'; + else + { + end[-1] = '\0'; + } + } /* the trailing null byte doesn't count towards the total * ++str; diff --git a/src/slab.c b/src/slab.c index f4806ddb60..0872ecf092 100644 --- a/src/slab.c +++ b/src/slab.c @@ -217,9 +217,9 @@ struct memusage }; static struct memusage *memusage = RT_NULL; #define btokup(addr) \ - (&memusage[((rt_uint32_t)(addr) - heap_start) >> RT_MM_PAGE_BITS]) + (&memusage[((rt_ubase_t)(addr) - heap_start) >> RT_MM_PAGE_BITS]) -static rt_uint32_t heap_start, heap_end; +static rt_ubase_t heap_start, heap_end; /* page allocator */ struct rt_page_head @@ -275,7 +275,7 @@ void rt_page_free(void *addr, rt_size_t npages) struct rt_page_head **prev; RT_ASSERT(addr != RT_NULL); - RT_ASSERT((rt_uint32_t)addr % RT_MM_PAGE_SIZE == 0); + RT_ASSERT((rt_ubase_t)addr % RT_MM_PAGE_SIZE == 0); RT_ASSERT(npages != 0); n = (struct rt_page_head *)addr; @@ -348,13 +348,13 @@ void rt_system_heap_init(void *begin_addr, void *end_addr) RT_DEBUG_NOT_IN_INTERRUPT; /* align begin and end addr to page */ - heap_start = RT_ALIGN((rt_uint32_t)begin_addr, RT_MM_PAGE_SIZE); - heap_end = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_MM_PAGE_SIZE); + heap_start = RT_ALIGN((rt_ubase_t)begin_addr, RT_MM_PAGE_SIZE); + heap_end = RT_ALIGN_DOWN((rt_ubase_t)end_addr, RT_MM_PAGE_SIZE); if (heap_start >= heap_end) { rt_kprintf("rt_system_heap_init, wrong address[0x%x - 0x%x]\n", - (rt_uint32_t)begin_addr, (rt_uint32_t)end_addr); + (rt_ubase_t)begin_addr, (rt_ubase_t)end_addr); return; } @@ -391,7 +391,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr) memusage = rt_page_alloc(limsize / RT_MM_PAGE_SIZE); RT_DEBUG_LOG(RT_DEBUG_SLAB, ("memusage 0x%x, size 0x%x\n", - (rt_uint32_t)memusage, limsize)); + (rt_ubase_t)memusage, limsize)); } /* @@ -401,7 +401,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr) rt_inline int zoneindex(rt_size_t *bytes) { /* unsigned for shift opt */ - rt_uint32_t n = (rt_uint32_t)(*bytes); + rt_ubase_t n = (rt_ubase_t)(*bytes); if (n < 128) { @@ -507,7 +507,7 @@ void *rt_malloc(rt_size_t size) ("malloc a large memory 0x%x, page cnt %d, kup %d\n", size, size >> RT_MM_PAGE_BITS, - ((rt_uint32_t)chunk - heap_start) >> RT_MM_PAGE_BITS)); + ((rt_ubase_t)chunk - heap_start) >> RT_MM_PAGE_BITS)); /* lock heap */ rt_sem_take(&heap_sem, RT_WAITING_FOREVER); @@ -610,7 +610,7 @@ void *rt_malloc(rt_size_t size) rt_sem_take(&heap_sem, RT_WAITING_FOREVER); RT_DEBUG_LOG(RT_DEBUG_SLAB, ("alloc a new zone: 0x%x\n", - (rt_uint32_t)z)); + (rt_ubase_t)z)); /* set message usage */ for (off = 0, kup = btokup(z); off < zone_page_cnt; off ++) @@ -694,7 +694,7 @@ void *rt_realloc(void *ptr, rt_size_t size) * Get the original allocation's zone. If the new request winds up * using the same chunk size we do not have to do anything. */ - kup = btokup((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK); + kup = btokup((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK); if (kup->type == PAGE_TYPE_LARGE) { rt_size_t osize; @@ -709,7 +709,7 @@ void *rt_realloc(void *ptr, rt_size_t size) } else if (kup->type == PAGE_TYPE_SMALL) { - z = (slab_zone *)(((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK) - + z = (slab_zone *)(((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK) - kup->size * RT_MM_PAGE_SIZE); RT_ASSERT(z->z_magic == ZALLOC_SLAB_MAGIC); @@ -783,20 +783,20 @@ void rt_free(void *ptr) /* get memory usage */ #if RT_DEBUG_SLAB { - rt_uint32_t addr = ((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK); + rt_ubase_t addr = ((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK); RT_DEBUG_LOG(RT_DEBUG_SLAB, ("free a memory 0x%x and align to 0x%x, kup index %d\n", - (rt_uint32_t)ptr, - (rt_uint32_t)addr, - ((rt_uint32_t)(addr) - heap_start) >> RT_MM_PAGE_BITS)); + (rt_ubase_t)ptr, + (rt_ubase_t)addr, + ((rt_ubase_t)(addr) - heap_start) >> RT_MM_PAGE_BITS)); } #endif - kup = btokup((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK); + kup = btokup((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK); /* release large allocation */ if (kup->type == PAGE_TYPE_LARGE) { - rt_uint32_t size; + rt_ubase_t size; /* lock heap */ rt_sem_take(&heap_sem, RT_WAITING_FOREVER); @@ -811,7 +811,7 @@ void rt_free(void *ptr) RT_DEBUG_LOG(RT_DEBUG_SLAB, ("free large memory block 0x%x, page count %d\n", - (rt_uint32_t)ptr, size)); + (rt_ubase_t)ptr, size)); /* free this page */ rt_page_free(ptr, size); @@ -823,7 +823,7 @@ void rt_free(void *ptr) rt_sem_take(&heap_sem, RT_WAITING_FOREVER); /* zone case. get out zone. */ - z = (slab_zone *)(((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK) - + z = (slab_zone *)(((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK) - kup->size * RT_MM_PAGE_SIZE); RT_ASSERT(z->z_magic == ZALLOC_SLAB_MAGIC); @@ -857,7 +857,7 @@ void rt_free(void *ptr) slab_zone **pz; RT_DEBUG_LOG(RT_DEBUG_SLAB, ("free zone 0x%x\n", - (rt_uint32_t)z, z->z_zoneindex)); + (rt_ubase_t)z, z->z_zoneindex)); /* remove zone from zone array list */ for (pz = &zone_array[z->z_zoneindex]; z != *pz; pz = &(*pz)->z_next) |
