summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2008-10-23 21:43:33 +0200
committerMichael Buesch <mb@bu3sch.de>2008-10-23 21:43:33 +0200
commit8421080c367083e01e07569d82ea4fe6f63cb86c (patch)
tree951108e7cb5fb6ebde6eca845ef07432dfa0a6bf /pressure_control/firmware
parent13ff7496a156bb366b7c861575ba77b1ed337dfb (diff)
downloadcnc-8421080c367083e01e07569d82ea4fe6f63cb86c.tar.xz
cnc-8421080c367083e01e07569d82ea4fe6f63cb86c.zip
pressure_control: Implement RX timeout
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Diffstat (limited to 'pressure_control/firmware')
-rw-r--r--pressure_control/firmware/main.c1
-rw-r--r--pressure_control/firmware/remote.c21
-rw-r--r--pressure_control/firmware/remote.h1
3 files changed, 23 insertions, 0 deletions
diff --git a/pressure_control/firmware/main.c b/pressure_control/firmware/main.c
index ef4c81e..fc16dad 100644
--- a/pressure_control/firmware/main.c
+++ b/pressure_control/firmware/main.c
@@ -108,6 +108,7 @@ ISR(TIMER1_COMPA_vect)
{
if (state.sensor_trigger_cnt > 0)
state.sensor_trigger_cnt--;
+ remote_1khz_work();
}
void system_timer_init(void)
diff --git a/pressure_control/firmware/remote.c b/pressure_control/firmware/remote.c
index dafca5d..29b15b4 100644
--- a/pressure_control/firmware/remote.c
+++ b/pressure_control/firmware/remote.c
@@ -36,6 +36,7 @@ static struct remote_message rx_msg;
static uint8_t rx_msg_count;
static bool rx_msg_valid;
static bool rx_softirq;
+static uint16_t rx_timeout;
static inline void usart_tx(uint8_t data)
@@ -236,6 +237,7 @@ static void usart_handle_rx_irq(void)
rxbuf[rx_msg_count++] = data;
if (rx_msg_count == sizeof(struct remote_message)) {
rx_msg_count = 0;
+ rx_timeout = 0;
mb();
rx_msg_valid = 1;
break;
@@ -254,6 +256,19 @@ ISR(USART_RXC_vect)
usart_handle_rx_irq();
}
+/* Called with IRQs disabled. */
+static void usart_rx_timeout_check()
+{
+ if (rx_msg_count > 0)
+ rx_timeout++;
+ if (rx_timeout > 100 /* milliseconds */) {
+ /* Timeout! Reset the RX buffer. */
+ rx_msg_count = 0;
+ rx_timeout = 0;
+ }
+ mb();
+}
+
void print_pgm(const prog_char *str)
{
struct remote_message msg;
@@ -291,6 +306,12 @@ void remote_work(void)
sei();
}
+/* Maintanance work. Called at a frequency of 1KHz with IRQs disabled. */
+void remote_1khz_work(void)
+{
+ usart_rx_timeout_check();
+}
+
void remote_pressure_change_notification(uint16_t mbar,
uint16_t hysteresis)
{
diff --git a/pressure_control/firmware/remote.h b/pressure_control/firmware/remote.h
index ad67540..9aabfe9 100644
--- a/pressure_control/firmware/remote.h
+++ b/pressure_control/firmware/remote.h
@@ -78,6 +78,7 @@ void remote_pressure_change_notification(uint16_t mbar,
uint16_t hysteresis);
void remote_work(void);
+void remote_1khz_work(void);
void remote_init(void);
#endif /* REMOTE_H_ */
bues.ch cgit interface