diff --git a/APP_Framework/Applications/app_test/test_socket.c b/APP_Framework/Applications/app_test/test_socket.c index 5e77b9d3b..2d4d10be9 100644 --- a/APP_Framework/Applications/app_test/test_socket.c +++ b/APP_Framework/Applications/app_test/test_socket.c @@ -335,10 +335,22 @@ void TestSocket(int argc, char* argv[]) if (mode == IPERF_MODE_SERVER) { printf("[%s] Running iperf server at port %d.\n", __func__, iperf_param.port); - PrivTaskCreate(&thd, NULL, TestIperfServer, (void*)&iperf_param); +#ifdef ADD_XIZI_FEATURES + char task_name[] = "test_iperf_server"; + pthread_args_t args; + args.pthread_name = task_name; + args.arg = (void *)&iperf_param; + PrivTaskCreate(&thd, NULL, TestIperfServer, (void*)&args); +#endif } else if (mode == IPERF_MODE_CLIENT) { printf("[%s] Running iperf client to server at %s:%d.\n", __func__, iperf_param.host, iperf_param.port); - PrivTaskCreate(&thd, NULL, TestIperfClient, (void*)&iperf_param); +#ifdef ADD_XIZI_FEATURES + char task_name[] = "test_iperf_client"; + pthread_args_t args; + args.pthread_name = task_name; + args.arg = (void *)&iperf_param; + PrivTaskCreate(&thd, NULL, TestIperfClient, (void*)&args); +#endif } PrivTaskStartup(&thd); diff --git a/APP_Framework/Framework/connection/adapter_agent.c b/APP_Framework/Framework/connection/adapter_agent.c index c54caf946..353beab17 100755 --- a/APP_Framework/Framework/connection/adapter_agent.c +++ b/APP_Framework/Framework/connection/adapter_agent.c @@ -549,13 +549,19 @@ static int ATAgentInit(ATAgentType agent) attr.priority = 18; attr.stacksize = 8192; + PrivTaskCreate(&agent->at_handler, &attr, ATAgentReceiveProcess, agent); #else pthread_attr_t attr; attr.schedparam.sched_priority = 25; attr.stacksize = 4096; -#endif - PrivTaskCreate(&agent->at_handler, &attr, ATAgentReceiveProcess, agent); + char task_name[] = "at_agent"; + pthread_args_t args; + args.pthread_name = task_name; + args.arg = (void *)agent; + + PrivTaskCreate(&agent->at_handler, &attr, ATAgentReceiveProcess, (void *)&args); +#endif return result; diff --git a/APP_Framework/Framework/connection/lora/adapter_lora.c b/APP_Framework/Framework/connection/lora/adapter_lora.c index 6133e52cc..490d1f28e 100644 --- a/APP_Framework/Framework/connection/lora/adapter_lora.c +++ b/APP_Framework/Framework/connection/lora/adapter_lora.c @@ -848,8 +848,10 @@ static int AdapterLoraRegister(struct Adapter *adapter) ret = AdapterDeviceRegister(adapter); if (ret < 0) { printf("Adapter4G register error\n"); +#ifdef AS_LORA_GATEWAY_ROLE if (lora_gateway) PrivFree(lora_gateway); +#endif if (lora_client) PrivFree(lora_client); @@ -952,22 +954,32 @@ int AdapterLoraTest(void) pthread_attr_t lora_gateway_attr = PTHREAD_ATTR_INITIALIZER; lora_gateway_attr.priority = 20; lora_gateway_attr.stacksize = 2048; + PrivTaskCreate(&lora_recv_data_task, &lora_gateway_attr, &LoraReceiveTask, (void *)adapter); #else pthread_attr_t lora_gateway_attr; lora_gateway_attr.schedparam.sched_priority = 20; lora_gateway_attr.stacksize = 2048; + + char task_name_1[] = "adapter_lora_recv"; + pthread_args_t args; + args.pthread_name = task_name_1; + args.arg = (void *)adapter; + PrivTaskCreate(&lora_recv_data_task, &lora_gateway_attr, &LoraReceiveTask, (void *)&args); #endif - PrivTaskCreate(&lora_recv_data_task, &lora_gateway_attr, &LoraReceiveTask, (void *)adapter); PrivTaskStartup(&lora_recv_data_task); #ifdef ADD_NUTTX_FEATURES lora_gateway_attr.priority = 20; + PrivTaskCreate(&lora_gateway_task, &lora_gateway_attr, &LoraGatewayTask, (void *)adapter); #else lora_gateway_attr.schedparam.sched_priority = 20; + char task_name_2[] = "adapter_lora_gateway"; + args.pthread_name = task_name_2; + args.arg = (void *)adapter; + PrivTaskCreate(&lora_recv_data_task, &lora_gateway_attr, &LoraReceiveTask, (void *)&args); #endif - PrivTaskCreate(&lora_gateway_task, &lora_gateway_attr, &LoraGatewayTask, (void *)adapter); PrivTaskStartup(&lora_gateway_task); #else //AS_LORA_CLIENT_ROLE @@ -975,22 +987,34 @@ int AdapterLoraTest(void) pthread_attr_t lora_client_attr = PTHREAD_ATTR_INITIALIZER; lora_client_attr.priority = 20; lora_client_attr.stacksize = 2048; + + PrivTaskCreate(&lora_recv_data_task, &lora_client_attr, &LoraReceiveTask, (void *)adapter); #else pthread_attr_t lora_client_attr; lora_client_attr.schedparam.sched_priority = 20; lora_client_attr.stacksize = 2048; + + char task_name_1[] = "adapter_lora_recv"; + pthread_args_t args; + args.pthread_name = task_name_1; + args.arg = (void *)adapter; + PrivTaskCreate(&lora_recv_data_task, &lora_client_attr, &LoraReceiveTask, (void *)&args); #endif - PrivTaskCreate(&lora_recv_data_task, &lora_client_attr, &LoraReceiveTask, (void *)adapter); + PrivTaskStartup(&lora_recv_data_task); #ifdef ADD_NUTTX_FEATURES lora_client_attr.priority = 20; + PrivTaskCreate(&lora_client_data_task, &lora_client_attr, &LoraClientDataTask, (void *)adapter); #else lora_client_attr.schedparam.sched_priority = 20; + char task_name_2[] = "adapter_lora_client"; + args.pthread_name = task_name_2; + args.arg = (void *)adapter; + PrivTaskCreate(&lora_client_data_task, &lora_client_attr, &LoraClientDataTask, (void *)&args); #endif //create lora client task - PrivTaskCreate(&lora_client_data_task, &lora_client_attr, &LoraClientDataTask, (void *)adapter); PrivTaskStartup(&lora_client_data_task); #endif diff --git a/APP_Framework/Framework/control/shared/control_def.c b/APP_Framework/Framework/control/shared/control_def.c index 4808b2423..79fb251fc 100644 --- a/APP_Framework/Framework/control/shared/control_def.c +++ b/APP_Framework/Framework/control/shared/control_def.c @@ -322,7 +322,12 @@ int ControlProtocolOpenDef(struct ControlProtocol *control_protocol) attr.schedparam.sched_priority = 19; attr.stacksize = 2048; - PrivTaskCreate(&recv_plc_data_task, &attr, &ReceivePlcDataTask, control_protocol); + char task_name[] = "control_recv_data"; + pthread_args_t args; + args.pthread_name = task_name; + args.arg = (void *)control_protocol; + + PrivTaskCreate(&recv_plc_data_task, &attr, &ReceivePlcDataTask, (void *)&args); PrivTaskStartup(&recv_plc_data_task); } diff --git a/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c b/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c index 615fc398e..e1c405c0d 100644 --- a/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c +++ b/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c @@ -80,7 +80,12 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) result = PrivIoctl(sdev->fd, OPE_INT, &cfg); - PrivTaskCreate(&active_task_id, NULL, &ReadTask, sdev); + char task_name[] = "ps5308_recv_data"; + pthread_args_t args; + args.pthread_name = task_name; + args.arg = (void *)sdev; + + PrivTaskCreate(&active_task_id, NULL, &ReadTask, (void *)&args); PrivTaskStartup(&active_task_id); return result; diff --git a/APP_Framework/Framework/sensor/voice/d124/d124.c b/APP_Framework/Framework/sensor/voice/d124/d124.c index 232680c21..cdbf3895e 100644 --- a/APP_Framework/Framework/sensor/voice/d124/d124.c +++ b/APP_Framework/Framework/sensor/voice/d124/d124.c @@ -116,7 +116,12 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) attr.schedparam.sched_priority = 20; attr.stacksize = 2048; - PrivTaskCreate(&active_task_id, &attr, &ReadTask, sdev); + char task_name[] = "d124_recv_data"; + pthread_args_t args; + args.pthread_name = task_name; + args.arg = (void *)sdev; + + PrivTaskCreate(&active_task_id, &attr, &ReadTask, (void *)&args); PrivTaskStartup(&active_task_id); return result; diff --git a/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/include/pthread.h b/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/include/pthread.h index d7feca1f0..d2c87ed84 100644 --- a/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/include/pthread.h +++ b/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/include/pthread.h @@ -72,6 +72,11 @@ extern "C" { typedef int pid_t; // typedef int pthread_mutex_t ; +typedef struct pthread_args +{ + void *arg; + const char *pthread_name; +}pthread_args_t; /* scheduling algorithms */ #define SCHED_OTHER 0 diff --git a/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/pthread.c b/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/pthread.c index 76cca1b1a..a7652ee36 100644 --- a/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/pthread.c +++ b/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/pthread.c @@ -29,28 +29,40 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { - int ret ; - int pid ; + int ret; + int pid; char task_name[32] = {0}; static int utask_id = 0; - UtaskType task ; + UtaskType task; + pthread_args_t *pthread_args = (pthread_args_t *)arg; if (NULL == attr) { task.prio = KTASK_PRIORITY_MAX / 2; - task.stack_size = 4096 ; + task.stack_size = 4096; } else { - task.prio = attr->schedparam.sched_priority ; - task.stack_size = attr->stacksize ; + task.prio = attr->schedparam.sched_priority; + task.stack_size = attr->stacksize; + } + + task.func_entry = start_routine; + + if (NULL == pthread_args) { + task.func_param = NULL; + snprintf(task_name, sizeof(task_name) - 1, "utask%02d", utask_id++); + } else { + task.func_param = pthread_args->arg; + if (NULL == pthread_args->pthread_name) { + snprintf(task_name, sizeof(task_name) - 1, "utask%02d", utask_id++); + } else { + snprintf(task_name, sizeof(task_name) - 1, pthread_args->pthread_name); + } } - task.func_entry = start_routine ; - task.func_param = arg; - snprintf(task_name, sizeof(task_name) - 1, "utask%02d",utask_id++); memcpy(task.name , task_name, sizeof(task_name) - 1); pid = UserTaskCreate(task); if (pid < 0) - return -1 ; + return -1; ret = UserTaskStartup(pid); *thread = (pthread_t)(long)pid; diff --git a/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/timer.c b/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/timer.c index e0d167504..e302c0a4a 100644 --- a/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/timer.c +++ b/APP_Framework/Framework/transform_layer/xizi/user_api/posix_support/timer.c @@ -25,8 +25,11 @@ #include "include/semaphore.h" #include "include/pthread.h" -static sem_t timer_sem; -static pthread_t timer_task; +#define TIMER_NUM 20 + +static sem_t timer_sem[TIMER_NUM]; +static pthread_t timer_task[TIMER_NUM]; +static char timer_idx[TIMER_NUM]; struct timer_func { union sigval value; @@ -34,16 +37,17 @@ struct timer_func { void (* user_timer_function)(union sigval val); }; -struct timer_func g_timer_func; +struct timer_func g_timer_func[TIMER_NUM]; static void *timer_callback(void *args) { - struct sigevent *evp = (struct sigevent *)args; + clockid_t clockid = *((clockid_t *)args); while (1) { - if (g_timer_func.user_timer_function != NULL) { - if (0 == sem_timedwait(&timer_sem, NULL)) { - g_timer_func.user_timer_function(g_timer_func.value); + if (g_timer_func[clockid].user_timer_function != NULL) { + if (0 == sem_timedwait(&(timer_sem[clockid]), NULL)) { + g_timer_func[clockid].value.sival_ptr = &clockid; + g_timer_func[clockid].user_timer_function(g_timer_func[clockid].value); } } } @@ -68,30 +72,37 @@ int timer_create(clockid_t clockid, struct sigevent * evp, timer_t * timerid) memset(timer_name, 0, sizeof(timer_name)); snprintf(timer_name, sizeof(timer_name), "timer_%ld", clockid); - sem_init(&timer_sem, 0, 0); + sem_init(&(timer_sem[clockid]), 0, 0); - g_timer_func.value = evp->sigev_value; - g_timer_func.user_timer_function = evp->sigev_notify_function; - g_timer_func.timer_flags = *(int *)(evp->sigev_notify_attributes); + g_timer_func[clockid].value = evp->sigev_value; + g_timer_func[clockid].user_timer_function = evp->sigev_notify_function; + g_timer_func[clockid].timer_flags = *(int *)(evp->sigev_notify_attributes); pthread_attr_t attr; attr.schedparam.sched_priority = 22; attr.stacksize = 2048; - pthread_create(&timer_task, &attr, &timer_callback, (void *)evp); - - timer_id = UserTimerCreate(timer_name, NULL, (void *)&timer_sem, 1000, g_timer_func.timer_flags); + pthread_args_t args; + args.pthread_name = timer_name; + args.arg = &clockid; + + pthread_create(&(timer_task[clockid]), &attr, &timer_callback, (void *)&args); + + timer_id = UserTimerCreate(timer_name, NULL, (void *)&(timer_sem[clockid]), clockid, g_timer_func[clockid].timer_flags); *timerid = timer_id; return timer_id; } int timer_delete(timer_t timerid) { - pthread_kill(timer_task, 0); + sem_t sem; + int timer_id = timerid; + pthread_kill(timer_task[timer_id], 0); UserTimerQuitRun(timerid); - sem_destroy(&timer_sem); + sem = timer_sem[timer_id]; + sem_destroy(&sem); return 0; } diff --git a/APP_Framework/lib/lorawan/README.md b/APP_Framework/lib/lorawan/README.md index bff82e90b..f120f8af5 100644 --- a/APP_Framework/lib/lorawan/README.md +++ b/APP_Framework/lib/lorawan/README.md @@ -20,10 +20,14 @@ xiuos/APP_Framework/lib/lorawan ``` # 下载代码 -# 进入APP_Framework/lib/lorawan目录下载更新子模块 +# 进入APP_Framework/lib/lorawan目录下载更新子模块,首先执行以下命令: git submodule init +# 若需要使用lora_radio_driver子模块,执行以下命令: git submodule update APP_Framework/lib/lorawan/lora_radio_driver +# 若需要使用lorawan_devicenode子模块,执行以下命令: git submodule update APP_Framework/lib/lorawan/lorawan_devicenode +# 若需要使用lorawan_gateway_single_channel子模块,执行以下命令: +git submodule update APP_Framework/lib/lorawan/lorawan_gateway_single_channel # 进入 APP_Framework/lib/lorawan/Kconfig 配置,增加子模块source路径,从而编译时可找到相应lib的配置 menuconfig LIB_USING_LORAWAN_GATEWAY_SC diff --git a/APP_Framework/lib/lorawan/lora_radio_driver b/APP_Framework/lib/lorawan/lora_radio_driver index a94c007cb..0ced8f47f 160000 --- a/APP_Framework/lib/lorawan/lora_radio_driver +++ b/APP_Framework/lib/lorawan/lora_radio_driver @@ -1 +1 @@ -Subproject commit a94c007cb4ee726cc29b10626f8bbfc19c989b89 +Subproject commit 0ced8f47f86ea96a414479424d7f534426a818eb diff --git a/APP_Framework/lib/lorawan/lorawan_devicenode b/APP_Framework/lib/lorawan/lorawan_devicenode index 254754bc7..4c543f77f 160000 --- a/APP_Framework/lib/lorawan/lorawan_devicenode +++ b/APP_Framework/lib/lorawan/lorawan_devicenode @@ -1 +1 @@ -Subproject commit 254754bc7d06011cbec4655cd229c8ccfb95240b +Subproject commit 4c543f77fcc639696939098a31145fdc1654f0f6 diff --git a/APP_Framework/lib/lorawan/lorawan_gateway_single_channel b/APP_Framework/lib/lorawan/lorawan_gateway_single_channel index ac1c6516e..986318f68 160000 --- a/APP_Framework/lib/lorawan/lorawan_gateway_single_channel +++ b/APP_Framework/lib/lorawan/lorawan_gateway_single_channel @@ -1 +1 @@ -Subproject commit ac1c6516ec9b2998c0c50796a4e5a8b78781dc8c +Subproject commit 986318f686df3e77eb3dc6cc690b3d1da3a32359 diff --git a/Ubiquitous/XiZi_IIoT/Makefile b/Ubiquitous/XiZi_IIoT/Makefile index c41b4eda9..fda533036 100755 --- a/Ubiquitous/XiZi_IIoT/Makefile +++ b/Ubiquitous/XiZi_IIoT/Makefile @@ -5,7 +5,7 @@ MAKEFLAGS += --no-print-directory .PHONY:COMPILE_APP COMPILE_KERNEL -riscv_support := kd233 maix-go hifive1-rev-B gapuino gd32vf103-rvstar rv32m1-vega aiit-riscv64-board xidatong-riscv64 edu-riscv64 +riscv_support := kd233 maix-go hifive1-rev-B gapuino gd32vf103-rvstar rv32m1-vega aiit-riscv64-board xidatong-riscv64 edu-riscv64 ch32v307vct6 arm_support += stm32f407-st-discovery stm32f407zgt6 stm32f103-nano nuvoton-m2354 ok1052-c imxrt1176-sbc aiit-arm32-board xidatong-arm32 xiwangtong-arm32 edu-arm32 emulator_support += hifive1-emulator k210-emulator cortex-m0-emulator cortex-m3-emulator cortex-m4-emulator support := $(riscv_support) $(arm_support) $(emulator_support) diff --git a/Ubiquitous/XiZi_IIoT/board/edu-arm32/config.mk b/Ubiquitous/XiZi_IIoT/board/edu-arm32/config.mk index 222e6736c..bb44261da 100644 --- a/Ubiquitous/XiZi_IIoT/board/edu-arm32/config.mk +++ b/Ubiquitous/XiZi_IIoT/board/edu-arm32/config.mk @@ -1,6 +1,6 @@ export CROSS_COMPILE ?=/usr/bin/arm-none-eabi- -export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror -Wformat -Wuninitialized +export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror -Wuninitialized # export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2 export LFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-edu-arm32.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds diff --git a/Ubiquitous/XiZi_IIoT/kernel/kernel_service/xs_service.c b/Ubiquitous/XiZi_IIoT/kernel/kernel_service/xs_service.c index d857f2cd5..5e0e30a2b 100644 --- a/Ubiquitous/XiZi_IIoT/kernel/kernel_service/xs_service.c +++ b/Ubiquitous/XiZi_IIoT/kernel/kernel_service/xs_service.c @@ -775,19 +775,24 @@ uint8_t UserGetTaskPriority(int32_t id) } #ifdef KERNEL_SOFTTIMER -static int32 timer_sem; +#define TIMER_NUM 20 +static int32 timer_sem[TIMER_NUM]; +static uint32_t timer_id[TIMER_NUM]; static void UserTimerCallback(void *parameter) { - KSemaphoreAbandon(timer_sem); + uint32_t timer_id = *((uint32_t *)parameter); + KSemaphoreAbandon(timer_sem[timer_id]); } int32 UserTimerCreate(const char *name, void (*timeout)(void *parameter), void *parameter, uint32_t time, uint8_t trigger_mode) { int32 ret; - timer_sem = *((int *)parameter); + timer_id[time] = time; + timer_sem[time] = *((int *)parameter); + + ret = KCreateTimer(name, UserTimerCallback, (void *)&(timer_id[time]), 1000, trigger_mode); - ret = KCreateTimer(name, UserTimerCallback, NONE, time, trigger_mode); return ret; } diff --git a/Ubiquitous/XiZi_IIoT/kernel/thread/softtimer.c b/Ubiquitous/XiZi_IIoT/kernel/thread/softtimer.c index f08f3d1cb..6ad68fd84 100644 --- a/Ubiquitous/XiZi_IIoT/kernel/thread/softtimer.c +++ b/Ubiquitous/XiZi_IIoT/kernel/thread/softtimer.c @@ -301,7 +301,9 @@ void CheckTimerList(void) ((WorkQueueDoneType *)sys_workq->done)->WorkSubmit((WorkqueueType *)sys_workq->property, t->t_work, 0); lock = CriticalAreaLock(); } else { - KPrintf("sortlist run unactive timer(%s), quit this timer\n", t->name); + // KPrintf("sortlist run unactive timer(%s), current %d deadline %d quit this timer\n", + // t->name, current_tick, t->deadline_timeslice); + break; } } else diff --git a/Ubiquitous/XiZi_IIoT/resources/serial/dev_serial.c b/Ubiquitous/XiZi_IIoT/resources/serial/dev_serial.c index 156db4ebb..d490c017d 100644 --- a/Ubiquitous/XiZi_IIoT/resources/serial/dev_serial.c +++ b/Ubiquitous/XiZi_IIoT/resources/serial/dev_serial.c @@ -286,6 +286,7 @@ static inline int SerialDevDMARead(struct SerialHardwareDevice *serial_dev, stru x_size_t read_dma_length; x_size_t read_dma_size = SerialGetRxFifoLength(serial_dev); + lock = CriticalAreaLock(); if (serial_cfg->data_cfg.serial_buffer_size) { if(read_length < (int)read_dma_size) read_dma_length = read_length;