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

📄 eachdayalarm.c

📁 ADI公司blackfin DSP开发板BF533 EZ-KIT LITE附带的全部原代码
💻 C
字号:
/* system service include file */
#include <services/services.h>

/* real time clock service include file */
#include <services/rtc/adi_rtc.h>

/* system time include file */
#include <time.h>

/* initialization 'sizings' */
#include "adi_ssl_init.h"

/**************************************************************

 Below are masks that are OR's into the final result, to 
 determine what specific things may have failed.
 
***************************************************************/
 
#define ADI_TEST_SUCCESSFUL           0
#define ADI_TEST_SSL_INIT_FAILED      0x01
#define ADI_TEST_SET_DATETIME_FAILED  0x04
#define ADI_TEST_GET_DATETIME_FAILED  0x08
#define ADI_TEST_DATETIME_WRONG       0x10
#define ADI_TEST_SSL_TERMINATE_FAILED 0x40


volatile static u32 EachDayAlarmCompleteFlag, SecondsCompleteFlag;


/*  Callback function */

	
static void RTCCallback(void *ClientHandle, u32  Event, void *pArg)	
{
    
    switch ( (u32)Event ) 
    {

    	/* one second periodic interrupt */    	
    	case ADI_RTC_EVENT_SECONDS:  
    	{
           SecondsCompleteFlag = 1;
           adi_rtc_RemoveCallback(ADI_RTC_EVENT_SECONDS );           	        
           break;
    	}  
         /* one minute periodic interrupt */  
        case ADI_RTC_EVENT_MINUTES :                 
           break;
           
        /*  hourly periodic interrupt */
        case ADI_RTC_EVENT_HOURS:            
            break;
               
        /* daily periodic interrupt */
        case ADI_RTC_EVENT_DAYS:             
             break;
            
        /* stopwatch countdown timeout event */              
        case ADI_RTC_EVENT_STOPWATCH:        
            break;

        /*  time of day, daily alarm  */
        case ADI_RTC_EVENT_EACH_DAY_ALARM: 
        {
/* Remove the callback when you no longer want the alarm to occur each day */        	
/*         	adi_rtc_RemoveCallback( ADI_RTC_EVENT_EACH_DAY_ALARM ); */
        	EachDayAlarmCompleteFlag = 1;         
            break;
        }   
        /*  day & time once only alarm  */
        case ADI_RTC_EVENT_ONCE_ALARM:          
             break;
        
         /*  pending register writes complete */
        case ADI_RTC_EVENT_WRITES_COMPLETE:  
            break;

        default:
            break;	
    }
    return;
}




/* **************************************************************
 *
 * Main Function of the Application
 *
 * **************************************************************/

main()
{	
    /* variables for storing result codes */
    u32 TmpResult, FinalResult, NumSeconds;
	
    /* argument for saving critical region data */
    void  *critical_region_arg = 0;
	
    /* "tm" structure (see 'time.h') */
    struct tm DateTime;
    
    /*  Start by assuming success. */
	    	
    FinalResult = ADI_TEST_SUCCESSFUL;
    
    /* Initialize the system services. */	
    /* Use temporary result code to check whether system services */
    /* were successfully initialized - see 'ssl_init.c' */
	
    if(( TmpResult = adi_ssl_Init() ) != 0 )
    {
         /* Add a specific error code to the final result */		
        FinalResult |= ADI_TEST_SSL_INIT_FAILED;
    }
		
    /* For the most predictable performance, synchronize the write to the 1 Hz "tick".  */

    if( FinalResult == 0 )
    {
        /* set up the fields of the date/time structure with any time */
        DateTime.tm_sec = 33;         /* 33 seconds */
        DateTime.tm_min = 22;         /* 22 minutes */
        DateTime.tm_hour = 9;         /* hour 9 */
        DateTime.tm_mday = 7;         /* day of month 7 */
        DateTime.tm_mon = 6;          /* July (tm_mon ranges = 0-11) */
        DateTime.tm_year = 2007 - 1900;   /* year 2007 */    
    
        /* zero this flag */
        SecondsCompleteFlag = 0;	
	 
        /* install a callback, that will set the flag */
        adi_rtc_InstallCallback(ADI_RTC_EVENT_SECONDS, (void*)NULL, NULL, RTCCallback, (void*)NULL );
	
	
        /* and set a breakpoint in the callback */
        while( SecondsCompleteFlag == 0 );	 


        /* set the date and time */

        /* pass a pointer to the structure */        
        if( TmpResult = adi_rtc_SetDateTime( &DateTime ) != 0)
        {
            /* Add a specific error code to the final result */	    	
            FinalResult |= ADI_TEST_SET_DATETIME_FAILED;
        }   

        /* synchronize again */

        /* zero this flag */
        SecondsCompleteFlag = 0;	
	
        /* install a callback, that will set the flag */
        adi_rtc_InstallCallback(ADI_RTC_EVENT_SECONDS, (void*)NULL, NULL, RTCCallback, (void*)NULL );
	
	
        /* and set a breakpoint in the callback */
        while( SecondsCompleteFlag == 0 );


        /* read the date and time */ 
        /* pass a pointer to the second tm structure */        
        if(( TmpResult = adi_rtc_GetDateTime( &DateTime )) != 0 )
        {
            /* Add a specific error code to the final result */	    	
            FinalResult |= ADI_TEST_GET_DATETIME_FAILED;
        }
        else
        {
            /* okay to proceed; use the current time to set an alarm */			
            /* Add 5 seconds to the current time. Alarm will happen in 5 seconds */
            NumSeconds = (DateTime.tm_sec)+5;
	
            /* if we overlapped */
            if( NumSeconds >= 60 )
            {        
                /* set seconds accordingly */
                DateTime.tm_sec = NumSeconds-60;
        
                /* use this variable temporarily to increment minutes */
               	NumSeconds = DateTime.tm_min+1;
	
               	/* if minutes wrapped around */
                if( NumSeconds >= 60 )
                {
                    /* wrap it around in the struct */
                    DateTime.tm_min = 0;
	    	
                    /* use var temporarily to add one to hours */
                    NumSeconds = DateTime.tm_hour+1;
	        
                    /* if hours wrapped around */
                    if( NumSeconds == 24 )
                    {
                        /* wrap it around in the struct */
                        DateTime.tm_hour = 0;
                    }
                /* no need to check for midnight in this example */
                }
            }
            else
            {
                /* no overlap, just put the incremented value in the time struct */
    	        DateTime.tm_sec = NumSeconds;
            }
        }
    }        
 
	
    /* zero the flag */
    EachDayAlarmCompleteFlag = 0;
	
	
    /* install a once alarm to happen in three seconds */
    adi_rtc_InstallCallback(ADI_RTC_EVENT_EACH_DAY_ALARM, (void*)NULL, NULL, RTCCallback, (void*)&DateTime );
	

    /* callback removes the callback */
    while( EachDayAlarmCompleteFlag == 0 );
	

    /* Terminate the system services */
    if(( TmpResult = adi_ssl_Terminate()) != 0 )
    {
        /* Add a specific error code to the final result */  
    	FinalResult |= ADI_TEST_SSL_TERMINATE_FAILED;
    }
   
    /* Here, examine the value of "FinalResult" and see the definitions at
       the beginning of this file which describe result, 0 means no errors. */
    while( 1 )
    {
    	TmpResult = FinalResult ;
    }
}

⌨️ 快捷键说明

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