ARM7 based quadrocopter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
2.2KB

  1. /***************************************************************************
  2. * sam7fc - Real Time Clock Calibration *
  3. * *
  4. * Copyright (C) 02/2008 by Olaf Rempel *
  5. * razzor@kopf-tisch.de *
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; version 2 of the License *
  10. * *
  11. * This program is distributed in the hope that it will be useful, *
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  14. * GNU General Public License for more details. *
  15. * *
  16. * You should have received a copy of the GNU General Public License *
  17. * along with this program; if not, write to the *
  18. * Free Software Foundation, Inc., *
  19. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  20. ***************************************************************************/
  21. #include <stdio.h>
  22. #include "AT91SAM7S256.h"
  23. #include "at91_sysc.h"
  24. #include "board.h"
  25. static void rtt_isr(uint32_t status)
  26. {
  27. *AT91C_RTTC_RTAR = *AT91C_RTTC_RTVR +1;
  28. }
  29. void at91_rttc_test_init(void)
  30. {
  31. /* calculate SLOWCK from MAINCK and measured MAINF */
  32. uint32_t prescaler = MAINCK * 16 / (*AT91C_CKGR_MCFR & AT91C_CKGR_MAINF);
  33. sysc_register_isr(AT91_SYSIRQ_RTT, &rtt_isr);
  34. /*
  35. * AT91C_RTTC_RTTINCIEN doesn't work
  36. * use AT91C_RTTC_ALMIEN and increment RTAR in isr
  37. */
  38. *AT91C_RTTC_RTAR = *AT91C_RTTC_RTVR +1;
  39. *AT91C_RTTC_RTMR = (AT91C_RTTC_RTPRES & prescaler) |
  40. AT91C_RTTC_ALMIEN |
  41. AT91C_RTTC_RTTRST;
  42. printf("rttc running at %ld Hz\n\r", prescaler);
  43. }