diff --git a/Ubiquitous/XiZi_AIoT/services/Makefile b/Ubiquitous/XiZi_AIoT/services/Makefile index 10557717b..b3a5f2c41 100644 --- a/Ubiquitous/XiZi_AIoT/services/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/Makefile @@ -1,5 +1,5 @@ -SRC_DIR := fs shell lib boards drivers semaphore drivers tools net app +SRC_DIR := fs shell lib boards drivers semaphore drivers tools net app include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_AIoT/services/app/Makefile b/Ubiquitous/XiZi_AIoT/services/app/Makefile index 113508502..471b366f6 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/app/Makefile @@ -43,7 +43,7 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \ -I$(KERNEL_ROOT)/services/app ifeq ($(BOARD), imx6q-sabrelite) -all: init test_fault simple_client simple_server shell fs_server semaphore_server test_semaphore test_ipc_null test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server readme.txt | bin +all: init test_fault simple_client simple_server shell fs_server semaphore_server test_semaphore test_ipc_null test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server test_net lwip readme.txt | bin else all: init test_fault simple_client simple_server shell fs_server test_ipc_null test_thread test_semaphore readme.txt | bin endif diff --git a/Ubiquitous/XiZi_AIoT/services/app/test_net.c b/Ubiquitous/XiZi_AIoT/services/app/test_net.c index 424948855..396d01948 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/test_net.c +++ b/Ubiquitous/XiZi_AIoT/services/app/test_net.c @@ -18,7 +18,7 @@ static char udp_ip_str[128] = {0}; static uint16_t udp_socket_port = 8888; -#define UDP_DEMO_SEND_TIMES 20 +#define UDP_DEMO_SEND_TIMES 3 int main(int argc, char* argv[]) { diff --git a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.c b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.c index 6578105d7..cbe3a3d65 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.c +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.c @@ -34,8 +34,6 @@ #define SYS_THREAD_MAX 4 -static char sem_server_name[] = "DefaultSemaphoreServer"; - void sys_init(void) { // do nothing @@ -65,9 +63,8 @@ void sys_arch_unprotect(sys_prot_t pval) err_t sys_sem_new(sys_sem_t* sem, u8_t count) { - connect_session(&sem->sess, sem_server_name, 4096); - sem_create(&sem->sess, &sem->sem, (int)count); - + + *sem = semaphore_new(count); #if SYS_STATS ++lwip_stats.sys.sem.used; if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) { @@ -75,7 +72,7 @@ err_t sys_sem_new(sys_sem_t* sem, u8_t count) } #endif /* SYS_STATS */ - if (sem->sem >= 0) + if (*sem > 0) return ERR_OK; else { #if SYS_STATS @@ -91,36 +88,33 @@ void sys_sem_free(sys_sem_t* sem) #if SYS_STATS --lwip_stats.sys.sem.used; #endif /* SYS_STATS */ - sem_delete(&sem->sess, &sem->sem); - free_session(&sem->sess); - free(sem); - sem = SYS_SEM_NULL; + semaphore_free(*sem); } int sys_sem_valid(sys_sem_t* sem) { - return (sem->sem >= 0); + return (*sem > 0); } void sys_sem_set_invalid(sys_sem_t* sem) { - sem->sem = -1; + *sem = -1; } u32_t sys_arch_sem_wait(sys_sem_t* sem, u32_t timeout) { s32_t wait_time = 0; - if (sem->sem < 0) + if (*sem <= 0) return SYS_ARCH_TIMEOUT; - sem_wait(&sem->sess, &sem->sem, 0); + semaphore_wait(*sem); return 0; } void sys_sem_signal(sys_sem_t* sem) { - sem_signal(&sem->sess, &sem->sem); + semaphore_signal(*sem); } err_t sys_mutex_new(sys_mutex_t* mutex) @@ -163,6 +157,7 @@ err_t sys_mbox_new(sys_mbox_t* mbox, int size) sys_sem_new(&mbox->not_full, 0); sys_sem_new(&mbox->mutex, 1); mbox->wait_send = 0; + mbox->valid = 1; #if SYS_STATS ++lwip_stats.sys.mbox.used; @@ -181,23 +176,22 @@ err_t sys_mbox_new(sys_mbox_t* mbox, int size) void sys_mbox_free(sys_mbox_t* mbox) { if (mbox != SYS_MBOX_NULL){ - // sys_arch_sem_wait(&mbox->mutex, 0); - // sys_sem_free(&mbox->not_empty); - // sys_sem_free(&mbox->not_full); - // sys_sem_free(&mbox->mutex); + sys_arch_sem_wait(&mbox->mutex, 0); + sys_sem_free(&mbox->not_empty); + sys_sem_free(&mbox->not_full); + sys_sem_free(&mbox->mutex); free(mbox); - mbox = NULL; } } int sys_mbox_valid(sys_mbox_t* mbox) { - return (mbox != SYS_MBOX_NULL); + return (mbox->valid == 1); } void sys_mbox_set_invalid(sys_mbox_t* mbox) { - mbox = SYS_MBOX_NULL; + mbox->valid = 0; } void sys_mbox_post(sys_mbox_t* q, void* msg) diff --git a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.h b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.h index e02c42359..2159f2767 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.h +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.h @@ -39,22 +39,19 @@ #define SYS_MRTEX_NULL SYS_SEM_NULL #define SYS_MBOX_SIZE 128 -struct sys_sem -{ - sem_t sem; - struct Session sess; -}; -typedef struct sys_sem sys_sem_t; -typedef struct sys_sem sys_mutex_t; + +typedef int sys_sem_t; +typedef int sys_mutex_t; struct sys_mbox{ int first, last; void *msgs[SYS_MBOX_SIZE]; - struct sys_sem not_empty; - struct sys_sem not_full; - struct sys_sem mutex; + int not_empty; + int not_full; + int mutex; int wait_send; + int valid; }; typedef struct sys_mbox sys_mbox_t; diff --git a/Ubiquitous/XiZi_AIoT/softkernel/task/semaphore.c b/Ubiquitous/XiZi_AIoT/softkernel/task/semaphore.c index 575e1aa7d..f1c5b5443 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/task/semaphore.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/task/semaphore.c @@ -35,10 +35,10 @@ static inline struct ksemaphore* ksemaphore_get_by_id(struct XiziSemaphorePool* DOUBLE_LIST_FOR_EACH_ENTRY(sem, &sem_pool->sem_list_guard, sem_list_node) { if (sem->id == sem_id) { - break; + return sem; } } - return sem; + return NULL; } int ksemaphore_alloc(struct XiziSemaphorePool* sem_pool, int val) @@ -102,8 +102,9 @@ bool ksemaphore_signal(struct XiziSemaphorePool* sem_pool, uint32_t sem_id) if (sem->val < 0) { if (!IS_DOUBLE_LIST_EMPTY(&sem->wait_list_guard)) { - assert(sem->wait_list_guard.next != NULL); - xizi_task_manager.task_unblock(CONTAINER_OF(sem->wait_list_guard.next, struct Thread, node)); + struct Thread* thd = CONTAINER_OF(sem->wait_list_guard.next, struct Thread, node); + assert(thd != NULL && thd->state == BLOCKED); + xizi_task_manager.task_unblock(thd); } }