pkarashchenko commented on a change in pull request #5499: URL: https://github.com/apache/incubator-nuttx/pull/5499#discussion_r810047658
########## File path: drivers/timers/rx8010.c ########## @@ -0,0 +1,613 @@ +/**************************************************************************** + * drivers/timers/rx8010.c + * + * 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 + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdbool.h> +#include <time.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <nuttx/i2c/i2c_master.h> +#include <nuttx/timers/rx8010.h> + +#include "rx8010.h" + +#ifdef CONFIG_RTC_RX8010SJ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* This RTC implementation supports only date/time RTC hardware */ + +#ifndef CONFIG_RTC_DATETIME +# error CONFIG_RTC_DATETIME must be set to use this driver +#endif + +#ifdef CONFIG_RTC_HIRES +# error CONFIG_RTC_HIRES must NOT be set with this driver +#endif + +#ifndef CONFIG_RX8010SJ_I2C_FREQUENCY +# error CONFIG_RX8010SJ_I2C_FREQUENCY is not configured +# define CONFIG_RX8010SJ_I2C_FREQUENCY 400000 +#endif + +#if CONFIG_RX8010SJ_I2C_FREQUENCY > 400000 +# error CONFIG_RX8010SJ_I2C_FREQUENCY is out of range +#endif + +#define RX8010_I2C_ADDRESS 0x32 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This structure describes the state of the RX8010SJ chip. + * Only a single RTC is supported. + */ + +struct rx8010_dev_s +{ + FAR struct i2c_master_s *i2c; /* Contained reference to the I2C bus driver */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* g_rtc_enabled is set true after the RTC has successfully initialized */ + +volatile bool g_rtc_enabled = false; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* The state of the RX8010 chip. Only a single RTC is supported */ + +static struct rx8010_dev_s g_rx8010; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int rx8010_init(); + +/**************************************************************************** + * Name: rtc_dumptime + * + * Description: + * Show the broken out time. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_DEBUG_RTC_INFO +static void rtc_dumptime(FAR struct tm *tp, FAR const char *msg) +{ + rtcinfo("%s:\n", msg); + rtcinfo(" tm_sec: %08x\n", tp->tm_sec); + rtcinfo(" tm_min: %08x\n", tp->tm_min); + rtcinfo(" tm_hour: %08x\n", tp->tm_hour); + rtcinfo(" tm_mday: %08x\n", tp->tm_mday); + rtcinfo(" tm_mon: %08x\n", tp->tm_mon); + rtcinfo(" tm_year: %08x\n", tp->tm_year); + rtcinfo(" tm_wday: %08x\n", tp->tm_wday); + rtcinfo(" tm_yday: %08x\n", tp->tm_yday); + rtcinfo(" tm_isdst: %08x\n", tp->tm_isdst); +} +#else +# define rtc_dumptime(tp, msg) +#endif + +/**************************************************************************** + * Name: rtc_bin2bcd + * + * Description: + * Converts a 2 digit binary to BCD format + * + * Input Parameters: + * value - The byte to be converted. + * + * Returned Value: + * The value in BCD representation + * + ****************************************************************************/ + +static uint8_t rtc_bin2bcd(int value) +{ + uint8_t msbcd = 0; + + while (value >= 10) + { + msbcd++; + value -= 10; + } + + return (msbcd << 4) | value; +} + +/**************************************************************************** + * Name: rtc_bcd2bin + * + * Description: + * Convert from 2 digit BCD to binary. + * + * Input Parameters: + * value - The BCD value to be converted. + * + * Returned Value: + * The value in binary representation + * + ****************************************************************************/ + +static int rtc_bcd2bin(uint8_t value) +{ + int tens = ((int)value >> 4) * 10; + return tens + (value & 0x0f); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dsxxxx_rtc_initialize + * + * Description: + * Initialize the hardware RTC per the selected configuration. + * This function is called once during the OS initialization sequence by + * board-specific logic. + * + * After dsxxxx_rtc_initialize() is called, the OS function Review comment: ```suggestion * After rx8010_rtc_initialize() is called, the OS function ``` ########## File path: drivers/timers/rx8010.c ########## @@ -0,0 +1,613 @@ +/**************************************************************************** + * drivers/timers/rx8010.c + * + * 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 + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdbool.h> +#include <time.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <nuttx/i2c/i2c_master.h> +#include <nuttx/timers/rx8010.h> + +#include "rx8010.h" + +#ifdef CONFIG_RTC_RX8010SJ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +/* This RTC implementation supports only date/time RTC hardware */ + +#ifndef CONFIG_RTC_DATETIME +# error CONFIG_RTC_DATETIME must be set to use this driver +#endif + +#ifdef CONFIG_RTC_HIRES +# error CONFIG_RTC_HIRES must NOT be set with this driver +#endif + +#ifndef CONFIG_RX8010SJ_I2C_FREQUENCY +# error CONFIG_RX8010SJ_I2C_FREQUENCY is not configured +# define CONFIG_RX8010SJ_I2C_FREQUENCY 400000 +#endif + +#if CONFIG_RX8010SJ_I2C_FREQUENCY > 400000 +# error CONFIG_RX8010SJ_I2C_FREQUENCY is out of range +#endif + +#define RX8010_I2C_ADDRESS 0x32 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* This structure describes the state of the RX8010SJ chip. + * Only a single RTC is supported. + */ + +struct rx8010_dev_s +{ + FAR struct i2c_master_s *i2c; /* Contained reference to the I2C bus driver */ +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* g_rtc_enabled is set true after the RTC has successfully initialized */ + +volatile bool g_rtc_enabled = false; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* The state of the RX8010 chip. Only a single RTC is supported */ + +static struct rx8010_dev_s g_rx8010; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int rx8010_init(); + +/**************************************************************************** + * Name: rtc_dumptime + * + * Description: + * Show the broken out time. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_DEBUG_RTC_INFO +static void rtc_dumptime(FAR struct tm *tp, FAR const char *msg) +{ + rtcinfo("%s:\n", msg); + rtcinfo(" tm_sec: %08x\n", tp->tm_sec); + rtcinfo(" tm_min: %08x\n", tp->tm_min); + rtcinfo(" tm_hour: %08x\n", tp->tm_hour); + rtcinfo(" tm_mday: %08x\n", tp->tm_mday); + rtcinfo(" tm_mon: %08x\n", tp->tm_mon); + rtcinfo(" tm_year: %08x\n", tp->tm_year); + rtcinfo(" tm_wday: %08x\n", tp->tm_wday); + rtcinfo(" tm_yday: %08x\n", tp->tm_yday); + rtcinfo(" tm_isdst: %08x\n", tp->tm_isdst); +} +#else +# define rtc_dumptime(tp, msg) +#endif + +/**************************************************************************** + * Name: rtc_bin2bcd + * + * Description: + * Converts a 2 digit binary to BCD format + * + * Input Parameters: + * value - The byte to be converted. + * + * Returned Value: + * The value in BCD representation + * + ****************************************************************************/ + +static uint8_t rtc_bin2bcd(int value) +{ + uint8_t msbcd = 0; + + while (value >= 10) + { + msbcd++; + value -= 10; + } + + return (msbcd << 4) | value; +} + +/**************************************************************************** + * Name: rtc_bcd2bin + * + * Description: + * Convert from 2 digit BCD to binary. + * + * Input Parameters: + * value - The BCD value to be converted. + * + * Returned Value: + * The value in binary representation + * + ****************************************************************************/ + +static int rtc_bcd2bin(uint8_t value) +{ + int tens = ((int)value >> 4) * 10; + return tens + (value & 0x0f); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dsxxxx_rtc_initialize Review comment: ```suggestion * Name: rx8010_rtc_initialize ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org