summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Kconfig4
-rw-r--r--src/SConscript6
-rw-r--r--src/clock.c2
-rw-r--r--src/components.c10
-rw-r--r--src/device.c16
-rw-r--r--src/idle.c17
-rw-r--r--src/ipc.c245
-rw-r--r--src/irq.c10
-rw-r--r--src/kservice.c43
-rw-r--r--src/mem.c45
-rw-r--r--src/memheap.c2
-rw-r--r--src/mempool.c27
-rw-r--r--src/object.c5
-rw-r--r--src/scheduler.c24
-rw-r--r--src/slab.c42
-rw-r--r--src/thread.c14
16 files changed, 331 insertions, 181 deletions
diff --git a/src/Kconfig b/src/Kconfig
index 54881e8836..c06a85875b 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -69,8 +69,8 @@ config RT_USING_IDLE_HOOK
default y if RT_USING_HOOK
if RT_USING_IDLE_HOOK
- config RT_IDEL_HOOK_LIST_SIZE
- int "The max size of idel hook list"
+ config RT_IDLE_HOOK_LIST_SIZE
+ int "The max size of idle hook list"
default 4
range 1 16
help
diff --git a/src/SConscript b/src/SConscript
index 7f448725a2..82c3b8aaf1 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -6,9 +6,6 @@ src = Glob('*.c')
CPPPATH = [RTT_ROOT + '/include']
-if GetDepend('RT_USING_COMPONENTS_INIT') == False:
- SrcRemove(src, ['components.c'])
-
if GetDepend('RT_USING_MODULE') == False:
SrcRemove(src, ['module.c'])
@@ -29,6 +26,9 @@ if GetDepend('RT_USING_MEMHEAP') == False:
if GetDepend('RT_USING_DEVICE') == False:
SrcRemove(src, ['device.c'])
+if GetDepend('RT_USING_SMP') == False:
+ SrcRemove(src, ['cpu.c'])
+
group = DefineGroup('Kernel', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
diff --git a/src/clock.c b/src/clock.c
index e969a19b5e..6bdfd21e91 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -20,7 +20,7 @@
static rt_tick_t rt_tick = 0;
/**
- * This function will init system tick and set it to zero.
+ * This function will initialize system tick and set it to zero.
* @ingroup SystemInit
*
* @deprecated since 1.1.0, this function does not need to be invoked
diff --git a/src/components.c b/src/components.c
index 67658afde5..8280056153 100644
--- a/src/components.c
+++ b/src/components.c
@@ -125,6 +125,7 @@ void rt_components_init(void)
}
#endif
}
+#endif /* RT_USING_COMPONENTS_INIT */
#ifdef RT_USING_USER_MAIN
@@ -152,7 +153,6 @@ int __low_level_init(void)
return 0;
}
#elif defined(__GNUC__)
-extern int main(void);
/* Add -eentry to arm-none-eabi-gcc argument */
int entry(void)
{
@@ -173,10 +173,11 @@ void main_thread_entry(void *parameter)
{
extern int main(void);
extern int $Super$$main(void);
-
+
+#ifdef RT_USING_COMPONENTS_INIT
/* RT-Thread components initialization */
rt_components_init();
-
+#endif
/* invoke system main function */
#if defined(__CC_ARM) || defined(__CLANG_ARM)
$Super$$main(); /* for ARMCC. */
@@ -200,7 +201,7 @@ void rt_application_init(void)
result = rt_thread_init(tid, "main", main_thread_entry, RT_NULL,
main_stack, sizeof(main_stack), RT_MAIN_THREAD_PRIORITY, 20);
RT_ASSERT(result == RT_EOK);
-
+
/* if not define RT_USING_HEAP, using to eliminate the warning */
(void)result;
#endif
@@ -247,4 +248,3 @@ int rtthread_startup(void)
return 0;
}
#endif
-#endif
diff --git a/src/device.c b/src/device.c
index 51fc6176a6..32c06b380c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -95,7 +95,7 @@ RTM_EXPORT(rt_device_unregister);
* @return the error code, RT_EOK on successfully.
*
* @deprecated since 1.2.x, this function is not needed because the initialization
- * of a device is performed when applicaiton opens it.
+ * of a device is performed when application opens it.
*/
rt_err_t rt_device_init_all(void)
{
@@ -162,7 +162,7 @@ rt_device_t rt_device_create(int type, int attach_size)
size = RT_ALIGN(sizeof(struct rt_device), RT_ALIGN_SIZE);
attach_size = RT_ALIGN(attach_size, RT_ALIGN_SIZE);
- /* use the totoal size */
+ /* use the total size */
size += attach_size;
device = (rt_device_t)rt_malloc(size);
@@ -208,7 +208,7 @@ rt_err_t rt_device_init(rt_device_t dev)
RT_ASSERT(dev != RT_NULL);
- /* get device init handler */
+ /* get device_init handler */
if (device_init != RT_NULL)
{
if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED))
@@ -269,7 +269,7 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
return -RT_EBUSY;
}
- /* call device open interface */
+ /* call device_open interface */
if (device_open != RT_NULL)
{
result = device_open(dev, oflag);
@@ -317,7 +317,7 @@ rt_err_t rt_device_close(rt_device_t dev)
if (dev->ref_count != 0)
return RT_EOK;
- /* call device close interface */
+ /* call device_close interface */
if (device_close != RT_NULL)
{
result = device_close(dev);
@@ -357,7 +357,7 @@ rt_size_t rt_device_read(rt_device_t dev,
return 0;
}
- /* call device read interface */
+ /* call device_read interface */
if (device_read != RT_NULL)
{
return device_read(dev, pos, buffer, size);
@@ -396,7 +396,7 @@ rt_size_t rt_device_write(rt_device_t dev,
return 0;
}
- /* call device write interface */
+ /* call device_write interface */
if (device_write != RT_NULL)
{
return device_write(dev, pos, buffer, size);
@@ -423,7 +423,7 @@ rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg)
RT_ASSERT(dev != RT_NULL);
RT_ASSERT(rt_object_get_type(&dev->parent) == RT_Object_Class_Device);
- /* call device write interface */
+ /* call device_write interface */
if (device_control != RT_NULL)
{
return device_control(dev, cmd, arg);
diff --git a/src/idle.c b/src/idle.c
index bf5f2d1dc8..d54ad67a40 100644
--- a/src/idle.c
+++ b/src/idle.c
@@ -36,19 +36,18 @@
#endif
#endif
+extern rt_list_t rt_thread_defunct;
+
static struct rt_thread idle;
ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t rt_thread_stack[IDLE_THREAD_STACK_SIZE];
-extern rt_list_t rt_thread_defunct;
-
#ifdef RT_USING_IDLE_HOOK
-
-#ifndef RT_IDEL_HOOK_LIST_SIZE
-#define RT_IDEL_HOOK_LIST_SIZE 4
+#ifndef RT_IDLE_HOOK_LIST_SIZE
+#define RT_IDLE_HOOK_LIST_SIZE 4
#endif
-static void (*idle_hook_list[RT_IDEL_HOOK_LIST_SIZE])();
+static void (*idle_hook_list[RT_IDLE_HOOK_LIST_SIZE])(void);
/**
* @ingroup Hook
@@ -71,7 +70,7 @@ rt_err_t rt_thread_idle_sethook(void (*hook)(void))
/* disable interrupt */
level = rt_hw_interrupt_disable();
- for (i = 0; i < RT_IDEL_HOOK_LIST_SIZE; i++)
+ for (i = 0; i < RT_IDLE_HOOK_LIST_SIZE; i++)
{
if (idle_hook_list[i] == RT_NULL)
{
@@ -103,7 +102,7 @@ rt_err_t rt_thread_idle_delhook(void (*hook)(void))
/* disable interrupt */
level = rt_hw_interrupt_disable();
- for (i = 0; i < RT_IDEL_HOOK_LIST_SIZE; i++)
+ for (i = 0; i < RT_IDLE_HOOK_LIST_SIZE; i++)
{
if (idle_hook_list[i] == hook)
{
@@ -230,7 +229,7 @@ static void rt_thread_idle_entry(void *parameter)
#ifdef RT_USING_IDLE_HOOK
rt_size_t i;
- for (i = 0; i < RT_IDEL_HOOK_LIST_SIZE; i++)
+ for (i = 0; i < RT_IDLE_HOOK_LIST_SIZE; i++)
{
if (idle_hook_list[i] != RT_NULL)
{
diff --git a/src/ipc.c b/src/ipc.c
index 36b714d19f..e6955bae37 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -32,6 +32,8 @@
* 2010-11-10 Bernard add IPC reset command implementation.
* 2011-12-18 Bernard add more parameter checking in message queue
* 2013-09-14 Grissiom add an option check in rt_event_recv
+ * 2018-10-02 Bernard add 64bit support for mailbox
+ * 2019-09-16 tyx add send wait support for message queue
*/
#include <rtthread.h>
@@ -58,7 +60,7 @@ extern void (*rt_object_put_hook)(struct rt_object *object);
*/
rt_inline rt_err_t rt_ipc_object_init(struct rt_ipc_object *ipc)
{
- /* init ipc object */
+ /* initialize ipc object */
rt_list_init(&(ipc->suspend_thread));
return RT_EOK;
@@ -157,13 +159,13 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list)
struct rt_thread *thread;
register rt_ubase_t temp;
- /* wakeup all suspend threads */
+ /* wakeup all suspended threads */
while (!rt_list_isempty(list))
{
/* disable interrupt */
temp = rt_hw_interrupt_disable();
- /* get next suspend thread */
+ /* get next suspended thread */
thread = rt_list_entry(list->next, struct rt_thread, tlist);
/* set error code to RT_ERROR */
thread->error = -RT_ERROR;
@@ -171,7 +173,7 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list)
/*
* resume thread
* In rt_thread_resume function, it will remove current thread from
- * suspend list
+ * suspended list
*/
rt_thread_resume(thread);
@@ -189,7 +191,7 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list)
*
* @param sem the semaphore object
* @param name the name of semaphore
- * @param value the init value of semaphore
+ * @param value the initial value of semaphore
* @param flag the flag of semaphore
*
* @return the operation status, RT_EOK on successful
@@ -202,13 +204,13 @@ rt_err_t rt_sem_init(rt_sem_t sem,
RT_ASSERT(sem != RT_NULL);
RT_ASSERT(value < 0x10000U);
- /* init object */
+ /* initialize object */
rt_object_init(&(sem->parent.parent), RT_Object_Class_Semaphore, name);
- /* init ipc object */
+ /* initialize ipc object */
rt_ipc_object_init(&(sem->parent));
- /* set init value */
+ /* set initial value */
sem->value = (rt_uint16_t)value;
/* set parent */
@@ -234,7 +236,7 @@ rt_err_t rt_sem_detach(rt_sem_t sem)
RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore);
RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent));
- /* wakeup all suspend threads */
+ /* wakeup all suspended threads */
rt_ipc_list_resume_all(&(sem->parent.suspend_thread));
/* detach semaphore object */
@@ -249,7 +251,7 @@ RTM_EXPORT(rt_sem_detach);
* This function will create a semaphore from system resource
*
* @param name the name of semaphore
- * @param value the init value of semaphore
+ * @param value the initial value of semaphore
* @param flag the flag of semaphore
*
* @return the created semaphore, RT_NULL on error happen
@@ -268,10 +270,10 @@ rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag)
if (sem == RT_NULL)
return sem;
- /* init ipc object */
+ /* initialize ipc object */
rt_ipc_object_init(&(sem->parent));
- /* set init value */
+ /* set initial value */
sem->value = value;
/* set parent */
@@ -299,7 +301,7 @@ rt_err_t rt_sem_delete(rt_sem_t sem)
RT_ASSERT(rt_object_get_type(&sem->parent.parent) == RT_Object_Class_Semaphore);
RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent) == RT_FALSE);
- /* wakeup all suspend threads */
+ /* wakeup all suspended threads */
rt_ipc_list_resume_all(&(sem->parent.suspend_thread));
/* delete semaphore object */
@@ -488,10 +490,10 @@ rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg)
if (cmd == RT_IPC_CMD_RESET)
{
- rt_uint32_t value;
+ rt_ubase_t value;
/* get value */
- value = (rt_uint32_t)arg;
+ value = (rt_ubase_t)arg;
/* disable interrupt */
level = rt_hw_interrupt_disable();
@@ -530,10 +532,10 @@ rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag)
/* parameter check */
RT_ASSERT(mutex != RT_NULL);
- /* init object */
+ /* initialize object */
rt_object_init(&(mutex->parent.parent), RT_Object_Class_Mutex, name);
- /* init ipc object */
+ /* initialize ipc object */
rt_ipc_object_init(&(mutex->parent));
mutex->value = 1;
@@ -564,7 +566,7 @@ rt_err_t rt_mutex_detach(rt_mutex_t mutex)
RT_ASSERT(rt_object_get_type(&mutex->parent.parent) == RT_Object_Class_Mutex);
RT_ASSERT(rt_object_is_systemobject(&mutex->parent.parent));
- /* wakeup all suspend threads */
+ /* wakeup all suspended threads */
rt_ipc_list_resume_all(&(mutex->parent.suspend_thread));
/* detach semaphore object */
@@ -596,7 +598,7 @@ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag)
if (mutex == RT_NULL)
return mutex;
- /* init ipc object */
+ /* initialize ipc object */
rt_ipc_object_init(&(mutex->parent));
mutex->value = 1;
@@ -629,10 +631,10 @@ rt_err_t rt_mutex_delete(rt_mutex_t mutex)
RT_ASSERT(rt_object_get_type(&mutex->parent.parent) == RT_Object_Class_Mutex);
RT_ASSERT(rt_object_is_systemobject(&mutex->parent.parent) == RT_FALSE);
- /* wakeup all suspend threads */
+ /* wakeup all suspended threads */
rt_ipc_list_resume_all(&(mutex->parent.suspend_thread));
- /* delete semaphore object */
+ /* delete mutex object */
rt_object_delete(&(mutex->parent.parent));
return RT_EOK;
@@ -915,16 +917,16 @@ rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag)
/* parameter check */
RT_ASSERT(event != RT_NULL);
- /* init object */
+ /* initialize object */
rt_object_init(&(event->parent.parent), RT_Object_Class_Event, name);
/* set parent flag */
event->parent.parent.flag = flag;
- /* init ipc object */
+ /* initialize ipc object */
rt_ipc_object_init(&(event->parent));
- /* init event */
+ /* initialize event */
event->set = 0;
return RT_EOK;
@@ -978,10 +980,10 @@ rt_event_t rt_event_create(const char *name, rt_uint8_t flag)
/* set parent */
event->parent.parent.flag = flag;
- /* init ipc object */
+ /* initialize ipc object */
rt_ipc_object_init(&(event->parent));
- /* init event */
+ /* initialize event */
event->set = 0;
return event;
@@ -1048,7 +1050,7 @@ rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set)
event->set |= set;
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(event->parent.parent)));
-
+
if (!rt_list_isempty(&event->parent.suspend_thread))
{
/* search thread list to resume thread */
@@ -1071,7 +1073,7 @@ rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set)
{
if (thread->event_set & event->set)
{
- /* save recieved event set */
+ /* save the received event set */
thread->event_set = thread->event_set & event->set;
/* received an OR event */
@@ -1141,7 +1143,7 @@ rt_err_t rt_event_recv(rt_event_t event,
if (set == 0)
return -RT_ERROR;
- /* init status */
+ /* initialize status */
status = -RT_ERROR;
/* get current thread */
thread = rt_thread_self();
@@ -1251,7 +1253,7 @@ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg)
/* parameter check */
RT_ASSERT(event != RT_NULL);
RT_ASSERT(rt_object_get_type(&event->parent.parent) == RT_Object_Class_Event);
-
+
if (cmd == RT_IPC_CMD_RESET)
{
/* disable interrupt */
@@ -1260,7 +1262,7 @@ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg)
/* resume all waiting thread */
rt_ipc_list_resume_all(&event->parent.suspend_thread);
- /* init event set */
+ /* initialize event set */
event->set = 0;
/* enable interrupt */
@@ -1297,23 +1299,23 @@ rt_err_t rt_mb_init(rt_mailbox_t mb,
{
RT_ASSERT(mb != RT_NULL);
- /* init object */
+ /* initialize object */
rt_object_init(&(mb->parent.parent), RT_Object_Class_MailBox, name);
/* set parent flag */
mb->parent.parent.flag = flag;
- /* init ipc object */
+ /* initialize ipc object */
rt_ipc_object_init(&(mb->parent));
- /* init mailbox */
- mb->msg_pool = msgpool;
+ /* initialize mailbox */
+ mb->msg_pool = (rt_ubase_t *)msgpool;
mb->size = size;
mb->entry = 0;
mb->in_offset = 0;
mb->out_offset = 0;
- /* init an additional list of sender suspend thread */
+ /* initialize an additional list of sender suspend thread */
rt_list_init(&(mb->suspend_sender_thread));
return RT_EOK;
@@ -1370,12 +1372,12 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag)
/* set parent */
mb->parent.parent.flag = flag;
- /* init ipc object */
+ /* initialize ipc object */
rt_ipc_object_init(&(mb->parent));
- /* init mailbox */
+ /* initialize mailbox */
mb->size = size;
- mb->msg_pool = RT_KERNEL_MALLOC(mb->size * sizeof(rt_uint32_t));
+ mb->msg_pool = (rt_ubase_t *)RT_KERNEL_MALLOC(mb->size * sizeof(rt_ubase_t));
if (mb->msg_pool == RT_NULL)
{
/* delete mailbox object */
@@ -1387,7 +1389,7 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag)
mb->in_offset = 0;
mb->out_offset = 0;
- /* init an additional list of sender suspend thread */
+ /* initialize an additional list of sender suspend thread */
rt_list_init(&(mb->suspend_sender_thread));
return mb;
@@ -1438,7 +1440,7 @@ RTM_EXPORT(rt_mb_delete);
* @return the error code
*/
rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
- rt_uint32_t value,
+ rt_ubase_t value,
rt_int32_t timeout)
{
struct rt_thread *thread;
@@ -1569,7 +1571,7 @@ RTM_EXPORT(rt_mb_send_wait);
*
* @return the error code
*/
-rt_err_t rt_mb_send(rt_mailbox_t mb, rt_uint32_t value)
+rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value)
{
return rt_mb_send_wait(mb, value, 0);
}
@@ -1585,7 +1587,7 @@ RTM_EXPORT(rt_mb_send);
*
* @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_ubase_t *value, rt_int32_t timeout)
{
struct rt_thread *thread;
register rt_ubase_t temp;
@@ -1789,39 +1791,42 @@ rt_err_t rt_mq_init(rt_mq_t mq,
/* parameter check */
RT_ASSERT(mq != RT_NULL);
- /* init object */
+ /* initialize object */
rt_object_init(&(mq->parent.parent), RT_Object_Class_MessageQueue, name);
/* set parent flag */
mq->parent.parent.flag = flag;
- /* init ipc object */
+ /* initialize ipc object */
rt_ipc_object_init(&(mq->parent));
- /* set messasge pool */
+ /* set message pool */
mq->msg_pool = msgpool;
/* get correct message size */
mq->msg_size = RT_ALIGN(msg_size, RT_ALIGN_SIZE);
mq->max_msgs = pool_size / (mq->msg_size + sizeof(struct rt_mq_message));
- /* init message list */
+ /* initialize message list */
mq->msg_queue_head = RT_NULL;
mq->msg_queue_tail = RT_NULL;
- /* init message empty list */
+ /* initialize message empty list */
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 +
temp * (mq->msg_size + sizeof(struct rt_mq_message)));
- head->next = mq->msg_queue_free;
+ head->next = (struct rt_mq_message *)mq->msg_queue_free;
mq->msg_queue_free = head;
}
/* the initial entry is zero */
mq->entry = 0;
+ /* initialize an additional list of sender suspend thread */
+ rt_list_init(&(mq->suspend_sender_thread));
+
return RT_EOK;
}
RTM_EXPORT(rt_mq_init);
@@ -1842,6 +1847,8 @@ rt_err_t rt_mq_detach(rt_mq_t mq)
/* resume all suspended thread */
rt_ipc_list_resume_all(&mq->parent.suspend_thread);
+ /* also resume all message queue private suspended thread */
+ rt_ipc_list_resume_all(&(mq->suspend_sender_thread));
/* detach message queue object */
rt_object_detach(&(mq->parent.parent));
@@ -1880,10 +1887,10 @@ rt_mq_t rt_mq_create(const char *name,
/* set parent */
mq->parent.parent.flag = flag;
- /* init ipc object */
+ /* initialize ipc object */
rt_ipc_object_init(&(mq->parent));
- /* init message queue */
+ /* initialize message queue */
/* get correct message size */
mq->msg_size = RT_ALIGN(msg_size, RT_ALIGN_SIZE);
@@ -1893,28 +1900,31 @@ rt_mq_t rt_mq_create(const char *name,
mq->msg_pool = RT_KERNEL_MALLOC((mq->msg_size + sizeof(struct rt_mq_message)) * mq->max_msgs);
if (mq->msg_pool == RT_NULL)
{
- rt_mq_delete(mq);
+ rt_object_delete(&(mq->parent.parent));
return RT_NULL;
}
- /* init message list */
+ /* initialize message list */
mq->msg_queue_head = RT_NULL;
mq->msg_queue_tail = RT_NULL;
- /* init message empty list */
+ /* initialize message empty list */
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 +
temp * (mq->msg_size + sizeof(struct rt_mq_message)));
- head->next = mq->msg_queue_free;
+ head->next = (struct rt_mq_message *)mq->msg_queue_free;
mq->msg_queue_free = head;
}
/* the initial entry is zero */
mq->entry = 0;
+ /* initialize an additional list of sender suspend thread */
+ rt_list_init(&(mq->suspend_sender_thread));
+
return mq;
}
RTM_EXPORT(rt_mq_create);
@@ -1937,6 +1947,8 @@ rt_err_t rt_mq_delete(rt_mq_t mq)
/* resume all suspended thread */
rt_ipc_list_resume_all(&(mq->parent.suspend_thread));
+ /* also resume all message queue private suspended thread */
+ rt_ipc_list_resume_all(&(mq->suspend_sender_thread));
/* free message queue pool */
RT_KERNEL_FREE(mq->msg_pool);
@@ -1950,19 +1962,25 @@ RTM_EXPORT(rt_mq_delete);
#endif
/**
- * This function will send a message to message queue object, if there are
- * threads suspended on message queue object, it will be waked up.
+ * This function will send a message to message queue object. If the message queue is full,
+ * current thread will be suspended until timeout.
*
* @param mq the message queue object
* @param buffer the message
* @param size the size of buffer
+ * @param timeout the waiting time
*
* @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_wait(rt_mq_t mq,
+ const void *buffer,
+ rt_size_t size,
+ rt_int32_t timeout)
{
register rt_ubase_t temp;
struct rt_mq_message *msg;
+ rt_uint32_t tick_delta;
+ struct rt_thread *thread;
/* parameter check */
RT_ASSERT(mq != RT_NULL);
@@ -1974,6 +1992,11 @@ rt_err_t rt_mq_send(rt_mq_t mq, void *buffer, rt_size_t size)
if (size > mq->msg_size)
return -RT_ERROR;
+ /* initialize delta tick */
+ tick_delta = 0;
+ /* get current thread */
+ thread = rt_thread_self();
+
RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mq->parent.parent)));
/* disable interrupt */
@@ -1981,14 +2004,78 @@ rt_err_t rt_mq_send(rt_mq_t mq, void *buffer, rt_size_t size)
/* get a free list, there must be an empty item */
msg = (struct rt_mq_message *)mq->msg_queue_free;
- /* message queue is full */
- if (msg == RT_NULL)
+ /* for non-blocking call */
+ if (msg == RT_NULL && timeout == 0)
{
/* enable interrupt */
rt_hw_interrupt_enable(temp);
return -RT_EFULL;
}
+
+ /* message queue is full */
+ while ((msg = mq->msg_queue_free) == RT_NULL)
+ {
+ /* reset error number in thread */
+ thread->error = RT_EOK;
+
+ /* no waiting, return timeout */
+ if (timeout == 0)
+ {
+ /* enable interrupt */
+ rt_hw_interrupt_enable(temp);
+
+ return -RT_EFULL;
+ }
+
+ RT_DEBUG_IN_THREAD_CONTEXT;
+ /* suspend current thread */
+ rt_ipc_list_suspend(&(mq->suspend_sender_thread),
+ thread,
+ mq->parent.parent.flag);
+
+ /* has waiting time, start thread timer */
+ if (timeout > 0)
+ {
+ /* get the start tick of timer */
+ tick_delta = rt_tick_get();
+
+ RT_DEBUG_LOG(RT_DEBUG_IPC, ("mq_send_wait: start timer of thread:%s\n",
+ thread->name));
+
+ /* reset the timeout of thread timer and start it */
+ rt_timer_control(&(thread->thread_timer),
+ RT_TIMER_CTRL_SET_TIME,
+ &timeout);
+ rt_timer_start(&(thread->thread_timer));
+ }
+
+ /* enable interrupt */
+ rt_hw_interrupt_enable(temp);
+
+ /* re-schedule */
+ rt_schedule();
+
+ /* resume from suspend state */
+ if (thread->error != RT_EOK)
+ {
+ /* return error */
+ return thread->error;
+ }
+
+ /* disable interrupt */
+ temp = rt_hw_interrupt_disable();
+
+ /* if it's not waiting forever and then re-calculate timeout tick */
+ if (timeout > 0)
+ {
+ tick_delta = rt_tick_get() - tick_delta;
+ timeout -= tick_delta;
+ if (timeout < 0)
+ timeout = 0;
+ }
+ }
+
/* move free list pointer */
mq->msg_queue_free = msg->next;
@@ -2036,6 +2123,22 @@ rt_err_t rt_mq_send(rt_mq_t mq, void *buffer, rt_size_t size)
return RT_EOK;
}
+RTM_EXPORT(rt_mq_send_wait)
+
+/**
+ * This function will send a message to message queue object, if there are
+ * threads suspended on message queue object, it will be waked up.
+ *
+ * @param mq the message queue object
+ * @param buffer the message
+ * @param size the size of buffer
+ *
+ * @return the error code
+ */
+rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size)
+{
+ return rt_mq_send_wait(mq, buffer, size, 0);
+}
RTM_EXPORT(rt_mq_send);
/**
@@ -2049,7 +2152,7 @@ RTM_EXPORT(rt_mq_send);
*
* @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, const void *buffer, rt_size_t size)
{
register rt_ubase_t temp;
struct rt_mq_message *msg;
@@ -2092,7 +2195,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, void *buffer, rt_size_t size)
temp = rt_hw_interrupt_disable();
/* link msg to the beginning of message queue */
- msg->next = mq->msg_queue_head;
+ msg->next = (struct rt_mq_message *)mq->msg_queue_head;
mq->msg_queue_head = msg;
/* if there is no tail */
@@ -2256,6 +2359,22 @@ rt_err_t rt_mq_recv(rt_mq_t mq,
/* put message to free list */
msg->next = (struct rt_mq_message *)mq->msg_queue_free;
mq->msg_queue_free = msg;
+
+ /* resume suspended thread */
+ if (!rt_list_isempty(&(mq->suspend_sender_thread)))
+ {
+ rt_ipc_list_resume(&(mq->suspend_sender_thread));
+
+ /* enable interrupt */
+ rt_hw_interrupt_enable(temp);
+
+ RT_OBJECT_HOOK_CALL(rt_object_take_hook, (&(mq->parent.parent)));
+
+ rt_schedule();
+
+ return RT_EOK;
+ }
+
/* enable interrupt */
rt_hw_interrupt_enable(temp);
@@ -2291,6 +2410,8 @@ rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg)
/* resume all waiting thread */
rt_ipc_list_resume_all(&mq->parent.suspend_thread);
+ /* also resume all message queue private suspended thread */
+ rt_ipc_list_resume_all(&(mq->suspend_sender_thread));
/* release all message in the queue */
while (mq->msg_queue_head != RT_NULL)
diff --git a/src/irq.c b/src/irq.c
index 72d220bd92..8b4d0d0a9e 100644
--- a/src/irq.c
+++ b/src/irq.c
@@ -100,9 +100,15 @@ RTM_EXPORT(rt_interrupt_leave);
*
* @return the number of nested interrupts.
*/
-rt_uint8_t rt_interrupt_get_nest(void)
+RT_WEAK rt_uint8_t rt_interrupt_get_nest(void)
{
- return rt_interrupt_nest;
+ rt_uint8_t ret;
+ rt_base_t level;
+
+ level = rt_hw_interrupt_disable();
+ ret = rt_interrupt_nest;
+ rt_hw_interrupt_enable(level);
+ return ret;
}
RTM_EXPORT(rt_interrupt_get_nest);
diff --git a/src/kservice.c b/src/kservice.c
index 1d3dace340..58f04330f1 100644
--- a/src/kservice.c
+++ b/src/kservice.c
@@ -316,7 +316,7 @@ RTM_EXPORT(rt_memmove);
* This function will compare two areas of memory
*
* @param cs one area of memory
- * @param ct znother area of memory
+ * @param ct another area of memory
* @param count the size of the area
*
* @return the result
@@ -326,7 +326,7 @@ 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 = (const unsigned char *)cs, su2 = (const unsigned char *)ct; 0 < count; ++su1, ++su2, count--)
if ((res = *su1 - *su2) != 0)
break;
@@ -1117,14 +1117,14 @@ RTM_EXPORT(rt_console_get_device);
*/
rt_device_t rt_console_set_device(const char *name)
{
- rt_device_t new, old;
+ rt_device_t new_device, old_device;
/* save old device */
- old = _console_device;
+ old_device = _console_device;
/* find new console device */
- new = rt_device_find(name);
- if (new != RT_NULL)
+ new_device = rt_device_find(name);
+ if (new_device != RT_NULL)
{
if (_console_device != RT_NULL)
{
@@ -1133,11 +1133,11 @@ rt_device_t rt_console_set_device(const char *name)
}
/* set new console device */
- rt_device_open(new, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM);
- _console_device = new;
+ rt_device_open(new_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM);
+ _console_device = new_device;
}
- return old;
+ return old_device;
}
RTM_EXPORT(rt_console_set_device);
#endif
@@ -1228,31 +1228,36 @@ RTM_EXPORT(rt_kprintf);
*/
void *rt_malloc_align(rt_size_t size, rt_size_t align)
{
- void *align_ptr;
void *ptr;
+ void *align_ptr;
+ int uintptr_size;
rt_size_t align_size;
- /* align the alignment size to 4 byte */
- align = ((align + 0x03) & ~0x03);
+ /* sizeof pointer */
+ uintptr_size = sizeof(void*);
+ uintptr_size -= 1;
+
+ /* align the alignment size to uintptr size byte */
+ align = ((align + uintptr_size) & ~uintptr_size);
/* get total aligned size */
- align_size = ((size + 0x03) & ~0x03) + align;
+ align_size = ((size + uintptr_size) & ~uintptr_size) + align;
/* allocate memory block from heap */
ptr = rt_malloc(align_size);
if (ptr != RT_NULL)
{
/* the allocated memory block is aligned */
- if (((rt_uint32_t)ptr & (align - 1)) == 0)
+ if (((rt_ubase_t)ptr & (align - 1)) == 0)
{
- align_ptr = (void *)((rt_uint32_t)ptr + align);
+ align_ptr = (void *)((rt_ubase_t)ptr + align);
}
else
{
- align_ptr = (void *)(((rt_uint32_t)ptr + (align - 1)) & ~(align - 1));
+ align_ptr = (void *)(((rt_ubase_t)ptr + (align - 1)) & ~(align - 1));
}
/* set the pointer before alignment pointer to the real pointer */
- *((rt_uint32_t *)((rt_uint32_t)align_ptr - sizeof(void *))) = (rt_uint32_t)ptr;
+ *((rt_ubase_t *)((rt_ubase_t)align_ptr - sizeof(void *))) = (rt_ubase_t)ptr;
ptr = align_ptr;
}
@@ -1271,7 +1276,7 @@ void rt_free_align(void *ptr)
{
void *real_ptr;
- real_ptr = (void *) * (rt_uint32_t *)((rt_uint32_t)ptr - sizeof(void *));
+ real_ptr = (void *) * (rt_ubase_t *)((rt_ubase_t)ptr - sizeof(void *));
rt_free(real_ptr);
}
RTM_EXPORT(rt_free_align);
@@ -1327,7 +1332,9 @@ int __rt_ffs(int value)
#ifdef RT_DEBUG
/* RT_ASSERT(EX)'s hook */
+
void (*rt_assert_hook)(const char *ex, const char *func, rt_size_t line);
+
/**
* This function will set a hook function to RT_ASSERT(EX). It will run when the expression is false.
*
diff --git a/src/mem.c b/src/mem.c
index 2fefb48b67..8099b6bb7e 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -11,6 +11,7 @@
* 2010-07-13 Bernard fix RT_ALIGN issue found by kuronca
* 2010-10-14 Bernard fix rt_realloc issue when realloc a NULL pointer.
* 2017-07-14 armink fix rt_realloc issue when new size is 0
+ * 2018-10-02 Bernard Add 64bit support
*/
/*
@@ -97,12 +98,19 @@ struct heap_mem
/* magic and used flag */
rt_uint16_t magic;
rt_uint16_t used;
+#ifdef ARCH_CPU_64BIT
+ rt_uint32_t resv;
+#endif
rt_size_t next, prev;
#ifdef RT_USING_MEMTRACE
+#ifdef ARCH_CPU_64BIT
+ rt_uint8_t thread[8];
+#else
rt_uint8_t thread[4]; /* thread name */
#endif
+#endif
};
/** pointer to the heap: for alignment, heap_ptr is now a pointer instead of an array */
@@ -111,7 +119,12 @@ static rt_uint8_t *heap_ptr;
/** the last entry, always unused! */
static struct heap_mem *heap_end;
+#ifdef ARCH_CPU_64BIT
+#define MIN_SIZE 24
+#else
#define MIN_SIZE 12
+#endif
+
#define MIN_SIZE_ALIGNED RT_ALIGN(MIN_SIZE, RT_ALIGN_SIZE)
#define SIZEOF_STRUCT_MEM RT_ALIGN(sizeof(struct heap_mem), RT_ALIGN_SIZE)
@@ -191,8 +204,8 @@ static void plug_holes(struct heap_mem *mem)
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);
- rt_uint32_t end_align = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_ALIGN_SIZE);
+ rt_ubase_t begin_align = RT_ALIGN((rt_ubase_t)begin_addr, RT_ALIGN_SIZE);
+ rt_ubase_t end_align = RT_ALIGN_DOWN((rt_ubase_t)end_addr, RT_ALIGN_SIZE);
RT_DEBUG_NOT_IN_INTERRUPT;
@@ -206,7 +219,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
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);
+ (rt_ubase_t)begin_addr, (rt_ubase_t)end_addr);
return;
}
@@ -215,7 +228,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
heap_ptr = (rt_uint8_t *)begin_align;
RT_DEBUG_LOG(RT_DEBUG_MEM, ("mem init, heap begin address 0x%x, size %d\n",
- (rt_uint32_t)heap_ptr, mem_size_aligned));
+ (rt_ubase_t)heap_ptr, mem_size_aligned));
/* initialize the start of the heap */
mem = (struct heap_mem *)heap_ptr;
@@ -374,14 +387,14 @@ void *rt_malloc(rt_size_t size)
}
rt_sem_release(&heap_sem);
- RT_ASSERT((rt_uint32_t)mem + SIZEOF_STRUCT_MEM + size <= (rt_uint32_t)heap_end);
- 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_ASSERT((rt_ubase_t)mem + SIZEOF_STRUCT_MEM + size <= (rt_ubase_t)heap_end);
+ RT_ASSERT((rt_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM) % RT_ALIGN_SIZE == 0);
+ RT_ASSERT((((rt_ubase_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_ubase_t)((rt_uint8_t *)mem + SIZEOF_STRUCT_MEM),
+ (rt_ubase_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));
@@ -539,7 +552,7 @@ void rt_free(void *rmem)
RT_DEBUG_NOT_IN_INTERRUPT;
- RT_ASSERT((((rt_uint32_t)rmem) & (RT_ALIGN_SIZE - 1)) == 0);
+ RT_ASSERT((((rt_ubase_t)rmem) & (RT_ALIGN_SIZE - 1)) == 0);
RT_ASSERT((rt_uint8_t *)rmem >= (rt_uint8_t *)heap_ptr &&
(rt_uint8_t *)rmem < (rt_uint8_t *)heap_end);
@@ -558,8 +571,8 @@ void rt_free(void *rmem)
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_ubase_t)rmem,
+ (rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - heap_ptr))));
/* protect the heap from concurrent access */
@@ -624,14 +637,14 @@ FINSH_FUNCTION_EXPORT(list_mem, list memory usage information)
int memcheck(void)
{
int position;
- rt_uint32_t level;
+ rt_ubase_t level;
struct heap_mem *mem;
level = rt_hw_interrupt_disable();
for (mem = (struct heap_mem *)heap_ptr; mem != heap_end; mem = (struct heap_mem *)&heap_ptr[mem->next])
{
- position = (rt_uint32_t)mem - (rt_uint32_t)heap_ptr;
+ position = (rt_ubase_t)mem - (rt_ubase_t)heap_ptr;
if (position < 0) goto __exit;
- if (position > mem_size_aligned) goto __exit;
+ if (position > (int)mem_size_aligned) goto __exit;
if (mem->magic != HEAP_MAGIC) goto __exit;
if (mem->used != 0 && mem->used != 1) goto __exit;
}
@@ -664,7 +677,7 @@ int memtrace(int argc, char **argv)
rt_kprintf("\n--memory item information --\n");
for (mem = (struct heap_mem *)heap_ptr; mem != heap_end; mem = (struct heap_mem *)&heap_ptr[mem->next])
{
- int position = (rt_uint32_t)mem - (rt_uint32_t)heap_ptr;
+ int position = (rt_ubase_t)mem - (rt_ubase_t)heap_ptr;
int size;
rt_kprintf("[0x%08x - ", mem);
diff --git a/src/memheap.c b/src/memheap.c
index eb5d710029..aef56e1a74 100644
--- a/src/memheap.c
+++ b/src/memheap.c
@@ -34,7 +34,7 @@
#define RT_MEMHEAP_MINIALLOC 12
#define RT_MEMHEAP_SIZE RT_ALIGN(sizeof(struct rt_memheap_item), RT_ALIGN_SIZE)
-#define MEMITEM_SIZE(item) ((rt_uint32_t)item->next - (rt_uint32_t)item - RT_MEMHEAP_SIZE)
+#define MEMITEM_SIZE(item) ((rt_ubase_t)item->next - (rt_ubase_t)item - RT_MEMHEAP_SIZE)
/*
* The initialized memory pool will be:
diff --git a/src/mempool.c b/src/mempool.c
index 2184586aba..00471efb35 100644
--- a/src/mempool.c
+++ b/src/mempool.c
@@ -85,6 +85,9 @@ rt_err_t rt_mp_init(struct rt_mempool *mp,
/* parameter check */
RT_ASSERT(mp != RT_NULL);
+ RT_ASSERT(name != RT_NULL);
+ RT_ASSERT(start != RT_NULL);
+ RT_ASSERT(size > 0 && block_size > 0);
/* initialize object */
rt_object_init(&(mp->parent), RT_Object_Class_MemPool, name);
@@ -103,7 +106,6 @@ rt_err_t rt_mp_init(struct rt_mempool *mp,
/* initialize suspended thread list */
rt_list_init(&(mp->suspend_thread));
- mp->suspend_thread_count = 0;
/* initialize free block list */
block_ptr = (rt_uint8_t *)mp->start_address;
@@ -157,9 +159,6 @@ rt_err_t rt_mp_detach(struct rt_mempool *mp)
*/
rt_thread_resume(thread);
- /* decrease suspended thread count */
- mp->suspend_thread_count --;
-
/* enable interrupt */
rt_hw_interrupt_enable(temp);
}
@@ -192,6 +191,10 @@ rt_mp_t rt_mp_create(const char *name,
RT_DEBUG_NOT_IN_INTERRUPT;
+ /* parameter check */
+ RT_ASSERT(name != RT_NULL);
+ RT_ASSERT(block_count > 0 && block_size > 0);
+
/* allocate object */
mp = (struct rt_mempool *)rt_object_allocate(RT_Object_Class_MemPool, name);
/* allocate object failed */
@@ -219,7 +222,6 @@ rt_mp_t rt_mp_create(const char *name,
/* initialize suspended thread list */
rt_list_init(&(mp->suspend_thread));
- mp->suspend_thread_count = 0;
/* initialize free block list */
block_ptr = (rt_uint8_t *)mp->start_address;
@@ -275,9 +277,6 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
*/
rt_thread_resume(thread);
- /* decrease suspended thread count */
- mp->suspend_thread_count --;
-
/* enable interrupt */
rt_hw_interrupt_enable(temp);
}
@@ -308,6 +307,9 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time)
struct rt_thread *thread;
rt_uint32_t before_sleep = 0;
+ /* parameter check */
+ RT_ASSERT(mp != RT_NULL);
+
/* get current thread */
thread = rt_thread_self();
@@ -334,7 +336,6 @@ 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++;
if (time > 0)
{
@@ -402,6 +403,9 @@ void rt_mp_free(void *block)
struct rt_thread *thread;
register rt_base_t level;
+ /* parameter check */
+ if (block == RT_NULL) return;
+
/* 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;
@@ -418,7 +422,7 @@ void rt_mp_free(void *block)
*block_ptr = mp->block_list;
mp->block_list = (rt_uint8_t *)block_ptr;
- if (mp->suspend_thread_count > 0)
+ if (!rt_list_isempty(&(mp->suspend_thread)))
{
/* get the suspended thread */
thread = rt_list_entry(mp->suspend_thread.next,
@@ -431,9 +435,6 @@ void rt_mp_free(void *block)
/* resume thread */
rt_thread_resume(thread);
- /* decrease suspended thread count */
- mp->suspend_thread_count --;
-
/* enable interrupt */
rt_hw_interrupt_enable(level);
diff --git a/src/object.c b/src/object.c
index e85737ce8f..4ee2f6a1a1 100644
--- a/src/object.c
+++ b/src/object.c
@@ -262,7 +262,10 @@ void rt_object_init(struct rt_object *object,
struct rt_object *obj;
obj = rt_list_entry(node, struct rt_object, list);
- RT_ASSERT(obj != object);
+ if (obj) /* skip warning when disable debug */
+ {
+ RT_ASSERT(obj != object);
+ }
}
/* leave critical */
rt_exit_critical();
diff --git a/src/scheduler.c b/src/scheduler.c
index 513c5a70eb..c50df06bda 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -75,15 +75,15 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
RT_ASSERT(thread != RT_NULL);
#if defined(ARCH_CPU_STACK_GROWS_UPWARD)
- if (*((rt_uint8_t *)((rt_ubase_t)thread->stack_addr + thread->stack_size - 1)) != '#' ||
+ if (*((rt_uint8_t *)((rt_ubase_t)thread->stack_addr + thread->stack_size - 1)) != '#' ||
#else
if (*((rt_uint8_t *)thread->stack_addr) != '#' ||
#endif
- (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_ubase_t)thread->sp <= (rt_ubase_t)thread->stack_addr ||
+ (rt_ubase_t)thread->sp >
+ (rt_ubase_t)thread->stack_addr + (rt_ubase_t)thread->stack_size)
{
- rt_uint32_t level;
+ rt_ubase_t level;
rt_kprintf("thread:%s stack overflow\n", thread->name);
#ifdef RT_USING_FINSH
@@ -96,15 +96,15 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
while (level);
}
#if defined(ARCH_CPU_STACK_GROWS_UPWARD)
- else if ((rt_uint32_t)thread->sp > ((rt_uint32_t)thread->stack_addr + thread->stack_size))
+ else if ((rt_ubase_t)thread->sp > ((rt_ubase_t)thread->stack_addr + thread->stack_size))
{
rt_kprintf("warning: %s stack is close to the top of stack address.\n",
thread->name);
}
#else
- else if ((rt_uint32_t)thread->sp <= ((rt_uint32_t)thread->stack_addr + 32))
+ else if ((rt_ubase_t)thread->sp <= ((rt_ubase_t)thread->stack_addr + 32))
{
- rt_kprintf("warning: %s stack is close to the bottom of stack address.\n",
+ rt_kprintf("warning: %s stack is close to end of stack address.\n",
thread->name);
}
#endif
@@ -238,8 +238,8 @@ void rt_schedule(void)
if (rt_interrupt_nest == 0)
{
- rt_hw_context_switch((rt_uint32_t)&from_thread->sp,
- (rt_uint32_t)&to_thread->sp);
+ rt_hw_context_switch((rt_ubase_t)&from_thread->sp,
+ (rt_ubase_t)&to_thread->sp);
#ifdef RT_USING_SIGNALS
if (rt_current_thread->stat & RT_THREAD_STAT_SIGNAL_PENDING)
@@ -266,8 +266,8 @@ void rt_schedule(void)
{
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);
+ rt_hw_context_switch_interrupt((rt_ubase_t)&from_thread->sp,
+ (rt_ubase_t)&to_thread->sp);
}
}
}
diff --git a/src/slab.c b/src/slab.c
index f4806ddb60..0872ecf092 100644
--- a/src/slab.c
+++ b/src/slab.c
@@ -217,9 +217,9 @@ struct memusage
};
static struct memusage *memusage = RT_NULL;
#define btokup(addr) \
- (&memusage[((rt_uint32_t)(addr) - heap_start) >> RT_MM_PAGE_BITS])
+ (&memusage[((rt_ubase_t)(addr) - heap_start) >> RT_MM_PAGE_BITS])
-static rt_uint32_t heap_start, heap_end;
+static rt_ubase_t heap_start, heap_end;
/* page allocator */
struct rt_page_head
@@ -275,7 +275,7 @@ void rt_page_free(void *addr, rt_size_t npages)
struct rt_page_head **prev;
RT_ASSERT(addr != RT_NULL);
- RT_ASSERT((rt_uint32_t)addr % RT_MM_PAGE_SIZE == 0);
+ RT_ASSERT((rt_ubase_t)addr % RT_MM_PAGE_SIZE == 0);
RT_ASSERT(npages != 0);
n = (struct rt_page_head *)addr;
@@ -348,13 +348,13 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
RT_DEBUG_NOT_IN_INTERRUPT;
/* align begin and end addr to page */
- heap_start = RT_ALIGN((rt_uint32_t)begin_addr, RT_MM_PAGE_SIZE);
- heap_end = RT_ALIGN_DOWN((rt_uint32_t)end_addr, RT_MM_PAGE_SIZE);
+ heap_start = RT_ALIGN((rt_ubase_t)begin_addr, RT_MM_PAGE_SIZE);
+ heap_end = RT_ALIGN_DOWN((rt_ubase_t)end_addr, RT_MM_PAGE_SIZE);
if (heap_start >= heap_end)
{
rt_kprintf("rt_system_heap_init, wrong address[0x%x - 0x%x]\n",
- (rt_uint32_t)begin_addr, (rt_uint32_t)end_addr);
+ (rt_ubase_t)begin_addr, (rt_ubase_t)end_addr);
return;
}
@@ -391,7 +391,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
memusage = rt_page_alloc(limsize / RT_MM_PAGE_SIZE);
RT_DEBUG_LOG(RT_DEBUG_SLAB, ("memusage 0x%x, size 0x%x\n",
- (rt_uint32_t)memusage, limsize));
+ (rt_ubase_t)memusage, limsize));
}
/*
@@ -401,7 +401,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
rt_inline int zoneindex(rt_size_t *bytes)
{
/* unsigned for shift opt */
- rt_uint32_t n = (rt_uint32_t)(*bytes);
+ rt_ubase_t n = (rt_ubase_t)(*bytes);
if (n < 128)
{
@@ -507,7 +507,7 @@ void *rt_malloc(rt_size_t size)
("malloc a large memory 0x%x, page cnt %d, kup %d\n",
size,
size >> RT_MM_PAGE_BITS,
- ((rt_uint32_t)chunk - heap_start) >> RT_MM_PAGE_BITS));
+ ((rt_ubase_t)chunk - heap_start) >> RT_MM_PAGE_BITS));
/* lock heap */
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
@@ -610,7 +610,7 @@ void *rt_malloc(rt_size_t size)
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
RT_DEBUG_LOG(RT_DEBUG_SLAB, ("alloc a new zone: 0x%x\n",
- (rt_uint32_t)z));
+ (rt_ubase_t)z));
/* set message usage */
for (off = 0, kup = btokup(z); off < zone_page_cnt; off ++)
@@ -694,7 +694,7 @@ void *rt_realloc(void *ptr, rt_size_t size)
* Get the original allocation's zone. If the new request winds up
* using the same chunk size we do not have to do anything.
*/
- kup = btokup((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK);
+ kup = btokup((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK);
if (kup->type == PAGE_TYPE_LARGE)
{
rt_size_t osize;
@@ -709,7 +709,7 @@ void *rt_realloc(void *ptr, rt_size_t size)
}
else if (kup->type == PAGE_TYPE_SMALL)
{
- z = (slab_zone *)(((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK) -
+ z = (slab_zone *)(((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK) -
kup->size * RT_MM_PAGE_SIZE);
RT_ASSERT(z->z_magic == ZALLOC_SLAB_MAGIC);
@@ -783,20 +783,20 @@ void rt_free(void *ptr)
/* get memory usage */
#if RT_DEBUG_SLAB
{
- rt_uint32_t addr = ((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK);
+ rt_ubase_t addr = ((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK);
RT_DEBUG_LOG(RT_DEBUG_SLAB,
("free a memory 0x%x and align to 0x%x, kup index %d\n",
- (rt_uint32_t)ptr,
- (rt_uint32_t)addr,
- ((rt_uint32_t)(addr) - heap_start) >> RT_MM_PAGE_BITS));
+ (rt_ubase_t)ptr,
+ (rt_ubase_t)addr,
+ ((rt_ubase_t)(addr) - heap_start) >> RT_MM_PAGE_BITS));
}
#endif
- kup = btokup((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK);
+ kup = btokup((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK);
/* release large allocation */
if (kup->type == PAGE_TYPE_LARGE)
{
- rt_uint32_t size;
+ rt_ubase_t size;
/* lock heap */
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
@@ -811,7 +811,7 @@ void rt_free(void *ptr)
RT_DEBUG_LOG(RT_DEBUG_SLAB,
("free large memory block 0x%x, page count %d\n",
- (rt_uint32_t)ptr, size));
+ (rt_ubase_t)ptr, size));
/* free this page */
rt_page_free(ptr, size);
@@ -823,7 +823,7 @@ void rt_free(void *ptr)
rt_sem_take(&heap_sem, RT_WAITING_FOREVER);
/* zone case. get out zone. */
- z = (slab_zone *)(((rt_uint32_t)ptr & ~RT_MM_PAGE_MASK) -
+ z = (slab_zone *)(((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK) -
kup->size * RT_MM_PAGE_SIZE);
RT_ASSERT(z->z_magic == ZALLOC_SLAB_MAGIC);
@@ -857,7 +857,7 @@ void rt_free(void *ptr)
slab_zone **pz;
RT_DEBUG_LOG(RT_DEBUG_SLAB, ("free zone 0x%x\n",
- (rt_uint32_t)z, z->z_zoneindex));
+ (rt_ubase_t)z, z->z_zoneindex));
/* remove zone from zone array list */
for (pz = &zone_array[z->z_zoneindex]; z != *pz; pz = &(*pz)->z_next)
diff --git a/src/thread.c b/src/thread.c
index 940d24e6f2..db79f640b5 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -142,7 +142,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
(void *)rt_thread_exit);
#else
thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter,
- (void *)((char *)thread->stack_addr + thread->stack_size - 4),
+ (rt_uint8_t *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)),
(void *)rt_thread_exit);
#endif
@@ -169,7 +169,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
thread->cleanup = 0;
thread->user_data = 0;
- /* init thread timer */
+ /* initialize thread timer */
rt_timer_init(&(thread->thread_timer),
thread->name,
rt_thread_timeout,
@@ -230,7 +230,7 @@ rt_err_t rt_thread_init(struct rt_thread *thread,
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(stack_start != RT_NULL);
- /* init thread object */
+ /* initialize thread object */
rt_object_init((rt_object_t)thread, RT_Object_Class_Thread, name);
return _rt_thread_init(thread,
@@ -269,7 +269,7 @@ rt_err_t rt_thread_startup(rt_thread_t thread)
RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_INIT);
RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
- /* set current priority to init priority */
+ /* set current priority to initialize priority */
thread->current_priority = thread->init_priority;
/* calculate priority attribute */
@@ -422,12 +422,12 @@ rt_err_t rt_thread_delete(rt_thread_t thread)
/* release thread timer */
rt_timer_detach(&(thread->thread_timer));
- /* change stat */
- thread->stat = RT_THREAD_CLOSE;
-
/* disable interrupt */
lock = rt_hw_interrupt_disable();
+ /* change stat */
+ thread->stat = RT_THREAD_CLOSE;
+
/* insert to defunct thread list */
rt_list_insert_after(&rt_thread_defunct, &(thread->tlist));