提交 c0f80bdf 编写于 作者: D dzzxzz

cleanup kernel code

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1715 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 fea7d02b
/*
* File : clock.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -31,7 +31,7 @@ extern void rt_timer_switch(void);
* @ingroup SystemInit
*
*/
void rt_system_tick_init()
void rt_system_tick_init(void)
{
rt_tick = 0;
}
......@@ -47,7 +47,7 @@ void rt_system_tick_init()
*
* @return current tick
*/
rt_tick_t rt_tick_get()
rt_tick_t rt_tick_get(void)
{
/* return the global tick */
return rt_tick;
......@@ -70,9 +70,9 @@ void rt_tick_set(rt_tick_t tick)
* This function will notify kernel there is one tick passed. Normally,
* this function is invoked by clock ISR.
*/
void rt_tick_increase()
void rt_tick_increase(void)
{
struct rt_thread* thread;
struct rt_thread *thread;
/* increase the global tick */
++ rt_tick;
......@@ -87,10 +87,10 @@ void rt_tick_increase()
thread->remaining_tick = thread->init_tick;
/* yield */
rt_thread_yield();
rt_thread_yield();
}
/* check timer */
/* check timer */
rt_timer_check();
}
......@@ -104,7 +104,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+999) / 1000;
return (RT_TICK_PER_SECOND * ms + 999) / 1000;
}
/*@}*/
......
/*
* File : device.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -27,7 +27,7 @@
*
* @return the error code, RT_EOK on initialization successfully.
*/
rt_err_t rt_device_register(rt_device_t dev, const char* name, rt_uint16_t flags)
rt_err_t rt_device_register(rt_device_t dev, const char *name, rt_uint16_t flags)
{
if (dev == RT_NULL) return -RT_ERROR;
......@@ -58,10 +58,10 @@ rt_err_t rt_device_unregister(rt_device_t dev)
*
* @return the error code, RT_EOK on successfully.
*/
rt_err_t rt_device_init_all()
rt_err_t rt_device_init_all(void)
{
struct rt_device* device;
struct rt_list_node* node;
struct rt_device *device;
struct rt_list_node *node;
struct rt_object_information *information;
register rt_err_t result;
......@@ -73,7 +73,7 @@ rt_err_t rt_device_init_all()
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
{
rt_err_t (*init)(rt_device_t dev);
device = (struct rt_device*)rt_list_entry(node, struct rt_object, list);
device = (struct rt_device *)rt_list_entry(node, struct rt_object, list);
/* get device init handler */
init = device->init;
......@@ -102,10 +102,10 @@ rt_err_t rt_device_init_all()
*
* @return the registered device driver on successful, or RT_NULL on failure.
*/
rt_device_t rt_device_find(const char* name)
rt_device_t rt_device_find(const char *name)
{
struct rt_object* object;
struct rt_list_node* node;
struct rt_object *object;
struct rt_list_node *node;
struct rt_object_information *information;
extern struct rt_object_information rt_object_container[];
......@@ -167,7 +167,7 @@ rt_err_t rt_device_init(rt_device_t dev)
}
}
else result = -RT_ENOSYS;
return result;
}
......@@ -182,7 +182,7 @@ rt_err_t rt_device_init(rt_device_t dev)
rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
{
rt_err_t result;
rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
rt_err_t (*open)(rt_device_t dev, rt_uint16_t oflag);
RT_ASSERT(dev != RT_NULL);
......@@ -205,8 +205,7 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
}
/* device is a stand alone device and opened */
if ((dev->flag & RT_DEVICE_FLAG_STANDALONE) &&
(dev->open_flag & RT_DEVICE_OFLAG_OPEN))
if ((dev->flag & RT_DEVICE_FLAG_STANDALONE) && (dev->open_flag & RT_DEVICE_OFLAG_OPEN))
return -RT_EBUSY;
/* call device open interface */
......@@ -273,9 +272,9 @@ rt_err_t rt_device_close(rt_device_t dev)
*
* @note since 0.4.0, the unit of size/pos is a block for block device.
*/
rt_size_t rt_device_read (rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
rt_size_t rt_device_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
{
rt_size_t (*read)(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size);
rt_size_t (*read)(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
RT_ASSERT(dev != RT_NULL);
......@@ -303,9 +302,9 @@ rt_size_t rt_device_read (rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t
*
* @note since 0.4.0, the unit of size/pos is a block for block device.
*/
rt_size_t rt_device_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size)
rt_size_t rt_device_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
rt_size_t (*write)(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size);
rt_size_t (*write)(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
RT_ASSERT(dev != RT_NULL);
......@@ -330,9 +329,9 @@ rt_size_t rt_device_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_
*
* @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, rt_uint8_t cmd, void *arg)
{
rt_err_t (*control)(rt_device_t dev, rt_uint8_t cmd, void* arg);
rt_err_t (*control)(rt_device_t dev, rt_uint8_t cmd, void *arg);
RT_ASSERT(dev != RT_NULL);
......@@ -355,7 +354,7 @@ rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void* arg)
*
* @return RT_EOK
*/
rt_err_t rt_device_set_rx_indicate(rt_device_t dev, rt_err_t (*rx_ind )(rt_device_t dev, rt_size_t size))
rt_err_t rt_device_set_rx_indicate(rt_device_t dev, rt_err_t (*rx_ind)(rt_device_t dev, rt_size_t size))
{
RT_ASSERT(dev != RT_NULL);
......
......@@ -84,7 +84,7 @@ void rt_thread_idle_excute(void)
/* if the thread is module's main thread */
if (module != RT_NULL && module->module_thread == thread)
{
{
/* detach module's main thread */
module->module_thread = RT_NULL;
}
......@@ -134,8 +134,8 @@ void rt_thread_idle_excute(void)
if ((module->module_thread == RT_NULL) &&
rt_list_isempty(&module->module_object[RT_Object_Class_Thread].object_list) )
{
module->nref--;
}
module->nref --;
}
}
/* unload module */
......@@ -144,7 +144,7 @@ void rt_thread_idle_excute(void)
}
}
static void rt_thread_idle_entry(void* parameter)
static void rt_thread_idle_entry(void *parameter)
{
while (1)
{
......
......@@ -42,9 +42,9 @@
#include "kservice.h"
#ifdef RT_USING_HOOK
extern void (*rt_object_trytake_hook)(struct rt_object* object);
extern void (*rt_object_take_hook)(struct rt_object* object);
extern void (*rt_object_put_hook)(struct rt_object* object);
extern void (*rt_object_trytake_hook)(struct rt_object *object);
extern void (*rt_object_take_hook)(struct rt_object *object);
extern void (*rt_object_put_hook)(struct rt_object *object);
#endif
/**
......@@ -90,8 +90,8 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, struct rt_thread *thread
case RT_IPC_FLAG_PRIO:
{
struct rt_list_node* n;
struct rt_thread* sthread;
struct rt_list_node *n;
struct rt_thread *sthread;
/* find a suitable position */
for (n = list->next; n != list; n = n->next)
......@@ -126,9 +126,9 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, struct rt_thread *thread
*
* @return the operation status, RT_EOK on successful
*/
rt_inline rt_err_t rt_ipc_list_resume(rt_list_t* list)
rt_inline rt_err_t rt_ipc_list_resume(rt_list_t *list)
{
struct rt_thread* thread;
struct rt_thread *thread;
/* get thread entry */
thread = rt_list_entry(list->next, struct rt_thread, tlist);
......@@ -149,9 +149,9 @@ rt_inline rt_err_t rt_ipc_list_resume(rt_list_t* list)
*
* @return the operation status, RT_EOK on successful
*/
rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t* list)
rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list)
{
struct rt_thread* thread;
struct rt_thread *thread;
register rt_ubase_t temp;
/* wakeup all suspend threads */
......@@ -191,7 +191,7 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t* list)
*
* @return the operation status, RT_EOK on successful
*/
rt_err_t rt_sem_init(rt_sem_t sem, const char* name, rt_uint32_t value, rt_uint8_t flag)
rt_err_t rt_sem_init(rt_sem_t sem, const char *name, rt_uint32_t value, rt_uint8_t flag)
{
RT_ASSERT(sem != RT_NULL);
......@@ -244,7 +244,7 @@ rt_err_t rt_sem_detach(rt_sem_t sem)
*
* @see rt_sem_init
*/
rt_sem_t rt_sem_create(const char* name, rt_uint32_t value, rt_uint8_t flag)
rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag)
{
rt_sem_t sem;
......@@ -303,7 +303,7 @@ rt_err_t rt_sem_delete(rt_sem_t sem)
rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
{
register rt_base_t temp;
struct rt_thread* thread;
struct rt_thread *thread;
RT_ASSERT(sem != RT_NULL);
......@@ -314,7 +314,7 @@ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
RT_DEBUG_LOG(RT_DEBUG_IPC,
("thread %s take sem:%s, which value is: %d\n", rt_thread_self()->name,
((struct rt_object*)sem)->name, sem->value));
((struct rt_object *)sem)->name, sem->value));
if (sem->value > 0)
{
......@@ -344,8 +344,7 @@ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
/* reset thread error number */
thread->error = RT_EOK;
RT_DEBUG_LOG(RT_DEBUG_IPC,
("sem take: suspend thread - %s\n", thread->name));
RT_DEBUG_LOG(RT_DEBUG_IPC, ("sem take: suspend thread - %s\n", thread->name));
/* suspend thread */
rt_ipc_list_suspend(&(sem->parent.suspend_thread),
......@@ -413,7 +412,7 @@ rt_err_t rt_sem_release(rt_sem_t sem)
RT_DEBUG_LOG(RT_DEBUG_IPC,
("thread %s releases sem:%s, which value is: %d\n", rt_thread_self()->name,
((struct rt_object*)sem)->name, sem->value));
((struct rt_object *)sem)->name, sem->value));
if (!rt_list_isempty(&sem->parent.suspend_thread))
......@@ -442,7 +441,7 @@ rt_err_t rt_sem_release(rt_sem_t sem)
*
* @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, rt_uint8_t cmd, void *arg)
{
rt_ubase_t level;
RT_ASSERT(sem != RT_NULL);
......@@ -483,7 +482,7 @@ rt_err_t rt_sem_control(rt_sem_t sem, rt_uint8_t cmd, void* arg)
*
* @return the operation status, RT_EOK on successful
*/
rt_err_t rt_mutex_init(rt_mutex_t mutex, const char* name, rt_uint8_t flag)
rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag)
{
RT_ASSERT(mutex != RT_NULL);
......@@ -537,9 +536,9 @@ rt_err_t rt_mutex_detach(rt_mutex_t mutex)
*
* @see rt_mutex_init
*/
rt_mutex_t rt_mutex_create(const char* name, rt_uint8_t flag)
rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag)
{
struct rt_mutex* mutex;
struct rt_mutex *mutex;
RT_DEBUG_NOT_IN_INTERRUPT;
......@@ -598,7 +597,7 @@ rt_err_t rt_mutex_delete(rt_mutex_t mutex)
rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
{
register rt_base_t temp;
struct rt_thread* thread;
struct rt_thread *thread;
/* this function must not be used in interrupt even if time = 0 */
RT_DEBUG_NOT_IN_INTERRUPT;
......@@ -722,7 +721,7 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
rt_err_t rt_mutex_release(rt_mutex_t mutex)
{
register rt_base_t temp;
struct rt_thread* thread;
struct rt_thread *thread;
rt_bool_t need_schedule;
need_schedule = RT_FALSE;
......@@ -768,8 +767,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
/* get suspended thread */
thread = rt_list_entry(mutex->parent.suspend_thread.next, struct rt_thread, tlist);
RT_DEBUG_LOG(RT_DEBUG_IPC,
("mutex_release: resume thread: %s\n", thread->name));
RT_DEBUG_LOG(RT_DEBUG_IPC, ("mutex_release: resume thread: %s\n", thread->name));
/* set new owner and priority */
mutex->owner = thread;
......@@ -810,7 +808,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
*
* @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, rt_uint8_t cmd, void *arg)
{
return -RT_ERROR;
}
......@@ -827,7 +825,7 @@ rt_err_t rt_mutex_control(rt_mutex_t mutex, rt_uint8_t cmd, void* arg)
*
* @return the operation status, RT_EOK on successful
*/
rt_err_t rt_event_init(rt_event_t event, const char* name, rt_uint8_t flag)
rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag)
{
RT_ASSERT(event != RT_NULL);
......@@ -876,7 +874,7 @@ rt_err_t rt_event_detach(rt_event_t event)
*
* @return the created event, RT_NULL on error happen
*/
rt_event_t rt_event_create(const char* name, rt_uint8_t flag)
rt_event_t rt_event_create(const char *name, rt_uint8_t flag)
{
rt_event_t event;
......@@ -933,8 +931,8 @@ rt_err_t rt_event_delete(rt_event_t event)
*/
rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set)
{
struct rt_list_node* n;
struct rt_thread* thread;
struct rt_list_node *n;
struct rt_thread *thread;
register rt_ubase_t level;
register rt_base_t status;
rt_bool_t need_schedule;
......@@ -1023,9 +1021,9 @@ rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set)
*
* @return the error code
*/
rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_int32_t timeout, rt_uint32_t* recved)
rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_int32_t timeout, rt_uint32_t *recved)
{
struct rt_thread* thread;
struct rt_thread *thread;
register rt_ubase_t level;
register rt_base_t status;
......@@ -1077,8 +1075,7 @@ rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_
thread->event_info = option;
/* put thread to suspended thread list */
rt_ipc_list_suspend(&(event->parent.suspend_thread),
thread, event->parent.parent.flag);
rt_ipc_list_suspend(&(event->parent.suspend_thread), thread, event->parent.parent.flag);
/* if there is a waiting timeout, active thread timer */
if (timeout > 0)
......@@ -1124,7 +1121,7 @@ rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t option, rt_
*
* @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, rt_uint8_t cmd, void *arg)
{
rt_ubase_t level;
RT_ASSERT(event != RT_NULL);
......@@ -1163,7 +1160,7 @@ rt_err_t rt_event_control(rt_event_t event, rt_uint8_t cmd, void* arg)
*
* @return the operation status, RT_EOK on successful
*/
rt_err_t rt_mb_init(rt_mailbox_t mb, const char* name, void* msgpool, rt_size_t size, rt_uint8_t flag)
rt_err_t rt_mb_init(rt_mailbox_t mb, const char *name, void *msgpool, rt_size_t size, rt_uint8_t flag)
{
RT_ASSERT(mb != RT_NULL);
......@@ -1177,11 +1174,11 @@ rt_err_t rt_mb_init(rt_mailbox_t mb, const char* name, void* msgpool, rt_size_t
rt_ipc_object_init(&(mb->parent));
/* init mailbox */
mb->msg_pool = msgpool;
mb->size = size;
mb->entry = 0;
mb->in_offset = 0;
mb->out_offset = 0;
mb->msg_pool = msgpool;
mb->size = size;
mb->entry = 0;
mb->in_offset = 0;
mb->out_offset = 0;
/* init an additional list of sender suspend thread */
rt_list_init(&(mb->suspend_sender_thread));
......@@ -1222,7 +1219,7 @@ rt_err_t rt_mb_detach(rt_mailbox_t mb)
*
* @return the created mailbox, RT_NULL on error happen
*/
rt_mailbox_t rt_mb_create(const char* name, rt_size_t size, rt_uint8_t flag)
rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag)
{
rt_mailbox_t mb;
......@@ -1307,7 +1304,7 @@ rt_err_t rt_mb_delete(rt_mailbox_t mb)
*/
rt_err_t rt_mb_send_wait(rt_mailbox_t mb, rt_uint32_t value, rt_int32_t timeout)
{
struct rt_thread* thread;
struct rt_thread *thread;
register rt_ubase_t temp;
rt_uint32_t tick_delta;
......@@ -1347,8 +1344,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, rt_uint32_t value, rt_int32_t timeout)
RT_DEBUG_NOT_IN_INTERRUPT;
/* suspend current thread */
rt_ipc_list_suspend(&(mb->suspend_sender_thread),
thread, mb->parent.parent.flag);
rt_ipc_list_suspend(&(mb->suspend_sender_thread), thread, mb->parent.parent.flag);
/* has waiting time, start thread timer */
if (timeout > 0)
......@@ -1440,9 +1436,9 @@ rt_err_t rt_mb_send(rt_mailbox_t mb, rt_uint32_t value)
*
* @return the error code
*/
rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t *value, rt_int32_t timeout)
{
struct rt_thread* thread;
struct rt_thread *thread;
register rt_ubase_t temp;
rt_uint32_t tick_delta;
......@@ -1484,8 +1480,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
RT_DEBUG_NOT_IN_INTERRUPT;
/* suspend current thread */
rt_ipc_list_suspend(&(mb->parent.suspend_thread),
thread, mb->parent.parent.flag);
rt_ipc_list_suspend(&(mb->parent.suspend_thread), thread, mb->parent.parent.flag);
/* has waiting time, start thread timer */
if (timeout > 0)
......@@ -1530,7 +1525,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
*value = mb->msg_pool[mb->out_offset];
/* increase output offset */
++mb->out_offset;
++ mb->out_offset;
if (mb->out_offset >= mb->size) mb->out_offset = 0;
/* decrease message entry */
mb->entry --;
......@@ -1567,7 +1562,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_uint32_t* value, rt_int32_t timeout)
*
* @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, rt_uint8_t cmd, void *arg)
{
rt_ubase_t level;
RT_ASSERT(mb != RT_NULL);
......@@ -1601,7 +1596,7 @@ rt_err_t rt_mb_control(rt_mailbox_t mb, rt_uint8_t cmd, void* arg)
#ifdef RT_USING_MESSAGEQUEUE
struct rt_mq_message
{
struct rt_mq_message* next;
struct rt_mq_message *next;
};
/**
......@@ -1617,9 +1612,9 @@ struct rt_mq_message
*
* @return the operation status, RT_EOK on successful
*/
rt_err_t rt_mq_init(rt_mq_t mq, const char* name, void *msgpool, rt_size_t msg_size, rt_size_t pool_size, rt_uint8_t flag)
rt_err_t rt_mq_init(rt_mq_t mq, const char *name, void *msgpool, rt_size_t msg_size, rt_size_t pool_size, rt_uint8_t flag)
{
struct rt_mq_message* head;
struct rt_mq_message *head;
register rt_base_t temp;
/* parameter check */
......@@ -1649,7 +1644,7 @@ rt_err_t rt_mq_init(rt_mq_t mq, const char* name, void *msgpool, rt_size_t msg_s
mq->msg_queue_free = RT_NULL;
for (temp = 0; temp < mq->max_msgs; temp ++)
{
head = (struct rt_mq_message*)((rt_uint8_t*)mq->msg_pool +
head = (struct rt_mq_message *)((rt_uint8_t *)mq->msg_pool +
temp * (mq->msg_size + sizeof(struct rt_mq_message)));
head->next = mq->msg_queue_free;
mq->msg_queue_free = head;
......@@ -1693,10 +1688,10 @@ rt_err_t rt_mq_detach(rt_mq_t mq)
*
* @return the created message queue, RT_NULL on error happen
*/
rt_mq_t rt_mq_create(const char* name, rt_size_t msg_size, rt_size_t max_msgs, rt_uint8_t flag)
rt_mq_t rt_mq_create(const char *name, rt_size_t msg_size, rt_size_t max_msgs, rt_uint8_t flag)
{
struct rt_messagequeue* mq;
struct rt_mq_message* head;
struct rt_messagequeue *mq;
struct rt_mq_message *head;
register rt_base_t temp;
RT_DEBUG_NOT_IN_INTERRUPT;
......@@ -1789,10 +1784,10 @@ rt_err_t rt_mq_delete(rt_mq_t mq)
*
* @return the error code
*/
rt_err_t rt_mq_send(rt_mq_t mq, void* buffer, rt_size_t size)
rt_err_t rt_mq_send(rt_mq_t mq, void *buffer, rt_size_t size)
{
register rt_ubase_t temp;
struct rt_mq_message* msg;
struct rt_mq_message *msg;
/* greater than one message size */
if (size > mq->msg_size) return -RT_ERROR;
......@@ -1829,7 +1824,7 @@ rt_err_t rt_mq_send(rt_mq_t mq, void* buffer, rt_size_t size)
if (mq->msg_queue_tail != RT_NULL)
{
/* if the tail exists, */
((struct rt_mq_message*)mq->msg_queue_tail)->next = msg;
((struct rt_mq_message *)mq->msg_queue_tail)->next = msg;
}
/* set new tail */
......@@ -1869,10 +1864,10 @@ rt_err_t rt_mq_send(rt_mq_t mq, void* buffer, rt_size_t size)
*
* @return the error code
*/
rt_err_t rt_mq_urgent(rt_mq_t mq, void* buffer, rt_size_t size)
rt_err_t rt_mq_urgent(rt_mq_t mq, void *buffer, rt_size_t size)
{
register rt_ubase_t temp;
struct rt_mq_message* msg;
struct rt_mq_message *msg;
/* greater than one message size */
if (size > mq->msg_size) return -RT_ERROR;
......@@ -1883,7 +1878,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, void* buffer, rt_size_t size)
temp = rt_hw_interrupt_disable();
/* get a free list, there must be an empty item */
msg = (struct rt_mq_message*)mq->msg_queue_free;
msg = (struct rt_mq_message *)mq->msg_queue_free;
/* message queue is full */
if (msg == RT_NULL)
{
......@@ -1943,11 +1938,11 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, void* buffer, rt_size_t size)
*
* @return the error code
*/
rt_err_t rt_mq_recv(rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeout)
rt_err_t rt_mq_recv(rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout)
{
struct rt_thread* thread;
struct rt_thread *thread;
register rt_ubase_t temp;
struct rt_mq_message* msg;
struct rt_mq_message *msg;
rt_uint32_t tick_delta;
/* initialize delta tick */
......@@ -1985,8 +1980,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeout
}
/* suspend current thread */
rt_ipc_list_suspend(&(mq->parent.suspend_thread),
thread, mq->parent.parent.flag);
rt_ipc_list_suspend(&(mq->parent.suspend_thread), thread, mq->parent.parent.flag);
/* has waiting time, start thread timer */
if (timeout > 0)
......@@ -1994,8 +1988,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeout
/* get the start tick of timer */
tick_delta = rt_tick_get();
RT_DEBUG_LOG(RT_DEBUG_IPC,
("set thread:%s to timer list\n", thread->name));
RT_DEBUG_LOG(RT_DEBUG_IPC, ("set thread:%s to timer list\n", thread->name));
/* reset the timeout of thread timer and start it */
rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &timeout);
......@@ -2028,7 +2021,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeout
}
/* get message from queue */
msg = (struct rt_mq_message*) mq->msg_queue_head;
msg = (struct rt_mq_message *)mq->msg_queue_head;
/* move message queue head */
mq->msg_queue_head = msg->next;
......@@ -2042,13 +2035,12 @@ rt_err_t rt_mq_recv(rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeout
rt_hw_interrupt_enable(temp);
/* copy message */
rt_memcpy(buffer, msg + 1,
size > mq->msg_size? mq->msg_size : size);
rt_memcpy(buffer, msg + 1, size > mq->msg_size ? mq->msg_size : size);
/* disable interrupt */
temp = rt_hw_interrupt_disable();
/* put message to free list */
msg->next = (struct rt_mq_message*)mq->msg_queue_free;
msg->next = (struct rt_mq_message *)mq->msg_queue_free;
mq->msg_queue_free = msg;
/* enable interrupt */
rt_hw_interrupt_enable(temp);
......@@ -2067,10 +2059,10 @@ rt_err_t rt_mq_recv(rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeout
*
* @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, rt_uint8_t cmd, void *arg)
{
rt_ubase_t level;
struct rt_mq_message* msg;
struct rt_mq_message *msg;
RT_ASSERT(mq != RT_NULL);
......@@ -2086,7 +2078,7 @@ rt_err_t rt_mq_control(rt_mq_t mq, rt_uint8_t cmd, void* arg)
while (mq->msg_queue_head != RT_NULL)
{
/* get message from queue */
msg = (struct rt_mq_message*) mq->msg_queue_head;
msg = (struct rt_mq_message *)mq->msg_queue_head;
/* move message queue head */
mq->msg_queue_head = msg->next;
......@@ -2094,7 +2086,7 @@ rt_err_t rt_mq_control(rt_mq_t mq, rt_uint8_t cmd, void* arg)
if (mq->msg_queue_tail == msg) mq->msg_queue_tail = RT_NULL;
/* put message to free list */
msg->next = (struct rt_mq_message*)mq->msg_queue_free;
msg->next = (struct rt_mq_message *)mq->msg_queue_free;
mq->msg_queue_free = msg;
}
......
/*
* File : irq.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -33,11 +33,11 @@ volatile rt_uint8_t rt_interrupt_nest;
*
* @see rt_interrupt_leave
*/
void rt_interrupt_enter()
void rt_interrupt_enter(void)
{
rt_base_t level;
RT_DEBUG_LOG(RT_DEBUG_IRQ,("irq comming..., irq nest:%d\n", rt_interrupt_nest));
RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq comming..., irq nest:%d\n", rt_interrupt_nest));
level = rt_hw_interrupt_disable();
rt_interrupt_nest ++;
......@@ -51,11 +51,11 @@ void rt_interrupt_enter()
*
* @see rt_interrupt_enter
*/
void rt_interrupt_leave()
void rt_interrupt_leave(void)
{
rt_base_t level;
RT_DEBUG_LOG(RT_DEBUG_IRQ,("irq leave, irq nest:%d\n", rt_interrupt_nest));
RT_DEBUG_LOG(RT_DEBUG_IRQ, ("irq leave, irq nest:%d\n", rt_interrupt_nest));
level = rt_hw_interrupt_disable();
rt_interrupt_nest --;
......
/*
* File : kservice.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -26,7 +26,7 @@
/*@{*/
#ifndef RT_USING_NEWLIB
/* global errno in RT-Thread*/
/* global errno in RT-Thread */
static volatile int _errno;
#else
#include <errno.h>
......@@ -44,7 +44,7 @@ rt_err_t rt_get_errno(void)
{
rt_thread_t tid;
if(rt_interrupt_get_nest() != 0)
if (rt_interrupt_get_nest() != 0)
{
/* it's in interrupt context */
return _errno;
......@@ -65,7 +65,7 @@ void rt_set_errno(rt_err_t error)
{
rt_thread_t tid;
if(rt_interrupt_get_nest() != 0)
if (rt_interrupt_get_nest() != 0)
{
/* it's in interrupt context */
_errno = error;
......@@ -105,19 +105,19 @@ int *_rt_errno(void)
* @return the address of source memory
*
*/
void *rt_memset(void * s, int c, rt_ubase_t count)
void *rt_memset(void *s, int c, rt_ubase_t count)
{
#ifdef RT_TINY_SIZE
char *xs = (char *) s;
char *xs = (char *)s;
while (count--)
*xs++ = c;
return s;
#else
#define LBLOCKSIZE (sizeof(rt_int32_t))
#define UNALIGNED(X) ((rt_int32_t)X & (LBLOCKSIZE - 1))
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
#define LBLOCKSIZE (sizeof(rt_int32_t))
#define UNALIGNED(X) ((rt_int32_t)X & (LBLOCKSIZE - 1))
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
int i;
char *m = (char *)s;
......@@ -125,10 +125,10 @@ void *rt_memset(void * s, int c, rt_ubase_t count)
rt_uint32_t *aligned_addr;
rt_uint32_t d = c & 0xff;
if (!TOO_SMALL (count) && !UNALIGNED (s))
if (!TOO_SMALL(count) && !UNALIGNED(s))
{
/* If we get this far, we know that n is large and m is word-aligned. */
aligned_addr = (rt_uint32_t*)s;
aligned_addr = (rt_uint32_t *)s;
/* Store D into each char sized location in BUFFER so that
* we can set large blocks quickly.
......@@ -160,8 +160,8 @@ void *rt_memset(void * s, int c, rt_ubase_t count)
count -= LBLOCKSIZE;
}
/* Pick up the remainder with a bytewise loop. */
m = (char*)aligned_addr;
/* Pick up the remainder with a bytewise loop. */
m = (char *)aligned_addr;
}
while (count--)
......@@ -188,10 +188,10 @@ void *rt_memset(void * s, int c, rt_ubase_t count)
* @return the address of destination memory
*
*/
void *rt_memcpy(void * dst, const void *src, rt_ubase_t count)
void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
{
#ifdef RT_TINY_SIZE
char *tmp = (char *) dst, *s = (char *) src;
char *tmp = (char *)dst, *s = (char *)src;
while (count--)
*tmp++ = *s++;
......@@ -200,25 +200,25 @@ void *rt_memcpy(void * dst, const void *src, rt_ubase_t count)
#else
#define UNALIGNED(X, Y) \
(((rt_int32_t)X & (sizeof (rt_int32_t) - 1)) | ((rt_int32_t)Y & (sizeof (rt_int32_t) - 1)))
#define BIGBLOCKSIZE (sizeof (rt_int32_t) << 2)
#define LITTLEBLOCKSIZE (sizeof (rt_int32_t))
(((rt_int32_t)X & (sizeof(rt_int32_t) - 1)) | ((rt_int32_t)Y & (sizeof(rt_int32_t) - 1)))
#define BIGBLOCKSIZE (sizeof(rt_int32_t) << 2)
#define LITTLEBLOCKSIZE (sizeof(rt_int32_t))
#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
char *dst_ptr = (char*)dst;
char *src_ptr = (char*)src;
char *dst_ptr = (char *)dst;
char *src_ptr = (char *)src;
rt_int32_t *aligned_dst;
rt_int32_t *aligned_src;
int len = count;
/* If the size is small, or either SRC or DST is unaligned,
then punt into the byte copy loop. This should be rare. */
if (!TOO_SMALL(len) && !UNALIGNED (src_ptr, dst_ptr))
then punt into the byte copy loop. This should be rare. */
if (!TOO_SMALL(len) && !UNALIGNED(src_ptr, dst_ptr))
{
aligned_dst = (rt_int32_t*)dst_ptr;
aligned_src = (rt_int32_t*)src_ptr;
aligned_dst = (rt_int32_t *)dst_ptr;
aligned_src = (rt_int32_t *)src_ptr;
/* Copy 4X long words at a time if possible. */
/* Copy 4X long words at a time if possible. */
while (len >= BIGBLOCKSIZE)
{
*aligned_dst++ = *aligned_src++;
......@@ -228,16 +228,16 @@ void *rt_memcpy(void * dst, const void *src, rt_ubase_t count)
len -= BIGBLOCKSIZE;
}
/* Copy one long word at a time if possible. */
/* Copy one long word at a time if possible. */
while (len >= LITTLEBLOCKSIZE)
{
*aligned_dst++ = *aligned_src++;
len -= LITTLEBLOCKSIZE;
}
/* Pick up any residual with a byte copier. */
dst_ptr = (char*)aligned_dst;
src_ptr = (char*)aligned_src;
/* Pick up any residual with a byte copier. */
dst_ptr = (char *)aligned_dst;
src_ptr = (char *)aligned_src;
}
while (len--)
......@@ -262,14 +262,14 @@ void *rt_memcpy(void * dst, const void *src, rt_ubase_t count)
* @return the address of destination memory
*
*/
void* rt_memmove(void *dest, const void *src, rt_ubase_t n)
void *rt_memmove(void *dest, const void *src, rt_ubase_t n)
{
char *tmp = (char *) dest, *s = (char *) src;
char *tmp = (char *)dest, *s = (char *)src;
if (s < tmp && tmp < s + n)
{
tmp+=n;
s+=n;
tmp += n;
s += n;
while (n--)
*tmp-- = *s--;
......@@ -284,17 +284,20 @@ void* rt_memmove(void *dest, const void *src, rt_ubase_t n)
}
/**
* memcmp - Compare two areas of memory
* @param cs: One area of memory
* @param ct: Another area of memory
* @param count: The size of the area.
* This function will compare two areas of memory
*
* @param cs one area of memory
* @param ct znother area of memory
* @param count the size of the area
*
* @return the result
*/
rt_int32_t rt_memcmp(const void * cs,const void * ct, rt_ubase_t count)
rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_ubase_t count)
{
const unsigned char *su1, *su2;
int res = 0;
for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
if ((res = *su1 - *su2) != 0)
break;
return res;
......@@ -308,20 +311,20 @@ rt_int32_t rt_memcmp(const void * cs,const void * ct, rt_ubase_t count)
*
* @return the first occurrence of a s2 in s1, or RT_NULL if no found.
*/
char * rt_strstr(const char * s1,const char * s2)
char *rt_strstr(const char *s1, const char *s2)
{
int l1, l2;
l2 = rt_strlen(s2);
if (!l2)
return (char *) s1;
return (char *)s1;
l1 = rt_strlen(s1);
while (l1 >= l2)
{
l1--;
if (!rt_memcmp(s1,s2,l2))
return (char *) s1;
s1++;
l1 --;
if (!rt_memcmp(s1, s2, l2))
return (char *)s1;
s1 ++;
}
return RT_NULL;
}
......@@ -363,9 +366,9 @@ rt_uint32_t rt_strcasecmp(const char *a, const char *b)
*/
char *rt_strncpy(char *dest, const char *src, rt_ubase_t n)
{
char *tmp = (char *) dest, *s = (char *) src;
char *tmp = (char *)dest, *s = (char *)src;
while(n--)
while (n--)
*tmp++ = *s++;
return dest;
......@@ -380,7 +383,7 @@ char *rt_strncpy(char *dest, const char *src, rt_ubase_t n)
*
* @return the result
*/
rt_ubase_t rt_strncmp(const char * cs, const char * ct, rt_ubase_t count)
rt_ubase_t rt_strncmp(const char *cs, const char *ct, rt_ubase_t count)
{
register signed char __res = 0;
......@@ -388,7 +391,7 @@ rt_ubase_t rt_strncmp(const char * cs, const char * ct, rt_ubase_t count)
{
if ((__res = *cs - *ct++) != 0 || !*cs++)
break;
count--;
count --;
}
return __res;
......@@ -402,7 +405,7 @@ rt_ubase_t rt_strncmp(const char * cs, const char * ct, rt_ubase_t count)
*
* @return the result
*/
rt_ubase_t rt_strcmp (const char *cs, const char *ct)
rt_ubase_t rt_strcmp(const char *cs, const char *ct)
{
while (*cs && *cs == *ct)
cs++, ct++;
......@@ -440,7 +443,7 @@ char *rt_strdup(const char *s)
rt_size_t len = rt_strlen(s) + 1;
char *tmp = (char *)rt_malloc(len);
if(!tmp) return RT_NULL;
if (!tmp) return RT_NULL;
rt_memcpy(tmp, s, len);
return tmp;
......@@ -450,7 +453,7 @@ char *rt_strdup(const char *s)
/**
* This function will show the version of rt-thread rtos
*/
void rt_show_version()
void rt_show_version(void)
{
rt_kprintf("\n \\ | /\n");
rt_kprintf("- RT - Thread Operating System\n");
......@@ -488,18 +491,18 @@ rt_inline int skip_atoi(const char **s)
return i;
}
#define ZEROPAD (1 << 0) /* pad with zero */
#define SIGN (1 << 1) /* unsigned/signed long */
#define PLUS (1 << 2) /* show plus */
#define SPACE (1 << 3) /* space if plus */
#define LEFT (1 << 4) /* left justified */
#define SPECIAL (1 << 5) /* 0x */
#define LARGE (1 << 6) /* use 'ABCDEF' instead of 'abcdef' */
#define ZEROPAD (1 << 0) /* pad with zero */
#define SIGN (1 << 1) /* unsigned/signed long */
#define PLUS (1 << 2) /* show plus */
#define SPACE (1 << 3) /* space if plus */
#define LEFT (1 << 4) /* left justified */
#define SPECIAL (1 << 5) /* 0x */
#define LARGE (1 << 6) /* use 'ABCDEF' instead of 'abcdef' */
#ifdef RT_PRINTF_PRECISION
static char *print_number(char * buf, char * end, long num, int base, int s, int precision, int type)
static char *print_number(char *buf, char *end, long num, int base, int s, int precision, int type)
#else
static char *print_number(char * buf, char * end, long num, int base, int s, int type)
static char *print_number(char *buf, char *end, long num, int base, int s, int type)
#endif
{
char c, sign;
......@@ -558,10 +561,10 @@ static char *print_number(char * buf, char * end, long num, int base, int s, int
if (!(type&(ZEROPAD | LEFT)))
{
while(size-->0)
while (size-->0)
{
if (buf <= end) *buf = ' ';
++buf;
++ buf;
}
}
......@@ -570,9 +573,9 @@ static char *print_number(char * buf, char * end, long num, int base, int s, int
if (buf <= end)
{
*buf = sign;
--size;
-- size;
}
++buf;
++ buf;
}
#ifdef RT_PRINTF_SPECIAL
......@@ -581,17 +584,17 @@ static char *print_number(char * buf, char * end, long num, int base, int s, int
if (base==8)
{
if (buf <= end) *buf = '0';
++buf;
++ buf;
}
else if (base==16)
else if (base == 16)
{
if (buf <= end) *buf = '0';
++buf;
++ buf;
if (buf <= end)
{
*buf = type & LARGE? 'X' : 'x';
}
++buf;
++ buf;
}
}
#endif
......@@ -602,7 +605,7 @@ static char *print_number(char * buf, char * end, long num, int base, int s, int
while (size-- > 0)
{
if (buf <= end) *buf = c;
++buf;
++ buf;
}
}
......@@ -610,7 +613,7 @@ static char *print_number(char * buf, char * end, long num, int base, int s, int
while (i < precision--)
{
if (buf <= end) *buf = '0';
++buf;
++ buf;
}
#endif
......@@ -618,13 +621,13 @@ static char *print_number(char * buf, char * end, long num, int base, int s, int
while (i-- > 0)
{
if (buf <= end) *buf = tmp[i];
++buf;
++ buf;
}
while (size-- > 0)
{
if (buf <= end) *buf = ' ';
++buf;
++ buf;
}
return buf;
......@@ -665,17 +668,17 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
if (*fmt != '%')
{
if (str <= end) *str = *fmt;
++str;
++ str;
continue;
}
/* process flags */
flags = 0;
while(1)
while (1)
{
/* skips the first '%' also */
++fmt;
++ fmt;
if (*fmt == '-') flags |= LEFT;
else if (*fmt == '+') flags |= PLUS;
else if (*fmt == ' ') flags |= SPACE;
......@@ -689,7 +692,7 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
if (isdigit(*fmt)) field_width = skip_atoi(&fmt);
else if (*fmt == '*')
{
++fmt;
++ fmt;
/* it's the next argument */
field_width = va_arg(args, int);
if (field_width < 0)
......@@ -704,11 +707,11 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
precision = -1;
if (*fmt == '.')
{
++fmt;
++ fmt;
if (isdigit(*fmt)) precision = skip_atoi(&fmt);
else if (*fmt == '*')
{
++fmt;
++ fmt;
/* it's the next argument */
precision = va_arg(args, int);
}
......@@ -724,12 +727,12 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
)
{
qualifier = *fmt;
++fmt;
++ fmt;
#ifdef RT_PRINTF_LONGLONG
if (qualifier == 'l' && *fmt == 'l')
{
qualifier = 'L';
++fmt;
++ fmt;
}
#endif
}
......@@ -745,20 +748,20 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
while (--field_width > 0)
{
if (str <= end) *str = ' ';
++str;
++ str;
}
}
/* get character */
c = (rt_uint8_t) va_arg(args, int);
c = (rt_uint8_t)va_arg(args, int);
if (str <= end) *str = c;
++str;
++ str;
/* put width */
while (--field_width > 0)
{
if (str <= end) *str = ' ';
++str;
++ str;
}
continue;
......@@ -776,21 +779,21 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
while (len < field_width--)
{
if (str <= end) *str = ' ';
++str;
++ str;
}
}
for (i = 0; i < len; ++i)
{
if (str <= end) *str = *s;
++str;
++s;
++ str;
++ s;
}
while (len < field_width--)
{
if (str <= end) *str = ' ';
++str;
++ str;
}
continue;
......@@ -802,18 +805,18 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
}
#ifdef RT_PRINTF_PRECISION
str = print_number(str, end,
(long) va_arg(args, void *),
(long)va_arg(args, void *),
16, field_width, precision, flags);
#else
str = print_number(str, end,
(long) va_arg(args, void *),
(long)va_arg(args, void *),
16, field_width, flags);
#endif
continue;
case '%':
if (str <= end) *str = '%';
++str;
++ str;
continue;
/* integer number formats - set up the flags and "break" */
......@@ -835,16 +838,16 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
default:
if (str <= end) *str = '%';
++str;
++ str;
if (*fmt)
{
if (str <= end) *str = *fmt;
++str;
++ str;
}
else
{
--fmt;
-- fmt;
}
continue;
}
......@@ -857,17 +860,17 @@ static rt_int32_t vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list
#endif
{
num = va_arg(args, rt_uint32_t);
if (flags & SIGN) num = (rt_int32_t) num;
if (flags & SIGN) num = (rt_int32_t)num;
}
else if (qualifier == 'h')
{
num = (rt_uint16_t) va_arg(args, rt_int32_t);
if (flags & SIGN) num = (rt_int16_t) num;
num = (rt_uint16_t)va_arg(args, rt_int32_t);
if (flags & SIGN) num = (rt_int16_t)num;
}
else
{
num = va_arg(args, rt_uint32_t);
if (flags & SIGN) num = (rt_int32_t) num;
if (flags & SIGN) num = (rt_int32_t)num;
}
#ifdef RT_PRINTF_PRECISION
str = print_number(str, end, num, base, field_width, precision, flags);
......@@ -922,14 +925,14 @@ rt_int32_t rt_vsprintf(char *buf, const char *format, va_list arg_ptr)
* @param buf the buffer to save formatted string
* @param format the format
*/
rt_int32_t rt_sprintf(char *buf ,const char *format,...)
rt_int32_t rt_sprintf(char *buf, const char *format, ...)
{
rt_int32_t n;
va_list arg_ptr;
va_start(arg_ptr, format);
n = rt_vsprintf(buf ,format,arg_ptr);
va_end (arg_ptr);
n = rt_vsprintf(buf ,format, arg_ptr);
va_end(arg_ptr);
return n;
}
......@@ -946,7 +949,7 @@ rt_int32_t rt_sprintf(char *buf ,const char *format,...)
*
* @return the old console device handler
*/
rt_device_t rt_console_set_device(const char* name)
rt_device_t rt_console_set_device(const char *name)
{
rt_device_t new, old;
......@@ -973,18 +976,18 @@ rt_device_t rt_console_set_device(const char* name)
#endif
#if defined(__GNUC__)
void rt_hw_console_output(const char* str) __attribute__((weak));
void rt_hw_console_output(const char* str)
void rt_hw_console_output(const char *str) __attribute__((weak));
void rt_hw_console_output(const char *str)
#elif defined(__CC_ARM)
__weak void rt_hw_console_output(const char* str)
__weak void rt_hw_console_output(const char *str)
#elif defined(__IAR_SYSTEMS_ICC__)
#if __VER__ > 540
__weak
#endif
void rt_hw_console_output(const char* str)
void rt_hw_console_output(const char *str)
#endif
{
/* empty console output */
/* empty console output */
}
/**
......@@ -1004,7 +1007,7 @@ void rt_kprintf(const char *fmt, ...)
#ifdef RT_USING_DEVICE
if (_console_device == RT_NULL)
{
rt_hw_console_output(rt_log_buf);
rt_hw_console_output(rt_log_buf);
}
else
{
......@@ -1023,9 +1026,9 @@ void rt_kprintf(const char *fmt, ...)
#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC) && defined (__GNUC__)
#include <sys/types.h>
void* memcpy(void *dest, const void *src, size_t n) __attribute__((weak, alias("rt_memcpy")));
void* memset(void *s, int c, size_t n) __attribute__((weak, alias("rt_memset")));
void* memmove(void *dest, const void *src, size_t n) __attribute__((weak, alias("rt_memmove")));
void *memcpy(void *dest, const void *src, size_t n) __attribute__((weak, alias("rt_memcpy")));
void *memset(void *s, int c, size_t n) __attribute__((weak, alias("rt_memset")));
void *memmove(void *dest, const void *src, size_t n) __attribute__((weak, alias("rt_memmove")));
int memcmp(const void *s1, const void *s2, size_t n) __attribute__((weak, alias("rt_memcmp")));
size_t strlen(const char *s) __attribute__((weak, alias("rt_strlen")));
......@@ -1037,7 +1040,7 @@ int strncmp(const char *cs, const char *ct, size_t count) __attribute__((weak, a
char *strdup(const char *s) __attribute__((weak, alias("rt_strdup")));
#endif
int sprintf(char * buf,const char * format,...) __attribute__((weak, alias("rt_sprintf")));
int sprintf(char *buf, const char *format, ...) __attribute__((weak, alias("rt_sprintf")));
int snprintf(char *buf, rt_size_t size, const char *fmt, ...) __attribute__((weak, alias("rt_snprintf")));
int vsprintf(char *buf, const char *format, va_list arg_ptr) __attribute__((weak, alias("rt_vsprintf")));
......
/*
* File : kservice.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......
/*
* File : mem.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2009, RT-Thread Development Team
* COPYRIGHT (C) 2008 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -165,7 +165,7 @@ static void plug_holes(struct heap_mem *mem)
* @param end_addr the end address of system page
*
*/
void rt_system_heap_init(void* begin_addr, void* end_addr)
void rt_system_heap_init(void *begin_addr, void *end_addr)
{
struct heap_mem *mem;
rt_uint32_t begin_align = RT_ALIGN((rt_uint32_t)begin_addr, RT_ALIGN_SIZE);
......@@ -174,12 +174,14 @@ void rt_system_heap_init(void* begin_addr, void* end_addr)
RT_DEBUG_NOT_IN_INTERRUPT;
/* alignment addr */
if((end_align > (2 * SIZEOF_STRUCT_MEM) ) &&
((end_align - 2 * SIZEOF_STRUCT_MEM) >= begin_align )) {
/* calculate the aligned memory size */
if ((end_align > (2 * SIZEOF_STRUCT_MEM)) &&
((end_align - 2 * SIZEOF_STRUCT_MEM) >= begin_align))
{
/* calculate the aligned memory size */
mem_size_aligned = end_align - begin_align - 2 * SIZEOF_STRUCT_MEM;
}
else {
else
{
rt_kprintf("mem init, error begin address 0x%x, and end address 0x%x\n", (rt_uint32_t)begin_addr, (rt_uint32_t)end_addr);
return;
}
......@@ -242,13 +244,13 @@ void *rt_malloc(rt_size_t size)
if (size > mem_size_aligned)
{
RT_DEBUG_LOG(RT_DEBUG_MEM,("no memory\n"));
RT_DEBUG_LOG(RT_DEBUG_MEM, ("no memory\n"));
return RT_NULL;
}
/* every data block must be at least MIN_SIZE_ALIGNED long */
if(size < MIN_SIZE_ALIGNED) size = MIN_SIZE_ALIGNED;
if (size < MIN_SIZE_ALIGNED) size = MIN_SIZE_ALIGNED;
/* take memory semaphore */
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
......@@ -258,8 +260,7 @@ void *rt_malloc(rt_size_t size)
{
mem = (struct heap_mem *)&heap_ptr[ptr];
if ((!mem->used) &&
(mem->next - (ptr + SIZEOF_STRUCT_MEM)) >= size)
if ((!mem->used) && (mem->next - (ptr + SIZEOF_STRUCT_MEM)) >= size)
{
/* mem is not used and at least perfect fit is possible:
* mem->next - (ptr + SIZEOF_STRUCT_MEM) gives us the 'user data size' of mem */
......@@ -328,9 +329,9 @@ void *rt_malloc(rt_size_t size)
RT_ASSERT((rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0);
RT_ASSERT((((rt_uint32_t)mem) & (RT_ALIGN_SIZE-1)) == 0);
RT_DEBUG_LOG(RT_DEBUG_MEM,("allocate memory at 0x%x, size: %d\n",
(rt_uint32_t)((rt_uint8_t*)mem + SIZEOF_STRUCT_MEM),
(rt_uint32_t)(mem->next - ((rt_uint8_t*)mem - heap_ptr))));
RT_DEBUG_LOG(RT_DEBUG_MEM, ("allocate memory at 0x%x, size: %d\n",
(rt_uint32_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM),
(rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
RT_OBJECT_HOOK_CALL(rt_malloc_hook, (((void*)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM)), size));
/* return the memory data except mem struct */
......@@ -355,7 +356,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
rt_size_t size;
rt_size_t ptr, ptr2;
struct heap_mem *mem, *mem2;
void* nmem;
void *nmem;
RT_DEBUG_NOT_IN_INTERRUPT;
......@@ -363,7 +364,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
newsize = RT_ALIGN(newsize, RT_ALIGN_SIZE);
if (newsize > mem_size_aligned)
{
RT_DEBUG_LOG(RT_DEBUG_MEM,("realloc: out of memory\n"));
RT_DEBUG_LOG(RT_DEBUG_MEM, ("realloc: out of memory\n"));
return RT_NULL;
}
......@@ -478,7 +479,7 @@ void rt_free(void *rmem)
if ((rt_uint8_t *)rmem < (rt_uint8_t *)heap_ptr || (rt_uint8_t *)rmem >= (rt_uint8_t *)heap_end)
{
RT_DEBUG_LOG(RT_DEBUG_MEM,("illegal memory\n"));
RT_DEBUG_LOG(RT_DEBUG_MEM, ("illegal memory\n"));
return;
}
......@@ -486,9 +487,9 @@ void rt_free(void *rmem)
/* Get the corresponding struct heap_mem ... */
mem = (struct heap_mem *)((rt_uint8_t *)rmem - SIZEOF_STRUCT_MEM);
RT_DEBUG_LOG(RT_DEBUG_MEM,("release memory 0x%x, size: %d\n",
RT_DEBUG_LOG(RT_DEBUG_MEM, ("release memory 0x%x, size: %d\n",
(rt_uint32_t)rmem,
(rt_uint32_t)(mem->next - ((rt_uint8_t*)mem - heap_ptr))));
(rt_uint32_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
/* protect the heap from concurrent access */
......@@ -517,9 +518,7 @@ void rt_free(void *rmem)
}
#ifdef RT_MEM_STATS
void rt_memory_info(rt_uint32_t *total,
rt_uint32_t *used,
rt_uint32_t *max_used)
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;
......@@ -528,7 +527,7 @@ void rt_memory_info(rt_uint32_t *total,
#ifdef RT_USING_FINSH
#include <finsh.h>
void list_mem()
void list_mem(void)
{
rt_kprintf("total memory: %d\n", mem_size_aligned);
rt_kprintf("used memory : %d\n", used_mem);
......
/*
* File : mempool.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -27,8 +27,8 @@
#ifdef RT_USING_MEMPOOL
#ifdef RT_USING_HOOK
static void (*rt_mp_alloc_hook)(struct rt_mempool* mp, void *block);
static void (*rt_mp_free_hook)(struct rt_mempool* mp, void *block);
static void (*rt_mp_alloc_hook)(struct rt_mempool *mp, void *block);
static void (*rt_mp_free_hook)(struct rt_mempool *mp, void *block);
/**
* @addtogroup Hook
......@@ -41,7 +41,7 @@ static void (*rt_mp_free_hook)(struct rt_mempool* mp, void *block);
*
* @param hook the hook function
*/
void rt_mp_alloc_sethook(void (*hook)(struct rt_mempool* mp, void *block))
void rt_mp_alloc_sethook(void (*hook)(struct rt_mempool *mp, void *block))
{
rt_mp_alloc_hook = hook;
}
......@@ -52,7 +52,7 @@ void rt_mp_alloc_sethook(void (*hook)(struct rt_mempool* mp, void *block))
*
* @param hook the hook function
*/
void rt_mp_free_sethook(void (*hook)(struct rt_mempool* mp, void *block))
void rt_mp_free_sethook(void (*hook)(struct rt_mempool *mp, void *block))
{
rt_mp_free_hook = hook;
}
......@@ -79,7 +79,7 @@ void rt_mp_free_sethook(void (*hook)(struct rt_mempool* mp, void *block))
* @return RT_EOK
*
*/
rt_err_t rt_mp_init(struct rt_mempool* mp, const char* name, void *start, rt_size_t size, rt_size_t block_size)
rt_err_t rt_mp_init(struct rt_mempool *mp, const char *name, void *start, rt_size_t size, rt_size_t block_size)
{
rt_uint8_t *block_ptr;
register rt_base_t offset;
......@@ -97,7 +97,7 @@ rt_err_t rt_mp_init(struct rt_mempool* mp, const char* name, void *start, rt_siz
mp->block_size = block_size;
/* align to align size byte */
mp->block_total_count = mp->size / (mp->block_size + sizeof(rt_uint8_t*));
mp->block_total_count = mp->size / (mp->block_size + sizeof(rt_uint8_t *));
mp->block_free_count = mp->block_total_count;
/* init suspended thread list */
......@@ -105,14 +105,14 @@ rt_err_t rt_mp_init(struct rt_mempool* mp, const char* name, void *start, rt_siz
mp->suspend_thread_count = 0;
/* init free block list */
block_ptr = (rt_uint8_t*) mp->start_address;
block_ptr = (rt_uint8_t *)mp->start_address;
for (offset = 0; offset < mp->block_total_count; offset ++)
{
*(rt_uint8_t**)(block_ptr + offset * (block_size + sizeof(rt_uint8_t*)))
= (rt_uint8_t*)(block_ptr + (offset + 1) * (block_size + sizeof(rt_uint8_t*)));
*(rt_uint8_t **)(block_ptr + offset * (block_size + sizeof(rt_uint8_t *)))
= (rt_uint8_t *)(block_ptr + (offset + 1) * (block_size + sizeof(rt_uint8_t *)));
}
*(rt_uint8_t**)(block_ptr + (offset - 1) * (block_size + sizeof(rt_uint8_t*))) = RT_NULL;
*(rt_uint8_t **)(block_ptr + (offset - 1) * (block_size + sizeof(rt_uint8_t *))) = RT_NULL;
mp->block_list = block_ptr;
......@@ -126,9 +126,9 @@ rt_err_t rt_mp_init(struct rt_mempool* mp, const char* name, void *start, rt_siz
*
* @return RT_EOK
*/
rt_err_t rt_mp_detach(struct rt_mempool* mp)
rt_err_t rt_mp_detach(struct rt_mempool *mp)
{
struct rt_thread* thread;
struct rt_thread *thread;
register rt_ubase_t temp;
/* parameter check */
......@@ -176,24 +176,24 @@ rt_err_t rt_mp_detach(struct rt_mempool* mp)
* @return the created mempool object
*
*/
rt_mp_t rt_mp_create(const char* name, rt_size_t block_count, rt_size_t block_size)
rt_mp_t rt_mp_create(const char *name, rt_size_t block_count, rt_size_t block_size)
{
rt_uint8_t *block_ptr;
struct rt_mempool* mp;
struct rt_mempool *mp;
register rt_base_t offset;
RT_DEBUG_NOT_IN_INTERRUPT;
/* allocate object */
mp = (struct rt_mempool*)rt_object_allocate(RT_Object_Class_MemPool, name);
mp = (struct rt_mempool *)rt_object_allocate(RT_Object_Class_MemPool, name);
if (mp == RT_NULL) return RT_NULL; /* allocate object failed */
/* init memory pool */
mp->block_size = RT_ALIGN(block_size, RT_ALIGN_SIZE);
mp->size = (block_size + sizeof(rt_uint8_t*))* block_count;
mp->size = (block_size + sizeof(rt_uint8_t *)) * block_count;
/* allocate memory */
mp->start_address = rt_malloc((block_size + sizeof(rt_uint8_t*))* block_count);
mp->start_address = rt_malloc((block_size + sizeof(rt_uint8_t *)) * block_count);
if (mp->start_address == RT_NULL)
{
/* no memory, delete memory pool object */
......@@ -210,14 +210,14 @@ rt_mp_t rt_mp_create(const char* name, rt_size_t block_count, rt_size_t block_si
mp->suspend_thread_count = 0;
/* init free block list */
block_ptr = (rt_uint8_t*) mp->start_address;
block_ptr = (rt_uint8_t *)mp->start_address;
for (offset = 0; offset < mp->block_total_count; offset ++)
{
*(rt_uint8_t**)(block_ptr + offset * (block_size + sizeof(rt_uint8_t*)))
= block_ptr + (offset + 1) * (block_size + sizeof(rt_uint8_t*));
*(rt_uint8_t **)(block_ptr + offset * (block_size + sizeof(rt_uint8_t *)))
= block_ptr + (offset + 1) * (block_size + sizeof(rt_uint8_t *));
}
*(rt_uint8_t**)(block_ptr + (offset - 1) * (block_size + sizeof(rt_uint8_t*))) = RT_NULL;
*(rt_uint8_t **)(block_ptr + (offset - 1) * (block_size + sizeof(rt_uint8_t *))) = RT_NULL;
mp->block_list = block_ptr;
......@@ -234,7 +234,7 @@ rt_mp_t rt_mp_create(const char* name, rt_size_t block_count, rt_size_t block_si
*/
rt_err_t rt_mp_delete(rt_mp_t mp)
{
struct rt_thread* thread;
struct rt_thread *thread;
register rt_ubase_t temp;
RT_DEBUG_NOT_IN_INTERRUPT;
......@@ -269,7 +269,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
#if defined(RT_USING_MODULE) && defined(RT_USING_SLAB)
/* the mp object belongs to an application module */
if(mp->parent.flag & RT_OBJECT_FLAG_MODULE)
if (mp->parent.flag & RT_OBJECT_FLAG_MODULE)
rt_module_free(mp->parent.module_id, mp->start_address);
else
#endif
......@@ -293,26 +293,26 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
* @return the allocated memory block or RT_NULL on allocated failed
*
*/
void *rt_mp_alloc (rt_mp_t mp, rt_int32_t time)
void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
{
rt_uint8_t* block_ptr;
rt_uint8_t *block_ptr;
register rt_base_t level;
struct rt_thread* thread;
struct rt_thread *thread;
/* disable interrupt */
level = rt_hw_interrupt_disable();
if(mp->block_free_count)
if (mp->block_free_count)
{
/* memory block is available. decrease the free block counter */
mp->block_free_count--;
mp->block_free_count --;
/* get block from block list */
block_ptr = mp->block_list;
mp->block_list = *(rt_uint8_t**)block_ptr;
mp->block_list = *(rt_uint8_t **)block_ptr;
/* point to memory pool */
*(rt_uint8_t**)block_ptr = (rt_uint8_t*)mp;
*(rt_uint8_t **)block_ptr = (rt_uint8_t *)mp;
}
else
{
......@@ -333,7 +333,7 @@ void *rt_mp_alloc (rt_mp_t mp, rt_int32_t time)
/* need suspend thread */
rt_thread_suspend(thread);
rt_list_insert_after(&(mp->suspend_thread), &(thread->tlist));
mp->suspend_thread_count++;
mp->suspend_thread_count ++;
if (time > 0)
{
......@@ -358,19 +358,19 @@ void *rt_mp_alloc (rt_mp_t mp, rt_int32_t time)
/* get block from block list */
block_ptr = mp->block_list;
mp->block_list = *(rt_uint8_t**)block_ptr;
mp->block_list = *(rt_uint8_t **)block_ptr;
/* point to memory pool */
*(rt_uint8_t**)block_ptr = (rt_uint8_t*)mp;
*(rt_uint8_t **)block_ptr = (rt_uint8_t *)mp;
}
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
RT_OBJECT_HOOK_CALL(rt_mp_alloc_hook, (mp, (rt_uint8_t*)(block_ptr + sizeof(rt_uint8_t*))));
RT_OBJECT_HOOK_CALL(rt_mp_alloc_hook, (mp, (rt_uint8_t *)(block_ptr + sizeof(rt_uint8_t *))));
return (rt_uint8_t*)(block_ptr + sizeof(rt_uint8_t*));
return (rt_uint8_t *)(block_ptr + sizeof(rt_uint8_t *));
}
/**
......@@ -379,7 +379,7 @@ void *rt_mp_alloc (rt_mp_t mp, rt_int32_t time)
* @param block the address of memory block to be released
*
*/
void rt_mp_free (void *block)
void rt_mp_free(void *block)
{
rt_uint8_t **block_ptr;
struct rt_mempool *mp;
......@@ -387,8 +387,8 @@ void rt_mp_free (void *block)
register rt_base_t level;
/* get the control block of pool which the block belongs to */
block_ptr = (rt_uint8_t**)((rt_uint8_t*)block - sizeof(rt_uint8_t*));
mp = (struct rt_mempool*) *block_ptr;
block_ptr = (rt_uint8_t **)((rt_uint8_t *)block - sizeof(rt_uint8_t *));
mp = (struct rt_mempool *)*block_ptr;
RT_OBJECT_HOOK_CALL(rt_mp_free_hook, (mp, block));
......@@ -400,7 +400,7 @@ void rt_mp_free (void *block)
/* link the block into the block list */
*block_ptr = mp->block_list;
mp->block_list = (rt_uint8_t*)block_ptr;
mp->block_list = (rt_uint8_t *)block_ptr;
if (mp->suspend_thread_count > 0)
{
......
此差异已折叠。
/*
* File : module.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2010-01-09 Bernard first version
* 2010-04-09 yi.qiu implement based on first version
*/
#ifndef __MODULE_H__
#define __MODULE_H__
#include <rtdef.h>
typedef rt_uint8_t Elf_Byte;
typedef rt_uint8_t Elf_Byte;
typedef rt_uint32_t Elf32_Addr; /* Unsigned program address */
typedef rt_uint32_t Elf32_Off; /* Unsigned file offset */
typedef rt_int32_t Elf32_Sword; /* Signed large integer */
typedef rt_uint32_t Elf32_Word; /* Unsigned large integer */
typedef rt_uint16_t Elf32_Half; /* Unsigned medium integer */
typedef rt_uint32_t Elf32_Addr; /* Unsigned program address */
typedef rt_uint32_t Elf32_Off; /* Unsigned file offset */
typedef rt_int32_t Elf32_Sword; /* Signed large integer */
typedef rt_uint32_t Elf32_Word; /* Unsigned large integer */
typedef rt_uint16_t Elf32_Half; /* Unsigned medium integer */
/* e_ident[] magic number */
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
#define RTMMAG "\177RTM" /* magic */
#define ELFMAG "\177ELF" /* magic */
#define SELFMAG 4 /* size of magic */
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
#define RTMMAG "\177RTM" /* magic */
#define ELFMAG "\177ELF" /* magic */
#define SELFMAG 4 /* size of magic */
#define EI_CLASS 4 /* file class */
#define EI_NIDENT 16 /* Size of e_ident[] */
#define EI_CLASS 4 /* file class */
#define EI_NIDENT 16 /* Size of e_ident[] */
/* e_ident[] file class */
#define ELFCLASSNONE 0 /* invalid */
#define ELFCLASS32 1 /* 32-bit objs */
#define ELFCLASS64 2 /* 64-bit objs */
#define ELFCLASSNUM 3 /* number of classes */
#define ELFCLASSNONE 0 /* invalid */
#define ELFCLASS32 1 /* 32-bit objs */
#define ELFCLASS64 2 /* 64-bit objs */
#define ELFCLASSNUM 3 /* number of classes */
/* e_ident[] data encoding */
#define ELFDATANONE 0 /* invalid */
#define ELFDATA2LSB 1 /* Little-Endian */
#define ELFDATA2MSB 2 /* Big-Endian */
#define ELFDATANUM 3 /* number of data encode defines */
#define ELFDATANONE 0 /* invalid */
#define ELFDATA2LSB 1 /* Little-Endian */
#define ELFDATA2MSB 2 /* Big-Endian */
#define ELFDATANUM 3 /* number of data encode defines */
/* e_ident */
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
......@@ -42,175 +57,181 @@ typedef rt_uint16_t Elf32_Half; /* Unsigned medium integer */
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
/* ELF Header */
typedef struct elfhdr {
unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
Elf32_Half e_type; /* object file type */
Elf32_Half e_machine; /* machine */
Elf32_Word e_version; /* object file version */
Elf32_Addr e_entry; /* virtual entry point */
Elf32_Off e_phoff; /* program header table offset */
Elf32_Off e_shoff; /* section header table offset */
Elf32_Word e_flags; /* processor-specific flags */
Elf32_Half e_ehsize; /* ELF header size */
Elf32_Half e_phentsize; /* program header entry size */
Elf32_Half e_phnum; /* number of program header entries */
Elf32_Half e_shentsize; /* section header entry size */
Elf32_Half e_shnum; /* number of section header entries */
Elf32_Half e_shstrndx; /* section header table's "section
header string table" entry offset */
typedef struct elfhdr
{
unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
Elf32_Half e_type; /* object file type */
Elf32_Half e_machine; /* machine */
Elf32_Word e_version; /* object file version */
Elf32_Addr e_entry; /* virtual entry point */
Elf32_Off e_phoff; /* program header table offset */
Elf32_Off e_shoff; /* section header table offset */
Elf32_Word e_flags; /* processor-specific flags */
Elf32_Half e_ehsize; /* ELF header size */
Elf32_Half e_phentsize; /* program header entry size */
Elf32_Half e_phnum; /* number of program header entries */
Elf32_Half e_shentsize; /* section header entry size */
Elf32_Half e_shnum; /* number of section header entries */
Elf32_Half e_shstrndx; /* section header table's "section
header string table" entry offset */
} Elf32_Ehdr;
/* Section Header */
typedef struct {
Elf32_Word sh_name; /* name - index into section header
string table section */
Elf32_Word sh_type; /* type */
Elf32_Word sh_flags; /* flags */
Elf32_Addr sh_addr; /* address */
Elf32_Off sh_offset; /* file offset */
Elf32_Word sh_size; /* section size */
Elf32_Word sh_link; /* section header table index link */
Elf32_Word sh_info; /* extra information */
Elf32_Word sh_addralign; /* address alignment */
Elf32_Word sh_entsize; /* section entry size */
typedef struct
{
Elf32_Word sh_name; /* name - index into section header
string table section */
Elf32_Word sh_type; /* type */
Elf32_Word sh_flags; /* flags */
Elf32_Addr sh_addr; /* address */
Elf32_Off sh_offset; /* file offset */
Elf32_Word sh_size; /* section size */
Elf32_Word sh_link; /* section header table index link */
Elf32_Word sh_info; /* extra information */
Elf32_Word sh_addralign; /* address alignment */
Elf32_Word sh_entsize; /* section entry size */
} Elf32_Shdr;
/* Section names */
#define ELF_BSS ".bss" /* uninitialized data */
#define ELF_DATA ".data" /* initialized data */
#define ELF_DEBUG ".debug" /* debug */
#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
#define ELF_DYNSTR ".dynstr" /* dynamic string table */
#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
#define ELF_FINI ".fini" /* termination code */
#define ELF_GOT ".got" /* global offset table */
#define ELF_HASH ".hash" /* symbol hash table */
#define ELF_INIT ".init" /* initialization code */
#define ELF_REL_DATA ".rel.data" /* relocation data */
#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
#define ELF_REL_TEXT ".rel.text" /* relocation code */
#define ELF_RODATA ".rodata" /* read-only data */
#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
#define ELF_STRTAB ".strtab" /* string table */
#define ELF_SYMTAB ".symtab" /* symbol table */
#define ELF_TEXT ".text" /* code */
#define ELF_RTMSYMTAB "RTMSymTab"
#define ELF_BSS ".bss" /* uninitialized data */
#define ELF_DATA ".data" /* initialized data */
#define ELF_DEBUG ".debug" /* debug */
#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
#define ELF_DYNSTR ".dynstr" /* dynamic string table */
#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
#define ELF_FINI ".fini" /* termination code */
#define ELF_GOT ".got" /* global offset table */
#define ELF_HASH ".hash" /* symbol hash table */
#define ELF_INIT ".init" /* initialization code */
#define ELF_REL_DATA ".rel.data" /* relocation data */
#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
#define ELF_REL_TEXT ".rel.text" /* relocation code */
#define ELF_RODATA ".rodata" /* read-only data */
#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
#define ELF_STRTAB ".strtab" /* string table */
#define ELF_SYMTAB ".symtab" /* symbol table */
#define ELF_TEXT ".text" /* code */
#define ELF_RTMSYMTAB "RTMSymTab"
/* Symbol Table Entry */
typedef struct elf32_sym {
Elf32_Word st_name; /* name - index into string table */
Elf32_Addr st_value; /* symbol value */
Elf32_Word st_size; /* symbol size */
unsigned char st_info; /* type and binding */
unsigned char st_other; /* 0 - no defined meaning */
Elf32_Half st_shndx; /* section header index */
typedef struct elf32_sym
{
Elf32_Word st_name; /* name - index into string table */
Elf32_Addr st_value; /* symbol value */
Elf32_Word st_size; /* symbol size */
unsigned char st_info; /* type and binding */
unsigned char st_other; /* 0 - no defined meaning */
Elf32_Half st_shndx; /* section header index */
} Elf32_Sym;
#define STB_LOCAL 0 /* BIND */
#define STB_GLOBAL 1
#define STB_WEAK 2
#define STB_NUM 3
#define STB_LOCAL 0 /* BIND */
#define STB_GLOBAL 1
#define STB_WEAK 2
#define STB_NUM 3
#define STB_LOPROC 13 /* processor specific range */
#define STB_HIPROC 15
#define STT_NOTYPE 0 /* symbol type is unspecified */
#define STT_OBJECT 1 /* data object */
#define STT_FUNC 2 /* code object */
#define STT_SECTION 3 /* symbol identifies an ELF section */
#define STT_FILE 4 /* symbol's name is file name */
#define STT_COMMON 5 /* common data object */
#define STT_TLS 6 /* thread-local data object */
#define STT_NUM 7 /* # defined types in generic range */
#define STT_LOOS 10 /* OS specific range */
#define STT_HIOS 12
#define STT_LOPROC 13 /* processor specific range */
#define STT_HIPROC 15
#define STB_LOPROC 13 /* processor specific range */
#define STB_HIPROC 15
#define STT_NOTYPE 0 /* symbol type is unspecified */
#define STT_OBJECT 1 /* data object */
#define STT_FUNC 2 /* code object */
#define STT_SECTION 3 /* symbol identifies an ELF section */
#define STT_FILE 4 /* symbol's name is file name */
#define STT_COMMON 5 /* common data object */
#define STT_TLS 6 /* thread-local data object */
#define STT_NUM 7 /* # defined types in generic range */
#define STT_LOOS 10 /* OS specific range */
#define STT_HIOS 12
#define STT_LOPROC 13 /* processor specific range */
#define STT_HIPROC 15
#define ELF_ST_BIND(info) ((info) >> 4)
#define ELF_ST_TYPE(info) ((info) & 0xf)
#define ELF_ST_INFO(bind, type) (((bind)<<4)+((type)&0xf))
#define ELF_ST_BIND(info) ((info) >> 4)
#define ELF_ST_TYPE(info) ((info) & 0xf)
#define ELF_ST_INFO(bind, type) (((bind)<<4)+((type)&0xf))
/* Relocation entry with implicit addend */
typedef struct {
Elf32_Addr r_offset; /* offset of relocation */
Elf32_Word r_info; /* symbol table index and type */
typedef struct
{
Elf32_Addr r_offset; /* offset of relocation */
Elf32_Word r_info; /* symbol table index and type */
} Elf32_Rel;
/* Relocation entry with explicit addend */
typedef struct {
Elf32_Addr r_offset; /* offset of relocation */
Elf32_Word r_info; /* symbol table index and type */
Elf32_Sword r_addend;
typedef struct
{
Elf32_Addr r_offset; /* offset of relocation */
Elf32_Word r_info; /* symbol table index and type */
Elf32_Sword r_addend;
} Elf32_Rela;
/* Extract relocation info - r_info */
#define ELF32_R_SYM(i) ((i) >> 8)
#define ELF32_R_TYPE(i) ((unsigned char) (i))
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
#define ELF32_R_SYM(i) ((i) >> 8)
#define ELF32_R_TYPE(i) ((unsigned char) (i))
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
/*
* Relocation type for arm
*/
#define R_ARM_NONE 0
#define R_ARM_PC24 1
#define R_ARM_ABS32 2
#define R_ARM_GLOB_DAT 21
#define R_ARM_JUMP_SLOT 22
#define R_ARM_RELATIVE 23
#define R_ARM_PLT32 27
#define R_ARM_CALL 28
#define R_ARM_JUMP24 29
#define R_ARM_V4BX 40
#define R_ARM_NONE 0
#define R_ARM_PC24 1
#define R_ARM_ABS32 2
#define R_ARM_GLOB_DAT 21
#define R_ARM_JUMP_SLOT 22
#define R_ARM_RELATIVE 23
#define R_ARM_PLT32 27
#define R_ARM_CALL 28
#define R_ARM_JUMP24 29
#define R_ARM_V4BX 40
/* Program Header */
typedef struct {
Elf32_Word p_type; /* segment type */
Elf32_Off p_offset; /* segment offset */
Elf32_Addr p_vaddr; /* virtual address of segment */
Elf32_Addr p_paddr; /* physical address - ignored? */
Elf32_Word p_filesz; /* number of bytes in file for seg. */
Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
Elf32_Word p_flags; /* flags */
Elf32_Word p_align; /* memory alignment */
typedef struct
{
Elf32_Word p_type; /* segment type */
Elf32_Off p_offset; /* segment offset */
Elf32_Addr p_vaddr; /* virtual address of segment */
Elf32_Addr p_paddr; /* physical address - ignored? */
Elf32_Word p_filesz; /* number of bytes in file for seg. */
Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
Elf32_Word p_flags; /* flags */
Elf32_Word p_align; /* memory alignment */
} Elf32_Phdr;
/* p_type */
#define PT_LOAD 1
#define PT_LOAD 1
/* p_flags */
#define PF_X 1
#define PF_W 2
#define PF_R 4
#define PF_X 1
#define PF_W 2
#define PF_R 4
/* sh_type */
#define SHT_NULL 0 /* inactive */
#define SHT_PROGBITS 1 /* program defined information */
#define SHT_SYMTAB 2 /* symbol table section */
#define SHT_STRTAB 3 /* string table section */
#define SHT_RELA 4 /* relocation section with addends*/
#define SHT_HASH 5 /* symbol hash table section */
#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_SHLIB 10 /* reserved - purpose unknown */
#define SHT_DYNSYM 11 /* dynamic symbol table section */
#define SHT_NUM 12 /* number of section types */
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
#define SHT_HIPROC 0x7fffffff /* specific section header types */
#define SHT_LOUSER 0x80000000 /* reserved range for application */
#define SHT_HIUSER 0xffffffff /* specific indexes */
#define SHT_NULL 0 /* inactive */
#define SHT_PROGBITS 1 /* program defined information */
#define SHT_SYMTAB 2 /* symbol table section */
#define SHT_STRTAB 3 /* string table section */
#define SHT_RELA 4 /* relocation section with addends*/
#define SHT_HASH 5 /* symbol hash table section */
#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_SHLIB 10 /* reserved - purpose unknown */
#define SHT_DYNSYM 11 /* dynamic symbol table section */
#define SHT_NUM 12 /* number of section types */
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
#define SHT_HIPROC 0x7fffffff /* specific section header types */
#define SHT_LOUSER 0x80000000 /* reserved range for application */
#define SHT_HIUSER 0xffffffff /* specific indexes */
/* Section Attribute Flags - sh_flags */
#define SHF_WRITE 0x1 /* Writable */
#define SHF_ALLOC 0x2 /* occupies memory */
#define SHF_EXECINSTR 0x4 /* executable */
#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
/* specific section attributes */
#define SHF_WRITE 0x1 /* Writable */
#define SHF_ALLOC 0x2 /* occupies memory */
#define SHF_EXECINSTR 0x4 /* executable */
#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
/* specific section attributes */
#endif
/*
* File : object.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -65,11 +65,11 @@ struct rt_object_information rt_object_container[RT_Object_Class_Unknown] =
};
#ifdef RT_USING_HOOK
static void (*rt_object_attach_hook)(struct rt_object* object);
static void (*rt_object_detach_hook)(struct rt_object* object);
void (*rt_object_trytake_hook)(struct rt_object* object);
void (*rt_object_take_hook)(struct rt_object* object);
void (*rt_object_put_hook)(struct rt_object* object);
static void (*rt_object_attach_hook)(struct rt_object *object);
static void (*rt_object_detach_hook)(struct rt_object *object);
void (*rt_object_trytake_hook)(struct rt_object *object);
void (*rt_object_take_hook)(struct rt_object *object);
void (*rt_object_put_hook)(struct rt_object *object);
/**
* @addtogroup Hook
......@@ -82,7 +82,7 @@ void (*rt_object_put_hook)(struct rt_object* object);
*
* @param hook the hook function
*/
void rt_object_attach_sethook(void (*hook)(struct rt_object* object))
void rt_object_attach_sethook(void (*hook)(struct rt_object *object))
{
rt_object_attach_hook = hook;
}
......@@ -93,7 +93,7 @@ void rt_object_attach_sethook(void (*hook)(struct rt_object* object))
*
* @param hook the hook function
*/
void rt_object_detach_sethook(void (*hook)(struct rt_object* object))
void rt_object_detach_sethook(void (*hook)(struct rt_object *object))
{
rt_object_detach_hook = hook;
}
......@@ -111,7 +111,7 @@ void rt_object_detach_sethook(void (*hook)(struct rt_object* object))
*
* @param hook the hook function
*/
void rt_object_trytake_sethook(void (*hook)(struct rt_object* object))
void rt_object_trytake_sethook(void (*hook)(struct rt_object *object))
{
rt_object_trytake_hook = hook;
}
......@@ -130,7 +130,7 @@ void rt_object_trytake_sethook(void (*hook)(struct rt_object* object))
*
* @param hook the hook function
*/
void rt_object_take_sethook(void (*hook)(struct rt_object* object))
void rt_object_take_sethook(void (*hook)(struct rt_object *object))
{
rt_object_take_hook = hook;
}
......@@ -141,7 +141,7 @@ void rt_object_take_sethook(void (*hook)(struct rt_object* object))
*
* @param hook the hook function
*/
void rt_object_put_sethook(void (*hook)(struct rt_object* object))
void rt_object_put_sethook(void (*hook)(struct rt_object *object))
{
rt_object_put_hook = hook;
}
......@@ -184,7 +184,7 @@ struct rt_object_information *rt_object_get_information(enum rt_object_class_typ
* @param type the object type.
* @param name the object name. In system, the object's name must be unique.
*/
void rt_object_init(struct rt_object* object, enum rt_object_class_type type, const char* name)
void rt_object_init(struct rt_object *object, enum rt_object_class_type type, const char *name)
{
register rt_base_t temp;
struct rt_object_information* information;
......@@ -255,11 +255,11 @@ void rt_object_detach(rt_object_t object)
*
* @return object
*/
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name)
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
{
struct rt_object* object;
struct rt_object *object;
register rt_base_t temp;
struct rt_object_information* information;
struct rt_object_information *information;
RT_DEBUG_NOT_IN_INTERRUPT;
......@@ -272,7 +272,7 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name)
information = &rt_object_container[type];
#endif
object = (struct rt_object*)rt_malloc(information->object_size);
object = (struct rt_object *)rt_malloc(information->object_size);
if (object == RT_NULL)
{
/* no memory can be allocated */
......@@ -288,11 +288,11 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name)
object->flag = 0;
#ifdef RT_USING_MODULE
if(rt_module_self() != RT_NULL)
if (rt_module_self() != RT_NULL)
{
object->flag |= RT_OBJECT_FLAG_MODULE;
}
object->module_id = (void*)rt_module_self();
object->module_id = (void *)rt_module_self();
#endif
/* copy name */
......@@ -341,7 +341,7 @@ void rt_object_delete(rt_object_t object)
rt_hw_interrupt_enable(temp);
#if defined(RT_USING_MODULE) && defined(RT_USING_SLAB)
if(object->flag & RT_OBJECT_FLAG_MODULE)
if (object->flag & RT_OBJECT_FLAG_MODULE)
rt_module_free((rt_module_t)object->module_id, object);
else
#endif
......@@ -382,16 +382,15 @@ rt_err_t rt_object_is_systemobject(rt_object_t object)
*
* @note this function shall not be invoked in interrupt status.
*/
rt_object_t rt_object_find(const char* name, rt_uint8_t type)
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 *object;
struct rt_list_node *node;
struct rt_object_information *information;
extern volatile rt_uint8_t rt_interrupt_nest;
/* parameter check */
if ((name == RT_NULL) ||
(type > RT_Object_Class_Unknown))
if ((name == RT_NULL) || (type > RT_Object_Class_Unknown))
return RT_NULL;
/* which is invoke in interrupt status */
......
/*
* File : rtm.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2010-04-12 yi.qiu first version
* Date Author Notes
* 2010-04-12 yi.qiu first version
*/
#include <rtthread.h>
#include <rtthread.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
......@@ -25,7 +25,7 @@
RTM_EXPORT(rt_object_get_information);
/*
* thread interface symbol
* thread interface symbol
*/
RTM_EXPORT(rt_thread_init);
......@@ -79,7 +79,7 @@ RTM_EXPORT(rt_event_create);
RTM_EXPORT(rt_event_delete);
RTM_EXPORT(rt_event_send);
RTM_EXPORT(rt_event_recv);
RTM_EXPORT(rt_event_control);
RTM_EXPORT(rt_event_control);
#endif
#ifdef RT_USING_MAILBOX
......@@ -92,7 +92,7 @@ RTM_EXPORT(rt_mb_create);
RTM_EXPORT(rt_mb_delete);
RTM_EXPORT(rt_mb_send);
RTM_EXPORT(rt_mb_recv);
RTM_EXPORT(rt_mb_control);
RTM_EXPORT(rt_mb_control);
#endif
#ifdef RT_USING_MESSAGEQUEUE
......@@ -105,8 +105,8 @@ RTM_EXPORT(rt_mq_create);
RTM_EXPORT(rt_mq_delete);
RTM_EXPORT(rt_mq_send);
RTM_EXPORT(rt_mq_urgent);
RTM_EXPORT(rt_mq_recv);
RTM_EXPORT(rt_mq_control);
RTM_EXPORT(rt_mq_recv);
RTM_EXPORT(rt_mq_control);
#endif
#ifdef RT_USING_MEMPOOL
......@@ -159,8 +159,8 @@ RTM_EXPORT(rt_snprintf);
/*
* misc interface symbol
*/
extern int __aeabi_idiv;
extern int __aeabi_ddiv;
extern int __aeabi_idiv;
extern int __aeabi_ddiv;
extern int __aeabi_dmul;
extern int __aeabi_i2d;
extern int __aeabi_uidiv;
......
/*
* File : scheduler.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -35,7 +35,7 @@ static rt_int16_t rt_scheduler_lock_nest;
extern volatile rt_uint8_t rt_interrupt_nest;
rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
struct rt_thread* rt_current_thread;
struct rt_thread *rt_current_thread;
rt_uint8_t rt_current_priority;
......@@ -71,7 +71,7 @@ const rt_uint8_t rt_lowest_bitmap[] =
};
#ifdef RT_USING_HOOK
static void (*rt_scheduler_hook)(struct rt_thread* from, struct rt_thread* to);
static void (*rt_scheduler_hook)(struct rt_thread *from, struct rt_thread *to);
/**
* @addtogroup Hook
......@@ -84,40 +84,39 @@ static void (*rt_scheduler_hook)(struct rt_thread* from, struct rt_thread* to);
*
* @param hook the hook function
*/
void rt_scheduler_sethook(void (*hook)(struct rt_thread* from, struct rt_thread* to))
void rt_scheduler_sethook(void (*hook)(struct rt_thread *from, struct rt_thread *to))
{
rt_scheduler_hook = hook;
rt_scheduler_hook = hook;
}
/*@}*/
#endif
#ifdef RT_USING_OVERFLOW_CHECK
static void _rt_scheduler_stack_check(struct rt_thread* thread)
static void _rt_scheduler_stack_check(struct rt_thread *thread)
{
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(thread != RT_NULL);
if ( (rt_uint32_t)thread->sp <= (rt_uint32_t)thread->stack_addr ||
(rt_uint32_t)thread->sp >
(rt_uint32_t)thread->stack_addr + (rt_uint32_t)thread->stack_size )
{
rt_uint32_t level;
if ((rt_uint32_t)thread->sp <= (rt_uint32_t)thread->stack_addr ||
(rt_uint32_t)thread->sp >
(rt_uint32_t)thread->stack_addr + (rt_uint32_t)thread->stack_size)
{
rt_uint32_t level;
rt_kprintf("thread:%s stack overflow\n", thread->name);
rt_kprintf("thread:%s stack overflow\n", thread->name);
#ifdef RT_USING_FINSH
{
extern long list_thread(void);
list_thread();
}
#endif
level = rt_hw_interrupt_disable();
while (level);
}
else if ((rt_uint32_t)thread->sp <= ((rt_uint32_t)thread->stack_addr + 32))
{
rt_kprintf("warning: %s stack is close to end of stack address.\n",
thread->name);
}
level = rt_hw_interrupt_disable();
while (level);
}
else if ((rt_uint32_t)thread->sp <= ((rt_uint32_t)thread->stack_addr + 32))
{
rt_kprintf("warning: %s stack is close to end of stack address.\n", thread->name);
}
}
#endif
......@@ -128,31 +127,31 @@ static void _rt_scheduler_stack_check(struct rt_thread* thread)
*/
void rt_system_scheduler_init(void)
{
register rt_base_t offset;
register rt_base_t offset;
rt_scheduler_lock_nest = 0;
rt_scheduler_lock_nest = 0;
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
("start scheduler: max priority 0x%02x\n", RT_THREAD_PRIORITY_MAX));
for (offset = 0; offset < RT_THREAD_PRIORITY_MAX; offset ++)
{
rt_list_init(&rt_thread_priority_table[offset]);
}
for (offset = 0; offset < RT_THREAD_PRIORITY_MAX; offset ++)
{
rt_list_init(&rt_thread_priority_table[offset]);
}
rt_current_priority = RT_THREAD_PRIORITY_MAX - 1;
rt_current_thread = RT_NULL;
rt_current_priority = RT_THREAD_PRIORITY_MAX - 1;
rt_current_thread = RT_NULL;
/* init ready priority group */
rt_thread_ready_priority_group = 0;
/* init ready priority group */
rt_thread_ready_priority_group = 0;
#if RT_THREAD_PRIORITY_MAX > 32
/* init ready table */
rt_memset(rt_thread_ready_table, 0, sizeof(rt_thread_ready_table));
/* init ready table */
rt_memset(rt_thread_ready_table, 0, sizeof(rt_thread_ready_table));
#endif
/* init thread defunct */
rt_list_init(&rt_thread_defunct);
/* init thread defunct */
rt_list_init(&rt_thread_defunct);
}
/**
......@@ -160,50 +159,50 @@ void rt_system_scheduler_init(void)
* This function will startup scheduler. It will select one thread
* with the highest priority level, then switch to it.
*/
void rt_system_scheduler_start()
void rt_system_scheduler_start(void)
{
register struct rt_thread *to_thread;
register rt_ubase_t highest_ready_priority;
register struct rt_thread *to_thread;
register rt_ubase_t highest_ready_priority;
#if RT_THREAD_PRIORITY_MAX == 8
highest_ready_priority = rt_lowest_bitmap[rt_thread_ready_priority_group];
#else
register rt_ubase_t number;
/* find out the highest priority task */
if (rt_thread_ready_priority_group & 0xff)
{
number = rt_lowest_bitmap[rt_thread_ready_priority_group & 0xff];
}
else if (rt_thread_ready_priority_group & 0xff00)
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 8) & 0xff] + 8;
}
else if (rt_thread_ready_priority_group & 0xff0000)
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 16) & 0xff] + 16;
}
else
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 24) & 0xff] + 24;
}
register rt_ubase_t number;
/* find out the highest priority task */
if (rt_thread_ready_priority_group & 0xff)
{
number = rt_lowest_bitmap[rt_thread_ready_priority_group & 0xff];
}
else if (rt_thread_ready_priority_group & 0xff00)
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 8) & 0xff] + 8;
}
else if (rt_thread_ready_priority_group & 0xff0000)
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 16) & 0xff] + 16;
}
else
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 24) & 0xff] + 24;
}
#if RT_THREAD_PRIORITY_MAX > 32
highest_ready_priority = (number << 3) + rt_lowest_bitmap[rt_thread_ready_table[number]];
highest_ready_priority = (number << 3) + rt_lowest_bitmap[rt_thread_ready_table[number]];
#else
highest_ready_priority = number;
highest_ready_priority = number;
#endif
#endif
/* get switch to thread */
to_thread = rt_list_entry(rt_thread_priority_table[highest_ready_priority].next,
struct rt_thread, tlist);
/* get switch to thread */
to_thread = rt_list_entry(rt_thread_priority_table[highest_ready_priority].next,
struct rt_thread, tlist);
rt_current_thread = to_thread;
rt_current_thread = to_thread;
/* switch to new thread */
rt_hw_context_switch_to((rt_uint32_t)&to_thread->sp);
/* switch to new thread */
rt_hw_context_switch_to((rt_uint32_t)&to_thread->sp);
/* never come back */
/* never come back */
}
/**
......@@ -215,91 +214,90 @@ void rt_system_scheduler_start()
* This function will perform one schedule. It will select one thread
* with the highest priority level, then switch to it.
*/
void rt_schedule()
void rt_schedule(void)
{
rt_base_t level;
struct rt_thread *to_thread;
struct rt_thread *from_thread;
rt_base_t level;
struct rt_thread *to_thread;
struct rt_thread *from_thread;
/* disable interrupt */
level = rt_hw_interrupt_disable();
/* disable interrupt */
level = rt_hw_interrupt_disable();
/* check the scheduler is enabled or not */
if (rt_scheduler_lock_nest == 0)
{
register rt_ubase_t highest_ready_priority;
/* check the scheduler is enabled or not */
if (rt_scheduler_lock_nest == 0)
{
register rt_ubase_t highest_ready_priority;
#if RT_THREAD_PRIORITY_MAX == 8
highest_ready_priority = rt_lowest_bitmap[rt_thread_ready_priority_group];
#else
register rt_ubase_t number;
/* find out the highest priority task */
if (rt_thread_ready_priority_group & 0xff)
{
number = rt_lowest_bitmap[rt_thread_ready_priority_group & 0xff];
}
else if (rt_thread_ready_priority_group & 0xff00)
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 8) & 0xff] + 8;
}
else if (rt_thread_ready_priority_group & 0xff0000)
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 16) & 0xff] + 16;
}
else
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 24) & 0xff] + 24;
}
register rt_ubase_t number;
/* find out the highest priority task */
if (rt_thread_ready_priority_group & 0xff)
{
number = rt_lowest_bitmap[rt_thread_ready_priority_group & 0xff];
}
else if (rt_thread_ready_priority_group & 0xff00)
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 8) & 0xff] + 8;
}
else if (rt_thread_ready_priority_group & 0xff0000)
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 16) & 0xff] + 16;
}
else
{
number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 24) & 0xff] + 24;
}
#if RT_THREAD_PRIORITY_MAX > 32
highest_ready_priority = (number << 3) + rt_lowest_bitmap[rt_thread_ready_table[number]];
highest_ready_priority = (number << 3) + rt_lowest_bitmap[rt_thread_ready_table[number]];
#else
highest_ready_priority = number;
highest_ready_priority = number;
#endif
#endif
/* get switch to thread */
to_thread = rt_list_entry(rt_thread_priority_table[highest_ready_priority].next,
struct rt_thread, tlist);
/* get switch to thread */
to_thread = rt_list_entry(rt_thread_priority_table[highest_ready_priority].next,
struct rt_thread, tlist);
/* if the destination thread is not the same as current thread */
if (to_thread != rt_current_thread)
{
rt_current_priority = highest_ready_priority;
from_thread = rt_current_thread;
rt_current_thread = to_thread;
/* if the destination thread is not the same as current thread */
if (to_thread != rt_current_thread)
{
rt_current_priority = highest_ready_priority;
from_thread = rt_current_thread;
rt_current_thread = to_thread;
#ifdef RT_USING_MODULE
rt_module_set ((rt_current_thread->module_id != RT_NULL) ?
(rt_module_t)rt_current_thread->module_id : RT_NULL);
rt_module_set((rt_current_thread->module_id != RT_NULL) ?
(rt_module_t)rt_current_thread->module_id : RT_NULL);
#endif
RT_OBJECT_HOOK_CALL(rt_scheduler_hook, (from_thread, to_thread));
/* switch to new thread */
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
("[%d]switch to priority#%d thread:%s\n", rt_interrupt_nest,
highest_ready_priority, to_thread->name));
/* switch to new thread */
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,
("[%d]switch to priority#%d thread:%s\n", rt_interrupt_nest,
highest_ready_priority, to_thread->name));
#ifdef RT_USING_OVERFLOW_CHECK
_rt_scheduler_stack_check(to_thread);
_rt_scheduler_stack_check(to_thread);
#endif
if (rt_interrupt_nest == 0)
{
rt_hw_context_switch((rt_uint32_t)&from_thread->sp, (rt_uint32_t)&to_thread->sp);
}
else
{
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER,("switch in interrupt\n"));
rt_hw_context_switch_interrupt((rt_uint32_t)&from_thread->sp,
(rt_uint32_t)&to_thread->sp);
}
}
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
if (rt_interrupt_nest == 0)
{
rt_hw_context_switch((rt_uint32_t)&from_thread->sp, (rt_uint32_t)&to_thread->sp);
}
else
{
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("switch in interrupt\n"));
rt_hw_context_switch_interrupt((rt_uint32_t)&from_thread->sp, (rt_uint32_t)&to_thread->sp);
}
}
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
}
/*
......@@ -309,38 +307,37 @@ void rt_schedule()
* @param thread the thread to be inserted
* @note Please do not invoke this function in user application.
*/
void rt_schedule_insert_thread(struct rt_thread* thread)
void rt_schedule_insert_thread(struct rt_thread *thread)
{
register rt_base_t temp;
register rt_base_t temp;
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(thread != RT_NULL);
/* disable interrupt */
temp = rt_hw_interrupt_disable();
/* disable interrupt */
temp = rt_hw_interrupt_disable();
/* change stat */
thread->stat = RT_THREAD_READY;
/* change stat */
thread->stat = RT_THREAD_READY;
/* insert thread to ready list */
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
&(thread->tlist));
/* insert thread to ready list */
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]), &(thread->tlist));
/* set priority mask */
/* set priority mask */
#if RT_THREAD_PRIORITY_MAX <= 32
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%s], the priority: %d\n",
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%s], the priority: %d\n",
thread->name, thread->current_priority));
#else
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%s], the priority: %d 0x%x %d\n",
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%s], the priority: %d 0x%x %d\n",
thread->name, thread->number, thread->number_mask, thread->high_mask));
#endif
#if RT_THREAD_PRIORITY_MAX > 32
rt_thread_ready_table[thread->number] |= thread->high_mask;
rt_thread_ready_table[thread->number] |= thread->high_mask;
#endif
rt_thread_ready_priority_group |= thread->number_mask;
rt_thread_ready_priority_group |= thread->number_mask;
/* enable interrupt */
rt_hw_interrupt_enable(temp);
/* enable interrupt */
rt_hw_interrupt_enable(temp);
}
/*
......@@ -350,85 +347,85 @@ void rt_schedule_insert_thread(struct rt_thread* thread)
*
* @note Please do not invoke this function in user application.
*/
void rt_schedule_remove_thread(struct rt_thread* thread)
void rt_schedule_remove_thread(struct rt_thread *thread)
{
register rt_base_t temp;
register rt_base_t temp;
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(thread != RT_NULL);
/* disable interrupt */
temp = rt_hw_interrupt_disable();
/* disable interrupt */
temp = rt_hw_interrupt_disable();
#if RT_THREAD_PRIORITY_MAX <= 32
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("remove thread[%s], the priority: %d\n",
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("remove thread[%s], the priority: %d\n",
thread->name, thread->current_priority));
#else
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("remove thread[%s], the priority: %d 0x%x %d\n",
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("remove thread[%s], the priority: %d 0x%x %d\n",
thread->name, thread->number, thread->number_mask, thread->high_mask));
#endif
/* remove thread from ready list */
rt_list_remove(&(thread->tlist));
if (rt_list_isempty(&(rt_thread_priority_table[thread->current_priority])))
{
/* remove thread from ready list */
rt_list_remove(&(thread->tlist));
if (rt_list_isempty(&(rt_thread_priority_table[thread->current_priority])))
{
#if RT_THREAD_PRIORITY_MAX > 32
rt_thread_ready_table[thread->number] &= ~thread->high_mask;
if (rt_thread_ready_table[thread->number] == 0)
{
rt_thread_ready_priority_group &= ~thread->number_mask;
}
rt_thread_ready_table[thread->number] &= ~thread->high_mask;
if (rt_thread_ready_table[thread->number] == 0)
{
rt_thread_ready_priority_group &= ~thread->number_mask;
}
#else
rt_thread_ready_priority_group &= ~thread->number_mask;
rt_thread_ready_priority_group &= ~thread->number_mask;
#endif
}
}
/* enable interrupt */
rt_hw_interrupt_enable(temp);
/* enable interrupt */
rt_hw_interrupt_enable(temp);
}
/**
* This function will lock the thread scheduler.
*/
void rt_enter_critical()
void rt_enter_critical(void)
{
register rt_base_t level;
register rt_base_t level;
/* disable interrupt */
level = rt_hw_interrupt_disable();
/* disable interrupt */
level = rt_hw_interrupt_disable();
/* the maximal number of nest is RT_UINT16_MAX, which is big
* enough and does not check here */
rt_scheduler_lock_nest++;
rt_scheduler_lock_nest ++;
/* enable interrupt */
rt_hw_interrupt_enable(level);
/* enable interrupt */
rt_hw_interrupt_enable(level);
}
/**
* This function will unlock the thread scheduler.
*/
void rt_exit_critical()
void rt_exit_critical(void)
{
register rt_base_t level;
/* disable interrupt */
level = rt_hw_interrupt_disable();
rt_scheduler_lock_nest --;
if (rt_scheduler_lock_nest <= 0)
{
rt_scheduler_lock_nest = 0;
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_schedule();
}
else
{
/* enable interrupt */
rt_hw_interrupt_enable(level);
}
register rt_base_t level;
/* disable interrupt */
level = rt_hw_interrupt_disable();
rt_scheduler_lock_nest --;
if (rt_scheduler_lock_nest <= 0)
{
rt_scheduler_lock_nest = 0;
/* enable interrupt */
rt_hw_interrupt_enable(level);
rt_schedule();
}
else
{
/* enable interrupt */
rt_hw_interrupt_enable(level);
}
}
/*@}*/
......
/*
* File : slab.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2008 - 2009, RT-Thread Development Team
* COPYRIGHT (C) 2008 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -11,8 +11,8 @@
* Date Author Notes
* 2008-07-12 Bernard the first version
* 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca
* 2010-10-23 yi.qiu add module memory allocator
* 2010-12-18 yi.qiu fix zone release bug
* 2010-10-23 yi.qiu add module memory allocator
* 2010-12-18 yi.qiu fix zone release bug
*/
/*
......@@ -158,36 +158,37 @@ void rt_free_sethook(void (*hook)(void *ptr))
*/
typedef struct slab_chunk
{
struct slab_chunk *c_next;
struct slab_chunk *c_next;
} slab_chunk;
/*
* The IN-BAND zone header is placed at the beginning of each zone.
*/
typedef struct slab_zone {
rt_int32_t z_magic; /* magic number for sanity check */
rt_int32_t z_nfree; /* total free chunks / ualloc space in zone */
rt_int32_t z_nmax; /* maximum free chunks */
typedef struct slab_zone
{
rt_int32_t z_magic; /* magic number for sanity check */
rt_int32_t z_nfree; /* total free chunks / ualloc space in zone */
rt_int32_t z_nmax; /* maximum free chunks */
struct slab_zone *z_next; /* zoneary[] link if z_nfree non-zero */
rt_uint8_t *z_baseptr; /* pointer to start of chunk array */
struct slab_zone *z_next; /* zoneary[] link if z_nfree non-zero */
rt_uint8_t *z_baseptr; /* pointer to start of chunk array */
rt_int32_t z_uindex; /* current initial allocation index */
rt_int32_t z_chunksize; /* chunk size for validation */
rt_int32_t z_uindex; /* current initial allocation index */
rt_int32_t z_chunksize; /* chunk size for validation */
rt_int32_t z_zoneindex; /* zone index */
slab_chunk *z_freechunk; /* free chunk list */
rt_int32_t z_zoneindex; /* zone index */
slab_chunk *z_freechunk; /* free chunk list */
} slab_zone;
#define ZALLOC_SLAB_MAGIC 0x51ab51ab
#define ZALLOC_ZONE_LIMIT (16 * 1024) /* max slab-managed alloc */
#define ZALLOC_MIN_ZONE_SIZE (32 * 1024) /* minimum zone size */
#define ZALLOC_MAX_ZONE_SIZE (128 * 1024) /* maximum zone size */
#define NZONES 72 /* number of zones */
#define ZONE_RELEASE_THRESH 2 /* threshold number of zones */
#define ZALLOC_SLAB_MAGIC 0x51ab51ab
#define ZALLOC_ZONE_LIMIT (16 * 1024) /* max slab-managed alloc */
#define ZALLOC_MIN_ZONE_SIZE (32 * 1024) /* minimum zone size */
#define ZALLOC_MAX_ZONE_SIZE (128 * 1024) /* maximum zone size */
#define NZONES 72 /* number of zones */
#define ZONE_RELEASE_THRESH 2 /* threshold number of zones */
static slab_zone *zone_array[NZONES]; /* linked list of zones NFree > 0 */
static slab_zone *zone_free; /* whole zones that have become free */
static slab_zone *zone_array[NZONES]; /* linked list of zones NFree > 0 */
static slab_zone *zone_free; /* whole zones that have become free */
static int zone_free_cnt;
static int zone_size;
......@@ -198,18 +199,19 @@ static int zone_page_cnt;
* Misc constants. Note that allocations that are exact multiples of
* RT_MM_PAGE_SIZE, or exceed the zone limit, fall through to the kmem module.
*/
#define MIN_CHUNK_SIZE 8 /* in bytes */
#define MIN_CHUNK_MASK (MIN_CHUNK_SIZE - 1)
#define MIN_CHUNK_SIZE 8 /* in bytes */
#define MIN_CHUNK_MASK (MIN_CHUNK_SIZE - 1)
/*
* Array of descriptors that describe the contents of each page
*/
#define PAGE_TYPE_FREE 0x00
#define PAGE_TYPE_SMALL 0x01
#define PAGE_TYPE_LARGE 0x02
struct memusage {
#define PAGE_TYPE_FREE 0x00
#define PAGE_TYPE_SMALL 0x01
#define PAGE_TYPE_LARGE 0x02
struct memusage
{
rt_uint32_t type:2 ; /* page type */
rt_uint32_t size:30; /* pages allocated or offset from zone */
rt_uint32_t size:30; /* pages allocated or offset from zone */
};
static struct memusage *memusage = RT_NULL;
#define btokup(addr) (&memusage[((rt_uint32_t)(addr) - heap_start) >> RT_MM_PAGE_BITS])
......@@ -219,8 +221,8 @@ static rt_uint32_t heap_start, heap_end;
/* page allocator */
struct rt_page_head
{
struct rt_page_head *next; /* next valid page */
rt_size_t page; /* number of page */
struct rt_page_head *next; /* next valid page */
rt_size_t page; /* number of page */
/* dummy */
char dummy[RT_MM_PAGE_SIZE - (sizeof(struct rt_page_head*) + sizeof (rt_size_t))];
......@@ -317,7 +319,7 @@ _return:
/*
* Initialize the page allocator
*/
static void rt_page_init(void* addr, rt_size_t npages)
static void rt_page_init(void *addr, rt_size_t npages)
{
RT_ASSERT(addr != RT_NULL);
RT_ASSERT(npages != 0);
......@@ -335,17 +337,18 @@ static void rt_page_init(void* addr, rt_size_t npages)
* @param end_addr the end address of system page
*
*/
void rt_system_heap_init(void *begin_addr, void* end_addr)
void rt_system_heap_init(void *begin_addr, void *end_addr)
{
rt_uint32_t limsize, npages;
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_uint32_t)begin_addr, RT_MM_PAGE_SIZE);
heap_end = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_MM_PAGE_SIZE);
if(heap_start >= heap_end) {
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);
return;
......@@ -361,7 +364,7 @@ void rt_system_heap_init(void *begin_addr, void* end_addr)
("heap[0x%x - 0x%x], size 0x%x, 0x%x pages\n", heap_start, heap_end, limsize, npages));
/* init pages */
rt_page_init((void*)heap_start, npages);
rt_page_init((void *)heap_start, npages);
/* calculate zone size */
zone_size = ZALLOC_MIN_ZONE_SIZE;
......@@ -383,7 +386,6 @@ void rt_system_heap_init(void *begin_addr, void* end_addr)
RT_DEBUG_LOG(RT_DEBUG_SLAB,
("memusage 0x%x, size 0x%x\n", (rt_uint32_t)memusage, limsize));
}
/*
......@@ -468,7 +470,7 @@ void *rt_malloc(rt_size_t size)
if (size == 0) return RT_NULL;
#ifdef RT_USING_MODULE
if(rt_module_self() != RT_NULL) return rt_module_malloc(size);
if (rt_module_self() != RT_NULL) return rt_module_malloc(size);
#endif
/*
......@@ -487,7 +489,7 @@ void *rt_malloc(rt_size_t size)
kup->type = PAGE_TYPE_LARGE;
kup->size = size >> RT_MM_PAGE_BITS;
RT_DEBUG_LOG(RT_DEBUG_SLAB,("malloc a large memory 0x%x, page cnt %d, kup %d\n",
RT_DEBUG_LOG(RT_DEBUG_SLAB, ("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));
......@@ -516,8 +518,7 @@ void *rt_malloc(rt_size_t size)
zi = zoneindex(&size);
RT_ASSERT(zi < NZONES);
RT_DEBUG_LOG(RT_DEBUG_SLAB,
("try to malloc 0x%x on zone: %d\n", size, zi));
RT_DEBUG_LOG(RT_DEBUG_SLAB, ("try to malloc 0x%x on zone: %d\n", size, zi));
if ((z = zone_array[zi]) != RT_NULL)
{
......@@ -573,7 +574,7 @@ void *rt_malloc(rt_size_t size)
{
/* remove zone from free zone list */
zone_free = z->z_next;
--zone_free_cnt;
-- zone_free_cnt;
}
else
{
......@@ -587,7 +588,7 @@ void *rt_malloc(rt_size_t size)
/* lock heap */
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_DEBUG_LOG(RT_DEBUG_SLAB, ("alloc a new zone: 0x%x\n", (rt_uint32_t)z));
/* set message usage */
for (off = 0, kup = btokup(z); off < zone_page_cnt; off ++)
......@@ -614,13 +615,13 @@ void *rt_malloc(rt_size_t size)
else
off = (off + MIN_CHUNK_MASK) & ~MIN_CHUNK_MASK;
z->z_magic = ZALLOC_SLAB_MAGIC;
z->z_zoneindex = zi;
z->z_nmax = (zone_size - off) / size;
z->z_nfree = z->z_nmax - 1;
z->z_baseptr = (rt_uint8_t*)z + off;
z->z_uindex = 0;
z->z_chunksize = size;
z->z_magic = ZALLOC_SLAB_MAGIC;
z->z_zoneindex = zi;
z->z_nmax = (zone_size - off) / size;
z->z_nfree = z->z_nmax - 1;
z->z_baseptr = (rt_uint8_t *)z + off;
z->z_uindex = 0;
z->z_chunksize = size;
chunk = (slab_chunk *)(z->z_baseptr + z->z_uindex * size);
......@@ -637,7 +638,7 @@ void *rt_malloc(rt_size_t size)
done:
rt_sem_release(&heap_sem);
RT_OBJECT_HOOK_CALL(rt_malloc_hook, ((char*)chunk, size));
RT_OBJECT_HOOK_CALL(rt_malloc_hook, ((char *)chunk, size));
return chunk;
......@@ -668,7 +669,7 @@ void *rt_realloc(void *ptr, rt_size_t size)
}
#ifdef RT_USING_MODULE
if(rt_module_self() != RT_NULL) return rt_module_realloc(ptr, size);
if (rt_module_self() != RT_NULL) return rt_module_realloc(ptr, size);
#endif
/*
......@@ -682,14 +683,14 @@ void *rt_realloc(void *ptr, rt_size_t size)
osize = kup->size << RT_MM_PAGE_BITS;
if ((nptr = rt_malloc(size)) == RT_NULL) return RT_NULL;
rt_memcpy(nptr, ptr, size > osize? osize : size);
rt_memcpy(nptr, ptr, size > osize ? osize : size);
rt_free(ptr);
return nptr;
}
else if (kup->type == PAGE_TYPE_SMALL)
{
z = (slab_zone*)(((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK) - kup->size * RT_MM_PAGE_SIZE);
z = (slab_zone *)(((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK) - kup->size * RT_MM_PAGE_SIZE);
RT_ASSERT(z->z_magic == ZALLOC_SLAB_MAGIC);
zoneindex(&size);
......@@ -702,7 +703,7 @@ void *rt_realloc(void *ptr, rt_size_t size)
*/
if ((nptr = rt_malloc(size)) == RT_NULL) return RT_NULL;
rt_memcpy(nptr, ptr, size > z->z_chunksize? z->z_chunksize : size);
rt_memcpy(nptr, ptr, size > z->z_chunksize ? z->z_chunksize : size);
rt_free(ptr);
return nptr;
......@@ -802,10 +803,10 @@ 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) - kup->size * RT_MM_PAGE_SIZE);
z = (slab_zone *)(((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK) - kup->size * RT_MM_PAGE_SIZE);
RT_ASSERT(z->z_magic == ZALLOC_SLAB_MAGIC);
chunk = (slab_chunk*)ptr;
chunk = (slab_chunk *)ptr;
chunk->c_next = z->z_freechunk;
z->z_freechunk = chunk;
......@@ -829,16 +830,14 @@ void rt_free(void *ptr)
* this code can be called from an IPI callback, do *NOT* try to mess
* with kernel_map here. Hysteresis will be performed at malloc() time.
*/
if (z->z_nfree == z->z_nmax &&
(z->z_next || zone_array[z->z_zoneindex] != z))
if (z->z_nfree == z->z_nmax && (z->z_next || zone_array[z->z_zoneindex] != z))
{
slab_zone **pz;
RT_DEBUG_LOG(RT_DEBUG_SLAB,
("free zone 0x%x\n", (rt_uint32_t)z, z->z_zoneindex));
RT_DEBUG_LOG(RT_DEBUG_SLAB, ("free zone 0x%x\n", (rt_uint32_t)z, z->z_zoneindex));
/* remove zone from zone array list */
for (pz = &zone_array[z->z_zoneindex]; z != *pz; pz = &(*pz)->z_next) ;
for (pz = &zone_array[z->z_zoneindex]; z != *pz; pz = &(*pz)->z_next);
*pz = z->z_next;
/* reset zone */
......@@ -848,7 +847,7 @@ void rt_free(void *ptr)
z->z_next = zone_free;
zone_free = z;
++zone_free_cnt;
++ zone_free_cnt;
/* release zone to page allocator */
if (zone_free_cnt > ZONE_RELEASE_THRESH)
......@@ -857,7 +856,7 @@ void rt_free(void *ptr)
z = zone_free;
zone_free = z->z_next;
--zone_free_cnt;
-- zone_free_cnt;
/* set message usage */
for (i = 0, kup = btokup(z); i < zone_page_cnt; i ++)
......@@ -880,9 +879,7 @@ void rt_free(void *ptr)
}
#ifdef RT_MEM_STATS
void rt_memory_info(rt_uint32_t *total,
rt_uint32_t *used,
rt_uint32_t *max_used)
void rt_memory_info(rt_uint32_t *total, rt_uint32_t *used, rt_uint32_t *max_used)
{
if (total != RT_NULL) *total = heap_end - heap_start;
if (used != RT_NULL) *used = used_mem;
......@@ -891,7 +888,7 @@ void rt_memory_info(rt_uint32_t *total,
#ifdef RT_USING_FINSH
#include <finsh.h>
void list_mem()
void list_mem(void)
{
rt_kprintf("total memory: %d\n", heap_end - heap_start);
rt_kprintf("used memory : %d\n", used_mem);
......
/*
* File : thread.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -29,25 +29,24 @@
#include <rthw.h>
#include "kservice.h"
extern rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX];
extern struct rt_thread* rt_current_thread;
extern struct rt_thread *rt_current_thread;
extern rt_uint8_t rt_current_priority;
extern rt_list_t rt_thread_defunct;
static void rt_thread_exit(void);
void rt_thread_timeout(void* parameter);
void rt_thread_timeout(void *parameter);
static rt_err_t _rt_thread_init(struct rt_thread* thread,
const char* name,
void (*entry)(void* parameter), void* parameter,
void* stack_start, rt_uint32_t stack_size,
static rt_err_t _rt_thread_init(struct rt_thread *thread,
const char *name,
void (*entry)(void *parameter), void *parameter,
void *stack_start, rt_uint32_t stack_size,
rt_uint8_t priority, rt_uint32_t tick)
{
/* init thread list */
rt_list_init(&(thread->tlist));
thread->entry = (void*)entry;
thread->entry = (void *)entry;
thread->parameter = parameter;
/* stack init */
......@@ -56,9 +55,9 @@ static rt_err_t _rt_thread_init(struct rt_thread* thread,
/* init thread stack */
rt_memset(thread->stack_addr, '#', thread->stack_size);
thread->sp = (void*)rt_hw_stack_init(thread->entry, thread->parameter,
thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter,
(void *) ((char *)thread->stack_addr + thread->stack_size - 4),
(void*)rt_thread_exit);
(void *)rt_thread_exit);
/* priority init */
RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX);
......@@ -110,10 +109,10 @@ static rt_err_t _rt_thread_init(struct rt_thread* thread,
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_thread_init(struct rt_thread* thread,
const char* name,
void (*entry)(void* parameter), void* parameter,
void* stack_start, rt_uint32_t stack_size,
rt_err_t rt_thread_init(struct rt_thread *thread,
const char *name,
void (*entry)(void *parameter), void *parameter,
void *stack_start, rt_uint32_t stack_size,
rt_uint8_t priority, rt_uint32_t tick)
{
/* thread check */
......@@ -143,19 +142,19 @@ rt_err_t rt_thread_init(struct rt_thread* thread,
* @return the created thread object
*
*/
rt_thread_t rt_thread_create (const char* name,
void (*entry)(void* parameter), void* parameter,
rt_thread_t rt_thread_create (const char *name,
void (*entry)(void *parameter), void *parameter,
rt_uint32_t stack_size,
rt_uint8_t priority,
rt_uint32_t tick)
{
struct rt_thread* thread;
void* stack_start;
struct rt_thread *thread;
void *stack_start;
thread = (struct rt_thread*) rt_object_allocate(RT_Object_Class_Thread, name);
thread = (struct rt_thread *) rt_object_allocate(RT_Object_Class_Thread, name);
if (thread == RT_NULL) return RT_NULL;
stack_start = (void*)rt_malloc(stack_size);
stack_start = (void *)rt_malloc(stack_size);
if (stack_start == RT_NULL)
{
/* allocate stack failure */
......@@ -177,7 +176,7 @@ rt_thread_t rt_thread_create (const char* name,
* @return the self thread object
*
*/
rt_thread_t rt_thread_self (void)
rt_thread_t rt_thread_self(void)
{
return rt_current_thread;
}
......@@ -190,7 +189,7 @@ rt_thread_t rt_thread_self (void)
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_thread_startup (rt_thread_t thread)
rt_err_t rt_thread_startup(rt_thread_t thread)
{
/* thread check */
RT_ASSERT(thread != RT_NULL);
......@@ -201,11 +200,11 @@ rt_err_t rt_thread_startup (rt_thread_t thread)
/* calculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
thread->number = thread->current_priority >> 3; /* 5bit */
thread->number_mask = 1L << thread->number;
thread->high_mask = 1L << (thread->current_priority & 0x07); /* 3bit */
thread->number = thread->current_priority >> 3; /* 5bit */
thread->number_mask = 1L << thread->number;
thread->high_mask = 1L << (thread->current_priority & 0x07); /* 3bit */
#else
thread->number_mask = 1L << thread->current_priority; //1L means long int,fixed compile mistake with IAR EW M16C v3.401,fify 20100410
thread->number_mask = 1L << thread->current_priority;
#endif
RT_DEBUG_LOG(RT_DEBUG_THREAD,\
......@@ -223,9 +222,9 @@ rt_err_t rt_thread_startup (rt_thread_t thread)
return RT_EOK;
}
static void rt_thread_exit()
static void rt_thread_exit(void)
{
struct rt_thread* thread;
struct rt_thread *thread;
register rt_base_t level;
/* get current thread */
......@@ -270,7 +269,7 @@ static void rt_thread_exit()
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_thread_detach (rt_thread_t thread)
rt_err_t rt_thread_detach(rt_thread_t thread)
{
rt_base_t lock;
......@@ -314,7 +313,7 @@ rt_err_t rt_thread_detach (rt_thread_t thread)
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_thread_delete (rt_thread_t thread)
rt_err_t rt_thread_delete(rt_thread_t thread)
{
rt_base_t lock;
......@@ -351,7 +350,7 @@ rt_err_t rt_thread_delete (rt_thread_t thread)
* @return RT_EOK
*
*/
rt_err_t rt_thread_yield ()
rt_err_t rt_thread_yield(void)
{
register rt_base_t level;
struct rt_thread *thread;
......@@ -394,7 +393,7 @@ rt_err_t rt_thread_yield ()
* @return RT_EOK
*
*/
rt_err_t rt_thread_sleep (rt_tick_t tick)
rt_err_t rt_thread_sleep(rt_tick_t tick)
{
register rt_base_t temp;
struct rt_thread *thread;
......@@ -449,7 +448,7 @@ rt_err_t rt_thread_delay(rt_tick_t tick)
*
* @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, rt_uint8_t cmd, void *arg)
{
register rt_base_t temp;
......@@ -469,13 +468,13 @@ rt_err_t rt_thread_control (rt_thread_t thread, rt_uint8_t cmd, void* arg)
rt_schedule_remove_thread(thread);
/* change thread priority */
thread->current_priority = *(rt_uint8_t*) arg;
thread->current_priority = *(rt_uint8_t *)arg;
/* recalculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
thread->number = thread->current_priority >> 3; /* 5bit */
thread->number_mask = 1 << thread->number;
thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */
thread->number = thread->current_priority >> 3; /* 5bit */
thread->number_mask = 1 << thread->number;
thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */
#else
thread->number_mask = 1 << thread->current_priority;
#endif
......@@ -485,13 +484,13 @@ rt_err_t rt_thread_control (rt_thread_t thread, rt_uint8_t cmd, void* arg)
}
else
{
thread->current_priority = *(rt_uint8_t*) arg;
thread->current_priority = *(rt_uint8_t *)arg;
/* recalculate priority attribute */
#if RT_THREAD_PRIORITY_MAX > 32
thread->number = thread->current_priority >> 3; /* 5bit */
thread->number_mask = 1 << thread->number;
thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */
thread->number = thread->current_priority >> 3; /* 5bit */
thread->number_mask = 1 << thread->number;
thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */
#else
thread->number_mask = 1 << thread->current_priority;
#endif
......@@ -526,7 +525,7 @@ rt_err_t rt_thread_control (rt_thread_t thread, rt_uint8_t cmd, void* arg)
* @note if suspend self thread, after this function call, the
* rt_schedule() must be invoked.
*/
rt_err_t rt_thread_suspend (rt_thread_t thread)
rt_err_t rt_thread_suspend(rt_thread_t thread)
{
register rt_base_t temp;
......@@ -564,7 +563,7 @@ rt_err_t rt_thread_suspend (rt_thread_t thread)
* @return the operation status, RT_EOK on OK, -RT_ERROR on error
*
*/
rt_err_t rt_thread_resume (rt_thread_t thread)
rt_err_t rt_thread_resume(rt_thread_t thread)
{
register rt_base_t temp;
......@@ -609,11 +608,11 @@ rt_err_t rt_thread_resume (rt_thread_t thread)
* @param parameter the parameter of thread timeout function
*
*/
void rt_thread_timeout(void* parameter)
void rt_thread_timeout(void *parameter)
{
struct rt_thread* thread;
struct rt_thread *thread;
thread = (struct rt_thread*) parameter;
thread = (struct rt_thread *)parameter;
/* thread check */
RT_ASSERT(thread != RT_NULL);
......@@ -641,11 +640,11 @@ void rt_thread_timeout(void* parameter)
*
* @note please don't invoke this function in interrupt status.
*/
rt_thread_t rt_thread_find(char* name)
rt_thread_t rt_thread_find(char *name)
{
struct rt_object_information *information;
struct rt_object* object;
struct rt_list_node* node;
struct rt_object *object;
struct rt_list_node *node;
extern struct rt_object_information rt_object_container[];
......
/*
* File : timer.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
......@@ -33,9 +33,9 @@ static rt_list_t rt_soft_timer_list;
#endif
#ifdef RT_USING_HOOK
extern void (*rt_object_take_hook)(struct rt_object* object);
extern void (*rt_object_put_hook)(struct rt_object* object);
static void (*rt_timer_timeout_hook)(struct rt_timer* timer);
extern void (*rt_object_take_hook)(struct rt_object *object);
extern void (*rt_object_put_hook)(struct rt_object *object);
static void (*rt_timer_timeout_hook)(struct rt_timer *timer);
/**
* @addtogroup Hook
......@@ -48,7 +48,7 @@ static void (*rt_timer_timeout_hook)(struct rt_timer* timer);
*
* @param hook the hook function
*/
void rt_timer_timeout_sethook(void (*hook)(struct rt_timer* timer))
void rt_timer_timeout_sethook(void (*hook)(struct rt_timer *timer))
{
rt_timer_timeout_hook = hook;
}
......@@ -57,20 +57,20 @@ void rt_timer_timeout_sethook(void (*hook)(struct rt_timer* timer))
#endif
static void _rt_timer_init(rt_timer_t timer,
void (*timeout)(void* parameter), void* parameter,
void (*timeout)(void *parameter), void *parameter,
rt_tick_t time, rt_uint8_t flag)
{
/* set flag */
timer->parent.flag = flag;
timer->parent.flag = flag;
/* set deactivated */
timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED;
timer->timeout_func = timeout;
timer->parameter = parameter;
timer->parameter = parameter;
timer->timeout_tick = 0;
timer->init_tick = time;
timer->timeout_tick = 0;
timer->init_tick = time;
/* initialize timer list */
rt_list_init(&(timer->list));
......@@ -93,8 +93,8 @@ static void _rt_timer_init(rt_timer_t timer,
* @param flag the flag of timer
*/
void rt_timer_init(rt_timer_t timer,
const char* name,
void (*timeout)(void* parameter), void* parameter,
const char *name,
void (*timeout)(void *parameter), void *parameter,
rt_tick_t time, rt_uint8_t flag)
{
/* timer check */
......@@ -146,12 +146,12 @@ rt_err_t rt_timer_detach(rt_timer_t timer)
*
* @return the created timer object
*/
rt_timer_t rt_timer_create(const char* name, void (*timeout)(void* parameter), void* parameter, rt_tick_t time, rt_uint8_t flag)
rt_timer_t rt_timer_create(const char *name, void (*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag)
{
struct rt_timer* timer;
struct rt_timer *timer;
/* allocate a object */
timer = (struct rt_timer*)rt_object_allocate(RT_Object_Class_Timer, name);
timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name);
if (timer == RT_NULL)
{
return RT_NULL;
......@@ -202,7 +202,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer)
*/
rt_err_t rt_timer_start(rt_timer_t timer)
{
struct rt_timer* t;
struct rt_timer *t;
register rt_base_t level;
rt_list_t *n, *timer_list;
......@@ -273,7 +273,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
/* timer check */
RT_ASSERT(timer != RT_NULL);
if(!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)) return -RT_ERROR;
if (!(timer->parent.flag & RT_TIMER_FLAG_ACTIVATED)) return -RT_ERROR;
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(timer->parent)));
......@@ -302,7 +302,7 @@ rt_err_t rt_timer_stop(rt_timer_t timer)
* @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, rt_uint8_t cmd, void *arg)
{
/* timer check */
RT_ASSERT(timer != RT_NULL);
......@@ -310,11 +310,11 @@ rt_err_t rt_timer_control(rt_timer_t timer, rt_uint8_t cmd, void* arg)
switch (cmd)
{
case RT_TIMER_CTRL_GET_TIME:
*(rt_tick_t*)arg = timer->init_tick;
*(rt_tick_t *)arg = timer->init_tick;
break;
case RT_TIMER_CTRL_SET_TIME:
timer->init_tick = *(rt_tick_t*)arg;
timer->init_tick = *(rt_tick_t *)arg;
break;
case RT_TIMER_CTRL_SET_ONESHOT:
......@@ -336,7 +336,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, rt_uint8_t cmd, void* arg)
* @note this function shall be invoked in operating system timer interrupt.
*/
#ifdef RT_USING_TIMER_SOFT
void rt_soft_timer_tick_increase (void);
void rt_soft_timer_tick_increase(void);
#endif
void rt_timer_check(void)
{
......@@ -344,7 +344,7 @@ void rt_timer_check(void)
rt_tick_t current_tick;
register rt_base_t level;
RT_DEBUG_LOG(RT_DEBUG_TIMER,("timer check enter\n"));
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check enter\n"));
current_tick = rt_tick_get();
......@@ -354,7 +354,7 @@ void rt_timer_check(void)
while (!rt_list_isempty(&rt_timer_list))
{
t = rt_list_entry(rt_timer_list.next, struct rt_timer, list);
/*
* It supposes that the new tick shall less than the half duration of tick max.
*/
......@@ -371,7 +371,7 @@ void rt_timer_check(void)
/* re-get tick */
current_tick = rt_tick_get();
RT_DEBUG_LOG(RT_DEBUG_TIMER,("current tick: %d\n", current_tick));
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));
if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
(t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
......@@ -394,11 +394,10 @@ void rt_timer_check(void)
/* increase soft timer tick */
#ifdef RT_USING_TIMER_SOFT
rt_soft_timer_tick_increase ( );
rt_soft_timer_tick_increase();
#endif
RT_DEBUG_LOG(RT_DEBUG_TIMER,("timer check leave\n"));
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check leave\n"));
}
#ifdef RT_USING_TIMER_SOFT
......@@ -409,9 +408,9 @@ static struct rt_semaphore timer_sem;
static rt_uint16_t timer_ex_cnt;
void rt_soft_timer_tick_increase (void)
void rt_soft_timer_tick_increase(void)
{
timer_ex_cnt++;
timer_ex_cnt ++;
if (timer_ex_cnt >= (RT_TICK_PER_SECOND / RT_TIMER_TICK_PER_SECOND))
{
timer_ex_cnt = 0;
......@@ -424,20 +423,20 @@ void rt_soft_timer_tick_increase (void)
* corresponding timeout function will be invoked.
*
*/
void rt_soft_timer_check()
void rt_soft_timer_check(void)
{
rt_tick_t current_tick;
rt_list_t *n;
struct rt_timer *t;
RT_DEBUG_LOG(RT_DEBUG_TIMER,("software timer check enter\n"));
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check enter\n"));
current_tick = rt_tick_get();
for (n = rt_soft_timer_list.next; n != &(rt_soft_timer_list); )
for (n = rt_soft_timer_list.next; n != &(rt_soft_timer_list);)
{
t = rt_list_entry(n, struct rt_timer, list);
/*
* It supposes that the new tick shall less than the half duration of tick max.
*/
......@@ -457,7 +456,7 @@ void rt_soft_timer_check()
/* re-get tick */
current_tick = rt_tick_get();
RT_DEBUG_LOG(RT_DEBUG_TIMER,("current tick: %d\n", current_tick));
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("current tick: %d\n", current_tick));
if ((t->parent.flag & RT_TIMER_FLAG_PERIODIC) &&
(t->parent.flag & RT_TIMER_FLAG_ACTIVATED))
......@@ -475,25 +474,24 @@ void rt_soft_timer_check()
else break; /* not check anymore */
}
RT_DEBUG_LOG(RT_DEBUG_TIMER,("software timer check leave\n"));
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check leave\n"));
}
/* system timer thread entry */
static void rt_thread_timer_entry(void* parameter)
static void rt_thread_timer_entry(void *parameter)
{
while (1)
{
/* take software timer semaphore */
rt_sem_take(&timer_sem,RT_WAITING_FOREVER);
rt_sem_take(&timer_sem, RT_WAITING_FOREVER);
/* lock scheduler */
/* lock scheduler */
rt_enter_critical();
/* check software timer */
/* check software timer */
rt_soft_timer_check();
/* unlock scheduler */
/* unlock scheduler */
rt_exit_critical();
}
}
......@@ -505,13 +503,13 @@ static void rt_thread_timer_entry(void* parameter)
* This function will initialize system timer
*
*/
void rt_system_timer_init()
void rt_system_timer_init(void)
{
rt_list_init(&rt_timer_list);
#ifdef RT_USING_TIMER_SOFT
rt_list_init(&rt_soft_timer_list);
rt_sem_init(&timer_sem, "timer", 0, RT_IPC_FLAG_FIFO);
rt_sem_init(&timer_sem, "timer", 0, RT_IPC_FLAG_FIFO);
#endif
}
......@@ -521,10 +519,10 @@ void rt_system_timer_init()
* This function will initialize system timer thread
*
*/
void rt_system_timer_thread_init()
void rt_system_timer_thread_init(void)
{
#ifdef RT_USING_TIMER_SOFT
/* start software timer thread */
/* start software timer thread */
rt_thread_init(&timer_thread,
"timer",
rt_thread_timer_entry, RT_NULL,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册