9 static uint8_t cmd_buffer[15];
10 static uint8_t cmd_length = 0;
11 static uint8_t cmd_read_pos = 0;
13 static uint8_t dispatch_command(const uint8_t *, uint8_t);
15 void interface_init(void)
17 DDRD = (DDRD&0xFC)|0x02;
22 void interface_check(void)
25 if(serial_read_overrun())
26 interface_send1(RECEIVE_OVERRUN);
28 count = serial_read_available();
33 uint8_t l = ~serial_read();
37 interface_send1(FRAMING_ERROR);
46 if(cmd_read_pos<cmd_length)
49 if(cmd_read_pos+count>cmd_length)
50 count = cmd_length-cmd_read_pos;
51 for(i=0; i<count; ++i)
52 cmd_buffer[cmd_read_pos++] = serial_read();
54 if(cmd_read_pos>=cmd_length)
56 uint8_t result = dispatch_command(cmd_buffer, cmd_length);
57 interface_send1(result);
64 static uint8_t dispatch_command(const uint8_t *cmd, uint8_t length)
66 uint8_t type = cmd[0]>>4;
69 uint8_t subtype = (cmd[0]>>3)&1;
71 return output_command(cmd, length);
73 return monitor_command(cmd, length);
76 return motorola_command(cmd, length);
78 return s88_command(cmd, length);
80 return INVALID_COMMAND;
83 void interface_send(const uint8_t *cmd, uint8_t length)
87 serial_write(~length);
88 for(i=0; i<length; ++i)
92 void interface_send1(uint8_t cmd)