cxd56_cpu1signal: Fix an issue that gnss does not work

Because a thread of gnss receiver is created by pthread in the
AppBringUp task, the thread would be killed when AppBringUp
task exits.
Change to use kthread_create instead of pthread_create to prevent
this issue.
This commit is contained in:
SPRESENSE 2021-01-07 20:03:00 +09:00 committed by Xiang Xiao
parent d5f66e5583
commit 2f29521dd1

View File

@ -59,7 +59,7 @@ struct cxd56_sigtype_s
struct cxd56cpu1_info_s struct cxd56cpu1_info_s
{ {
pthread_t workertid; int workerpid;
int ndev; int ndev;
struct cxd56_sigtype_s sigtype[CXD56_CPU1_DATA_TYPE_MAX]; struct cxd56_sigtype_s sigtype[CXD56_CPU1_DATA_TYPE_MAX];
}; };
@ -77,9 +77,9 @@ static struct cxd56cpu1_info_s g_cpu1_info =
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
static FAR void *cxd56cpu1_worker(FAR void *arg) static int cxd56cpu1_worker(int argc, FAR char *argv[])
{ {
struct cxd56cpu1_info_s *priv = (struct cxd56cpu1_info_s *)arg; struct cxd56cpu1_info_s *priv = &g_cpu1_info;
iccmsg_t msg; iccmsg_t msg;
uint8_t sigtype; uint8_t sigtype;
int ret; int ret;
@ -108,7 +108,7 @@ static FAR void *cxd56cpu1_worker(FAR void *arg)
} }
} }
return arg; return 0;
} }
/**************************************************************************** /****************************************************************************
@ -154,9 +154,7 @@ void cxd56_cpu1sigunregisterhandler(uint8_t sigtype)
int cxd56_cpu1siginit(uint8_t sigtype, FAR void *data) int cxd56_cpu1siginit(uint8_t sigtype, FAR void *data)
{ {
struct cxd56cpu1_info_s *priv = &g_cpu1_info; struct cxd56cpu1_info_s *priv = &g_cpu1_info;
pthread_attr_t tattr; int pid;
struct sched_param param;
pthread_t tid;
int ret; int ret;
if (sigtype >= CXD56_CPU1_DATA_TYPE_MAX) if (sigtype >= CXD56_CPU1_DATA_TYPE_MAX)
@ -194,21 +192,19 @@ int cxd56_cpu1siginit(uint8_t sigtype, FAR void *data)
goto err0; goto err0;
} }
pthread_attr_init(&tattr); pid = kthread_create("gnss_receiver",
tattr.stacksize = CONFIG_CXD56CPU1_WORKER_STACKSIZE; CONFIG_CXD56CPU1_WORKER_THREAD_PRIORITY,
param.sched_priority = CONFIG_CXD56CPU1_WORKER_THREAD_PRIORITY; CONFIG_CXD56CPU1_WORKER_STACKSIZE, cxd56cpu1_worker,
pthread_attr_setschedparam(&tattr, &param); (FAR char * const *) NULL);
ret = pthread_create(&tid, &tattr, cxd56cpu1_worker, if (pid < 0)
(pthread_addr_t)priv);
if (ret != 0)
{ {
cxd56_iccuninitmsg(CXD56CPU1_CPUID); cxd56_iccuninitmsg(CXD56CPU1_CPUID);
ret = -ret; /* pthread_create does not modify errno. */ ret = -errno;
goto err0; goto err0;
} }
priv->workertid = tid; priv->workerpid = pid;
return ret; return ret;
@ -225,7 +221,7 @@ err1:
int cxd56_cpu1siguninit(uint8_t sigtype) int cxd56_cpu1siguninit(uint8_t sigtype)
{ {
struct cxd56cpu1_info_s *priv = &g_cpu1_info; struct cxd56cpu1_info_s *priv = &g_cpu1_info;
pthread_t tid; int pid;
int ret; int ret;
if (sigtype >= CXD56_CPU1_DATA_TYPE_MAX) if (sigtype >= CXD56_CPU1_DATA_TYPE_MAX)
@ -252,13 +248,17 @@ int cxd56_cpu1siguninit(uint8_t sigtype)
return ret; return ret;
} }
tid = priv->workertid; pid = priv->workerpid;
priv->workertid = 0; priv->workerpid = 0;
sched_unlock(); sched_unlock();
pthread_cancel(tid); ret = kthread_delete(pid);
pthread_join(tid, NULL);
if (ret)
{
_err("Failed to delete GNSS receiver task. ret = %d\n", ret);
}
cxd56_iccuninit(CXD56CPU1_CPUID); cxd56_iccuninit(CXD56CPU1_CPUID);