2 #include <avr/interrupt.h>
8 #ifdef __AVR_ATmega16__
14 #error "Please add chassis power/reset-PIN information for this chip"
17 #define __CPORT(port) PORT##port
18 #define _CPORT(port) __CPORT(port)
19 #define CPORT _CPORT(CHASSISPORT)
21 #define __CDDR(port) DDR##port
22 #define _CDDR(port) __CDDR(port)
23 #define CDDR _CDDR(CHASSISPORT)
25 static volatile int power_cnt
= 0;
26 static volatile int reset_cnt
= 0;
27 static volatile int power_cycle
= 0;
29 static void chassis_set_pins(uint8_t pins
, uint8_t state
);
33 chassis_set_pins((1<<POWER_PIN
) | (1<<RESET_PIN
), 0);
34 CDDR
|= ((1<<POWER_PIN
) | (1<<RESET_PIN
));
37 OCR0
= ((F_CPU
/64)/1000) - 1;
39 TCCR0
= ((1<<WGM01
) | (1<<CS01
) | (1<<CS00
)); /* CTC, Prescaler 64 */
44 static void chassis_set_pins(uint8_t pins
, uint8_t state
)
57 static void chassis_power(int msec
)
59 uint8_t old_SREG
= SREG
;
61 chassis_set_pins((1<<POWER_PIN
), 1);
69 static void chassis_reset(int msec
)
71 uint8_t old_SREG
= SREG
;
73 chassis_set_pins((1<<RESET_PIN
), 1);
81 void chassis_control(unsigned char action
)
83 uint8_t old_SREG
= SREG
;
86 printf("Chassis control 0x%02x\n", action
);
90 case CHASSIS_ACTION_POWER_DOWN
:
91 chassis_power(POWERDOWN_TIME_MS
);
94 case CHASSIS_ACTION_POWER_UP
:
95 chassis_power(POWERUP_TIME_MS
);
98 case CHASSIS_ACTION_HARD_RESET
:
99 chassis_reset(RESET_TIME_MS
);
102 case CHASSIS_ACTION_POWER_CYCLE
:
104 power_cycle
= POWER_CYCLE_PAUSE_MS
;
106 chassis_power(POWERDOWN_TIME_MS
);
110 printf("Unimplemented chassis action 0x%02x\n", action
);
116 ISR(TIMER0_COMP_vect
)
122 chassis_set_pins((1<<POWER_PIN
), 0);
123 } else if (power_cycle
) {
127 chassis_set_pins((1<<POWER_PIN
), 1);
128 power_cnt
= POWERUP_TIME_MS
;
135 chassis_set_pins((1<<RESET_PIN
), 0);