Added the previously forgotten arduino reset script.
[cerebrum.git] / common / main.c
blob875c708dde4d9187a61476e0e4f10fadb9331525
1 /*
2 Copyright (C) 2012 jaseg <s@jaseg.de>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 3 as published by the Free Software Foundation.
7 */
9 #ifdef __AVR__
10 #include <avr/interrupt.h>
11 #include <avr/io.h>
12 #endif
14 #include <comm.h>
15 #include <autocode.h>
16 #include <config.h>
17 #include <uart.h>
18 #ifdef __TEST__
19 #include "comm_handle.h"
20 #endif
22 void init(void);
23 void loop(void);
25 int main(void){
26 init();
27 #ifdef __TEST__
28 //debug stuff
29 int16_t v;
30 while((v = getchar()) >= 0){
31 comm_handle(v);
33 #else
34 for(;;) auto_loop();
35 #endif
38 void init(){
40 #if defined(__MSPGCC__)
41 WDTCTL = WDTPW | WDTHOLD; //Disable WDT
43 //oscillator control
44 DCOCTL |= DCO1 | DCO0;
45 BCSCTL1 |= RSEL3 | RSEL2 | RSEL0;
47 #ifndef __MSP430G2553__
48 #error No port setup for that part. Please fix this!
49 #endif//__MSP430G2553__
50 //UART io setup for the msp430g2553 (RX: P1.1, TX: P1.2)
51 P1SEL |= 0x03;
52 P1SEL2 |= 0x03;
53 #elif defined(__AVR__)//__MSPGCC__
54 uart_init(UART_BAUD_SELECT_DOUBLE_SPEED(9600, F_CPU));
55 #endif//AVR
57 init_auto();
59 //enable interrupts
60 #if defined(__AVR__)
61 sei();
62 #elif defined(__MSPGCC__)//__AVR__
63 _BIS_SR(GIE);
64 #endif//__MSPGCC__