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.

12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /***************************************************************************
  2. * sam7fc - main loop *
  3. * *
  4. * Copyright (C) 01/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 <string.h>
  23. #include "AT91SAM7S256.h"
  24. #include "board.h"
  25. #include "at91_sysc.h"
  26. #include "at91_dbgu.h"
  27. #include "at91_pitc.h"
  28. #include "at91_adc.h"
  29. #include "at91_tests.h"
  30. #include "at91_udp.h"
  31. #include "at91_pio.h"
  32. #include "at91_twi.h"
  33. #include "at91_tc1.h"
  34. #include "memalloc.h"
  35. #include "telemetrie.h"
  36. extern void base_ctrl(void);
  37. volatile static uint32_t run_ctrl;
  38. static uint32_t base_ctrl_trigger(struct pitc_timer *timer)
  39. {
  40. /* trigger adc, after ~15us () result should be ready */
  41. adc_trigger();
  42. run_ctrl = 1;
  43. return PITC_RESTART_TIMER;
  44. }
  45. static struct pitc_timer base_timer = {
  46. .interval = 2,
  47. .func = &base_ctrl_trigger,
  48. };
  49. int main(void)
  50. {
  51. /* LED outputs */
  52. *AT91C_PIOA_PER = LED_GREEN | LED_ORANGE;
  53. *AT91C_PIOA_OER = LED_GREEN | LED_ORANGE;
  54. /* needed for dbgu */
  55. at91_sysc_init();
  56. at91_dbgu_init();
  57. at91_dbgu_puts("==========================================================\n\rGood morning Dave\n\r");
  58. /* triggers pinchange-isrs */
  59. at91_pio_init();
  60. /* timer */
  61. at91_pitc_init();
  62. at91_rttc_test_init();
  63. /* twi */
  64. at91_twi_init();
  65. at91_twi_test();
  66. /* remote control, needs twi */
  67. at91_tc1_init();
  68. /* usb */
  69. at91_udp_init();
  70. /* adc, need timer, twi */
  71. at91_adc_init();
  72. pitc_schedule_timer(&base_timer);
  73. tdc_init();
  74. printf("static alloc: %5ld bytes\n\r", static_alloc_used());
  75. while (1) {
  76. if (run_ctrl) {
  77. // TODO: racy?
  78. run_ctrl = 0;
  79. base_ctrl();
  80. }
  81. tdc_check();
  82. }
  83. }