⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lh79520_rtc_driver.c

📁 Sharp Lh79520 RTC 驱动源码.
💻 C
字号:
/***********************************************************************
 * $Workfile:   lh79520_rtc_driver.c  $
 * $Revision:   1.0  $
 * $Author:   LiJ  $
 * $Date:   Jul 07 2003 16:40:00  $
 *
 * Project: LH79520 RTC real time clock driver
 *
 * Description:
 *     This file contains driver support for the RTC module on the
 *     LH79520
 *
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh79520/source/lh79520_rtc_driver.c-arc  $
 * 
 *    Rev 1.0   Jul 07 2003 16:40:00   LiJ
 * Initial revision.
 * 
 * SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
 * OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
 * AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES, 
 * SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
 *
 * SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY 
 * FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A 
 * SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
 * FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
 *
 *  COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
 *      CAMAS, WA
 *
 **********************************************************************/

#include "lh79520_rcpc.h"
#include "lh79520_rtc_driver.h"

/***********************************************************************
 * RTC driver private data
 **********************************************************************/

/* RTC device configuration structure */
STATIC RTC_CFG_T rtccfg;

/***********************************************************************
 * RTC driver public functions
 **********************************************************************/

/***********************************************************************
 *
 * Function: rtc_open
 *
 * Purpose: Open the RTC
 *
 * Processing:
 *     If init is not FALSE, return 0x00000000 to the caller. Otherwise,
 *     set init to TRUE, save the RTC peripheral register set address,
 *     disable and reset the match interrupt, and return a pointer to
 *     the RTC config structure to the caller.
 *
 * Parameters:
 *     ipbase: Real Time clock descriptor device address
 *     arg   : Not used
 *
 * Outputs: None
 *
 * Returns: The pointer to a Real Time clock config structure or 0
 *
 * Notes: None
 *
 **********************************************************************/
INT_32 rtc_open(void *ipbase, INT_32 arg)
{
    INT_32 status = 0;

    if ((rtccfg.init == FALSE) && ((RTC_REGS_T *) ipbase == RTC))
    {
        /* Device is valid and not previously initialized */
        rtccfg.init = TRUE;

        /* Save and return address of peripheral block */
        rtccfg.regptr = (RTC_REGS_T *) ipbase;

        /* Enable RTC clock in RCPC */
        RCPC->periphclkctrl &= ~RCPC_CLKCTRL_RTC_DISABLE;
        
        /* Disable and clear match interrupt */
        rtccfg.regptr->cr = 0x00000000;
        rtccfg.regptr->stat_eoi = 0x00000000;

        /* Return pointer to RTC configuration structure */
        status = (INT_32) &rtccfg;
    }

    return status;
}

/***********************************************************************
 *
 * Function: rtc_close
 *
 * Purpose: Close the RTC
 *
 * Processing:
 *     If init is not TRUE, then return _ERROR to the caller as the
 *     device was not previously opened. Otherwise, set init to FALSE
 *     and return _NO_ERROR to the caller.
 *
 * Parameters:
 *     devid: Pointer to Real time clock config structure
 *
 * Outputs: None
 *
 * Returns: The status of the close operation
 *
 * Notes: None
 *
 **********************************************************************/
STATUS rtc_close(INT_32 devid)
{
    RTC_CFG_T *rtccfgptr = (RTC_CFG_T *) devid;
    STATUS status = _ERROR;

    if (rtccfgptr->init == TRUE)
    {
        /* Disable RTC clock in RCPC */
        RCPC->periphclkctrl |= RCPC_CLKCTRL_RTC_DISABLE;
        
        /* 'Uninitialize' device */
        rtccfgptr->init = FALSE;
        status = _NO_ERROR;
    }

    return status;
}

/***********************************************************************
 *
 * Function: rtc_ioctl
 *
 * Purpose: RTC configuration block
 *
 * Processing:
 *     This function is a large case block. Based on the passed function
 *     and option values, set or get the appropriate real time clock
 *     parameter.
 *
 * Parameters:
 *     devid: Pointer to Real time clock config structure
 *     cmd:   ioctl command
 *     arg:   ioctl argument
 *
 * Outputs: None
 *
 * Returns: The status of the ioctl operation
 *
 * Notes: None
 *
 **********************************************************************/
