alarm.c

来自「RTC programming in eCos.」· C语言 代码 · 共 76 行

C
76
字号
//============================================================================
//        Include
//============================================================================

#include <stdio.h>
#include <cyg/kernel/kapi.h>
#include <cyg/io/rtc/fie702x_rtc.h>
#include "RTCSystem.h"

//============================================================================
//        Global Variables
//============================================================================

cyg_io_handle_t rtc_handle;

static int RTC_alarm = 0;

void DSR_handler (void)
{
	RTC_alarm = 1;
}

int main (void)
{	
	RTC_Time time;
	int err;	
	
	printf("RTC test\n");	
	
	/* open rtc driver
	*/
	err = cyg_io_lookup( "/dev/rtc", &rtc_handle );

	if (ENOERR != err) 
	{
		printf("Can't open '%s'\n", "/dev/rtc");
	}
	
	API_RTC_set_AlarmHandler(rtc_handle, DSR_handler);
	
	
	while (1)
	{
		API_RTC_get_Time(rtc_handle, &time);
		printf("Hour:%d Min:%d Sec:%d\n",time.hour,time.minute,time.second);
		
		time.second += 5; // after five second, the alarm will be triggered
      
		if (time.second >= 60)
		{
			time.second -= 60;
			time.minute ++;
          
			if (time.minute >= 60)
			{
				time.minute -= 60;
				time.hour ++;
			}
		}
		
		API_RTC_set_Alarm(rtc_handle, &time);
		
		while (1)
		{
			if (RTC_alarm)
			{
				printf("RTC alarm!!!\n");
				RTC_alarm = 0;
				break;
			}
		}
	}
	
	return 0;
}

⌨️ 快捷键说明

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