]> git.zerfleddert.de Git - rsbs2/blobdiff - bmc/chassis.c
use of qw() as parentheses is deprecated...
[rsbs2] / bmc / chassis.c
index 852e726ff1e5f8c85aaa3b6a00d3f716633e7388..29541f288e12e593af3f2efc1aa99dd40089eec1 100644 (file)
@@ -2,6 +2,7 @@
 #include <avr/interrupt.h>
 #include <stdio.h>
 
 #include <avr/interrupt.h>
 #include <stdio.h>
 
+#include "config.h"
 #include "chassis.h"
 
 #ifdef __AVR_ATmega16__
 #include "chassis.h"
 
 #ifdef __AVR_ATmega16__
 
 static volatile int power_cnt = 0;
 static volatile int reset_cnt = 0;
 
 static volatile int power_cnt = 0;
 static volatile int reset_cnt = 0;
+static volatile int power_cycle = 0;
 
 static void chassis_set_pins(uint8_t pins, uint8_t state);
 
 void chassis_init()
 {
        chassis_set_pins((1<<POWER_PIN) | (1<<RESET_PIN), 0);
 
 static void chassis_set_pins(uint8_t pins, uint8_t state);
 
 void chassis_init()
 {
        chassis_set_pins((1<<POWER_PIN) | (1<<RESET_PIN), 0);
-       CDDR |= ((1<<POWER_PIN) | (1<<RESET_PIN));
 
        /* About 1ms */
        OCR0 = ((F_CPU/64)/1000) - 1;
 
        /* About 1ms */
        OCR0 = ((F_CPU/64)/1000) - 1;
@@ -39,16 +40,27 @@ void chassis_init()
 
 }
 
 
 }
 
+/* gracefully transition between tri-state and active */
 static void chassis_set_pins(uint8_t pins, uint8_t state)
 {
 static void chassis_set_pins(uint8_t pins, uint8_t state)
 {
-#ifdef ACTIVE_LOW
-       state = !state;
-#endif
-
        if(state) {
        if(state) {
+               /* active */
+#ifndef ACTIVE_LOW
+               /* Pull UPs for a short moment... */
                CPORT |= pins;
                CPORT |= pins;
+#endif
+               CDDR |= pins;
+#ifdef ACTIVE_LOW
+               CPORT &= ~pins;
+#endif
        } else {
        } else {
+#ifdef ACTIVE_LOW
+               CPORT &= ~pins; /* NoOp... */
+#endif
+               CDDR &= ~pins;
+#ifndef ACTIVE_LOW
                CPORT &= ~pins;
                CPORT &= ~pins;
+#endif
        }
 }
 
        }
 }
 
@@ -78,23 +90,31 @@ static void chassis_reset(int msec)
 
 void chassis_control(unsigned char action)
 {
 
 void chassis_control(unsigned char action)
 {
+       uint8_t old_SREG = SREG;
+
 #ifdef DEBUG
        printf("Chassis control 0x%02x\n", action);
 #endif
 
        switch(action) {
                case CHASSIS_ACTION_POWER_DOWN:
 #ifdef DEBUG
        printf("Chassis control 0x%02x\n", action);
 #endif
 
        switch(action) {
                case CHASSIS_ACTION_POWER_DOWN:
-                       chassis_power(5000);
+                       chassis_power(POWERDOWN_TIME_MS);
                        break;
 
                case CHASSIS_ACTION_POWER_UP:
                        break;
 
                case CHASSIS_ACTION_POWER_UP:
-                       chassis_power(200);
+                       chassis_power(POWERUP_TIME_MS);
                        break;
 
                case CHASSIS_ACTION_HARD_RESET:
                        break;
 
                case CHASSIS_ACTION_HARD_RESET:
-                       chassis_reset(200);
+                       chassis_reset(RESET_TIME_MS);
                        break;
 
                        break;
 
+               case CHASSIS_ACTION_POWER_CYCLE:
+                       cli();
+                       power_cycle = POWER_CYCLE_PAUSE_MS;
+                       SREG = old_SREG;
+                       chassis_power(POWERDOWN_TIME_MS);
+
                default:
 #ifdef DEBUG
                        printf("Unimplemented chassis action 0x%02x\n", action);
                default:
 #ifdef DEBUG
                        printf("Unimplemented chassis action 0x%02x\n", action);
@@ -110,6 +130,13 @@ ISR(TIMER0_COMP_vect)
 
                if (!power_cnt)
                        chassis_set_pins((1<<POWER_PIN), 0);
 
                if (!power_cnt)
                        chassis_set_pins((1<<POWER_PIN), 0);
+       } else if (power_cycle) {
+               power_cycle--;
+
+               if (!power_cycle) {
+                       chassis_set_pins((1<<POWER_PIN), 1);
+                       power_cnt = POWERUP_TIME_MS;
+               }
        }
        if (reset_cnt) {
                reset_cnt--;
        }
        if (reset_cnt) {
                reset_cnt--;
Impressum, Datenschutz