STATUS rtc_ioctl(INT_32 devid,
                 INT_32 cmd,
                 INT_32 arg)
{
    RTC_REGS_T *rtcclock;
    RTC_CFG_T *rtccfgptr = (RTC_CFG_T *) devid;
    STATUS status = _ERROR;

    if (rtccfgptr->init == TRUE)
    {
        status = _NO_ERROR;
        rtcclock = rtccfgptr->regptr;

        switch (cmd)
        {
            case RTC_START:
                // Start the RTC with initial value specified
                // it could be 0x0 for RTC counter start to count from 0
                rtcclock->clr = (UNS_32) arg;
                break;

            case RTC_SET_TIME_MS:
                if(arg >= 2000) // >=2 secs, use 1Hz clock
                {
                    // use 1 Hz clock
                    RCPC->periphclksel &= ~RCPC_PCLKSEL_RTC_32KHZ;
                    /* Set RTC match value */
                    rtcclock->mr = (UNS_32) (arg/1000);
                }
                else    //<2 secs, use 32Khz clock
                {
                    // use 32 Khz clock
                    RCPC->periphclksel |= RCPC_PCLKSEL_RTC_32KHZ;
                    /* Set RTC match value */
                     rtcclock->mr = (UNS_32) (arg*CLOCK_32KHZ/1000);
                }
                break;

            case RTC_ENABLE_MATCH_INT:
                /* Enable RTC match interrupt */
                rtcclock->cr = RTC_CR_MIE;
                break;

            case RTC_DISABLE_MATCH_INT:
                /* Disable RTC match interrupt */
                rtcclock->cr = 0x00000000;
                break;
                
            case RTC_CLEAR_MATCH_INT:
                /* Clear the RTC match interrupt */
                rtcclock->stat_eoi = 0x00000000;
                break;

            case RTC_GET_STATUS:
                /* Return an RTC status */
                switch (arg)
                {
                    case RTC_GET_LOAD:
                        /* Get RTC clock value */
                         status = (INT_32) rtcclock->clr;
                         break;

                    case RTC_GET_CURRENT:
                        /* Get RTC current clock value */
                         status = (INT_32) rtcclock->dr;
                         break;

                    case RTC_GET_MATCH:
                        /* Get RTC match value */
                         status = (INT_32) rtcclock->mr;
                         break;

                    case GET_INT_PENDING:
                        if ((rtcclock->stat_eoi & RTC_RTCINTR) != 0)
                        {
                            /* RTC match interrupt is pending */
                            status = TRUE;
                        }
                        else
                        {
                            /* RTC match interrupt is not pending */
                            status = FALSE;
                        }
                        break;

                    default:
                        /* Unsupported parameter */
                        status = _ERROR;
                }
                break;

            default:
                /* Unsupported parameter */
                status = _NO_ERROR;
        }
    }

    return status;
}

/***********************************************************************
 *
 * Function: rtc_read
 *
 * Purpose: RTC read function (stub only)
 *
 * Processing:
 *     Return 0 to the caller.
 *
 * Parameters:
 *     devid:     Pointer to Real time clock config structure
 *     buffer:    Pointer to data buffer to copy to
 *     max_bytes: Number of bytes to read
 *
 * Outputs: None
 *
 * Returns: Number of bytes actually read (always 0)
 *
 * Notes: None
 *
 **********************************************************************/
INT_32 rtc_read(INT_32 devid,
                void *buffer,
                INT_32 max_bytes)
{
    return _ERROR;
}

/***********************************************************************
 *
 * Function: rtc_write
 *
 * Purpose: RTC write function (stub only)
 *
 * Processing:
 *     Return 0 to the caller.
 *
 * Parameters:
 *     devid:   Pointer to Real time clock config structure
 *     buffer:  Pointer to data buffer to copy from
 *     n_bytes: Number of bytes to write
 *
 * Outputs: None
 *
 * Returns: Number of bytes actually written (always 0)
 *
 * Notes: None
 *
 **********************************************************************/
INT_32 rtc_write(INT_32 devid,
                 void *buffer,
                 INT_32 n_bytes)
{
    return _ERROR;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -