35 lines
782 B
C
35 lines
782 B
C
|
#include <stdio.h>
|
||
|
#include "AT91SAM7S256.h"
|
||
|
#include "at91_sysc.h"
|
||
|
#include "board.h"
|
||
|
|
||
|
static void rtt_isr(uint32_t status)
|
||
|
{
|
||
|
*AT91C_RTTC_RTAR = *AT91C_RTTC_RTVR +1;
|
||
|
/*
|
||
|
static uint32_t i;
|
||
|
*AT91C_PIOA_SODR = i;
|
||
|
i = i ^ LED_ORANGE;
|
||
|
*AT91C_PIOA_CODR = i;
|
||
|
*/
|
||
|
}
|
||
|
|
||
|
void at91_rttc_test_init(void)
|
||
|
{
|
||
|
/* calculate SLOWCK from MAINCK and measured MAINF */
|
||
|
uint32_t prescaler = MAINCK * 16 / (*AT91C_CKGR_MCFR & AT91C_CKGR_MAINF);
|
||
|
|
||
|
sysc_register_isr(AT91_SYSIRQ_RTT, &rtt_isr);
|
||
|
|
||
|
/*
|
||
|
* AT91C_RTTC_RTTINCIEN doesn't work
|
||
|
* use AT91C_RTTC_ALMIEN and increment RTAR in isr
|
||
|
*/
|
||
|
*AT91C_RTTC_RTAR = *AT91C_RTTC_RTVR +1;
|
||
|
*AT91C_RTTC_RTMR = (AT91C_RTTC_RTPRES & prescaler) |
|
||
|
AT91C_RTTC_ALMIEN |
|
||
|
AT91C_RTTC_RTTRST;
|
||
|
|
||
|
printf("rttc running at %ld Hz\n\r", prescaler);
|
||
|
}
|