]> cvs.zerfleddert.de Git - rsbs2/commitdiff
start implementing power/reset handling as needed on PCs
authorMichael Gernoth <michael@gernoth.net>
Mon, 23 Aug 2010 10:19:05 +0000 (12:19 +0200)
committerMichael Gernoth <michael@gernoth.net>
Mon, 23 Aug 2010 10:19:05 +0000 (12:19 +0200)
bmc/chassis.c

index fd488663d7ec3735efebe70a3a71cb0bc9356b9a..1b6822e876c4ab650f7e5b5737b36b9685e48c07 100644 (file)
@@ -3,10 +3,66 @@
 
 #include "chassis.h"
 
 
 #include "chassis.h"
 
+#ifdef __AVR_ATmega16__
+#define CHASSISPORT B
+#define POWER_PIN 0
+#define RESET_PIN 1
+#define ACTIVE_LOW
+#else
+#error "Please add chassis power/reset-PIN information for this chip"
+#endif
+
+#define __CPORT(port) PORT##port
+#define _CPORT(port) __CPORT(port)
+#define CPORT _CPORT(CHASSISPORT)
+
+#define __CDDR(port) DDR##port
+#define _CDDR(port) __CDDR(port)
+#define CDDR _CDDR(CHASSISPORT)
+
+static void chassis_set_pins(uint8_t pins, uint8_t state);
+
 void chassis_init()
 {
 void chassis_init()
 {
-       DDRB = 0xff;
-       PORTB = 0xff;
+       chassis_set_pins((1<<POWER_PIN) | (1<<RESET_PIN), 0);
+       CDDR |= ((1<<POWER_PIN) | (1<<RESET_PIN));
+}
+
+static void chassis_set_pins(uint8_t pins, uint8_t state)
+{
+#ifdef ACTIVE_LOW
+       state = !state;
+#endif
+
+       if(state) {
+               CPORT |= pins;
+       } else {
+               CPORT &= ~pins;
+       }
+}
+
+static void chassis_power(int msec)
+{
+       volatile int i;
+
+       chassis_set_pins((1<<POWER_PIN), 1);
+
+       /* FIXME */
+       for(i = 0; i < (msec<<2); i++);
+
+       chassis_set_pins((1<<POWER_PIN), 0);
+}
+
+static void chassis_reset(int msec)
+{
+       volatile int i;
+
+       chassis_set_pins((1<<RESET_PIN), 1);
+
+       /* FIXME */
+       for(i = 0; i < (msec<<2); i++);
+
+       chassis_set_pins((1<<RESET_PIN), 0);
 }
 
 void chassis_control(unsigned char action)
 }
 
 void chassis_control(unsigned char action)
@@ -17,15 +73,15 @@ void chassis_control(unsigned char action)
 
        switch(action) {
                case CHASSIS_ACTION_POWER_DOWN:
 
        switch(action) {
                case CHASSIS_ACTION_POWER_DOWN:
-                       PORTB=0xff;
+                       chassis_power(5000);
                        break;
 
                case CHASSIS_ACTION_POWER_UP:
                        break;
 
                case CHASSIS_ACTION_POWER_UP:
-                       PORTB=0x00;
+                       chassis_power(500);
                        break;
 
                case CHASSIS_ACTION_HARD_RESET:
                        break;
 
                case CHASSIS_ACTION_HARD_RESET:
-                       PORTB=0x55;
+                       chassis_reset(500);
                        break;
 
                default:
                        break;
 
                default:
Impressum, Datenschutz