Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (3.38 KB)

1
/******** * This file is part of Tooltron.
2
 *
3
 * Tooltron is free software: you can redistribute it and/or modify
4
 * it under the terms of the Lesser GNU General Public License as published by
5
 * the Free Software Foundation, either version 3 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * Tooltron is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * Lesser GNU General Public License for more details.
12
 * You should have received a copy of the Lesser GNU General Public License
13
 * along with Tooltron.  If not, see <http://www.gnu.org/licenses/>.
14
 *
15
 * Copyright 2009 Kevin Woo <kwoo@2ndt.com>
16
 *
17
 ********/
18
/** @file main.c
19
 *  @brief Contains the main function for the toolbox code.
20
 *
21
 *  @author Suresh Nidhiry (snidhiry), Kevin Woo (kwoo)
22
 */
23

    
24
//Includes
25
#include <avr/io.h>
26
#include <avr/interrupt.h>
27
#include <stdint.h>
28
#include <util/delay.h>
29
#include <avr/wdt.h>
30
#include <avr/eeprom.h>
31
#include "../../common/toolbox_pindefs.h"
32
#include "../../common/tooltron.h"
33
#include "../../toolbox/jumptable.h"
34

    
35
/* #define RELAY       _BV(PORTD4) */
36
/* #define VAC_SENSE   _BV(PIND3) */
37
/* #define BUT_RED     _BV(PINB4)#define BUT_BLACK   _BV(PINB3) */
38
/* #define LED_GREEN   _BV(PORTB2) */
39
/* #define LED_YELLOW  _BV(PORTB1) */
40
/* #define LED_RED     _BV(PORTB0) */
41
/* #define ON      0x01 */
42
/* #define OFF     0x00 */
43

    
44
/***** change ADDR ****/
45
#define ADDR 14
46
#define DELIM '^'
47
#define SERVER 1
48
#define TURNON 'O'
49

    
50
/***
51
 * TWAIT - minutes to wait before green button is pressed to kill power
52
 * TWARN - minutes until warning (blink yellow, allow more time with green button)
53
 * TMAX  - minutes until power is killed (unless tool is on)
54
 */
55
#define TWAIT   1
56
#define TWARN   1
57
#define TMAX    2
58

    
59

    
60
uint8_t sec;
61
uint8_t min;
62

    
63
typedef enum {
64
    sd,     // start delimitor
65
    src,    // src
66
    dest,   // destination
67
    data,   // data
68
    cs,     // checksum
69
    ack,    // send ack
70
    pwron,  // poweron
71
    idiot,  // user tried to hit green with the machine switch on
72
    toolon, // tool on
73
    warn,   // time warning
74
    off     // tool off
75
} state_t;
76

    
77
void init_pins(void) {
78
    DDRB = 0x00;
79
    DDRB = _BV(DDB0) | _BV(DDB1) | _BV(DDB2) | _BV(DDB5);
80
    DDRD = _BV(DDB4);
81
    PORTB = 0x00;
82
}
83

    
84
void toggle_led(uint8_t which, uint8_t state) {
85
    if (state == ON) {
86
        PORTB &= ~which;
87
    } else {
88
        PORTB |= which;
89
    }
90
}
91

    
92
void (*bootloader)(void) = 0x400/2;
93

    
94
void reset(void) {
95
    wdt_enable(WDTO_15MS);
96
    //bootloader();
97
}
98

    
99
int main(int argc, char **argv) {
100

    
101
    uint8_t mbuf[PROGD_PACKET_SIZE];    // ignored
102
    uint8_t len;
103

    
104
        /***** Start Start-up Sequence *****/
105
    init_pins();                //Set pin directions
106
        //        init_uart(51);                //Set registers for uart
107
        /***** End Start-up Sequence *****/
108

    
109
    uint8_t a,b,c, correct;
110

    
111
    eeprom_write_byte(EEPROM_ADDR1, ADDR);
112
    eeprom_write_byte(EEPROM_ADDR2, ADDR);
113
    eeprom_write_byte(EEPROM_ADDR3, ADDR);
114
    
115
    PORTB = 0x7;
116

    
117
    a = eeprom_read_byte(EEPROM_ADDR1);
118
    b = eeprom_read_byte(EEPROM_ADDR2);
119
    c = eeprom_read_byte(EEPROM_ADDR3);
120

    
121
    correct = (a == ADDR) + (b == ADDR) + (c == ADDR);
122

    
123
    if ( correct == 3 ) {
124
      PORTB |= LED_GREEN;
125
    }
126
    else if(correct == 0){
127
      PORTB |= LED_RED;
128
    }
129
    else {
130
      PORTB |= LED_YELLOW;
131
    }
132

    
133

    
134
    while(1) {
135
      parse_packet(mbuf, &len, ADDR);
136
    }
137

    
138
    return 0;
139
}