Fishwaldo commented on code in PR #19889:
URL: https://github.com/apache/nuttx/pull/19889#discussion_r3797046895


##########
drivers/timers/pcf8563.c:
##########
@@ -0,0 +1,554 @@
+/****************************************************************************
+ * drivers/timers/pcf8563.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <stdint.h>
+#include <time.h>
+#include <errno.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/debug.h>
+#include <nuttx/i2c/i2c_master.h>
+#include <nuttx/timers/pcf8563.h>
+
+#ifdef CONFIG_RTC_PCF8563
+
+#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
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Register map.  Everything that carries a time is BCD. */
+
+#define PCF8563_CTRL1        0x00
+#define PCF8563_CTRL2        0x01
+#define PCF8563_SECONDS      0x02
+#define PCF8563_MINUTES      0x03
+#define PCF8563_HOURS        0x04
+#define PCF8563_DAY          0x05
+#define PCF8563_WEEKDAY      0x06
+#define PCF8563_MONTH        0x07
+#define PCF8563_YEAR         0x08
+
+/* Alarm at 0x09 to 0x0c, clock output at 0x0d, and a countdown timer at
+ * 0x0e and 0x0f.  None is used here.  They are written down because
+ * knowing where they are is most of the work of adding them, and because
+ * a reader wondering whether an alarm exists deserves an answer.
+ */
+
+#define PCF8563_ALARM_MIN    0x09
+#define PCF8563_ALARM_HOUR   0x0a
+#define PCF8563_ALARM_DAY    0x0b
+#define PCF8563_ALARM_WEEK   0x0c
+#define PCF8563_CLKOUT       0x0d
+#define PCF8563_TIMER_CTRL   0x0e
+#define PCF8563_TIMER        0x0f
+
+/* The seconds register carries a flag rather than a tenth digit: the
+ * oscillator has stopped at some point since the time was last set, so
+ * what the rest of the register file says is not to be believed.
+ */
+
+#define PCF8563_SEC_VL       0x80
+#define PCF8563_SEC_MASK     0x7f
+
+#define PCF8563_MIN_MASK     0x7f
+#define PCF8563_HOUR_MASK    0x3f
+#define PCF8563_DAY_MASK     0x3f
+#define PCF8563_WEEKDAY_MASK 0x07
+#define PCF8563_MONTH_MASK   0x1f
+#define PCF8563_YEAR_MASK    0xff
+
+/* The month register's top bit marks a century rollover.  Which value
+ * stands for which century is not settled between parts, so this driver
+ * does not try to read one out of it.  See pcf8563_getdatetime().
+ */
+
+#define PCF8563_MONTH_C      0x80
+
+/* Stopping the counters while the registers are written keeps a carry
+ * from landing in the middle of the write.
+ */
+
+#define PCF8563_CTRL1_STOP   0x20
+
+#ifndef CONFIG_PCF8563_I2C_FREQUENCY
+#  define CONFIG_PCF8563_I2C_FREQUENCY 100000
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct pcf8563_dev_s
+{
+  FAR struct i2c_master_s *i2c;
+
+  /* The century bit exactly as it was last seen, so that it can be
+   * written back the same way round.  See pcf8563_getdatetime().
+   */
+
+  bool c_polarity;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int pcf8563_getdatetime(FAR struct pcf8563_dev_s *priv,
+                               FAR struct tm *tp);
+static int pcf8563_setdatetime(FAR struct pcf8563_dev_s *priv,
+                               FAR const struct tm *tp);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Only one of these is supported, because up_rtc_getdatetime() takes no
+ * argument saying which.
+ */
+
+static struct pcf8563_dev_s g_pcf8563;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* Set once the chip is bound to a bus.  Read by up_rtc_getdatetime(), which
+ * the system may call before that has happened.
+ */
+
+volatile bool g_rtc_enabled = false;

Review Comment:
   its defined as a EXTERN in include/nuttx/arch.h:221 - Moving it into 
pcf8563_dev_s would break the "an RTC exists and is ready" that the 
clock_settime.c and clock_systime_timespec.c depend upon. 
   
   I can add a code comment saying its a global var. 
   
   (the other I2C drivers - ds3231, pcf85263, mcp794xx, rx8010 do the same)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to