rtc/rpmsg: Replace clock_[get|set]time with rtc_ops_s::[rd|set]time

to support the multiple rtc driver instance

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-01-15 14:03:30 +08:00 committed by Petro Karashchenko
parent 3d3c4767a9
commit 2b238d0772

View File

@ -583,6 +583,7 @@ static int rpmsg_rtc_server_ept_cb(FAR struct rpmsg_endpoint *ept,
FAR void *data, size_t len, uint32_t src, FAR void *data, size_t len, uint32_t src,
FAR void *priv) FAR void *priv)
{ {
FAR struct rpmsg_rtc_server_s *server = priv;
FAR struct rpmsg_rtc_header_s *header = data; FAR struct rpmsg_rtc_header_s *header = data;
switch (header->command) switch (header->command)
@ -590,22 +591,25 @@ static int rpmsg_rtc_server_ept_cb(FAR struct rpmsg_endpoint *ept,
case RPMSG_RTC_GET: case RPMSG_RTC_GET:
{ {
FAR struct rpmsg_rtc_get_s *msg = data; FAR struct rpmsg_rtc_get_s *msg = data;
struct timespec ts; struct rtc_time rtctime;
header->result = clock_gettime(CLOCK_REALTIME, &ts); header->result = server->lower->ops->rdtime(server->lower,
msg->sec = ts.tv_sec; &rtctime);
msg->nsec = ts.tv_nsec; msg->sec = timegm((FAR struct tm *)&rtctime);
msg->nsec = rtctime.tm_nsec;
return rpmsg_send(ept, msg, sizeof(*msg)); return rpmsg_send(ept, msg, sizeof(*msg));
} }
case RPMSG_RTC_SET: case RPMSG_RTC_SET:
{ {
FAR struct rpmsg_rtc_set_s *msg = data; FAR struct rpmsg_rtc_set_s *msg = data;
struct timespec ts; struct rtc_time rtctime;
time_t time = msg->sec;
ts.tv_sec = msg->sec; gmtime_r(&time, (FAR struct tm *)&rtctime);
ts.tv_nsec = msg->nsec; rtctime.tm_nsec = msg->nsec;
header->result = clock_settime(CLOCK_REALTIME, &ts); header->result = server->lower->ops->settime(server->lower,
&rtctime);
return rpmsg_send(ept, msg, sizeof(*msg)); return rpmsg_send(ept, msg, sizeof(*msg));
} }
@ -615,7 +619,6 @@ static int rpmsg_rtc_server_ept_cb(FAR struct rpmsg_endpoint *ept,
FAR struct rpmsg_rtc_client_s *client = container_of(ept, FAR struct rpmsg_rtc_client_s *client = container_of(ept,
struct rpmsg_rtc_client_s, ept); struct rpmsg_rtc_client_s, ept);
FAR struct rpmsg_rtc_alarm_set_s *msg = data; FAR struct rpmsg_rtc_alarm_set_s *msg = data;
FAR struct rpmsg_rtc_server_s *server = priv;
time_t time = msg->sec; time_t time = msg->sec;
struct lower_setalarm_s alarminfo = struct lower_setalarm_s alarminfo =
{ {
@ -634,7 +637,6 @@ static int rpmsg_rtc_server_ept_cb(FAR struct rpmsg_endpoint *ept,
case RPMSG_RTC_ALARM_CANCEL: case RPMSG_RTC_ALARM_CANCEL:
{ {
FAR struct rpmsg_rtc_alarm_cancel_s *msg = data; FAR struct rpmsg_rtc_alarm_cancel_s *msg = data;
FAR struct rpmsg_rtc_server_s *server = priv;
header->result = server->lower->ops->cancelalarm(server->lower, header->result = server->lower->ops->cancelalarm(server->lower,
msg->id); msg->id);
return rpmsg_send(ept, msg, sizeof(*msg)); return rpmsg_send(ept, msg, sizeof(*msg));