]> git.zerfleddert.de Git - rsbs2/blobdiff - bmc/bmc.c
module configs now need .conf
[rsbs2] / bmc / bmc.c
index 4db28a6fab3cb2c9408a38f7b39dcdd6da8cdc55..e3690a47b5eef72f953e745e0cc88248bacb36af 100644 (file)
--- a/bmc/bmc.c
+++ b/bmc/bmc.c
@@ -1,64 +1,48 @@
 #include <avr/io.h>
-#include <avr/sleep.h>
 #include <avr/interrupt.h>
+#include <avr/sleep.h>
+#include <string.h>
 #include <stdio.h>
 #include "usart.h"
 #include "i2c.h"
+#include "ipmb.h"
+#include "chassis.h"
 #include "bmc.h"
 
-uint8_t ipmb_csum(unsigned char *buf, int len)
-{
-       uint8_t csum = 0x00;
-       int i;
-
-       for(i = 0; i < len; i++) {
-               csum += buf[i];
-       }
-
-       return -csum;
-}
-
-void decode_bmc_cmd(unsigned char *buf, int len)
-{
-       int i;
-
-       printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
-       printf("Connection Header:\n");
-       printf("\trs Slave Addr.: 0x%02x\n", buf[0]);
-       printf("\tnetFn: 0x%02x, LUN: 0x%02x\n", (buf[1]>>2)&0x3f, (buf[1] & 0x03));
-       printf("\tChecksum: 0x%02x (%s)\n", buf[2],
-               (buf[2] == ipmb_csum(buf, 2)) ? "OK" : "Wrong");
-       printf("Data:\n");
-       printf("\trq Slave Addr.: 0x%02x\n", buf[3]);
-       printf("\trqSeq: 0x%02x, rqLUN: 0x%02x\n", (buf[4]>>2)&0x3f, (buf[4] & 0x03));
-       printf("\tcmd: 0x%02x\n", buf[5]);
-       printf("\tData: ");
-       for(i = 6; i < (len - 1); i++) {
-               printf("0x%02x ", buf[i]);
-       }
-       printf("\n");
-       printf("\tChecksum: 0x%02x (%s)\n", buf[len-1],
-               (buf[len-1] == ipmb_csum(buf+3, len-4)) ? "OK" : "Wrong");
-       printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
-}
+#undef SLEEP_MODE
 
 int main(void)
 {
-       DDRB = 0xff;
-       PORTB = 0xff;
+       unsigned char buf[24];
+       unsigned int len;
 
-       usart_init();
-       printf("\n");
+       set_sleep_mode(SLEEP_MODE_IDLE);
 
+       chassis_init();
+       usart_init();
+       sei();
        i2c_init();
 
-       printf("Waiting for I2C...\n");
+       while(1) {
+               cli();
+               while (i2c_done) {
+                       len = i2c_len;
+                       memcpy(buf, (unsigned char*)i2c_databuf, len);
+                       i2c_done = 0x00;
+                       sei();
 
-       sei();
+                       decode_ipmb_pkt(buf, len);
 
-       while(1) {
-#if 1
-               sleep_mode();
+                       cli();
+               }
+
+#ifdef SLEEP_MODE
+               sleep_enable();
+#endif
+               sei();
+#ifdef SLEEP_MODE
+               sleep_cpu();
+               sleep_disable();
 #endif
        }
 
Impressum, Datenschutz