alarm.c

来自「S3C24A0的完整BSP包,对开发此芯片的开发者很有用.」· C语言 代码 · 共 127 行

C
127
字号
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  Module: rtc.c
//
//  Real-time clock (RTC) routines for the Samsung S3C24A0 processor
//
#include <windows.h>
#include <ceddk.h>
#include <nkintr.h>
#include <oal.h>
#include <s3c24A0.h>

//------------------------------------------------------------------------------
// Defines 
#define TO_BCD(n)       ((((n) / 10) << 4) | ((n) % 10))
#define RTC_YEAR_DATUM  1980
#define RETAIL_ON		1
//------------------------------------------------------------------------------
//
//  Function:  OALIoCtlHalInitRTC
//
//  This function is called by WinCE OS to initialize the time after boot.
//  Input buffer contains SYSTEMTIME structure with default time value.
//  If hardware has persistent real time clock it will ignore this value
//  (or all call).
//
BOOL OALIoCtlHalInitRTC(
    UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer,
    UINT32 outSize, UINT32 *pOutSize
) {
    BOOL rc = FALSE;
    SYSTEMTIME *pTime = (SYSTEMTIME*)pInpBuffer;

    RETAILMSG(RETAIL_ON, (L"+OALIoCtlHalInitRTC(...)\r\n"));

    // Validate inputs
    if (pInpBuffer == NULL || inpSize < sizeof(SYSTEMTIME)) 
	{
        NKSetLastError(ERROR_INVALID_PARAMETER);
		RETAILMSG(1, (TEXT("**** Input invalid \r\n")));
        OALMSG(OAL_ERROR, (
            L"ERROR: OALIoCtlHalInitRTC: Invalid parameter\r\n"
        ));
        goto cleanUp;
    }

    // Add static mapping for RTC alarm
	OALIntrStaticTranslate(SYSINTR_RTC_ALARM, IRQ_RTC);
	
//	RETAILMSG(1, (TEXT("**** pTime is \r\n")));
    // Set time
    rc = OEMSetRealTime(pTime);
    
cleanUp:
    RETAILMSG(RETAIL_ON, (L"-OALIoCtlHalInitRTC(rc = %d)\r\n", rc));
    return rc;
}

//------------------------------------------------------------------------------
//
//  Function:  OEMSetAlarmTime
//
//  Set the RTC alarm time.
//
BOOL OEMSetAlarmTime(SYSTEMTIME *pTime)
{
    BOOL rc = FALSE;
    volatile S3C24A0_RTC_REG *pRTCReg;
	volatile S3C24A0_INTR_REG *pINTReg;
	UINT32 irq;

    OALMSG(OAL_RTC&&OAL_FUNC, (
        L"+OEMSetAlarmTime(%d/%d/%d %d:%d:%d.%03d)\r\n", 
        pTime->wMonth, pTime->wDay, pTime->wYear, pTime->wHour, pTime->wMinute,
        pTime->wSecond, pTime->wMilliseconds
    ));

    if (pTime == NULL) goto cleanUp;
    
    // Get uncached virtual address
    pRTCReg = (S3C24A0_RTC_REG *)OALPAtoVA(S3C24A0_BASE_REG_PA_RTC, FALSE);
    pINTReg = (S3C24A0_INTR_REG *)OALPAtoVA(S3C24A0_BASE_REG_PA_INTR, FALSE);
	
    // Enable RTC control
    pRTCReg->RTCCON = 0x1;

    pRTCReg->ALMSEC =  TO_BCD(pTime->wSecond);
    pRTCReg->ALMMIN =  TO_BCD(pTime->wMinute);
    pRTCReg->ALMHOUR = TO_BCD(pTime->wHour);
    pRTCReg->ALMDAY = TO_BCD(pTime->wDay);
    pRTCReg->ALMMON =  TO_BCD(pTime->wMonth);
    pRTCReg->ALMYEAR = TO_BCD(pTime->wYear % 100);
   
    // Enable the RTC alarm interrupt
    pRTCReg->RTCALM = 0x7F;
 
    // Disable RTC control.
    pRTCReg->RTCCON = 0x1;

    // Enable/clear RTC interrupt
	irq = IRQ_RTC;
	OALIntrDoneIrqs(1, &irq);
	pINTReg->SRCPND  =  BIT_RTC;					/* RTC Alarm Interrupt Clear	*/
	pINTReg->INTPND  =  BIT_RTC;
	pINTReg->INTMSK &= ~BIT_RTC;					/* RTC Alarm Enable				*/


    // Done
    rc = TRUE;
    
cleanUp:
    OALMSG(OAL_RTC&&OAL_FUNC, (L"-OEMSetAlarmTime(rc = %d)\r\n", rc));
    return rc;
}

//------------------------------------------------------------------------------

⌨️ 快捷键说明

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