forked from xuos/xiuos
Merge branch 'prepare_for_master' of https://gitlink.org.cn/xuos/xiuos into jerryscript
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user