10 static uint8_t cmd_buffer[15];
11 static uint8_t cmd_length = 0;
12 static uint8_t cmd_read_pos = 0;
14 static uint8_t dispatch_command(const uint8_t *, uint8_t);
16 void interface_init(void)
19 DDRD = (DDRD&0xFC)|0x02;
24 void interface_check(void)
26 if(serial_read_overrun())
27 interface_send1(RECEIVE_OVERRUN);
29 uint8_t count = serial_read_available();
35 uint8_t l = ~serial_read();
39 interface_send1(FRAMING_ERROR);
48 if(cmd_read_pos<cmd_length)
50 if(cmd_read_pos+count>cmd_length)
51 count = cmd_length-cmd_read_pos;
52 for(uint8_t i=0; i<count; ++i)
53 cmd_buffer[cmd_read_pos++] = serial_read();
55 if(cmd_read_pos>=cmd_length)
57 uint8_t result = dispatch_command(cmd_buffer, cmd_length);
58 interface_send1(result);
66 static uint8_t dispatch_command(const uint8_t *cmd, uint8_t length)
68 uint8_t type = cmd[0]>>4;
71 uint8_t subtype = (cmd[0]>>3)&1;
73 return output_command(cmd, length);
75 return monitor_command(cmd, length);
78 return motorola_command(cmd, length);
80 return mfx_command(cmd, length);
82 return s88_command(cmd, length);
84 return INVALID_COMMAND;
87 void interface_send(const uint8_t *cmd, uint8_t length)
89 serial_write(~length);
90 for(uint8_t i=0; i<length; ++i)
94 void interface_send1(uint8_t cmd)