root / trunk / programmer / test / main.c @ 210
History | View | Annotate | Download (3.08 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 |
#include <avr/eeprom.h> |
32 |
|
33 |
#define RELAY _BV(PORTD4)
|
34 |
#define VAC_SENSE _BV(PIND3)
|
35 |
#define BUT_RED _BV(PINB4)
|
36 |
#define BUT_BLACK _BV(PINB3)
|
37 |
#define LED_GREEN _BV(PORTB2)
|
38 |
#define LED_YELLOW _BV(PORTB1)
|
39 |
#define LED_RED _BV(PORTB0)
|
40 |
#define ON 0x01 |
41 |
#define OFF 0x00 |
42 |
|
43 |
/***** change ADDR ****/
|
44 |
#define ADDR 18 |
45 |
#define DELIM '^' |
46 |
#define SERVER 1 |
47 |
#define TURNON 'O' |
48 |
|
49 |
/***
|
50 |
* TWAIT - minutes to wait before green button is pressed to kill power
|
51 |
* TWARN - minutes until warning (blink yellow, allow more time with green button)
|
52 |
* TMAX - minutes until power is killed (unless tool is on)
|
53 |
*/
|
54 |
#define TWAIT 1 |
55 |
#define TWARN 1 |
56 |
#define TMAX 2 |
57 |
|
58 |
|
59 |
uint8_t sec; |
60 |
uint8_t min; |
61 |
|
62 |
typedef enum { |
63 |
sd, // start delimitor
|
64 |
src, // src
|
65 |
dest, // destination
|
66 |
data, // data
|
67 |
cs, // checksum
|
68 |
ack, // send ack
|
69 |
pwron, // poweron
|
70 |
idiot, // user tried to hit green with the machine switch on
|
71 |
toolon, // tool on
|
72 |
warn, // time warning
|
73 |
off // tool off
|
74 |
} state_t; |
75 |
|
76 |
void init_pins(void) { |
77 |
DDRB = 0x00;
|
78 |
DDRB = _BV(DDB0) | _BV(DDB1) | _BV(DDB2) | _BV(DDB5); |
79 |
DDRD = _BV(DDB4); |
80 |
PORTB = 0x00;
|
81 |
} |
82 |
|
83 |
void toggle_led(uint8_t which, uint8_t state) {
|
84 |
if (state == ON) {
|
85 |
PORTB &= ~which; |
86 |
} else {
|
87 |
PORTB |= which; |
88 |
} |
89 |
} |
90 |
|
91 |
void (*bootloader)(void) = 0x400/2; |
92 |
|
93 |
void reset(void) { |
94 |
wdt_enable(WDTO_15MS); |
95 |
//bootloader();
|
96 |
} |
97 |
|
98 |
int main(int argc, char **argv) { |
99 |
state_t state = sd; |
100 |
uint8_t packet[3];
|
101 |
uint8_t ms_timer=0;
|
102 |
|
103 |
uint8_t myaddr; |
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 r; |
110 |
|
111 |
//eeprom_write_byte(1, 18);
|
112 |
|
113 |
PORTB = 0x7;
|
114 |
|
115 |
/* myaddr = eeprom_read_byte(1); */
|
116 |
/* if (myaddr == 18) { */
|
117 |
/* PORTB = 0x7; */
|
118 |
/* } */
|
119 |
/* _delay_ms(1000); */
|
120 |
/* PORTB |= _BV(PORTB0); */
|
121 |
/* _delay_ms(1000); */
|
122 |
/* reset(); */
|
123 |
|
124 |
while(1) { |
125 |
_delay_ms(1000);
|
126 |
PORTB |= _BV(PORTB0); |
127 |
_delay_ms(1000);
|
128 |
PORTB &= ~_BV(PORTB0); |
129 |
} |
130 |
|
131 |
return 0; |
132 |
} |