From 076941612a5105acd51a42e5c0d36eb632f5dffa Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 4 Jun 2021 00:34:27 +0800 Subject: [PATCH 01/11] =?UTF-8?q?[kernel]=20=E8=A7=84=E8=8C=83=E5=86=85?= =?UTF-8?q?=E6=A0=B8=E5=86=85=E9=83=A8=E5=87=BD=E6=95=B0=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/idle.c | 4 +- src/ipc.c | 102 ++++++++++++++++++++++++------------------------ src/scheduler.c | 14 +++---- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/idle.c b/src/idle.c index 59868352d8..317ee76926 100644 --- a/src/idle.c +++ b/src/idle.c @@ -129,7 +129,7 @@ rt_err_t rt_thread_idle_delhook(void (*hook)(void)) #ifdef RT_USING_HEAP /* Return whether there is defunctional thread to be deleted. */ -rt_inline int _has_defunct_thread(void) +rt_inline int _rt_has_defunct_thread(void) { /* The rt_list_isempty has prototype of "int rt_list_isempty(const rt_list_t *l)". * So the compiler has a good reason that the rt_thread_defunct list does @@ -165,7 +165,7 @@ void rt_thread_idle_excute(void) lock = rt_hw_interrupt_disable(); /* check whether list is empty */ - if (!_has_defunct_thread()) + if (!_rt_has_defunct_thread()) { rt_hw_interrupt_enable(lock); break; diff --git a/src/ipc.c b/src/ipc.c index 6cd38b74ab..311724f0a6 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -64,7 +64,7 @@ extern void (*rt_object_put_hook)(struct rt_object *object); * * @return the operation status, RT_EOK on successful */ -rt_inline rt_err_t rt_ipc_object_init(struct rt_ipc_object *ipc) +rt_inline rt_err_t _rt_ipc_object_init(struct rt_ipc_object *ipc) { /* initialize ipc object */ rt_list_init(&(ipc->suspend_thread)); @@ -83,7 +83,7 @@ rt_inline rt_err_t rt_ipc_object_init(struct rt_ipc_object *ipc) * * @return the operation status, RT_EOK on successful */ -rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, +rt_inline rt_err_t _rt_ipc_list_suspend(rt_list_t *list, struct rt_thread *thread, rt_uint8_t flag) { @@ -141,7 +141,7 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list, * * @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; @@ -164,7 +164,7 @@ 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; register rt_ubase_t temp; @@ -202,7 +202,7 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list) * * @return the highest priority */ -rt_uint8_t rt_ipc_get_highest_priority(rt_list_t *list) +rt_uint8_t _rt_ipc_get_highest_priority(rt_list_t *list) { struct rt_list_node *n; struct rt_thread *sthread; @@ -243,7 +243,7 @@ rt_err_t rt_sem_init(rt_sem_t sem, rt_object_init(&(sem->parent.parent), RT_Object_Class_Semaphore, name); /* initialize ipc object */ - rt_ipc_object_init(&(sem->parent)); + _rt_ipc_object_init(&(sem->parent)); /* set initial value */ sem->value = (rt_uint16_t)value; @@ -272,7 +272,7 @@ rt_err_t rt_sem_detach(rt_sem_t sem) RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent)); /* wakeup all suspended threads */ - rt_ipc_list_resume_all(&(sem->parent.suspend_thread)); + _rt_ipc_list_resume_all(&(sem->parent.suspend_thread)); /* detach semaphore object */ rt_object_detach(&(sem->parent.parent)); @@ -306,7 +306,7 @@ rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag) return sem; /* initialize ipc object */ - rt_ipc_object_init(&(sem->parent)); + _rt_ipc_object_init(&(sem->parent)); /* set initial value */ sem->value = value; @@ -337,7 +337,7 @@ rt_err_t rt_sem_delete(rt_sem_t sem) RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent) == RT_FALSE); /* wakeup all suspended threads */ - rt_ipc_list_resume_all(&(sem->parent.suspend_thread)); + _rt_ipc_list_resume_all(&(sem->parent.suspend_thread)); /* delete semaphore object */ rt_object_delete(&(sem->parent.parent)); @@ -408,7 +408,7 @@ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time) thread->name)); /* suspend thread */ - rt_ipc_list_suspend(&(sem->parent.suspend_thread), + _rt_ipc_list_suspend(&(sem->parent.suspend_thread), thread, sem->parent.parent.flag); @@ -489,7 +489,7 @@ rt_err_t rt_sem_release(rt_sem_t sem) if (!rt_list_isempty(&sem->parent.suspend_thread)) { /* resume the suspended thread */ - rt_ipc_list_resume(&(sem->parent.suspend_thread)); + _rt_ipc_list_resume(&(sem->parent.suspend_thread)); need_schedule = RT_TRUE; } else @@ -543,7 +543,7 @@ rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg) level = rt_hw_interrupt_disable(); /* resume all waiting thread */ - rt_ipc_list_resume_all(&sem->parent.suspend_thread); + _rt_ipc_list_resume_all(&sem->parent.suspend_thread); /* set new value */ sem->value = (rt_uint16_t)value; @@ -581,7 +581,7 @@ rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag) rt_object_init(&(mutex->parent.parent), RT_Object_Class_Mutex, name); /* initialize ipc object */ - rt_ipc_object_init(&(mutex->parent)); + _rt_ipc_object_init(&(mutex->parent)); mutex->value = 1; mutex->owner = RT_NULL; @@ -612,7 +612,7 @@ rt_err_t rt_mutex_detach(rt_mutex_t mutex) RT_ASSERT(rt_object_is_systemobject(&mutex->parent.parent)); /* wakeup all suspended threads */ - rt_ipc_list_resume_all(&(mutex->parent.suspend_thread)); + _rt_ipc_list_resume_all(&(mutex->parent.suspend_thread)); /* detach semaphore object */ rt_object_detach(&(mutex->parent.parent)); @@ -644,7 +644,7 @@ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag) return mutex; /* initialize ipc object */ - rt_ipc_object_init(&(mutex->parent)); + _rt_ipc_object_init(&(mutex->parent)); mutex->value = 1; mutex->owner = RT_NULL; @@ -677,7 +677,7 @@ rt_err_t rt_mutex_delete(rt_mutex_t mutex) RT_ASSERT(rt_object_is_systemobject(&mutex->parent.parent) == RT_FALSE); /* wakeup all suspended threads */ - rt_ipc_list_resume_all(&(mutex->parent.suspend_thread)); + _rt_ipc_list_resume_all(&(mutex->parent.suspend_thread)); /* delete mutex object */ rt_object_delete(&(mutex->parent.parent)); @@ -791,7 +791,7 @@ __again: } /* suspend current thread */ - rt_ipc_list_suspend(&(mutex->parent.suspend_thread), + _rt_ipc_list_suspend(&(mutex->parent.suspend_thread), thread, mutex->parent.parent.flag); @@ -938,7 +938,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) * 2.The priority of the thread to be resumed is not equal to the * highest priority in the queue; */ - max_priority_in_queue = rt_ipc_get_highest_priority(&mutex->parent.suspend_thread); + max_priority_in_queue = _rt_ipc_get_highest_priority(&mutex->parent.suspend_thread); if (mutex->parent.parent.flag == RT_IPC_FLAG_FIFO && thread->current_priority != max_priority_in_queue) { @@ -958,7 +958,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) } /* resume thread */ - rt_ipc_list_resume(&(mutex->parent.suspend_thread)); + _rt_ipc_list_resume(&(mutex->parent.suspend_thread)); need_schedule = RT_TRUE; } @@ -1035,7 +1035,7 @@ rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag) event->parent.parent.flag = flag; /* initialize ipc object */ - rt_ipc_object_init(&(event->parent)); + _rt_ipc_object_init(&(event->parent)); /* initialize event */ event->set = 0; @@ -1059,7 +1059,7 @@ rt_err_t rt_event_detach(rt_event_t event) RT_ASSERT(rt_object_is_systemobject(&event->parent.parent)); /* resume all suspended thread */ - rt_ipc_list_resume_all(&(event->parent.suspend_thread)); + _rt_ipc_list_resume_all(&(event->parent.suspend_thread)); /* detach event object */ rt_object_detach(&(event->parent.parent)); @@ -1092,7 +1092,7 @@ rt_event_t rt_event_create(const char *name, rt_uint8_t flag) event->parent.parent.flag = flag; /* initialize ipc object */ - rt_ipc_object_init(&(event->parent)); + _rt_ipc_object_init(&(event->parent)); /* initialize event */ event->set = 0; @@ -1118,7 +1118,7 @@ rt_err_t rt_event_delete(rt_event_t event) RT_DEBUG_NOT_IN_INTERRUPT; /* resume all suspended thread */ - rt_ipc_list_resume_all(&(event->parent.suspend_thread)); + _rt_ipc_list_resume_all(&(event->parent.suspend_thread)); /* delete event object */ rt_object_delete(&(event->parent.parent)); @@ -1321,7 +1321,7 @@ rt_err_t rt_event_recv(rt_event_t event, thread->event_info = option; /* put thread to suspended thread list */ - rt_ipc_list_suspend(&(event->parent.suspend_thread), + _rt_ipc_list_suspend(&(event->parent.suspend_thread), thread, event->parent.parent.flag); @@ -1387,7 +1387,7 @@ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg) level = rt_hw_interrupt_disable(); /* resume all waiting thread */ - rt_ipc_list_resume_all(&event->parent.suspend_thread); + _rt_ipc_list_resume_all(&event->parent.suspend_thread); /* initialize event set */ event->set = 0; @@ -1433,7 +1433,7 @@ rt_err_t rt_mb_init(rt_mailbox_t mb, mb->parent.parent.flag = flag; /* initialize ipc object */ - rt_ipc_object_init(&(mb->parent)); + _rt_ipc_object_init(&(mb->parent)); /* initialize mailbox */ mb->msg_pool = (rt_ubase_t *)msgpool; @@ -1464,9 +1464,9 @@ rt_err_t rt_mb_detach(rt_mailbox_t mb) RT_ASSERT(rt_object_is_systemobject(&mb->parent.parent)); /* resume all suspended thread */ - rt_ipc_list_resume_all(&(mb->parent.suspend_thread)); + _rt_ipc_list_resume_all(&(mb->parent.suspend_thread)); /* also resume all mailbox private suspended thread */ - rt_ipc_list_resume_all(&(mb->suspend_sender_thread)); + _rt_ipc_list_resume_all(&(mb->suspend_sender_thread)); /* detach mailbox object */ rt_object_detach(&(mb->parent.parent)); @@ -1500,7 +1500,7 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag) mb->parent.parent.flag = flag; /* initialize ipc object */ - rt_ipc_object_init(&(mb->parent)); + _rt_ipc_object_init(&(mb->parent)); /* initialize mailbox */ mb->size = size; @@ -1540,10 +1540,10 @@ rt_err_t rt_mb_delete(rt_mailbox_t mb) RT_ASSERT(rt_object_is_systemobject(&mb->parent.parent) == RT_FALSE); /* resume all suspended thread */ - rt_ipc_list_resume_all(&(mb->parent.suspend_thread)); + _rt_ipc_list_resume_all(&(mb->parent.suspend_thread)); /* also resume all mailbox private suspended thread */ - rt_ipc_list_resume_all(&(mb->suspend_sender_thread)); + _rt_ipc_list_resume_all(&(mb->suspend_sender_thread)); /* free mailbox pool */ RT_KERNEL_FREE(mb->msg_pool); @@ -1612,7 +1612,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, RT_DEBUG_IN_THREAD_CONTEXT; /* suspend current thread */ - rt_ipc_list_suspend(&(mb->suspend_sender_thread), + _rt_ipc_list_suspend(&(mb->suspend_sender_thread), thread, mb->parent.parent.flag); @@ -1679,7 +1679,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, /* resume suspended thread */ if (!rt_list_isempty(&mb->parent.suspend_thread)) { - rt_ipc_list_resume(&(mb->parent.suspend_thread)); + _rt_ipc_list_resume(&(mb->parent.suspend_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -1760,7 +1760,7 @@ rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value) /* resume suspended thread */ if (!rt_list_isempty(&mb->parent.suspend_thread)) { - rt_ipc_list_resume(&(mb->parent.suspend_thread)); + _rt_ipc_list_resume(&(mb->parent.suspend_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -1834,7 +1834,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout) RT_DEBUG_IN_THREAD_CONTEXT; /* suspend current thread */ - rt_ipc_list_suspend(&(mb->parent.suspend_thread), + _rt_ipc_list_suspend(&(mb->parent.suspend_thread), thread, mb->parent.parent.flag); @@ -1897,7 +1897,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout) /* resume suspended thread */ if (!rt_list_isempty(&(mb->suspend_sender_thread))) { - rt_ipc_list_resume(&(mb->suspend_sender_thread)); + _rt_ipc_list_resume(&(mb->suspend_sender_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -1941,9 +1941,9 @@ rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg) level = rt_hw_interrupt_disable(); /* resume all waiting thread */ - rt_ipc_list_resume_all(&(mb->parent.suspend_thread)); + _rt_ipc_list_resume_all(&(mb->parent.suspend_thread)); /* also resume all mailbox private suspended thread */ - rt_ipc_list_resume_all(&(mb->suspend_sender_thread)); + _rt_ipc_list_resume_all(&(mb->suspend_sender_thread)); /* re-init mailbox */ mb->entry = 0; @@ -2002,7 +2002,7 @@ rt_err_t rt_mq_init(rt_mq_t mq, mq->parent.parent.flag = flag; /* initialize ipc object */ - rt_ipc_object_init(&(mq->parent)); + _rt_ipc_object_init(&(mq->parent)); /* set message pool */ mq->msg_pool = msgpool; @@ -2050,9 +2050,9 @@ rt_err_t rt_mq_detach(rt_mq_t mq) RT_ASSERT(rt_object_is_systemobject(&mq->parent.parent)); /* resume all suspended thread */ - rt_ipc_list_resume_all(&mq->parent.suspend_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)); + _rt_ipc_list_resume_all(&(mq->suspend_sender_thread)); /* detach message queue object */ rt_object_detach(&(mq->parent.parent)); @@ -2092,7 +2092,7 @@ rt_mq_t rt_mq_create(const char *name, mq->parent.parent.flag = flag; /* initialize ipc object */ - rt_ipc_object_init(&(mq->parent)); + _rt_ipc_object_init(&(mq->parent)); /* initialize message queue */ @@ -2150,9 +2150,9 @@ rt_err_t rt_mq_delete(rt_mq_t mq) RT_ASSERT(rt_object_is_systemobject(&mq->parent.parent) == RT_FALSE); /* resume all suspended thread */ - rt_ipc_list_resume_all(&(mq->parent.suspend_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)); + _rt_ipc_list_resume_all(&(mq->suspend_sender_thread)); /* free message queue pool */ RT_KERNEL_FREE(mq->msg_pool); @@ -2234,7 +2234,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, RT_DEBUG_IN_THREAD_CONTEXT; /* suspend current thread */ - rt_ipc_list_suspend(&(mq->suspend_sender_thread), + _rt_ipc_list_suspend(&(mq->suspend_sender_thread), thread, mq->parent.parent.flag); @@ -2320,7 +2320,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, /* resume suspended thread */ if (!rt_list_isempty(&mq->parent.suspend_thread)) { - rt_ipc_list_resume(&(mq->parent.suspend_thread)); + _rt_ipc_list_resume(&(mq->parent.suspend_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -2428,7 +2428,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) /* resume suspended thread */ if (!rt_list_isempty(&mq->parent.suspend_thread)) { - rt_ipc_list_resume(&(mq->parent.suspend_thread)); + _rt_ipc_list_resume(&(mq->parent.suspend_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -2510,7 +2510,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq, } /* suspend current thread */ - rt_ipc_list_suspend(&(mq->parent.suspend_thread), + _rt_ipc_list_suspend(&(mq->parent.suspend_thread), thread, mq->parent.parent.flag); @@ -2586,7 +2586,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq, /* resume suspended thread */ if (!rt_list_isempty(&(mq->suspend_sender_thread))) { - rt_ipc_list_resume(&(mq->suspend_sender_thread)); + _rt_ipc_list_resume(&(mq->suspend_sender_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -2632,9 +2632,9 @@ rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg) level = rt_hw_interrupt_disable(); /* resume all waiting thread */ - rt_ipc_list_resume_all(&mq->parent.suspend_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)); + _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/scheduler.c b/src/scheduler.c index ed0f30fc81..179ad85e07 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -23,7 +23,7 @@ * 2013-12-21 Grissiom add rt_critical_level * 2018-11-22 Jesven remove the current task from ready queue * add per cpu ready queue - * add _get_highest_priority_thread to find highest priority task + * add _rt_get_highest_priority_thread to find highest priority task * rt_schedule_insert_thread won't insert current task to ready queue * in smp version, rt_hw_context_switch_interrupt maybe switch to * new task directly @@ -114,7 +114,7 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread) * get the highest priority thread in ready queue */ #ifdef RT_USING_SMP -static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio) +static struct rt_thread* _rt_get_highest_priority_thread(rt_ubase_t *highest_prio) { register struct rt_thread *highest_priority_thread; register rt_ubase_t highest_ready_priority, local_highest_ready_priority; @@ -150,7 +150,7 @@ static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio) return highest_priority_thread; } #else -static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio) +static struct rt_thread* _rt_get_highest_priority_thread(rt_ubase_t *highest_prio) { register struct rt_thread *highest_priority_thread; register rt_ubase_t highest_ready_priority; @@ -239,7 +239,7 @@ void rt_system_scheduler_start(void) register struct rt_thread *to_thread; rt_ubase_t highest_ready_priority; - to_thread = _get_highest_priority_thread(&highest_ready_priority); + to_thread = _rt_get_highest_priority_thread(&highest_ready_priority); #ifdef RT_USING_SMP to_thread->oncpu = rt_hw_cpu_id(); @@ -327,7 +327,7 @@ void rt_schedule(void) if (rt_thread_ready_priority_group != 0 || pcpu->priority_group != 0) { - to_thread = _get_highest_priority_thread(&highest_ready_priority); + to_thread = _rt_get_highest_priority_thread(&highest_ready_priority); current_thread->oncpu = RT_CPU_DETACHED; if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING) { @@ -425,7 +425,7 @@ void rt_schedule(void) /* need_insert_from_thread: need to insert from_thread to ready queue */ int need_insert_from_thread = 0; - to_thread = _get_highest_priority_thread(&highest_ready_priority); + to_thread = _rt_get_highest_priority_thread(&highest_ready_priority); if ((rt_current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING) { @@ -576,7 +576,7 @@ void rt_scheduler_do_irq_switch(void *context) if (rt_thread_ready_priority_group != 0 || pcpu->priority_group != 0) { - to_thread = _get_highest_priority_thread(&highest_ready_priority); + to_thread = _rt_get_highest_priority_thread(&highest_ready_priority); current_thread->oncpu = RT_CPU_DETACHED; if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING) { From bb848db2a40fd02ffaf059367a2e21603e47866c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 8 Jun 2021 10:49:20 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ipc.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/src/ipc.c b/src/ipc.c index 311724f0a6..b586a44181 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -194,31 +194,6 @@ rt_inline rt_err_t _rt_ipc_list_resume_all(rt_list_t *list) return RT_EOK; } -/** - * This function will get the highest priority from the specified - * list of threads - * - * @param list of the threads - * - * @return the highest priority - */ -rt_uint8_t _rt_ipc_get_highest_priority(rt_list_t *list) -{ - struct rt_list_node *n; - struct rt_thread *sthread; - rt_uint8_t priority = RT_THREAD_PRIORITY_MAX - 1; - - for (n = list->next; n != list; n = n->next) - { - sthread = rt_list_entry(n, struct rt_thread, tlist); - - priority = priority < sthread->current_priority ? - priority : - sthread->current_priority; - } - return priority; -} - #ifdef RT_USING_SEMAPHORE /** * This function will initialize a semaphore and put it under control of @@ -870,7 +845,6 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) register rt_base_t temp; struct rt_thread *thread; rt_bool_t need_schedule; - rt_uint8_t max_priority_in_queue = RT_THREAD_PRIORITY_MAX - 1; /* parameter check */ RT_ASSERT(mutex != RT_NULL); @@ -932,21 +906,6 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) mutex->owner = thread; mutex->original_priority = thread->current_priority; - /* Priority adjustment occurs only when the following conditions - * are met simultaneously: - * 1.The type of mutex is RT_IPC_FLAG_FIFO; - * 2.The priority of the thread to be resumed is not equal to the - * highest priority in the queue; - */ - max_priority_in_queue = _rt_ipc_get_highest_priority(&mutex->parent.suspend_thread); - if (mutex->parent.parent.flag == RT_IPC_FLAG_FIFO && - thread->current_priority != max_priority_in_queue) - { - rt_thread_control(thread, - RT_THREAD_CTRL_CHANGE_PRIORITY, - &(max_priority_in_queue)); - } - if(mutex->hold < RT_MUTEX_HOLD_MAX) { mutex->hold ++; From 3cb13b452394d1aca4874ccb935bed2c0f7d462f Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Fri, 30 Jul 2021 14:14:08 +0800 Subject: [PATCH 03/11] [stm32][eth] beautify codes --- bsp/stm32/libraries/HAL_Drivers/drv_eth.c | 24 +++++++++++++++-------- bsp/stm32/libraries/HAL_Drivers/drv_eth.h | 12 ++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_eth.c b/bsp/stm32/libraries/HAL_Drivers/drv_eth.c index 41e86b5134..b02bc351a4 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_eth.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_eth.c @@ -41,9 +41,9 @@ struct rt_stm32_eth /* interface address info, hw address */ rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* ETH_Speed */ - uint32_t ETH_Speed; + rt_uint32_t ETH_Speed; /* ETH_Duplex_Mode */ - uint32_t ETH_Mode; + rt_uint32_t ETH_Mode; }; static ETH_DMADescTypeDef *DMARxDscrTab, *DMATxDscrTab; @@ -167,8 +167,14 @@ static rt_err_t rt_stm32_eth_control(rt_device_t dev, int cmd, void *args) { case NIOCTL_GADDR: /* get mac address */ - if (args) rt_memcpy(args, stm32_eth_device.dev_addr, 6); - else return -RT_ERROR; + if (args) + { + rt_memcpy(args, stm32_eth_device.dev_addr, 6); + } + else + { + return -RT_ERROR; + } break; default : @@ -214,7 +220,7 @@ rt_err_t rt_stm32_eth_tx(rt_device_t dev, struct pbuf *p) while ((byteslefttocopy + bufferoffset) > ETH_TX_BUF_SIZE) { /* Copy data to Tx buffer*/ - memcpy((uint8_t *)((uint8_t *)buffer + bufferoffset), (uint8_t *)((uint8_t *)q->payload + payloadoffset), (ETH_TX_BUF_SIZE - bufferoffset)); + rt_memcpy((uint8_t *)((uint8_t *)buffer + bufferoffset), (uint8_t *)((uint8_t *)q->payload + payloadoffset), (ETH_TX_BUF_SIZE - bufferoffset)); /* Point to next descriptor */ DmaTxDesc = (ETH_DMADescTypeDef *)(DmaTxDesc->Buffer2NextDescAddr); @@ -236,7 +242,7 @@ rt_err_t rt_stm32_eth_tx(rt_device_t dev, struct pbuf *p) } /* Copy the remaining bytes */ - memcpy((uint8_t *)((uint8_t *)buffer + bufferoffset), (uint8_t *)((uint8_t *)q->payload + payloadoffset), byteslefttocopy); + rt_memcpy((uint8_t *)((uint8_t *)buffer + bufferoffset), (uint8_t *)((uint8_t *)q->payload + payloadoffset), byteslefttocopy); bufferoffset = bufferoffset + byteslefttocopy; framelength = framelength + byteslefttocopy; } @@ -327,7 +333,7 @@ struct pbuf *rt_stm32_eth_rx(rt_device_t dev) while ((byteslefttocopy + bufferoffset) > ETH_RX_BUF_SIZE) { /* Copy data to pbuf */ - memcpy((uint8_t *)((uint8_t *)q->payload + payloadoffset), (uint8_t *)((uint8_t *)buffer + bufferoffset), (ETH_RX_BUF_SIZE - bufferoffset)); + rt_memcpy((uint8_t *)((uint8_t *)q->payload + payloadoffset), (uint8_t *)((uint8_t *)buffer + bufferoffset), (ETH_RX_BUF_SIZE - bufferoffset)); /* Point to next descriptor */ dmarxdesc = (ETH_DMADescTypeDef *)(dmarxdesc->Buffer2NextDescAddr); @@ -338,7 +344,7 @@ struct pbuf *rt_stm32_eth_rx(rt_device_t dev) bufferoffset = 0; } /* Copy remaining data in pbuf */ - memcpy((uint8_t *)((uint8_t *)q->payload + payloadoffset), (uint8_t *)((uint8_t *)buffer + bufferoffset), byteslefttocopy); + rt_memcpy((uint8_t *)((uint8_t *)q->payload + payloadoffset), (uint8_t *)((uint8_t *)buffer + bufferoffset), byteslefttocopy); bufferoffset = bufferoffset + byteslefttocopy; } } @@ -385,7 +391,9 @@ void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth) rt_err_t result; result = eth_device_ready(&(stm32_eth_device.parent)); if (result != RT_EOK) + { LOG_I("RxCpltCallback err = %d", result); + } } void HAL_ETH_ErrorCallback(ETH_HandleTypeDef *heth) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_eth.h b/bsp/stm32/libraries/HAL_Drivers/drv_eth.h index 44eb75bbb8..3f98137697 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_eth.h +++ b/bsp/stm32/libraries/HAL_Drivers/drv_eth.h @@ -28,13 +28,12 @@ /* The PHY ID one register */ #define PHY_ID1_REG 0x02U - /* The PHY ID two register */ #define PHY_ID2_REG 0x03U - /* The PHY auto-negotiate advertise register */ #define PHY_AUTONEG_ADVERTISE_REG 0x04U + #ifdef PHY_USING_LAN8720A /* The PHY interrupt source flag register. */ #define PHY_INTERRUPT_FLAG_REG 0x1DU @@ -51,9 +50,8 @@ #define PHY_Status_SPEED_10M(sr) ((sr) & PHY_10M_MASK) #define PHY_Status_SPEED_100M(sr) ((sr) & PHY_100M_MASK) #define PHY_Status_FULL_DUPLEX(sr) ((sr) & PHY_FULL_DUPLEX_MASK) -#endif /* PHY_USING_LAN8720A */ -#ifdef PHY_USING_DM9161CEP +#elif defined(PHY_USING_DM9161CEP) #define PHY_Status_REG 0x11U #define PHY_10M_MASK ((1<<12) || (1<<13)) #define PHY_100M_MASK ((1<<14) || (1<<15)) @@ -69,9 +67,7 @@ #define PHY_LINK_CHANGE_MASK (1<<9) #define PHY_INT_MASK 0 -#endif /* PHY_USING_DM9161CEP */ - -#ifdef PHY_USING_DP83848C +#elif defined(PHY_USING_DP83848C) #define PHY_Status_REG 0x10U #define PHY_10M_MASK (1<<1) #define PHY_FULL_DUPLEX_MASK (1<<2) @@ -87,6 +83,6 @@ /* The PHY interrupt mask register. */ #define PHY_INTERRUPT_MASK_REG 0x12U #define PHY_INT_MASK (1<<5) -#endif /* PHY_USING_DP83848C */ +#endif #endif /* __DRV_ETH_H__ */ From 4cac267927bfabef0987e32dc2d1bf722757f6c6 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 3 Aug 2021 10:27:48 +0800 Subject: [PATCH 04/11] [lwip] implement RT_USING_ASM_MEMCPY --- components/net/lwip-1.4.1/src/lwipopts.h | 7 +++++++ components/net/lwip-2.0.2/src/lwipopts.h | 11 +++++++++-- components/net/lwip-2.0.3/src/lwipopts.h | 11 +++++++++-- components/net/lwip-2.1.2/src/lwipopts.h | 11 +++++++++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/components/net/lwip-1.4.1/src/lwipopts.h b/components/net/lwip-1.4.1/src/lwipopts.h index 0b7e092d6c..9148066d50 100644 --- a/components/net/lwip-1.4.1/src/lwipopts.h +++ b/components/net/lwip-1.4.1/src/lwipopts.h @@ -222,6 +222,13 @@ #define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) /* ---------- Memory options ---------- */ +#ifdef RT_USING_ASM_MEMCPY +#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len) +#else +#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#endif /* RT_USING_ASM_MEMCPY */ +#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len) + #define MEM_ALIGNMENT 4 #define MEM_LIBC_MALLOC 1 diff --git a/components/net/lwip-2.0.2/src/lwipopts.h b/components/net/lwip-2.0.2/src/lwipopts.h index d559684c02..fdfe1437b2 100644 --- a/components/net/lwip-2.0.2/src/lwipopts.h +++ b/components/net/lwip-2.0.2/src/lwipopts.h @@ -230,14 +230,21 @@ #define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) /* ---------- Memory options ---------- */ +#ifdef RT_USING_ASM_MEMCPY +#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len) +#else +#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#endif /* RT_USING_ASM_MEMCPY */ +#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len) + #ifdef RT_LWIP_MEM_ALIGNMENT #define MEM_ALIGNMENT RT_LWIP_MEM_ALIGNMENT #else #define MEM_ALIGNMENT 4 #endif -#define MEMP_OVERFLOW_CHECK 1 //// -#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //// +#define MEMP_OVERFLOW_CHECK 1 +#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //#define MEM_LIBC_MALLOC 1 //#define MEM_USE_POOLS 1 //#define MEMP_USE_CUSTOM_POOLS 1 diff --git a/components/net/lwip-2.0.3/src/lwipopts.h b/components/net/lwip-2.0.3/src/lwipopts.h index d559684c02..fdfe1437b2 100644 --- a/components/net/lwip-2.0.3/src/lwipopts.h +++ b/components/net/lwip-2.0.3/src/lwipopts.h @@ -230,14 +230,21 @@ #define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) /* ---------- Memory options ---------- */ +#ifdef RT_USING_ASM_MEMCPY +#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len) +#else +#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#endif /* RT_USING_ASM_MEMCPY */ +#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len) + #ifdef RT_LWIP_MEM_ALIGNMENT #define MEM_ALIGNMENT RT_LWIP_MEM_ALIGNMENT #else #define MEM_ALIGNMENT 4 #endif -#define MEMP_OVERFLOW_CHECK 1 //// -#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //// +#define MEMP_OVERFLOW_CHECK 1 +#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //#define MEM_LIBC_MALLOC 1 //#define MEM_USE_POOLS 1 //#define MEMP_USE_CUSTOM_POOLS 1 diff --git a/components/net/lwip-2.1.2/src/lwipopts.h b/components/net/lwip-2.1.2/src/lwipopts.h index 2cd7cb023a..a964ab13ac 100644 --- a/components/net/lwip-2.1.2/src/lwipopts.h +++ b/components/net/lwip-2.1.2/src/lwipopts.h @@ -242,9 +242,16 @@ #endif /* ---------- Memory options ---------- */ +#ifdef RT_USING_ASM_MEMCPY +#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len) +#else +#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#endif /* RT_USING_ASM_MEMCPY */ +#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len) + #define MEM_ALIGNMENT 4 -#define MEMP_OVERFLOW_CHECK 1 //// -#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //// +#define MEMP_OVERFLOW_CHECK 1 +#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //#define MEM_LIBC_MALLOC 1 //#define MEM_USE_POOLS 1 //#define MEMP_USE_CUSTOM_POOLS 1 From e41bb4f8be2c2e1cf839d1e527e7e065412af2bb Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 3 Aug 2021 10:29:17 +0800 Subject: [PATCH 05/11] [eth] replace rt_memcpy with SMEMCPY --- bsp/stm32/libraries/HAL_Drivers/drv_eth.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_eth.c b/bsp/stm32/libraries/HAL_Drivers/drv_eth.c index b02bc351a4..8b16c56157 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_eth.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_eth.c @@ -169,7 +169,7 @@ static rt_err_t rt_stm32_eth_control(rt_device_t dev, int cmd, void *args) /* get mac address */ if (args) { - rt_memcpy(args, stm32_eth_device.dev_addr, 6); + SMEMCPY(args, stm32_eth_device.dev_addr, 6); } else { @@ -220,7 +220,7 @@ rt_err_t rt_stm32_eth_tx(rt_device_t dev, struct pbuf *p) while ((byteslefttocopy + bufferoffset) > ETH_TX_BUF_SIZE) { /* Copy data to Tx buffer*/ - rt_memcpy((uint8_t *)((uint8_t *)buffer + bufferoffset), (uint8_t *)((uint8_t *)q->payload + payloadoffset), (ETH_TX_BUF_SIZE - bufferoffset)); + SMEMCPY((uint8_t *)((uint8_t *)buffer + bufferoffset), (uint8_t *)((uint8_t *)q->payload + payloadoffset), (ETH_TX_BUF_SIZE - bufferoffset)); /* Point to next descriptor */ DmaTxDesc = (ETH_DMADescTypeDef *)(DmaTxDesc->Buffer2NextDescAddr); @@ -242,7 +242,7 @@ rt_err_t rt_stm32_eth_tx(rt_device_t dev, struct pbuf *p) } /* Copy the remaining bytes */ - rt_memcpy((uint8_t *)((uint8_t *)buffer + bufferoffset), (uint8_t *)((uint8_t *)q->payload + payloadoffset), byteslefttocopy); + SMEMCPY((uint8_t *)((uint8_t *)buffer + bufferoffset), (uint8_t *)((uint8_t *)q->payload + payloadoffset), byteslefttocopy); bufferoffset = bufferoffset + byteslefttocopy; framelength = framelength + byteslefttocopy; } @@ -333,7 +333,7 @@ struct pbuf *rt_stm32_eth_rx(rt_device_t dev) while ((byteslefttocopy + bufferoffset) > ETH_RX_BUF_SIZE) { /* Copy data to pbuf */ - rt_memcpy((uint8_t *)((uint8_t *)q->payload + payloadoffset), (uint8_t *)((uint8_t *)buffer + bufferoffset), (ETH_RX_BUF_SIZE - bufferoffset)); + SMEMCPY((uint8_t *)((uint8_t *)q->payload + payloadoffset), (uint8_t *)((uint8_t *)buffer + bufferoffset), (ETH_RX_BUF_SIZE - bufferoffset)); /* Point to next descriptor */ dmarxdesc = (ETH_DMADescTypeDef *)(dmarxdesc->Buffer2NextDescAddr); @@ -344,7 +344,7 @@ struct pbuf *rt_stm32_eth_rx(rt_device_t dev) bufferoffset = 0; } /* Copy remaining data in pbuf */ - rt_memcpy((uint8_t *)((uint8_t *)q->payload + payloadoffset), (uint8_t *)((uint8_t *)buffer + bufferoffset), byteslefttocopy); + SMEMCPY((uint8_t *)((uint8_t *)q->payload + payloadoffset), (uint8_t *)((uint8_t *)buffer + bufferoffset), byteslefttocopy); bufferoffset = bufferoffset + byteslefttocopy; } } From 396297a993b03772165413ee9cd30fe4d89af87e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 3 Aug 2021 10:33:17 +0800 Subject: [PATCH 06/11] [ethernetif] replace rt_memcpy with SMEMCPY --- components/net/lwip-1.4.1/src/netif/ethernetif.c | 8 ++++---- components/net/lwip-2.0.2/src/netif/ethernetif.c | 8 ++++---- components/net/lwip-2.0.3/src/netif/ethernetif.c | 8 ++++---- components/net/lwip-2.1.2/src/netif/ethernetif.c | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 4565f5e528..40cd8fb6ef 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -201,14 +201,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, { return -RT_ERROR; } - rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); - rt_memcpy(&ina, &h->sin_addr, sizeof(ina)); + SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); + SMEMCPY(&ina, &h->sin_addr, sizeof(ina)); lwip_freeaddrinfo(res); if (inet_aton(inet_ntoa(ina), &target_addr) == 0) { return -RT_ERROR; } - rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); + SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) @@ -331,7 +331,7 @@ static int netdev_add(struct netif *lwip_netif) netdev->mtu = lwip_netif->mtu; netdev->ops = &lwip_netdev_ops; netdev->hwaddr_len = lwip_netif->hwaddr_len; - rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); + SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); netdev->ip_addr = lwip_netif->ip_addr; netdev->gw = lwip_netif->gw; netdev->netmask = lwip_netif->netmask; diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 1c0f3ca9b2..0b1943fdff 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -210,14 +210,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, { return -RT_ERROR; } - rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); - rt_memcpy(&ina, &h->sin_addr, sizeof(ina)); + SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); + SMEMCPY(&ina, &h->sin_addr, sizeof(ina)); lwip_freeaddrinfo(res); if (inet_aton(inet_ntoa(ina), &target_addr) == 0) { return -RT_ERROR; } - rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); + SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) @@ -340,7 +340,7 @@ static int netdev_add(struct netif *lwip_netif) netdev->mtu = lwip_netif->mtu; netdev->ops = &lwip_netdev_ops; netdev->hwaddr_len = lwip_netif->hwaddr_len; - rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); + SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); netdev->ip_addr = lwip_netif->ip_addr; netdev->gw = lwip_netif->gw; netdev->netmask = lwip_netif->netmask; diff --git a/components/net/lwip-2.0.3/src/netif/ethernetif.c b/components/net/lwip-2.0.3/src/netif/ethernetif.c index 1c0f3ca9b2..0b1943fdff 100644 --- a/components/net/lwip-2.0.3/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.3/src/netif/ethernetif.c @@ -210,14 +210,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, { return -RT_ERROR; } - rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); - rt_memcpy(&ina, &h->sin_addr, sizeof(ina)); + SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); + SMEMCPY(&ina, &h->sin_addr, sizeof(ina)); lwip_freeaddrinfo(res); if (inet_aton(inet_ntoa(ina), &target_addr) == 0) { return -RT_ERROR; } - rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); + SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) @@ -340,7 +340,7 @@ static int netdev_add(struct netif *lwip_netif) netdev->mtu = lwip_netif->mtu; netdev->ops = &lwip_netdev_ops; netdev->hwaddr_len = lwip_netif->hwaddr_len; - rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); + SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); netdev->ip_addr = lwip_netif->ip_addr; netdev->gw = lwip_netif->gw; netdev->netmask = lwip_netif->netmask; diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 81dd792f29..bd4db225ee 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -208,14 +208,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, { return -RT_ERROR; } - rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); - rt_memcpy(&ina, &h->sin_addr, sizeof(ina)); + SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); + SMEMCPY(&ina, &h->sin_addr, sizeof(ina)); lwip_freeaddrinfo(res); if (inet_aton(inet_ntoa(ina), &target_addr) == 0) { return -RT_ERROR; } - rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); + SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) @@ -338,7 +338,7 @@ static int netdev_add(struct netif *lwip_netif) netdev->mtu = lwip_netif->mtu; netdev->ops = &lwip_netdev_ops; netdev->hwaddr_len = lwip_netif->hwaddr_len; - rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); + SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); netdev->ip_addr = lwip_netif->ip_addr; netdev->gw = lwip_netif->gw; netdev->netmask = lwip_netif->netmask; From 24d29d829760f1432a68c9e06aaa7c47ff652d1f Mon Sep 17 00:00:00 2001 From: Weilin Wang Date: Tue, 3 Aug 2021 11:26:46 +0800 Subject: [PATCH 07/11] fix net driver --- bsp/raspberry-pi/raspi4-32/.config | 151 ++++++---- bsp/raspberry-pi/raspi4-32/Kconfig | 1 + bsp/raspberry-pi/raspi4-32/driver/drv_eth.c | 289 ++++++++++---------- bsp/raspberry-pi/raspi4-32/link.lds | 2 +- bsp/raspberry-pi/raspi4-32/rtconfig.h | 29 +- bsp/raspberry-pi/raspi4-32/rtconfig.py | 2 +- 6 files changed, 258 insertions(+), 216 deletions(-) diff --git a/bsp/raspberry-pi/raspi4-32/.config b/bsp/raspberry-pi/raspi4-32/.config index 813f9417f1..40f89fce1a 100644 --- a/bsp/raspberry-pi/raspi4-32/.config +++ b/bsp/raspberry-pi/raspi4-32/.config @@ -23,6 +23,12 @@ CONFIG_IDLE_THREAD_STACK_SIZE=2048 CONFIG_RT_USING_TIMER_SOFT=y CONFIG_RT_TIMER_THREAD_PRIO=4 CONFIG_RT_TIMER_THREAD_STACK_SIZE=2048 + +# +# kservice optimization +# +# CONFIG_RT_KSERVICE_USING_STDLIB is not set +# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set CONFIG_RT_DEBUG=y # CONFIG_RT_DEBUG_COLOR is not set # CONFIG_RT_DEBUG_INIT_CONFIG is not set @@ -67,8 +73,10 @@ CONFIG_RT_USING_DEVICE=y CONFIG_RT_USING_CONSOLE=y CONFIG_RT_CONSOLEBUF_SIZE=128 CONFIG_RT_CONSOLE_DEVICE_NAME="uart1" -CONFIG_RT_VER_NUM=0x40003 +# CONFIG_RT_PRINTF_LONGLONG is not set +CONFIG_RT_VER_NUM=0x40004 # CONFIG_RT_USING_CPU_FFS is not set +CONFIG_RT_USING_GIC_V2=y CONFIG_ARCH_ARMV8=y # CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set @@ -125,6 +133,11 @@ CONFIG_RT_DFS_ELM_WORD_ACCESS=y # CONFIG_RT_DFS_ELM_USE_LFN_2 is not set CONFIG_RT_DFS_ELM_USE_LFN_3=y CONFIG_RT_DFS_ELM_USE_LFN=3 +CONFIG_RT_DFS_ELM_LFN_UNICODE_0=y +# CONFIG_RT_DFS_ELM_LFN_UNICODE_1 is not set +# CONFIG_RT_DFS_ELM_LFN_UNICODE_2 is not set +# CONFIG_RT_DFS_ELM_LFN_UNICODE_3 is not set +CONFIG_RT_DFS_ELM_LFN_UNICODE=0 CONFIG_RT_DFS_ELM_MAX_LFN=255 CONFIG_RT_DFS_ELM_DRIVES=2 CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512 @@ -133,8 +146,6 @@ CONFIG_RT_DFS_ELM_REENTRANT=y CONFIG_RT_USING_DFS_DEVFS=y # CONFIG_RT_USING_DFS_ROMFS is not set # CONFIG_RT_USING_DFS_RAMFS is not set -# CONFIG_RT_USING_DFS_UFFS is not set -# CONFIG_RT_USING_DFS_JFFS2 is not set # CONFIG_RT_USING_DFS_NFS is not set # @@ -146,6 +157,8 @@ CONFIG_RT_USING_SYSTEM_WORKQUEUE=y CONFIG_RT_SYSTEM_WORKQUEUE_STACKSIZE=2048 CONFIG_RT_SYSTEM_WORKQUEUE_PRIORITY=23 CONFIG_RT_USING_SERIAL=y +CONFIG_RT_USING_SERIAL_V1=y +# CONFIG_RT_USING_SERIAL_V2 is not set CONFIG_RT_SERIAL_USING_DMA=y CONFIG_RT_SERIAL_RB_BUFSZ=512 # CONFIG_RT_USING_CAN is not set @@ -181,6 +194,7 @@ CONFIG_RT_USING_WDT=y # CONFIG_RT_USING_AUDIO is not set # CONFIG_RT_USING_SENSOR is not set CONFIG_RT_USING_TOUCH=y +# CONFIG_RT_TOUCH_PIN_IRQ is not set # CONFIG_RT_USING_HWCRYPTO is not set # CONFIG_RT_USING_PULSE_ENCODER is not set # CONFIG_RT_USING_INPUT_CAPTURE is not set @@ -203,6 +217,7 @@ CONFIG_RT_USING_POSIX=y # CONFIG_RT_USING_POSIX_GETLINE is not set # CONFIG_RT_USING_POSIX_AIO is not set # CONFIG_RT_USING_MODULE is not set +CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # # Network @@ -212,6 +227,7 @@ CONFIG_RT_USING_POSIX=y # Socket abstraction layer # CONFIG_RT_USING_SAL=y +CONFIG_SAL_INTERNET_CHECK=y # # protocol stack implement @@ -238,6 +254,7 @@ CONFIG_NETDEV_IPV6=0 CONFIG_RT_USING_LWIP=y # CONFIG_RT_USING_LWIP141 is not set CONFIG_RT_USING_LWIP202=y +# CONFIG_RT_USING_LWIP203 is not set # CONFIG_RT_USING_LWIP212 is not set # CONFIG_RT_USING_LWIP_IPV6 is not set CONFIG_RT_LWIP_MEM_ALIGNMENT=4 @@ -252,8 +269,8 @@ CONFIG_IP_SOF_BROADCAST_RECV=1 # # Static IPv4 Address # -CONFIG_RT_LWIP_IPADDR="192.168.1.30" -CONFIG_RT_LWIP_GWADDR="192.168.1.1" +CONFIG_RT_LWIP_IPADDR="192.168.111.172" +CONFIG_RT_LWIP_GWADDR="192.168.111.1" CONFIG_RT_LWIP_MSKADDR="255.255.255.0" CONFIG_RT_LWIP_UDP=y CONFIG_RT_LWIP_TCP=y @@ -307,6 +324,12 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_RT_USING_RYM is not set # CONFIG_RT_USING_ULOG is not set # CONFIG_RT_USING_UTEST is not set +# CONFIG_RT_USING_RT_LINK is not set + +# +# RT-Thread Utestcases +# +# CONFIG_RT_USING_UTESTCASES is not set # # RT-Thread online packages @@ -375,8 +398,6 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_LIBRWS is not set # CONFIG_PKG_USING_TCPSERVER is not set # CONFIG_PKG_USING_PROTOBUF_C is not set -# CONFIG_PKG_USING_ONNX_PARSER is not set -# CONFIG_PKG_USING_ONNX_BACKEND is not set # CONFIG_PKG_USING_DLT645 is not set # CONFIG_PKG_USING_QXWZ is not set # CONFIG_PKG_USING_SMTP_CLIENT is not set @@ -390,6 +411,13 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_PDULIB is not set # CONFIG_PKG_USING_BTSTACK is not set # CONFIG_PKG_USING_LORAWAN_ED_STACK is not set +# CONFIG_PKG_USING_WAYZ_IOTKIT is not set +# CONFIG_PKG_USING_MAVLINK is not set +# CONFIG_PKG_USING_RAPIDJSON is not set +# CONFIG_PKG_USING_BSAL is not set +# CONFIG_PKG_USING_AGILE_MODBUS is not set +# CONFIG_PKG_USING_AGILE_FTP is not set +# CONFIG_PKG_USING_EMBEDDEDPROTO is not set # # security packages @@ -415,6 +443,7 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_STEMWIN is not set # CONFIG_PKG_USING_WAVPLAYER is not set # CONFIG_PKG_USING_TJPGD is not set +# CONFIG_PKG_USING_PDFGEN is not set # CONFIG_PKG_USING_HELIX is not set # CONFIG_PKG_USING_AZUREGUIX is not set # CONFIG_PKG_USING_TOUCHGFX2RTT is not set @@ -429,6 +458,8 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_RDB is not set # CONFIG_PKG_USING_QRCODE is not set # CONFIG_PKG_USING_ULOG_EASYFLASH is not set +# CONFIG_PKG_USING_ULOG_FILE is not set +# CONFIG_PKG_USING_LOGMGR is not set # CONFIG_PKG_USING_ADBD is not set # CONFIG_PKG_USING_COREMARK is not set # CONFIG_PKG_USING_DHRYSTONE is not set @@ -441,6 +472,20 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_URLENCODE is not set # CONFIG_PKG_USING_UMCN is not set # CONFIG_PKG_USING_LWRB2RTT is not set +# CONFIG_PKG_USING_CPU_USAGE is not set +# CONFIG_PKG_USING_GBK2UTF8 is not set +# CONFIG_PKG_USING_VCONSOLE is not set +# CONFIG_PKG_USING_KDB is not set +# CONFIG_PKG_USING_WAMR is not set +# CONFIG_PKG_USING_MICRO_XRCE_DDS_CLIENT is not set +# CONFIG_PKG_USING_LWLOG is not set +# CONFIG_PKG_USING_ANV_TRACE is not set +# CONFIG_PKG_USING_ANV_MEMLEAK is not set +# CONFIG_PKG_USING_ANV_TESTSUIT is not set +# CONFIG_PKG_USING_ANV_BENCH is not set +# CONFIG_PKG_USING_DEVMEM is not set +# CONFIG_PKG_USING_REGEX is not set +# CONFIG_PKG_USING_MEM_SANDBOX is not set # # system packages @@ -448,7 +493,6 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_GUIENGINE is not set # CONFIG_PKG_USING_CAIRO is not set # CONFIG_PKG_USING_PIXMAN is not set -# CONFIG_PKG_USING_LWEXT4 is not set # CONFIG_PKG_USING_PARTITION is not set # CONFIG_PKG_USING_FAL is not set # CONFIG_PKG_USING_FLASHDB is not set @@ -458,6 +502,9 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_CMSIS is not set # CONFIG_PKG_USING_DFS_YAFFS is not set # CONFIG_PKG_USING_LITTLEFS is not set +# CONFIG_PKG_USING_DFS_JFFS2 is not set +# CONFIG_PKG_USING_DFS_UFFS is not set +# CONFIG_PKG_USING_LWEXT4 is not set # CONFIG_PKG_USING_THREAD_POOL is not set # CONFIG_PKG_USING_ROBOTS is not set # CONFIG_PKG_USING_EV is not set @@ -478,6 +525,15 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_UC_COMMON is not set # CONFIG_PKG_USING_UC_MODBUS is not set # CONFIG_PKG_USING_PPOOL is not set +# CONFIG_PKG_USING_OPENAMP is not set +# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set +# CONFIG_PKG_USING_RT_MEMCPY_CM is not set +# CONFIG_PKG_USING_QFPLIB_M0_FULL is not set +# CONFIG_PKG_USING_QFPLIB_M0_TINY is not set +# CONFIG_PKG_USING_QFPLIB_M3 is not set +# CONFIG_PKG_USING_LPM is not set +# CONFIG_PKG_USING_TLSF is not set +# CONFIG_PKG_USING_EVENT_RECORDER is not set # # peripheral libraries and drivers @@ -486,6 +542,7 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_REALTEK_AMEBA is not set # CONFIG_PKG_USING_SHT2X is not set # CONFIG_PKG_USING_SHT3X is not set +# CONFIG_PKG_USING_AS7341 is not set # CONFIG_PKG_USING_STM32_SDIO is not set # CONFIG_PKG_USING_ICM20608 is not set # CONFIG_PKG_USING_U8G2 is not set @@ -534,6 +591,29 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_DM9051 is not set # CONFIG_PKG_USING_SSD1306 is not set # CONFIG_PKG_USING_QKEY is not set +# CONFIG_PKG_USING_RS485 is not set +# CONFIG_PKG_USING_NES is not set +# CONFIG_PKG_USING_VIRTUAL_SENSOR is not set +# CONFIG_PKG_USING_VDEVICE is not set +# CONFIG_PKG_USING_SGM706 is not set +# CONFIG_PKG_USING_STM32WB55_SDK is not set +# CONFIG_PKG_USING_RDA58XX is not set +# CONFIG_PKG_USING_LIBNFC is not set +# CONFIG_PKG_USING_MFOC is not set +# CONFIG_PKG_USING_TMC51XX is not set + +# +# AI packages +# +# CONFIG_PKG_USING_LIBANN is not set +# CONFIG_PKG_USING_NNOM is not set +# CONFIG_PKG_USING_ONNX_BACKEND is not set +# CONFIG_PKG_USING_ONNX_PARSER is not set +# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set +# CONFIG_PKG_USING_ELAPACK is not set +# CONFIG_PKG_USING_ULAPACK is not set +# CONFIG_PKG_USING_QUEST is not set +# CONFIG_PKG_USING_NAXOS is not set # # miscellaneous packages @@ -543,6 +623,7 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_FASTLZ is not set # CONFIG_PKG_USING_MINILZO is not set # CONFIG_PKG_USING_QUICKLZ is not set +# CONFIG_PKG_USING_LZMA is not set # CONFIG_PKG_USING_MULTIBUTTON is not set # CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set # CONFIG_PKG_USING_CANFESTIVAL is not set @@ -564,64 +645,24 @@ CONFIG_RT_LWIP_USING_PING=y # CONFIG_PKG_USING_HELLO is not set # CONFIG_PKG_USING_VI is not set # CONFIG_PKG_USING_KI is not set -# CONFIG_PKG_USING_NNOM is not set -# CONFIG_PKG_USING_LIBANN is not set -# CONFIG_PKG_USING_ELAPACK is not set # CONFIG_PKG_USING_ARMv7M_DWT is not set # CONFIG_PKG_USING_VT100 is not set -# CONFIG_PKG_USING_ULAPACK is not set # CONFIG_PKG_USING_UKAL is not set # CONFIG_PKG_USING_CRCLIB is not set # -# games: games run on RT-Thread console +# entertainment: terminal games and other interesting software packages # # CONFIG_PKG_USING_THREES is not set # CONFIG_PKG_USING_2048 is not set +# CONFIG_PKG_USING_SNAKE is not set # CONFIG_PKG_USING_TETRIS is not set +# CONFIG_PKG_USING_DONUT is not set +# CONFIG_PKG_USING_ACLOCK is not set # CONFIG_PKG_USING_LWGPS is not set -# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set - -# -# Privated Packages of RealThread -# -# CONFIG_PKG_USING_CODEC is not set -# CONFIG_PKG_USING_PLAYER is not set -# CONFIG_PKG_USING_MPLAYER is not set -# CONFIG_PKG_USING_PERSIMMON_SRC is not set -# CONFIG_PKG_USING_JS_PERSIMMON is not set -# CONFIG_PKG_USING_JERRYSCRIPT_WIN32 is not set - -# -# Network Utilities -# -# CONFIG_PKG_USING_MDNS is not set -# CONFIG_PKG_USING_UPNP is not set -# CONFIG_PKG_USING_WICED is not set -# CONFIG_PKG_USING_CLOUDSDK is not set -# CONFIG_PKG_USING_POWER_MANAGER is not set -# CONFIG_PKG_USING_RT_OTA is not set -# CONFIG_PKG_USING_RDBD_SRC is not set -# CONFIG_PKG_USING_RTINSIGHT is not set -# CONFIG_PKG_USING_SMARTCONFIG is not set -# CONFIG_PKG_USING_RTX is not set -# CONFIG_RT_USING_TESTCASE is not set -# CONFIG_PKG_USING_NGHTTP2 is not set -# CONFIG_PKG_USING_AVS is not set -# CONFIG_PKG_USING_ALI_LINKKIT is not set -# CONFIG_PKG_USING_STS is not set -# CONFIG_PKG_USING_DLMS is not set -# CONFIG_PKG_USING_AUDIO_FRAMEWORK is not set -# CONFIG_PKG_USING_ZBAR is not set -# CONFIG_PKG_USING_MCF is not set -# CONFIG_PKG_USING_URPC is not set -# CONFIG_PKG_USING_BSAL is not set -# CONFIG_PKG_USING_DCM is not set -# CONFIG_PKG_USING_EMQ is not set -# CONFIG_PKG_USING_CFGM is not set -# CONFIG_PKG_USING_RT_CMSIS_DAP is not set -# CONFIG_PKG_USING_VIRTUAL_DEVICE is not set -# CONFIG_PKG_USING_SMODULE is not set +# CONFIG_PKG_USING_STATE_MACHINE is not set +# CONFIG_PKG_USING_MCURSES is not set +# CONFIG_PKG_USING_COWSAY is not set CONFIG_BCM2711_SOC=y # CONFIG_BSP_SUPPORT_FPU is not set diff --git a/bsp/raspberry-pi/raspi4-32/Kconfig b/bsp/raspberry-pi/raspi4-32/Kconfig index 1e49c47680..79712f4f17 100644 --- a/bsp/raspberry-pi/raspi4-32/Kconfig +++ b/bsp/raspberry-pi/raspi4-32/Kconfig @@ -23,6 +23,7 @@ config BCM2711_SOC select ARCH_ARMV8 select RT_USING_COMPONENTS_INIT select RT_USING_USER_MAIN + select RT_USING_GIC_V2 default y source "driver/Kconfig" diff --git a/bsp/raspberry-pi/raspi4-32/driver/drv_eth.c b/bsp/raspberry-pi/raspi4-32/driver/drv_eth.c index 163f58c150..a11707f7a2 100644 --- a/bsp/raspberry-pi/raspi4-32/driver/drv_eth.c +++ b/bsp/raspberry-pi/raspi4-32/driver/drv_eth.c @@ -19,6 +19,7 @@ #include "raspi4.h" #include "drv_eth.h" + #define DBG_LEVEL DBG_LOG #include #define LOG_TAG "drv.eth" @@ -26,12 +27,14 @@ static int link_speed = 0; static int link_flag = 0; -#define RECV_CACHE_BUF (2048) -#define SEND_CACHE_BUF (2048) -#define DMA_DISC_ADDR_SIZE (2 * 1024 *1024) +#define RECV_CACHE_BUF (1024) +#define SEND_CACHE_BUF (1024) +#define SEND_DATA_NO_CACHE (0x08200000) +#define RECV_DATA_NO_CACHE (0x08400000) +#define DMA_DISC_ADDR_SIZE (4 * 1024 *1024) -#define RX_DESC_BASE (mac_reg_base_addr + GENET_RX_OFF) -#define TX_DESC_BASE (mac_reg_base_addr + GENET_TX_OFF) +#define RX_DESC_BASE (MAC_REG + GENET_RX_OFF) +#define TX_DESC_BASE (MAC_REG + GENET_TX_OFF) #define MAX_ADDR_LEN (6) @@ -45,11 +48,11 @@ static rt_thread_t link_thread_tid = RT_NULL; #define LINK_THREAD_PRIORITY (20) #define LINK_THREAD_TIMESLICE (10) - static rt_uint32_t tx_index = 0; static rt_uint32_t rx_index = 0; static rt_uint32_t index_flag = 0; +static rt_uint32_t send_cache_pbuf[RECV_CACHE_BUF]; struct rt_eth_dev { @@ -60,12 +63,11 @@ struct rt_eth_dev int state; int index; struct rt_timer link_timer; + struct rt_timer rx_poll_timer; void *priv; }; static struct rt_eth_dev eth_dev; - -static struct rt_semaphore send_finsh_sem_lock; - +static struct rt_semaphore sem_lock; static struct rt_semaphore link_ack; static inline rt_uint32_t read32(void *addr) @@ -78,18 +80,12 @@ static inline void write32(void *addr, rt_uint32_t value) (*((volatile unsigned int*)(addr))) = value; } - - - static void eth_rx_irq(int irq, void *param) { rt_uint32_t val = 0; - - val = read32(mac_reg_base_addr + GENET_INTRL2_CPU_STAT); - val &= ~read32(mac_reg_base_addr + GENET_INTRL2_CPU_STAT_MASK); - - write32(mac_reg_base_addr + GENET_INTRL2_CPU_CLEAR, val); - + val = read32(MAC_REG + GENET_INTRL2_CPU_STAT); + val &= ~read32(MAC_REG + GENET_INTRL2_CPU_STAT_MASK); + write32(MAC_REG + GENET_INTRL2_CPU_CLEAR, val); if (val & GENET_IRQ_RXDMA_DONE) { eth_device_ready(ð_dev.parent); @@ -97,7 +93,7 @@ static void eth_rx_irq(int irq, void *param) if (val & GENET_IRQ_TXDMA_DONE) { - rt_sem_release(&send_finsh_sem_lock); + rt_sem_release(&sem_lock); } } @@ -109,11 +105,10 @@ static int bcmgenet_interface_set(void) { case PHY_INTERFACE_MODE_RGMII: case PHY_INTERFACE_MODE_RGMII_RXID: - write32(mac_reg_base_addr + SYS_PORT_CTRL, PORT_MODE_EXT_GPHY); + write32(MAC_REG + SYS_PORT_CTRL, PORT_MODE_EXT_GPHY); break; - default: - rt_kprintf("unknown phy mode: %d\n", mac_reg_base_addr); + rt_kprintf("unknown phy mode: %d\n", MAC_REG); return -1; } return 0; @@ -122,48 +117,44 @@ static int bcmgenet_interface_set(void) static void bcmgenet_umac_reset(void) { rt_uint32_t reg; - reg = read32(mac_reg_base_addr + SYS_RBUF_FLUSH_CTRL); + reg = read32(MAC_REG + SYS_RBUF_FLUSH_CTRL); reg |= BIT(1); - write32((mac_reg_base_addr + SYS_RBUF_FLUSH_CTRL), reg); + write32((MAC_REG + SYS_RBUF_FLUSH_CTRL), reg); reg &= ~BIT(1); - write32((mac_reg_base_addr + SYS_RBUF_FLUSH_CTRL), reg); + write32((MAC_REG + SYS_RBUF_FLUSH_CTRL), reg); DELAY_MICROS(10); - - write32((mac_reg_base_addr + SYS_RBUF_FLUSH_CTRL), 0); + write32((MAC_REG + SYS_RBUF_FLUSH_CTRL), 0); DELAY_MICROS(10); - - write32(mac_reg_base_addr + UMAC_CMD, 0); - write32(mac_reg_base_addr + UMAC_CMD, (CMD_SW_RESET | CMD_LCL_LOOP_EN)); + write32(MAC_REG + UMAC_CMD, 0); + write32(MAC_REG + UMAC_CMD, (CMD_SW_RESET | CMD_LCL_LOOP_EN)); DELAY_MICROS(2); - - write32(mac_reg_base_addr + UMAC_CMD, 0); + write32(MAC_REG + UMAC_CMD, 0); /* clear tx/rx counter */ - write32(mac_reg_base_addr + UMAC_MIB_CTRL, MIB_RESET_RX | MIB_RESET_TX | MIB_RESET_RUNT); - write32(mac_reg_base_addr + UMAC_MIB_CTRL, 0); - write32(mac_reg_base_addr + UMAC_MAX_FRAME_LEN, ENET_MAX_MTU_SIZE); - + write32(MAC_REG + UMAC_MIB_CTRL, MIB_RESET_RX | MIB_RESET_TX | MIB_RESET_RUNT); + write32(MAC_REG + UMAC_MIB_CTRL, 0); + write32(MAC_REG + UMAC_MAX_FRAME_LEN, ENET_MAX_MTU_SIZE); /* init rx registers, enable ip header optimization */ - reg = read32(mac_reg_base_addr + RBUF_CTRL); + reg = read32(MAC_REG + RBUF_CTRL); reg |= RBUF_ALIGN_2B; - write32(mac_reg_base_addr + RBUF_CTRL, reg); - write32(mac_reg_base_addr + RBUF_TBUF_SIZE_CTRL, 1); + write32(MAC_REG + RBUF_CTRL, reg); + write32(MAC_REG + RBUF_TBUF_SIZE_CTRL, 1); } static void bcmgenet_disable_dma(void) { rt_uint32_t tdma_reg = 0, rdma_reg = 0; - tdma_reg = read32(mac_reg_base_addr + TDMA_REG_BASE + DMA_CTRL); + tdma_reg = read32(MAC_REG + TDMA_REG_BASE + DMA_CTRL); tdma_reg &= ~(1UL << DMA_EN); - write32(mac_reg_base_addr + TDMA_REG_BASE + DMA_CTRL, tdma_reg); - rdma_reg = read32(mac_reg_base_addr + RDMA_REG_BASE + DMA_CTRL); + write32(MAC_REG + TDMA_REG_BASE + DMA_CTRL, tdma_reg); + rdma_reg = read32(MAC_REG + RDMA_REG_BASE + DMA_CTRL); rdma_reg &= ~(1UL << DMA_EN); - write32(mac_reg_base_addr + RDMA_REG_BASE + DMA_CTRL, rdma_reg); - write32(mac_reg_base_addr + UMAC_TX_FLUSH, 1); + write32(MAC_REG + RDMA_REG_BASE + DMA_CTRL, rdma_reg); + write32(MAC_REG + UMAC_TX_FLUSH, 1); DELAY_MICROS(100); - write32(mac_reg_base_addr + UMAC_TX_FLUSH, 0); + write32(MAC_REG + UMAC_TX_FLUSH, 0); } static void bcmgenet_enable_dma(void) @@ -172,10 +163,10 @@ static void bcmgenet_enable_dma(void) rt_uint32_t dma_ctrl = 0; dma_ctrl = (1 << (DEFAULT_Q + DMA_RING_BUF_EN_SHIFT)) | DMA_EN; - write32(mac_reg_base_addr + TDMA_REG_BASE + DMA_CTRL, dma_ctrl); + write32(MAC_REG + TDMA_REG_BASE + DMA_CTRL, dma_ctrl); - reg = read32(mac_reg_base_addr + RDMA_REG_BASE + DMA_CTRL); - write32(mac_reg_base_addr + RDMA_REG_BASE + DMA_CTRL, dma_ctrl | reg); + reg = read32(MAC_REG + RDMA_REG_BASE + DMA_CTRL); + write32(MAC_REG + RDMA_REG_BASE + DMA_CTRL, dma_ctrl | reg); } static int bcmgenet_mdio_write(rt_uint32_t addr, rt_uint32_t reg, rt_uint32_t value) @@ -183,16 +174,16 @@ static int bcmgenet_mdio_write(rt_uint32_t addr, rt_uint32_t reg, rt_uint32_t va int count = 10000; rt_uint32_t val; val = MDIO_WR | (addr << MDIO_PMD_SHIFT) | (reg << MDIO_REG_SHIFT) | (0xffff & value); - write32(mac_reg_base_addr + MDIO_CMD, val); + write32(MAC_REG + MDIO_CMD, val); - rt_uint32_t reg_val = read32(mac_reg_base_addr + MDIO_CMD); + rt_uint32_t reg_val = read32(MAC_REG + MDIO_CMD); reg_val = reg_val | MDIO_START_BUSY; - write32(mac_reg_base_addr + MDIO_CMD, reg_val); + write32(MAC_REG + MDIO_CMD, reg_val); - while ((read32(mac_reg_base_addr + MDIO_CMD) & MDIO_START_BUSY) && (--count)) + while ((read32(MAC_REG + MDIO_CMD) & MDIO_START_BUSY) && (--count)) DELAY_MICROS(1); - reg_val = read32(mac_reg_base_addr + MDIO_CMD); + reg_val = read32(MAC_REG + MDIO_CMD); return reg_val & 0xffff; } @@ -204,31 +195,32 @@ static int bcmgenet_mdio_read(rt_uint32_t addr, rt_uint32_t reg) rt_uint32_t reg_val = 0; val = MDIO_RD | (addr << MDIO_PMD_SHIFT) | (reg << MDIO_REG_SHIFT); - write32(mac_reg_base_addr + MDIO_CMD, val); + write32(MAC_REG + MDIO_CMD, val); - reg_val = read32(mac_reg_base_addr + MDIO_CMD); + reg_val = read32(MAC_REG + MDIO_CMD); reg_val = reg_val | MDIO_START_BUSY; - write32(mac_reg_base_addr + MDIO_CMD, reg_val); + write32(MAC_REG + MDIO_CMD, reg_val); - while ((read32(mac_reg_base_addr + MDIO_CMD) & MDIO_START_BUSY) && (--count)) + while ((read32(MAC_REG + MDIO_CMD) & MDIO_START_BUSY) && (--count)) DELAY_MICROS(1); - reg_val = read32(mac_reg_base_addr + MDIO_CMD); + reg_val = read32(MAC_REG + MDIO_CMD); return reg_val & 0xffff; } static int bcmgenet_gmac_write_hwaddr(void) { + //{0xdc,0xa6,0x32,0x28,0x22,0x50}; rt_uint8_t addr[6]; rt_uint32_t reg; bcm271x_mbox_hardware_get_mac_address(&addr[0]); reg = addr[0] << 24 | addr[1] << 16 | addr[2] << 8 | addr[3]; - write32(mac_reg_base_addr + UMAC_MAC0, reg); + write32(MAC_REG + UMAC_MAC0, reg); reg = addr[4] << 8 | addr[5]; - write32(mac_reg_base_addr + UMAC_MAC1, reg); + write32(MAC_REG + UMAC_MAC1, reg); return 0; } @@ -254,8 +246,10 @@ static void bcmgenet_mdio_init(void) rt_uint32_t ret = 0; /*get ethernet uid*/ ret = get_ethernet_uid(); - if (ret == 0) return; - + if (ret == 0) + { + return; + } /* reset phy */ bcmgenet_mdio_write(1, BCM54213PE_MII_CONTROL, MII_CONTROL_PHY_RESET); /* read control reg */ @@ -282,34 +276,34 @@ static void bcmgenet_mdio_init(void) static void rx_ring_init(void) { - write32(mac_reg_base_addr + RDMA_REG_BASE + DMA_SCB_BURST_SIZE, DMA_MAX_BURST_LENGTH); - write32(mac_reg_base_addr + RDMA_RING_REG_BASE + DMA_START_ADDR, 0x0); - write32(mac_reg_base_addr + RDMA_READ_PTR, 0x0); - write32(mac_reg_base_addr + RDMA_WRITE_PTR, 0x0); - write32(mac_reg_base_addr + RDMA_RING_REG_BASE + DMA_END_ADDR, RX_DESCS * DMA_DESC_SIZE / 4 - 1); + write32(MAC_REG + RDMA_REG_BASE + DMA_SCB_BURST_SIZE, DMA_MAX_BURST_LENGTH); + write32(MAC_REG + RDMA_RING_REG_BASE + DMA_START_ADDR, 0x0); + write32(MAC_REG + RDMA_READ_PTR, 0x0); + write32(MAC_REG + RDMA_WRITE_PTR, 0x0); + write32(MAC_REG + RDMA_RING_REG_BASE + DMA_END_ADDR, RX_DESCS * DMA_DESC_SIZE / 4 - 1); - write32(mac_reg_base_addr + RDMA_PROD_INDEX, 0x0); - write32(mac_reg_base_addr + RDMA_CONS_INDEX, 0x0); - write32(mac_reg_base_addr + RDMA_RING_REG_BASE + DMA_RING_BUF_SIZE, (RX_DESCS << DMA_RING_SIZE_SHIFT) | RX_BUF_LENGTH); - write32(mac_reg_base_addr + RDMA_XON_XOFF_THRESH, DMA_FC_THRESH_VALUE); - write32(mac_reg_base_addr + RDMA_REG_BASE + DMA_RING_CFG, 1 << DEFAULT_Q); + write32(MAC_REG + RDMA_PROD_INDEX, 0x0); + write32(MAC_REG + RDMA_CONS_INDEX, 0x0); + write32(MAC_REG + RDMA_RING_REG_BASE + DMA_RING_BUF_SIZE, (RX_DESCS << DMA_RING_SIZE_SHIFT) | RX_BUF_LENGTH); + write32(MAC_REG + RDMA_XON_XOFF_THRESH, DMA_FC_THRESH_VALUE); + write32(MAC_REG + RDMA_REG_BASE + DMA_RING_CFG, 1 << DEFAULT_Q); } static void tx_ring_init(void) { - write32(mac_reg_base_addr + TDMA_REG_BASE + DMA_SCB_BURST_SIZE, DMA_MAX_BURST_LENGTH); - write32(mac_reg_base_addr + TDMA_RING_REG_BASE + DMA_START_ADDR, 0x0); - write32(mac_reg_base_addr + TDMA_READ_PTR, 0x0); - write32(mac_reg_base_addr + TDMA_READ_PTR, 0x0); - write32(mac_reg_base_addr + TDMA_READ_PTR, 0x0); - write32(mac_reg_base_addr + TDMA_WRITE_PTR, 0x0); - write32(mac_reg_base_addr + TDMA_RING_REG_BASE + DMA_END_ADDR, TX_DESCS * DMA_DESC_SIZE / 4 - 1); - write32(mac_reg_base_addr + TDMA_PROD_INDEX, 0x0); - write32(mac_reg_base_addr + TDMA_CONS_INDEX, 0x0); - write32(mac_reg_base_addr + TDMA_RING_REG_BASE + DMA_MBUF_DONE_THRESH, 0x1); - write32(mac_reg_base_addr + TDMA_FLOW_PERIOD, 0x0); - write32(mac_reg_base_addr + TDMA_RING_REG_BASE + DMA_RING_BUF_SIZE, (TX_DESCS << DMA_RING_SIZE_SHIFT) | RX_BUF_LENGTH); - write32(mac_reg_base_addr + TDMA_REG_BASE + DMA_RING_CFG, 1 << DEFAULT_Q); + write32(MAC_REG + TDMA_REG_BASE + DMA_SCB_BURST_SIZE, DMA_MAX_BURST_LENGTH); + write32(MAC_REG + TDMA_RING_REG_BASE + DMA_START_ADDR, 0x0); + write32(MAC_REG + TDMA_READ_PTR, 0x0); + write32(MAC_REG + TDMA_READ_PTR, 0x0); + write32(MAC_REG + TDMA_READ_PTR, 0x0); + write32(MAC_REG + TDMA_WRITE_PTR, 0x0); + write32(MAC_REG + TDMA_RING_REG_BASE + DMA_END_ADDR, TX_DESCS * DMA_DESC_SIZE / 4 - 1); + write32(MAC_REG + TDMA_PROD_INDEX, 0x0); + write32(MAC_REG + TDMA_CONS_INDEX, 0x0); + write32(MAC_REG + TDMA_RING_REG_BASE + DMA_MBUF_DONE_THRESH, 0x1); + write32(MAC_REG + TDMA_FLOW_PERIOD, 0x0); + write32(MAC_REG + TDMA_RING_REG_BASE + DMA_RING_BUF_SIZE, (TX_DESCS << DMA_RING_SIZE_SHIFT) | RX_BUF_LENGTH); + write32(MAC_REG + TDMA_REG_BASE + DMA_RING_CFG, 1 << DEFAULT_Q); } static void rx_descs_init(void) @@ -348,14 +342,14 @@ static int bcmgenet_adjust_link(void) return -1; } - rt_uint32_t reg1 = read32(mac_reg_base_addr + EXT_RGMII_OOB_CTRL); + rt_uint32_t reg1 = read32(MAC_REG + EXT_RGMII_OOB_CTRL); //reg1 &= ~(1UL << OOB_DISABLE); //rt_kprintf("OOB_DISABLE is %d\n", OOB_DISABLE); reg1 |= (RGMII_LINK | RGMII_MODE_EN | ID_MODE_DIS); - write32(mac_reg_base_addr + EXT_RGMII_OOB_CTRL, reg1); + write32(MAC_REG + EXT_RGMII_OOB_CTRL, reg1); DELAY_MICROS(1000); - write32(mac_reg_base_addr + UMAC_CMD, speed << CMD_SPEED_SHIFT); + write32(MAC_REG + UMAC_CMD, speed << CMD_SPEED_SHIFT); return 0; } @@ -393,28 +387,28 @@ static int bcmgenet_gmac_eth_start(void) } /* wait tx index clear */ - while ((read32(mac_reg_base_addr + TDMA_CONS_INDEX) != 0) && (--count)) + while ((read32(MAC_REG + TDMA_CONS_INDEX) != 0) && (--count)) DELAY_MICROS(1); - tx_index = read32(mac_reg_base_addr + TDMA_CONS_INDEX); - write32(mac_reg_base_addr + TDMA_PROD_INDEX, tx_index); + tx_index = read32(MAC_REG + TDMA_CONS_INDEX); + write32(MAC_REG + TDMA_PROD_INDEX, tx_index); - index_flag = read32(mac_reg_base_addr + RDMA_PROD_INDEX); + index_flag = read32(MAC_REG + RDMA_PROD_INDEX); rx_index = index_flag % RX_DESCS; - write32(mac_reg_base_addr + RDMA_CONS_INDEX, index_flag); - write32(mac_reg_base_addr + RDMA_PROD_INDEX, index_flag); + write32(MAC_REG + RDMA_CONS_INDEX, index_flag); + write32(MAC_REG + RDMA_PROD_INDEX, index_flag); /* Enable Rx/Tx */ rt_uint32_t rx_tx_en; - rx_tx_en = read32(mac_reg_base_addr + UMAC_CMD); + rx_tx_en = read32(MAC_REG + UMAC_CMD); + rx_tx_en |= (CMD_TX_EN | CMD_RX_EN); - write32(mac_reg_base_addr + UMAC_CMD, rx_tx_en); - - // eanble IRQ for TxDMA done and RxDMA done - write32(mac_reg_base_addr + GENET_INTRL2_CPU_CLEAR_MASK, GENET_IRQ_TXDMA_DONE | GENET_IRQ_RXDMA_DONE); + write32(MAC_REG + UMAC_CMD, rx_tx_en); + //IRQ + write32(MAC_REG + GENET_INTRL2_CPU_CLEAR_MASK, GENET_IRQ_TXDMA_DONE | GENET_IRQ_RXDMA_DONE); return 0; } @@ -424,16 +418,17 @@ static rt_uint32_t bcmgenet_gmac_eth_recv(rt_uint8_t **packetp) { void* desc_base; rt_uint32_t length = 0, addr = 0; - rt_uint32_t prod_index = read32(mac_reg_base_addr + RDMA_PROD_INDEX); - if(prod_index == index_flag) //no buff + rt_uint32_t prod_index = read32(MAC_REG + RDMA_PROD_INDEX); + if(prod_index == index_flag) { cur_recv_cnt = index_flag; index_flag = 0x7fffffff; + /* no buff */ return 0; } else { - if(prev_recv_cnt == (prod_index & 0xffff)) //no new buff + if(prev_recv_cnt == prod_index & 0xffff) { return 0; } @@ -446,11 +441,7 @@ static rt_uint32_t bcmgenet_gmac_eth_recv(rt_uint8_t **packetp) * This would actually not be needed if we don't program * RBUF_ALIGN_2B */ - - //Convert to memory address - addr = addr + eth_recv_no_cache - RECV_DATA_NO_CACHE; - rt_hw_cpu_dcache_invalidate(addr,length); - + rt_hw_cpu_dcache_invalidate(addr,length); *packetp = (rt_uint8_t *)(addr + RX_BUF_OFFSET); rx_index = rx_index + 1; @@ -458,8 +449,7 @@ static rt_uint32_t bcmgenet_gmac_eth_recv(rt_uint8_t **packetp) { rx_index = 0; } - - write32(mac_reg_base_addr + RDMA_CONS_INDEX, cur_recv_cnt); + write32(MAC_REG + RDMA_CONS_INDEX, cur_recv_cnt); cur_recv_cnt = cur_recv_cnt + 1; @@ -469,43 +459,45 @@ static rt_uint32_t bcmgenet_gmac_eth_recv(rt_uint8_t **packetp) } prev_recv_cnt = cur_recv_cnt; - return length - RX_BUF_OFFSET; + return length; } } - -static int bcmgenet_gmac_eth_send(rt_uint32_t packet, int length,struct pbuf *p) +static int bcmgenet_gmac_eth_send(void *packet, int length) { - rt_ubase_t level; void *desc_base = (TX_DESC_BASE + tx_index * DMA_DESC_SIZE); - pbuf_copy_partial(p, (void*)(packet + tx_index * SEND_CACHE_BUF), p->tot_len, 0); rt_uint32_t len_stat = length << DMA_BUFLENGTH_SHIFT; + + rt_uint32_t prod_index, cons; + rt_uint32_t tries = 100; + + prod_index = read32(MAC_REG + TDMA_PROD_INDEX); + len_stat |= 0x3F << DMA_TX_QTAG_SHIFT; len_stat |= DMA_TX_APPEND_CRC | DMA_SOP | DMA_EOP; - rt_hw_cpu_dcache_clean((void*)(packet + tx_index * SEND_CACHE_BUF),length); - rt_uint32_t prod_index; - - prod_index = read32(mac_reg_base_addr + TDMA_PROD_INDEX); - - write32((desc_base + DMA_DESC_ADDRESS_LO), SEND_DATA_NO_CACHE + tx_index * SEND_CACHE_BUF); + rt_hw_cpu_dcache_clean((void*)packet, length); + write32((desc_base + DMA_DESC_ADDRESS_LO), packet); write32((desc_base + DMA_DESC_ADDRESS_HI), 0); write32((desc_base + DMA_DESC_LENGTH_STATUS), len_stat); - tx_index ++; - if(tx_index >= TX_DESCS) - { - tx_index = 0; - } + tx_index = tx_index + 1; prod_index = prod_index + 1; - if (prod_index > 0xffff) + if (prod_index == 0xe000) { + write32(MAC_REG + TDMA_PROD_INDEX, 0); prod_index = 0; } + if (tx_index >= TX_DESCS) + { + tx_index = 0; + } + /* Start Transmisson */ - write32(mac_reg_base_addr + TDMA_PROD_INDEX, prod_index); + write32(MAC_REG + TDMA_PROD_INDEX, prod_index); + rt_sem_take(&sem_lock, RT_WAITING_FOREVER); return 0; } @@ -514,10 +506,8 @@ static void link_task_entry(void *param) struct eth_device *eth_device = (struct eth_device *)param; RT_ASSERT(eth_device != RT_NULL); struct rt_eth_dev *dev = ð_dev; - //start mdio bcmgenet_mdio_init(); - //start timer link rt_timer_init(&dev->link_timer, "link_timer", link_irq, @@ -532,7 +522,7 @@ static void link_task_entry(void *param) rt_timer_stop(&dev->link_timer); //set mac - // bcmgenet_gmac_write_hwaddr(); + bcmgenet_gmac_write_hwaddr(); bcmgenet_gmac_write_hwaddr(); //check link speed @@ -552,13 +542,9 @@ static void link_task_entry(void *param) rt_kprintf("Support link mode Speed 10M\n"); } - - //Convert to memory address bcmgenet_gmac_eth_start(); - rt_hw_interrupt_install(ETH_IRQ, eth_rx_irq, NULL, "eth_irq"); rt_hw_interrupt_umask(ETH_IRQ); - link_flag = 1; } @@ -569,7 +555,7 @@ static rt_err_t bcmgenet_eth_init(rt_device_t device) /* Read GENET HW version */ rt_uint8_t major = 0; - hw_reg = read32(mac_reg_base_addr + SYS_REV_CTRL); + hw_reg = read32(MAC_REG + SYS_REV_CTRL); major = (hw_reg >> 24) & 0x0f; if (major != 6) { @@ -589,12 +575,12 @@ static rt_err_t bcmgenet_eth_init(rt_device_t device) } /* rbuf clear */ - write32(mac_reg_base_addr + SYS_RBUF_FLUSH_CTRL, 0); + write32(MAC_REG + SYS_RBUF_FLUSH_CTRL, 0); /* disable MAC while updating its registers */ - write32(mac_reg_base_addr + UMAC_CMD, 0); + write32(MAC_REG + UMAC_CMD, 0); /* issue soft reset with (rg)mii loopback to ensure a stable rxclk */ - write32(mac_reg_base_addr + UMAC_CMD, CMD_SW_RESET | CMD_LCL_LOOP_EN); + write32(MAC_REG + UMAC_CMD, CMD_SW_RESET | CMD_LCL_LOOP_EN); link_thread_tid = rt_thread_create("link", link_task_entry, (void *)device, LINK_THREAD_STACK_SIZE, @@ -623,28 +609,32 @@ static rt_err_t bcmgenet_eth_control(rt_device_t dev, int cmd, void *args) rt_err_t rt_eth_tx(rt_device_t device, struct pbuf *p) { + rt_uint32_t sendbuf = (rt_uint32_t)SEND_DATA_NO_CACHE + (rt_uint32_t)(tx_index * SEND_CACHE_BUF); + /* lock eth device */ if (link_flag == 1) { - bcmgenet_gmac_eth_send((rt_uint32_t)eth_send_no_cache, p->tot_len,p); - rt_sem_take(&send_finsh_sem_lock,RT_WAITING_FOREVER); + pbuf_copy_partial(p, (void *)&send_cache_pbuf[0], p->tot_len, 0); + rt_memcpy((void *)sendbuf, send_cache_pbuf, p->tot_len); + bcmgenet_gmac_eth_send((void *)sendbuf, p->tot_len); } - return RT_EOK; } struct pbuf *rt_eth_rx(rt_device_t device) { int recv_len = 0; - rt_uint8_t* addr_point = RT_NULL; + rt_uint8_t *addr_point = RT_NULL; struct pbuf *pbuf = RT_NULL; if (link_flag == 1) { - recv_len = bcmgenet_gmac_eth_recv(&addr_point); + recv_len = bcmgenet_gmac_eth_recv((rt_uint8_t **)&addr_point); if (recv_len > 0) { pbuf = pbuf_alloc(PBUF_LINK, recv_len, PBUF_RAM); - if(pbuf) - rt_memcpy(pbuf->payload, addr_point, recv_len); + if(pbuf) + { + rt_memcpy(pbuf->payload, addr_point, recv_len); + } } } return pbuf; @@ -653,14 +643,15 @@ struct pbuf *rt_eth_rx(rt_device_t device) int rt_hw_eth_init(void) { rt_uint8_t mac_addr[6]; - rt_sem_init(&send_finsh_sem_lock,"send_finsh_sem_lock",TX_DESCS,RT_IPC_FLAG_FIFO); + rt_sem_init(&sem_lock, "eth_send_lock", TX_DESCS, RT_IPC_FLAG_FIFO); rt_sem_init(&link_ack, "link_ack", 0, RT_IPC_FLAG_FIFO); + memset(ð_dev, 0, sizeof(eth_dev)); - memset((void *)eth_send_no_cache, 0, DMA_DISC_ADDR_SIZE); - memset((void *)eth_recv_no_cache, 0, DMA_DISC_ADDR_SIZE); + memset((void *)SEND_DATA_NO_CACHE, 0, DMA_DISC_ADDR_SIZE); + memset((void *)RECV_DATA_NO_CACHE, 0, DMA_DISC_ADDR_SIZE); bcm271x_mbox_hardware_get_mac_address(&mac_addr[0]); - eth_dev.iobase = mac_reg_base_addr; + eth_dev.iobase = MAC_REG; eth_dev.name = "e0"; eth_dev.dev_addr[0] = mac_addr[0]; eth_dev.dev_addr[1] = mac_addr[1]; diff --git a/bsp/raspberry-pi/raspi4-32/link.lds b/bsp/raspberry-pi/raspi4-32/link.lds index df4ecb5ad3..6ab3707d08 100644 --- a/bsp/raspberry-pi/raspi4-32/link.lds +++ b/bsp/raspberry-pi/raspi4-32/link.lds @@ -11,7 +11,7 @@ SECTIONS { - . = 0x8000; + . = 0x200000; . = ALIGN(4096); .text : { diff --git a/bsp/raspberry-pi/raspi4-32/rtconfig.h b/bsp/raspberry-pi/raspi4-32/rtconfig.h index c31d300cb2..0ceac4cfd7 100644 --- a/bsp/raspberry-pi/raspi4-32/rtconfig.h +++ b/bsp/raspberry-pi/raspi4-32/rtconfig.h @@ -19,6 +19,9 @@ #define RT_USING_TIMER_SOFT #define RT_TIMER_THREAD_PRIO 4 #define RT_TIMER_THREAD_STACK_SIZE 2048 + +/* kservice optimization */ + #define RT_DEBUG /* Inter-Thread communication */ @@ -41,7 +44,8 @@ #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 128 #define RT_CONSOLE_DEVICE_NAME "uart1" -#define RT_VER_NUM 0x40003 +#define RT_VER_NUM 0x40004 +#define RT_USING_GIC_V2 #define ARCH_ARMV8 /* RT-Thread Components */ @@ -84,6 +88,8 @@ #define RT_DFS_ELM_WORD_ACCESS #define RT_DFS_ELM_USE_LFN_3 #define RT_DFS_ELM_USE_LFN 3 +#define RT_DFS_ELM_LFN_UNICODE_0 +#define RT_DFS_ELM_LFN_UNICODE 0 #define RT_DFS_ELM_MAX_LFN 255 #define RT_DFS_ELM_DRIVES 2 #define RT_DFS_ELM_MAX_SECTOR_SIZE 512 @@ -98,6 +104,7 @@ #define RT_SYSTEM_WORKQUEUE_STACKSIZE 2048 #define RT_SYSTEM_WORKQUEUE_PRIORITY 23 #define RT_USING_SERIAL +#define RT_USING_SERIAL_V1 #define RT_SERIAL_USING_DMA #define RT_SERIAL_RB_BUFSZ 512 #define RT_USING_I2C @@ -120,12 +127,14 @@ #define RT_USING_LIBC #define RT_USING_POSIX +#define RT_LIBC_DEFAULT_TIMEZONE 8 /* Network */ /* Socket abstraction layer */ #define RT_USING_SAL +#define SAL_INTERNET_CHECK /* protocol stack implement */ @@ -156,8 +165,8 @@ /* Static IPv4 Address */ -#define RT_LWIP_IPADDR "192.168.1.30" -#define RT_LWIP_GWADDR "192.168.1.1" +#define RT_LWIP_IPADDR "192.168.111.172" +#define RT_LWIP_GWADDR "192.168.111.1" #define RT_LWIP_MSKADDR "255.255.255.0" #define RT_LWIP_UDP #define RT_LWIP_TCP @@ -195,6 +204,9 @@ /* Utilities */ +/* RT-Thread Utestcases */ + + /* RT-Thread online packages */ /* IoT - internet of things */ @@ -232,19 +244,16 @@ /* peripheral libraries and drivers */ +/* AI packages */ + + /* miscellaneous packages */ /* samples: kernel and components samples */ -/* games: games run on RT-Thread console */ - - -/* Privated Packages of RealThread */ - - -/* Network Utilities */ +/* entertainment: terminal games and other interesting software packages */ #define BCM2711_SOC diff --git a/bsp/raspberry-pi/raspi4-32/rtconfig.py b/bsp/raspberry-pi/raspi4-32/rtconfig.py index 681ec91b9e..49fa603b1e 100644 --- a/bsp/raspberry-pi/raspi4-32/rtconfig.py +++ b/bsp/raspberry-pi/raspi4-32/rtconfig.py @@ -37,7 +37,7 @@ if PLATFORM == 'gcc': DEVICE = ' -march=armv8-a -mtune=cortex-a72' CFLAGS = DEVICE + ' -Wall' - AFLAGS = ' -c' + ' -x assembler-with-cpp -D__ASSEMBLY__' + AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -D__ASSEMBLY__' LFLAGS = DEVICE + ' -nostartfiles -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,system_vectors -T link.lds' CPATH = '' LPATH = '' From b339b5cf330cb4ca880a204389b851a7d23f99a6 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 3 Aug 2021 10:55:16 +0800 Subject: [PATCH 08/11] =?UTF-8?q?[src][Kconfig]=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=9A=90=E6=80=A7RT=5FUSING=5FASM=5FMEMCPY=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Kconfig | 4 ++++ src/kservice.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Kconfig b/src/Kconfig index a987daab46..71abd9cf4f 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -131,6 +131,10 @@ config RT_KSERVICE_USING_TINY_SIZE bool "Enable kservice to use tiny size" default n +config RT_USING_ASM_MEMCPY + bool + default n + endmenu menuconfig RT_DEBUG diff --git a/src/kservice.c b/src/kservice.c index 128a9f4f54..91872492fb 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -198,6 +198,7 @@ RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count) } RTM_EXPORT(rt_memset); +#ifndef RT_USING_ASM_MEMCPY /** * This function will copy memory content from source address to destination * address. @@ -208,7 +209,7 @@ RTM_EXPORT(rt_memset); * * @return the address of destination memory */ -RT_WEAK 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_KSERVICE_USING_TINY_SIZE char *tmp = (char *)dst, *s = (char *)src; @@ -280,6 +281,7 @@ RT_WEAK void *rt_memcpy(void *dst, const void *src, rt_ubase_t count) #endif /* RT_KSERVICE_USING_TINY_SIZE */ } RTM_EXPORT(rt_memcpy); +#endif /* RT_USING_ASM_MEMCPY */ #ifndef RT_KSERVICE_USING_STDLIB From ae7b0af42cc1a06e1f2cd7d1a5801c46a82dada9 Mon Sep 17 00:00:00 2001 From: Weilin Wang Date: Tue, 3 Aug 2021 12:30:23 +0800 Subject: [PATCH 09/11] fix raspi net driver --- .github/workflows/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 2959a63c07..154b4b0255 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -131,6 +131,7 @@ jobs: - {RTT_BSP: "at32/at32f407-start", RTT_TOOL_CHAIN: "sourcery-arm"} - {RTT_BSP: "smartfusion2", RTT_TOOL_CHAIN: "sourcery-arm"} - {RTT_BSP: "raspberry-pico", RTT_TOOL_CHAIN: "sourcery-arm"} + - {RTT_BSP: "raspberry-pi/raspi4-32", RTT_TOOL_CHAIN: "sourcery-arm"} steps: - uses: actions/checkout@v2 - name: Set up Python From c10678c1f0968a1ce9f5af1eb051b39f3bb2c1d6 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 13 Jul 2021 13:20:36 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E5=86=85=E9=83=A8=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E4=BB=A5=5F=E5=BC=80=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/idle.c | 4 +- src/ipc.c | 102 ++++++++++++++++++++++++------------------------ src/scheduler.c | 14 +++---- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/idle.c b/src/idle.c index a6efad5628..81ac7e30dd 100644 --- a/src/idle.c +++ b/src/idle.c @@ -129,7 +129,7 @@ rt_err_t rt_thread_idle_delhook(void (*hook)(void)) #ifdef RT_USING_HEAP /* Return whether there is defunctional thread to be deleted. */ -rt_inline int _rt_has_defunct_thread(void) +rt_inline int _idle_has_defunct_thread(void) { /* The rt_list_isempty has prototype of "int rt_list_isempty(const rt_list_t *l)". * So the compiler has a good reason that the rt_thread_defunct list does @@ -165,7 +165,7 @@ void rt_thread_idle_excute(void) lock = rt_hw_interrupt_disable(); /* check whether list is empty */ - if (!_rt_has_defunct_thread()) + if (!_idle_has_defunct_thread()) { rt_hw_interrupt_enable(lock); break; diff --git a/src/ipc.c b/src/ipc.c index d57aa64d59..30ed44de56 100755 --- a/src/ipc.c +++ b/src/ipc.c @@ -63,7 +63,7 @@ extern void (*rt_object_put_hook)(struct rt_object *object); * * @return the operation status, RT_EOK on successful */ -rt_inline rt_err_t _rt_ipc_object_init(struct rt_ipc_object *ipc) +rt_inline rt_err_t _ipc_object_init(struct rt_ipc_object *ipc) { /* initialize ipc object */ rt_list_init(&(ipc->suspend_thread)); @@ -82,9 +82,9 @@ rt_inline rt_err_t _rt_ipc_object_init(struct rt_ipc_object *ipc) * * @return the operation status, RT_EOK on successful */ -rt_inline rt_err_t _rt_ipc_list_suspend(rt_list_t *list, - struct rt_thread *thread, - rt_uint8_t flag) +rt_inline rt_err_t _ipc_list_suspend(rt_list_t *list, + struct rt_thread *thread, + rt_uint8_t flag) { /* suspend thread */ rt_thread_suspend(thread); @@ -140,7 +140,7 @@ rt_inline rt_err_t _rt_ipc_list_suspend(rt_list_t *list, * * @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 _ipc_list_resume(rt_list_t *list) { struct rt_thread *thread; @@ -163,7 +163,7 @@ 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 _ipc_list_resume_all(rt_list_t *list) { struct rt_thread *thread; register rt_ubase_t temp; @@ -217,7 +217,7 @@ rt_err_t rt_sem_init(rt_sem_t sem, rt_object_init(&(sem->parent.parent), RT_Object_Class_Semaphore, name); /* initialize ipc object */ - _rt_ipc_object_init(&(sem->parent)); + _ipc_object_init(&(sem->parent)); /* set initial value */ sem->value = (rt_uint16_t)value; @@ -246,7 +246,7 @@ rt_err_t rt_sem_detach(rt_sem_t sem) RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent)); /* wakeup all suspended threads */ - _rt_ipc_list_resume_all(&(sem->parent.suspend_thread)); + _ipc_list_resume_all(&(sem->parent.suspend_thread)); /* detach semaphore object */ rt_object_detach(&(sem->parent.parent)); @@ -280,7 +280,7 @@ rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag) return sem; /* initialize ipc object */ - _rt_ipc_object_init(&(sem->parent)); + _ipc_object_init(&(sem->parent)); /* set initial value */ sem->value = value; @@ -311,7 +311,7 @@ rt_err_t rt_sem_delete(rt_sem_t sem) RT_ASSERT(rt_object_is_systemobject(&sem->parent.parent) == RT_FALSE); /* wakeup all suspended threads */ - _rt_ipc_list_resume_all(&(sem->parent.suspend_thread)); + _ipc_list_resume_all(&(sem->parent.suspend_thread)); /* delete semaphore object */ rt_object_delete(&(sem->parent.parent)); @@ -382,7 +382,7 @@ rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time) thread->name)); /* suspend thread */ - _rt_ipc_list_suspend(&(sem->parent.suspend_thread), + _ipc_list_suspend(&(sem->parent.suspend_thread), thread, sem->parent.parent.flag); @@ -463,7 +463,7 @@ rt_err_t rt_sem_release(rt_sem_t sem) if (!rt_list_isempty(&sem->parent.suspend_thread)) { /* resume the suspended thread */ - _rt_ipc_list_resume(&(sem->parent.suspend_thread)); + _ipc_list_resume(&(sem->parent.suspend_thread)); need_schedule = RT_TRUE; } else @@ -517,7 +517,7 @@ rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg) level = rt_hw_interrupt_disable(); /* resume all waiting thread */ - _rt_ipc_list_resume_all(&sem->parent.suspend_thread); + _ipc_list_resume_all(&sem->parent.suspend_thread); /* set new value */ sem->value = (rt_uint16_t)value; @@ -555,7 +555,7 @@ rt_err_t rt_mutex_init(rt_mutex_t mutex, const char *name, rt_uint8_t flag) rt_object_init(&(mutex->parent.parent), RT_Object_Class_Mutex, name); /* initialize ipc object */ - _rt_ipc_object_init(&(mutex->parent)); + _ipc_object_init(&(mutex->parent)); mutex->value = 1; mutex->owner = RT_NULL; @@ -586,7 +586,7 @@ rt_err_t rt_mutex_detach(rt_mutex_t mutex) RT_ASSERT(rt_object_is_systemobject(&mutex->parent.parent)); /* wakeup all suspended threads */ - _rt_ipc_list_resume_all(&(mutex->parent.suspend_thread)); + _ipc_list_resume_all(&(mutex->parent.suspend_thread)); /* detach semaphore object */ rt_object_detach(&(mutex->parent.parent)); @@ -618,7 +618,7 @@ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag) return mutex; /* initialize ipc object */ - _rt_ipc_object_init(&(mutex->parent)); + _ipc_object_init(&(mutex->parent)); mutex->value = 1; mutex->owner = RT_NULL; @@ -651,7 +651,7 @@ rt_err_t rt_mutex_delete(rt_mutex_t mutex) RT_ASSERT(rt_object_is_systemobject(&mutex->parent.parent) == RT_FALSE); /* wakeup all suspended threads */ - _rt_ipc_list_resume_all(&(mutex->parent.suspend_thread)); + _ipc_list_resume_all(&(mutex->parent.suspend_thread)); /* delete mutex object */ rt_object_delete(&(mutex->parent.parent)); @@ -765,7 +765,7 @@ __again: } /* suspend current thread */ - _rt_ipc_list_suspend(&(mutex->parent.suspend_thread), + _ipc_list_suspend(&(mutex->parent.suspend_thread), thread, mutex->parent.parent.flag); @@ -916,7 +916,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) } /* resume thread */ - _rt_ipc_list_resume(&(mutex->parent.suspend_thread)); + _ipc_list_resume(&(mutex->parent.suspend_thread)); need_schedule = RT_TRUE; } @@ -993,7 +993,7 @@ rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag) event->parent.parent.flag = flag; /* initialize ipc object */ - _rt_ipc_object_init(&(event->parent)); + _ipc_object_init(&(event->parent)); /* initialize event */ event->set = 0; @@ -1017,7 +1017,7 @@ rt_err_t rt_event_detach(rt_event_t event) RT_ASSERT(rt_object_is_systemobject(&event->parent.parent)); /* resume all suspended thread */ - _rt_ipc_list_resume_all(&(event->parent.suspend_thread)); + _ipc_list_resume_all(&(event->parent.suspend_thread)); /* detach event object */ rt_object_detach(&(event->parent.parent)); @@ -1050,7 +1050,7 @@ rt_event_t rt_event_create(const char *name, rt_uint8_t flag) event->parent.parent.flag = flag; /* initialize ipc object */ - _rt_ipc_object_init(&(event->parent)); + _ipc_object_init(&(event->parent)); /* initialize event */ event->set = 0; @@ -1076,7 +1076,7 @@ rt_err_t rt_event_delete(rt_event_t event) RT_DEBUG_NOT_IN_INTERRUPT; /* resume all suspended thread */ - _rt_ipc_list_resume_all(&(event->parent.suspend_thread)); + _ipc_list_resume_all(&(event->parent.suspend_thread)); /* delete event object */ rt_object_delete(&(event->parent.parent)); @@ -1279,7 +1279,7 @@ rt_err_t rt_event_recv(rt_event_t event, thread->event_info = option; /* put thread to suspended thread list */ - _rt_ipc_list_suspend(&(event->parent.suspend_thread), + _ipc_list_suspend(&(event->parent.suspend_thread), thread, event->parent.parent.flag); @@ -1345,7 +1345,7 @@ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg) level = rt_hw_interrupt_disable(); /* resume all waiting thread */ - _rt_ipc_list_resume_all(&event->parent.suspend_thread); + _ipc_list_resume_all(&event->parent.suspend_thread); /* initialize event set */ event->set = 0; @@ -1391,7 +1391,7 @@ rt_err_t rt_mb_init(rt_mailbox_t mb, mb->parent.parent.flag = flag; /* initialize ipc object */ - _rt_ipc_object_init(&(mb->parent)); + _ipc_object_init(&(mb->parent)); /* initialize mailbox */ mb->msg_pool = (rt_ubase_t *)msgpool; @@ -1422,9 +1422,9 @@ rt_err_t rt_mb_detach(rt_mailbox_t mb) RT_ASSERT(rt_object_is_systemobject(&mb->parent.parent)); /* resume all suspended thread */ - _rt_ipc_list_resume_all(&(mb->parent.suspend_thread)); + _ipc_list_resume_all(&(mb->parent.suspend_thread)); /* also resume all mailbox private suspended thread */ - _rt_ipc_list_resume_all(&(mb->suspend_sender_thread)); + _ipc_list_resume_all(&(mb->suspend_sender_thread)); /* detach mailbox object */ rt_object_detach(&(mb->parent.parent)); @@ -1458,7 +1458,7 @@ rt_mailbox_t rt_mb_create(const char *name, rt_size_t size, rt_uint8_t flag) mb->parent.parent.flag = flag; /* initialize ipc object */ - _rt_ipc_object_init(&(mb->parent)); + _ipc_object_init(&(mb->parent)); /* initialize mailbox */ mb->size = size; @@ -1498,10 +1498,10 @@ rt_err_t rt_mb_delete(rt_mailbox_t mb) RT_ASSERT(rt_object_is_systemobject(&mb->parent.parent) == RT_FALSE); /* resume all suspended thread */ - _rt_ipc_list_resume_all(&(mb->parent.suspend_thread)); + _ipc_list_resume_all(&(mb->parent.suspend_thread)); /* also resume all mailbox private suspended thread */ - _rt_ipc_list_resume_all(&(mb->suspend_sender_thread)); + _ipc_list_resume_all(&(mb->suspend_sender_thread)); /* free mailbox pool */ RT_KERNEL_FREE(mb->msg_pool); @@ -1570,7 +1570,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, RT_DEBUG_IN_THREAD_CONTEXT; /* suspend current thread */ - _rt_ipc_list_suspend(&(mb->suspend_sender_thread), + _ipc_list_suspend(&(mb->suspend_sender_thread), thread, mb->parent.parent.flag); @@ -1637,7 +1637,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, /* resume suspended thread */ if (!rt_list_isempty(&mb->parent.suspend_thread)) { - _rt_ipc_list_resume(&(mb->parent.suspend_thread)); + _ipc_list_resume(&(mb->parent.suspend_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -1718,7 +1718,7 @@ rt_err_t rt_mb_urgent(rt_mailbox_t mb, rt_ubase_t value) /* resume suspended thread */ if (!rt_list_isempty(&mb->parent.suspend_thread)) { - _rt_ipc_list_resume(&(mb->parent.suspend_thread)); + _ipc_list_resume(&(mb->parent.suspend_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -1792,7 +1792,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout) RT_DEBUG_IN_THREAD_CONTEXT; /* suspend current thread */ - _rt_ipc_list_suspend(&(mb->parent.suspend_thread), + _ipc_list_suspend(&(mb->parent.suspend_thread), thread, mb->parent.parent.flag); @@ -1855,7 +1855,7 @@ rt_err_t rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeout) /* resume suspended thread */ if (!rt_list_isempty(&(mb->suspend_sender_thread))) { - _rt_ipc_list_resume(&(mb->suspend_sender_thread)); + _ipc_list_resume(&(mb->suspend_sender_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -1899,9 +1899,9 @@ rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg) level = rt_hw_interrupt_disable(); /* resume all waiting thread */ - _rt_ipc_list_resume_all(&(mb->parent.suspend_thread)); + _ipc_list_resume_all(&(mb->parent.suspend_thread)); /* also resume all mailbox private suspended thread */ - _rt_ipc_list_resume_all(&(mb->suspend_sender_thread)); + _ipc_list_resume_all(&(mb->suspend_sender_thread)); /* re-init mailbox */ mb->entry = 0; @@ -1960,7 +1960,7 @@ rt_err_t rt_mq_init(rt_mq_t mq, mq->parent.parent.flag = flag; /* initialize ipc object */ - _rt_ipc_object_init(&(mq->parent)); + _ipc_object_init(&(mq->parent)); /* set message pool */ mq->msg_pool = msgpool; @@ -2008,9 +2008,9 @@ rt_err_t rt_mq_detach(rt_mq_t mq) RT_ASSERT(rt_object_is_systemobject(&mq->parent.parent)); /* resume all suspended thread */ - _rt_ipc_list_resume_all(&mq->parent.suspend_thread); + _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)); + _ipc_list_resume_all(&(mq->suspend_sender_thread)); /* detach message queue object */ rt_object_detach(&(mq->parent.parent)); @@ -2050,7 +2050,7 @@ rt_mq_t rt_mq_create(const char *name, mq->parent.parent.flag = flag; /* initialize ipc object */ - _rt_ipc_object_init(&(mq->parent)); + _ipc_object_init(&(mq->parent)); /* initialize message queue */ @@ -2108,9 +2108,9 @@ rt_err_t rt_mq_delete(rt_mq_t mq) RT_ASSERT(rt_object_is_systemobject(&mq->parent.parent) == RT_FALSE); /* resume all suspended thread */ - _rt_ipc_list_resume_all(&(mq->parent.suspend_thread)); + _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)); + _ipc_list_resume_all(&(mq->suspend_sender_thread)); /* free message queue pool */ RT_KERNEL_FREE(mq->msg_pool); @@ -2192,7 +2192,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, RT_DEBUG_IN_THREAD_CONTEXT; /* suspend current thread */ - _rt_ipc_list_suspend(&(mq->suspend_sender_thread), + _ipc_list_suspend(&(mq->suspend_sender_thread), thread, mq->parent.parent.flag); @@ -2278,7 +2278,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, /* resume suspended thread */ if (!rt_list_isempty(&mq->parent.suspend_thread)) { - _rt_ipc_list_resume(&(mq->parent.suspend_thread)); + _ipc_list_resume(&(mq->parent.suspend_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -2386,7 +2386,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) /* resume suspended thread */ if (!rt_list_isempty(&mq->parent.suspend_thread)) { - _rt_ipc_list_resume(&(mq->parent.suspend_thread)); + _ipc_list_resume(&(mq->parent.suspend_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -2468,7 +2468,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq, } /* suspend current thread */ - _rt_ipc_list_suspend(&(mq->parent.suspend_thread), + _ipc_list_suspend(&(mq->parent.suspend_thread), thread, mq->parent.parent.flag); @@ -2544,7 +2544,7 @@ rt_err_t rt_mq_recv(rt_mq_t mq, /* resume suspended thread */ if (!rt_list_isempty(&(mq->suspend_sender_thread))) { - _rt_ipc_list_resume(&(mq->suspend_sender_thread)); + _ipc_list_resume(&(mq->suspend_sender_thread)); /* enable interrupt */ rt_hw_interrupt_enable(temp); @@ -2590,9 +2590,9 @@ rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg) level = rt_hw_interrupt_disable(); /* resume all waiting thread */ - _rt_ipc_list_resume_all(&mq->parent.suspend_thread); + _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)); + _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/scheduler.c b/src/scheduler.c index 179ad85e07..8849d7f3ec 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -23,7 +23,7 @@ * 2013-12-21 Grissiom add rt_critical_level * 2018-11-22 Jesven remove the current task from ready queue * add per cpu ready queue - * add _rt_get_highest_priority_thread to find highest priority task + * add _scheduler_get_highest_priority_thread to find highest priority task * rt_schedule_insert_thread won't insert current task to ready queue * in smp version, rt_hw_context_switch_interrupt maybe switch to * new task directly @@ -114,7 +114,7 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread) * get the highest priority thread in ready queue */ #ifdef RT_USING_SMP -static struct rt_thread* _rt_get_highest_priority_thread(rt_ubase_t *highest_prio) +static struct rt_thread* _scheduler_get_highest_priority_thread(rt_ubase_t *highest_prio) { register struct rt_thread *highest_priority_thread; register rt_ubase_t highest_ready_priority, local_highest_ready_priority; @@ -150,7 +150,7 @@ static struct rt_thread* _rt_get_highest_priority_thread(rt_ubase_t *highest_pri return highest_priority_thread; } #else -static struct rt_thread* _rt_get_highest_priority_thread(rt_ubase_t *highest_prio) +static struct rt_thread* _scheduler_get_highest_priority_thread(rt_ubase_t *highest_prio) { register struct rt_thread *highest_priority_thread; register rt_ubase_t highest_ready_priority; @@ -239,7 +239,7 @@ void rt_system_scheduler_start(void) register struct rt_thread *to_thread; rt_ubase_t highest_ready_priority; - to_thread = _rt_get_highest_priority_thread(&highest_ready_priority); + to_thread = _scheduler_get_highest_priority_thread(&highest_ready_priority); #ifdef RT_USING_SMP to_thread->oncpu = rt_hw_cpu_id(); @@ -327,7 +327,7 @@ void rt_schedule(void) if (rt_thread_ready_priority_group != 0 || pcpu->priority_group != 0) { - to_thread = _rt_get_highest_priority_thread(&highest_ready_priority); + to_thread = _scheduler_get_highest_priority_thread(&highest_ready_priority); current_thread->oncpu = RT_CPU_DETACHED; if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING) { @@ -425,7 +425,7 @@ void rt_schedule(void) /* need_insert_from_thread: need to insert from_thread to ready queue */ int need_insert_from_thread = 0; - to_thread = _rt_get_highest_priority_thread(&highest_ready_priority); + to_thread = _scheduler_get_highest_priority_thread(&highest_ready_priority); if ((rt_current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING) { @@ -576,7 +576,7 @@ void rt_scheduler_do_irq_switch(void *context) if (rt_thread_ready_priority_group != 0 || pcpu->priority_group != 0) { - to_thread = _rt_get_highest_priority_thread(&highest_ready_priority); + to_thread = _scheduler_get_highest_priority_thread(&highest_ready_priority); current_thread->oncpu = RT_CPU_DETACHED; if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING) { From 963cce1e1bd6fbb7c4a2cf7c81812d9fca8d9a70 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 5 Aug 2021 21:11:03 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E9=80=89=E5=AE=9AFAL=E5=92=8Clittlefs=E8=BD=AF=E4=BB=B6?= =?UTF-8?q?=E5=8C=85=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E6=8C=82=E8=BD=BD=E9=A1=BA=E5=BA=8F=E4=B8=8D=E5=90=88=E7=90=86?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?spiflash=E8=AE=BE=E5=A4=87=E4=B8=BAspiflash0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stm32f407-atk-explorer/board/Kconfig | 3 ++ .../board/ports/drv_filesystem.c | 45 +++++-------------- .../board/ports/fal_cfg.h | 2 +- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/bsp/stm32/stm32f407-atk-explorer/board/Kconfig b/bsp/stm32/stm32f407-atk-explorer/board/Kconfig index 7d6d8cf883..8690baf177 100644 --- a/bsp/stm32/stm32f407-atk-explorer/board/Kconfig +++ b/bsp/stm32/stm32f407-atk-explorer/board/Kconfig @@ -99,6 +99,9 @@ menu "Onboard Peripheral Drivers" select RT_USING_MTD_NOR select BSP_USING_SPI_FLASH select BSP_USING_FS + select PKG_USING_FAL + select FAL_USING_SFUD_PORT + select PKG_USING_LITTLEFS select RT_USING_SYSTEM_WORKQUEUE default n diff --git a/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c b/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c index 07e6140722..82f9c9c76b 100644 --- a/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c +++ b/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c @@ -16,7 +16,6 @@ #include #include #include -#include #if DFS_FILESYSTEMS_MAX < 4 #error "Please define DFS_FILESYSTEMS_MAX more than 4" @@ -77,55 +76,34 @@ static int onboard_sdcard_mount(void) #endif #ifdef BSP_USING_SPI_FLASH_LITTLEFS +#include +#define FS_PARTITION_NAME "spiflash0" -#define FS_PARTITION_NAME "filesystem" - -static void spiflash_mount(void *parameter) +static int onboard_spiflash_mount(void) { struct rt_device *mtd_dev = RT_NULL; + fal_init(); mtd_dev = fal_mtd_nor_device_create(FS_PARTITION_NAME); if (!mtd_dev) { LOG_E("Can't create a mtd device on '%s' partition.", FS_PARTITION_NAME); } - while (1) - { - rt_thread_mdelay(500); - if(rt_device_find(FS_PARTITION_NAME) != RT_NULL) - { - if (dfs_mount(FS_PARTITION_NAME, "/flash", "lfs", 0, 0) == RT_EOK) - { - LOG_I("spi flash mount to '/flash'"); - break; - } - else - { - LOG_W("spi flash mount to '/flash' failed!"); - } - } - } -} -static int onboard_spiflash_mount(void) -{ - rt_thread_t tid; - - if (dfs_mount(FS_PARTITION_NAME, "/flash", "lfs", 0, 0) == RT_EOK) + if (dfs_mount(FS_PARTITION_NAME, "/spiflash", "lfs", 0, 0) == RT_EOK) { - LOG_I("spi flash mount to '/flash'"); + LOG_I("spi flash mount to '/spiflash'"); } else { - tid = rt_thread_create("spiflash_mount", spiflash_mount, RT_NULL, - 1024, RT_THREAD_PRIORITY_MAX - 3, 20); - if (tid != RT_NULL) + dfs_mkfs("lfs", FS_PARTITION_NAME); + if (dfs_mount(FS_PARTITION_NAME, "/spiflash", "lfs", 0, 0) == RT_EOK) { - rt_thread_startup(tid); + LOG_I("spi flash mount to '/spiflash'"); } else { - LOG_E("create spiflash_mount thread err!"); + LOG_E("spi flash failed to mount to '/spiflash'"); } } @@ -133,7 +111,6 @@ static int onboard_spiflash_mount(void) } #endif - static const struct romfs_dirent _romfs_root[] = { #ifdef BSP_USING_SDCARD @@ -141,7 +118,7 @@ static const struct romfs_dirent _romfs_root[] = #endif #ifdef BSP_USING_SPI_FLASH_LITTLEFS - {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0}, + {ROMFS_DIRENT_DIR, "spiflash", RT_NULL, 0}, #endif }; diff --git a/bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h b/bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h index 0cea945fe5..304efe869d 100644 --- a/bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h +++ b/bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h @@ -52,7 +52,7 @@ extern const struct fal_flash_dev stm32_onchip_flash_128k; #ifdef BSP_USING_SPI_FLASH_LITTLEFS #define FAL_PART_TABLE \ { \ - {FAL_PART_MAGIC_WROD, "filesystem",FAL_USING_NOR_FLASH_DEV_NAME, 0 , 16 * 1024 * 1024, 0}, \ + {FAL_PART_MAGIC_WROD, "spiflash0", FAL_USING_NOR_FLASH_DEV_NAME, 0 , 16 * 1024 * 1024, 0}, \ } #else #define FAL_PART_TABLE \