From d51930558a73dd1083b924159971d4c77df411e6 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 22 Aug 2010 21:42:37 +0200 Subject: [PATCH] I2C master mode implemented and more decoding --- bmc/Makefile | 2 +- bmc/bmc.c | 36 --------------------------------- bmc/bmc.h | 1 - bmc/i2c.c | 45 +++++++++++++++++++++++++++++++++++++++-- bmc/i2c.h | 1 + bmc/ipmb.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bmc/ipmb.h | 13 ++++++++++++ 7 files changed, 114 insertions(+), 40 deletions(-) create mode 100644 bmc/ipmb.c create mode 100644 bmc/ipmb.h diff --git a/bmc/Makefile b/bmc/Makefile index 6f8b4dd..d9ad589 100644 --- a/bmc/Makefile +++ b/bmc/Makefile @@ -11,7 +11,7 @@ OBJCOPY=avr-objcopy all: bmc.bin -bmc: bmc.o usart.o i2c.o +bmc: bmc.o usart.o i2c.o ipmb.o bmc.bin: bmc $(OBJCOPY) -j .text -j .data -O binary $^ $@ diff --git a/bmc/bmc.c b/bmc/bmc.c index 4db28a6..525785e 100644 --- a/bmc/bmc.c +++ b/bmc/bmc.c @@ -6,42 +6,6 @@ #include "i2c.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"); -} - int main(void) { DDRB = 0xff; diff --git a/bmc/bmc.h b/bmc/bmc.h index 99d5810..e69de29 100644 --- a/bmc/bmc.h +++ b/bmc/bmc.h @@ -1 +0,0 @@ -void decode_bmc_cmd(unsigned char *buf, int len); diff --git a/bmc/i2c.c b/bmc/i2c.c index 4ada02e..6550c92 100644 --- a/bmc/i2c.c +++ b/bmc/i2c.c @@ -2,7 +2,7 @@ #include #include #include "i2c.h" -#include "bmc.h" +#include "ipmb.h" #define TWCR_ACK TWCR = (1< + +#include "ipmb.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_ipmb_pkt(unsigned char *buf, int len) +{ + int i; + struct ipmb_req req; + + req.rsSA = buf[0]; + req.netFn = (buf[1]>>2)&0x3f; + req.rsLUN = (buf[1] & 0x03); + req.rqSA = buf[3]; + req.rqSEQ = (buf[4]>>2)&0x3f; + req.rqLUN = (buf[4] & 0x03); + req.cmd = buf[5]; + req.data = buf+6; + req.datalen = len - 6 - 1; + + printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); + printf("Connection Header:\n"); + printf("\trs Slave Addr.: 0x%02x\n", req.rsSA); + printf("\tnetFn: 0x%02x, LUN: 0x%02x\n", req.netFn, req.rsLUN); + 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", req.rqSA); + printf("\trqSeq: 0x%02x, rqLUN: 0x%02x\n", req.rqSEQ, req.rqLUN); + printf("\tcmd: 0x%02x\n", req.cmd); + printf("\tData: "); + for(i = 0; i < req.datalen; i++) { + printf("0x%02x ", req.data[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"); + + if ((buf[2] != ipmb_csum(buf, 2)) || + (buf[len-1] == ipmb_csum(buf+3, len-4))) + return; /* Checksum wrong */ + + //i2c_send((unsigned char*)"\x28\x00",1); +} diff --git a/bmc/ipmb.h b/bmc/ipmb.h new file mode 100644 index 0000000..c48ad31 --- /dev/null +++ b/bmc/ipmb.h @@ -0,0 +1,13 @@ +struct ipmb_req { + uint8_t rsSA; + uint8_t netFn; + uint8_t rsLUN; + uint8_t rqSA; + uint8_t rqSEQ; + uint8_t rqLUN; + uint8_t cmd; + unsigned char *data; + uint8_t datalen; +}; + +void decode_ipmb_pkt(unsigned char *buf, int len); -- 2.39.2