+#include <avr/io.h>
#include "interface.h"
#include "monitor.h"
#include "motorola.h"
#include "serial.h"
#include "s88.h"
-volatile uint8_t recv_buf[32];
-uint8_t recv_head = 0;
-uint8_t recv_tail = 0;
-volatile uint8_t recv_fill = 0;
-volatile uint8_t recv_overrun = 0;
-
-void process_commands(void);
uint8_t dispatch_command(const uint8_t *, uint8_t);
void interface_init(void)
void interface_check(void)
{
- if(recv_overrun)
- {
+ if(serial_read_overrun())
interface_send1(RECEIVE_OVERRUN);
- recv_overrun = 0;
- }
- if(recv_fill>0)
- process_commands();
-}
-void process_commands(void)
-{
- while(recv_fill>0)
+ while(serial_read_available())
{
- uint8_t cmd[15];
- uint8_t length = ~recv_buf[recv_tail];
+ uint8_t length = ~serial_read();
- if(length<0x10)
- {
- if(recv_fill<=length)
- break;
-
- uint8_t i, j;
- for(i=0, j=recv_tail+1; i<length; ++i, ++j)
- {
- if(j>=sizeof(recv_buf))
- j = 0;
- cmd[i] = recv_buf[j];
- }
- }
- else
- {
- length = 0;
+ if(length>=0x10)
interface_send1(FRAMING_ERROR);
- }
+ else if(length>0)
+ {
+ uint8_t cmd[15];
+ uint8_t i;
- recv_tail += length+1;
- if(recv_tail>=sizeof(recv_buf))
- recv_tail -= sizeof(recv_buf);
- recv_fill -= length+1;
+ for(i=0; i<length; ++i)
+ cmd[i] = serial_read();
- if(length>0)
- {
uint8_t result = dispatch_command(cmd, length);
interface_send1(result);
}
serial_write(0xFE);
serial_write(cmd);
}
-
-static inline void receive(uint8_t c)
-{
- if(recv_fill>=sizeof(recv_buf))
- {
- recv_overrun = 1;
- return;
- }
-
- recv_buf[recv_head++] = c;
- if(recv_head>=sizeof(recv_buf))
- recv_head = 0;
- ++recv_fill;
-}
-
-SERIAL_SET_CALLBACK(receive)