root / trunk / programmer / test / main.c @ 213
History | View | Annotate | Download (3.05 KB)
1 | 160 | bneuman | /********
|
---|---|---|---|
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 | 175 | kwoo | #include <avr/wdt.h> |
31 | 201 | kwoo | #include <avr/eeprom.h> |
32 | 160 | bneuman | |
33 | #define RELAY _BV(PORTD4)
|
||
34 | #define VAC_SENSE _BV(PIND3)
|
||
35 | 213 | bneuman | #define BUT_RED _BV(PINB4)#define BUT_BLACK _BV(PINB3) |
36 | 160 | bneuman | #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 | 201 | kwoo | |
58 | 160 | bneuman | uint8_t sec; |
59 | uint8_t min; |
||
60 | |||
61 | typedef enum { |
||
62 | sd, // start delimitor
|
||
63 | src, // src
|
||
64 | dest, // destination
|
||
65 | data, // data
|
||
66 | cs, // checksum
|
||
67 | ack, // send ack
|
||
68 | pwron, // poweron
|
||
69 | idiot, // user tried to hit green with the machine switch on
|
||
70 | toolon, // tool on
|
||
71 | warn, // time warning
|
||
72 | off // tool off
|
||
73 | } state_t; |
||
74 | |||
75 | void init_pins(void) { |
||
76 | DDRB = 0x00;
|
||
77 | DDRB = _BV(DDB0) | _BV(DDB1) | _BV(DDB2) | _BV(DDB5); |
||
78 | DDRD = _BV(DDB4); |
||
79 | PORTB = 0x00;
|
||
80 | } |
||
81 | |||
82 | void toggle_led(uint8_t which, uint8_t state) {
|
||
83 | if (state == ON) {
|
||
84 | PORTB &= ~which; |
||
85 | } else {
|
||
86 | PORTB |= which; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | 175 | kwoo | void (*bootloader)(void) = 0x400/2; |
91 | 160 | bneuman | |
92 | 175 | kwoo | void reset(void) { |
93 | wdt_enable(WDTO_15MS); |
||
94 | //bootloader();
|
||
95 | } |
||
96 | |||
97 | 160 | bneuman | int main(int argc, char **argv) { |
98 | state_t state = sd; |
||
99 | uint8_t packet[3];
|
||
100 | uint8_t ms_timer=0;
|
||
101 | |||
102 | 201 | kwoo | uint8_t myaddr; |
103 | 160 | bneuman | /***** Start Start-up Sequence *****/
|
104 | init_pins(); //Set pin directions
|
||
105 | // init_uart(51); //Set registers for uart
|
||
106 | /***** End Start-up Sequence *****/
|
||
107 | |||
108 | uint8_t r; |
||
109 | |||
110 | 213 | bneuman | //eeprom_write_byte(1, 12);
|
111 | 175 | kwoo | |
112 | 201 | kwoo | PORTB = 0x7;
|
113 | |||
114 | 213 | bneuman | myaddr = eeprom_read_byte(1);
|
115 | if (myaddr == 11) { |
||
116 | PORTB = 0;
|
||
117 | while(1); |
||
118 | } |
||
119 | _delay_ms(1000);
|
||
120 | PORTB |= _BV(PORTB0); |
||
121 | _delay_ms(1000);
|
||
122 | reset(); |
||
123 | 201 | kwoo | |
124 | 160 | bneuman | while(1) { |
125 | 213 | bneuman | _delay_ms(1000);
|
126 | 201 | kwoo | PORTB |= _BV(PORTB0); |
127 | _delay_ms(1000);
|
||
128 | PORTB &= ~_BV(PORTB0); |
||
129 | 160 | bneuman | } |
130 | |||
131 | return 0; |
||
132 | } |