]> git.zerfleddert.de Git - rsbs2/blob - bmc/chassis.c
1b6822e876c4ab650f7e5b5737b36b9685e48c07
[rsbs2] / bmc / chassis.c
1 #include <avr/io.h>
2 #include <stdio.h>
3
4 #include "chassis.h"
5
6 #ifdef __AVR_ATmega16__
7 #define CHASSISPORT B
8 #define POWER_PIN 0
9 #define RESET_PIN 1
10 #define ACTIVE_LOW
11 #else
12 #error "Please add chassis power/reset-PIN information for this chip"
13 #endif
14
15 #define __CPORT(port) PORT##port
16 #define _CPORT(port) __CPORT(port)
17 #define CPORT _CPORT(CHASSISPORT)
18
19 #define __CDDR(port) DDR##port
20 #define _CDDR(port) __CDDR(port)
21 #define CDDR _CDDR(CHASSISPORT)
22
23 static void chassis_set_pins(uint8_t pins, uint8_t state);
24
25 void chassis_init()
26 {
27 chassis_set_pins((1<<POWER_PIN) | (1<<RESET_PIN), 0);
28 CDDR |= ((1<<POWER_PIN) | (1<<RESET_PIN));
29 }
30
31 static void chassis_set_pins(uint8_t pins, uint8_t state)
32 {
33 #ifdef ACTIVE_LOW
34 state = !state;
35 #endif
36
37 if(state) {
38 CPORT |= pins;
39 } else {
40 CPORT &= ~pins;
41 }
42 }
43
44 static void chassis_power(int msec)
45 {
46 volatile int i;
47
48 chassis_set_pins((1<<POWER_PIN), 1);
49
50 /* FIXME */
51 for(i = 0; i < (msec<<2); i++);
52
53 chassis_set_pins((1<<POWER_PIN), 0);
54 }
55
56 static void chassis_reset(int msec)
57 {
58 volatile int i;
59
60 chassis_set_pins((1<<RESET_PIN), 1);
61
62 /* FIXME */
63 for(i = 0; i < (msec<<2); i++);
64
65 chassis_set_pins((1<<RESET_PIN), 0);
66 }
67
68 void chassis_control(unsigned char action)
69 {
70 #ifdef DEBUG
71 printf("Chassis control 0x%02x\n", action);
72 #endif
73
74 switch(action) {
75 case CHASSIS_ACTION_POWER_DOWN:
76 chassis_power(5000);
77 break;
78
79 case CHASSIS_ACTION_POWER_UP:
80 chassis_power(500);
81 break;
82
83 case CHASSIS_ACTION_HARD_RESET:
84 chassis_reset(500);
85 break;
86
87 default:
88 #ifdef DEBUG
89 printf("Unimplemented chassis action 0x%02x\n", action);
90 #endif
91 break;
92 }
93 }
Impressum, Datenschutz