From: Mikko Rasa Date: Mon, 28 Oct 2013 19:59:48 +0000 (+0200) Subject: Rewrite arducontrol interface module to use the new serial API X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=70404f704dc8acbfa4bae971661dd484a997085a;p=model-railway-devices.git Rewrite arducontrol interface module to use the new serial API --- diff --git a/arducontrol/Makefile b/arducontrol/Makefile index a7cb562..be2ca32 100644 --- a/arducontrol/Makefile +++ b/arducontrol/Makefile @@ -1,3 +1,4 @@ +FEATURES := SERIAL_ASYNC include ../common/build.mk arducontrol.elf: adc.o interface.o monitor.o motorola.o output.o serial.o s88.o timer.o diff --git a/arducontrol/interface.c b/arducontrol/interface.c index 4064120..675770f 100644 --- a/arducontrol/interface.c +++ b/arducontrol/interface.c @@ -1,3 +1,4 @@ +#include #include "interface.h" #include "monitor.h" #include "motorola.h" @@ -5,13 +6,6 @@ #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) @@ -23,48 +17,23 @@ 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=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; i0) - { uint8_t result = dispatch_command(cmd, length); interface_send1(result); } @@ -104,19 +73,3 @@ void interface_send1(uint8_t cmd) 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)