2019-11-02 18:30:33 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/timers/rpmsg_rtc.c
|
|
|
|
*
|
2020-08-22 18:36:57 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2019-11-02 18:30:33 +01:00
|
|
|
*
|
2020-08-22 18:36:57 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2019-11-02 18:30:33 +01:00
|
|
|
*
|
2020-08-22 18:36:57 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2019-11-02 18:30:33 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 03:19:49 +01:00
|
|
|
#include <nuttx/nuttx.h>
|
2021-03-19 07:34:43 +01:00
|
|
|
#include <nuttx/list.h>
|
2019-11-02 18:30:33 +01:00
|
|
|
#include <nuttx/clock.h>
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/rptun/openamp.h>
|
2022-09-06 08:18:45 +02:00
|
|
|
#include <nuttx/mutex.h>
|
2019-11-02 18:30:33 +01:00
|
|
|
#include <nuttx/timers/rpmsg_rtc.h>
|
2022-01-13 15:01:53 +01:00
|
|
|
#include <nuttx/timers/arch_rtc.h>
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2023-11-03 08:44:36 +01:00
|
|
|
#include "clock/clock.h"
|
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#define RPMSG_RTC_EPT_NAME "rpmsg-rtc"
|
|
|
|
|
|
|
|
#define RPMSG_RTC_SET 0
|
|
|
|
#define RPMSG_RTC_GET 1
|
|
|
|
#define RPMSG_RTC_ALARM_SET 2
|
|
|
|
#define RPMSG_RTC_ALARM_CANCEL 3
|
|
|
|
#define RPMSG_RTC_ALARM_FIRE 4
|
2021-03-19 07:34:43 +01:00
|
|
|
#define RPMSG_RTC_SYNC 5
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
begin_packed_struct struct rpmsg_rtc_header_s
|
|
|
|
{
|
|
|
|
uint32_t command;
|
|
|
|
int32_t result;
|
|
|
|
uint64_t cookie;
|
|
|
|
} end_packed_struct;
|
|
|
|
|
|
|
|
begin_packed_struct struct rpmsg_rtc_set_s
|
|
|
|
{
|
|
|
|
struct rpmsg_rtc_header_s header;
|
2023-11-03 08:44:36 +01:00
|
|
|
int64_t base_sec;
|
2019-11-02 18:30:33 +01:00
|
|
|
int64_t sec;
|
|
|
|
int32_t nsec;
|
2023-11-03 08:44:36 +01:00
|
|
|
int32_t base_nsec;
|
2019-11-02 18:30:33 +01:00
|
|
|
} end_packed_struct;
|
|
|
|
|
|
|
|
#define rpmsg_rtc_get_s rpmsg_rtc_set_s
|
|
|
|
|
|
|
|
begin_packed_struct struct rpmsg_rtc_alarm_set_s
|
|
|
|
{
|
|
|
|
struct rpmsg_rtc_header_s header;
|
|
|
|
int64_t sec;
|
|
|
|
int32_t nsec;
|
|
|
|
int32_t id;
|
|
|
|
} end_packed_struct;
|
|
|
|
|
|
|
|
begin_packed_struct struct rpmsg_rtc_alarm_cancel_s
|
|
|
|
{
|
|
|
|
struct rpmsg_rtc_header_s header;
|
|
|
|
int32_t id;
|
|
|
|
} end_packed_struct;
|
|
|
|
|
|
|
|
#define rpmsg_rtc_alarm_fire_s rpmsg_rtc_alarm_cancel_s
|
|
|
|
|
2021-05-07 05:28:35 +02:00
|
|
|
#ifndef CONFIG_RTC_RPMSG_SERVER
|
2019-11-02 18:30:33 +01:00
|
|
|
struct rpmsg_rtc_cookie_s
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_header_s *msg;
|
|
|
|
sem_t sem;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This is the private type for the RTC state. It must be cast compatible
|
|
|
|
* with struct rtc_lowerhalf_s.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct rpmsg_rtc_lowerhalf_s
|
|
|
|
{
|
|
|
|
/* This is the contained reference to the read-only, lower-half
|
|
|
|
* operations vtable (which may lie in FLASH or ROM)
|
|
|
|
*/
|
|
|
|
|
|
|
|
FAR const struct rtc_ops_s *ops;
|
|
|
|
|
|
|
|
/* Data following is private to this driver and not visible outside of
|
|
|
|
* this file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct rpmsg_endpoint ept;
|
|
|
|
|
|
|
|
#ifdef CONFIG_RTC_ALARM
|
|
|
|
struct lower_setalarm_s alarminfo[CONFIG_RTC_NALARMS];
|
|
|
|
#endif
|
|
|
|
};
|
2021-05-07 05:28:35 +02:00
|
|
|
#else
|
2021-03-19 07:34:43 +01:00
|
|
|
struct rpmsg_rtc_server_s
|
|
|
|
{
|
|
|
|
FAR struct rtc_ops_s *ops;
|
|
|
|
FAR struct rtc_lowerhalf_s *lower;
|
|
|
|
struct list_node list;
|
2022-09-06 08:18:45 +02:00
|
|
|
mutex_t lock;
|
2021-03-19 07:34:43 +01:00
|
|
|
};
|
|
|
|
|
2022-01-14 14:48:31 +01:00
|
|
|
struct rpmsg_rtc_client_s
|
2021-03-19 07:34:43 +01:00
|
|
|
{
|
|
|
|
struct list_node node;
|
|
|
|
struct rpmsg_endpoint ept;
|
|
|
|
};
|
2021-05-07 05:28:35 +02:00
|
|
|
#endif
|
2021-03-19 07:34:43 +01:00
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-05-07 05:28:35 +02:00
|
|
|
#ifndef CONFIG_RTC_RPMSG_SERVER
|
2019-11-02 18:30:33 +01:00
|
|
|
static void rpmsg_rtc_device_created(FAR struct rpmsg_device *rdev,
|
2020-05-17 16:47:40 +02:00
|
|
|
FAR void *priv);
|
2019-11-02 18:30:33 +01:00
|
|
|
static void rpmsg_rtc_device_destroy(FAR struct rpmsg_device *rdev,
|
2020-05-17 16:47:40 +02:00
|
|
|
FAR void *priv);
|
2019-11-02 18:30:33 +01:00
|
|
|
static void rpmsg_rtc_alarm_fire_handler(FAR struct rpmsg_endpoint *ept,
|
2020-05-17 16:47:40 +02:00
|
|
|
FAR void *data, size_t len, uint32_t src, FAR void *priv);
|
2019-11-02 18:30:33 +01:00
|
|
|
static int rpmsg_rtc_ept_cb(FAR struct rpmsg_endpoint *ept, FAR void *data,
|
2020-05-17 16:47:40 +02:00
|
|
|
size_t len, uint32_t src, FAR void *priv);
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
static int rpmsg_rtc_send_recv(FAR struct rpmsg_rtc_lowerhalf_s *lower,
|
2020-05-17 16:47:40 +02:00
|
|
|
uint32_t command, FAR struct rpmsg_rtc_header_s *msg, int len);
|
2019-11-02 18:30:33 +01:00
|
|
|
static int rpmsg_rtc_rdtime(FAR struct rtc_lowerhalf_s *lower,
|
2020-05-17 16:47:40 +02:00
|
|
|
FAR struct rtc_time *rtctime);
|
2019-11-02 18:30:33 +01:00
|
|
|
static int rpmsg_rtc_settime(FAR struct rtc_lowerhalf_s *lower,
|
2020-05-17 16:47:40 +02:00
|
|
|
FAR const struct rtc_time *rtctime);
|
2019-11-02 18:30:33 +01:00
|
|
|
static bool rpmsg_rtc_havesettime(FAR struct rtc_lowerhalf_s *lower);
|
2021-03-19 07:34:43 +01:00
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
#ifdef CONFIG_RTC_ALARM
|
|
|
|
static int rpmsg_rtc_setalarm(FAR struct rtc_lowerhalf_s *lower_,
|
2020-05-17 16:47:40 +02:00
|
|
|
FAR const struct lower_setalarm_s *alarminfo);
|
2019-11-02 18:30:33 +01:00
|
|
|
static int rpmsg_rtc_setrelative(FAR struct rtc_lowerhalf_s *lower,
|
2020-05-17 16:47:40 +02:00
|
|
|
FAR const struct lower_setrelative_s *relinfo);
|
2019-11-02 18:30:33 +01:00
|
|
|
static int rpmsg_rtc_cancelalarm(FAR struct rtc_lowerhalf_s *lower,
|
2020-05-17 16:47:40 +02:00
|
|
|
int alarmid);
|
2019-11-02 18:30:33 +01:00
|
|
|
static int rpmsg_rtc_rdalarm(FAR struct rtc_lowerhalf_s *lower_,
|
2020-05-17 16:47:40 +02:00
|
|
|
FAR struct lower_rdalarm_s *alarminfo);
|
2019-11-02 18:30:33 +01:00
|
|
|
#endif
|
2021-05-07 05:28:35 +02:00
|
|
|
#else
|
2021-03-19 07:34:43 +01:00
|
|
|
static int rpmsg_rtc_server_rdtime(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR struct rtc_time *rtctime);
|
|
|
|
static int rpmsg_rtc_server_settime(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR const struct rtc_time *rtctime);
|
|
|
|
static bool rpmsg_rtc_server_havesettime(FAR struct rtc_lowerhalf_s *lower);
|
|
|
|
|
|
|
|
#ifdef CONFIG_RTC_ALARM
|
|
|
|
static int rpmsg_rtc_server_setalarm(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR const struct lower_setalarm_s *alarminfo);
|
|
|
|
static int rpmsg_rtc_server_setrelative(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR const struct lower_setrelative_s *relinfo);
|
|
|
|
static int rpmsg_rtc_server_cancelalarm(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
int alarmid);
|
|
|
|
static int rpmsg_rtc_server_rdalarm(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR struct lower_rdalarm_s *alarminfo);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_RTC_PERIODIC
|
|
|
|
static int rpmsg_rtc_server_setperiodic(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR const struct lower_setperiodic_s *alarminfo);
|
|
|
|
|
2022-01-16 09:50:51 +01:00
|
|
|
static int rpmsg_rtc_server_cancelperiodic(
|
|
|
|
FAR struct rtc_lowerhalf_s *lower, int alarmid);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_RTC_IOCTL
|
|
|
|
static int rpmsg_rtc_server_ioctl(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
int cmd, unsigned long arg);
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
|
|
|
static int rpmsg_rtc_server_destroy(FAR struct rtc_lowerhalf_s *lower);
|
2021-03-19 07:34:43 +01:00
|
|
|
#endif
|
2021-05-07 05:28:35 +02:00
|
|
|
#endif
|
2021-03-19 07:34:43 +01:00
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-05-07 05:28:35 +02:00
|
|
|
#ifndef CONFIG_RTC_RPMSG_SERVER
|
2019-11-02 18:30:33 +01:00
|
|
|
static const struct rtc_ops_s g_rpmsg_rtc_ops =
|
|
|
|
{
|
2022-01-16 09:18:09 +01:00
|
|
|
rpmsg_rtc_rdtime,
|
|
|
|
rpmsg_rtc_settime,
|
|
|
|
rpmsg_rtc_havesettime,
|
2019-11-02 18:30:33 +01:00
|
|
|
#ifdef CONFIG_RTC_ALARM
|
2022-01-16 09:18:09 +01:00
|
|
|
rpmsg_rtc_setalarm,
|
|
|
|
rpmsg_rtc_setrelative,
|
|
|
|
rpmsg_rtc_cancelalarm,
|
|
|
|
rpmsg_rtc_rdalarm,
|
2019-11-02 18:30:33 +01:00
|
|
|
#endif
|
|
|
|
};
|
2021-05-07 05:28:35 +02:00
|
|
|
#else
|
2021-03-19 07:34:43 +01:00
|
|
|
static struct rtc_ops_s g_rpmsg_rtc_server_ops =
|
|
|
|
{
|
2022-01-16 09:18:09 +01:00
|
|
|
rpmsg_rtc_server_rdtime,
|
|
|
|
rpmsg_rtc_server_settime,
|
|
|
|
rpmsg_rtc_server_havesettime,
|
2021-03-19 07:34:43 +01:00
|
|
|
#ifdef CONFIG_RTC_ALARM
|
2022-01-16 09:18:09 +01:00
|
|
|
rpmsg_rtc_server_setalarm,
|
|
|
|
rpmsg_rtc_server_setrelative,
|
|
|
|
rpmsg_rtc_server_cancelalarm,
|
|
|
|
rpmsg_rtc_server_rdalarm,
|
2021-03-19 07:34:43 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_RTC_PERIODIC
|
2022-01-16 09:18:09 +01:00
|
|
|
rpmsg_rtc_server_setperiodic,
|
|
|
|
rpmsg_rtc_server_cancelperiodic,
|
2021-03-19 07:34:43 +01:00
|
|
|
#endif
|
2022-01-16 09:50:51 +01:00
|
|
|
#ifdef CONFIG_RTC_IOCTL
|
|
|
|
rpmsg_rtc_server_ioctl,
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
|
|
|
rpmsg_rtc_server_destroy,
|
|
|
|
#endif
|
2021-03-19 07:34:43 +01:00
|
|
|
};
|
2021-05-07 05:28:35 +02:00
|
|
|
#endif
|
2021-03-19 07:34:43 +01:00
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-05-07 05:28:35 +02:00
|
|
|
#ifndef CONFIG_RTC_RPMSG_SERVER
|
2019-11-02 18:30:33 +01:00
|
|
|
static void rpmsg_rtc_device_created(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_lowerhalf_s *lower = priv;
|
|
|
|
|
2021-04-24 08:18:21 +02:00
|
|
|
if (strcmp(CONFIG_RTC_RPMSG_SERVER_NAME,
|
|
|
|
rpmsg_get_cpuname(rdev)) == 0)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
|
|
|
lower->ept.priv = lower;
|
|
|
|
|
|
|
|
rpmsg_create_ept(&lower->ept, rdev, RPMSG_RTC_EPT_NAME,
|
|
|
|
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
|
|
|
|
rpmsg_rtc_ept_cb, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rpmsg_rtc_device_destroy(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_lowerhalf_s *lower = priv;
|
|
|
|
|
2021-04-24 08:18:21 +02:00
|
|
|
if (strcmp(CONFIG_RTC_RPMSG_SERVER_NAME,
|
|
|
|
rpmsg_get_cpuname(rdev)) == 0)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
|
|
|
rpmsg_destroy_ept(&lower->ept);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rpmsg_rtc_alarm_fire_handler(FAR struct rpmsg_endpoint *ept,
|
|
|
|
FAR void *data, size_t len,
|
|
|
|
uint32_t src, FAR void *priv)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_RTC_ALARM
|
|
|
|
FAR struct rpmsg_rtc_lowerhalf_s *lower = priv;
|
|
|
|
FAR struct rpmsg_rtc_alarm_fire_s *msg = data;
|
|
|
|
FAR struct lower_setalarm_s *alarminfo = &lower->alarminfo[msg->id];
|
|
|
|
|
|
|
|
alarminfo->cb(alarminfo->priv, alarminfo->id);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmsg_rtc_ept_cb(FAR struct rpmsg_endpoint *ept, FAR void *data,
|
|
|
|
size_t len, uint32_t src, FAR void *priv)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_header_s *header = data;
|
|
|
|
FAR struct rpmsg_rtc_cookie_s *cookie =
|
2021-03-19 07:34:43 +01:00
|
|
|
(FAR struct rpmsg_rtc_cookie_s *)(uintptr_t)header->cookie;
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
switch (header->command)
|
|
|
|
{
|
|
|
|
case RPMSG_RTC_ALARM_FIRE:
|
|
|
|
rpmsg_rtc_alarm_fire_handler(ept, data, len, src, priv);
|
|
|
|
break;
|
|
|
|
|
2021-03-19 07:34:43 +01:00
|
|
|
case RPMSG_RTC_SYNC:
|
2022-01-13 15:01:53 +01:00
|
|
|
{
|
|
|
|
struct rpmsg_rtc_set_s *msg = data;
|
2023-11-03 08:44:36 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_RTC_RPMSG_SYNC_BASETIME
|
|
|
|
g_basetime.tv_sec = msg->base_sec;
|
|
|
|
g_basetime.tv_nsec = msg->base_nsec;
|
|
|
|
#else
|
2022-01-13 15:01:53 +01:00
|
|
|
struct timespec tp;
|
|
|
|
|
|
|
|
tp.tv_sec = msg->sec;
|
|
|
|
tp.tv_nsec = msg->nsec;
|
|
|
|
|
|
|
|
clock_synchronize(&tp);
|
2023-11-03 08:44:36 +01:00
|
|
|
#endif
|
2022-01-13 15:01:53 +01:00
|
|
|
}
|
2021-03-19 07:34:43 +01:00
|
|
|
break;
|
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
default:
|
|
|
|
if (cookie)
|
|
|
|
{
|
|
|
|
memcpy(cookie->msg, data, len);
|
|
|
|
nxsem_post(&cookie->sem);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmsg_rtc_send_recv(FAR struct rpmsg_rtc_lowerhalf_s *lower,
|
|
|
|
uint32_t command,
|
|
|
|
FAR struct rpmsg_rtc_header_s *msg, int len)
|
|
|
|
{
|
2021-03-19 07:34:43 +01:00
|
|
|
struct rpmsg_rtc_cookie_s cookie;
|
2019-11-02 18:30:33 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
nxsem_init(&cookie.sem, 0, 0);
|
|
|
|
cookie.msg = msg;
|
|
|
|
|
|
|
|
msg->command = command;
|
|
|
|
msg->result = -ENXIO;
|
|
|
|
msg->cookie = (uintptr_t)&cookie;
|
|
|
|
|
|
|
|
ret = rpmsg_send(&lower->ept, msg, len);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
ret = nxsem_wait_uninterruptible(&cookie.sem);
|
|
|
|
if (ret == 0)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
ret = msg->result;
|
2019-11-02 18:30:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
nxsem_destroy(&cookie.sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmsg_rtc_rdtime(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR struct rtc_time *rtctime)
|
|
|
|
{
|
|
|
|
struct rpmsg_rtc_get_s msg;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = rpmsg_rtc_send_recv((FAR struct rpmsg_rtc_lowerhalf_s *)lower,
|
|
|
|
RPMSG_RTC_GET, (struct rpmsg_rtc_header_s *)&msg, sizeof(msg));
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
time_t time = msg.sec;
|
|
|
|
gmtime_r(&time, (FAR struct tm *)rtctime);
|
|
|
|
rtctime->tm_nsec = msg.nsec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmsg_rtc_settime(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR const struct rtc_time *rtctime)
|
|
|
|
{
|
2022-01-16 09:18:09 +01:00
|
|
|
struct rpmsg_rtc_set_s msg;
|
|
|
|
|
|
|
|
msg.sec = timegm((FAR struct tm *)rtctime);
|
|
|
|
msg.nsec = rtctime->tm_nsec;
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
return rpmsg_rtc_send_recv((FAR struct rpmsg_rtc_lowerhalf_s *)lower,
|
|
|
|
RPMSG_RTC_SET, (struct rpmsg_rtc_header_s *)&msg, sizeof(msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool rpmsg_rtc_havesettime(FAR struct rtc_lowerhalf_s *lower)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_RTC_ALARM
|
|
|
|
static int rpmsg_rtc_setalarm(FAR struct rtc_lowerhalf_s *lower_,
|
|
|
|
FAR const struct lower_setalarm_s *alarminfo)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_lowerhalf_s *lower =
|
|
|
|
(FAR struct rpmsg_rtc_lowerhalf_s *)lower_;
|
2022-01-16 09:18:09 +01:00
|
|
|
struct rpmsg_rtc_alarm_set_s msg;
|
2019-11-02 18:30:33 +01:00
|
|
|
int ret;
|
|
|
|
|
2022-01-16 09:18:09 +01:00
|
|
|
msg.id = alarminfo->id;
|
|
|
|
msg.sec = timegm((FAR struct tm *)&alarminfo->time);
|
|
|
|
msg.nsec = alarminfo->time.tm_nsec;
|
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
ret = rpmsg_rtc_send_recv(lower, RPMSG_RTC_ALARM_SET,
|
|
|
|
(struct rpmsg_rtc_header_s *)&msg, sizeof(msg));
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
lower->alarminfo[alarminfo->id] = *alarminfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-05-17 16:47:40 +02:00
|
|
|
static int
|
2021-03-19 07:34:43 +01:00
|
|
|
rpmsg_rtc_setrelative(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR const struct lower_setrelative_s *relinfo)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
2022-01-18 16:41:05 +01:00
|
|
|
struct lower_setalarm_s alarminfo;
|
2019-11-02 18:30:33 +01:00
|
|
|
time_t time;
|
|
|
|
|
2022-01-16 09:18:09 +01:00
|
|
|
alarminfo.id = relinfo->id;
|
|
|
|
alarminfo.cb = relinfo->cb;
|
|
|
|
alarminfo.priv = relinfo->priv;
|
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
rpmsg_rtc_rdtime(lower, &alarminfo.time);
|
2021-06-21 18:44:48 +02:00
|
|
|
time = timegm((FAR struct tm *)&alarminfo.time);
|
2019-11-02 18:30:33 +01:00
|
|
|
time = time + relinfo->reltime;
|
|
|
|
gmtime_r(&time, (FAR struct tm *)&alarminfo.time);
|
|
|
|
|
|
|
|
return rpmsg_rtc_setalarm(lower, &alarminfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmsg_rtc_cancelalarm(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
int alarmid)
|
|
|
|
{
|
2022-01-16 09:18:09 +01:00
|
|
|
struct rpmsg_rtc_alarm_cancel_s msg;
|
2019-11-02 18:30:33 +01:00
|
|
|
|
2022-01-16 09:18:09 +01:00
|
|
|
msg.id = alarmid;
|
2019-11-02 18:30:33 +01:00
|
|
|
return rpmsg_rtc_send_recv((FAR struct rpmsg_rtc_lowerhalf_s *)lower,
|
|
|
|
RPMSG_RTC_ALARM_CANCEL, (struct rpmsg_rtc_header_s *)&msg,
|
|
|
|
sizeof(msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmsg_rtc_rdalarm(FAR struct rtc_lowerhalf_s *lower_,
|
|
|
|
FAR struct lower_rdalarm_s *alarminfo)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_lowerhalf_s *lower =
|
|
|
|
(FAR struct rpmsg_rtc_lowerhalf_s *)lower_;
|
|
|
|
|
|
|
|
*alarminfo->time = lower->alarminfo[alarminfo->id].time;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2021-05-07 05:28:35 +02:00
|
|
|
#else
|
2021-03-19 07:34:43 +01:00
|
|
|
static int rpmsg_rtc_server_rdtime(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR struct rtc_time *rtctime)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server =
|
|
|
|
(FAR struct rpmsg_rtc_server_s *)lower;
|
|
|
|
|
|
|
|
return server->lower->ops->rdtime(server->lower, rtctime);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmsg_rtc_server_settime(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR const struct rtc_time *rtctime)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server =
|
|
|
|
(FAR struct rpmsg_rtc_server_s *)lower;
|
2022-01-14 14:48:31 +01:00
|
|
|
FAR struct rpmsg_rtc_client_s *client;
|
2021-03-19 07:34:43 +01:00
|
|
|
FAR struct list_node *node;
|
2022-01-13 15:01:53 +01:00
|
|
|
struct rpmsg_rtc_set_s msg;
|
2021-03-19 07:34:43 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = server->lower->ops->settime(server->lower, rtctime);
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
2022-01-13 15:01:53 +01:00
|
|
|
msg.sec = timegm((FAR struct tm *)rtctime);
|
|
|
|
msg.nsec = rtctime->tm_nsec;
|
|
|
|
msg.header.command = RPMSG_RTC_SYNC;
|
2023-11-19 16:39:47 +01:00
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
struct timespec tp;
|
|
|
|
|
|
|
|
tp.tv_sec = msg.sec;
|
|
|
|
tp.tv_nsec = msg.nsec;
|
|
|
|
clock_synchronize(&tp);
|
|
|
|
|
|
|
|
ret = 1; /* Request the upper half skip clock synchronize */
|
|
|
|
}
|
|
|
|
|
2023-11-03 08:44:36 +01:00
|
|
|
msg.base_sec = g_basetime.tv_sec;
|
|
|
|
msg.base_nsec = g_basetime.tv_nsec;
|
|
|
|
|
2023-11-19 16:39:47 +01:00
|
|
|
nxmutex_lock(&server->lock);
|
2023-11-03 08:44:36 +01:00
|
|
|
|
2021-03-19 07:34:43 +01:00
|
|
|
list_for_every(&server->list, node)
|
|
|
|
{
|
2022-01-14 14:48:31 +01:00
|
|
|
client = (FAR struct rpmsg_rtc_client_s *)node;
|
2022-01-13 15:01:53 +01:00
|
|
|
rpmsg_send(&client->ept, &msg, sizeof(msg));
|
2021-03-19 07:34:43 +01:00
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&server->lock);
|
2021-03-19 07:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool rpmsg_rtc_server_havesettime(FAR struct rtc_lowerhalf_s *lower)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server =
|
|
|
|
(FAR struct rpmsg_rtc_server_s *)lower;
|
|
|
|
|
|
|
|
return server->lower->ops->havesettime(server->lower);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_RTC_ALARM
|
|
|
|
static int rpmsg_rtc_server_setalarm(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR const struct lower_setalarm_s *alarminfo)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server =
|
|
|
|
(FAR struct rpmsg_rtc_server_s *)lower;
|
|
|
|
|
|
|
|
return server->lower->ops->setalarm(server->lower, alarminfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmsg_rtc_server_setrelative(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR const struct lower_setrelative_s *relinfo)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server =
|
|
|
|
(FAR struct rpmsg_rtc_server_s *)lower;
|
|
|
|
|
|
|
|
return server->lower->ops->setrelative(server->lower, relinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmsg_rtc_server_cancelalarm(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
int alarmid)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server =
|
|
|
|
(FAR struct rpmsg_rtc_server_s *)lower;
|
|
|
|
|
|
|
|
return server->lower->ops->cancelalarm(server->lower, alarmid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rpmsg_rtc_server_rdalarm(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR struct lower_rdalarm_s *alarminfo)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server =
|
|
|
|
(FAR struct rpmsg_rtc_server_s *)lower;
|
|
|
|
|
|
|
|
return server->lower->ops->rdalarm(server->lower, alarminfo);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_RTC_PERIODIC
|
|
|
|
static int rpmsg_rtc_server_setperiodic(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
FAR const struct lower_setperiodic_s *alarminfo)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server =
|
|
|
|
(FAR struct rpmsg_rtc_server_s *)lower;
|
|
|
|
|
|
|
|
return server->lower->ops->setperiodic(server->lower, alarminfo);
|
|
|
|
}
|
|
|
|
|
2022-01-16 09:50:51 +01:00
|
|
|
static int rpmsg_rtc_server_cancelperiodic(
|
|
|
|
FAR struct rtc_lowerhalf_s *lower, int alarmid)
|
2021-03-19 07:34:43 +01:00
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server =
|
|
|
|
(FAR struct rpmsg_rtc_server_s *)lower;
|
|
|
|
|
|
|
|
return server->lower->ops->cancelperiodic(server->lower, alarmid);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-01-16 09:50:51 +01:00
|
|
|
#ifdef CONFIG_RTC_IOCTL
|
|
|
|
static int rpmsg_rtc_server_ioctl(FAR struct rtc_lowerhalf_s *lower,
|
|
|
|
int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server =
|
|
|
|
(FAR struct rpmsg_rtc_server_s *)lower;
|
|
|
|
|
|
|
|
return server->lower->ops->ioctl(server->lower, cmd, arg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
|
|
|
static int rpmsg_rtc_server_destroy(FAR struct rtc_lowerhalf_s *lower)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server =
|
|
|
|
(FAR struct rpmsg_rtc_server_s *)lower;
|
|
|
|
FAR struct rpmsg_rtc_client_s *client;
|
|
|
|
FAR struct list_node *node;
|
|
|
|
FAR struct list_node *temp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = server->lower->ops->destroy(server->lower);
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
list_for_every_safe(&server->list, node, temp)
|
|
|
|
{
|
|
|
|
client = (FAR struct rpmsg_rtc_client_s *)node;
|
|
|
|
list_delete(&client->node);
|
|
|
|
rpmsg_destroy_ept(&client->ept);
|
|
|
|
kmm_free(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
kmm_free(server);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-03-19 07:34:43 +01:00
|
|
|
static void rpmsg_rtc_server_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
|
|
|
{
|
2022-01-14 14:48:31 +01:00
|
|
|
FAR struct rpmsg_rtc_client_s *client = container_of(ept,
|
|
|
|
struct rpmsg_rtc_client_s, ept);
|
2021-03-19 07:34:43 +01:00
|
|
|
FAR struct rpmsg_rtc_server_s *server = ept->priv;
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_lock(&server->lock);
|
2022-01-14 14:48:31 +01:00
|
|
|
list_delete(&client->node);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&server->lock);
|
2022-01-14 14:48:31 +01:00
|
|
|
rpmsg_destroy_ept(&client->ept);
|
|
|
|
kmm_free(client);
|
2021-03-19 07:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_RTC_ALARM
|
|
|
|
static void rpmsg_rtc_server_alarm_cb(FAR void *priv, int alarmid)
|
|
|
|
{
|
2022-01-14 14:48:31 +01:00
|
|
|
FAR struct rpmsg_rtc_client_s *client = priv;
|
2022-01-16 09:18:09 +01:00
|
|
|
struct rpmsg_rtc_alarm_fire_s msg;
|
|
|
|
|
|
|
|
msg.header.command = RPMSG_RTC_ALARM_FIRE;
|
|
|
|
msg.id = alarmid;
|
2021-03-19 07:34:43 +01:00
|
|
|
|
2022-01-14 14:48:31 +01:00
|
|
|
rpmsg_send(&client->ept, &msg, sizeof(msg));
|
2021-03-19 07:34:43 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int rpmsg_rtc_server_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|
|
|
FAR void *data, size_t len, uint32_t src,
|
|
|
|
FAR void *priv)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_header_s *header = data;
|
|
|
|
|
|
|
|
switch (header->command)
|
|
|
|
{
|
|
|
|
case RPMSG_RTC_GET:
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_get_s *msg = data;
|
2022-01-15 07:03:30 +01:00
|
|
|
struct rtc_time rtctime;
|
2021-03-19 07:34:43 +01:00
|
|
|
|
2022-01-18 17:24:17 +01:00
|
|
|
header->result = rpmsg_rtc_server_rdtime(priv, &rtctime);
|
|
|
|
|
2022-01-15 07:03:30 +01:00
|
|
|
msg->sec = timegm((FAR struct tm *)&rtctime);
|
|
|
|
msg->nsec = rtctime.tm_nsec;
|
2021-03-19 07:34:43 +01:00
|
|
|
return rpmsg_send(ept, msg, sizeof(*msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
case RPMSG_RTC_SET:
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_set_s *msg = data;
|
2022-01-15 07:03:30 +01:00
|
|
|
struct rtc_time rtctime;
|
|
|
|
time_t time = msg->sec;
|
2021-03-19 07:34:43 +01:00
|
|
|
|
2022-01-15 07:03:30 +01:00
|
|
|
gmtime_r(&time, (FAR struct tm *)&rtctime);
|
|
|
|
rtctime.tm_nsec = msg->nsec;
|
2022-01-18 17:24:17 +01:00
|
|
|
|
|
|
|
header->result = rpmsg_rtc_server_settime(priv, &rtctime);
|
2021-03-19 07:34:43 +01:00
|
|
|
return rpmsg_send(ept, msg, sizeof(*msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_RTC_ALARM
|
|
|
|
case RPMSG_RTC_ALARM_SET:
|
|
|
|
{
|
2022-01-14 14:48:31 +01:00
|
|
|
FAR struct rpmsg_rtc_client_s *client = container_of(ept,
|
|
|
|
struct rpmsg_rtc_client_s, ept);
|
2021-03-19 07:34:43 +01:00
|
|
|
FAR struct rpmsg_rtc_alarm_set_s *msg = data;
|
|
|
|
time_t time = msg->sec;
|
2022-01-16 09:18:09 +01:00
|
|
|
struct lower_setalarm_s alarminfo;
|
|
|
|
|
|
|
|
alarminfo.id = msg->id;
|
|
|
|
alarminfo.cb = rpmsg_rtc_server_alarm_cb;
|
|
|
|
alarminfo.priv = client;
|
2021-03-19 07:34:43 +01:00
|
|
|
|
|
|
|
gmtime_r(&time, (FAR struct tm *)&alarminfo.time);
|
|
|
|
alarminfo.time.tm_nsec = msg->nsec;
|
2022-01-18 17:24:17 +01:00
|
|
|
header->result = rpmsg_rtc_server_setalarm(priv, &alarminfo);
|
2021-03-19 07:34:43 +01:00
|
|
|
return rpmsg_send(ept, msg, sizeof(*msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
case RPMSG_RTC_ALARM_CANCEL:
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_alarm_cancel_s *msg = data;
|
2022-01-18 17:24:17 +01:00
|
|
|
header->result = rpmsg_rtc_server_cancelalarm(priv, msg->id);
|
2021-03-19 07:34:43 +01:00
|
|
|
return rpmsg_send(ept, msg, sizeof(*msg));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
header->result = -ENOSYS;
|
|
|
|
return rpmsg_send(ept, header, sizeof(*header));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 10:38:11 +02:00
|
|
|
static bool rpmsg_rtc_server_ns_match(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv,
|
|
|
|
FAR const char *name,
|
|
|
|
uint32_t dest)
|
|
|
|
{
|
|
|
|
return !strcmp(name, RPMSG_RTC_EPT_NAME);
|
|
|
|
}
|
|
|
|
|
2021-03-19 07:34:43 +01:00
|
|
|
static void rpmsg_rtc_server_ns_bind(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv,
|
|
|
|
FAR const char *name,
|
|
|
|
uint32_t dest)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server = priv;
|
2022-01-14 14:48:31 +01:00
|
|
|
FAR struct rpmsg_rtc_client_s *client;
|
2022-04-02 08:27:20 +02:00
|
|
|
struct rpmsg_rtc_set_s msg;
|
|
|
|
struct rtc_time rtctime;
|
2021-03-19 07:34:43 +01:00
|
|
|
|
2022-01-14 14:48:31 +01:00
|
|
|
client = kmm_zalloc(sizeof(*client));
|
|
|
|
if (client == NULL)
|
2021-03-19 07:34:43 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-14 14:48:31 +01:00
|
|
|
client->ept.priv = server;
|
|
|
|
if (rpmsg_create_ept(&client->ept, rdev, RPMSG_RTC_EPT_NAME,
|
2021-03-19 07:34:43 +01:00
|
|
|
RPMSG_ADDR_ANY, dest,
|
|
|
|
rpmsg_rtc_server_ept_cb,
|
|
|
|
rpmsg_rtc_server_ns_unbind) < 0)
|
|
|
|
{
|
2022-01-14 14:48:31 +01:00
|
|
|
kmm_free(client);
|
2021-03-19 07:34:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-02 08:27:20 +02:00
|
|
|
if (server->lower->ops->rdtime(server->lower, &rtctime) >= 0)
|
|
|
|
{
|
|
|
|
msg.sec = timegm((FAR struct tm *)&rtctime);
|
|
|
|
msg.nsec = rtctime.tm_nsec;
|
2023-11-03 08:44:36 +01:00
|
|
|
msg.base_sec = g_basetime.tv_sec;
|
|
|
|
msg.base_nsec = g_basetime.tv_nsec;
|
|
|
|
|
2022-04-02 08:27:20 +02:00
|
|
|
msg.header.command = RPMSG_RTC_SYNC;
|
|
|
|
rpmsg_send(&client->ept, &msg, sizeof(msg));
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_lock(&server->lock);
|
2022-01-14 14:48:31 +01:00
|
|
|
list_add_tail(&server->list, &client->node);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&server->lock);
|
2021-03-19 07:34:43 +01:00
|
|
|
}
|
2021-05-07 05:28:35 +02:00
|
|
|
#endif
|
2021-03-19 07:34:43 +01:00
|
|
|
|
2019-11-02 18:30:33 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpmsg_rtc_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
* Take remote core RTC as external RTC hardware through rpmsg.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2021-03-19 07:34:43 +01:00
|
|
|
* Return the lower half RTC driver instance on success;
|
|
|
|
* A NULL pointer on failure.
|
2019-11-02 18:30:33 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-05-07 05:28:35 +02:00
|
|
|
#ifndef CONFIG_RTC_RPMSG_SERVER
|
2022-01-15 05:08:41 +01:00
|
|
|
FAR struct rtc_lowerhalf_s *rpmsg_rtc_initialize(void)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_lowerhalf_s *lower;
|
|
|
|
|
|
|
|
lower = kmm_zalloc(sizeof(*lower));
|
2022-01-15 05:08:41 +01:00
|
|
|
if (lower != NULL)
|
2019-11-02 18:30:33 +01:00
|
|
|
{
|
2022-01-15 05:08:41 +01:00
|
|
|
lower->ops = &g_rpmsg_rtc_ops;
|
2019-11-02 18:30:33 +01:00
|
|
|
|
|
|
|
rpmsg_register_callback(lower,
|
|
|
|
rpmsg_rtc_device_created,
|
|
|
|
rpmsg_rtc_device_destroy,
|
2022-06-06 10:38:11 +02:00
|
|
|
NULL,
|
2019-11-02 18:30:33 +01:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (FAR struct rtc_lowerhalf_s *)lower;
|
|
|
|
}
|
2021-03-19 07:34:43 +01:00
|
|
|
|
2021-05-07 05:28:35 +02:00
|
|
|
#else
|
2021-03-19 07:34:43 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: rpmsg_rtc_server_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Sync RTC info to remote core without external RTC hardware through
|
|
|
|
* rpmsg.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Return the lower half RTC driver instance on success;
|
|
|
|
* A NULL pointer on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR struct rtc_lowerhalf_s *rpmsg_rtc_server_initialize(
|
|
|
|
FAR struct rtc_lowerhalf_s *lower)
|
|
|
|
{
|
|
|
|
FAR struct rpmsg_rtc_server_s *server;
|
|
|
|
|
|
|
|
server = kmm_zalloc(sizeof(*server));
|
|
|
|
if (server)
|
|
|
|
{
|
|
|
|
server->ops = &g_rpmsg_rtc_server_ops;
|
|
|
|
server->lower = lower;
|
|
|
|
list_initialize(&server->list);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_init(&server->lock);
|
2021-03-19 07:34:43 +01:00
|
|
|
if (rpmsg_register_callback(server, NULL, NULL,
|
2022-06-06 10:38:11 +02:00
|
|
|
rpmsg_rtc_server_ns_match,
|
2021-03-19 07:34:43 +01:00
|
|
|
rpmsg_rtc_server_ns_bind) < 0)
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_destroy(&server->lock);
|
2021-03-19 07:34:43 +01:00
|
|
|
kmm_free(server);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (FAR struct rtc_lowerhalf_s *)server;
|
|
|
|
}
|
2021-05-07 05:28:35 +02:00
|
|
|
#endif
|