sam7fc/main.c

107 lines
2.9 KiB
C

/***************************************************************************
* sam7fc - main loop *
* *
* Copyright (C) 01/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 <stdio.h>
#include <string.h>
#include "AT91SAM7S256.h"
#include "board.h"
#include "at91_sysc.h"
#include "at91_dbgu.h"
#include "at91_pitc.h"
#include "at91_adc.h"
#include "at91_tests.h"
#include "at91_udp.h"
#include "at91_pio.h"
#include "at91_twi.h"
#include "at91_tc1.h"
#include "memalloc.h"
#include "telemetrie.h"
extern void base_ctrl(void);
volatile static uint32_t run_ctrl;
static uint32_t base_ctrl_trigger(struct pitc_timer *timer)
{
/* trigger adc, after ~15us () result should be ready */
adc_trigger();
run_ctrl = 1;
return PITC_RESTART_TIMER;
}
static struct pitc_timer base_timer = {
.interval = 2,
.func = &base_ctrl_trigger,
};
int main(void)
{
/* LED outputs */
*AT91C_PIOA_PER = LED_GREEN | LED_ORANGE;
*AT91C_PIOA_OER = LED_GREEN | LED_ORANGE;
/* needed for dbgu */
at91_sysc_init();
at91_dbgu_init();
at91_dbgu_puts("==========================================================\n\rGood morning Dave\n\r");
/* triggers pinchange-isrs */
at91_pio_init();
/* timer */
at91_pitc_init();
at91_rttc_test_init();
/* twi */
at91_twi_init();
at91_twi_test();
/* remote control, needs twi */
at91_tc1_init();
/* usb */
at91_udp_init();
/* adc, need timer, twi */
at91_adc_init();
pitc_schedule_timer(&base_timer);
tdc_init();
printf("static alloc: %5ld bytes\n\r", static_alloc_used());
while (1) {
if (run_ctrl) {
// TODO: racy?
run_ctrl = 0;
base_ctrl();
}
tdc_check();
}
}