]>
Commit | Line | Data |
---|---|---|
1 | #include <avr/io.h> | |
2 | #include <avr/sleep.h> | |
3 | #include <avr/interrupt.h> | |
4 | #include <stdio.h> | |
5 | #include "usart.h" | |
6 | #include "i2c.h" | |
7 | #include "bmc.h" | |
8 | ||
9 | uint8_t ipmb_csum(unsigned char *buf, int len) | |
10 | { | |
11 | uint8_t csum = 0x00; | |
12 | int i; | |
13 | ||
14 | for(i = 0; i < len; i++) { | |
15 | csum += buf[i]; | |
16 | } | |
17 | ||
18 | return -csum; | |
19 | } | |
20 | ||
21 | void decode_bmc_cmd(unsigned char *buf, int len) | |
22 | { | |
23 | int i; | |
24 | ||
25 | printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); | |
26 | printf("Connection Header:\n"); | |
27 | printf("\trs Slave Addr.: 0x%02x\n", buf[0]); | |
28 | printf("\tnetFn: 0x%02x, LUN: 0x%02x\n", (buf[1]>>2)&0x3f, (buf[1] & 0x03)); | |
29 | printf("\tChecksum: 0x%02x (%s)\n", buf[2], | |
30 | (buf[2] == ipmb_csum(buf, 2)) ? "OK" : "Wrong"); | |
31 | printf("Data:\n"); | |
32 | printf("\trq Slave Addr.: 0x%02x\n", buf[3]); | |
33 | printf("\trqSeq: 0x%02x, rqLUN: 0x%02x\n", (buf[4]>>2)&0x3f, (buf[4] & 0x03)); | |
34 | printf("\tcmd: 0x%02x\n", buf[5]); | |
35 | printf("\tData: "); | |
36 | for(i = 6; i < (len - 1); i++) { | |
37 | printf("0x%02x ", buf[i]); | |
38 | } | |
39 | printf("\n"); | |
40 | printf("\tChecksum: 0x%02x (%s)\n", buf[len-1], | |
41 | (buf[len-1] == ipmb_csum(buf+3, len-4)) ? "OK" : "Wrong"); | |
42 | printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); | |
43 | } | |
44 | ||
45 | int main(void) | |
46 | { | |
47 | DDRB = 0xff; | |
48 | PORTB = 0xff; | |
49 | ||
50 | usart_init(); | |
51 | printf("\n"); | |
52 | ||
53 | i2c_init(); | |
54 | ||
55 | printf("Waiting for I2C...\n"); | |
56 | ||
57 | sei(); | |
58 | ||
59 | while(1) { | |
60 | #if 1 | |
61 | sleep_mode(); | |
62 | #endif | |
63 | } | |
64 | ||
65 | return 0; | |
66 | } |