2 #include <avr/interrupt.h> 
   7 #ifdef __AVR_ATmega16__ 
  13 #error "Please add chassis power/reset-PIN information for this chip" 
  16 #define __CPORT(port) PORT##port 
  17 #define _CPORT(port) __CPORT(port) 
  18 #define CPORT _CPORT(CHASSISPORT) 
  20 #define __CDDR(port) DDR##port 
  21 #define _CDDR(port) __CDDR(port) 
  22 #define CDDR _CDDR(CHASSISPORT) 
  24 static volatile int power_cnt 
= 0; 
  25 static volatile int reset_cnt 
= 0; 
  27 static void chassis_set_pins(uint8_t pins
, uint8_t state
); 
  31         chassis_set_pins((1<<POWER_PIN
) | (1<<RESET_PIN
), 0); 
  32         CDDR 
|= ((1<<POWER_PIN
) | (1<<RESET_PIN
)); 
  35         OCR0 
= ((F_CPU
/256)/1000)-1; 
  37         TCCR0 
= ((1<<WGM01
) | (1<<CS02
)); /* CTC, Prescaler 256 */ 
  42 static void chassis_set_pins(uint8_t pins
, uint8_t state
) 
  55 static void chassis_power(int msec
) 
  57         uint8_t old_SREG 
= SREG
; 
  59         chassis_set_pins((1<<POWER_PIN
), 1); 
  67 static void chassis_reset(int msec
) 
  69         uint8_t old_SREG 
= SREG
; 
  71         chassis_set_pins((1<<RESET_PIN
), 1); 
  79 void chassis_control(unsigned char action
) 
  82         printf("Chassis control 0x%02x\n", action
); 
  86                 case CHASSIS_ACTION_POWER_DOWN
: 
  90                 case CHASSIS_ACTION_POWER_UP
: 
  94                 case CHASSIS_ACTION_HARD_RESET
: 
 100                         printf("Unimplemented chassis action 0x%02x\n", action
); 
 106 ISR(TIMER0_COMP_vect
) 
 112                         chassis_set_pins((1<<POWER_PIN
), 0); 
 118                         chassis_set_pins((1<<RESET_PIN
), 0);