2 вопроса по AT91SAM7S256.
1. PIT пошёл в общем-то без проблем, но не пойму с какой частотой он прерывания генерит.
CODE
/// PIT period value in µseconds.
#define PIT_PERIOD 1000
//------------------------------------------------------------------------------
/// 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); // Запретить прерывание PIT
// Задать обработчик прерывания PIT
IRQ_ConfigureIT(AT91C_ID_SYS, AT91C_AIC_PRIOR_LOWEST, ISR_Pit);
// Разрешить прерывание PIT
IRQ_EnableIT(AT91C_ID_SYS);
PIT_EnableIT();
// Enable the pit
PIT_Enable();
} // ConfigurePit
//------------------------------------------------------------------------------
/// Handler for PIT interrupt. Increments the timestamp counter.
//------------------------------------------------------------------------------
// 250 mks, 4 kHz - 1 ms
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);
seconds ++; // increment seconds
..........
} // if
} // ISR_Pit
//------------------------------------------------------------------------------
/// Waits for the given number of milliseconds (using the timestamp generated
/// by the SAM7 microcontroller's PIT
/// \param delay Delay to wait for, in milliseconds.
//------------------------------------------------------------------------------
void delay_ms(unsigned long delay)
{
volatile unsigned int start = timestamp;
unsigned int elapsed;
do {
elapsed = timestamp;
elapsed -= start;
}
while (elapsed < delay);
}
delay_ms работает нормально, а в seconds бред собачий... Я наверное не врубился в логику его работы.
2. TC0 . Взял из иаровского примера, не работает вообще
CODE
//------------------------------------------------------------------------------
/// Configure Timer Counter 0 to generate an interrupt every 250ms.
//------------------------------------------------------------------------------
void ConfigureTc(void)
{
unsigned int div;
unsigned int tcclks;
// Enable peripheral clock
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_TC0;
// Configure TC for a 4Hz frequency and trigger on RC compare
TC_FindMckDivisor(4, BOARD_MCK, &div, &tcclks);
TC_Configure(AT91C_BASE_TC0, tcclks | AT91C_TC_CPCTRG);
AT91C_BASE_TC0->TC_RC = (BOARD_MCK / div) / 4; // timerFreq / desiredFreq
// Configure and enable interrupt on RC compare
IRQ_ConfigureIT(AT91C_ID_TC0, 0, TC0_IrqHandler);
AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;
IRQ_EnableIT(AT91C_ID_TC0);
} // ConfigureTc
//------------------------------------------------------------------------------
// Прерывание TC0
//------------------------------------------------------------------------------
void TC0_IrqHandler(void)
{
volatile unsigned int dummy;
// Clear status bit to acknowledge interrupt
dummy = AT91C_BASE_TC0->TC_SR;
// Toggle LED state
LED_Toggle(0);
} // TC0_IrqHandler
Сам по себе LED_Toggle(0); работает. Поверено в PIT.
Полный проект иара прилагаю.
Помогите, кто может пожалуйста. Спасибо.
Дисплей HD44780 работает нормально. Проблем нет
