diff options
author | 2020-11-20 23:36:23 +0900 | |
---|---|---|
committer | 2020-11-22 09:02:55 +0900 | |
commit | 17cf21bcf8a2e29d2cbcf0a313474d2a4ee44f5d (patch) | |
tree | 582a9768558d9eaf261ca5df6136e9de54c95816 /hal/clock_hal/src | |
parent | 9e86046cdb356913ae026f616e5bf17f6f238aa5 (diff) |
Re-organized sub-directory by category
Since all the sub-directories were placed in the
first level, created sub-directories, "hal", "module",
and "service" for classification and relocated each component.
Signed-off-by: Tadao Tanikawa <tanikawa.tadao@jp.panasonic.com>
Change-Id: Ifdf743ac0d1893bd8e445455cf0d2c199a011d5c
Diffstat (limited to 'hal/clock_hal/src')
-rwxr-xr-x | hal/clock_hal/src/clock_hal.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/hal/clock_hal/src/clock_hal.cpp b/hal/clock_hal/src/clock_hal.cpp new file mode 100755 index 0000000..cccbd5b --- /dev/null +++ b/hal/clock_hal/src/clock_hal.cpp @@ -0,0 +1,91 @@ +/* + * @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +#include "clock_hal.h" + +#include <assert.h> +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <linux/rtc.h> +#include <stdio.h> +#include <string.h> +#include <sys/ioctl.h> +#include <unistd.h> + +#include "clock_hal_clockhallog.h" + +#define RTC_NODE_PATH_DEPTH 64 +#define RTC_NODE_PERANT_PATH "/dev" + +// set time to hardware +EFrameworkunifiedStatus SetHardwareClock(HANDLE h_app, const struct tm *l_tm) { + if (NULL == h_app) { + return eFrameworkunifiedStatusInvldHandle; + } + if (NULL == l_tm) { + return eFrameworkunifiedStatusNullPointer; + } + + EFrameworkunifiedStatus e_status = eFrameworkunifiedStatusOK; + struct rtc_time hal_rtc_time; + hal_rtc_time.tm_year = l_tm->tm_year; + hal_rtc_time.tm_mon = l_tm->tm_mon; + hal_rtc_time.tm_mday = l_tm->tm_mday; + hal_rtc_time.tm_hour = l_tm->tm_hour; + hal_rtc_time.tm_min = l_tm->tm_min; + hal_rtc_time.tm_sec = l_tm->tm_sec; + hal_rtc_time.tm_wday = l_tm->tm_wday; + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "setting time : %d-%02d/%02d %02d:%02d:%02d\n", + 1900 + l_tm->tm_year, l_tm->tm_mon + 1, l_tm->tm_mday, + l_tm->tm_hour, l_tm->tm_min, l_tm->tm_sec); + + // Search RTC node + DIR *dir = ::opendir(RTC_NODE_PERANT_PATH); + char rtc_path[RTC_NODE_PATH_DEPTH] = { '\0' }; + for (struct dirent *dp = readdir(dir); dp != NULL; dp = readdir(dir)) { + if (strstr(dp->d_name, "rtc") != NULL) { + snprintf(rtc_path, sizeof(rtc_path), "/dev/%s", dp->d_name); + break; + } + } + closedir(dir); + if (strlen(rtc_path) == 0) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "/dev/rtcX not found.\n"); + e_status = eFrameworkunifiedStatusFail; + return e_status; + } + + // Set time to /dev/rtcX + int fd = ::open(rtc_path, O_WRONLY); + if (-1 == fd) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "Error open(/dev/rtc)=[%d] errno=%d\n", + fd, errno); + return eFrameworkunifiedStatusFail; + } + int ret = ::ioctl(fd, RTC_SET_TIME, &hal_rtc_time); + if (0 != ret) { + FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, + "Error ioctl(fd, RTC_SET_TIME, hal_rtc_time)=[%d] errno=%d\n", + ret, errno); + e_status = eFrameworkunifiedStatusFail; + } else { + FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, + "Success ioctl(fd, RTC_SET_TIME, hal_rtc_time)=[%d]\n", ret); + } + ::close(fd); + return e_status; +} |