Just another thought.

On Wed, Aug 09, 2017 at 10:12:37PM +0800, Jun Nie wrote:
> diff --git 
> a/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.h 
> b/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.h
> new file mode 100644
> index 0000000..3b5a4d4
> --- /dev/null
> +++ b/Silicon/Sanchip/Library/Zx6718RealTimeClockLib/Zx296718RealTimeClock.h
> @@ -0,0 +1,102 @@
> +/** @file
> +*
> +*  Copyright (C) 2017 Sanechips Technology Co., Ltd.
> +*  Copyright (c) 2017, Linaro Ltd.
> +*
> +*  This program and the accompanying materials
> +*  are licensed and made available under the terms and conditions of the BSD 
> License
> +*  which accompanies this distribution.  The full text of the license may be 
> found at
> +*  http://opensource.org/licenses/bsd-license.php
> +*
> +*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
> IMPLIED.
> +*
> +*  Based on the files under 
> ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.inf
> +**/
> +
> +
> +#ifndef __DS3231_REAL_TIME_CLOCK_H__
> +#define __DS3231_REAL_TIME_CLOCK_H__
> +
> +#define RTC_POWER_INI1_PARA     (0xCDBC)
> +#define RTC_POWER_INI2_PARA     (0xCFCC)
> +#define CONFIG_PARMETER         (0xC1CD)
> +
> +#define ZX_RTC_CMP_VALUE        (0x3FFF)
> +#define WAIT_FOR_COUNT          (2000)
> +#define INIT_DELAY              (100)
> +
> +
> +/* RTC Control register description */
> +#define RTC_CTRL_STOP                   (~(0x1 << 0))
> +#define RTC_CTRL_RUN                    (0x1 << 0)
> +#define RTC_CTRL_ROUND30S               (0x1 << 1)
> +#define RTC_CTRL_AUTO_COMPENSATION      (0x1 << 2)
> +#define RTC_CTRL_MODULE12               (0x1 << 3)
> +#define RTC_CTRL_MODULE24               (~(0x1 << 3))
> +#define RTC_CTRL_SET_32_COUNTER         (0x1 << 5)
> +#define RTC_CTRL_SOFT_RESET             (0x1 << 6)
> +#define RTC_CTRL_CLK_32K_OUTEN          (0x1 << 8)
> +
> +#define RTC_CTRL_BIT6_0                 ( ~(0x1 << 6))
> +#define RTC_CTRL_BIT6_1                 (0x1 << 6)
> +
> +
> +
> +/* RTC Interrupt register description */
> +#define RTC_EVERY_MASK          (0x3 << 0)
> +#define RTC_EVERY_SEC           0x00                    /* second periodic 
> intrrupt */
> +#define RTC_EVERY_MIN           0x01                    /* minute periodic 
> interrupt */
> +#define RTC_EVERY_HR            0x02                    /* hour periodic 
> interrupt */
> +#define RTC_EVERY_DAY           0x03                    /* day periodic 
> interrupt */
> +#define RTC_IT_TIMER            (0x1 << 2)              /* Enable periodic 
> interrupt */
> +#define RTC_IT_ALARM            (0x1 << 3)              /* Enable alarm 
> clock interrupt */
> +#define RTC_IT_MASK             (0x3 << 2)
> +
> +/* RTC Status register description */
> +#define RTC_BUSY                (0x1 << 0)              /* Read-only, 
> indicate refresh*/
> +#define RTC_RUN                 (0x1 << 1)              /* Read-only, RTC is 
> running */
> +#define RTC_ALARM               (0x1 << 6)              /* Read/Write, Alarm 
> interrupt has been generated */
> +#define RTC_TIMER               (0x1 << 7)              /* Read/Write, Timer 
> interrupt has been generated */
> +#define RTC_POWER_UP            (0x1 << 8)              /* Read/Write, Reset 
> */
> +
> +#define TM_YEAR_START               1900
> +
> +#define TM_MONTH_OFFSET             1
> +
> +#define TM_WDAY_SUNDAY              0
> +#define ZX_RTC_SUNDAY               7
> +
> +#define BCD2BIN(val)    (((val) & 0x0f) + ((val) >> 4) * 10)
> +#define BIN2BCD(val)    ((((val) / 10) << 4) + (val) % 10)

Are these not equivalent to DecimalToBcd8/BcdToDecimal8 in BaseLib?
If so, could we drop these and use the BasLib versions in the code?

> +
> +#define BCD4_2_BIN(x)   (( (x) & 0x0F) +                    \
> +                        ((((x) & 0x0F0) >>   4) * 10)  +    \
> +                        ((((x) & 0xF00) >>   8) * 100) +    \
> +                        ((((x) & 0xF000) >> 12) * 1000))
> +
> +
> +#define BIN_2_BCD4(x)   (((x % 10) & 0x0F)       |          \
> +                        (((x /10 ) % 10)  <<  4) |          \
> +                        (((x /100) % 10)  <<  8) |          \
> +                        (((x /1000) % 10) << 12))
> +

And would these not be DecimalToBcd16/BcdToDecimal16? Should we add
those to BaseLib?

/
    Leif
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to