Statistics
| Revision:

root / trunk / programmer / test / main.c @ 175

History | View | Annotate | Download (2.8 KB)

1
/********
2
 * This file is part of Tooltron.
3
 *
4
 * Tooltron is free software: you can redistribute it and/or modify
5
 * it under the terms of the Lesser GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * Tooltron is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * Lesser GNU General Public License for more details.
13
 * You should have received a copy of the Lesser GNU General Public License
14
 * along with Tooltron.  If not, see <http://www.gnu.org/licenses/>.
15
 *
16
 * Copyright 2009 Kevin Woo <kwoo@2ndt.com>
17
 *
18
 ********/
19
/** @file main.c
20
 *  @brief Contains the main function for the toolbox code.
21
 *
22
 *  @author Suresh Nidhiry (snidhiry), Kevin Woo (kwoo)
23
 */
24
25
//Includes
26
#include <avr/io.h>
27
#include <avr/interrupt.h>
28
#include <stdint.h>
29
#include <util/delay.h>
30
#include <avr/wdt.h>
31
32
#define RELAY       _BV(PORTD4)
33
#define VAC_SENSE   _BV(PIND3)
34
#define BUT_RED     _BV(PINB4)
35
#define BUT_BLACK   _BV(PINB3)
36
#define LED_GREEN   _BV(PORTB2)
37
#define LED_YELLOW  _BV(PORTB1)
38
#define LED_RED     _BV(PORTB0)
39
#define ON      0x01
40
#define OFF     0x00
41
42
/***** change ADDR ****/
43
#define ADDR 18
44
#define DELIM '^'
45
#define SERVER 1
46
#define TURNON 'O'
47
48
/***
49
 * TWAIT - minutes to wait before green button is pressed to kill power
50
 * TWARN - minutes until warning (blink yellow, allow more time with green button)
51
 * TMAX  - minutes until power is killed (unless tool is on)
52
 */
53
#define TWAIT   1
54
#define TWARN   1
55
#define TMAX    2
56
57
uint8_t sec;
58
uint8_t min;
59
60
typedef enum {
61
    sd,     // start delimitor
62
    src,    // src
63
    dest,   // destination
64
    data,   // data
65
    cs,     // checksum
66
    ack,    // send ack
67
    pwron,  // poweron
68
    idiot,  // user tried to hit green with the machine switch on
69
    toolon, // tool on
70
    warn,   // time warning
71
    off     // tool off
72
} state_t;
73
74
void init_pins(void) {
75
    DDRB = 0x00;
76
    DDRB = _BV(DDB0) | _BV(DDB1) | _BV(DDB2) | _BV(DDB5);
77
    DDRD = _BV(DDB4);
78
    PORTB = 0x00;
79
}
80
81
void toggle_led(uint8_t which, uint8_t state) {
82
    if (state == ON) {
83
        PORTB &= ~which;
84
    } else {
85
        PORTB |= which;
86
    }
87
}
88
89
void (*bootloader)(void) = 0x400/2;
90
91
void reset(void) {
92
    wdt_enable(WDTO_15MS);
93
    //bootloader();
94
}
95
96
int main(int argc, char **argv) {
97
    state_t state = sd;
98
    uint8_t packet[3];
99
    uint8_t ms_timer=0;
100
101
        /***** Start Start-up Sequence *****/
102
        init_pins();                //Set pin directions
103
        //        init_uart(51);                //Set registers for uart
104
        /***** End Start-up Sequence *****/
105
106
    uint8_t r;
107
    
108
    PORTB &= ~_BV(PORTB0);
109
110
    _delay_ms(1000);
111
    PORTB |= _BV(PORTB0);
112
    _delay_ms(1000);
113
    reset();
114
115
    while(1) {
116
    }
117
118
    return 0;
119
}