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

📄 periodicstopwatch.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



/* maintain a static stopwatch event counter that is initialized to 0 */
volatile static u32  SWEventCounter = 0;

/* Use a flag to signal the occurence of a stopwatch event */
volatile static u32 StopwatchCompleteFlag;


                            
/* **************************************************************
 *
 * Below is a structure for passing the 'Value' field to the 
 * adi_rtc_InstallCallback function when installing a stopwatch 
 * timeout callback. This field can be anything. In this example
 * the structure holds a stopwatch counter and a periodic flag.
 * If the periodic flag is set, the callback will be installed 
 * which places the counter value back into the RTC_SWCNT register 
 * so the callback will recurr.  Otherwise, a callback is installed 
 * which occurs only once. 
 * 
 * NOTE: the "tm" structure, defined in 'time.h' is used for 
 * passing the pOptionalInfo field to the adi_rtc_InstallCallback 
 * function when installing an alarm callback (daily, or once-only)  
 *
 * **************************************************************/

/* This structure is used to pass the stopwatch callback info */
  
 /* structure  used to pass the stopwatch counter info */
typedef struct 
{
    u32 PeriodicFlag;   /* whether the callback shall be periodic or one-shot */
    u32 SecondsCounter; /* value to place in RTC_SWCNT when installing callback */
    u32 NumRepetitions; 
} STOPWATCH_INFO;


/*  Callback function */

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

    STOPWATCH_INFO CountdownStruct = *(STOPWATCH_INFO*)ClientHandle;
    
    switch ( (u32)Event ) 
    {
    	/* one second periodic interrupt */    	
    	case 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:        
        {
            /* increment the stopwatch event counter */
            SWEventCounter++;
        	
            /* use the fields of the data structure to see whether we are done */
            /* if it's a one-shot ...*/
            if ( ( CountdownStruct.PeriodicFlag == 0 )  

        	 /* or if it's periodic... */
            || ( (  CountdownStruct.PeriodicFlag == 1 )

            /* but the stopwatch event counter reached the number of repetitions  */ 
            && ( SWEventCounter == CountdownStruct.NumRepetitions ) 

       	       /* (NOTE: Make sure NumRepetitions is not 0, because that means to */
       	       /* repeat forever and at this point the counter could have wrapped */
       	       /* around to zero, but we don't want to stop */
        	   && (CountdownStruct.NumRepetitions != 0 ) ) ) 
        	        
            {
            	adi_rtc_RemoveCallback( ADI_RTC_EVENT_STOPWATCH );
            	StopwatchCompleteFlag = 1;
            	SWEventCounter = 0;              	
            }       	           
            else  
            {
       		/* the else condition means it is periodic and either the repetitions */
       		/* are unlimited or the count has not yet reached number of repetitions */   
                /* so re-enable the event */
                adi_rtc_ResetStopwatch(  CountdownStruct.SecondsCounter );
            }
            /* done */
            break;
        }
        
        /*  time of day, daily alarm  */
        case ADI_RTC_EVENT_EACH_DAY_ALARM:          
            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;

    u32 ResponseCount;

    void *critical_region_arg = 0;

 
     
    int NumSeconds; 
    int* pNumSeconds;   
    
  
    /* to pass information when installing stopwatch callback */
    STOPWATCH_INFO StopwatchCallbackInfo;
    
    /* and a pointer to it */
    STOPWATCH_INFO* pStopwatchCallbackInfo;   
 
  
    /* 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;
    }
	
    /* zero this flag */
    StopwatchCompleteFlag = 0;	
 
 	
    /* initialize the static stopwatch event counter  */
    SWEventCounter = 0;    
    
    /* set up the fields of the ClientHandle structure */
    /* calback will reset stopwatch to time out after five seconds */
    StopwatchCallbackInfo.SecondsCounter = 5;
	
    /* stopwatch will happen periodically */
    StopwatchCallbackInfo.PeriodicFlag = 1;
	
    /* stopwatch will be reset three times */
    StopwatchCallbackInfo.NumRepetitions = 3;
	
    pStopwatchCallbackInfo = &StopwatchCallbackInfo;
    
    /* the first stopwatch timeout will be the same as subsequent timeouts */ 
    NumSeconds = StopwatchCallbackInfo.SecondsCounter; 	
	
    /* install the stopwatch callback */
    adi_rtc_InstallCallback(ADI_RTC_EVENT_STOPWATCH, (void*)pStopwatchCallbackInfo, NULL, RTCCallback, (void*)NumSeconds );

	
    /* wait for the stopwatch event to occur after 5 seconds & repeat */
    /* three times.  Will happen in 20 seconds */
    while( StopwatchCompleteFlag == 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 + -