annotate tests/cptest.c @ 13:1ea479d26fce tip

Make sure shifting phase and add bypass.py. - shifting phase is started after entering SHIFT state Transition from CAP to SHIFT does not induce shifting. - shifting phase is stoped after leaving SHIFT state. Transition from SHIFT to EXIT1 also induce a bit of shifting.
author Thinker K.F. Li <thinker@branda.to>
date Wed, 25 Feb 2009 20:08:29 +0800
parents e410832c3280
children
rev   line source
1
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <string.h>
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <util/delay.h>
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include "avriotools.h"
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include "cmd_proto.h"
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #define BAUD_RATE 420000
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 void flash_init(void) {
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 pin_mode(&PORTB, PINB0, PM_OUTPUT);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 pin_mode(&PORTB, PINB1, PM_OUTPUT);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 pin_lo(PORTB, PINB0);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 pin_lo(PORTB, PINB1);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 }
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 void flash_led(void) {
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 pin_hi(PORTB, PINB0);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 _delay_ms(50);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 pin_lo(PORTB, PINB0);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 }
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 int main(int argc, char * const argv[]) {
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 int c;
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 cmd_proto_t *cp;
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 cp_cmd_t *cmd;
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 char buf[255 + CP_CMD_OVERHEAD];
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 int sz;
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 int i;
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 flash_init();
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 uart_init(BAUD_RATE);
3
e410832c3280 Issue of avr-ld.
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
33
1
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 cp = cmd_proto_new();
3
e410832c3280 Issue of avr-ld.
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
35
1
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 while(1) {
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 uart_getc(c);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 cmd = cmd_proto_rcv(cp, c);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 if(cmd == NULL)
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 continue;
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 flash_led();
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 if(cmd == &BAD_CMD) {
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 memcpy(buf + CP_CMD_HEAD_SZ, "bad cmd", 7);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 sz = cmd_proto_cmd_fill(buf, cmd->seq, CPCMD_NAK, 7);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 for(i = 0; i < sz; i++)
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 uart_putc(buf[i]);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 continue;
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 }
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 if(cmd == &CSUM_ERR_CMD) {
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 memcpy(buf + CP_CMD_HEAD_SZ, "csum err", 8);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 sz = cmd_proto_cmd_fill(buf, cmd->seq, CPCMD_NAK, 8);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 for(i = 0; i < sz; i++)
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 uart_putc(buf[i]);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 continue;
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 }
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 switch(cmd->code) {
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 case CPCMD_PING:
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 memcpy(buf + CP_CMD_HEAD_SZ, cmd->data, cmd->data_sz);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 sz = cmd_proto_cmd_fill(buf, cmd->seq, CPCMD_PONG, cmd->data_sz);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 for(i = 0; i < sz; i++)
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 uart_putc(buf[i]);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 break;
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 default:
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 memcpy(buf + CP_CMD_HEAD_SZ, cmd->data, cmd->data_sz);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 sz = cmd_proto_cmd_fill(buf, cmd->seq, CPCMD_DATA, cmd->data_sz);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 for(i = 0; i < sz; i++)
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 uart_putc(buf[i]);
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 }
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 }
f7c60e525801 cptest and cp_ping.py to test cmd_proto.c.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 }