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

📄 rtc_example.c

📁 含t h r e a d x,u c o s 的b s p
💻 C
字号:
/***********************************************************************
 * $Workfile:   rtc_example.c  $
 * $Revision:   1.2  $
 * $Author:   WellsK  $
 * $Date:   Oct 01 2003 12:03:58  $
 *
 * Project: RTC driver example
 *
 * Description:
 *     A simple RTC driver example.
 *
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh7a404/bsps/sdk7a404/examples/rtc/rtc_example.c-arc  $
 * 
 *    Rev 1.2   Oct 01 2003 12:03:58   WellsK
 * Added logic to get TTB address from register CP15 TTB.
 * 
 *    Rev 1.1   Sep 18 2003 09:25:46   WellsK
 * Updated example for MMU and VIC driver changes.
 * 
 *    Rev 1.0   Jul 01 2003 10:04:56   WellsK
 * 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 "abl_types.h"
#include "abl_irq_fiq.h"
#include "abl_arm922t_cp15_driver.h"
#include "lh7a404_vic_driver.h"
#include "lh7a404_rtc_driver.h"
#include "lh7a404_csc_driver.h"
#include "sdk7a404_cpld_driver.h"

/* RTC device handle */
STATIC INT_32 rtcdev;

/* Test flag */
STATIC volatile INT_32 wakeupflag;

/***********************************************************************
 *
 * Function: rtc_match_user_interrupt
 *
 * Purpose: RTC interrupt handler
 *
 * Processing:
 *     Clear the RTC match interrupt and increment the match flag.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void rtc_match_user_interrupt(void)
{
    /* Clear the RTC match interrupt */
    rtc_ioctl(rtcdev, RTC_CLEAR_MATCH_INT, 0);
    wakeupflag++;
}

/***********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Real Time clock example with automatic wakeup on match
 *
 * Processing:
 *     See function. This example sets up the RTC clock and puts the
 *     chip to sleep. The chip will wakeup after being asleep for two
 *     seconds and toggle the LED a few times.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns 1
 *
 * Notes:
 *     Warning - debuggers that constantly interrogate the chip may
 *     lose communications with the chip when it is alseep. It is best
 *     not to stop the chip while it is asleep. This example may not
 *     work with all debuggers.
 *
 **********************************************************************/
int c_entry(void)
{
    INT_32 oldwakeupflag;
    BOOL_32 ledstate = TRUE;

    /* Disable interrupts in ARM core */
    disable_irq_fiq();

    /* Set virtual address of MMU table (needed for VIC driver
       functions) */
    cp15_set_vmmu_addr((UNS_32 *) cp15_get_ttb());

    /* Initialize interrupt system */
    vic_initialize(0xC0000000);

    /* Install standard IRQ dispatcher at ARM IRQ vector */
    vic_install_arm_handler(IRQ_VEC, (PFV) vic_arm_irq_dispatcher);

    /* Install VIC1 and VIC2 handlers */
    vic_install_arm_handler(VIC1_IRQ_VEC, (PFV) vic1_irq_dispatcher);
    vic_install_arm_handler(VIC2_IRQ_VEC, (PFV) vic2_irq_dispatcher);

    /* Install RTC handler as a vectored interrupt */
    /* Install timer handler as an IRQ interrupt */
    vic_install_handler(VIC_RTCMINTR, VIC_IRQ,
        (PFV) rtc_match_user_interrupt);

    /* Open RTC */
    if ((rtcdev = rtc_open(RTC, 0)) == 0x00000000)
    {
        return 0;
    }

    /* Reset RTC count value to 0 */
    rtc_ioctl(rtcdev, RTC_SET_CLOCK, 0);
    /* Setup RTC to wakeup in at least 2~3 seconds (match of 2) */
    rtc_ioctl(rtcdev, RTC_SET_MATCH, 2);
    /* Enable match interrupt in the RTC */
    rtc_ioctl(rtcdev, RTC_ENABLE_MATCH_INT, 1);
    /* Clear match interrupt in the RTC */
    rtc_ioctl(rtcdev, RTC_CLEAR_MATCH_INT, 0);

    /* Enable RTC match interrupt in the interrupt controller */
    vic_int_enable(VIC_RTCMINTR, TRUE);

    /* Enable IRQ interrupts in the ARM core */
    enable_irq();

    /* Go to sleep until match expires */
    csc_stby_wakeup_enable(FALSE);
    csc_enter_low_power_state(HALT);

    wakeupflag = 0;
    oldwakeupflag = 1;

    /* Set initial state of LED */
    cpld_enable_led(ledstate);
    
    /* Wait for 6 match events */
    while (wakeupflag < 6)
    {
        if (oldwakeupflag != wakeupflag)
        {
            oldwakeupflag = wakeupflag;
            /* Match even occurred, set next match for a second later */
            rtc_ioctl(rtcdev, RTC_SET_MATCH,
                (rtc_ioctl(rtcdev, RTC_GET_STATUS, RTC_CURRENT) + 1));

            if (ledstate == TRUE)
            {
                /* Toggle state */
                ledstate = FALSE;
            }
            else
            {
                ledstate = TRUE;
            }

            /* Set new state of LED */
            cpld_enable_led(ledstate);
        }
    }

    /* Close RTC */
    rtc_close(rtcdev);

    /* Disable RTC match interrupt in the interrupt controller */
    vic_int_enable(VIC_RTCMINTR, FALSE);

    /* Disable ARM core IRQ interrupts */
    disable_fiq();

    return 1;
}

#ifndef __GNUC__
/* With ARM and GHS toolsets, the entry point is main() - this will
   allow the linker to generate wrapper code to setup stacks, allocate
   heap area, and initialize and copy code and data segments. For GNU
   toolsets, the entry point is through __start() in the crt0_gnu.asm
   file, and that startup code will setup stacks and data */
int main(void)
{
    return c_entry();
}
#endif

⌨️ 快捷键说明

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