X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/rsbs2/blobdiff_plain/20ef0f397c40ec362d25b6349b3e3383e80fc2af..99f916c4f2f21a5e41464b3b9455f4442ce5069e:/bmc/bmc.c diff --git a/bmc/bmc.c b/bmc/bmc.c index 4db28a6..e3690a4 100644 --- a/bmc/bmc.c +++ b/bmc/bmc.c @@ -1,64 +1,48 @@ #include -#include #include +#include +#include #include #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 }