static void prvSetupTimerInterrupt( void ) { WDG_InitTypeDef xWdg; unsigned short a; unsigned long n = configCPU_PERIPH_HZ / configTICK_RATE_HZ, b; /* Configure the watchdog as a free running timer that generates a periodic interrupt. */ SCU_APBPeriphClockConfig( __WDG, ENABLE ); WDG_DeInit(); WDG_StructInit(&xWdg); prvFindFactors( n, &a, &b ); xWdg.WDG_Prescaler = a - 1; xWdg.WDG_Preload = b - 1; WDG_Init( &xWdg ); WDG_ITConfig(ENABLE); /* Configure the VIC for the WDG interrupt. */ VIC_Config( WDG_ITLine, VIC_IRQ, 10 ); VIC_ITCmd( WDG_ITLine, ENABLE ); /* Install the default handlers for both VIC's. */ VIC0->DVAR = ( unsigned long ) prvDefaultHandler; VIC1->DVAR = ( unsigned long ) prvDefaultHandler; WDG_Cmd(ENABLE); }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main() { #ifdef DEBUG debug(); #endif SCU_MCLKSourceConfig(SCU_MCLK_OSC); /*Use OSC as the default clock source*/ SCU_PCLKDivisorConfig(SCU_PCLK_Div1); /* ARM Peripheral bus clokdivisor = 1*/ WDG_InitTypeDef WDG_InitStructure; GPIO_InitTypeDef GPIO3_InitStruct; SCU_APBPeriphClockConfig(__GPIO3, ENABLE);/* Enable the clock for GPIO3*/ GPIO_DeInit(GPIO3);/* GPIO3 default configuration : Reset configuration*/ /* Configure the GPIO3 */ GPIO3_InitStruct.GPIO_Pin= GPIO_Pin_2; /* Choose the pin "P3.2 port"*/ GPIO3_InitStruct.GPIO_Direction=GPIO_PinOutput; /* Choose the P3.2 port Direction "output".*/ GPIO3_InitStruct.GPIO_Type = GPIO_Type_PushPull ; GPIO3_InitStruct.GPIO_Alternate=GPIO_OutputAlt1; GPIO_Init(GPIO3,&GPIO3_InitStruct); /*GPIO3 initialization with the previous chosen parameters.*/ GPIO_WriteBit(GPIO3, GPIO_Pin_2, Bit_RESET); /* Reset the P3.2 port " on STR912-SK-IAR Board, LED3 is on "*/ SCU_APBPeriphClockConfig(__WDG, ENABLE); /* Enable the clock for the WDG peripheral*/ WDG_DeInit();/* WDG default configuration : Reset configuration*/ /* Configure the WDG to generate a system reset signal each 1s */ WDG_InitStructure.WDG_Mode = WDG_Mode_Wdg; WDG_InitStructure.WDG_Preload = 0x7d; WDG_InitStructure.WDG_Prescaler = 0xFF; WDG_InitStructure.WDG_ClockSource=WDG_ClockSource_Rtc; /* using the 32khz RTC clock as clock source*/ WDG_Init(&WDG_InitStructure); /* WDG initialization with the previous chosen parameters.*/ while(1) { GPIO_WriteBit(GPIO3, GPIO_Pin_2, Bit_SET); } }