#include <cdefBF518.h>
#include <sys\exception.h>
#include <cdefBF51x_base.h>
#include <blackfin.h>
#include <bfrom.h>
#include <string.h>
#include <stdio.h>
void Set_PLL(int pmsel,int pssel)
{
int new_PLL_CTL;
*pPLL_DIV = pssel;
asm("ssync;");
new_PLL_CTL = (pmsel & 0x3f) << 9;
*pSIC_IWR |= 0xffffffff;
if (new_PLL_CTL != *pPLL_CTL)
{
*pPLL_CTL = new_PLL_CTL;
asm("ssync;");
asm("idle;");
}
}
EX_INTERRUPT_HANDLER(RTC_ISR) //标识符为RTC_ISR 的中断函数
{
// *pTIMER_STATUS = 0x0001; //清除定时器中断标志
*pRTC_ISTAT = 0;
int times = *pRTC_STAT;
int day = (times>>17)&0x7fff;
int hours = (times>>12)&0x1f;
int min = (times>>6)&0x3f;
int sec = times &0x3f;
printf("time is %d day %d:%d:%d\n",day,hours,min,sec);
}
void init_Interrupts(void)
{
*pSIC_IAR0 = 0xffffffff;
*pSIC_IAR1 = 0xf1ffffff; //配置real time clock中断等级数据为8-7
*pSIC_IAR2 = 0xffffffff;
*pSIC_IAR3 = 0xffffffff;
*pSIC_IAR4 = 0xffffffff;
*pSIC_IAR5 = 0xffffffff;
*pSIC_IAR6 = 0xffffffff;
*pSIC_IAR7 = 0xffffffff;
register_handler(ik_ivg8, RTC_ISR); //注册中断等级为8,标识符为RTC_ISR
*pSIC_IMASK0 = 0x00004000; //开启中断
*pSIC_IMASK1 = 0x00000000;
}
void init_RTC(int day,int hour,int minute,int second) //REAL TIME CLOCK
{
*pRTC_PREN = 1;
*pRTC_ISTAT = 0;
*pRTC_ICTL = 0x807f;
*pRTC_STAT = (day<<17)|(hour<<12)|(minute<<6)|(second);
}
void main(void)
{
int times,day,hours,min,sec ;
Set_PLL(16,4);
init_RTC(29,10,47,50);
while(1)
{
/*times = *pRTC_STAT;
day = (times>>17)&0x7fff;
hours = (times>>12)&0x1f;
min = (times>>6)&0x3f;
sec = times &0x3f;
printf("time is %d day %d:%d:%d\n",day,hours,min,sec);
*/
}
}