CODE
//------------------------------------------------------------------------------
/// Handler for PIT interrupt. Increments the timestamp counter.
//------------------------------------------------------------------------------
void ISR_Pit(void)
{
unsigned int status;
// Read the PIT status register
status = PIT_GetStatus() & AT91C_PITC_PITS;
if (status != 0) {
// 1 = The Periodic Interval timer has reached PIV since the last read of PIT_PIVR.
// Read the PIVR to acknowledge interrupt and get number of ticks
//Returns the number of occurrences of periodic intervals since the last read of PIT_PIVR.
timestamp += (PIT_GetPIVR() >> 20);
}
}
//------------------------------------------------------------------------------
/// Configure the periodic interval timer (PIT) to generate an interrupt every
/// millisecond.
//------------------------------------------------------------------------------
void ConfigurePit(void)
{
// Initialize the PIT to the desired frequency
PIT_Init(PIT_PERIOD, BOARD_MCK / 1000000);
// Configure interrupt on PIT
IRQ_DisableIT(AT91C_ID_SYS);
IRQ_ConfigureIT(AT91C_ID_SYS, AT91C_AIC_PRIOR_LOWEST, ISR_Pit);
IRQ_EnableIT(AT91C_ID_SYS);
PIT_EnableIT();
// Enable the pit
PIT_Enable();
}
//------------------------------------------------------------------------------
/// Waits for the given number of milliseconds (using the timestamp generated
/// by the SAM7 & SAM9 microcontrollers's PIT, or SAM3's microcontrollers's system tick).
/// \param delay Delay to wait for, in milliseconds.
//------------------------------------------------------------------------------
void Wait(unsigned long delay)
{
volatile unsigned int start = timestamp;
unsigned int elapsed;
do {
elapsed = timestamp;
elapsed -= start;
}
while (elapsed < delay);
}
/// Handler for PIT interrupt. Increments the timestamp counter.
//------------------------------------------------------------------------------
void ISR_Pit(void)
{
unsigned int status;
// Read the PIT status register
status = PIT_GetStatus() & AT91C_PITC_PITS;
if (status != 0) {
// 1 = The Periodic Interval timer has reached PIV since the last read of PIT_PIVR.
// Read the PIVR to acknowledge interrupt and get number of ticks
//Returns the number of occurrences of periodic intervals since the last read of PIT_PIVR.
timestamp += (PIT_GetPIVR() >> 20);
}
}
//------------------------------------------------------------------------------
/// Configure the periodic interval timer (PIT) to generate an interrupt every
/// millisecond.
//------------------------------------------------------------------------------
void ConfigurePit(void)
{
// Initialize the PIT to the desired frequency
PIT_Init(PIT_PERIOD, BOARD_MCK / 1000000);
// Configure interrupt on PIT
IRQ_DisableIT(AT91C_ID_SYS);
IRQ_ConfigureIT(AT91C_ID_SYS, AT91C_AIC_PRIOR_LOWEST, ISR_Pit);
IRQ_EnableIT(AT91C_ID_SYS);
PIT_EnableIT();
// Enable the pit
PIT_Enable();
}
//------------------------------------------------------------------------------
/// Waits for the given number of milliseconds (using the timestamp generated
/// by the SAM7 & SAM9 microcontrollers's PIT, or SAM3's microcontrollers's system tick).
/// \param delay Delay to wait for, in milliseconds.
//------------------------------------------------------------------------------
void Wait(unsigned long delay)
{
volatile unsigned int start = timestamp;
unsigned int elapsed;
do {
elapsed = timestamp;
elapsed -= start;
}
while (elapsed < delay);
}
Собственно здесь: ISR_Pit - обработчик прерывания, ConfigurePit - конфигурирование PIT и System Controller, Wait - процедура таймерной задержки.
При выполнении данного кода, а точнее при выполнении процедуры IRQ_EnableIT(AT91C_ID_SYS), контроллер "виснет", т.е. постоянно уходит в прерывание (прерывания обрабатываются) и не выполняется дальнейший код. Пробовал запускать программу в режиме отладки через jtag emulator в sram, так же пробовал грузить и запускать через SAM-BA по jtag-у в sram.
Где в данном случае подвох? Подскажите пожалуйста знающие люди.