#include "chassis.h"
-#define DEBUG
+#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()
{
- 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)
switch(action) {
case CHASSIS_ACTION_POWER_DOWN:
- PORTB=0xff;
+ chassis_power(5000);
break;
case CHASSIS_ACTION_POWER_UP:
- PORTB=0x00;
+ chassis_power(500);
break;
case CHASSIS_ACTION_HARD_RESET:
- PORTB=0x55;
+ chassis_reset(500);
break;
default:
+#ifdef DEBUG
printf("Unimplemented chassis action 0x%02x\n", action);
+#endif
break;
}
}