]> cvs.zerfleddert.de Git - rsbs2/blame - bmc/chassis.c
start implementing power/reset handling as needed on PCs
[rsbs2] / bmc / chassis.c
CommitLineData
da7751cb
MG
1#include <avr/io.h>
2#include <stdio.h>
3
4#include "chassis.h"
5
19d56e39
MG
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
23static void chassis_set_pins(uint8_t pins, uint8_t state);
24
da7751cb
MG
25void chassis_init()
26{
19d56e39
MG
27 chassis_set_pins((1<<POWER_PIN) | (1<<RESET_PIN), 0);
28 CDDR |= ((1<<POWER_PIN) | (1<<RESET_PIN));
29}
30
31static 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
44static 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
56static 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);
da7751cb
MG
66}
67
68void 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:
19d56e39 76 chassis_power(5000);
da7751cb
MG
77 break;
78
79 case CHASSIS_ACTION_POWER_UP:
19d56e39 80 chassis_power(500);
da7751cb
MG
81 break;
82
83 case CHASSIS_ACTION_HARD_RESET:
19d56e39 84 chassis_reset(500);
da7751cb
MG
85 break;
86
87 default:
f9d5c6e0 88#ifdef DEBUG
da7751cb 89 printf("Unimplemented chassis action 0x%02x\n", action);
f9d5c6e0 90#endif
da7751cb
MG
91 break;
92 }
93}
Impressum, Datenschutz