/*************************************************************************** * sam7fc - Real Time Clock Calibration * * * * Copyright (C) 02/2008 by Olaf Rempel * * razzor@kopf-tisch.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; version 2 of the License * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include "AT91SAM7S256.h" #include "at91_sysc.h" #include "board.h" static void rtt_isr(uint32_t status) { *AT91C_RTTC_RTAR = *AT91C_RTTC_RTVR +1; } 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); }